Changeset 7128 in josm


Ignore:
Timestamp:
2014-05-14T20:52:13+02:00 (5 years ago)
Author:
simon04
Message:

Fix Sonar issue (package cycle)

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PresetListPanel.java

    r6986 r7128  
    22package org.openstreetmap.josm.gui.dialogs.properties;
    33
    4 import java.awt.Cursor;
    5 import java.awt.Dimension;
    6 import java.awt.Font;
    7 import java.awt.GridBagLayout;
    8 import java.awt.event.MouseEvent;
    9 import java.awt.event.MouseListener;
    10 import java.awt.font.TextAttribute;
    11 import java.util.Collection;
    12 import java.util.Collections;
    13 import java.util.List;
    14 import java.util.Map;
     4import org.openstreetmap.josm.data.osm.OsmPrimitive;
     5import org.openstreetmap.josm.gui.tagging.PresetHandler;
     6import org.openstreetmap.josm.gui.tagging.TaggingPreset;
     7import org.openstreetmap.josm.gui.tagging.TaggingPresetType;
     8import org.openstreetmap.josm.gui.tagging.PresetLabel;
     9import org.openstreetmap.josm.tools.GBC;
    1510
    1611import javax.swing.JLabel;
    1712import javax.swing.JPanel;
     13import java.awt.Dimension;
     14import java.awt.GridBagLayout;
     15import java.awt.event.MouseAdapter;
     16import java.awt.event.MouseEvent;
     17import java.util.Collection;
     18import java.util.Map;
    1819
    19 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    20 import org.openstreetmap.josm.data.osm.Tag;
    21 import org.openstreetmap.josm.gui.tagging.TaggingPreset;
    22 import org.openstreetmap.josm.gui.tagging.TaggingPresetType;
    23 import org.openstreetmap.josm.tools.GBC;
    24 
     20/**
     21 * A list of matching presets for a set of tags.
     22 */
    2523public class PresetListPanel extends JPanel {
    2624
     
    3230    }
    3331
    34     public interface PresetHandler {
    35         Collection<OsmPrimitive> getSelection();
    36         void updateTags(List<Tag> tags);
    37     }
    38 
    3932    /**
    40      * Small helper class that manages the highlighting of the label on hover as well as opening
    41      * the corresponding preset when clicked
     33     * Updates the preset list based on the {@code tags} and {@code types},
     34     * and associates an interaction with (matching) presets via {@code presetHandler}.
    4235     */
    43     public static class PresetLabelML implements MouseListener {
    44         final JLabel label;
    45         final Font hover;
    46         final Font normal;
    47         final TaggingPreset tag;
    48         final PresetHandler presetHandler;
    49 
    50         public PresetLabelML(JLabel lbl, TaggingPreset t, PresetHandler presetHandler) {
    51             super();
    52             label = lbl;
    53             lbl.setCursor(new Cursor(Cursor.HAND_CURSOR));
    54             normal = label.getFont();
    55             hover = normal.deriveFont(Collections.singletonMap(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_DOTTED));
    56             tag = t;
    57             this.presetHandler = presetHandler;
    58         }
    59         @Override
    60         public void mouseClicked(MouseEvent arg0) {
    61             Collection<OsmPrimitive> selection = tag.createSelection(presetHandler.getSelection());
    62             if (selection == null || selection.isEmpty())
    63                 return;
    64             int answer = tag.showDialog(selection, false);
    65 
    66             if (answer == TaggingPreset.DIALOG_ANSWER_APPLY) {
    67                 presetHandler.updateTags(tag.getChangedTags());
    68             }
    69 
    70         }
    71         @Override
    72         public void mouseEntered(MouseEvent arg0) {
    73             label.setFont(hover);
    74         }
    75         @Override
    76         public void mouseExited(MouseEvent arg0) {
    77             label.setFont(normal);
    78         }
    79         @Override
    80         public void mousePressed(MouseEvent arg0) {}
    81         @Override
    82         public void mouseReleased(MouseEvent arg0) {}
    83     }
    84 
    85     public static JLabel createLabelForPreset(TaggingPreset t) {
    86         JLabel lbl = new JLabel(t.getName() + " …");
    87         lbl.setIcon(t.getIcon());
    88         return lbl;
    89     }
    90 
    91     public void updatePresets(final Collection<TaggingPresetType> types, final Map<String, String> tags, PresetHandler presetHandler) {
     36    public void updatePresets(final Collection<TaggingPresetType> types, final Map<String, String> tags, final PresetHandler presetHandler) {
    9237
    9338        removeAll();
     
    9742        }
    9843
    99         for (TaggingPreset t : TaggingPreset.getMatchingPresets(types, tags, true)) {
    100             final JLabel lbl = createLabelForPreset(t);
    101             lbl.addMouseListener(new PresetLabelML(lbl, t, presetHandler));
     44        for (final TaggingPreset t : TaggingPreset.getMatchingPresets(types, tags, true)) {
     45            final JLabel lbl = new PresetLabel(t);
     46            lbl.addMouseListener(new MouseAdapter() {
     47                @Override
     48                public void mouseClicked(MouseEvent e) {
     49                    Collection<OsmPrimitive> selection = t.createSelection(presetHandler.getSelection());
     50                    if (selection == null || selection.isEmpty())
     51                        return;
     52                    int answer = t.showDialog(selection, false);
     53
     54                    if (answer == TaggingPreset.DIALOG_ANSWER_APPLY) {
     55                        presetHandler.updateTags(t.getChangedTags());
     56                    }
     57                }
     58            });
    10259            add(lbl, GBC.eol().fill(GBC.HORIZONTAL));
    10360        }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r7113 r7128  
    8484import org.openstreetmap.josm.gui.SideButton;
    8585import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
    86 import org.openstreetmap.josm.gui.dialogs.properties.PresetListPanel.PresetHandler;
    8786import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
    8887import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     88import org.openstreetmap.josm.gui.tagging.PresetHandler;
    8989import org.openstreetmap.josm.gui.tagging.TaggingPreset;
    9090import org.openstreetmap.josm.gui.tagging.TaggingPresetType;
     
    267267        membershipTable.getSelectionModel().addListSelectionListener(deleteAction);
    268268
    269         JScrollPane scrollPane = (JScrollPane) createLayout(bothTables, true, Arrays.asList(new SideButton[] {
    270                 this.btnAdd, this.btnEdit, this.btnDel
    271         }));
     269        JScrollPane scrollPane = (JScrollPane) createLayout(bothTables, true,
     270                Arrays.asList(this.btnAdd, this.btnEdit, this.btnDel));
    272271
    273272        MouseClickWatch mouseClickWatch = new MouseClickWatch();
     
    460459        // ENTER = editAction, open "edit" dialog
    461460        tagTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
    462                 .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),"onTableEnter");
     461                .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "onTableEnter");
    463462        tagTable.getActionMap().put("onTableEnter",editAction);
    464463        membershipTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java

    r7050 r7128  
    7474import org.openstreetmap.josm.gui.MainMenu;
    7575import org.openstreetmap.josm.gui.SideButton;
    76 import org.openstreetmap.josm.gui.dialogs.properties.PresetListPanel.PresetHandler;
    7776import org.openstreetmap.josm.gui.help.ContextSensitiveHelpAction;
    7877import org.openstreetmap.josm.gui.help.HelpUtil;
    7978import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     79import org.openstreetmap.josm.gui.tagging.PresetHandler;
    8080import org.openstreetmap.josm.gui.tagging.TagEditorPanel;
    8181import org.openstreetmap.josm.gui.tagging.TaggingPreset;
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java

    r7005 r7128  
    3535import org.openstreetmap.josm.data.osm.event.TagsChangedEvent;
    3636import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent;
    37 import org.openstreetmap.josm.gui.dialogs.properties.PresetListPanel;
    3837import org.openstreetmap.josm.gui.dialogs.relation.sort.RelationSorter;
    3938import org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionType;
    4039import org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionTypeCalculator;
    4140import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     41import org.openstreetmap.josm.gui.tagging.PresetHandler;
    4242import org.openstreetmap.josm.gui.tagging.TaggingPreset;
    4343import org.openstreetmap.josm.gui.tagging.TaggingPresetType;
     
    5555    private final CopyOnWriteArrayList<IMemberModelListener> listeners;
    5656    private final OsmDataLayer layer;
    57     private final PresetListPanel.PresetHandler presetHandler;
     57    private final PresetHandler presetHandler;
    5858
    5959    private final WayConnectionTypeCalculator wayConnectionTypeCalculator = new WayConnectionTypeCalculator();
     
    6363     * constructor
    6464     */
    65     public MemberTableModel(OsmDataLayer layer, PresetListPanel.PresetHandler presetHandler) {
     65    public MemberTableModel(OsmDataLayer layer, PresetHandler presetHandler) {
    6666        members = new ArrayList<>();
    6767        listeners = new CopyOnWriteArrayList<>();
  • trunk/src/org/openstreetmap/josm/gui/tagging/TagEditorPanel.java

    r6890 r7128  
    2020
    2121import org.openstreetmap.josm.gui.dialogs.properties.PresetListPanel;
    22 import org.openstreetmap.josm.gui.dialogs.properties.PresetListPanel.PresetHandler;
    2322import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2423import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList;
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetItems.java

    r7118 r7128  
    1212import java.awt.event.ActionEvent;
    1313import java.awt.event.ActionListener;
     14import java.awt.event.MouseAdapter;
    1415import java.awt.event.MouseEvent;
    1516import java.io.File;
     
    4950import org.openstreetmap.josm.data.osm.Tag;
    5051import org.openstreetmap.josm.data.preferences.BooleanProperty;
    51 import org.openstreetmap.josm.gui.dialogs.properties.PresetListPanel;
    5252import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
    5353import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionItemPriority;
     
    6868 */
    6969public final class TaggingPresetItems {
    70     private TaggingPresetItems() {    }
     70    private TaggingPresetItems() {
     71    }
    7172
    7273    private static int auto_increment_selected = 0;
     
    7677
    7778    // cache the parsing of types using a LRU cache (http://java-planet.blogspot.com/2005/08/how-to-set-up-simple-lru-cache-using.html)
    78     private static final Map<String,EnumSet<TaggingPresetType>> typeCache = new LinkedHashMap<>(16, 1.1f, true);
     79    private static final Map<String,EnumSet<TaggingPresetType>> TYPE_CACHE = new LinkedHashMap<>(16, 1.1f, true);
    7980
    8081    /**
    8182     * Last value of each key used in presets, used for prefilling corresponding fields
    8283     */
    83     private static final Map<String,String> lastValue = new HashMap<>();
     84    private static final Map<String,String> LAST_VALUES = new HashMap<>();
    8485
    8586    public static class PresetListEntry {
     
    408409            }).iterator().next();
    409410            if (t == null) return false;
    410             JLabel lbl = PresetListPanel.createLabelForPreset(t);
    411             lbl.addMouseListener(new PresetListPanel.PresetLabelML(lbl, t, null) {
     411            JLabel lbl = new PresetLabel(t);
     412            lbl.addMouseListener(new MouseAdapter() {
    412413                @Override
    413414                public void mouseClicked(MouseEvent arg0) {
     
    597598                if (auto_increment_selected != 0  && auto_increment != null) {
    598599                    try {
    599                         textField.setText(Integer.toString(Integer.parseInt(lastValue.get(key)) + auto_increment_selected));
     600                        textField.setText(Integer.toString(Integer.parseInt(LAST_VALUES.get(key)) + auto_increment_selected));
    600601                    } catch (NumberFormatException ex) {
    601602                        // Ignore - cannot auto-increment if last was non-numeric
     
    604605                else if (!usage.hadKeys() || PROP_FILL_DEFAULT.get() || "force".equals(use_last_as_default)) {
    605606                    // selected osm primitives are untagged or filling default values feature is enabled
    606                     if (!"false".equals(use_last_as_default) && lastValue.containsKey(key) && !presetInitiallyMatches) {
    607                         textField.setText(lastValue.get(key));
     607                    if (!"false".equals(use_last_as_default) && LAST_VALUES.containsKey(key) && !presetInitiallyMatches) {
     608                        textField.setText(LAST_VALUES.get(key));
    608609                    } else {
    609610                        textField.setText(default_);
     
    724725
    725726            if (!"false".equals(use_last_as_default) || auto_increment != null) {
    726                 lastValue.put(key, v);
     727                LAST_VALUES.put(key, v);
    727728            }
    728729            if (v.equals(originalValue) || (originalValue == null && v.length() == 0))
     
    10931094
    10941095            if (!"false".equals(use_last_as_default)) {
    1095                 lastValue.put(key, value);
     1096                LAST_VALUES.put(key, value);
    10961097            }
    10971098            changedTags.add(new Tag(key, value));
     
    12351236                // all items were unset (and so is default)
    12361237                originalValue = lhm.get("");
    1237                 if ("force".equals(use_last_as_default) && lastValue.containsKey(key) && !presetInitiallyMatches) {
    1238                     combo.setSelectedItem(lhm.get(lastValue.get(key)));
     1238                if ("force".equals(use_last_as_default) && LAST_VALUES.containsKey(key) && !presetInitiallyMatches) {
     1239                    combo.setSelectedItem(lhm.get(LAST_VALUES.get(key)));
    12391240                } else {
    12401241                    combo.setSelectedItem(originalValue);
     
    13631364
    13641365    public static EnumSet<TaggingPresetType> getType(String types) throws SAXException {
    1365         if (typeCache.containsKey(types))
    1366             return typeCache.get(types);
     1366        if (TYPE_CACHE.containsKey(types))
     1367            return TYPE_CACHE.get(types);
    13671368        EnumSet<TaggingPresetType> result = EnumSet.noneOf(TaggingPresetType.class);
    13681369        for (String type : Arrays.asList(types.split(","))) {
     
    13741375            }
    13751376        }
    1376         typeCache.put(types, result);
     1377        TYPE_CACHE.put(types, result);
    13771378        return result;
    13781379    }
Note: See TracChangeset for help on using the changeset viewer.