Changeset 9484 in josm for trunk/src


Ignore:
Timestamp:
2016-01-16T13:32:46+01:00 (4 years ago)
Author:
simon04
Message:

Refactoring: add JosmComboBox.getEditorComponent, Javadoc

Location:
trunk/src/org/openstreetmap/josm
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/OverpassDownloadAction.java

    r9385 r9484  
    150150            overpassWizard = new HistoryComboBox();
    151151            overpassWizard.setToolTipText(tooltip);
    152             overpassWizard.getEditor().getEditorComponent().addFocusListener(disableActionsFocusListener);
     152            overpassWizard.getEditorComponent().addFocusListener(disableActionsFocusListener);
    153153            final JButton buildQuery = new JButton(tr("Build query"));
    154154            buildQuery.addActionListener(new AbstractAction() {
  • trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java

    r9371 r9484  
    209209                    public void mouseClicked(MouseEvent e) {
    210210                        try {
    211                             JTextComponent tf = (JTextComponent) hcb.getEditor().getEditorComponent();
     211                            JTextComponent tf = hcb.getEditorComponent();
    212212                            tf.getDocument().insertString(tf.getCaretPosition(), ' ' + insertText, null);
    213213                        } catch (BadLocationException ex) {
     
    283283        buildHints(right, hcbSearchString);
    284284
    285         final JTextComponent editorComponent = (JTextComponent) hcbSearchString.getEditor().getEditorComponent();
     285        final JTextComponent editorComponent = hcbSearchString.getEditorComponent();
    286286        editorComponent.getDocument().addDocumentListener(new AbstractTextComponentValidator(editorComponent) {
    287287
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java

    r9271 r9484  
    508508        protected FocusAdapter addFocusAdapter(final AutoCompletionManager autocomplete, final Comparator<AutoCompletionListItem> comparator) {
    509509           // get the combo box' editor component
    510            JTextComponent editor = (JTextComponent) values.getEditor().getEditorComponent();
     510           final JTextComponent editor = values.getEditorComponent();
    511511           // Refresh the values model when focus is gained
    512512           FocusAdapter focus = new FocusAdapter() {
  • trunk/src/org/openstreetmap/josm/gui/download/PlaceSelection.java

    r9309 r9484  
    3131import javax.swing.JScrollPane;
    3232import javax.swing.JTable;
    33 import javax.swing.JTextField;
    3433import javax.swing.ListSelectionModel;
    3534import javax.swing.UIManager;
     
    121120        SearchAction searchAction = new SearchAction();
    122121        JButton btnSearch = new JButton(searchAction);
    123         ((JTextField) cbSearchExpression.getEditor().getEditorComponent()).getDocument().addDocumentListener(searchAction);
    124         ((JTextField) cbSearchExpression.getEditor().getEditorComponent()).addActionListener(searchAction);
     122        cbSearchExpression.getEditorComponent().getDocument().addDocumentListener(searchAction);
     123        cbSearchExpression.getEditorComponent().addActionListener(searchAction);
    125124
    126125        panel.add(btnSearch, GBC.eol().insets(5, 5, 0, 5));
  • trunk/src/org/openstreetmap/josm/gui/io/BasicUploadSettingsPanel.java

    r9198 r9484  
    6565        CommentModelListener commentModelListener = new CommentModelListener(hcbUploadComment, changesetCommentModel);
    6666        hcbUploadComment.getEditor().addActionListener(commentModelListener);
    67         hcbUploadComment.getEditor().getEditorComponent().addFocusListener(commentModelListener);
     67        hcbUploadComment.getEditorComponent().addFocusListener(commentModelListener);
    6868        pnl.add(hcbUploadComment, GBC.eol().fill(GBC.HORIZONTAL));
    6969
     
    9090        CommentModelListener sourceModelListener = new CommentModelListener(hcbUploadSource, changesetSourceModel);
    9191        hcbUploadSource.getEditor().addActionListener(sourceModelListener);
    92         hcbUploadSource.getEditor().getEditorComponent().addFocusListener(sourceModelListener);
     92        hcbUploadSource.getEditorComponent().addFocusListener(sourceModelListener);
    9393        pnl.add(hcbUploadSource, GBC.eol().fill(GBC.HORIZONTAL));
    9494        return pnl;
     
    130130    public void setHistoryComboBoxDownFocusTraversalHandler(final Action handler, final HistoryComboBox hcb) {
    131131        hcb.getEditor().addActionListener(handler);
    132         hcb.getEditor().getEditorComponent().addKeyListener(
     132        hcb.getEditorComponent().addKeyListener(
    133133                new KeyListener() {
    134134                    @Override
     
    166166    public void startUserInput() {
    167167        hcbUploadComment.requestFocusInWindow();
    168         hcbUploadComment.getEditor().getEditorComponent().requestFocusInWindow();
     168        hcbUploadComment.getEditorComponent().requestFocusInWindow();
    169169    }
    170170
  • trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletingComboBox.java

    r8840 r9484  
    130130                }
    131131            }
    132             JTextComponent editorComponent = (JTextComponent) comboBox.getEditor().getEditorComponent();
     132            final JTextComponent editorComponent = comboBox.getEditorComponent();
    133133            // save unix system selection (middle mouse paste)
    134134            Clipboard sysSel = Toolkit.getDefaultToolkit().getSystemSelection();
     
    180180        super(new AutoCompletionListItem(prototype));
    181181        setRenderer(new AutoCompleteListCellRenderer());
    182         final JTextComponent editorComponent = (JTextComponent) this.getEditor().getEditorComponent();
     182        final JTextComponent editorComponent = this.getEditorComponent();
    183183        editorComponent.setDocument(new AutoCompletingComboBoxDocument(this));
    184184        editorComponent.addFocusListener(
  • trunk/src/org/openstreetmap/josm/gui/widgets/ComboBoxHistory.java

    r9078 r9484  
    1010import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem;
    1111
    12 public class ComboBoxHistory extends DefaultComboBoxModel<AutoCompletionListItem> implements Iterable<AutoCompletionListItem> {
     12/**
     13 * A data model for {@link HistoryComboBox}
     14 */
     15class ComboBoxHistory extends DefaultComboBoxModel<AutoCompletionListItem> implements Iterable<AutoCompletionListItem> {
    1316
    1417    private final int maxSize;
     
    1619    private final transient List<HistoryChangedListener> listeners = new ArrayList<>();
    1720
    18     public ComboBoxHistory(int size) {
     21    /**
     22     * Constructs a {@code ComboBoxHistory} keeping track of {@code maxSize} items
     23     * @param size the history size
     24     */
     25    ComboBoxHistory(int size) {
    1926        maxSize = size;
    2027    }
    2128
     29    /**
     30     * Adds or moves an element to the top of the history
     31     * @param s the element to add
     32     */
    2233    public void addElement(String s) {
    2334        addElement(new AutoCompletionListItem(s));
     
    2637    /**
    2738     * Adds or moves an element to the top of the history
     39     * @param o the element to add
    2840     */
    2941    @Override
     
    8092    }
    8193
     94    /**
     95     * {@link javax.swing.DefaultComboBoxModel#removeAllElements() Removes all items}
     96     * and {@link ComboBoxHistory#addElement(String) adds} the given items.
     97     * @param items the items to set
     98     */
    8299    public void setItemsAsString(List<String> items) {
    83100        removeAllElements();
    84101        for (int i = items.size()-1; i >= 0; i--) {
    85             addElement(new AutoCompletionListItem(items.get(i)));
     102            addElement(items.get(i));
    86103        }
    87104    }
    88105
     106    /**
     107     * Returns the {@link AutoCompletionListItem} items as strings
     108     * @return a list of strings
     109     */
    89110    public List<String> asStringList() {
    90111        List<String> list = new ArrayList<>(maxSize);
  • trunk/src/org/openstreetmap/josm/gui/widgets/HistoryComboBox.java

    r9078 r9484  
    99import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingComboBox;
    1010
     11/**
     12 * An {@link AutoCompletingComboBox} which keeps a history
     13 */
    1114public class HistoryComboBox extends AutoCompletingComboBox {
    1215    private final ComboBoxHistory model;
     
    2326    }
    2427
     28    /**
     29     * Returns the text contained in this component
     30     * @return the text
     31     * @see JTextComponent#getText()
     32     */
    2533    public String getText() {
    26         return ((JTextComponent) getEditor().getEditorComponent()).getText();
     34        return getEditorComponent().getText();
    2735    }
    2836
     37    /**
     38     * Sets the text of this component to the specified text
     39     * @param value the text to set
     40     * @see JTextComponent#setText(java.lang.String)
     41     */
    2942    public void setText(String value) {
    3043        setAutocompleteEnabled(false);
    31         ((JTextComponent) getEditor().getEditorComponent()).setText(value);
     44        getEditorComponent().setText(value);
    3245        setAutocompleteEnabled(true);
    3346    }
    3447
     48    /**
     49     * Adds or moves the current element to the top of the history
     50     * @see ComboBoxHistory#addElement(java.lang.String)
     51     */
    3552    public void addCurrentItemToHistory() {
    3653        model.addElement((String) getEditor().getItem());
    3754    }
    3855
     56    /**
     57     * Sets the elements of the ComboBox to the given items
     58     * @param history the items to set
     59     * @see ComboBoxHistory#setItemsAsString(java.util.List)
     60     */
    3961    public void setHistory(List<String> history) {
    4062        model.setItemsAsString(history);
    4163    }
    4264
     65    /**
     66     * Returns the items as strings
     67     * @return the items as strings
     68     * @see ComboBoxHistory#asStringList()
     69     */
    4370    public List<String> getHistory() {
    4471        return model.asStringList();
  • trunk/src/org/openstreetmap/josm/gui/widgets/JosmComboBox.java

    r8777 r9484  
    1515
    1616import javax.accessibility.Accessible;
     17import javax.swing.ComboBoxEditor;
    1718import javax.swing.ComboBoxModel;
    1819import javax.swing.DefaultComboBoxModel;
    1920import javax.swing.JComboBox;
    2021import javax.swing.JList;
     22import javax.swing.JTextField;
    2123import javax.swing.plaf.basic.ComboPopup;
    2224import javax.swing.text.JTextComponent;
     
    9395        super(items);
    9496        init(findPrototypeDisplayValue(Arrays.asList(items)));
     97    }
     98
     99    /**
     100     * Returns the editor component
     101     * @return the editor component
     102     * @see ComboBoxEditor#getEditorComponent()
     103     * @since 9484
     104     */
     105    public JTextField getEditorComponent() {
     106        return (JTextField) getEditor().getEditorComponent();
    95107    }
    96108
Note: See TracChangeset for help on using the changeset viewer.