Skip to content

Commit

Permalink
'#1866: Replace bookmark "rename" option by "edit" (name and color).
Browse files Browse the repository at this point in the history
  • Loading branch information
wladimirleite committed Sep 12, 2023
1 parent 6488d1d commit 31c19d3
Show file tree
Hide file tree
Showing 8 changed files with 250 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ BookmarksManager.ConfirmDelTitle=Confirm
BookmarksManager.Dataset=Dataset:
BookmarksManager.Delete=Delete
BookmarksManager.Delete.Tip=Delete selected bookmarks
BookmarksManager.Edit=Edit
BookmarksManager.Edit.Color=Color
BookmarksManager.Edit.Name=Name
BookmarksManager.Edit.Tip=Edit selected bookmark name and color
BookmarksManager.Edit.Title=Edit Bookmark
BookmarksManager.Highlighted=Highlighted items
BookmarksManager.KeyStrokeBookmark=<html>Type a key (combination) to define a shortcut to 'Add'.<br>ALT+key always 'Remove'.</html>
BookmarksManager.KeyStrokeAlert1=Select just one bookmark to define key shortcut.
Expand All @@ -65,10 +70,8 @@ BookmarksManager.LoadingHashes=Loading Hashes...
BookmarksManager.New=New
BookmarksManager.New.Tip=New bookmark
BookmarksManager.NewBookmark.Tip=Enter bookmark name
BookmarksManager.NewName=New name to first selected bookmark
BookmarksManager.Remove=Remove
BookmarksManager.Remove.Tip=Remove items from selected bookmarks
BookmarksManager.Rename=Rename
BookmarksManager.SearchingDuplicates=Searching Duplicates...
BookmarksManager.Title=Bookmarks
BookmarksManager.CommentsTooltip=Bookmark comments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ BookmarksManager.ConfirmDelTitle=Bestätigung
BookmarksManager.Dataset=Datensatz:
BookmarksManager.Delete=Löschen
BookmarksManager.Delete.Tip=lösche markierte Lesezeichen
BookmarksManager.Edit=Edit[TBT]
BookmarksManager.Edit.Color=Color[TBT]
BookmarksManager.Edit.Name=Name[TBT]
BookmarksManager.Edit.Tip=Edit selected bookmark name and color[TBT]
BookmarksManager.Edit.Title=Edit Bookmark[TBT]
BookmarksManager.Highlighted=markierte Objekte
BookmarksManager.KeyStrokeBookmark=<html>Drücke eine Taste(nkombination) um einen Kurzbefehl für das Hinzufügen zu erstellen.<br>Alt+key bedeutet 'Entfernen'.</html>
BookmarksManager.KeyStrokeAlert1=Bitte ein Lesezeichen wählen um einen Kurzbefehl zu definieren.
Expand All @@ -65,10 +70,8 @@ BookmarksManager.LoadingHashes=Lade Hashes...
BookmarksManager.New=Neu
BookmarksManager.New.Tip=Neues Lesezeichen
BookmarksManager.NewBookmark.Tip=Name für Lesezeichen eingeben
BookmarksManager.NewName=Neue Bezeichnung für erstes ausgewähltes Lesezeichen
BookmarksManager.Remove=Entfernen
BookmarksManager.Remove.Tip=Entferne Objekte von ausgewähltem Lesezeichen
BookmarksManager.Rename=Umbenennen
BookmarksManager.SearchingDuplicates=Suche Duplikate...
BookmarksManager.Title=Lesezeichen
BookmarksManager.CommentsTooltip=Kommentare zu Lesezeichen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ BookmarksManager.ConfirmDelTitle=Confirmar
BookmarksManager.Dataset=Conjunto de datos:
BookmarksManager.Delete=Eliminar
BookmarksManager.Delete.Tip=Eliminar marcadores seleccionados
BookmarksManager.Edit=Edit[TBT]
BookmarksManager.Edit.Color=Color[TBT]
BookmarksManager.Edit.Name=Name[TBT]
BookmarksManager.Edit.Tip=Edit selected bookmark name and color[TBT]
BookmarksManager.Edit.Title=Edit Bookmark[TBT]
BookmarksManager.Highlighted=Elementos resaltados
BookmarksManager.KeyStrokeBookmark=<html>Escriba (o combine) teclas para establecer un atajo para 'Añadir'.<br>Alt+tecla siempre activa 'Eliminar'.</html>
BookmarksManager.KeyStrokeAlert1=Seleccione solo 1 marcador para definir el atajo de teclas.
Expand All @@ -65,10 +70,8 @@ BookmarksManager.LoadingHashes=Cargando hashes...
BookmarksManager.New=Nuevo
BookmarksManager.New.Tip=Nuevo marcador
BookmarksManager.NewBookmark.Tip=Ingrese el nombre del marcador
BookmarksManager.NewName=Nuevo nombre para el primer marcador seleccionado
BookmarksManager.Remove=Eliminar
BookmarksManager.Remove.Tip=Eliminar elementos de los marcadores seleccionados
BookmarksManager.Rename=Renombrar
BookmarksManager.SearchingDuplicates=Buscando duplicados...
BookmarksManager.Title=Marcadores
BookmarksManager.CommentsTooltip=Marcar comentarios
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ BookmarksManager.ConfirmDelTitle=Conferma
BookmarksManager.Dataset=Set di dati:
BookmarksManager.Delete=Elimina
BookmarksManager.Delete.Tip=Elimina i segnalibri selezionati
BookmarksManager.Edit=Edit[TBT]
BookmarksManager.Edit.Color=Color[TBT]
BookmarksManager.Edit.Name=Name[TBT]
BookmarksManager.Edit.Tip=Edit selected bookmark name and color[TBT]
BookmarksManager.Edit.Title=Edit Bookmark[TBT]
BookmarksManager.Highlighted=Elementi evidenziati
BookmarksManager.KeyStrokeBookmark=<html>Digita un tasto (combinazione) per definire una scorciatoia per 'Aggiungi'.<br>Alt+key 'Rimuovi' sempre.</html>
BookmarksManager.KeyStrokeAlert1=Seleziona solo un segnalibro per definire una scorciatoia.
Expand All @@ -65,10 +70,8 @@ BookmarksManager.LoadingHashes=Caricamento Hash...
BookmarksManager.New=Nuovo
BookmarksManager.New.Tip=Nuovo segnalibro
BookmarksManager.NewBookmark.Tip=Inserisci il nome del segnalibro
BookmarksManager.NewName=Nuovo nome al primo segnalibro selezionato
BookmarksManager.Remove=Rimuovi
BookmarksManager.Remove.Tip=Rimuovi elementi dai segnalibri selezionati
BookmarksManager.Rename=Rinomina
BookmarksManager.SearchingDuplicates=Trova duplicati...
BookmarksManager.Title=Segnalibri
BookmarksManager.CommentsTooltip=Commenti ai segnalibri
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ BookmarksManager.ConfirmDelTitle=Confirmar
BookmarksManager.Dataset=Conjunto de dados:
BookmarksManager.Delete=Apagar
BookmarksManager.Delete.Tip=Apagar marcadores selecionados
BookmarksManager.Edit=Editar
BookmarksManager.Edit.Color=Cor
BookmarksManager.Edit.Name=Nome
BookmarksManager.Edit.Tip=Editar nome e cor do marcador selecionado
BookmarksManager.Edit.Title=Editar Marcador
BookmarksManager.Highlighted=Itens Destacados
BookmarksManager.KeyStrokeBookmark=<html>Digite (ou combine) teclas para definir atalho p/ 'Adicionar'.<br>ALT+tecla sempre aciona 'Remover'.</html>
BookmarksManager.KeyStrokeAlert1=Selecione apenas um marcador para definir a tecla de atalho.
Expand All @@ -65,10 +70,8 @@ BookmarksManager.LoadingHashes=Obtendo hashes...
BookmarksManager.New=Criar novo
BookmarksManager.New.Tip=Novo marcador
BookmarksManager.NewBookmark.Tip=Novo marcador
BookmarksManager.NewName=Novo nome para o primeiro marcador selecionado
BookmarksManager.Remove=Remover
BookmarksManager.Remove.Tip=Remover itens dos marcadores selecionados
BookmarksManager.Rename=Renomear
BookmarksManager.SearchingDuplicates=Pesquisando duplicatas...
BookmarksManager.Title=Marcadores
BookmarksManager.CommentsTooltip=Comentários do marcador
Expand Down
52 changes: 35 additions & 17 deletions iped-app/src/main/java/iped/app/ui/BookmarksManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package iped.app.ui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
Expand Down Expand Up @@ -71,6 +72,7 @@

