Changeset 2156 in josm for trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
- Timestamp:
- 2009-09-17T21:52:20+02:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
r2048 r2156 70 70 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 71 71 import org.openstreetmap.josm.gui.tagging.AutoCompletingTextField; 72 import org.openstreetmap.josm.gui.tagging.TagCellEditor; 73 import org.openstreetmap.josm.gui.tagging.TagEditorModel; 74 import org.openstreetmap.josm.gui.tagging.TagTable; 72 import org.openstreetmap.josm.gui.tagging.TagEditorPanel; 75 73 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionCache; 76 74 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList; … … 92 90 93 91 /** the tag table and its model */ 94 private TagEditorModel tagEditorModel; 95 private TagTable tagTable; 96 private AutoCompletionCache acCache; 97 private AutoCompletionList acList; 92 private TagEditorPanel tagEditorPanel; 98 93 private ReferringRelationsBrowser referrerBrowser; 99 94 private ReferringRelationsBrowserModel referrerModel; … … 124 119 // initialize the autocompletion infrastructure 125 120 // 126 acCache = AutoCompletionCache.getCacheForLayer(getLayer()); 127 acCache.initFromDataSet(); 128 acList = new AutoCompletionList(); 121 AutoCompletionCache.getCacheForLayer(getLayer()).initFromDataSet(); 129 122 130 123 // init the various models 131 124 // 132 tagEditorModel = new TagEditorModel();133 125 memberTableModel = new MemberTableModel(getLayer()); 134 126 selectionTableModel = new SelectionTableModel(getLayer()); 135 127 referrerModel = new ReferringRelationsBrowserModel(relation); 136 128 129 tagEditorPanel = new TagEditorPanel(); 137 130 // populate the models 138 131 // 139 132 if (relation != null) { 140 this.tagEditorModel.initFromPrimitive(relation); 133 tagEditorPanel.getModel().initFromPrimitive(relation); 134 //this.tagEditorModel.initFromPrimitive(relation); 141 135 this.memberTableModel.populate(relation); 142 136 if (!getLayer().data.relations.contains(relation)) { … … 146 140 } 147 141 } else { 148 tagEditor Model.clear();142 tagEditorPanel.getModel().clear(); 149 143 this.memberTableModel.populate(null); 150 144 } 151 tagEditor Model.ensureOneTag();145 tagEditorPanel.getModel().ensureOneTag(); 152 146 153 147 JSplitPane pane = buildSplitPane(); … … 211 205 212 206 /** 213 * build the panel with the buttons on the left214 * 215 * @return 207 * builds the panel with the tag editor 208 * 209 * @return the panel with the tag editor 216 210 */ 217 protected JPanel buildTagEditor ControlPanel() {211 protected JPanel buildTagEditorPanel() { 218 212 JPanel pnl = new JPanel(); 219 213 pnl.setLayout(new GridBagLayout()); … … 224 218 gc.gridheight = 1; 225 219 gc.gridwidth = 1; 226 gc.insets = new Insets(0, 5, 0, 5);227 gc.fill = GridBagConstraints.HORIZONTAL;228 gc.anchor = GridBagConstraints.CENTER;229 gc.weightx = 0.0;230 gc.weighty = 0.0;231 232 // -----233 AddTagAction addTagAction = new AddTagAction();234 pnl.add(new JButton(addTagAction), gc);235 236 // -----237 gc.gridy = 1;238 DeleteTagAction deleteTagAction = new DeleteTagAction();239 tagTable.getSelectionModel().addListSelectionListener(deleteTagAction);240 pnl.add(new JButton(deleteTagAction), gc);241 242 // ------243 // just grab the remaining space244 gc.gridy = 2;245 gc.weighty = 1.0;246 gc.fill = GridBagConstraints.BOTH;247 pnl.add(new JPanel(), gc);248 return pnl;249 }250 251 /**252 * builds the panel with the tag editor253 *254 * @return the panel with the tag editor255 */256 protected JPanel buildTagEditorPanel() {257 JPanel pnl = new JPanel();258 pnl.setLayout(new GridBagLayout());259 260 // setting up the tag table261 //262 tagTable = new TagTable(tagEditorModel);263 TagCellEditor editor = ((TagCellEditor) tagTable.getColumnModel().getColumn(0).getCellEditor());264 editor.setAutoCompletionCache(acCache);265 editor.setAutoCompletionList(acList);266 editor = ((TagCellEditor) tagTable.getColumnModel().getColumn(1).getCellEditor());267 editor.setAutoCompletionCache(acCache);268 editor.setAutoCompletionList(acList);269 270 final JScrollPane scrollPane = new JScrollPane(tagTable);271 272 GridBagConstraints gc = new GridBagConstraints();273 gc.gridx = 0;274 gc.gridy = 0;275 gc.gridheight = 1;276 gc.gridwidth = 3;277 220 gc.fill = GridBagConstraints.HORIZONTAL; 278 221 gc.anchor = GridBagConstraints.FIRST_LINE_START; … … 283 226 gc.gridx = 0; 284 227 gc.gridy = 1; 285 gc.gridheight = 1;286 gc.gridwidth = 1;287 gc.fill = GridBagConstraints.VERTICAL;288 gc.anchor = GridBagConstraints.NORTHWEST;289 gc.weightx = 0.0;290 gc.weighty = 1.0;291 pnl.add(buildTagEditorControlPanel(), gc);292 293 gc.gridx = 1;294 gc.gridy = 1;295 228 gc.fill = GridBagConstraints.BOTH; 296 229 gc.anchor = GridBagConstraints.CENTER; 297 gc.weightx = 0.8;230 gc.weightx = 1.0; 298 231 gc.weighty = 1.0; 299 pnl.add( scrollPane, gc);232 pnl.add(tagEditorPanel, gc); 300 233 return pnl; 301 234 } … … 311 244 // setting up the member table 312 245 memberTable = new MemberTable(getLayer(),memberTableModel); 313 MemberRoleCellEditor editor = ((MemberRoleCellEditor) memberTable.getColumnModel().getColumn(0).getCellEditor());314 editor.setAutoCompletionCache(acCache);315 editor.setAutoCompletionList(acList);316 317 246 memberTable.addMouseListener(new MemberTableDblClickAdapter()); 318 247 memberTableModel.addMemberModelListener(memberTable); … … 587 516 } 588 517 }); 589 tfRole.setAutoCompletionList( acList);518 tfRole.setAutoCompletionList(new AutoCompletionList()); 590 519 tfRole.addFocusListener( 591 520 new FocusAdapter() { 592 521 @Override 593 522 public void focusGained(FocusEvent e) { 594 acCache.populateWithMemberRoles(acList); 523 AutoCompletionList list = tfRole.getAutoCompletionList(); 524 AutoCompletionCache.getCacheForLayer(Main.main.getEditLayer()).populateWithMemberRoles(list); 595 525 } 596 526 } … … 629 559 630 560 @Override 631 public void setVisible(boolean b) { 632 super.setVisible(b); 633 if (!b) { 561 public void setVisible(boolean visible) { 562 if (visible) { 563 tagEditorPanel.initAutoCompletion(Main.main.getEditLayer()); 564 } 565 super.setVisible(visible); 566 if (!visible) { 634 567 dispose(); 635 568 } … … 1063 996 // If the user wanted to create a new relation, but hasn't added any members or 1064 997 // tags, don't add an empty relation 1065 if (memberTableModel.getRowCount() == 0 && tagEditor Model.getKeys().isEmpty())998 if (memberTableModel.getRowCount() == 0 && tagEditorPanel.getModel().getKeys().isEmpty()) 1066 999 return; 1067 1000 Relation newRelation = new Relation(); 1068 tagEditor Model.applyToPrimitive(newRelation);1001 tagEditorPanel.getModel().applyToPrimitive(newRelation); 1069 1002 memberTableModel.applyToRelation(newRelation); 1070 1003 Main.main.undoRedo.add(new AddCommand(getLayer(),newRelation)); … … 1089 1022 protected void applyExistingConflictingRelation() { 1090 1023 Relation editedRelation = new Relation(getRelation()); 1091 tagEditor Model.applyToPrimitive(editedRelation);1024 tagEditorPanel.getModel().applyToPrimitive(editedRelation); 1092 1025 memberTableModel.applyToRelation(editedRelation); 1093 1026 Conflict<Relation> conflict = new Conflict<Relation>(getRelation(), editedRelation); … … 1102 1035 protected void applyExistingNonConflictingRelation() { 1103 1036 Relation editedRelation = new Relation(getRelation()); 1104 tagEditor Model.applyToPrimitive(editedRelation);1037 tagEditorPanel.getModel().applyToPrimitive(editedRelation); 1105 1038 memberTableModel.applyToRelation(editedRelation); 1106 1039 Main.main.undoRedo.add(new ChangeCommand(getRelation(), editedRelation)); … … 1165 1098 applyNewRelation(); 1166 1099 } else if (!memberTableModel.hasSameMembersAs(getRelationSnapshot()) 1167 || tagEditor Model.isDirty()) {1100 || tagEditorPanel.getModel().isDirty()) { 1168 1101 if (isDirtyRelation()) { 1169 1102 if (confirmClosingBecauseOfDirtyState()) { … … 1198 1131 applyNewRelation(); 1199 1132 } else if (!memberTableModel.hasSameMembersAs(getRelationSnapshot()) 1200 || tagEditor Model.isDirty()) {1133 || tagEditorPanel.getModel().isDirty()) { 1201 1134 if (isDirtyRelation()) { 1202 1135 if (confirmClosingBecauseOfDirtyState()) { … … 1246 1179 1247 1180 public void actionPerformed(ActionEvent e) { 1248 tagEditorModel.appendNewTag(); 1249 } 1250 } 1251 1252 class DeleteTagAction extends AbstractAction implements ListSelectionListener { 1253 public DeleteTagAction() { 1254 putValue(SHORT_DESCRIPTION, tr("Delete the currently selected tags")); 1255 putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete")); 1256 // putValue(NAME, tr("Cancel")); 1257 refreshEnabled(); 1258 } 1259 1260 public void actionPerformed(ActionEvent e) { 1261 run(); 1262 } 1263 1264 /** 1265 * delete a selection of tag names 1266 */ 1267 protected void deleteTagNames() { 1268 int[] rows = tagTable.getSelectedRows(); 1269 tagEditorModel.deleteTagNames(rows); 1270 } 1271 1272 /** 1273 * delete a selection of tag values 1274 */ 1275 protected void deleteTagValues() { 1276 int[] rows = tagTable.getSelectedRows(); 1277 tagEditorModel.deleteTagValues(rows); 1278 } 1279 1280 /** 1281 * delete a selection of tags 1282 */ 1283 protected void deleteTags() { 1284 tagEditorModel.deleteTags(tagTable.getSelectedRows()); 1285 } 1286 1287 public void run() { 1288 if (!isEnabled()) 1289 return; 1290 if (tagTable.getSelectedColumnCount() == 1) { 1291 if (tagTable.getSelectedColumn() == 0) { 1292 deleteTagNames(); 1293 } else if (tagTable.getSelectedColumn() == 1) { 1294 deleteTagValues(); 1295 } else 1296 // should not happen 1297 // 1298 throw new IllegalStateException("unexpected selected clolumn: getSelectedColumn() is " 1299 + tagTable.getSelectedColumn()); 1300 } else if (tagTable.getSelectedColumnCount() == 2) { 1301 deleteTags(); 1302 } 1303 if (tagEditorModel.getRowCount() == 0) { 1304 tagEditorModel.ensureOneTag(); 1305 } 1306 } 1307 1308 protected void refreshEnabled() { 1309 setEnabled(tagTable.getSelectedRowCount() > 0 || tagTable.getSelectedColumnCount() > 0); 1310 } 1311 1312 public void valueChanged(ListSelectionEvent e) { 1313 refreshEnabled(); 1181 tagEditorPanel.getModel().appendNewTag(); 1314 1182 } 1315 1183 } … … 1419 1287 public void actionPerformed(ActionEvent e) { 1420 1288 Relation copy = new Relation(); 1421 tagEditor Model.applyToPrimitive(copy);1289 tagEditorPanel.getModel().applyToPrimitive(copy); 1422 1290 memberTableModel.applyToRelation(copy); 1423 1291 RelationEditor editor = RelationEditor.getEditor(getLayer(), copy, memberTableModel.getSelectedMembers());
Note:
See TracChangeset
for help on using the changeset viewer.
