-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
'#1866: Replace bookmark "rename" option by "edit" (name and color).
- Loading branch information
1 parent
6488d1d
commit 31c19d3
Showing
8 changed files
with
250 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
iped-app/src/main/java/iped/app/ui/bookmarks/BookmarkEditDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
package iped.app.ui.bookmarks; | ||
|
||
import java.awt.BorderLayout; | ||
import java.awt.Color; | ||
import java.awt.Dimension; | ||
import java.awt.FlowLayout; | ||
import java.awt.GridLayout; | ||
import java.awt.event.ActionEvent; | ||
import java.awt.event.ActionListener; | ||
import java.awt.event.FocusAdapter; | ||
import java.awt.event.FocusEvent; | ||
|
||
import javax.swing.BorderFactory; | ||
import javax.swing.JButton; | ||
import javax.swing.JDialog; | ||
import javax.swing.JLabel; | ||
import javax.swing.JPanel; | ||
import javax.swing.JTextField; | ||
import javax.swing.UIManager; | ||
|
||
import iped.app.ui.Messages; | ||
|
||
public class BookmarkEditDialog extends JDialog { | ||
private static final long serialVersionUID = -8204366293115657785L; | ||
|
||
private String newName; | ||
private Color newColor; | ||
|
||
private JButton selButton; | ||
|
||
public BookmarkEditDialog(JDialog parent, String currentName, Color currentColor) { | ||
super(parent, ModalityType.APPLICATION_MODAL); | ||
setTitle(Messages.getString("BookmarksManager.Edit.Title")); | ||
setLocationRelativeTo(parent); | ||
setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); | ||
|
||
JPanel content = new JPanel(new BorderLayout(10, 10)); | ||
content.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); | ||
setContentPane(content); | ||
|
||
// Bookmark name | ||
JPanel p1 = new JPanel(new BorderLayout(2, 2)); | ||
add(p1, BorderLayout.NORTH); | ||
|
||
p1.add(new JLabel(Messages.getString("BookmarksManager.Edit.Name") + ":"), BorderLayout.NORTH); | ||
|
||
JTextField txtName = new JTextField(); | ||
txtName.setText(currentName); | ||
txtName.addFocusListener(new FocusAdapter() { | ||
@Override | ||
public void focusGained(FocusEvent e) { | ||
txtName.selectAll(); | ||
} | ||
}); | ||
p1.add(txtName, BorderLayout.CENTER); | ||
|
||
// Bookmark color | ||
JPanel p2 = new JPanel(new BorderLayout(2, 2)); | ||
add(p2, BorderLayout.CENTER); | ||
|
||
p2.add(new JLabel(Messages.getString("BookmarksManager.Edit.Color") + ":"), BorderLayout.NORTH); | ||
|
||
int numColors = BookmarkStandardColors.colors.length + 1; | ||
JPanel colorGrid = new JPanel(new GridLayout(BookmarkStandardColors.numStandardColors / 9, 10, 2, 2)); | ||
int x = 0; | ||
int y = 0; | ||
boolean seen = false; | ||
newColor = currentColor; | ||
for (int i = 0; i < numColors; i++) { | ||
int idx = x < 9 ? x + y * 9 : BookmarkStandardColors.numStandardColors + y; | ||
Color color = idx < BookmarkStandardColors.colors.length ? BookmarkStandardColors.colors[idx] : null; | ||
boolean checked = false; | ||
if (color == null) { | ||
if (seen) { | ||
break; | ||
} | ||
color = currentColor; | ||
checked = true; | ||
} else if (color.equals(currentColor)) { | ||
checked = true; | ||
seen = true; | ||
} | ||
BookmarkIcon icon = BookmarkIcon.getIcon(color, checked); | ||
JButton but = new JButton(icon); | ||
if (checked) { | ||
selButton = but; | ||
} | ||
colorGrid.add(but); | ||
but.setFocusable(true); | ||
but.setFocusPainted(false); | ||
but.setBorder(null); | ||
but.setContentAreaFilled(false); | ||
but.addActionListener(new ActionListener() { | ||
public void actionPerformed(ActionEvent e) { | ||
if (selButton != null) { | ||
((BookmarkIcon) (selButton.getIcon())).setChecked(false); | ||
selButton.repaint(); | ||
} | ||
newColor = icon.getColor(); | ||
icon.setChecked(true); | ||
selButton = but; | ||
} | ||
}); | ||
|
||
if (++x == 10) { | ||
x = 0; | ||
y++; | ||
} | ||
} | ||
p2.add(colorGrid, BorderLayout.CENTER); | ||
|
||
// Buttons | ||
JPanel p3 = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 2)); | ||
add(p3, BorderLayout.SOUTH); | ||
|
||
Dimension dim = new Dimension(90, 30); | ||
JButton butOk = new JButton(); | ||
butOk.setText(UIManager.get("OptionPane.okButtonText").toString()); | ||
butOk.setPreferredSize(dim); | ||
p3.add(butOk); | ||
|
||
JButton butCancel = new JButton(); | ||
butCancel.setPreferredSize(dim); | ||
butCancel.setText(UIManager.get("OptionPane.cancelButtonText").toString()); | ||
p3.add(butCancel); | ||
|
||
butOk.addActionListener(new ActionListener() { | ||
public void actionPerformed(ActionEvent e) { | ||
newName = txtName.getText().trim(); | ||
setVisible(false); | ||
} | ||
}); | ||
|
||
butCancel.addActionListener(new ActionListener() { | ||
public void actionPerformed(ActionEvent e) { | ||
newName = null; | ||
newColor = null; | ||
setVisible(false); | ||
} | ||
}); | ||
|
||
pack(); | ||
} | ||
|
||
public String getNewName() { | ||
return newName; | ||
} | ||
|
||
public Color getNewColor() { | ||
return newColor; | ||
} | ||
} |
Oops, something went wrong.