import iped.app.ui.bookmarks.BookmarkAndKey;
import iped.app.ui.bookmarks.BookmarkColorsManager;
import iped.app.ui.bookmarks.BookmarkEditDialog;
import iped.app.ui.bookmarks.BookmarkListRenderer;
import iped.data.IItem;
import iped.data.IItemId;
Expand Down Expand Up @@ -100,7 +102,7 @@ public class BookmarksManager implements ActionListener, ListSelectionListener,
JCheckBox duplicates = new JCheckBox();
JButton butAdd = new JButton(Messages.getString("BookmarksManager.Add")); //$NON-NLS-1$
JButton butRemove = new JButton(Messages.getString("BookmarksManager.Remove")); //$NON-NLS-1$
JButton butRename = new JButton(Messages.getString("BookmarksManager.Rename")); //$NON-NLS-1$
JButton butEdit = new JButton(Messages.getString("BookmarksManager.Edit")); //$NON-NLS-1$
JTextField newBookmark = new JTextField();
JTextArea comments = new JTextArea();
JButton butNew = new JButton(Messages.getString("BookmarksManager.New")); //$NON-NLS-1$
Expand Down Expand Up @@ -154,6 +156,7 @@ private BookmarksManager() {
butAdd.setToolTipText(Messages.getString("BookmarksManager.Add.Tip")); //$NON-NLS-1$
butRemove.setToolTipText(Messages.getString("BookmarksManager.Remove.Tip")); //$NON-NLS-1$
butDelete.setToolTipText(Messages.getString("BookmarksManager.Delete.Tip")); //$NON-NLS-1$
butEdit.setToolTipText(Messages.getString("BookmarksManager.Edit.Tip")); //$NON-NLS-1$

JPanel top = new JPanel(new GridLayout(3, 2, 0, 5));
top.add(msg);
Expand All @@ -178,7 +181,7 @@ private BookmarksManager() {
left1.add(left3);

JPanel left2 = new JPanel(new GridLayout(0, 1, 0, 0));
left2.add(butRename);
left2.add(butEdit);
left2.add(butDelete);

JPanel left = new JPanel(new BorderLayout());
Expand Down Expand Up @@ -211,7 +214,7 @@ private BookmarksManager() {
butAdd.addActionListener(this);
butUpdateComment.addActionListener(this);
butRemove.addActionListener(this);
butRename.addActionListener(this);
butEdit.addActionListener(this);
butNew.addActionListener(this);
butDelete.addActionListener(this);

Expand Down Expand Up @@ -408,15 +411,15 @@ private void includeDuplicates(ArrayList<IItemId> uniqueSelectedIds) {
@Override
public void actionPerformed(final ActionEvent evt) {
if (evt.getSource() == butAdd || evt.getSource() == butRemove || evt.getSource() == butUpdateComment
|| evt.getSource() == butRename || evt.getSource() == butDelete) {
|| evt.getSource() == butEdit || evt.getSource() == butDelete) {
// Check if there is at least one bookmark selected
if (list.getSelectedIndex() == -1) {
showMessage(Messages.getString("BookmarksManager.AlertNoSelectedBookmarks"));
return;
}
}

if (evt.getSource() == butUpdateComment || evt.getSource() == butRename) {
if (evt.getSource() == butUpdateComment || evt.getSource() == butEdit) {
// Check if there is more than one bookmark selected
if (list.getSelectedIndices().length > 1) {
showMessage(Messages.getString("BookmarksManager.AlertMultipleSelectedBookmarks"));
Expand Down Expand Up @@ -475,21 +478,36 @@ public void actionPerformed(final ActionEvent evt) {

}

} else if (evt.getSource() == butRename) {
String newBookmark = JOptionPane.showInputDialog(dialog, Messages.getString("BookmarksManager.NewName"), //$NON-NLS-1$
list.getSelectedValue().getName());
if (newBookmark != null && !newBookmark.trim().isEmpty()) {
newBookmark = newBookmark.trim();
int selIdx = list.getSelectedIndex();
String bookmark = list.getModel().getElementAt(selIdx).getName();
if (!bookmark.equalsIgnoreCase(newBookmark) && listModel.contains(new BookmarkAndKey(newBookmark))) {
JOptionPane.showMessageDialog(dialog, Messages.getString("BookmarksManager.AlreadyExists"));
return;
} else if (evt.getSource() == butEdit) {
String currentName = list.getSelectedValue().getName();
Color currentColor = multiBookmarks.getBookmarkColor(currentName);
BookmarkEditDialog editDialog = new BookmarkEditDialog(dialog, currentName, currentColor);
editDialog.setVisible(true);

boolean changed = false;
String newName = editDialog.getNewName();
if (newName != null) {
if (!newName.isEmpty() && !newName.equals(currentName)) {
if (!currentName.equalsIgnoreCase(newName) && listModel.contains(new BookmarkAndKey(newName))) {
JOptionPane.showMessageDialog(dialog, Messages.getString("BookmarksManager.AlreadyExists"));
} else {
multiBookmarks.renameBookmark(currentName, newName);
updateList(currentName, newName);
currentName = newName;
changed = true;
}
}
multiBookmarks.renameBookmark(bookmark, newBookmark);
updateList(bookmark, newBookmark);
}
Color newColor = editDialog.getNewColor();
if (newColor != null && !newColor.equals(currentColor)) {
multiBookmarks.setBookmarkColor(currentName, newColor);
changed = true;
}

if (changed) {
multiBookmarks.saveState();
BookmarksController.get().updateUI();
list.repaint();
}
}

Expand Down
152 changes: 152 additions & 0 deletions iped-app/src/main/java/iped/app/ui/bookmarks/BookmarkEditDialog.java
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;
}
}
Loading

0 comments on commit 31c19d3

Please sign in to comment.