Changeset 35643 in osm for applications/editors/josm/plugins
- Timestamp:
- 2020-11-16T17:01:04+01:00 (4 years ago)
- Location:
- applications/editors/josm/plugins/colorscheme
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/colorscheme/build.xml
r34573 r35643 5 5 <property name="commit.message" value="Uses new constructor for Plugin"/> 6 6 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 7 <property name="plugin.main.version" value="1 4153"/>7 <property name="plugin.main.version" value="17314"/> 8 8 9 9 <property name="plugin.author" value="Christof Dallermassl"/> -
applications/editors/josm/plugins/colorscheme/src/org/openstreetmap/josm/plugins/colorscheme/ColorSchemePreference.java
r34573 r35643 8 8 9 9 import java.awt.GridBagLayout; 10 import java.util.ArrayList;11 10 import java.util.Arrays; 12 import java.util.Collections;13 11 import java.util.HashMap; 14 import java.util.List;15 12 import java.util.Map; 16 13 import java.util.StringTokenizer; … … 29 26 import org.openstreetmap.josm.data.preferences.ColorInfo; 30 27 import org.openstreetmap.josm.gui.MainApplication; 31 import org.openstreetmap.josm.gui.preferences.PreferenceSetting;32 28 import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane; 33 29 import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting; … … 43 39 public static final String PREF_KEY_COLOR_PREFIX = "color."; 44 40 private JList<String> schemesList; 45 private DefaultListModel<String> listModel;46 private List<String>colorKeys;47 private ColorPreference colorPreference;48 49 /**50 * Default Constructor51 */52 public ColorSchemePreference() {53 }54 41 55 42 @Override … … 58 45 panel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 59 46 60 Map<String, String> colorMap = Preferences.main().getAllPrefix(PREF_KEY_COLOR_PREFIX); 61 colorKeys = new ArrayList<>(colorMap.keySet()); 62 Collections.sort(colorKeys); 63 listModel = new DefaultListModel<>(); 47 DefaultListModel<String> listModel = new DefaultListModel<>(); 64 48 schemesList = new JList<>(listModel); 65 String schemes = Config.getPref().get(PREF_KEY_SCHEMES_NAMES); 66 StringTokenizer st = new StringTokenizer(schemes, ";"); 67 String schemeName; 49 StringTokenizer st = new StringTokenizer(Config.getPref().get(PREF_KEY_SCHEMES_NAMES), ";"); 68 50 while (st.hasMoreTokens()) { 69 schemeName = st.nextToken(); 70 listModel.addElement(schemeName); 51 listModel.addElement(st.nextToken()); 71 52 } 72 53 … … 76 57 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), tr("Please select a scheme to use.")); 77 58 else { 78 String schemeName1 = (String)listModel.get(schemesList.getSelectedIndex());59 String schemeName1 = listModel.get(schemesList.getSelectedIndex()); 79 60 getColorPreference(gui).setColors(getColorMap(schemeName1)); 80 61 } … … 82 63 JButton addScheme = new JButton(tr("Add")); 83 64 addScheme.addActionListener(e -> { 84 String schemeName 1= JOptionPane.showInputDialog(MainApplication.getMainFrame(), tr("Color Scheme"));85 if (schemeName 1== null)65 String schemeName = JOptionPane.showInputDialog(MainApplication.getMainFrame(), tr("Color Scheme")); 66 if (schemeName == null) 86 67 return; 87 schemeName 1= schemeName1.replaceAll("\\.", "_");88 setColorScheme(schemeName 1, getColorPreference(gui).getColors());89 listModel.addElement(schemeName 1);68 schemeName = schemeName.replace("\\.", "_"); 69 setColorScheme(schemeName, getColorPreference(gui).getColors()); 70 listModel.addElement(schemeName); 90 71 saveSchemeNamesToPref(); 91 72 }); … … 96 77 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), tr("Please select the scheme to delete.")); 97 78 else { 98 String schemeName 1 = (String)listModel.get(schemesList.getSelectedIndex());99 removeColorSchemeFromPreferences(schemeName 1);79 String schemeName = listModel.get(schemesList.getSelectedIndex()); 80 removeColorSchemeFromPreferences(schemeName); 100 81 listModel.remove(schemesList.getSelectedIndex()); 101 82 saveSchemeNamesToPref(); … … 119 100 JScrollPane scrollpane = new JScrollPane(panel); 120 101 scrollpane.setBorder(BorderFactory.createEmptyBorder( 0, 0, 0, 0 )); 121 g ui.getDisplayPreference().getTabPane().addTab(tr("Color Schemes"), scrollpane);102 getColorPreference(gui).getTabPane().addTab(tr("Color Schemes"), scrollpane); 122 103 } 123 104 124 105 @Override 125 106 public TabPreferenceSetting getTabPreferenceSetting(final PreferenceTabbedPane gui) { 126 return g ui.getDisplayPreference();107 return getColorPreference(gui); 127 108 } 128 109 … … 156 137 public void removeColorSchemeFromPreferences(String schemeName) { 157 138 // delete color entries for scheme in preferences: 158 Map<String, String> colors = Preferences.main().getAllPrefix(PREF_KEY_SCHEMES_PREFIX + schemeName + "."); 159 for(String key : colors.keySet()) { 139 for (String key : Preferences.main().getAllPrefix(PREF_KEY_SCHEMES_PREFIX + schemeName + ".").keySet()) { 160 140 Config.getPref().put(key, null); 161 141 } … … 168 148 */ 169 149 public void setColorScheme(String schemeName, Map<String, ColorInfo> colorMap) { 170 String key; 171 for(String colorKey : colorMap.keySet()) { 172 key = PREF_KEY_SCHEMES_PREFIX + schemeName + "." + PREF_KEY_COLOR_PREFIX + colorKey; 173 Config.getPref().put(key, ColorHelper.color2html(colorMap.get(colorKey).getValue())); 150 for (Map.Entry<String, ColorInfo> color : colorMap.entrySet()) { 151 String key = PREF_KEY_SCHEMES_PREFIX + schemeName + "." + PREF_KEY_COLOR_PREFIX + color.getKey(); 152 Config.getPref().put(key, ColorHelper.color2html(color.getValue().getValue())); 174 153 } 175 154 } … … 182 161 */ 183 162 public Map<String, ColorInfo> getColorMap(String schemeName) { 184 String colorKey;185 163 String prefix = PREF_KEY_SCHEMES_PREFIX + schemeName + "." + PREF_KEY_COLOR_PREFIX; 186 164 Map<String, ColorInfo> colorMap = new HashMap<>(); 187 165 for(String schemeColorKey : Preferences.main().getAllPrefix(prefix).keySet()) { 188 colorKey = schemeColorKey.substring(prefix.length()); 166 String colorKey = schemeColorKey.substring(prefix.length()); 189 167 colorMap.put(colorKey, ColorInfo.fromPref(Arrays.asList( 190 168 // FIXME: does not work, corrupts the color table ? See #16110 … … 195 173 196 174 public ColorPreference getColorPreference(PreferenceTabbedPane gui) { 197 if(colorPreference == null) { 198 for(PreferenceSetting setting : gui.getSettings()) { 199 if(setting instanceof ColorPreference) { 200 colorPreference = (ColorPreference) setting; 201 break; 202 } 203 } 204 } 205 return colorPreference; 175 return gui.getSetting(ColorPreference.class); 206 176 } 207 177 }
Note:
See TracChangeset
for help on using the changeset viewer.