Changeset 2974 in josm for trunk/src/org/openstreetmap/josm
- Timestamp:
- 2010-02-13T17:45:10+01:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetTagsPanel.java
r2711 r2974 7 7 8 8 import javax.swing.BorderFactory; 9 import javax.swing.DefaultListSelectionModel; 9 10 import javax.swing.JPanel; 10 11 import javax.swing.JScrollPane; … … 26 27 setLayout(new BorderLayout()); 27 28 setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 29 DefaultListSelectionModel rowSelectionModel = new DefaultListSelectionModel(); 30 DefaultListSelectionModel colSelectionModel = new DefaultListSelectionModel(); 28 31 29 tblTags = new TagTable(model = new TagEditorModel()); 32 model = new TagEditorModel(rowSelectionModel, colSelectionModel); 33 tblTags = new TagTable(model, rowSelectionModel, colSelectionModel); 30 34 tblTags.setEnabled(false); 31 35 add(new JScrollPane(tblTags), BorderLayout.CENTER); -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
r2915 r2974 26 26 import java.util.Iterator; 27 27 import java.util.List; 28 import java.util.logging.Logger; 28 29 29 30 import javax.swing.AbstractAction; … … 76 77 */ 77 78 public class GenericRelationEditor extends RelationEditor { 78 //static private final Logger logger = Logger.getLogger(GenericRelationEditor.class.getName());79 static private final Logger logger = Logger.getLogger(GenericRelationEditor.class.getName()); 79 80 80 81 /** the tag table and its model */ -
trunk/src/org/openstreetmap/josm/gui/tagging/TagCellEditor.java
r2946 r2974 10 10 11 11 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionCache; 12 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionItemPritority;13 12 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList; 14 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem;15 13 16 14 /** … … 26 24 private AutoCompletingTextField editor = null; 27 25 private TagModel currentTag = null; 28 private TagEditorModel tagEditorModel = null;29 private int currentColumn = 0;30 26 31 27 /** the cache of auto completion items derived from the current JOSM data set */ … … 99 95 if (column == 0) { 100 96 editor.setText(currentTag.getName()); 101 currentColumn = 0;102 97 TagEditorModel model = (TagEditorModel)table.getModel(); 103 98 initAutoCompletionListForKeys(model, currentTag); … … 112 107 editor.setText(""); 113 108 } 114 currentColumn = 1;115 109 initAutoCompletionListForValues(currentTag.getName()); 116 110 return editor; … … 123 117 public Object getCellEditorValue() { 124 118 return editor.getText(); 125 }126 127 @Override128 public void cancelCellEditing() {129 super.cancelCellEditing();130 }131 132 @Override133 public boolean stopCellEditing() {134 if (tagEditorModel == null) {135 logger.warning("no tag editor model set. Can't update edited values. Please set tag editor model first");136 return super.stopCellEditing();137 }138 139 if (currentColumn == 0) {140 tagEditorModel.updateTagName(currentTag, editor.getText());141 } else if (currentColumn == 1){142 if (currentTag.getValueCount() > 1 && ! editor.getText().equals("")) {143 tagEditorModel.updateTagValue(currentTag, editor.getText());144 } else if (currentTag.getValueCount() <= 1) {145 tagEditorModel.updateTagValue(currentTag, editor.getText());146 }147 }148 return super.stopCellEditing();149 119 } 150 120 … … 180 150 return editor; 181 151 } 182 183 /**184 * sets the tag editor model185 *186 * @param tagEditorModel the tag editor model187 */188 public void setTagEditorModel(TagEditorModel tagEditorModel) {189 this.tagEditorModel = tagEditorModel;190 }191 152 } -
trunk/src/org/openstreetmap/josm/gui/tagging/TagCellRenderer.java
r2512 r2974 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Color;7 6 import java.awt.Component; 8 7 import java.awt.Font; 9 8 import java.util.logging.Logger; 10 9 11 import javax.swing.BorderFactory;12 import javax.swing.ImageIcon;13 10 import javax.swing.JLabel; 14 11 import javax.swing.JTable; 15 import javax.swing. border.Border;12 import javax.swing.UIManager; 16 13 import javax.swing.border.EmptyBorder; 17 14 import javax.swing.table.TableCellRenderer; … … 25 22 public class TagCellRenderer extends JLabel implements TableCellRenderer { 26 23 27 private static Logger logger = Logger.getLogger(TagCellRenderer.class.getName()); 28 29 public static final Color BG_COLOR_SELECTED = new Color(143,170,255); 30 public static final Color BG_COLOR_HIGHLIGHTED = new Color(255,255,204); 31 32 public static final Border BORDER_EMPHASIZED = BorderFactory.createLineBorder(new Color(253,75,45)); 33 34 /** the icon displayed for deleting a tag */ 35 private ImageIcon deleteIcon = null; 24 private static final Logger logger = Logger.getLogger(TagCellRenderer.class.getName()); 36 25 37 26 private Font fontStandard = null; … … 39 28 40 29 public TagCellRenderer() { 41 fontStandard = getFont();30 fontStandard = UIManager.getFont("Table.font"); 42 31 fontItalic = fontStandard.deriveFont(Font.ITALIC); 43 32 setOpaque(true); … … 67 56 setText(tag.getValues().get(0)); 68 57 } else if (tag.getValueCount() > 1) { 69 setText(tr(" <multiple>"));58 setText(tr("multiple")); 70 59 setFont(fontItalic); 71 60 } … … 86 75 87 76 /** 88 * renders the background color. The default color is white. It is 89 * set to {@see TableCellRenderer#BG_COLOR_HIGHLIGHTED} if this cell 90 * displays the tag which is suggested by the currently selected 91 * preset. 92 * 77 * renders the background color. 78 * 93 79 * @param tagModel the tag model 94 80 * @param model the tag editor model 95 81 */ 96 82 protected void renderBackgroundColor(TagModel tagModel, TagEditorModel model) { 97 setBackground( Color.WHITE); // standard color83 setBackground(UIManager.getColor("Table.background")); // standard color 98 84 } 99 85 … … 117 103 // 118 104 if (isSelected){ 119 setBackground(BG_COLOR_SELECTED); 105 setBackground(UIManager.getColor("Table.selectionBackground")); 106 setForeground(UIManager.getColor("Table.selectionForeground")); 120 107 } else { 121 108 renderBackgroundColor(getModel(table).get(rowIndex), getModel(table)); … … 130 117 if (hasFocus && isSelected) { 131 118 if (table.getSelectedColumnCount() == 1 && table.getSelectedRowCount() == 1) { 132 boolean success = table.editCellAt(rowIndex, vColIndex);133 134 119 if (table.getEditorComponent() != null) { 135 120 table.getEditorComponent().requestFocusInWindow(); -
trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorModel.java
r2599 r2974 15 15 import java.util.logging.Logger; 16 16 17 import javax.swing.DefaultListSelectionModel; 17 18 import javax.swing.table.AbstractTableModel; 18 19 … … 42 43 private boolean dirty = false; 43 44 private PropertyChangeSupport propChangeSupport = null; 45 private DefaultListSelectionModel rowSelectionModel; 46 private DefaultListSelectionModel colSelectionModel; 44 47 45 48 /** 46 49 * constructor 47 50 */ 48 public TagEditorModel( ){51 public TagEditorModel(DefaultListSelectionModel rowSelectionModel, DefaultListSelectionModel colSelectionModel){ 49 52 tags = new ArrayList<TagModel>(); 50 53 propChangeSupport = new PropertyChangeSupport(this); 54 this.rowSelectionModel = rowSelectionModel; 55 this.colSelectionModel = colSelectionModel; 51 56 } 52 57 … … 86 91 switch(columnIndex) { 87 92 case 0: 88 case 1: return tag; 93 case 1: 94 return tag; 89 95 90 96 default: 91 97 throw new IndexOutOfBoundsException("unexpected columnIndex: columnIndex=" + columnIndex); 98 } 99 } 100 101 @Override 102 public void setValueAt(Object value, int row, int col) { 103 TagModel tag = get(row); 104 if (tag == null) return; 105 switch(col) { 106 case 0: 107 updateTagName(tag, (String)value); 108 break; 109 case 1: 110 String v = (String)value; 111 if (tag.getValueCount() > 1 && ! v.equals("")) { 112 updateTagValue(tag, v); 113 } else if (tag.getValueCount() <= 1) { 114 updateTagValue(tag, v); 115 } 92 116 } 93 117 } … … 166 190 167 191 public TagModel get(int idx) { 192 if (idx >= tags.size()) return null; 168 193 TagModel tagModel = tags.get(idx); 169 194 return tagModel; … … 453 478 setDirty(true); 454 479 } 455 fireTableDataChanged(); 480 SelectionStateMemento memento = new SelectionStateMemento(); 481 fireTableDataChanged(); 482 memento.apply(); 456 483 } 457 484 … … 469 496 setDirty(true); 470 497 } 471 fireTableDataChanged(); 498 SelectionStateMemento memento = new SelectionStateMemento(); 499 fireTableDataChanged(); 500 memento.apply(); 472 501 } 473 502 … … 480 509 return dirty; 481 510 } 511 512 class SelectionStateMemento { 513 private int rowMin; 514 private int rowMax; 515 private int colMin; 516 private int colMax; 517 518 public SelectionStateMemento() { 519 rowMin = rowSelectionModel.getMinSelectionIndex(); 520 rowMax = rowSelectionModel.getMaxSelectionIndex(); 521 colMin = colSelectionModel.getMinSelectionIndex(); 522 colMax = colSelectionModel.getMaxSelectionIndex(); 523 } 524 525 public void apply() { 526 rowSelectionModel.setValueIsAdjusting(true); 527 colSelectionModel.setValueIsAdjusting(true); 528 if (rowMin >= 0 && rowMax >=0) { 529 rowSelectionModel.setSelectionInterval(rowMin, rowMax); 530 } 531 if (colMin >=0 && colMax >= 0) { 532 colSelectionModel.setSelectionInterval(colMin, colMax); 533 } 534 rowSelectionModel.setValueIsAdjusting(false); 535 colSelectionModel.setValueIsAdjusting(false); 536 } 537 } 482 538 } -
trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorPanel.java
r2599 r2974 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.tagging; 3 4 import static org.openstreetmap.josm.tools.I18n.tr;5 3 6 4 import java.awt.BorderLayout; … … 8 6 import java.awt.GridBagLayout; 9 7 import java.awt.Insets; 10 import java.awt.event.ActionEvent; 11 import java.beans.PropertyChangeEvent; 12 import java.beans.PropertyChangeListener; 8 import java.util.logging.Logger; 13 9 14 import javax.swing.AbstractAction;15 10 import javax.swing.BoxLayout; 11 import javax.swing.DefaultListSelectionModel; 16 12 import javax.swing.JButton; 17 13 import javax.swing.JPanel; 18 14 import javax.swing.JScrollPane; 19 import javax.swing.event.ListSelectionEvent;20 import javax.swing.event.ListSelectionListener;21 15 22 16 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 23 17 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionCache; 24 18 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList; 25 import org.openstreetmap.josm.tools.ImageProvider;26 19 27 20 /** 28 21 * TagEditorPanel is a {@see JPanel} which can be embedded as UI component in 29 22 * UIs. It provides a spreadsheet like tabular control for editing tag names 30 * and tag values. Two action buttons are placed on the left, one for addi ting23 * and tag values. Two action buttons are placed on the left, one for adding 31 24 * a new tag and one for deleting the currently selected tags. 32 *33 25 * 34 26 */ 35 27 public class TagEditorPanel extends JPanel { 28 static private final Logger logger = Logger.getLogger(TagEditorPanel.class.getName()); 36 29 /** the tag editor model */ 37 30 private TagEditorModel model; … … 50 43 51 44 JPanel pnl = new JPanel(); 52 model = new TagEditorModel(); 53 tagTable = new TagTable(model); 45 DefaultListSelectionModel rowSelectionModel = new DefaultListSelectionModel(); 46 DefaultListSelectionModel colSelectionModel = new DefaultListSelectionModel(); 47 48 model = new TagEditorModel(rowSelectionModel, colSelectionModel); 49 tagTable = new TagTable(model, rowSelectionModel, colSelectionModel); 54 50 55 51 pnl.setLayout(new BorderLayout()); … … 69 65 // add action 70 66 // 71 AddAction addAction = new AddAction();72 67 JButton btn; 73 pnl.add(btn = new JButton( addAction));68 pnl.add(btn = new JButton(tagTable.getAddAction())); 74 69 btn.setMargin(new Insets(0,0,0,0)); 75 tagTable.add PropertyChangeListener(addAction);70 tagTable.addComponentNotStoppingCellEditing(btn); 76 71 77 72 // delete action 78 // 79 DeleteAction deleteAction = new DeleteAction(); 80 tagTable.getSelectionModel().addListSelectionListener(deleteAction); 81 tagTable.addPropertyChangeListener(deleteAction); 82 pnl.add(btn = new JButton(deleteAction)); 73 pnl.add(btn = new JButton(tagTable.getDeleteAction())); 83 74 btn.setMargin(new Insets(0,0,0,0)); 75 tagTable.addComponentNotStoppingCellEditing(btn); 84 76 return pnl; 85 77 } … … 129 121 } 130 122 131 /**132 * The action for adding a tag133 *134 */135 class AddAction extends AbstractAction implements PropertyChangeListener {136 public AddAction() {137 putValue(SMALL_ICON, ImageProvider.get("dialogs", "add"));138 putValue(SHORT_DESCRIPTION, tr("Add a new tag"));139 updateEnabledState();140 }141 142 public void actionPerformed(ActionEvent e) {143 model.appendNewTag();144 }145 146 protected void updateEnabledState() {147 setEnabled(tagTable.isEnabled());148 }149 150 public void propertyChange(PropertyChangeEvent evt) {151 updateEnabledState();152 }153 }154 155 /**156 * The action for deleting the currently selected tags157 *158 *159 */160 class DeleteAction extends AbstractAction implements ListSelectionListener, PropertyChangeListener {161 public DeleteAction() {162 putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete"));163 putValue(SHORT_DESCRIPTION, tr("Delete the selection in the tag table"));164 updateEnabledState();165 }166 167 public void actionPerformed(ActionEvent e) {168 run();169 }170 171 /**172 * delete a selection of tag names173 */174 protected void deleteTagNames() {175 int[] rows = tagTable.getSelectedRows();176 model.deleteTagNames(rows);177 }178 179 /**180 * delete a selection of tag values181 */182 protected void deleteTagValues() {183 int[] rows = tagTable.getSelectedRows();184 model.deleteTagValues(rows);185 }186 187 /**188 * delete a selection of tags189 */190 protected void deleteTags() {191 model.deleteTags(tagTable.getSelectedRows());192 }193 194 public void run() {195 if (!isEnabled())196 return;197 if (tagTable.getSelectedColumnCount() == 1) {198 if (tagTable.getSelectedColumn() == 0) {199 deleteTagNames();200 } else if (tagTable.getSelectedColumn() == 1) {201 deleteTagValues();202 } else203 // should not happen204 //205 throw new IllegalStateException("unexpected selected column: getSelectedColumn() is "206 + tagTable.getSelectedColumn());207 } else if (tagTable.getSelectedColumnCount() == 2) {208 deleteTags();209 }210 if (model.getRowCount() == 0) {211 model.ensureOneTag();212 }213 }214 215 public void updateEnabledState() {216 setEnabled(tagTable.isEnabled() &&217 (tagTable.getSelectedRowCount() > 0 || tagTable.getSelectedColumnCount() >0));218 }219 public void valueChanged(ListSelectionEvent e) {220 updateEnabledState();221 }222 223 public void propertyChange(PropertyChangeEvent evt) {224 updateEnabledState();225 }226 }227 228 123 public void initAutoCompletion(OsmDataLayer layer) { 229 124 // initialize the autocompletion infrastructure -
trunk/src/org/openstreetmap/josm/gui/tagging/TagTable.java
r2626 r2974 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.applet.Applet; 6 7 import java.awt.AWTException; 8 import java.awt.Component; 7 9 import java.awt.Container; 8 10 import java.awt.Dimension; 11 import java.awt.KeyboardFocusManager; 9 12 import java.awt.MouseInfo; 10 13 import java.awt.Point; 11 14 import java.awt.Rectangle; 12 15 import java.awt.Robot; 16 import java.awt.Window; 13 17 import java.awt.event.ActionEvent; 14 18 import java.awt.event.InputEvent; 15 19 import java.awt.event.KeyEvent; 16 20 import java.awt.event.KeyListener; 21 import java.beans.PropertyChangeEvent; 22 import java.beans.PropertyChangeListener; 23 import java.util.EventObject; 24 import java.util.concurrent.CopyOnWriteArrayList; 17 25 import java.util.logging.Level; 18 26 import java.util.logging.Logger; 19 27 20 28 import javax.swing.AbstractAction; 21 import javax.swing.Action; 29 import javax.swing.CellEditor; 30 import javax.swing.DefaultListSelectionModel; 22 31 import javax.swing.JComponent; 23 32 import javax.swing.JTable; … … 35 44 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionCache; 36 45 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList; 46 import org.openstreetmap.josm.tools.ImageProvider; 37 47 38 48 /** … … 40 50 * 41 51 */ 42 @SuppressWarnings("serial")43 52 public class TagTable extends JTable { 44 53 45 private static Logger logger = Logger.getLogger(TagTable.class.getName());54 private static final Logger logger = Logger.getLogger(TagTable.class.getName()); 46 55 47 56 /** the table cell editor used by this table */ 48 57 private TagCellEditor editor = null; 49 58 59 /** a list of components to which focus can be transferred withouth stopping 60 * cell editing this table. 61 */ 62 private final CopyOnWriteArrayList<Component> doNotStopCellEditingWhenFocused = new CopyOnWriteArrayList<Component>(); 63 private CellEditorRemover editorRemover; 64 50 65 /** 51 66 * The table has two columns. The first column is used for editing rendering and … … 54 69 */ 55 70 static class TagTableColumnModel extends DefaultTableColumnModel { 56 57 public TagTableColumnModel() {71 public TagTableColumnModel(DefaultListSelectionModel selectionModel) { 72 setSelectionModel(selectionModel); 58 73 TableColumn col = null; 59 74 TagCellRenderer renderer = new TagCellRenderer(); … … 72 87 col.setCellRenderer(renderer); 73 88 addColumn(col); 74 75 89 } 76 90 } … … 85 99 * last cell in the table</li> 86 100 * <ul> 87 *88 * @author gubaer89 101 * 90 102 */ … … 167 179 class DeleteAction extends RunnableAction implements ListSelectionListener { 168 180 181 public DeleteAction() { 182 putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete")); 183 putValue(SHORT_DESCRIPTION, tr("Delete the selection in the tag table")); 184 getSelectionModel().addListSelectionListener(this); 185 getColumnModel().getSelectionModel().addListSelectionListener(this); 186 updateEnabledState(); 187 } 188 169 189 /** 170 190 * delete a selection of tag names … … 194 214 } 195 215 196 /**197 * constructor198 */199 public DeleteAction() {200 putValue(Action.NAME, tr("Delete"));201 getSelectionModel().addListSelectionListener(this);202 getColumnModel().getSelectionModel().addListSelectionListener(this);203 }204 205 216 @Override 206 217 public void run() { 207 218 if (!isEnabled()) 208 219 return; 209 getCellEditor().stopCellEditing();210 if (getSelectedColumnCount() == 1) {220 switch(getSelectedColumnCount()) { 221 case 1: 211 222 if (getSelectedColumn() == 0) { 212 223 deleteTagNames(); … … 216 227 // should not happen 217 228 // 218 throw new IllegalStateException("unexpected selected clolumn: getSelectedColumn() is " + getSelectedColumn()); 219 } else if (getSelectedColumnCount() == 2) { 229 throw new IllegalStateException("unexpected selected column: getSelectedColumn() is " + getSelectedColumn()); 230 break; 231 case 2: 220 232 deleteTags(); 221 } 233 break; 234 } 235 236 if (isEditing()) { 237 CellEditor editor = getCellEditor(); 238 if (editor != null) { 239 editor.cancelCellEditing(); 240 } 241 } 242 222 243 TagEditorModel model = (TagEditorModel)getModel(); 223 244 if (model.getRowCount() == 0) { … … 231 252 */ 232 253 public void valueChanged(ListSelectionEvent e) { 254 updateEnabledState(); 255 } 256 257 protected void updateEnabledState() { 233 258 if (isEditing() && getSelectedColumnCount() == 1 && getSelectedRowCount() == 1) { 234 259 setEnabled(false); … … 240 265 setEnabled(false); 241 266 } 242 243 267 } 244 268 } … … 249 273 * 250 274 */ 251 class AddAction extends RunnableAction { 252 275 class AddAction extends RunnableAction implements PropertyChangeListener{ 253 276 public AddAction() { 254 putValue(Action.NAME, tr("Add")); 277 putValue(SMALL_ICON, ImageProvider.get("dialogs", "add")); 278 putValue(SHORT_DESCRIPTION, tr("Add a new tag")); 279 TagTable.this.addPropertyChangeListener(this); 280 updateEnabledState(); 255 281 } 256 282 257 283 @Override 258 284 public void run() { 259 getCellEditor().stopCellEditing(); 285 CellEditor editor = getCellEditor(); 286 if (editor != null) { 287 getCellEditor().stopCellEditing(); 288 } 260 289 ((TagEditorModel)getModel()).appendNewTag(); 261 290 final int rowIdx = getModel().getRowCount()-1; 262 291 requestFocusInCell(rowIdx, 0); 263 292 } 293 294 protected void updateEnabledState() { 295 setEnabled(TagTable.this.isEnabled()); 296 } 297 298 public void propertyChange(PropertyChangeEvent evt) { 299 updateEnabledState(); 300 } 264 301 } 265 302 … … 287 324 protected void init() { 288 325 setAutoResizeMode(JTable.AUTO_RESIZE_OFF); 289 setCellSelectionEnabled(true); 326 //setCellSelectionEnabled(true); 327 setRowSelectionAllowed(true); 328 setColumnSelectionAllowed(true); 290 329 setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); 291 putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);292 330 293 331 // make ENTER behave like TAB … … 316 354 // 317 355 editor = new TagCellEditor(); 318 editor.setTagEditorModel((TagEditorModel)getModel());319 356 getColumnModel().getColumn(0).setCellEditor(editor); 320 357 getColumnModel().getColumn(1).setCellEditor(editor); 358 359 getSelectionModel().addListSelectionListener(new ListSelectionListener() { 360 361 public void valueChanged(ListSelectionEvent e) { 362 ListSelectionModel rm = getSelectionModel(); 363 ListSelectionModel cm = getColumnModel().getSelectionModel(); 364 } 365 }); 321 366 } 322 367 … … 327 372 * @param columnModel 328 373 */ 329 public TagTable(TableModel model ) {330 super(model, new TagTableColumnModel( ));374 public TagTable(TableModel model, DefaultListSelectionModel rowSelectionModel, DefaultListSelectionModel colSelectionModel) { 375 super(model, new TagTableColumnModel(colSelectionModel), rowSelectionModel); 331 376 init(); 332 377 } … … 430 475 } 431 476 } 477 478 public void addComponentNotStoppingCellEditing(Component component) { 479 if (component == null) return; 480 doNotStopCellEditingWhenFocused.addIfAbsent(component); 481 } 482 483 public void removeComponentNotStoppingCellEditing(Component component) { 484 if (component == null) return; 485 doNotStopCellEditingWhenFocused.remove(component); 486 } 487 488 @Override 489 public boolean editCellAt(int row, int column, EventObject e){ 490 491 // a snipped copied from the Java 1.5 implementation of JTable 492 // 493 if (cellEditor != null && !cellEditor.stopCellEditing()) 494 return false; 495 496 if (row < 0 || row >= getRowCount() || 497 column < 0 || column >= getColumnCount()) 498 return false; 499 500 if (!isCellEditable(row, column)) 501 return false; 502 503 // make sure our custom implementation of CellEditorRemover is created 504 if (editorRemover == null) { 505 KeyboardFocusManager fm = 506 KeyboardFocusManager.getCurrentKeyboardFocusManager(); 507 editorRemover = new CellEditorRemover(fm); 508 fm.addPropertyChangeListener("permanentFocusOwner", editorRemover); 509 } 510 511 // delegate to the default implementation 512 return super.editCellAt(row, column,e); 513 } 514 515 516 @Override 517 public void removeEditor() { 518 // make sure we unregister our custom implementation of CellEditorRemover 519 KeyboardFocusManager.getCurrentKeyboardFocusManager(). 520 removePropertyChangeListener("permanentFocusOwner", editorRemover); 521 editorRemover = null; 522 super.removeEditor(); 523 } 524 525 @Override 526 public void removeNotify() { 527 // make sure we unregister our custom implementation of CellEditorRemover 528 KeyboardFocusManager.getCurrentKeyboardFocusManager(). 529 removePropertyChangeListener("permanentFocusOwner", editorRemover); 530 editorRemover = null; 531 super.removeNotify(); 532 } 533 534 /** 535 * This is a custom implementation of the CellEditorRemover used in JTable 536 * to handle the client property <tt>terminateEditOnFocusLost</tt>. 537 * 538 * This implementation also checks whether focus is transferred to one of a list 539 * of dedicated components, see {@see TagTable#doNotStopCellEditingWhenFocused}. 540 * A typical example for such a component is a button in {@see TagEditorPanel} 541 * which isn't a child component of {@see TagTable} but which should respond to 542 * to focus transfer in a similar way to a child of TagTable. 543 * 544 */ 545 class CellEditorRemover implements PropertyChangeListener { 546 KeyboardFocusManager focusManager; 547 548 public CellEditorRemover(KeyboardFocusManager fm) { 549 this.focusManager = fm; 550 } 551 552 public void propertyChange(PropertyChangeEvent ev) { 553 if (!isEditing()) 554 return; 555 556 Component c = focusManager.getPermanentFocusOwner(); 557 while (c != null) { 558 if (c == TagTable.this) 559 // focus remains inside the table 560 return; 561 if (doNotStopCellEditingWhenFocused.contains(c)) 562 // focus remains on one of the associated components 563 return; 564 else if ((c instanceof Window) || 565 (c instanceof Applet && c.getParent() == null)) { 566 if (c == SwingUtilities.getRoot(TagTable.this)) { 567 if (!getCellEditor().stopCellEditing()) { 568 getCellEditor().cancelCellEditing(); 569 } 570 } 571 break; 572 } 573 c = c.getParent(); 574 } 575 } 576 } 432 577 } -
trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionCache.java
r2960 r2974 147 147 if (item instanceof TaggingPreset.Check) { 148 148 TaggingPreset.Check ch = (TaggingPreset.Check) item; 149 if (ch.key == null) continue; 149 if (ch.key == null) { 150 continue; 151 } 150 152 presetTagCache.put(ch.key, OsmUtils.falseval); 151 153 presetTagCache.put(ch.key, OsmUtils.trueval); 152 154 } else if (item instanceof TaggingPreset.Combo) { 153 155 TaggingPreset.Combo co = (TaggingPreset.Combo) item; 154 if (co.key == null || co.values == null) continue; 156 if (co.key == null || co.values == null) { 157 continue; 158 } 155 159 for (String value : co.values.split(",")) { 156 160 presetTagCache.put(co.key, value); … … 158 162 } else if (item instanceof TaggingPreset.Key) { 159 163 TaggingPreset.Key ky = (TaggingPreset.Key) item; 160 if (ky.key == null || ky.value == null) continue; 164 if (ky.key == null || ky.value == null) { 165 continue; 166 } 161 167 presetTagCache.put(ky.key, ky.value); 162 168 } else if (item instanceof TaggingPreset.Text) { 163 169 TaggingPreset.Text tt = (TaggingPreset.Text) item; 164 if (tt.key == null) continue; 170 if (tt.key == null) { 171 continue; 172 } 165 173 presetTagCache.putVoid(tt.key); 166 174 if (tt.default_ != null && !tt.default_.equals("")) { … … 171 179 } 172 180 } 173 181 174 182 /** 175 183 * replies the keys held by the cache
Note:
See TracChangeset
for help on using the changeset viewer.