source: josm/trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableLinkedCellRenderer.java@ 2990

Last change on this file since 2990 was 2990, checked in by jttt, 14 years ago

Fix some eclipse warnings

File size: 4.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.dialogs.relation;
3
4import java.awt.Color;
5import java.awt.Component;
6import java.awt.Graphics;
7import java.awt.Image;
8
9import javax.swing.JTable;
10
11import org.openstreetmap.josm.gui.dialogs.relation.WayConnectionType.Direction;
12import org.openstreetmap.josm.tools.ImageProvider;
13
14public class MemberTableLinkedCellRenderer extends MemberTableCellRenderer {
15
16 final static Image arrowUp = ImageProvider.get("dialogs/relation", "arrowup").getImage();
17 final static Image arrowDown = ImageProvider.get("dialogs/relation", "arrowdown").getImage();
18 final static Image corners = ImageProvider.get("dialogs/relation", "roundedcorners").getImage();
19 final static Image roundabout_right = ImageProvider.get("dialogs/relation", "roundabout_right_tiny").getImage();
20 final static Image roundabout_left = ImageProvider.get("dialogs/relation", "roundabout_left_tiny").getImage();
21 private WayConnectionType value = new WayConnectionType();
22
23 @Override
24 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
25 int row, int column) {
26 reset();
27 this.value = (WayConnectionType) value;
28 renderForeground(isSelected);
29 //setText(value.toString());
30 setToolTipText(((WayConnectionType)value).getToolTip());
31 renderBackground(getModel(table), null, isSelected);
32 return this;
33 }
34
35 @Override
36 public void paintComponent(Graphics g) {
37 super.paintComponent(g);
38 if (value == null || !value.isValid())
39 return;
40
41 int ymax=this.getSize().height - 1;
42 int xloop = 8;
43 int xoff = this.getSize().width / 2;
44 if (value.isLoop) {
45 xoff -= xloop / 2 - 1;
46 }
47 int w = 2;
48 int p = 2 + w + 1;
49 int y1 = 0;
50 int y2 = 0;
51
52 if (value.linkPrev) {
53 g.setColor(Color.black);
54 g.fillRect(xoff - 1, 0, 3, 1);
55 y1 = 0;
56 } else {
57 if (value.isLoop) {
58 g.setColor(Color.black);
59 y1 = 5;
60 g.drawImage(corners,xoff,y1-3,xoff+3,y1, 0,0,3,3, new Color(0,0,0,0), null);
61 g.drawImage(corners,xoff+xloop-2,y1-3,xoff+xloop+1,y1, 2,0,5,3, new Color(0,0,0,0), null);
62 g.drawLine(xoff+3,y1-3,xoff+xloop-3,y1-3);
63 }
64 else {
65 g.setColor(Color.red);
66 g.drawRect(xoff-1, p - 1 - w, w, w);
67 y1 = p;
68 }
69 }
70
71 if (value.linkNext) {
72 g.setColor(Color.black);
73 g.fillRect(xoff - 1, ymax, 3, 1);
74 y2 = ymax;
75 } else {
76 if (value.isLoop) {
77 g.setColor(Color.black);
78 y2 = ymax - 5;
79 g.fillRect(xoff-1, y2+2, 3, 3);
80 g.drawLine(xoff, y2, xoff, y2+2);
81 g.drawImage(corners,xoff+xloop-2,y2+1,xoff+xloop+1,y2+4, 2,2,5,5, new Color(0,0,0,0), null);
82 g.drawLine(xoff+3-1,y2+3,xoff+xloop-3,y2+3);
83 }
84 else {
85 g.setColor(Color.red);
86 g.drawRect(xoff-1, ymax - p + 1, w, w);
87 y2 = ymax - p;
88 }
89 }
90
91 /* vertical lines */
92 g.setColor(Color.black);
93 g.drawLine(xoff, y1, xoff, y2);
94 if (value.isLoop) {
95 g.drawLine(xoff+xloop, y1, xoff+xloop, y2);
96 }
97
98 /* special icons */
99 Image arrow = null;
100 switch (value.direction) {
101 case FORWARD:
102 arrow = arrowDown;
103 break;
104 case BACKWARD:
105 arrow = arrowUp;
106 break;
107 }
108 if ((arrow != null) && (value.linkPrev || value.linkNext)) {
109 g.drawImage(arrow, xoff-3, (y1 + y2) / 2 - 2, null);
110 }
111 else if (value.direction == Direction.ROUNDABOUT_LEFT) {
112 g.drawImage(roundabout_left, xoff-6, 1, null);
113 } else if (value.direction == Direction.ROUNDABOUT_RIGHT) {
114 g.drawImage(roundabout_right, xoff-6, 1, null);
115 }
116 }
117}
Note: See TracBrowser for help on using the repository browser.