Changeset 12778 in osm for applications/editors/josm/plugins/colorscheme
- Timestamp:
- 2009-01-01T18:28:53+01:00 (17 years ago)
- Location:
- applications/editors/josm/plugins/colorscheme/src/at/dallermassl/josm/plugin/colorscheme
- Files:
-
- 2 edited
-
ColorSchemePlugin.java (modified) (2 diffs)
-
ColorSchemePreference.java (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/colorscheme/src/at/dallermassl/josm/plugin/colorscheme/ColorSchemePlugin.java
r4278 r12778 14 14 */ 15 15 public class ColorSchemePlugin extends Plugin { 16 16 17 17 /** 18 18 * Default Constructor 19 19 */ 20 20 public ColorSchemePlugin() { 21 21 22 22 } 23 23 … … 26 26 return new ColorSchemePreference(); 27 27 } 28 29 28 29 30 30 31 31 } -
applications/editors/josm/plugins/colorscheme/src/at/dallermassl/josm/plugin/colorscheme/ColorSchemePreference.java
r12588 r12778 36 36 private static final String PREF_KEY_SCHEMES_NAMES = PREF_KEY_SCHEMES_PREFIX + "names"; 37 37 public static final String PREF_KEY_COLOR_PREFIX = "color."; 38 private JList schemesList;39 private DefaultListModel listModel;40 private List<String>colorKeys;41 private ColorPreference colorPreference;42 43 /**44 * Default Constructor45 */46 public ColorSchemePreference() {47 }48 38 private JList schemesList; 39 private DefaultListModel listModel; 40 private List<String>colorKeys; 41 private ColorPreference colorPreference; 42 43 /** 44 * Default Constructor 45 */ 46 public ColorSchemePreference() { 47 } 48 49 49 50 /* (non-Javadoc)51 * @see org.openstreetmap.josm.gui.preferences.PreferenceSetting#addGui(org.openstreetmap.josm.gui.preferences.PreferenceDialog)52 */53 public void addGui(final PreferenceDialog gui) {50 /* (non-Javadoc) 51 * @see org.openstreetmap.josm.gui.preferences.PreferenceSetting#addGui(org.openstreetmap.josm.gui.preferences.PreferenceDialog) 52 */ 53 public void addGui(final PreferenceDialog gui) { 54 54 Map<String, String> colorMap = Main.pref.getAllPrefix(PREF_KEY_COLOR_PREFIX); 55 55 colorKeys = new ArrayList<String>(colorMap.keySet()); 56 56 Collections.sort(colorKeys); 57 listModel = new DefaultListModel();58 schemesList = new JList(listModel);57 listModel = new DefaultListModel(); 58 schemesList = new JList(listModel); 59 59 String schemes = Main.pref.get(PREF_KEY_SCHEMES_NAMES); 60 60 StringTokenizer st = new StringTokenizer(schemes, ";"); … … 76 76 } 77 77 }); 78 JButton addScheme = new JButton(tr("Add"));79 addScheme.addActionListener(new ActionListener(){80 public void actionPerformed(ActionEvent e) {81 String schemeName = JOptionPane.showInputDialog(Main.parent, tr("Color Scheme"));82 if (schemeName == null)83 return;84 schemeName = schemeName.replaceAll("\\.", "_");85 setColorScheme(schemeName, getColorPreference().getColorModel());86 listModel.addElement(schemeName);78 JButton addScheme = new JButton(tr("Add")); 79 addScheme.addActionListener(new ActionListener(){ 80 public void actionPerformed(ActionEvent e) { 81 String schemeName = JOptionPane.showInputDialog(Main.parent, tr("Color Scheme")); 82 if (schemeName == null) 83 return; 84 schemeName = schemeName.replaceAll("\\.", "_"); 85 setColorScheme(schemeName, getColorPreference().getColorModel()); 86 listModel.addElement(schemeName); 87 87 saveSchemeNamesToPref(); 88 }89 });88 } 89 }); 90 90 91 JButton deleteScheme = new JButton(tr("Delete"));92 deleteScheme.addActionListener(new ActionListener(){93 public void actionPerformed(ActionEvent e) {94 if (schemesList.getSelectedIndex() == -1)95 JOptionPane.showMessageDialog(Main.parent, tr("Please select the scheme to delete."));96 else {97 String schemeName = (String) listModel.get(schemesList.getSelectedIndex());98 removeColorSchemeFromPreferences(schemeName);99 listModel.remove(schemesList.getSelectedIndex());100 saveSchemeNamesToPref();101 }102 }103 });104 schemesList.setVisibleRowCount(3);91 JButton deleteScheme = new JButton(tr("Delete")); 92 deleteScheme.addActionListener(new ActionListener(){ 93 public void actionPerformed(ActionEvent e) { 94 if (schemesList.getSelectedIndex() == -1) 95 JOptionPane.showMessageDialog(Main.parent, tr("Please select the scheme to delete.")); 96 else { 97 String schemeName = (String) listModel.get(schemesList.getSelectedIndex()); 98 removeColorSchemeFromPreferences(schemeName); 99 listModel.remove(schemesList.getSelectedIndex()); 100 saveSchemeNamesToPref(); 101 } 102 } 103 }); 104 schemesList.setVisibleRowCount(3); 105 105 106 //schemesList.setToolTipText(tr("The sources (url or filename) of annotation preset definition files. See http://josm.eigenheimstrasse.de/wiki/AnnotationPresets for help."));106 //schemesList.setToolTipText(tr("The sources (url or filename) of annotation preset definition files. See http://josm.eigenheimstrasse.de/wiki/AnnotationPresets for help.")); 107 107 useScheme.setToolTipText(tr("Use the selected scheme from the list.")); 108 addScheme.setToolTipText(tr("Use the current colors as a new color scheme."));109 deleteScheme.setToolTipText(tr("Delete the selected scheme from the list."));108 addScheme.setToolTipText(tr("Use the current colors as a new color scheme.")); 109 deleteScheme.setToolTipText(tr("Delete the selected scheme from the list.")); 110 110 111 gui.map.add(new JLabel(tr("Color Schemes")), GBC.eol().insets(0,5,0,0));112 gui.map.add(new JScrollPane(schemesList), GBC.eol().fill(GBC.BOTH));113 JPanel buttonPanel = new JPanel(new GridBagLayout());114 gui.map.add(buttonPanel, GBC.eol().fill(GBC.HORIZONTAL));115 buttonPanel.add(Box.createHorizontalGlue(), GBC.std().fill(GBC.HORIZONTAL));111 gui.map.add(new JLabel(tr("Color Schemes")), GBC.eol().insets(0,5,0,0)); 112 gui.map.add(new JScrollPane(schemesList), GBC.eol().fill(GBC.BOTH)); 113 JPanel buttonPanel = new JPanel(new GridBagLayout()); 114 gui.map.add(buttonPanel, GBC.eol().fill(GBC.HORIZONTAL)); 115 buttonPanel.add(Box.createHorizontalGlue(), GBC.std().fill(GBC.HORIZONTAL)); 116 116 buttonPanel.add(useScheme, GBC.std().insets(0,5,5,0)); 117 buttonPanel.add(addScheme, GBC.std().insets(0,5,5,0));118 buttonPanel.add(deleteScheme, GBC.std().insets(0,5,5,0));119 }120 121 /**122 * Saves the names of the schemes to the preferences.123 */124 public void saveSchemeNamesToPref() {117 buttonPanel.add(addScheme, GBC.std().insets(0,5,5,0)); 118 buttonPanel.add(deleteScheme, GBC.std().insets(0,5,5,0)); 119 } 120 121 /** 122 * Saves the names of the schemes to the preferences. 123 */ 124 public void saveSchemeNamesToPref() { 125 125 if (schemesList.getModel().getSize() > 0) { 126 126 StringBuilder sb = new StringBuilder(); … … 129 129 Main.pref.put(PREF_KEY_SCHEMES_NAMES, sb.toString().substring(1)); 130 130 } else 131 Main.pref.put(PREF_KEY_SCHEMES_NAMES, null); 132 }131 Main.pref.put(PREF_KEY_SCHEMES_NAMES, null); 132 } 133 133 134 public boolean ok() {135 return false;// nothing to do136 }137 138 /**139 * Remove all color entries for the given scheme from the preferences.140 * @param schemeName the name of the scheme.141 */142 public void removeColorSchemeFromPreferences(String schemeName) {134 public boolean ok() { 135 return false;// nothing to do 136 } 137 138 /** 139 * Remove all color entries for the given scheme from the preferences. 140 * @param schemeName the name of the scheme. 141 */ 142 public void removeColorSchemeFromPreferences(String schemeName) { 143 143 // delete color entries for scheme in preferences: 144 144 Map<String, String> colors = Main.pref.getAllPrefix(PREF_KEY_SCHEMES_PREFIX + schemeName + "."); 145 145 for(String key : colors.keySet()) { 146 146 Main.pref.put(key, null); 147 } 148 }149 150 /**151 * Copy all color entries from the given map to entries in preferences with the scheme name.152 * @param schemeName the name of the scheme.153 * @param the map containing the color key (without prefix) and the html color values.154 */155 public void setColorScheme(String schemeName, Map<String, String> colorMap) {156 String key;157 for(String colorKey : colorMap.keySet()) {158 key = PREF_KEY_SCHEMES_PREFIX + schemeName + "." + PREF_KEY_COLOR_PREFIX + colorKey;159 Main.pref.put(key, colorMap.get(colorKey));160 }161 }162 163 /**164 * Reads all colors for a scheme and returns them in a map (key = color key without prefix,165 * value = html color code).166 * @param schemeName the name of the scheme.167 */168 public Map<String, String> getColorMap(String schemeName) {169 String colorKey;170 String prefix = PREF_KEY_SCHEMES_PREFIX + schemeName + "." + PREF_KEY_COLOR_PREFIX;171 Map<String, String>colorMap = new HashMap<String, String>();172 for(String schemeColorKey : Main.pref.getAllPrefix(prefix).keySet()) {173 colorKey = schemeColorKey.substring(prefix.length());174 colorMap.put(colorKey, Main.pref.get(schemeColorKey));175 }176 return colorMap;177 }147 } 148 } 149 150 /** 151 * Copy all color entries from the given map to entries in preferences with the scheme name. 152 * @param schemeName the name of the scheme. 153 * @param the map containing the color key (without prefix) and the html color values. 154 */ 155 public void setColorScheme(String schemeName, Map<String, String> colorMap) { 156 String key; 157 for(String colorKey : colorMap.keySet()) { 158 key = PREF_KEY_SCHEMES_PREFIX + schemeName + "." + PREF_KEY_COLOR_PREFIX + colorKey; 159 Main.pref.put(key, colorMap.get(colorKey)); 160 } 161 } 162 163 /** 164 * Reads all colors for a scheme and returns them in a map (key = color key without prefix, 165 * value = html color code). 166 * @param schemeName the name of the scheme. 167 */ 168 public Map<String, String> getColorMap(String schemeName) { 169 String colorKey; 170 String prefix = PREF_KEY_SCHEMES_PREFIX + schemeName + "." + PREF_KEY_COLOR_PREFIX; 171 Map<String, String>colorMap = new HashMap<String, String>(); 172 for(String schemeColorKey : Main.pref.getAllPrefix(prefix).keySet()) { 173 colorKey = schemeColorKey.substring(prefix.length()); 174 colorMap.put(colorKey, Main.pref.get(schemeColorKey)); 175 } 176 return colorMap; 177 } 178 178 179 179 public ColorPreference getColorPreference() {
Note:
See TracChangeset
for help on using the changeset viewer.
