mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 19:42:36 +02:00
File Choosers - fixed list rendering bug (clipping and color
alternation)
This commit is contained in:
parent
26b2dfef94
commit
538cbc1226
4 changed files with 50 additions and 35 deletions
|
@ -101,6 +101,7 @@ public abstract class AbstractGCellRenderer extends GDHtmlLabel {
|
||||||
*
|
*
|
||||||
* @param parent The parent being rendered -- likely a list or table.
|
* @param parent The parent being rendered -- likely a list or table.
|
||||||
* @param row The row being rendered.
|
* @param row The row being rendered.
|
||||||
|
* @return the color
|
||||||
*/
|
*/
|
||||||
protected Color getOSDependentBackgroundColor(JComponent parent, int row) {
|
protected Color getOSDependentBackgroundColor(JComponent parent, int row) {
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ class DirectoryList extends GList<File> implements GhidraFileChooserDirectoryMod
|
||||||
private GhidraFileChooser chooser;
|
private GhidraFileChooser chooser;
|
||||||
private DirectoryListModel model;
|
private DirectoryListModel model;
|
||||||
private JLabel listEditorLabel;
|
private JLabel listEditorLabel;
|
||||||
private JTextField listEditorText;
|
private JTextField listEditorField;
|
||||||
private JPanel listEditor;
|
private JPanel listEditor;
|
||||||
|
|
||||||
/** The file being edited */
|
/** The file being edited */
|
||||||
|
@ -50,6 +50,7 @@ class DirectoryList extends GList<File> implements GhidraFileChooserDirectoryMod
|
||||||
}
|
}
|
||||||
|
|
||||||
private void build() {
|
private void build() {
|
||||||
|
|
||||||
setLayoutOrientation(JList.VERTICAL_WRAP);
|
setLayoutOrientation(JList.VERTICAL_WRAP);
|
||||||
setCellRenderer(new FileListCellRenderer(chooser));
|
setCellRenderer(new FileListCellRenderer(chooser));
|
||||||
|
|
||||||
|
@ -137,9 +138,9 @@ class DirectoryList extends GList<File> implements GhidraFileChooserDirectoryMod
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
listEditorText = new JTextField();
|
listEditorField = new JTextField();
|
||||||
listEditorText.setName("LIST_EDITOR_FIELD");
|
listEditorField.setName("LIST_EDITOR_FIELD");
|
||||||
listEditorText.addKeyListener(new KeyAdapter() {
|
listEditorField.addKeyListener(new KeyAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void keyPressed(KeyEvent e) {
|
public void keyPressed(KeyEvent e) {
|
||||||
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
|
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
|
||||||
|
@ -161,7 +162,7 @@ class DirectoryList extends GList<File> implements GhidraFileChooserDirectoryMod
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
listEditorText.addFocusListener(new FocusAdapter() {
|
listEditorField.addFocusListener(new FocusAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void focusLost(FocusEvent e) {
|
public void focusLost(FocusEvent e) {
|
||||||
// Tracker SCR 3358 - Keep changes on focus lost
|
// Tracker SCR 3358 - Keep changes on focus lost
|
||||||
|
@ -173,10 +174,10 @@ class DirectoryList extends GList<File> implements GhidraFileChooserDirectoryMod
|
||||||
listEditor.setBorder(BorderFactory.createLineBorder(Color.GRAY));
|
listEditor.setBorder(BorderFactory.createLineBorder(Color.GRAY));
|
||||||
|
|
||||||
listEditor.add(listEditorLabel, BorderLayout.WEST);
|
listEditor.add(listEditorLabel, BorderLayout.WEST);
|
||||||
listEditor.add(listEditorText, BorderLayout.CENTER);
|
listEditor.add(listEditorField, BorderLayout.CENTER);
|
||||||
|
|
||||||
listEditor.setBackground(Color.WHITE);
|
listEditor.setBackground(Color.WHITE);
|
||||||
listEditorText.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
|
listEditorField.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
|
||||||
|
|
||||||
add(listEditor);
|
add(listEditor);
|
||||||
}
|
}
|
||||||
|
@ -280,6 +281,36 @@ class DirectoryList extends GList<File> implements GhidraFileChooserDirectoryMod
|
||||||
setSelectedIndices(indices);
|
setSelectedIndices(indices);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// overridden to account for the renderers insets, to avoid clipping
|
||||||
|
@Override
|
||||||
|
public void setFixedCellWidth(int width) {
|
||||||
|
|
||||||
|
int fullWidth = width;
|
||||||
|
ListCellRenderer<? super File> renderer = getCellRenderer();
|
||||||
|
if (renderer instanceof JComponent) {
|
||||||
|
JComponent c = (JComponent) renderer;
|
||||||
|
Insets insets = c.getInsets();
|
||||||
|
fullWidth += insets.left + insets.right;
|
||||||
|
}
|
||||||
|
|
||||||
|
super.setFixedCellWidth(fullWidth);
|
||||||
|
}
|
||||||
|
|
||||||
|
// overridden to account for the renderers insets, to avoid clipping
|
||||||
|
@Override
|
||||||
|
public void setFixedCellHeight(int height) {
|
||||||
|
|
||||||
|
int fullHeight = height;
|
||||||
|
ListCellRenderer<? super File> renderer = getCellRenderer();
|
||||||
|
if (renderer instanceof JComponent) {
|
||||||
|
JComponent c = (JComponent) renderer;
|
||||||
|
Insets insets = c.getInsets();
|
||||||
|
fullHeight += insets.top + insets.bottom;
|
||||||
|
}
|
||||||
|
|
||||||
|
super.setFixedCellHeight(fullHeight);
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isEditing() {
|
private boolean isEditing() {
|
||||||
return (editedFile != null);
|
return (editedFile != null);
|
||||||
}
|
}
|
||||||
|
@ -299,9 +330,9 @@ class DirectoryList extends GList<File> implements GhidraFileChooserDirectoryMod
|
||||||
listEditor.setBounds(r.x, r.y, r.width, r.height);
|
listEditor.setBounds(r.x, r.y, r.width, r.height);
|
||||||
listEditor.setVisible(true);
|
listEditor.setVisible(true);
|
||||||
listEditorLabel.setIcon(chooser.getModel().getIcon(editedFile));
|
listEditorLabel.setIcon(chooser.getModel().getIcon(editedFile));
|
||||||
listEditorText.setText(editedFile.getName());
|
listEditorField.setText(editedFile.getName());
|
||||||
listEditorText.requestFocus();
|
listEditorField.requestFocus();
|
||||||
listEditorText.selectAll();
|
listEditorField.selectAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
void cancelListEdit() {
|
void cancelListEdit() {
|
||||||
|
@ -309,7 +340,7 @@ class DirectoryList extends GList<File> implements GhidraFileChooserDirectoryMod
|
||||||
remove(listEditor);
|
remove(listEditor);
|
||||||
listEditor.setVisible(false);
|
listEditor.setVisible(false);
|
||||||
listEditorLabel.setIcon(null);
|
listEditorLabel.setIcon(null);
|
||||||
listEditorText.setText("");
|
listEditorField.setText("");
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,7 +355,7 @@ class DirectoryList extends GList<File> implements GhidraFileChooserDirectoryMod
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
throw new AssertException("Somehow editing file not in our model.");
|
throw new AssertException("Somehow editing file not in our model.");
|
||||||
}
|
}
|
||||||
File dest = new File(editedFileCopy.getParentFile(), listEditorText.getText());
|
File dest = new File(editedFileCopy.getParentFile(), listEditorField.getText());
|
||||||
cancelListEdit();
|
cancelListEdit();
|
||||||
if (chooser.getModel().renameFile(editedFileCopy, dest)) {
|
if (chooser.getModel().renameFile(editedFileCopy, dest)) {
|
||||||
model.set(index, dest);
|
model.set(index, dest);
|
||||||
|
@ -337,6 +368,6 @@ class DirectoryList extends GList<File> implements GhidraFileChooserDirectoryMod
|
||||||
}
|
}
|
||||||
|
|
||||||
/*junit*/ JTextField getListEditorText() {
|
/*junit*/ JTextField getListEditorText() {
|
||||||
return listEditorText;
|
return listEditorField;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,6 @@ package docking.widgets.list;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.event.ListSelectionEvent;
|
|
||||||
import javax.swing.event.ListSelectionListener;
|
|
||||||
|
|
||||||
import docking.widgets.GComponent;
|
import docking.widgets.GComponent;
|
||||||
import docking.widgets.table.GTable;
|
import docking.widgets.table.GTable;
|
||||||
|
@ -33,9 +31,9 @@ import docking.widgets.table.GTable;
|
||||||
* HTML rendering is disabled by default.
|
* HTML rendering is disabled by default.
|
||||||
* <p>
|
* <p>
|
||||||
*
|
*
|
||||||
|
* @param <T> the row type of the list
|
||||||
*/
|
*/
|
||||||
public class GList<T> extends JList<T> implements GComponent {
|
public class GList<T> extends JList<T> implements GComponent {
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
/**The timeout for the auto-lookup feature*/
|
/**The timeout for the auto-lookup feature*/
|
||||||
public static final long KEY_TIMEOUT = GTable.KEY_TIMEOUT;//made public for JUnits...
|
public static final long KEY_TIMEOUT = GTable.KEY_TIMEOUT;//made public for JUnits...
|
||||||
|
@ -87,24 +85,6 @@ public class GList<T> extends JList<T> implements GComponent {
|
||||||
if (getCellRenderer() instanceof JComponent) {
|
if (getCellRenderer() instanceof JComponent) {
|
||||||
GComponent.setHTMLRenderingFlag((JComponent) getCellRenderer(), false);
|
GComponent.setHTMLRenderingFlag((JComponent) getCellRenderer(), false);
|
||||||
}
|
}
|
||||||
addListSelectionListener(new ListSelectionListener() {
|
addListSelectionListener(e -> ensureIndexIsVisible(getSelectedIndex()));
|
||||||
@Override
|
|
||||||
public void valueChanged(ListSelectionEvent e) {
|
|
||||||
ensureIndexIsVisible(getSelectedIndex());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Turns off the HTML rendering in the specified component and its current cell renderer.
|
|
||||||
// *
|
|
||||||
// * @param list the list
|
|
||||||
// */
|
|
||||||
// public static void turnOffHTMLRendering(JList<?> list) {
|
|
||||||
// turnOffHTMLRendering((JComponent) list);
|
|
||||||
// if (list.getCellRenderer() instanceof JComponent) {
|
|
||||||
// turnOffHTMLRendering((JComponent) list.getCellRenderer());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,9 @@ public class GListCellRenderer<E> extends AbstractGCellRenderer implements ListC
|
||||||
* Constructs a new GListCellRenderer.
|
* Constructs a new GListCellRenderer.
|
||||||
*/
|
*/
|
||||||
public GListCellRenderer() {
|
public GListCellRenderer() {
|
||||||
|
|
||||||
|
// lists don't need alternation for rows, as they don't use long columnar data
|
||||||
|
setShouldAlternateRowBackgroundColors(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue