- Timestamp:
- 2009-07-18T15:49:59+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/dialogs/relation
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
r1801 r1804 80 80 81 81 static private final Logger logger = Logger.getLogger(GenericRelationEditor.class.getName()); 82 static private final Dimension DEFAULT_EDITOR_DIMENSION = new Dimension(700,500); 82 83 83 84 /** the tag table and its model */ … … 130 131 this.memberTableModel.populate(null); 131 132 } 132 memberTableModel.se lectMembers(selectedMembers);133 memberTableModel.setSelectedMembers(selectedMembers); 133 134 tagEditorModel.ensureOneTag(); 134 135 … … 529 530 buttonPanel.add(new SideButton(setRoleAction)); 530 531 tfRole.getDocument().addDocumentListener(setRoleAction); 532 533 //--- copy relation action 534 buttonPanel.add(new SideButton(new DuplicateRelationAction())); 531 535 return buttonPanel; 532 536 } … … 577 581 protected Dimension findMaxDialogSize() { 578 582 // FIXME: Make it remember dialog size 579 return new Dimension( 600, 500);583 return new Dimension(700, 500); 580 584 } 581 585 … … 938 942 public void removeUpdate(DocumentEvent e) { 939 943 refreshEnabled(); 944 } 945 } 946 947 /** 948 * Creates a new relation with a copy of the current editor state 949 * 950 */ 951 class DuplicateRelationAction extends AbstractAction { 952 public DuplicateRelationAction() { 953 putValue(SHORT_DESCRIPTION, tr("Create a copy of this relation and open it in another editor window")); 954 // FIXME provide an icon 955 putValue(SMALL_ICON, ImageProvider.get("duplicate")); 956 putValue(NAME, tr("Duplicate")); 957 setEnabled(true); 958 } 959 public void actionPerformed(ActionEvent e) { 960 Relation copy = new Relation(); 961 tagEditorModel.applyToPrimitive(copy); 962 memberTableModel.applyToRelation(copy); 963 RelationEditor editor = RelationEditor.getEditor(getLayer(), copy, memberTableModel.getSelectedMembers()); 964 editor.setVisible(true); 940 965 } 941 966 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTable.java
r1792 r1804 2 2 package org.openstreetmap.josm.gui.dialogs.relation; 3 3 4 import java.awt.Dimension; 4 5 import java.awt.Rectangle; 5 6 import java.awt.event.ActionEvent; … … 134 135 } 135 136 } 136 137 138 137 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java
r1798 r1804 5 5 import java.util.Arrays; 6 6 import java.util.Collection; 7 import java.util.Collections; 7 8 import java.util.Iterator; 8 9 import java.util.List; … … 205 206 } 206 207 207 public void selectMembers(Collection<RelationMember> selectedMembers) {208 if (selectedMembers == null) return;209 int min = Integer.MAX_VALUE;210 for (RelationMember member: selectedMembers) {211 int row = members.indexOf(member);212 if (row >= 0) {213 getSelectionModel();214 listSelectionModel.addSelectionInterval(row,row);215 min = Math.min(row, min);216 }217 }218 if (min < Integer.MAX_VALUE) {219 fireMakeMemberVisible(min);220 }221 }222 223 208 public void applyToRelation(Relation relation) { 224 209 relation.members.clear(); … … 346 331 } 347 332 } 333 334 /** 335 * Replies a collection with the currently selected relation members 336 * 337 * @return a collection with the currently selected relation members 338 */ 339 public Collection<RelationMember> getSelectedMembers() { 340 ArrayList<RelationMember> selectedMembers = new ArrayList<RelationMember>(); 341 for (int i: getSelectedIndices()) { 342 selectedMembers.add(members.get(i)); 343 } 344 return selectedMembers; 345 } 346 347 348 /** 349 * Selectes the members in the collection selectedMembers 350 * 351 * @param selectedMembers the collection of selected members 352 */ 353 public void setSelectedMembers(Collection<RelationMember> selectedMembers) { 354 if (selectedMembers == null || selectedMembers.isEmpty()) 355 return; 356 357 // lookup the indices for the respective members 358 // 359 ArrayList<Integer> selectedIndices = new ArrayList<Integer>(); 360 for (RelationMember member: selectedMembers) { 361 int idx = members.indexOf(member); 362 if (idx >= 0 && !selectedIndices.contains(idx)) { 363 selectedIndices.add(idx); 364 } 365 } 366 367 // select the members 368 // 369 Collections.sort(selectedIndices); 370 getSelectionModel().clearSelection(); 371 for (int row : selectedIndices) { 372 getSelectionModel().addSelectionInterval(row, row); 373 } 374 375 // make the first selected member visible 376 // 377 if (selectedIndices.size() > 0) { 378 fireMakeMemberVisible(selectedIndices.get(0)); 379 } 380 } 348 381 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationDialogManager.java
r1784 r1804 2 2 package org.openstreetmap.josm.gui.dialogs.relation; 3 3 4 import java.awt.Dimension; 5 import java.awt.Point; 6 import java.awt.Toolkit; 4 7 import java.awt.event.WindowAdapter; 5 8 import java.awt.event.WindowEvent; … … 12 15 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 13 16 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener; 17 14 18 15 19 /** … … 93 97 */ 94 98 public void register(OsmDataLayer layer, Relation relation, RelationEditor editor) { 99 if (relation == null) { 100 relation = new Relation(); 101 } 95 102 DialogContext context = new DialogContext(layer, relation); 96 103 openDialogs.put(context, editor); … … 100 107 /** 101 108 * Replies true if there is an open relation editor for the relation managed 102 * by the given layer 109 * by the given layer. Replies false if relation is null. 103 110 * 104 111 * @param layer the layer 105 * @param relation the relation 112 * @param relation the relation. May be null. 106 113 * @return true if there is an open relation editor for the relation managed 107 114 * by the given layer; false otherwise 108 115 */ 109 116 public boolean isOpenInEditor(OsmDataLayer layer, Relation relation) { 117 if (relation == null) return false; 110 118 DialogContext context = new DialogContext(layer, relation); 111 119 return openDialogs.keySet().contains(context); … … 115 123 /** 116 124 * Replies the editor for the relation managed by layer. Null, if no such editor 117 * is currently open. 125 * is currently open. Returns null, if relation is null. 118 126 * 119 127 * @param layer the layer … … 125 133 */ 126 134 public RelationEditor getEditorForRelation(OsmDataLayer layer, Relation relation) { 135 if (relation == null) return null; 127 136 DialogContext context = new DialogContext(layer, relation); 128 137 return openDialogs.get(context); … … 172 181 } 173 182 } 183 184 /** 185 * Positions an {@see RelationEditor} centered on the screen 186 * 187 * @param editor the editor 188 */ 189 protected void centerOnScreen(RelationEditor editor) { 190 Point p = new Point(0,0); 191 Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); 192 p.x = (d.width - editor.getSize().width)/2; 193 p.y = (d.height - editor.getSize().height)/2; 194 p.x = Math.max(p.x,0); 195 p.y = Math.max(p.y,0); 196 editor.setLocation(p); 197 } 198 199 /** 200 * Replies true, if there is another open {@see RelationEditor} whose 201 * upper left corner is close to <code>p</code>. 202 * 203 * @param p the reference point to check 204 * @return true, if there is another open {@see RelationEditor} whose 205 * upper left corner is close to <code>p</code>. 206 */ 207 protected boolean hasEditorWithCloseUpperLeftCorner(Point p) { 208 for (RelationEditor editor: openDialogs.values()) { 209 Point corner = editor.getLocation(); 210 if (p.x >= corner.x -5 && corner.x + 5 >= p.x 211 && p.y >= corner.y -5 && corner.y + 5 >= p.y) 212 return true; 213 } 214 return false; 215 } 216 217 /** 218 * Positions a {@see RelationEditor} close to the center of the screen, in such 219 * a way, that it doesn't entirely cover another {@see RelationEditor} 220 * 221 * @param editor 222 */ 223 protected void positionCloseToScreenCenter(RelationEditor editor) { 224 Point p = new Point(0,0); 225 Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); 226 p.x = (d.width - editor.getSize().width)/2; 227 p.y = (d.height - editor.getSize().height)/2; 228 p.x = Math.max(p.x,0); 229 p.y = Math.max(p.y,0); 230 while(hasEditorWithCloseUpperLeftCorner(p)) { 231 p.x += 20; 232 p.y += 20; 233 } 234 editor.setLocation(p); 235 } 236 237 /** 238 * Positions a {@see RelationEditor} on the screen. Tries to center it on the 239 * screen. If it hide another instance of an editor at the same position this 240 * method tries to reposition <code>editor</code> by moving it slightly down and 241 * slightly to the right. 242 * 243 * @param editor the editor 244 */ 245 public void positionOnScreen(RelationEditor editor) { 246 if (editor == null) return; 247 if (openDialogs.isEmpty()) { 248 centerOnScreen(editor); 249 } else { 250 positionCloseToScreenCenter(editor); 251 } 252 } 174 253 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationEditor.java
r1798 r1804 85 85 else { 86 86 RelationEditor editor = new GenericRelationEditor(layer, r, selectedMembers); 87 getRelationDialogManager().positionOnScreen(editor); 87 88 getRelationDialogManager().register(layer, r, editor); 88 89 return editor; -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/SelectionTableColumnModel.java
r1790 r1804 17 17 col = new TableColumn(0); 18 18 col.setHeaderValue(tr("Selection")); 19 col.set Resizable(true);19 col.setMinWidth(200); 20 20 col.setCellRenderer(renderer); 21 21 addColumn(col);
Note:
See TracChangeset
for help on using the changeset viewer.