Changeset 10536 in josm
- Timestamp:
- 2016-07-16T21:01:47+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/imagery/CacheContentsPanel.java
r10462 r10536 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Color;7 import java.awt.Component;8 6 import java.awt.GridBagLayout; 9 7 import java.awt.event.ActionEvent; 10 import java.awt.event.ActionListener;11 8 import java.util.ArrayList; 12 9 import java.util.Collections; … … 21 18 22 19 import javax.swing.AbstractAction; 23 import javax.swing.AbstractCellEditor;24 import javax.swing.Action;25 import javax.swing.Icon;26 import javax.swing.JButton;27 20 import javax.swing.JLabel; 28 21 import javax.swing.JPanel; 29 22 import javax.swing.JScrollPane; 30 23 import javax.swing.JTable; 31 import javax.swing.UIManager;32 import javax.swing.border.LineBorder;33 24 import javax.swing.table.DefaultTableModel; 34 import javax.swing.table.TableCellEditor;35 import javax.swing.table.TableCellRenderer;36 25 import javax.swing.table.TableColumn; 37 26 import javax.swing.table.TableModel; … … 47 36 import org.openstreetmap.josm.gui.layer.WMTSLayer; 48 37 import org.openstreetmap.josm.gui.util.GuiHelper; 38 import org.openstreetmap.josm.gui.widgets.ButtonColumn; 49 39 import org.openstreetmap.josm.tools.GBC; 50 40 import org.openstreetmap.josm.tools.Pair; … … 59 49 public class CacheContentsPanel extends JPanel { 60 50 61 /**62 *63 * Class based on: http://www.camick.com/java/source/ButtonColumn.java64 * https://tips4java.wordpress.com/2009/07/12/table-button-column/65 *66 */67 private static final class ButtonColumn extends AbstractCellEditor implements TableCellRenderer, TableCellEditor, ActionListener {68 private final Action action;69 private final JButton renderButton;70 private final JButton editButton;71 private Object editorValue;72 73 private ButtonColumn() {74 this(null);75 }76 77 private ButtonColumn(Action action) {78 this.action = action;79 renderButton = new JButton();80 editButton = new JButton();81 editButton.setFocusPainted(false);82 editButton.addActionListener(this);83 editButton.setBorder(new LineBorder(Color.BLUE));84 }85 86 @Override87 public Object getCellEditorValue() {88 return editorValue;89 }90 91 @Override92 public void actionPerformed(ActionEvent e) {93 this.action.actionPerformed(e);94 }95 96 @Override97 public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {98 this.editorValue = value;99 if (value == null) {100 editButton.setText("");101 editButton.setIcon(null);102 } else if (value instanceof Icon) {103 editButton.setText("");104 editButton.setIcon((Icon) value);105 } else {106 editButton.setText(value.toString());107 editButton.setIcon(null);108 }109 this.editorValue = value;110 return editButton;111 }112 113 @Override114 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,115 boolean hasFocus, int row, int column) {116 if (isSelected) {117 renderButton.setForeground(table.getSelectionForeground());118 renderButton.setBackground(table.getSelectionBackground());119 } else {120 renderButton.setForeground(table.getForeground());121 renderButton.setBackground(UIManager.getColor("Button.background"));122 }123 124 renderButton.setFocusPainted(hasFocus);125 126 if (value == null) {127 renderButton.setText("");128 renderButton.setIcon(null);129 } else if (value instanceof Icon) {130 renderButton.setText("");131 renderButton.setIcon((Icon) value);132 } else {133 renderButton.setText(value.toString());134 renderButton.setIcon(null);135 }136 return renderButton;137 }138 139 }140 51 141 52 private final transient ExecutorService executor = … … 192 103 } 193 104 194 p rivatestatic String[][] getCacheStats(CacheAccess<String, BufferedImageCacheEntry> cache) {105 public static String[][] getCacheStats(CacheAccess<String, BufferedImageCacheEntry> cache) { 195 106 Set<String> keySet = cache.getCacheControl().getKeySet(); 196 107 Map<String, int[]> temp = new ConcurrentHashMap<>(); // use int[] as a Object reference to int, gives better performance
Note:
See TracChangeset
for help on using the changeset viewer.