Changeset 25667 in osm


Ignore:
Timestamp:
2011-03-22T15:53:58+01:00 (14 years ago)
Author:
zverik
Message:

current

Location:
applications/editors/josm/plugins/relcontext
Files:
6 added
7 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/relcontext/build.xml

    r25649 r25667  
    2828**
    2929-->
    30 <project name="myPluginName" default="dist" basedir=".">
     30<project name="RelContext" default="dist" basedir=".">
    3131
    3232    <!-- enter the SVN commit message -->
     
    4444    <property name="plugin.src.dir"         value="src"/>
    4545    <!-- this is the directory where the plugin jar is copied to -->
    46     <property name="plugin.dist.dir"        value="../../dist"/>
     46    <property name="plugin.dist.dir"        value="/Users/Zverik/AppData/Roaming/JOSM/plugins"/>
    4747    <property name="ant.build.javac.target" value="1.5"/>
    48     <property name="plugin.dist.dir"        value="../../dist"/>
    4948    <property name="plugin.jar"             value="${plugin.dist.dir}/${ant.project.name}.jar"/>
    5049
     
    7877    <target name="dist" depends="compile,revision">
    7978        <echo message="creating ${ant.project.name}.jar ... "/>
    80         <copy todir="${plugin.build.dir}/resources">
    81             <fileset dir="resources"/>
    82         </copy>
    8379        <copy todir="${plugin.build.dir}/images">
    8480            <fileset dir="images"/>
  • applications/editors/josm/plugins/relcontext/src/relcontext/ChosenRelation.java

    r25649 r25667  
    4141        chosenRelation = rel;
    4242        analyse();
     43        Main.map.mapView.repaint();
    4344        for( ChosenRelationListener listener : chosenRelationListeners ) {
    4445            listener.chosenRelationChanged(oldRel, chosenRelation);
     
    9293        g.setColor(Color.yellow);
    9394        g.setStroke(new BasicStroke(6, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    94         g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));
     95        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f));
    9596        for( OsmPrimitive element : chosenRelation.getMemberPrimitives() ) {
    9697            if( element.getType() == OsmPrimitiveType.NODE ) {
     
    105106                    b.moveTo(p.x, p.y);
    106107                    for( int i = 1; i < way.getNodesCount(); i++ ) {
    107                         p = mv.getPoint(way.getNode(1));
     108                        p = mv.getPoint(way.getNode(i));
    108109                        b.lineTo(p.x, p.y);
    109110                    }
  • applications/editors/josm/plugins/relcontext/src/relcontext/RelContextDialog.java

    r25649 r25667  
    22
    33import java.awt.event.MouseEvent;
     4import java.util.Collection;
    45import org.openstreetmap.josm.data.osm.OsmPrimitive;
     6import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    57import static org.openstreetmap.josm.tools.I18n.tr;
    68
     
    911import java.awt.event.KeyEvent;
    1012import java.awt.event.MouseAdapter;
     13import java.util.Collections;
     14import java.util.HashSet;
     15import java.util.Set;
     16import javax.swing.DefaultListModel;
     17import javax.swing.JButton;
    1118
    1219import javax.swing.JList;
     
    1522import javax.swing.ListSelectionModel;
    1623import org.openstreetmap.josm.Main;
     24import org.openstreetmap.josm.data.SelectionChangedListener;
    1725import org.openstreetmap.josm.data.osm.Relation;
     26import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode;
     27import org.openstreetmap.josm.data.osm.event.SelectionEventManager;
    1828
    1929import org.openstreetmap.josm.gui.MapView;
     30import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener;
    2031import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    2132import org.openstreetmap.josm.gui.OsmPrimitivRenderer;
     
    2334import org.openstreetmap.josm.gui.layer.Layer;
    2435import org.openstreetmap.josm.tools.Shortcut;
     36import relcontext.actions.AddRemoveMemberAction;
     37import relcontext.actions.ClearChosenRelationAction;
     38import relcontext.actions.CreateRelationAction;
     39import relcontext.actions.DownloadChosenRelationAction;
     40import relcontext.actions.EditChosenRelationAction;
    2541
    2642/**
     
    2945 * @author Zverik
    3046 */
    31 public class RelContextDialog extends ToggleDialog implements LayerChangeListener, ChosenRelationListener {
     47public class RelContextDialog extends ToggleDialog implements EditLayerChangeListener, ChosenRelationListener, SelectionChangedListener {
    3248    private JList relationsList;
     49    private final DefaultListModel relationsData;
    3350    private ChosenRelation chosenRelation;
    3451
    3552    public RelContextDialog() {
    36         super(tr("Open Relation Editor"), "icon_relcontext",
     53        super(tr("Advanced Relation Editor"), "icon_relcontext",
    3754                tr("Opens advanced relation/multipolygon editor panel"),
    3855                Shortcut.registerShortcut("view:relcontext", tr("Toggle: {0}", tr("Open Relation Editor")),
    3956                KeyEvent.VK_R, Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 150);
     57
     58        JPanel rcPanel = new JPanel(new BorderLayout());
    4059
    4160        chosenRelation = new ChosenRelation();
     
    4362        MapView.addEditLayerChangeListener(chosenRelation);
    4463
    45         relationsList = new JList();
     64        relationsData = new DefaultListModel();
     65        relationsList = new JList(relationsData);
    4666        relationsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    4767        relationsList.setCellRenderer(new OsmPrimitivRenderer() {
     
    5878                }
    5979                chosenRelation.set((Relation)relationsList.getSelectedValue());
     80                relationsList.clearSelection();
    6081            }
    6182        });
    62         add(new JScrollPane(relationsList), BorderLayout.CENTER);
     83        rcPanel.add(new JScrollPane(relationsList), BorderLayout.CENTER);
    6384
    6485        // [±][X] relation U [AZ][Down][Edit]
    6586        JPanel topLine = new JPanel(new BorderLayout());
    6687        JPanel topLeftButtons = new JPanel(new FlowLayout(FlowLayout.LEFT));
     88        topLeftButtons.add(new JButton(new AddRemoveMemberAction(chosenRelation)));
     89        topLeftButtons.add(new JButton(new ClearChosenRelationAction(chosenRelation)));
     90        topLine.add(topLeftButtons, BorderLayout.WEST);
     91        topLine.add(new ChosenRelationComponent(chosenRelation), BorderLayout.CENTER);
    6792        JPanel topRightButtons = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    68         topLine.add(topLeftButtons, BorderLayout.WEST);
     93        topRightButtons.add(new JButton(new DownloadChosenRelationAction(chosenRelation)));
     94        topRightButtons.add(new JButton(new EditChosenRelationAction(chosenRelation)));
    6995        topLine.add(topRightButtons, BorderLayout.EAST);
    70         add(topLine, BorderLayout.NORTH);
     96        rcPanel.add(topLine, BorderLayout.NORTH);
    7197
    7298        // [+][Multi] [X]Adm [X]Tags [X]1
    7399        JPanel bottomLine = new JPanel(new FlowLayout(FlowLayout.LEFT));
    74         add(bottomLine, BorderLayout.SOUTH);
     100        bottomLine.add(new JButton(new CreateRelationAction(chosenRelation)));
     101        rcPanel.add(bottomLine, BorderLayout.SOUTH);
    75102
    76         MapView.addLayerChangeListener(this);
     103        add(rcPanel, BorderLayout.CENTER);
    77104    }
     105
     106    @Override
     107    public void hideNotify() {
     108        SelectionEventManager.getInstance().removeSelectionListener(this);
     109        MapView.removeEditLayerChangeListener(this);
     110    }
     111
     112    @Override
     113    public void showNotify() {
     114        SelectionEventManager.getInstance().addSelectionListener(this, FireMode.IN_EDT_CONSOLIDATED);
     115        MapView.addEditLayerChangeListener(this);
     116    }
     117
     118
    78119
    79120    public ChosenRelation getChosenRelation() {
     
    85126    }
    86127
    87     @Override
    88     public void activeLayerChange( Layer arg0, Layer arg1 ) {
    89         // TODO Auto-generated method stub
     128    public void selectionChanged( Collection<? extends OsmPrimitive> newSelection ) {
     129        if( !isVisible() || relationsData == null )
     130            return;
     131        // repopulate relations table
     132        relationsData.clear();
     133        if( newSelection == null )
     134            return;
     135        Set<Relation> rels = new HashSet<Relation>();
     136        for( OsmPrimitive element : newSelection ) {
     137            for( OsmPrimitive ref : element.getReferrers() ) {
     138                if( ref instanceof Relation && !ref.isIncomplete() && !ref.isDeleted() ) {
     139                    rels.add((Relation) ref);
     140                }
     141            }
     142        }
     143        for( Relation rel : rels )
     144            relationsData.addElement(rel);
    90145    }
    91146
    92     @Override
    93     public void layerAdded( Layer arg0 ) {
    94         // TODO Auto-generated method stub
     147    private void updateSelection() {
     148        if (Main.main.getCurrentDataSet() == null) {
     149            selectionChanged(Collections.<OsmPrimitive>emptyList());
     150        } else {
     151            selectionChanged(Main.main.getCurrentDataSet().getSelected());
     152        }
    95153    }
    96154
    97     @Override
    98     public void layerRemoved( Layer arg0 ) {
    99         // TODO Auto-generated method stub
     155    public void editLayerChanged( OsmDataLayer oldLayer, OsmDataLayer newLayer ) {
     156        updateSelection();
    100157    }
    101158}
  • applications/editors/josm/plugins/relcontext/src/relcontext/actions/AddRemoveMemberAction.java

    r25649 r25667  
    2222
    2323    public AddRemoveMemberAction( ChosenRelation rel ) {
    24         super(tr(ACTION_NAME), "add_remove_member", "Add/remove member from the chosen relation",
    25                 null, false);
     24        super("±", null, "Add/remove member from the chosen relation", null, false);
    2625        this.rel = rel;
     26        rel.addChosenRelationListener(this);
     27        updateEnabledState();
    2728    }
    2829
  • applications/editors/josm/plugins/relcontext/src/relcontext/actions/ClearChosenRelationAction.java

    r25649 r25667  
    88
    99public class ClearChosenRelationAction extends AbstractAction implements ChosenRelationListener {
     10    private ChosenRelation rel;
    1011
    11         private ChosenRelation rel;
     12    public ClearChosenRelationAction( ChosenRelation rel ) {
     13        super("X");
     14        this.rel = rel;
     15        rel.addChosenRelationListener(this);
     16        setEnabled(false);
     17    }
    1218
    13         public ClearChosenRelationAction( ChosenRelation rel ) {
    14                 this.rel = rel;
    15         }
     19    public void actionPerformed( ActionEvent e ) {
     20        rel.clear();
     21    }
    1622
    17         public void actionPerformed( ActionEvent e ) {
    18                 rel.clear();
    19         }
    20 
    21         public void chosenRelationChanged( Relation oldRelation, Relation newRelation ) {
    22                 setEnabled(newRelation != null);
    23         }
     23    public void chosenRelationChanged( Relation oldRelation, Relation newRelation ) {
     24        setEnabled(newRelation != null);
     25    }
    2426}
  • applications/editors/josm/plugins/relcontext/src/relcontext/actions/CreateRelationAction.java

    r25649 r25667  
    2121 */
    2222public class CreateRelationAction extends JosmAction {
     23    private static final String ACTION_NAME = "Create relation";
     24    protected ChosenRelation chRel;
    2325
    24         private static final String ACTION_NAME = "Create relation";
    25         protected ChosenRelation chRel;
     26    public CreateRelationAction( ChosenRelation chRel ) {
     27        super("+", null, "Create a relation from selected objects", null, false);
     28        this.chRel = chRel;
     29        updateEnabledState();
     30    }
    2631
    27         public CreateRelationAction( ChosenRelation chRel ) {
    28                 super(tr(ACTION_NAME), "create_relation", "Create a relation from selected objects",
    29                                 null, false);
    30                 this.chRel = chRel;
    31         }
     32    public CreateRelationAction() {
     33        this(null);
     34    }
    3235
    33         public CreateRelationAction() {
    34                 this(null);
    35         }
     36    public void actionPerformed( ActionEvent e ) {
     37        // todo: ask user for relation type
     38        String type = "";
    3639
    37         public void actionPerformed( ActionEvent e ) {
    38                 // todo: ask user for relation type
    39                 String type = "";
     40        Relation rel = new Relation();
     41        if( type != null && type.length() > 0 ) {
     42            rel.put("type", type);
     43        }
     44        for( OsmPrimitive selected : getCurrentDataSet().getSelected() ) {
     45            rel.addMember(new RelationMember("", selected));
     46        }
    4047
    41                 Relation rel = new Relation();
    42                 if( type != null && type.length() > 0 )
    43                         rel.put("type", type);
    44                 for( OsmPrimitive selected : getCurrentDataSet().getSelected() ) {
    45                         rel.addMember(new RelationMember("", selected));
    46                 }
     48        Collection<Command> cmds = new LinkedList<Command>();
     49        Main.main.undoRedo.add(new AddCommand(rel));
    4750
    48                 Collection<Command> cmds = new LinkedList<Command>();
    49                 Main.main.undoRedo.add(new AddCommand(rel));
     51        if( chRel != null ) {
     52            chRel.set(rel);
     53        }
     54    }
    5055
    51                 if( chRel != null)
    52                         chRel.set(rel);
    53         }
     56    @Override
     57    protected void updateEnabledState() {
     58        if( getCurrentDataSet() == null ) {
     59            setEnabled(false);
     60        } else {
     61            updateEnabledState(getCurrentDataSet().getSelected());
     62        }
     63    }
    5464
    55         @Override
    56         protected void updateEnabledState() {
    57                 if( getCurrentDataSet() == null )
    58                         setEnabled(false);
    59                 else
    60                         updateEnabledState(getCurrentDataSet().getSelected());
    61         }
    62 
    63         @Override
    64         protected void updateEnabledState( Collection<? extends OsmPrimitive> selection ) {
    65                 setEnabled(selection != null && !selection.isEmpty());
    66         }
     65    @Override
     66    protected void updateEnabledState( Collection<? extends OsmPrimitive> selection ) {
     67        setEnabled(selection != null && !selection.isEmpty());
     68    }
    6769}
  • applications/editors/josm/plugins/relcontext/src/relcontext/actions/EditChosenRelationAction.java

    r25649 r25667  
    1515 */
    1616public class EditChosenRelationAction extends AbstractAction implements ChosenRelationListener {
     17    private ChosenRelation rel;
    1718
    18         private ChosenRelation rel;
     19    public EditChosenRelationAction( ChosenRelation rel ) {
     20        super("E");
     21        this.rel = rel;
     22        rel.addChosenRelationListener(this);
     23        setEnabled(false);
     24    }
    1925
    20         public EditChosenRelationAction( ChosenRelation rel ) {
    21                 this.rel = rel;
    22         }
     26    public void actionPerformed( ActionEvent e ) {
     27        Relation relation = rel.get();
     28        if( relation == null ) return;
     29        RelationEditor.getEditor(Main.map.mapView.getEditLayer(), relation, null).setVisible(true);
     30    }
    2331
    24         public void actionPerformed( ActionEvent e ) {
    25         Relation relation = rel.get();
    26                 if( relation == null ) return;
    27         //Main.map.relationListDialog.selectRelation(relation); // is it needed?
    28         RelationEditor.getEditor(Main.map.mapView.getEditLayer(), relation, null).setVisible(true);
    29         }
    30 
    31         public void chosenRelationChanged( Relation oldRelation, Relation newRelation ) {
    32                 setEnabled(newRelation != null);
    33         }
     32    public void chosenRelationChanged( Relation oldRelation, Relation newRelation ) {
     33        setEnabled(newRelation != null);
     34    }
    3435}
Note: See TracChangeset for help on using the changeset viewer.