Changeset 20666 in osm for applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap
- Timestamp:
- 2010-03-25T11:16:13+01:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/BasicEditorPanel.java
r20586 r20666 11 11 import javax.swing.JScrollPane; 12 12 13 import org.openstreetmap.josm.data.Preferences; 13 14 import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel; 14 15 import org.openstreetmap.josm.plugins.turnrestrictions.editor.NavigationControler.BasicEditorFokusTargets; 16 import org.openstreetmap.josm.plugins.turnrestrictions.preferences.PreferenceKeys; 15 17 import org.openstreetmap.josm.tools.CheckParameterUtil; 16 18 … … 140 142 } 141 143 } 144 145 /** 146 * Initializes the set of icons used from the preference key 147 * {@see PreferenceKeys#ROAD_SIGNS}. 148 * 149 * @param prefs the JOSM preferences 150 */ 151 public void initIconSetFromPreferences(Preferences prefs){ 152 cbTurnRestrictions.initIconSetFromPreferences(prefs); 153 } 142 154 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionComboBox.java
r20489 r20666 2 2 3 3 import javax.swing.JComboBox; 4 5 import org.openstreetmap.josm.data.Preferences; 6 import org.openstreetmap.josm.plugins.turnrestrictions.preferences.PreferenceKeys; 4 7 /** 5 8 * A combo box for selecting a turn restriction type. … … 26 29 return (TurnRestrictionComboBoxModel)getModel(); 27 30 } 31 32 /** 33 * Initializes the set of icons used from the preference key 34 * {@see PreferenceKeys#ROAD_SIGNS}. 35 * 36 * @param prefs the JOSM preferences 37 */ 38 public void initIconSetFromPreferences(Preferences prefs){ 39 TurnRestrictionTypeRenderer renderer = (TurnRestrictionTypeRenderer)getRenderer(); 40 renderer.initIconSetFromPreferences(prefs); 41 repaint(); 42 } 28 43 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditor.java
r20633 r20666 39 39 import org.openstreetmap.josm.command.ChangeCommand; 40 40 import org.openstreetmap.josm.command.ConflictAddCommand; 41 import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent; 42 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener; 41 43 import org.openstreetmap.josm.data.conflict.Conflict; 42 44 import org.openstreetmap.josm.data.osm.Relation; … … 50 52 import org.openstreetmap.josm.gui.help.HelpUtil; 51 53 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 54 import org.openstreetmap.josm.plugins.turnrestrictions.preferences.PreferenceKeys; 52 55 import org.openstreetmap.josm.plugins.turnrestrictions.qa.IssuesView; 53 56 import org.openstreetmap.josm.tools.CheckParameterUtil; … … 88 91 private TurnRestrictionEditorModel editorModel; 89 92 private JTabbedPane tpEditors; 93 private PreferenceChangeHandler preferenceChangeHandler; 90 94 91 95 /** … … 202 206 203 207 editorModel.getIssuesModel().addObserver(new IssuesModelObserver()); 204 setSize(600,600); 208 setSize(600,600); 205 209 } 206 210 … … 335 339 pnlJosmSelection.wireListeners(); 336 340 editorModel.registerAsEventListener(); 341 Main.pref.addPreferenceChangeListener(this.preferenceChangeHandler = new PreferenceChangeHandler()); 342 pnlBasicEditor.initIconSetFromPreferences(Main.pref); 337 343 } else if (!visible && isVisible()) { 338 344 pnlJosmSelection.unwireListeners(); 339 345 editorModel.unregisterAsEventListener(); 346 Main.pref.removePreferenceChangeListener(preferenceChangeHandler); 340 347 } 341 348 super.setVisible(visible); … … 857 864 } 858 865 } 866 867 /** 868 * Listens the changes of the preference {@see PreferenceKeys#ROAD_SIGNS} 869 * and refreshes the set of road icons 870 * 871 */ 872 class PreferenceChangeHandler implements PreferenceChangedListener { 873 public void refreshIconSet() { 874 pnlBasicEditor.initIconSetFromPreferences(Main.pref); 875 } 876 877 public void preferenceChanged(PreferenceChangeEvent evt) { 878 if (!evt.getKey().equals(PreferenceKeys.ROAD_SIGNS)) return; 879 refreshIconSet(); 880 } 881 } 859 882 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionTypeRenderer.java
r20648 r20666 12 12 import javax.swing.UIManager; 13 13 14 import org.openstreetmap.josm.data.Preferences; 15 import org.openstreetmap.josm.plugins.turnrestrictions.preferences.PreferenceKeys; 14 16 import org.openstreetmap.josm.tools.ImageProvider; 15 17 import static org.openstreetmap.josm.tools.I18n.tr; … … 19 21 20 22 final private Map<TurnRestrictionType, ImageIcon> icons = new HashMap<TurnRestrictionType, ImageIcon>(); 23 private String iconSet = "set-a"; 21 24 22 25 /** … … 26 29 for(TurnRestrictionType type: TurnRestrictionType.values()) { 27 30 try { 28 ImageIcon icon = new ImageIcon(ImageProvider.get("types/ set-a", type.getTagValue()).getImage().getScaledInstance(16, 16, Image.SCALE_SMOOTH));31 ImageIcon icon = new ImageIcon(ImageProvider.get("types/" + iconSet, type.getTagValue()).getImage().getScaledInstance(16, 16, Image.SCALE_SMOOTH)); 29 32 icons.put(type,icon); 30 33 } catch(Exception e){ … … 50 53 } 51 54 55 /** 56 * Initializes the set of icons used from the preference key 57 * {@see PreferenceKeys#ROAD_SIGNS}. 58 * 59 * @param prefs the JOSM preferences 60 */ 61 public void initIconSetFromPreferences(Preferences prefs){ 62 iconSet = prefs.get(PreferenceKeys.ROAD_SIGNS, "set-a"); 63 iconSet = iconSet.trim().toLowerCase(); 64 if (!iconSet.equals("set-a") && !iconSet.equals("set-b")) { 65 iconSet = "set-a"; 66 } 67 loadImages(); 68 } 69 52 70 public Component getListCellRendererComponent(JList list, Object value, 53 71 int index, boolean isSelected, boolean cellHasFocus) { -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/AbstractTurnRestrictionsListView.java
r20489 r20666 4 4 import javax.swing.JPanel; 5 5 import javax.swing.event.ListSelectionListener; 6 7 import org.openstreetmap.josm.data.Preferences; 6 8 7 9 /** … … 31 33 lstTurnRestrictions.addListSelectionListener(listener); 32 34 } 33 35 36 public void initIconSetFromPreferences(Preferences prefs){ 37 TurnRestrictionCellRenderer renderer = (TurnRestrictionCellRenderer)lstTurnRestrictions.getCellRenderer(); 38 renderer.initIconSetFromPreferences(prefs); 39 } 34 40 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/TurnRestrictionCellRenderer.java
r20648 r20666 22 22 import javax.swing.table.TableCellRenderer; 23 23 24 import org.openstreetmap.josm.data.Preferences; 24 25 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 25 26 import org.openstreetmap.josm.data.osm.Relation; … … 28 29 import org.openstreetmap.josm.gui.DefaultNameFormatter; 29 30 import org.openstreetmap.josm.gui.JMultilineLabel; 31 import org.openstreetmap.josm.plugins.turnrestrictions.preferences.PreferenceKeys; 30 32 import org.openstreetmap.josm.tools.ImageProvider; 31 33 import static org.openstreetmap.josm.tools.I18n.trc; … … 58 60 private JLabel from; 59 61 private JLabel to; 62 private String iconSet = "set-a"; 60 63 61 64 public TurnRestrictionCellRenderer() { … … 84 87 */ 85 88 protected String buildImageName(String restrictionType) { 86 return "types/ set-a/" + restrictionType;89 return "types/" + iconSet + "/" + restrictionType; 87 90 } 88 91 … … 214 217 } 215 218 219 /** 220 * Initializes the set of icons used from the preference key 221 * {@see PreferenceKeys#ROAD_SIGNS}. 222 * 223 * @param prefs the JOSM preferences 224 */ 225 public void initIconSetFromPreferences(Preferences prefs){ 226 227 iconSet = prefs.get(PreferenceKeys.ROAD_SIGNS, "set-a"); 228 iconSet = iconSet.trim().toLowerCase(); 229 if (!iconSet.equals("set-a") && !iconSet.equals("set-b")) { 230 iconSet = "set-a"; 231 } 232 } 233 216 234 /* ---------------------------------------------------------------------------------- */ 217 235 /* interface ListCellRenderer */ -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/TurnRestrictionsListDialog.java
r20648 r20666 12 12 import java.util.HashSet; 13 13 import java.util.List; 14 import java.util.logging.Logger; 14 15 15 16 import javax.swing.AbstractAction; … … 23 24 import org.openstreetmap.josm.Main; 24 25 import org.openstreetmap.josm.actions.AutoScaleAction; 26 import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent; 27 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener; 25 28 import org.openstreetmap.josm.data.osm.OsmPrimitive; 26 29 import org.openstreetmap.josm.data.osm.Relation; … … 30 33 import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener; 31 34 import org.openstreetmap.josm.gui.dialogs.ToggleDialog; 32 import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;33 35 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 34 36 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; … … 36 38 import org.openstreetmap.josm.plugins.turnrestrictions.editor.TurnRestrictionEditor; 37 39 import org.openstreetmap.josm.plugins.turnrestrictions.editor.TurnRestrictionEditorManager; 40 import org.openstreetmap.josm.plugins.turnrestrictions.preferences.PreferenceKeys; 38 41 import org.openstreetmap.josm.tools.ImageProvider; 39 42 … … 48 51 */ 49 52 public class TurnRestrictionsListDialog extends ToggleDialog{ 53 private static final Logger logger = Logger.getLogger(TurnRestrictionsListDialog.class.getName()); 50 54 51 55 /** checkbox for switching between the two list views */ … … 68 72 /** the main content panel in this toggle dialog */ 69 73 private JPanel pnlContent; 74 private PreferenceChangeHandler preferenceChangeHandler; 70 75 71 76 @Override … … 75 80 MapView.addEditLayerChangeListener(actNew); 76 81 actNew.updateEnabledState(); 82 Main.pref.addPreferenceChangeListener(preferenceChangeHandler); 83 preferenceChangeHandler.refreshIconSet(); 77 84 } 78 85 … … 82 89 pnlTurnRestrictionsInSelection.unregisterAsListener(); 83 90 MapView.removeEditLayerChangeListener(actNew); 91 Main.pref.removePreferenceChangeListener(preferenceChangeHandler); 84 92 } 85 93 … … 141 149 pnlTurnRestrictionsInDataSet.getList().addMouseListener(launcher); 142 150 pnlTurnRestrictionsInSelection.getList().addMouseListener(launcher); 151 152 preferenceChangeHandler = new PreferenceChangeHandler(); 153 143 154 } 144 155 … … 429 440 } 430 441 } 442 443 /** 444 * Listens the changes of the preference {@see PreferenceKeys#ROAD_SIGNS} 445 * and refreshes the set of road icons 446 * 447 */ 448 class PreferenceChangeHandler implements PreferenceChangedListener { 449 public void refreshIconSet() { 450 pnlTurnRestrictionsInDataSet.initIconSetFromPreferences(Main.pref); 451 pnlTurnRestrictionsInSelection.initIconSetFromPreferences(Main.pref); 452 repaint(); 453 } 454 455 public void preferenceChanged(PreferenceChangeEvent evt) { 456 if (!evt.getKey().equals(PreferenceKeys.ROAD_SIGNS)) return; 457 refreshIconSet(); 458 } 459 } 431 460 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/preferences/PreferenceEditor.java
r20665 r20666 13 13 import javax.swing.JLabel; 14 14 import javax.swing.JPanel; 15 import javax.swing.JScrollPane; 15 16 import javax.swing.JTabbedPane; 16 17 import javax.swing.event.HyperlinkEvent; 17 18 import javax.swing.event.HyperlinkListener; 18 19 20 import org.openstreetmap.josm.Main; 19 21 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; 20 22 import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane; … … 29 31 */ 30 32 public class PreferenceEditor extends JPanel implements PreferenceSetting{ 33 34 private IconPreferencePanel pnlIconPreferences; 31 35 32 36 /** … … 70 74 } 71 75 76 protected JPanel buildIconPreferencePanel() { 77 JPanel pnl = new JPanel(new BorderLayout()); 78 79 pnlIconPreferences = new IconPreferencePanel(); 80 pnlIconPreferences.initFromPreferences(Main.pref); 81 82 JScrollPane sp = new JScrollPane(pnlIconPreferences); 83 sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); 84 sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); 85 86 pnl.add(sp, BorderLayout.CENTER); 87 return pnl; 88 } 72 89 73 90 protected void build() { 74 91 setLayout(new BorderLayout()); 75 92 JTabbedPane tp = new JTabbedPane(); 76 tp.add(buildCreditPanel()); 77 tp.setTitleAt(0, tr("Sponsor")); 93 tp.add(buildIconPreferencePanel()); 94 tp.add(buildCreditPanel()); 95 tp.setTitleAt(0, tr("Road Signs")); 96 tp.setToolTipTextAt(0,tr("Configure the set of road sign icons to be used in the turnrestrictions plugin")); 97 tp.setTitleAt(1, tr("Sponsor")); 78 98 add(tp, BorderLayout.CENTER); 79 99 } … … 90 110 91 111 public boolean ok() { 112 pnlIconPreferences.saveToPreferences(Main.pref); 92 113 return false; 93 114 }
Note:
See TracChangeset
for help on using the changeset viewer.