Changeset 25667 in osm for applications/editors
- Timestamp:
- 2011-03-22T15:53:58+01:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/relcontext
- Files:
-
- 6 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/relcontext/build.xml
r25649 r25667 28 28 ** 29 29 --> 30 <project name=" myPluginName" default="dist" basedir=".">30 <project name="RelContext" default="dist" basedir="."> 31 31 32 32 <!-- enter the SVN commit message --> … … 44 44 <property name="plugin.src.dir" value="src"/> 45 45 <!-- 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"/> 47 47 <property name="ant.build.javac.target" value="1.5"/> 48 <property name="plugin.dist.dir" value="../../dist"/>49 48 <property name="plugin.jar" value="${plugin.dist.dir}/${ant.project.name}.jar"/> 50 49 … … 78 77 <target name="dist" depends="compile,revision"> 79 78 <echo message="creating ${ant.project.name}.jar ... "/> 80 <copy todir="${plugin.build.dir}/resources">81 <fileset dir="resources"/>82 </copy>83 79 <copy todir="${plugin.build.dir}/images"> 84 80 <fileset dir="images"/> -
applications/editors/josm/plugins/relcontext/src/relcontext/ChosenRelation.java
r25649 r25667 41 41 chosenRelation = rel; 42 42 analyse(); 43 Main.map.mapView.repaint(); 43 44 for( ChosenRelationListener listener : chosenRelationListeners ) { 44 45 listener.chosenRelationChanged(oldRel, chosenRelation); … … 92 93 g.setColor(Color.yellow); 93 94 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)); 95 96 for( OsmPrimitive element : chosenRelation.getMemberPrimitives() ) { 96 97 if( element.getType() == OsmPrimitiveType.NODE ) { … … 105 106 b.moveTo(p.x, p.y); 106 107 for( int i = 1; i < way.getNodesCount(); i++ ) { 107 p = mv.getPoint(way.getNode( 1));108 p = mv.getPoint(way.getNode(i)); 108 109 b.lineTo(p.x, p.y); 109 110 } -
applications/editors/josm/plugins/relcontext/src/relcontext/RelContextDialog.java
r25649 r25667 2 2 3 3 import java.awt.event.MouseEvent; 4 import java.util.Collection; 4 5 import org.openstreetmap.josm.data.osm.OsmPrimitive; 6 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 5 7 import static org.openstreetmap.josm.tools.I18n.tr; 6 8 … … 9 11 import java.awt.event.KeyEvent; 10 12 import java.awt.event.MouseAdapter; 13 import java.util.Collections; 14 import java.util.HashSet; 15 import java.util.Set; 16 import javax.swing.DefaultListModel; 17 import javax.swing.JButton; 11 18 12 19 import javax.swing.JList; … … 15 22 import javax.swing.ListSelectionModel; 16 23 import org.openstreetmap.josm.Main; 24 import org.openstreetmap.josm.data.SelectionChangedListener; 17 25 import org.openstreetmap.josm.data.osm.Relation; 26 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode; 27 import org.openstreetmap.josm.data.osm.event.SelectionEventManager; 18 28 19 29 import org.openstreetmap.josm.gui.MapView; 30 import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener; 20 31 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 21 32 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; … … 23 34 import org.openstreetmap.josm.gui.layer.Layer; 24 35 import org.openstreetmap.josm.tools.Shortcut; 36 import relcontext.actions.AddRemoveMemberAction; 37 import relcontext.actions.ClearChosenRelationAction; 38 import relcontext.actions.CreateRelationAction; 39 import relcontext.actions.DownloadChosenRelationAction; 40 import relcontext.actions.EditChosenRelationAction; 25 41 26 42 /** … … 29 45 * @author Zverik 30 46 */ 31 public class RelContextDialog extends ToggleDialog implements LayerChangeListener, ChosenRelationListener {47 public class RelContextDialog extends ToggleDialog implements EditLayerChangeListener, ChosenRelationListener, SelectionChangedListener { 32 48 private JList relationsList; 49 private final DefaultListModel relationsData; 33 50 private ChosenRelation chosenRelation; 34 51 35 52 public RelContextDialog() { 36 super(tr(" OpenRelation Editor"), "icon_relcontext",53 super(tr("Advanced Relation Editor"), "icon_relcontext", 37 54 tr("Opens advanced relation/multipolygon editor panel"), 38 55 Shortcut.registerShortcut("view:relcontext", tr("Toggle: {0}", tr("Open Relation Editor")), 39 56 KeyEvent.VK_R, Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 150); 57 58 JPanel rcPanel = new JPanel(new BorderLayout()); 40 59 41 60 chosenRelation = new ChosenRelation(); … … 43 62 MapView.addEditLayerChangeListener(chosenRelation); 44 63 45 relationsList = new JList(); 64 relationsData = new DefaultListModel(); 65 relationsList = new JList(relationsData); 46 66 relationsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 47 67 relationsList.setCellRenderer(new OsmPrimitivRenderer() { … … 58 78 } 59 79 chosenRelation.set((Relation)relationsList.getSelectedValue()); 80 relationsList.clearSelection(); 60 81 } 61 82 }); 62 add(new JScrollPane(relationsList), BorderLayout.CENTER);83 rcPanel.add(new JScrollPane(relationsList), BorderLayout.CENTER); 63 84 64 85 // [±][X] relation U [AZ][Down][Edit] 65 86 JPanel topLine = new JPanel(new BorderLayout()); 66 87 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); 67 92 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))); 69 95 topLine.add(topRightButtons, BorderLayout.EAST); 70 add(topLine, BorderLayout.NORTH);96 rcPanel.add(topLine, BorderLayout.NORTH); 71 97 72 98 // [+][Multi] [X]Adm [X]Tags [X]1 73 99 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); 75 102 76 MapView.addLayerChangeListener(this);103 add(rcPanel, BorderLayout.CENTER); 77 104 } 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 78 119 79 120 public ChosenRelation getChosenRelation() { … … 85 126 } 86 127 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); 90 145 } 91 146 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 } 95 153 } 96 154 97 @Override 98 public void layerRemoved( Layer arg0 ) { 99 // TODO Auto-generated method stub 155 public void editLayerChanged( OsmDataLayer oldLayer, OsmDataLayer newLayer ) { 156 updateSelection(); 100 157 } 101 158 } -
applications/editors/josm/plugins/relcontext/src/relcontext/actions/AddRemoveMemberAction.java
r25649 r25667 22 22 23 23 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); 26 25 this.rel = rel; 26 rel.addChosenRelationListener(this); 27 updateEnabledState(); 27 28 } 28 29 -
applications/editors/josm/plugins/relcontext/src/relcontext/actions/ClearChosenRelationAction.java
r25649 r25667 8 8 9 9 public class ClearChosenRelationAction extends AbstractAction implements ChosenRelationListener { 10 private ChosenRelation rel; 10 11 11 private ChosenRelation rel; 12 public ClearChosenRelationAction( ChosenRelation rel ) { 13 super("X"); 14 this.rel = rel; 15 rel.addChosenRelationListener(this); 16 setEnabled(false); 17 } 12 18 13 public ClearChosenRelationAction( ChosenRelation rel) {14 this.rel = rel;15 19 public void actionPerformed( ActionEvent e ) { 20 rel.clear(); 21 } 16 22 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 } 24 26 } -
applications/editors/josm/plugins/relcontext/src/relcontext/actions/CreateRelationAction.java
r25649 r25667 21 21 */ 22 22 public class CreateRelationAction extends JosmAction { 23 private static final String ACTION_NAME = "Create relation"; 24 protected ChosenRelation chRel; 23 25 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 } 26 31 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 } 32 35 33 public CreateRelationAction() {34 this(null); 35 } 36 public void actionPerformed( ActionEvent e ) { 37 // todo: ask user for relation type 38 String type = ""; 36 39 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 } 40 47 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)); 47 50 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 } 50 55 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 } 54 64 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 } 67 69 } -
applications/editors/josm/plugins/relcontext/src/relcontext/actions/EditChosenRelationAction.java
r25649 r25667 15 15 */ 16 16 public class EditChosenRelationAction extends AbstractAction implements ChosenRelationListener { 17 private ChosenRelation rel; 17 18 18 private ChosenRelation rel; 19 public EditChosenRelationAction( ChosenRelation rel ) { 20 super("E"); 21 this.rel = rel; 22 rel.addChosenRelationListener(this); 23 setEnabled(false); 24 } 19 25 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 } 23 31 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 } 34 35 }
Note:
See TracChangeset
for help on using the changeset viewer.