Changeset 2974 in josm for trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorPanel.java
- Timestamp:
- 13.02.2010 17:45:10 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.
