Changeset 3141 in josm for trunk/src


Ignore:
Timestamp:
2010-03-17T11:11:55+01:00 (15 years ago)
Author:
Gubaer
Message:

small changes in tag editor panel

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetTagsPanel.java

    r3138 r3141  
    77
    88import javax.swing.BorderFactory;
    9 import javax.swing.DefaultListSelectionModel;
    109import javax.swing.JPanel;
    1110import javax.swing.JScrollPane;
     
    2726        setLayout(new BorderLayout());
    2827        setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    29         DefaultListSelectionModel rowSelectionModel = new DefaultListSelectionModel();
    30         DefaultListSelectionModel colSelectionModel = new DefaultListSelectionModel();
    31 
    32         model = new TagEditorModel(rowSelectionModel, colSelectionModel);
    33         tblTags = new TagTable(model, rowSelectionModel, colSelectionModel);
     28        model = new TagEditorModel();
     29        tblTags = new TagTable(model);
    3430        tblTags.setEnabled(false);
    3531        add(new JScrollPane(tblTags), BorderLayout.CENTER);
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorModel.java

    r3138 r3141  
    2424import org.openstreetmap.josm.data.osm.TagCollection;
    2525import org.openstreetmap.josm.data.osm.Tagged;
     26import org.openstreetmap.josm.tools.CheckParameterUtil;
    2627
    2728/**
     
    3738
    3839    /** the list holding the tags */
    39     protected ArrayList<TagModel> tags = null;
     40    protected final ArrayList<TagModel> tags =new ArrayList<TagModel>();
    4041
    4142    /** indicates whether the model is dirty */
    4243    private boolean dirty =  false;
    43     private PropertyChangeSupport propChangeSupport = null;
     44    private final PropertyChangeSupport propChangeSupport = new PropertyChangeSupport(this);
     45
    4446    private DefaultListSelectionModel rowSelectionModel;
    4547    private DefaultListSelectionModel colSelectionModel;
    4648
    4749    /**
    48      * constructor
    49      */
    50     public TagEditorModel(DefaultListSelectionModel rowSelectionModel, DefaultListSelectionModel colSelectionModel){
    51         tags = new ArrayList<TagModel>();
    52         propChangeSupport = new PropertyChangeSupport(this);
     50     * Creates a new tag editor model. Internally allocates two selection models
     51     * for row selection and column selection.
     52     *
     53     * To create a {@see JTable} with this model:
     54     * <pre>
     55     *    TagEditorModel model = new TagEditorModel();
     56     *    TagTable tbl  = new TagTabel(model);
     57     * </pre>
     58     *
     59     * @see #getRowSelectionModel()
     60     * @see #getColumnSelectionModel()
     61     */
     62    public TagEditorModel() {
     63        this.rowSelectionModel = new DefaultListSelectionModel();
     64        this.colSelectionModel  = new DefaultListSelectionModel();
     65    }
     66    /**
     67     * Creates a new tag editor model.
     68     *
     69     * @param rowSelectionModel the row selection model. Must not be null.
     70     * @param colSelectionModel the column selection model. Must not be null.
     71     * @throws IllegalArgumentException thrown if {@code rowSelectionModel} is null
     72     * @throws IllegalArgumentException thrown if {@code colSelectionModel} is null
     73     */
     74    public TagEditorModel(DefaultListSelectionModel rowSelectionModel, DefaultListSelectionModel colSelectionModel) throws IllegalArgumentException{
     75        CheckParameterUtil.ensureParameterNotNull(rowSelectionModel, "rowSelectionModel");
     76        CheckParameterUtil.ensureParameterNotNull(colSelectionModel, "colSelectionModel");
    5377        this.rowSelectionModel = rowSelectionModel;
    5478        this.colSelectionModel  = colSelectionModel;
     
    5781    public void addPropertyChangeListener(PropertyChangeListener listener) {
    5882        propChangeSupport.addPropertyChangeListener(listener);
     83    }
     84
     85    /**
     86     * Replies the row selection model used by this tag editor model
     87     *
     88     * @return the row selection model used by this tag editor model
     89     */
     90    public DefaultListSelectionModel getRowSelectionModel() {
     91        return rowSelectionModel;
     92    }
     93
     94    /**
     95     * Replies the column selection model used by this tag editor model
     96     *
     97     * @return the column selection model used by this tag editor model
     98     */
     99    public DefaultListSelectionModel getColumnSelectionModel() {
     100        return colSelectionModel;
    59101    }
    60102
     
    167209        if (tag == null) {
    168210            tag = new TagModel(name, value);
    169             add(tag);
     211            tags.add(tag);
    170212        } else {
    171213            tag.addValue(value);
    172214        }
    173215        setDirty(true);
     216        fireTableDataChanged();
    174217    }
    175218
     
    306349        for (String key : primitive.keySet()) {
    307350            String value = primitive.get(key);
    308             add(key,value);
     351            this.tags.add(new TagModel(key,value));
    309352        }
    310353        TagModel tag = new TagModel();
     
    323366        for (String key : tags.keySet()) {
    324367            String value = tags.get(key);
    325             add(key,value);
    326         }
     368            this.tags.add(new TagModel(key,value));
     369        }
     370        sort();
    327371        TagModel tag = new TagModel();
    328         sort();
    329372        this.tags.add(tag);
    330373        setDirty(false);
     
    345388        for (String key : tags.getKeys()) {
    346389            String value = tags.getJoinedValues(key);
    347             add(key,value);
     390            this.tags.add(new TagModel(key,value));
    348391        }
    349392        sort();
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorPanel.java

    r3083 r3141  
    99
    1010import javax.swing.BoxLayout;
    11 import javax.swing.DefaultListSelectionModel;
    1211import javax.swing.JButton;
    1312import javax.swing.JPanel;
     
    1716import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionCache;
    1817import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList;
     18import org.openstreetmap.josm.tools.CheckParameterUtil;
    1919
    2020/**
     
    4242     */
    4343    protected JPanel buildTagTableEditorPanel() {
    44 
    4544        JPanel pnl = new JPanel();
    46         DefaultListSelectionModel rowSelectionModel = new DefaultListSelectionModel();
    47         DefaultListSelectionModel colSelectionModel = new DefaultListSelectionModel();
    48 
    49         model = new TagEditorModel(rowSelectionModel, colSelectionModel);
    50         tagTable = new TagTable(model, rowSelectionModel, colSelectionModel);
    51 
     45        tagTable = new TagTable(model);
    5246        pnl.setLayout(new BorderLayout());
    5347        pnl.add(new JScrollPane(tagTable), BorderLayout.CENTER);
     
    107101
    108102    /**
    109      * constructor
     103     * Creates a new tag editor panel. The editor model is created
     104     * internally and can be retrieved with {@see #getModel()}.
    110105     */
    111106    public TagEditorPanel() {
     107        this(null);
     108    }
     109
     110    /**
     111     * Creates a new tag editor panel with a supplied model. If
     112     * {@code model} is null, a new model is created.
     113     *
     114     * @param model the tag editor model
     115     */
     116    public TagEditorPanel(TagEditorModel model) {
     117        this.model = model;
     118        if (this.model == null) {
     119            this.model = new TagEditorModel();
     120        }
    112121        build();
    113122    }
     
    122131    }
    123132
    124     public void initAutoCompletion(OsmDataLayer layer) {
     133    /**
     134     * Initializes the auto completion infrastructure used in this
     135     * tag editor panel. {@code layer} is the data layer from whose data set
     136     * tag values are proposed as auto completion items.
     137     *
     138     * @param layer the data layer. Must not be null.
     139     * @throws IllegalArgumentException thrown if {@code layer} is null
     140     */
     141    public void initAutoCompletion(OsmDataLayer layer) throws IllegalArgumentException{
     142        CheckParameterUtil.ensureParameterNotNull(layer, "layer");
    125143        // initialize the autocompletion infrastructure
    126144        //
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagTable.java

    r3100 r3141  
    3939import javax.swing.table.DefaultTableColumnModel;
    4040import javax.swing.table.TableColumn;
    41 import javax.swing.table.TableModel;
    4241
    4342import org.openstreetmap.josm.gui.dialogs.relation.RunnableAction;
     
    356355
    357356    /**
    358      * constructor
    359      *
    360      * @param model
    361      * @param columnModel
    362      */
    363     public TagTable(TableModel model, DefaultListSelectionModel rowSelectionModel, DefaultListSelectionModel colSelectionModel) {
    364         super(model, new TagTableColumnModel(colSelectionModel), rowSelectionModel);
     357     * Creates a new tag table
     358     *
     359     * @param model the tag editor model
     360     */
     361    public TagTable(TagEditorModel model) {
     362        super(model, new TagTableColumnModel(model.getColumnSelectionModel()), model.getRowSelectionModel());
    365363        init();
    366364    }
Note: See TracChangeset for help on using the changeset viewer.