Changeset 2974 in josm


Ignore:
Timestamp:
13.02.2010 17:45:10 (2 years ago)
Author:
Gubaer
Message:

fixed #4506: relation-editor: tag-delete-button does not work
removed duplicated code
fixed selection behaviour for tags tag in RelationEditor and UploadDialog

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  
    77 
    88import javax.swing.BorderFactory; 
     9import javax.swing.DefaultListSelectionModel; 
    910import javax.swing.JPanel; 
    1011import javax.swing.JScrollPane; 
     
    2627        setLayout(new BorderLayout()); 
    2728        setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 
     29        DefaultListSelectionModel rowSelectionModel = new DefaultListSelectionModel(); 
     30        DefaultListSelectionModel colSelectionModel = new DefaultListSelectionModel(); 
    2831 
    29         tblTags = new TagTable(model = new TagEditorModel()); 
     32        model = new TagEditorModel(rowSelectionModel, colSelectionModel); 
     33        tblTags = new TagTable(model, rowSelectionModel, colSelectionModel); 
    3034        tblTags.setEnabled(false); 
    3135        add(new JScrollPane(tblTags), BorderLayout.CENTER); 
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java

    r2915 r2974  
    2626import java.util.Iterator; 
    2727import java.util.List; 
     28import java.util.logging.Logger; 
    2829 
    2930import javax.swing.AbstractAction; 
     
    7677 */ 
    7778public 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()); 
    7980 
    8081    /** the tag table and its model */ 
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagCellEditor.java

    r2946 r2974  
    1010 
    1111import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionCache; 
    12 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionItemPritority; 
    1312import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList; 
    14 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem; 
    1513 
    1614/** 
     
    2624    private AutoCompletingTextField editor = null; 
    2725    private TagModel currentTag = null; 
    28     private TagEditorModel tagEditorModel = null; 
    29     private int currentColumn = 0; 
    3026 
    3127    /** the cache of auto completion items derived from the current JOSM data set */ 
     
    9995        if (column == 0) { 
    10096            editor.setText(currentTag.getName()); 
    101             currentColumn = 0; 
    10297            TagEditorModel model = (TagEditorModel)table.getModel(); 
    10398            initAutoCompletionListForKeys(model, currentTag); 
     
    112107                editor.setText(""); 
    113108            } 
    114             currentColumn = 1; 
    115109            initAutoCompletionListForValues(currentTag.getName()); 
    116110            return editor; 
     
    123117    public Object getCellEditorValue() { 
    124118        return editor.getText(); 
    125     } 
    126  
    127     @Override 
    128     public void cancelCellEditing() { 
    129         super.cancelCellEditing(); 
    130     } 
    131  
    132     @Override 
    133     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(); 
    149119    } 
    150120 
     
    180150        return editor; 
    181151    } 
    182  
    183     /** 
    184      * sets the tag editor model 
    185      * 
    186      * @param tagEditorModel  the tag editor model 
    187      */ 
    188     public void setTagEditorModel(TagEditorModel tagEditorModel) { 
    189         this.tagEditorModel = tagEditorModel; 
    190     } 
    191152} 
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagCellRenderer.java

    r2512 r2974  
    44import static org.openstreetmap.josm.tools.I18n.tr; 
    55 
    6 import java.awt.Color; 
    76import java.awt.Component; 
    87import java.awt.Font; 
    98import java.util.logging.Logger; 
    109 
    11 import javax.swing.BorderFactory; 
    12 import javax.swing.ImageIcon; 
    1310import javax.swing.JLabel; 
    1411import javax.swing.JTable; 
    15 import javax.swing.border.Border; 
     12import javax.swing.UIManager; 
    1613import javax.swing.border.EmptyBorder; 
    1714import javax.swing.table.TableCellRenderer; 
     
    2522public class TagCellRenderer extends JLabel implements TableCellRenderer  { 
    2623 
    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()); 
    3625 
    3726    private Font fontStandard = null; 
     
    3928 
    4029    public TagCellRenderer() { 
    41         fontStandard = getFont(); 
     30        fontStandard = UIManager.getFont("Table.font"); 
    4231        fontItalic = fontStandard.deriveFont(Font.ITALIC); 
    4332        setOpaque(true); 
     
    6756            setText(tag.getValues().get(0)); 
    6857        } else if (tag.getValueCount() >  1) { 
    69             setText(tr("<multiple>")); 
     58            setText(tr("multiple")); 
    7059            setFont(fontItalic); 
    7160        } 
     
    8675 
    8776    /** 
    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     *  
    9379     * @param tagModel the tag model 
    9480     * @param model the tag editor model 
    9581     */ 
    9682    protected void renderBackgroundColor(TagModel tagModel, TagEditorModel model) { 
    97         setBackground(Color.WHITE); // standard color 
     83        setBackground(UIManager.getColor("Table.background")); // standard color 
    9884    } 
    9985 
     
    117103        // 
    118104        if (isSelected){ 
    119             setBackground(BG_COLOR_SELECTED); 
     105            setBackground(UIManager.getColor("Table.selectionBackground")); 
     106            setForeground(UIManager.getColor("Table.selectionForeground")); 
    120107        } else { 
    121108            renderBackgroundColor(getModel(table).get(rowIndex), getModel(table)); 
     
    130117        if (hasFocus && isSelected) { 
    131118            if (table.getSelectedColumnCount() == 1 && table.getSelectedRowCount() == 1) { 
    132                 boolean success = table.editCellAt(rowIndex, vColIndex); 
    133  
    134119                if (table.getEditorComponent() != null) { 
    135120                    table.getEditorComponent().requestFocusInWindow(); 
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorModel.java

    r2599 r2974  
    1515import java.util.logging.Logger; 
    1616 
     17import javax.swing.DefaultListSelectionModel; 
    1718import javax.swing.table.AbstractTableModel; 
    1819 
     
    4243    private boolean dirty =  false; 
    4344    private PropertyChangeSupport propChangeSupport = null; 
     45    private DefaultListSelectionModel rowSelectionModel; 
     46    private DefaultListSelectionModel colSelectionModel; 
    4447 
    4548    /** 
    4649     * constructor 
    4750     */ 
    48     public TagEditorModel(){ 
     51    public TagEditorModel(DefaultListSelectionModel rowSelectionModel, DefaultListSelectionModel colSelectionModel){ 
    4952        tags = new ArrayList<TagModel>(); 
    5053        propChangeSupport = new PropertyChangeSupport(this); 
     54        this.rowSelectionModel = rowSelectionModel; 
     55        this.colSelectionModel  = colSelectionModel; 
    5156    } 
    5257 
     
    8691        switch(columnIndex) { 
    8792        case 0: 
    88         case 1: return tag; 
     93        case 1: 
     94            return tag; 
    8995 
    9096        default: 
    9197            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            } 
    92116        } 
    93117    } 
     
    166190 
    167191    public TagModel get(int idx) { 
     192        if (idx >= tags.size()) return null; 
    168193        TagModel tagModel = tags.get(idx); 
    169194        return tagModel; 
     
    453478            setDirty(true); 
    454479        } 
    455         fireTableDataChanged(); 
     480        SelectionStateMemento memento = new SelectionStateMemento(); 
     481        fireTableDataChanged(); 
     482        memento.apply(); 
    456483    } 
    457484 
     
    469496            setDirty(true); 
    470497        } 
    471         fireTableDataChanged(); 
     498        SelectionStateMemento memento = new SelectionStateMemento(); 
     499        fireTableDataChanged(); 
     500        memento.apply(); 
    472501    } 
    473502 
     
    480509        return dirty; 
    481510    } 
     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    } 
    482538} 
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorPanel.java

    r2599 r2974  
    11// License: GPL. For details, see LICENSE file. 
    22package org.openstreetmap.josm.gui.tagging; 
    3  
    4 import static org.openstreetmap.josm.tools.I18n.tr; 
    53 
    64import java.awt.BorderLayout; 
     
    86import java.awt.GridBagLayout; 
    97import java.awt.Insets; 
    10 import java.awt.event.ActionEvent; 
    11 import java.beans.PropertyChangeEvent; 
    12 import java.beans.PropertyChangeListener; 
     8import java.util.logging.Logger; 
    139 
    14 import javax.swing.AbstractAction; 
    1510import javax.swing.BoxLayout; 
     11import javax.swing.DefaultListSelectionModel; 
    1612import javax.swing.JButton; 
    1713import javax.swing.JPanel; 
    1814import javax.swing.JScrollPane; 
    19 import javax.swing.event.ListSelectionEvent; 
    20 import javax.swing.event.ListSelectionListener; 
    2115 
    2216import org.openstreetmap.josm.gui.layer.OsmDataLayer; 
    2317import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionCache; 
    2418import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList; 
    25 import org.openstreetmap.josm.tools.ImageProvider; 
    2619 
    2720/** 
    2821 * TagEditorPanel is a {@see JPanel} which can be embedded as UI component in 
    2922 * 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 additing 
     23 * and tag values. Two action buttons are placed on the left, one for adding 
    3124 * a new tag and one for deleting the currently selected tags. 
    32  * 
    3325 * 
    3426 */ 
    3527public class TagEditorPanel extends JPanel { 
     28    static private final Logger logger = Logger.getLogger(TagEditorPanel.class.getName()); 
    3629    /** the tag editor model */ 
    3730    private TagEditorModel model; 
     
    5043 
    5144        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); 
    5450 
    5551        pnl.setLayout(new BorderLayout()); 
     
    6965        // add action 
    7066        // 
    71         AddAction addAction = new AddAction(); 
    7267        JButton btn; 
    73         pnl.add(btn = new JButton(addAction)); 
     68        pnl.add(btn = new JButton(tagTable.getAddAction())); 
    7469        btn.setMargin(new Insets(0,0,0,0)); 
    75         tagTable.addPropertyChangeListener(addAction); 
     70        tagTable.addComponentNotStoppingCellEditing(btn); 
    7671 
    7772        // 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())); 
    8374        btn.setMargin(new Insets(0,0,0,0)); 
     75        tagTable.addComponentNotStoppingCellEditing(btn); 
    8476        return pnl; 
    8577    } 
     
    129121    } 
    130122 
    131     /** 
    132      * The action for adding a tag 
    133      * 
    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 tags 
    157      * 
    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 names 
    173          */ 
    174         protected void deleteTagNames() { 
    175             int[] rows = tagTable.getSelectedRows(); 
    176             model.deleteTagNames(rows); 
    177         } 
    178  
    179         /** 
    180          * delete a selection of tag values 
    181          */ 
    182         protected void deleteTagValues() { 
    183             int[] rows = tagTable.getSelectedRows(); 
    184             model.deleteTagValues(rows); 
    185         } 
    186  
    187         /** 
    188          * delete a selection of tags 
    189          */ 
    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                 } else 
    203                     // should not happen 
    204                     // 
    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  
    228123    public void initAutoCompletion(OsmDataLayer layer) { 
    229124        // initialize the autocompletion infrastructure 
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagTable.java

    r2626 r2974  
    44import static org.openstreetmap.josm.tools.I18n.tr; 
    55 
     6import java.applet.Applet; 
    67import java.awt.AWTException; 
     8import java.awt.Component; 
    79import java.awt.Container; 
    810import java.awt.Dimension; 
     11import java.awt.KeyboardFocusManager; 
    912import java.awt.MouseInfo; 
    1013import java.awt.Point; 
    1114import java.awt.Rectangle; 
    1215import java.awt.Robot; 
     16import java.awt.Window; 
    1317import java.awt.event.ActionEvent; 
    1418import java.awt.event.InputEvent; 
    1519import java.awt.event.KeyEvent; 
    1620import java.awt.event.KeyListener; 
     21import java.beans.PropertyChangeEvent; 
     22import java.beans.PropertyChangeListener; 
     23import java.util.EventObject; 
     24import java.util.concurrent.CopyOnWriteArrayList; 
    1725import java.util.logging.Level; 
    1826import java.util.logging.Logger; 
    1927 
    2028import javax.swing.AbstractAction; 
    21 import javax.swing.Action; 
     29import javax.swing.CellEditor; 
     30import javax.swing.DefaultListSelectionModel; 
    2231import javax.swing.JComponent; 
    2332import javax.swing.JTable; 
     
    3544import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionCache; 
    3645import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList; 
     46import org.openstreetmap.josm.tools.ImageProvider; 
    3747 
    3848/** 
     
    4050 * 
    4151 */ 
    42 @SuppressWarnings("serial") 
    4352public class TagTable extends JTable  { 
    4453 
    45     private static Logger logger = Logger.getLogger(TagTable.class.getName()); 
     54    private static final Logger logger = Logger.getLogger(TagTable.class.getName()); 
    4655 
    4756    /** the table cell editor used by this table */ 
    4857    private TagCellEditor editor = null; 
    4958 
     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 
    5065    /** 
    5166     * The table has two columns. The first column is used for editing rendering and 
     
    5469     */ 
    5570    static class TagTableColumnModel extends DefaultTableColumnModel { 
    56  
    57         public TagTableColumnModel() { 
     71        public TagTableColumnModel(DefaultListSelectionModel selectionModel) { 
     72            setSelectionModel(selectionModel); 
    5873            TableColumn col = null; 
    5974            TagCellRenderer renderer = new TagCellRenderer(); 
     
    7287            col.setCellRenderer(renderer); 
    7388            addColumn(col); 
    74  
    7589        } 
    7690    } 
     
    8599     *   last cell in the table</li> 
    86100     * <ul> 
    87      * 
    88      * @author gubaer 
    89101     * 
    90102     */ 
     
    167179    class DeleteAction extends RunnableAction implements ListSelectionListener { 
    168180 
     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 
    169189        /** 
    170190         * delete a selection of tag names 
     
    194214        } 
    195215 
    196         /** 
    197          * constructor 
    198          */ 
    199         public DeleteAction() { 
    200             putValue(Action.NAME, tr("Delete")); 
    201             getSelectionModel().addListSelectionListener(this); 
    202             getColumnModel().getSelectionModel().addListSelectionListener(this); 
    203         } 
    204  
    205216        @Override 
    206217        public void run() { 
    207218            if (!isEnabled()) 
    208219                return; 
    209             getCellEditor().stopCellEditing(); 
    210             if (getSelectedColumnCount() == 1) { 
     220            switch(getSelectedColumnCount()) { 
     221            case 1: 
    211222                if (getSelectedColumn() == 0) { 
    212223                    deleteTagNames(); 
     
    216227                    // should not happen 
    217228                    // 
    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: 
    220232                deleteTags(); 
    221             } 
     233                break; 
     234            } 
     235 
     236            if (isEditing()) { 
     237                CellEditor editor = getCellEditor(); 
     238                if (editor != null) { 
     239                    editor.cancelCellEditing(); 
     240                } 
     241            } 
     242 
    222243            TagEditorModel model = (TagEditorModel)getModel(); 
    223244            if (model.getRowCount() == 0) { 
     
    231252         */ 
    232253        public void valueChanged(ListSelectionEvent e) { 
     254            updateEnabledState(); 
     255        } 
     256 
     257        protected void updateEnabledState() { 
    233258            if (isEditing() && getSelectedColumnCount() == 1 && getSelectedRowCount() == 1) { 
    234259                setEnabled(false); 
     
    240265                setEnabled(false); 
    241266            } 
    242  
    243267        } 
    244268    } 
     
    249273     * 
    250274     */ 
    251     class AddAction extends RunnableAction { 
    252  
     275    class AddAction extends RunnableAction implements PropertyChangeListener{ 
    253276        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(); 
    255281        } 
    256282 
    257283        @Override 
    258284        public void run() { 
    259             getCellEditor().stopCellEditing(); 
     285            CellEditor editor = getCellEditor(); 
     286            if (editor != null) { 
     287                getCellEditor().stopCellEditing(); 
     288            } 
    260289            ((TagEditorModel)getModel()).appendNewTag(); 
    261290            final int rowIdx = getModel().getRowCount()-1; 
    262291            requestFocusInCell(rowIdx, 0); 
    263292        } 
     293 
     294        protected void updateEnabledState() { 
     295            setEnabled(TagTable.this.isEnabled()); 
     296        } 
     297 
     298        public void propertyChange(PropertyChangeEvent evt) { 
     299            updateEnabledState(); 
     300        } 
    264301    } 
    265302 
     
    287324    protected void init() { 
    288325        setAutoResizeMode(JTable.AUTO_RESIZE_OFF); 
    289         setCellSelectionEnabled(true); 
     326        //setCellSelectionEnabled(true); 
     327        setRowSelectionAllowed(true); 
     328        setColumnSelectionAllowed(true); 
    290329        setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); 
    291         putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); 
    292330 
    293331        // make ENTER behave like TAB 
     
    316354        // 
    317355        editor = new TagCellEditor(); 
    318         editor.setTagEditorModel((TagEditorModel)getModel()); 
    319356        getColumnModel().getColumn(0).setCellEditor(editor); 
    320357        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        }); 
    321366    } 
    322367 
     
    327372     * @param columnModel 
    328373     */ 
    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); 
    331376        init(); 
    332377    } 
     
    430475        } 
    431476    } 
     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    } 
    432577} 
  • trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionCache.java

    r2960 r2974  
    147147                if (item instanceof TaggingPreset.Check) { 
    148148                    TaggingPreset.Check ch = (TaggingPreset.Check) item; 
    149                     if (ch.key == null) continue; 
     149                    if (ch.key == null) { 
     150                        continue; 
     151                    } 
    150152                    presetTagCache.put(ch.key, OsmUtils.falseval); 
    151153                    presetTagCache.put(ch.key, OsmUtils.trueval); 
    152154                } else if (item instanceof TaggingPreset.Combo) { 
    153155                    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                    } 
    155159                    for (String value : co.values.split(",")) { 
    156160                        presetTagCache.put(co.key, value); 
     
    158162                } else if (item instanceof TaggingPreset.Key) { 
    159163                    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                    } 
    161167                    presetTagCache.put(ky.key, ky.value); 
    162168                } else if (item instanceof TaggingPreset.Text) { 
    163169                    TaggingPreset.Text tt = (TaggingPreset.Text) item; 
    164                     if (tt.key == null) continue; 
     170                    if (tt.key == null) { 
     171                        continue; 
     172                    } 
    165173                    presetTagCache.putVoid(tt.key); 
    166174                    if (tt.default_ != null && !tt.default_.equals("")) { 
     
    171179        } 
    172180    } 
    173      
     181 
    174182    /** 
    175183     * replies the keys held by the cache 
Note: See TracChangeset for help on using the changeset viewer.