Changeset 2156 in josm
- Timestamp:
- 2009-09-17T21:52:20+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 4 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()); -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberRoleCellEditor.java
r2048 r2156 9 9 import javax.swing.table.TableCellEditor; 10 10 11 import org.openstreetmap.josm.Main; 11 12 import org.openstreetmap.josm.gui.tagging.AutoCompletingTextField; 12 13 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionCache; 13 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionItemPritority;14 14 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList; 15 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem;16 15 17 16 public class MemberRoleCellEditor extends AbstractCellEditor implements TableCellEditor { … … 21 20 22 21 private AutoCompletingTextField editor = null; 23 24 /** the cache of auto completion items derived from the current JOSM data set */25 private AutoCompletionCache acCache = null;26 22 27 23 /** user input is matched against this list of auto completion items */ … … 33 29 public MemberRoleCellEditor() { 34 30 editor = new AutoCompletingTextField(); 35 acCache = new AutoCompletionCache(); 36 } 37 38 /** 39 * initializes the autocompletion editor with the list of member roles in 40 * the current dataset 41 * 42 */ 43 protected void initAutoCompletionListRoles() { 44 if (autoCompletionList == null) { 45 logger.warning("autoCompletionList is null. Make sure an instance of AutoCompletionList is injected into MemberRoleCellEditor."); 46 return; 47 } 48 autoCompletionList.clear(); 49 50 // add the list of keys in the current data set 51 // 52 for (String key : acCache.getMemberRoles()) { 53 autoCompletionList.add( 54 new AutoCompletionListItem(key, AutoCompletionItemPritority.IS_IN_DATASET) 55 ); 56 } 57 autoCompletionList.fireTableDataChanged(); 31 autoCompletionList = new AutoCompletionList(); 32 editor.setAutoCompletionList(autoCompletionList); 58 33 } 59 34 … … 66 41 String role = (String)value; 67 42 editor.setText(role); 68 initAutoCompletionListRoles(); 43 System.out.println(role + " - initializing autocompletion list ..."); 44 AutoCompletionCache.getCacheForLayer(Main.main.getEditLayer()).populateWithMemberRoles(autoCompletionList); 45 autoCompletionList.dump(); 69 46 return editor; 70 47 } … … 83 60 return super.stopCellEditing(); 84 61 } 85 86 /**87 * replies the {@link AutoCompletionList} this table cell editor synchronizes with88 *89 * @return the auto completion list90 */91 public AutoCompletionList getAutoCompletionList() {92 return autoCompletionList;93 }94 95 /**96 * sets the {@link AutoCompletionList} this table cell editor synchronizes with97 * @param autoCompletionList the auto completion list98 */99 public void setAutoCompletionList(AutoCompletionList autoCompletionList) {100 this.autoCompletionList = autoCompletionList;101 editor.setAutoCompletionList(autoCompletionList);102 }103 104 public void setAutoCompletionCache(AutoCompletionCache acCache) {105 this.acCache = acCache;106 }107 108 public AutoCompletingTextField getEditor() {109 return editor;110 }111 62 } -
trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorPanel.java
r2048 r2156 5 5 6 6 import java.awt.BorderLayout; 7 import java.awt.Component;8 7 import java.awt.GridBagConstraints; 9 8 import java.awt.GridBagLayout; -
trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionList.java
r2088 r2156 272 272 */ 273 273 public void clear() { 274 valutToItemMap.clear(); 274 275 list.clear(); 275 276 fireTableDataChanged(); … … 290 291 } 291 292 293 public void dump() { 294 System.out.println("---------------------------------"); 295 for (AutoCompletionListItem item: list) { 296 System.out.println(item.getValue()); 297 } 298 System.out.println("---------------------------------"); 299 } 292 300 }
Note:
See TracChangeset
for help on using the changeset viewer.