Changeset 2311 in josm for trunk/src/org


Ignore:
Timestamp:
2009-10-25T12:55:53+01:00 (15 years ago)
Author:
stoecker
Message:

applied #3771 - patch by bastiK - improve link display in relation handling

Location:
trunk/src/org/openstreetmap/josm/gui/dialogs/relation
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableLinkedCellRenderer.java

    r2298 r2311  
    22package org.openstreetmap.josm.gui.dialogs.relation;
    33
     4import static org.openstreetmap.josm.tools.I18n.tr;
     5
     6import java.awt.Color;
    47import java.awt.Component;
     8import java.awt.Graphics;
     9import java.awt.Image;
    510
    611import javax.swing.JTable;
    712
     13import org.openstreetmap.josm.tools.ImageProvider;
     14
    815public 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();
    920
    1021    @Override
     
    1223            int row, int column) {
    1324        reset();
    14 
     25        this.value = (WayConnectionType) value;
    1526        renderForeground(isSelected);
    16         setText(value.toString());
     27        //setText(value.toString());
    1728        setToolTipText(((WayConnectionType)value).getToolTip());
    1829        renderBackground(getModel(table), null, isSelected);
    1930        return this;
    2031    }
     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    }
    2183}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java

    r2298 r2311  
    9292            return members.get(rowIndex).getMember();
    9393        case 2:
    94             return linked(rowIndex);
     94            return wayConnection(rowIndex);
    9595        }
    9696        // should not happen
     
    682682    // no recursion and no forward/backward support
    683683    // 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) {
    685689        // this method is aimed at finding out whether the
    686690        // 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;
    693694        RelationMember m1 = members.get(i);
    694695        RelationMember m2 = members.get((i + 1) % members.size());
     
    708709            Node way2last = way2.lastNode();
    709710            if (way1first != null && way2first != null && (way1first == way2first)) {
    710                 link = WayConnectionType.tail_to_tail;
     711                link = -1;
    711712            } else if (way1first != null && way2last != null && (way1first == way2last)) {
    712                 link = WayConnectionType.tail_to_head;
     713                link = 1;
    713714            } else if (way1last != null && way2first != null && (way1last == way2first)) {
    714                 link = WayConnectionType.head_to_tail;
     715                link = 1;
    715716            } else if (way1last != null && way2last != null && (way1last == way2last)) {
    716                 link = WayConnectionType.head_to_head;
     717                link = -1;
    717718            }
    718719        }
     
    720721        return link;
    721722    }
     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    }
    722750}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/WayConnectionType.java

    r2298 r2311  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    6 public enum WayConnectionType {
     6public class WayConnectionType {
    77
    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;
    1314
    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;
    2020    }
    2121
    22     @Override
    23     public String toString() {
    24         return textSymbol;
     22    public WayConnectionType() {
     23        connectedToPrevious = false;
     24        connectedToNext = false;
     25        direction = 1;
     26        invalid = true;
    2527    }
    2628
     29//    @Override
     30//    public String toString() {
     31//        return ...
     32//    }
     33
    2734    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        }
    2950    }
    3051}
Note: See TracChangeset for help on using the changeset viewer.