Changeset 10072 in josm
- Timestamp:
- 2016-03-28T18:27:56+02:00 (9 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableMemberCellRenderer.java
r9867 r10072 15 15 */ 16 16 public class MemberTableMemberCellRenderer extends MemberTableCellRenderer { 17 18 /**19 * Constructs a new {@code MemberTableMemberCellRenderer}.20 */21 public MemberTableMemberCellRenderer() {22 super();23 }24 17 25 18 protected void renderPrimitive(OsmPrimitive primitive, Dimension cellSize) { -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/SelectionTableCellRenderer.java
r9867 r10072 3 3 4 4 import java.awt.Color; 5 import java.awt.Component;6 import java.awt.Dimension;7 5 8 import javax.swing.JLabel;9 6 import javax.swing.JTable; 10 7 import javax.swing.UIManager; … … 12 9 13 10 import org.openstreetmap.josm.data.osm.OsmPrimitive; 14 import org.openstreetmap.josm.gui.DefaultNameFormatter;15 11 import org.openstreetmap.josm.gui.util.GuiHelper; 16 import org.openstreetmap.josm.tools.ImageProvider;17 12 18 13 /** … … 20 15 * 21 16 */ 22 public class SelectionTableCellRenderer extends JLabel implements TableCellRenderer { 23 public static final Color BGCOLOR_DOUBLE_ENTRY = new Color(254, 226, 214); 24 public static final Color BGCOLOR_SINGLE_ENTRY = new Color(235, 255, 177); 17 public class SelectionTableCellRenderer extends MemberTableMemberCellRenderer { 18 public static final Color BGCOLOR_SINGLE_ENTRY = BGCOLOR_IN_JOSM_SELECTION; 25 19 26 20 /** 27 21 * reference to the member table model; required, in order to check whether a 28 * selected primitive is already used in the member list of the currently edited 29 * relation 22 * selected primitive is already used in the member list of the currently edited relation 30 23 */ 31 private MemberTableModel model;24 private final MemberTableModel model; 32 25 33 26 /** 34 27 * constructor 28 * @param model member table model 35 29 */ 36 public SelectionTableCellRenderer() { 37 setIcon(null); 38 setOpaque(true); 30 public SelectionTableCellRenderer(MemberTableModel model) { 31 this.model = model; 39 32 } 40 33 41 /** 42 * reset the renderer 43 */ 44 protected void reset() { 45 setBackground(UIManager.getColor("Table.background")); 46 setForeground(UIManager.getColor("Table.foreground")); 47 setBorder(null); 48 setIcon(null); 49 setToolTipText(null); 50 } 51 52 protected void renderBackground(OsmPrimitive primitive) { 34 @Override 35 protected void renderBackgroundForeground(MemberTableModel model, OsmPrimitive primitive, boolean isSelected) { 53 36 Color bgc = UIManager.getColor("Table.background"); 54 37 if (primitive != null && model != null && model.getNumMembersWithPrimitive(primitive) == 1) { … … 60 43 } 61 44 62 protected void renderPrimitive(OsmPrimitive primitive, Dimension cellSize) {63 int size = Math.min(cellSize.width, cellSize.height);64 setIcon(ImageProvider.getPadded(primitive, new Dimension(size, size)));65 setText(primitive.getDisplayName(DefaultNameFormatter.getInstance()));66 setToolTipText(DefaultNameFormatter.getInstance().buildDefaultToolTip(primitive));67 }68 69 45 @Override 70 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, 71 int row, int column) { 72 73 reset(); 74 if (value == null) 75 return this; 76 77 Dimension cellSize = table.getCellRect(row, column, false).getSize(); 78 79 renderBackground((OsmPrimitive) value); 80 renderPrimitive((OsmPrimitive) value, cellSize); 81 return this; 82 } 83 84 public void setMemberTableModel(MemberTableModel model) { 85 this.model = model; 46 protected MemberTableModel getModel(JTable table) { 47 return model; 86 48 } 87 49 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/SelectionTableColumnModel.java
r3083 r10072 10 10 public SelectionTableColumnModel(MemberTableModel model) { 11 11 TableColumn col = null; 12 SelectionTableCellRenderer renderer = new SelectionTableCellRenderer(); 13 renderer.setMemberTableModel(model); 12 SelectionTableCellRenderer renderer = new SelectionTableCellRenderer(model); 14 13 15 14 // column 0 - the member role -
trunk/test/unit/org/openstreetmap/josm/gui/dialogs/relation/SelectionTableCellRendererTest.java
r9907 r10072 30 30 public void testSelectionTableCellRenderer() { 31 31 MemberTableModel model = new MemberTableModel(null, null, null); 32 SelectionTableCellRenderer r = new SelectionTableCellRenderer(); 33 r.setMemberTableModel(model); 32 SelectionTableCellRenderer r = new SelectionTableCellRenderer(model); 34 33 assertEquals(r, r.getTableCellRendererComponent(null, null, false, false, 0, 0)); 35 34 assertEquals(r, r.getTableCellRendererComponent(new JTable(model), new Node(), false, false, 0, 0));
Note:
See TracChangeset
for help on using the changeset viewer.