Changeset 34091 in osm for applications/editors/josm
- Timestamp:
- 2018-03-20T01:44:41+01:00 (7 years ago)
- Location:
- applications/editors/josm/plugins/colorscheme
- Files:
-
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/colorscheme/build.xml
r32680 r34091 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 0580"/>7 <property name="plugin.main.version" value="12987"/> 8 8 9 9 <property name="plugin.author" value="Christof Dallermassl"/> -
applications/editors/josm/plugins/colorscheme/src/at/dallermassl/josm/plugin/colorscheme/ColorSchemePlugin.java
r23192 r34091 12 12 * ColorScheme Plugin for JOSM. 13 13 * @author cdaller 14 *15 14 */ 16 15 public class ColorSchemePlugin extends Plugin { … … 18 17 /** 19 18 * Default Constructor 19 * @param info plugin information 20 20 */ 21 21 public ColorSchemePlugin(PluginInformation info) { … … 27 27 return new ColorSchemePreference(); 28 28 } 29 30 31 32 29 } -
applications/editors/josm/plugins/colorscheme/src/at/dallermassl/josm/plugin/colorscheme/ColorSchemePreference.java
r30737 r34091 8 8 9 9 import java.awt.GridBagLayout; 10 import java.awt.event.ActionEvent;11 import java.awt.event.ActionListener;12 10 import java.util.ArrayList; 11 import java.util.Arrays; 13 12 import java.util.Collections; 14 13 import java.util.HashMap; … … 28 27 29 28 import org.openstreetmap.josm.Main; 29 import org.openstreetmap.josm.data.preferences.ColorInfo; 30 30 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; 31 31 import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane; … … 33 33 import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting; 34 34 import org.openstreetmap.josm.gui.preferences.display.ColorPreference; 35 import org.openstreetmap.josm.tools.ColorHelper; 35 36 import org.openstreetmap.josm.tools.GBC; 36 37 … … 69 70 70 71 JButton useScheme = new JButton(tr("Use")); 71 useScheme.addActionListener(new ActionListener(){ 72 public void actionPerformed(ActionEvent e) { 73 if (schemesList.getSelectedIndex() == -1) 74 JOptionPane.showMessageDialog(Main.parent, tr("Please select a scheme to use.")); 75 else { 76 String schemeName = (String) listModel.get(schemesList.getSelectedIndex()); 77 getColorPreference(gui).setColorModel(getColorMap(schemeName)); 78 } 72 useScheme.addActionListener(e -> { 73 if (schemesList.getSelectedIndex() == -1) 74 JOptionPane.showMessageDialog(Main.parent, tr("Please select a scheme to use.")); 75 else { 76 String schemeName1 = (String) listModel.get(schemesList.getSelectedIndex()); 77 getColorPreference(gui).setColors(getColorMap(schemeName1)); 79 78 } 80 79 }); 81 80 JButton addScheme = new JButton(tr("Add")); 82 addScheme.addActionListener(new ActionListener(){ 83 public void actionPerformed(ActionEvent e) { 84 String schemeName = JOptionPane.showInputDialog(Main.parent, tr("Color Scheme")); 85 if (schemeName == null) 86 return; 87 schemeName = schemeName.replaceAll("\\.", "_"); 88 setColorScheme(schemeName, getColorPreference(gui).getColorModel()); 89 listModel.addElement(schemeName); 81 addScheme.addActionListener(e -> { 82 String schemeName1 = JOptionPane.showInputDialog(Main.parent, tr("Color Scheme")); 83 if (schemeName1 == null) 84 return; 85 schemeName1 = schemeName1.replaceAll("\\.", "_"); 86 setColorScheme(schemeName1, getColorPreference(gui).getColors()); 87 listModel.addElement(schemeName1); 88 saveSchemeNamesToPref(); 89 }); 90 91 JButton deleteScheme = new JButton(tr("Delete")); 92 deleteScheme.addActionListener(e -> { 93 if (schemesList.getSelectedIndex() == -1) 94 JOptionPane.showMessageDialog(Main.parent, tr("Please select the scheme to delete.")); 95 else { 96 String schemeName1 = (String) listModel.get(schemesList.getSelectedIndex()); 97 removeColorSchemeFromPreferences(schemeName1); 98 listModel.remove(schemesList.getSelectedIndex()); 90 99 saveSchemeNamesToPref(); 91 }92 });93 94 JButton deleteScheme = new JButton(tr("Delete"));95 deleteScheme.addActionListener(new ActionListener(){96 public void actionPerformed(ActionEvent e) {97 if (schemesList.getSelectedIndex() == -1)98 JOptionPane.showMessageDialog(Main.parent, tr("Please select the scheme to delete."));99 else {100 String schemeName = (String) listModel.get(schemesList.getSelectedIndex());101 removeColorSchemeFromPreferences(schemeName);102 listModel.remove(schemesList.getSelectedIndex());103 saveSchemeNamesToPref();104 }105 100 } 106 101 }); … … 169 164 * Copy all color entries from the given map to entries in preferences with the scheme name. 170 165 * @param schemeName the name of the scheme. 171 * @param the map containing the color key (without prefix) and the html color values.172 */ 173 public void setColorScheme(String schemeName, Map<String, String> colorMap) {166 * @param colorMap the map containing the color key (without prefix) and the html color values. 167 */ 168 public void setColorScheme(String schemeName, Map<String, ColorInfo> colorMap) { 174 169 String key; 175 170 for(String colorKey : colorMap.keySet()) { 176 171 key = PREF_KEY_SCHEMES_PREFIX + schemeName + "." + PREF_KEY_COLOR_PREFIX + colorKey; 177 Main.pref.put(key, colorMap.get(colorKey));172 Main.pref.put(key, ColorHelper.color2html(colorMap.get(colorKey).getValue())); 178 173 } 179 174 } … … 183 178 * value = html color code). 184 179 * @param schemeName the name of the scheme. 185 */ 186 public Map<String, String> getColorMap(String schemeName) { 180 * @return color map for the given scheme name 181 */ 182 public Map<String, ColorInfo> getColorMap(String schemeName) { 187 183 String colorKey; 188 184 String prefix = PREF_KEY_SCHEMES_PREFIX + schemeName + "." + PREF_KEY_COLOR_PREFIX; 189 Map<String, String>colorMap = new HashMap<>();185 Map<String, ColorInfo> colorMap = new HashMap<>(); 190 186 for(String schemeColorKey : Main.pref.getAllPrefix(prefix).keySet()) { 191 187 colorKey = schemeColorKey.substring(prefix.length()); 192 colorMap.put(colorKey, Main.pref.get(schemeColorKey)); 188 colorMap.put(colorKey, ColorInfo.fromPref(Arrays.asList( 189 // FIXME: does not work, corrupts the color table ? See #16110 190 Main.pref.get(schemeColorKey), "", "", ""), false)); 193 191 } 194 192 return colorMap;
Note:
See TracChangeset
for help on using the changeset viewer.