- Timestamp:
- 2009-10-25T12:55:53+01:00 (15 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableLinkedCellRenderer.java
r2298 r2311 2 2 package org.openstreetmap.josm.gui.dialogs.relation; 3 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import java.awt.Color; 4 7 import java.awt.Component; 8 import java.awt.Graphics; 9 import java.awt.Image; 5 10 6 11 import javax.swing.JTable; 7 12 13 import org.openstreetmap.josm.tools.ImageProvider; 14 8 15 public class MemberTableLinkedCellRenderer extends MemberTableCellRenderer { 16 17 final static Image arrowUp = ImageProvider.get("dialogs", "arrowup").getImage(); 18 final static Image arrowDown = ImageProvider.get("dialogs", "arrowdown").getImage(); 19 private WayConnectionType value = new WayConnectionType(); 9 20 10 21 @Override … … 12 23 int row, int column) { 13 24 reset(); 14 25 this.value = (WayConnectionType) value; 15 26 renderForeground(isSelected); 16 setText(value.toString()); 27 //setText(value.toString()); 17 28 setToolTipText(((WayConnectionType)value).getToolTip()); 18 29 renderBackground(getModel(table), null, isSelected); 19 30 return this; 20 31 } 32 33 @Override 34 public void paintComponent(Graphics g) { 35 super.paintComponent(g); 36 if (value == null || value.invalid) { 37 return; 38 } 39 40 Image image = null; 41 switch (value.direction) { 42 case 1: 43 image = arrowDown; 44 break; 45 case -1: 46 image = arrowUp; 47 break; 48 } 49 50 int ymax=this.getSize().height - 1; 51 int xoff = this.getSize().width / 2; 52 int w = 2; 53 int p = 2 + w + 1; 54 int y1 = 0; 55 int y2 = 0; 56 57 if (image != null && (value.connectedToPrevious || value.connectedToNext)) { 58 g.drawImage(image, xoff-3, ymax / 2 - 2, null); 59 } 60 61 if (value.connectedToPrevious) { 62 g.setColor(Color.black); 63 g.fillRect(xoff - 2, 0, 5, 2); 64 y1 = 0; 65 } else { 66 g.setColor(Color.red); 67 g.drawRect(xoff-1, p - 1 - w, w, w); 68 y1 = p; 69 } 70 71 if (value.connectedToNext) { 72 g.setColor(Color.black); 73 g.fillRect(xoff - 2, ymax - 1, 5, 2); 74 y2 = ymax; 75 } else { 76 g.setColor(Color.red); 77 g.drawRect(xoff-1, ymax - p + 1, w, w); 78 y2 = ymax - p; 79 } 80 g.setColor(Color.black); 81 g.drawLine(xoff, y1, xoff, y2); 82 } 21 83 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java
r2298 r2311 92 92 return members.get(rowIndex).getMember(); 93 93 case 2: 94 return linked(rowIndex);94 return wayConnection(rowIndex); 95 95 } 96 96 // should not happen … … 682 682 // no recursion and no forward/backward support 683 683 // TODO: add back the number of linked elements 684 private WayConnectionType linked(int i) { 684 // Returns +1 if member i and (i+1) are ways and could be combined without changing 685 // the direction of one of them. If they are linked "head to head" or "tail to tail" 686 // -1 is returned. 687 // In all other cases the result is null. 688 private Integer linked(int i) { 685 689 // this method is aimed at finding out whether the 686 690 // relation member is "linked" with the next, i.e. whether 687 // (if both are ways) these ways are connected. It should 688 // really produce a much more beautiful output (with a linkage 689 // symbol somehow placed between the two member lines!), 690 // so... FIXME ;-) 691 692 WayConnectionType link = WayConnectionType.none; 691 // (if both are ways) these ways are connected. 692 693 Integer link = null; 693 694 RelationMember m1 = members.get(i); 694 695 RelationMember m2 = members.get((i + 1) % members.size()); … … 708 709 Node way2last = way2.lastNode(); 709 710 if (way1first != null && way2first != null && (way1first == way2first)) { 710 link = WayConnectionType.tail_to_tail;711 link = -1; 711 712 } else if (way1first != null && way2last != null && (way1first == way2last)) { 712 link = WayConnectionType.tail_to_head;713 link = 1; 713 714 } else if (way1last != null && way2first != null && (way1last == way2first)) { 714 link = WayConnectionType.head_to_tail;715 link = 1; 715 716 } else if (way1last != null && way2last != null && (way1last == way2last)) { 716 link = WayConnectionType.head_to_head;717 link = -1; 717 718 } 718 719 } … … 720 721 return link; 721 722 } 723 724 private WayConnectionType wayConnection(int i) { 725 RelationMember m = members.get(i); 726 if (! m.isWay()) { 727 return new WayConnectionType(); 728 } 729 Way w = m.getWay(); 730 if (w == null || w.incomplete) { 731 return new WayConnectionType(); 732 } 733 734 int ip = (i - 1 + members.size()) % members.size(); 735 Integer link_p = linked(ip); 736 Integer link_n = linked(i); 737 Integer dir = 1; 738 // FIXME: It is somewhat stupid to loop here, but 739 // there shouldn't be a performance problem in practice. 740 for (int k = i - 1; k >= 0; --k) { 741 Integer link = linked(k); 742 if (link != null) { 743 dir *= link; 744 } else { 745 break; 746 } 747 } 748 return new WayConnectionType(link_p != null, link_n != null, dir); 749 } 722 750 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/WayConnectionType.java
r2298 r2311 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 public enumWayConnectionType {6 public class WayConnectionType { 7 7 8 none("", tr("Not connected")), 9 head_to_head("-><-", tr("Last points of ways are connected")), 10 tail_to_tail("<-->", tr("First points of ways are connected")), 11 head_to_tail("->->", tr("First point of second way connects to last point of first way")), 12 tail_to_head("<-<-", tr("First point of first way connects to last point of second way")); 8 public final boolean connectedToPrevious; 9 public final boolean connectedToNext; 10 /** Is 1 if way has the same direction as the first way in the set of connected ways. Else it is (-1) */ 11 public final int direction; 12 /** The WayConnectionType is invalid, if the corresponding primitive is not a way or the way is incomplete */ 13 public final boolean invalid; 13 14 14 private String textSymbol; 15 private String toolTip; 16 17 WayConnectionType(String textSymbol, String toolTip) { 18 this.textSymbol = textSymbol; 19 this.toolTip = toolTip; 15 public WayConnectionType(boolean connectedToPrevious, boolean connectedToNext, int direction) { 16 this.connectedToPrevious = connectedToPrevious; 17 this.connectedToNext = connectedToNext; 18 this.direction = direction; 19 invalid = false; 20 20 } 21 21 22 @Override 23 public String toString() { 24 return textSymbol; 22 public WayConnectionType() { 23 connectedToPrevious = false; 24 connectedToNext = false; 25 direction = 1; 26 invalid = true; 25 27 } 26 28 29 // @Override 30 // public String toString() { 31 // return ... 32 // } 33 27 34 public String getToolTip() { 28 return toolTip; 35 if (invalid) { 36 return ""; 37 } 38 else if (connectedToPrevious && connectedToNext) { 39 return tr("way is connected"); 40 } 41 else if (connectedToPrevious) { 42 return tr("way is connected to previous relation member"); 43 } 44 else if (connectedToNext) { 45 return tr("way is connected to next relation member"); 46 } 47 else { 48 return tr("way is not connected to previous or next relation member"); 49 } 29 50 } 30 51 }
Note:
See TracChangeset
for help on using the changeset viewer.