Ignore:
Timestamp:
2011-03-24T14:52:57+01:00 (14 years ago)
Author:
zverik
Message:

final stretch for beta

Location:
applications/editors/josm/plugins/relcontext/src/relcontext
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/relcontext/src/relcontext/ChosenRelationComponent.java

    r25685 r25688  
    11package relcontext;
    22
     3import java.awt.Color;
    34import javax.swing.JLabel;
     5import javax.swing.border.BevelBorder;
     6import javax.swing.border.LineBorder;
    47import org.openstreetmap.josm.data.osm.Relation;
    58
     
    1720    public ChosenRelationComponent(ChosenRelation rel) {
    1821        super("");
     22/*        setBackground(Color.white);
     23        setOpaque(true);
     24        setBorder(new LineBorder(Color.black, 1, true));*/
    1925        this.chRel = rel;
    2026        rel.addChosenRelationListener(this);
  • applications/editors/josm/plugins/relcontext/src/relcontext/RelContextDialog.java

    r25685 r25688  
    11package relcontext;
    22
     3import java.awt.Component;
    34import java.awt.Dimension;
    45import org.openstreetmap.josm.tools.ImageProvider;
     
    1415
    1516import java.awt.BorderLayout;
     17import java.awt.Color;
    1618import java.awt.Dialog.ModalityType;
    17 import java.awt.FlowLayout;
    1819import java.awt.GridBagLayout;
    1920import java.beans.PropertyChangeEvent;
    2021import java.beans.PropertyChangeListener;
    2122import javax.swing.event.ListSelectionListener;
     23import javax.swing.table.DefaultTableCellRenderer;
    2224
    2325import org.openstreetmap.josm.Main;
     
    3739import org.openstreetmap.josm.tools.GBC;
    3840import org.openstreetmap.josm.command.ChangeCommand;
    39 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    4041import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingComboBox;
    4142import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem;
     
    5859
    5960    public RelContextDialog() {
    60         super(tr("Advanced Relation Editor"), "icon_relcontext",
    61                 tr("Opens advanced relation/multipolygon editor panel"),
    62                 Shortcut.registerShortcut("view:relcontext", tr("Toggle: {0}", tr("Open Relation Editor")),
     61        super(tr("Relation Toolbox"), "reltoolbox",
     62                tr("Open relation/multipolygon editor panel"),
     63                Shortcut.registerShortcut("subwindow:reltoolbox", tr("Toggle: {0}", tr("Relation Toolbox")),
    6364                KeyEvent.VK_R, Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 150, true);
    64 
    65         // todo: shrink all panels to ~20 pixels
    6665
    6766        JPanel rcPanel = new JPanel(new BorderLayout());
     
    166165    }
    167166
     167    private static final Color CHOSEN_RELATION_COLOR = new Color(255, 255, 128);
     168
    168169    private void configureRelationsTable( final JTable relationsTable ) {
    169170        relationsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
     
    174175            protected String getComponentToolTipText( OsmPrimitive value ) {
    175176                return null;
     177            }
     178
     179            @Override
     180            public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column ) {
     181                Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
     182                if( !isSelected && value instanceof Relation && chosenRelation.get() != null && value.equals(chosenRelation.get()) )
     183                    c.setBackground(CHOSEN_RELATION_COLOR);
     184                else
     185                    c.setBackground(table.getBackground());
     186                return c;
     187            }
     188
     189        });
     190        columns.getColumn(1).setCellRenderer(new DefaultTableCellRenderer() {
     191            @Override
     192            public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column ) {
     193                Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
     194                if( !isSelected && chosenRelation.get() != null && table.getValueAt(row, 0).equals(chosenRelation.get()) )
     195                    c.setBackground(CHOSEN_RELATION_COLOR);
     196                else
     197                    c.setBackground(table.getBackground());
     198                return c;
    176199            }
    177200        });
     
    307330        possibleRoles.put("tunnel", new String[] {"through", "outline", "edge"});
    308331        possibleRoles.put("surveillance", new String[] {"camera", "extent", "visible", "hidden"});
     332        possibleRoles.put("street", new String[] {"street", "address", "house", "associated"});
     333        possibleRoles.put("collection", new String[] {"member", "street", "river", "railway", "address", "associated"});
    309334    }
    310335
     
    341366        final AutoCompletingComboBox role = new AutoCompletingComboBox();
    342367        List<AutoCompletionListItem> items = new ArrayList<AutoCompletionListItem>();
    343         for( int i = 0; i < roleBox.getModel().getSize(); i++ )
    344             items.add((AutoCompletionListItem)roleBox.getModel().getElementAt(i));
     368        for( int i = 0; i < roleBox.getModel().getSize(); i++ ) {
     369            final AutoCompletionListItem item = (AutoCompletionListItem)roleBox.getModel().getElementAt(i);
     370            if( item.getValue().length() > 1 )
     371                items.add(item);
     372        }
    345373        role.setPossibleACItems(items);
    346374        role.setEditable(true);
  • applications/editors/josm/plugins/relcontext/src/relcontext/actions/AddRemoveMemberAction.java

    r25682 r25688  
    88import org.openstreetmap.josm.actions.JosmAction;
    99import org.openstreetmap.josm.command.ChangeCommand;
     10import org.openstreetmap.josm.data.osm.Node;
     11import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    1012import org.openstreetmap.josm.data.osm.Relation;
    1113import org.openstreetmap.josm.data.osm.RelationMember;
     14import org.openstreetmap.josm.data.osm.Way;
    1215import org.openstreetmap.josm.tools.ImageProvider;
    1316import relcontext.ChosenRelation;
     
    4750        // 2. add all new members
    4851        for( OsmPrimitive p : toAdd ) {
    49             r.addMember(new RelationMember("", p));
     52            int pos = -1; //p instanceof Way ? findAdjacentMember(p, r) : -1;
     53            if( pos < 0 )
     54                r.addMember(new RelationMember("", p));
     55            else
     56                r.addMember(pos, new RelationMember("", p));
    5057        }
    5158
    5259        if( !r.getMemberPrimitives().equals(rel.get().getMemberPrimitives()) )
    5360            Main.main.undoRedo.add(new ChangeCommand(rel.get(), r));
     61    }
     62
     63    /**
     64     * Finds two relation members between which to place given way. Incomplete.
     65     * @see org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel#determineDirection
     66     */
     67    protected int findAdjacentMember( Way w, Relation r ) {
     68        Node firstNode = w.firstNode();
     69        Node lastNode = w.lastNode();
     70
     71        if( firstNode != null && !firstNode.equals(lastNode) ) {
     72            for( int i = 0; i < r.getMembersCount(); i++ ) {
     73                if( r.getMember(i).getType().equals(OsmPrimitiveType.WAY) ) {
     74                    Way rw = (Way)r.getMember(i).getMember();
     75                    Node firstNodeR = rw.firstNode();
     76                    Node lastNodeR = rw.lastNode();
     77                    if( firstNode.equals(firstNodeR) || firstNode.equals(lastNodeR) || lastNode.equals(firstNodeR) || lastNode.equals(lastNodeR) )
     78                        return i + 1;
     79                }
     80            }
     81        }
     82        return -1;
    5483    }
    5584
  • applications/editors/josm/plugins/relcontext/src/relcontext/actions/CreateRelationAction.java

    r25682 r25688  
    7979    private static final List<String> RELATION_TYPES = Arrays.asList(new String[] {
    8080        "multipolygon", "boundary", "route", "site", "restriction", "associatedStreet", "public_transport",
    81         "street", "collection", "address", "enforcement", "destination_sign", "route_master", "junction", "site",
     81        "street", "collection", "address", "enforcement", "destination_sign", "route_master", "junction",
    8282        "waterway", "bridge", "tunnel", "surveillance"
    8383    });
  • applications/editors/josm/plugins/relcontext/src/relcontext/actions/SortAndFixAction.java

    r25682 r25688  
    88import org.openstreetmap.josm.Main;
    99import org.openstreetmap.josm.command.ChangeCommand;
    10 import org.openstreetmap.josm.command.Command;
    11 import org.openstreetmap.josm.command.SequenceCommand;
    1210import org.openstreetmap.josm.data.osm.*;
    1311import org.openstreetmap.josm.tools.ImageProvider;
     
    3129        if( rel.get() == null ) return;
    3230        Relation r = rel.get();
    33         List<Command> commands = new ArrayList<Command>();
     31        boolean fixed = false;
    3432        // todo: sort members
    3533        // todo: set roles for multipolygon members
    36         Relation fixed = fixMultipolygonRoles(rel.get());
    37         if( fixed != null ) {
    38             commands.add(new ChangeCommand(r, fixed));
    39             r = fixed;
     34        Relation rr = fixMultipolygonRoles(r);
     35        if( rr != null ) {
     36            r = rr;
     37            fixed = true;
    4038        }
    4139        // todo: set roles for boundary members
     40        rr= fixBoundaryRoles(r);
     41        if( rr != null ) {
     42            r = rr;
     43            fixed = true;
     44        }
    4245
    43         if( !commands.isEmpty() )
    44             Main.main.undoRedo.add(new SequenceCommand(tr("Sort and fix relation"), commands));
     46        if( fixed )
     47            Main.main.undoRedo.add(new ChangeCommand(rel.get(), r));
    4548    }
    4649
    4750    public void chosenRelationChanged( Relation oldRelation, Relation newRelation ) {
    48         setEnabled(newRelation != null && areMultipolygonTagsEmpty());
    49         // todo: enable when needs fixing (empty roles or not ordered members)
     51        setEnabled(newRelation != null && !isIncomplete(newRelation) && (areMultipolygonTagsEmpty() || areBoundaryTagsNotRight()));
    5052    }
    5153
     54    protected boolean isIncomplete( Relation r ) {
     55        if( r == null || r.isIncomplete() || r.isDeleted() )
     56            return true;
     57        for( RelationMember m : r.getMembers())
     58            if( m.getMember().isIncomplete() )
     59                return true;
     60        return false;
     61    }
     62
     63    /**
     64     * Check for ways that have roles different from "outer" and "inner".
     65     */
    5266    private boolean areMultipolygonTagsEmpty() {
    5367        Relation r = rel == null ? null : rel.get();
     
    5670        for( RelationMember m : r.getMembers() ) {
    5771            if( m.getType().equals(OsmPrimitiveType.WAY) && (m.getRole() == null || (!m.getRole().equals("outer") && !m.getRole().equals("inner"))) )
     72                return true;
     73        }
     74        return false;
     75    }
     76
     77    /**
     78     * Check for nodes and relations without needed roles.
     79     */
     80    private boolean areBoundaryTagsNotRight() {
     81        Relation r = rel == null ? null : rel.get();
     82        if( r == null || r.getMembersCount() == 0 || !r.hasKey("type") || !r.get("type").equals("boundary") )
     83            return false;
     84        for( RelationMember m : r.getMembers() ) {
     85            if( m.getType().equals(OsmPrimitiveType.RELATION) && (m.getRole() == null || !m.getRole().equals("subarea")) )
     86                return true;
     87            else if(m.getType().equals(OsmPrimitiveType.NODE) && (m.getRole() == null || (!m.getRole().equals("label") && !m.getRole().equals("admin_centre"))) )
    5888                return true;
    5989        }
     
    88118            if( m.getType().equals(OsmPrimitiveType.WAY) ) {
    89119                String role = null;
    90                 if( outerWays.contains(m.getMember()) )
     120                if( outerWays.contains((Way)m.getMember()) )
    91121                    role = "outer";
    92                 else if( innerWays.contains(m.getMember()) )
     122                else if( innerWays.contains((Way)m.getMember()) )
    93123                    role = "inner";
    94124                if( role != null && !role.equals(m.getRole()) ) {
     
    100130        return fixed ? r : null;
    101131    }
     132
     133    private Relation fixBoundaryRoles( Relation source ) {
     134        Relation r = new Relation(source);
     135        boolean fixed = false;
     136        for( int i = 0; i < r.getMembersCount(); i++ ) {
     137            RelationMember m = r.getMember(i);
     138            String role = null;
     139            if( m.getType().equals(OsmPrimitiveType.RELATION) )
     140                role = "subarea";
     141            else if( m.getType().equals(OsmPrimitiveType.NODE) ) {
     142                Node n = (Node)m.getMember();
     143                if( !n.isIncomplete() ) {
     144                    if( n.hasKey("place") )
     145                        role = "admin_centre";
     146                    else
     147                        role = "label";
     148                }
     149            }
     150            if( role != null && !role.equals(m.getRole()) ) {
     151                r.setMember(i, new RelationMember(role, m.getMember()));
     152                fixed = true;
     153            }
     154        }
     155        return fixed ? r : null;
     156    }
    102157}
Note: See TracChangeset for help on using the changeset viewer.