- Timestamp:
- 2009-02-25T16:04:52+01:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/ColorPreference.java
r1444 r1445 12 12 import java.util.regex.Matcher; 13 13 import java.util.regex.Pattern; 14 import java.util.ArrayList; 14 15 import java.util.HashMap; 15 16 import java.util.Map; … … 27 28 import javax.swing.JTable; 28 29 import javax.swing.ListSelectionModel; 30 import javax.swing.event.ListSelectionEvent; 29 31 import javax.swing.table.DefaultTableModel; 30 32 import javax.swing.table.TableCellRenderer; … … 43 45 private DefaultTableModel tableModel; 44 46 private JTable colors; 47 private ArrayList<String> del = new ArrayList<String>(); 48 49 JButton colorEdit; 50 JButton defaultSet; 51 JButton remove; 45 52 46 53 /** … … 136 143 setColorModel(Main.pref.getAllColors()); 137 144 145 colorEdit = new JButton(tr("Choose")); 146 colorEdit.addActionListener(new ActionListener(){ 147 public void actionPerformed(ActionEvent e) { 148 int sel = colors.getSelectedRow(); 149 JColorChooser chooser = new JColorChooser((Color)colors.getValueAt(sel, 1)); 150 int answer = JOptionPane.showConfirmDialog(gui, chooser, 151 tr("Choose a color for {0}", getName((String)colors.getValueAt(sel, 0))), 152 JOptionPane.OK_CANCEL_OPTION); 153 if (answer == JOptionPane.OK_OPTION) 154 colors.setValueAt(chooser.getColor(), sel, 1); 155 } 156 }); 157 defaultSet = new JButton(tr("Set to default")); 158 defaultSet.addActionListener(new ActionListener(){ 159 public void actionPerformed(ActionEvent e) { 160 int sel = colors.getSelectedRow(); 161 String name = (String)colors.getValueAt(sel, 0); 162 Color c = Main.pref.getDefaultColor(name); 163 if (c != null) 164 colors.setValueAt(c, sel, 1); 165 } 166 }); 167 JButton defaultAll = new JButton(tr("Set all to default")); 168 defaultAll.addActionListener(new ActionListener(){ 169 public void actionPerformed(ActionEvent e) { 170 for(int i = 0; i < colors.getRowCount(); ++i) 171 { 172 String name = (String)colors.getValueAt(i, 0); 173 Color c = Main.pref.getDefaultColor(name); 174 if (c != null) 175 colors.setValueAt(c, i, 1); 176 } 177 } 178 }); 179 remove = new JButton(tr("Remove")); 180 remove.addActionListener(new ActionListener(){ 181 public void actionPerformed(ActionEvent e) { 182 int sel = colors.getSelectedRow(); 183 del.add((String)colors.getValueAt(sel, 0)); 184 tableModel.removeRow(sel); 185 } 186 }); 187 remove.setEnabled(false); 188 colorEdit.setEnabled(false); 189 defaultSet.setEnabled(false); 190 138 191 colors = new JTable(tableModel) { 139 192 @Override public boolean isCellEditable(int row, int column) { 140 193 return false; 194 } 195 @Override public void valueChanged(ListSelectionEvent e) { 196 super.valueChanged(e); 197 int sel = colors.getSelectedRow(); 198 remove.setEnabled(sel > 0 && isRemoveColor(sel)); 199 colorEdit.setEnabled(sel > 0); 200 defaultSet.setEnabled(sel > 0); 141 201 } 142 202 }; … … 155 215 }); 156 216 colors.getColumnModel().getColumn(1).setWidth(100); 157 158 JButton colorEdit = new JButton(tr("Choose"));159 colorEdit.addActionListener(new ActionListener(){160 public void actionPerformed(ActionEvent e) {161 if (colors.getSelectedRowCount() == 0) {162 JOptionPane.showMessageDialog(gui, tr("Please select a color."));163 return;164 }165 int sel = colors.getSelectedRow();166 JColorChooser chooser = new JColorChooser((Color)colors.getValueAt(sel, 1));167 int answer = JOptionPane.showConfirmDialog(gui, chooser,168 tr("Choose a color for {0}", getName((String)colors.getValueAt(sel, 0))),169 JOptionPane.OK_CANCEL_OPTION);170 if (answer == JOptionPane.OK_OPTION)171 colors.setValueAt(chooser.getColor(), sel, 1);172 }173 });174 JButton defaultSet = new JButton(tr("Set to default"));175 defaultSet.addActionListener(new ActionListener(){176 public void actionPerformed(ActionEvent e) {177 if (colors.getSelectedRowCount() == 0) {178 JOptionPane.showMessageDialog(gui, tr("Please select a color."));179 return;180 }181 int sel = colors.getSelectedRow();182 String name = (String)colors.getValueAt(sel, 0);183 Color c = Main.pref.getDefaultColor(name);184 if (c != null)185 colors.setValueAt(c, sel, 1);186 }187 });188 JButton defaultAll = new JButton(tr("Set all to default"));189 defaultAll.addActionListener(new ActionListener(){190 public void actionPerformed(ActionEvent e) {191 for(int i = 0; i < colors.getRowCount(); ++i)192 {193 String name = (String)colors.getValueAt(i, 0);194 Color c = Main.pref.getDefaultColor(name);195 if (c != null)196 colors.setValueAt(c, i, 1);197 }198 }199 });200 217 colors.setToolTipText(tr("Colors used by different objects in JOSM.")); 201 218 colors.setPreferredScrollableViewportSize(new Dimension(100,112)); … … 212 229 buttonPanel.add(defaultSet, GBC.std().insets(5,5,5,0)); 213 230 buttonPanel.add(defaultAll, GBC.std().insets(0,5,0,0)); 231 buttonPanel.add(remove, GBC.std().insets(0,5,0,0)); 214 232 gui.displaycontent.addTab(tr("Colors"), panel); 233 } 234 235 Boolean isRemoveColor(int row) 236 { 237 return ((String)colors.getValueAt(row, 0)).startsWith("layer "); 215 238 } 216 239 … … 227 250 public boolean ok() { 228 251 Boolean ret = false; 252 for(String d : del) 253 Main.pref.put("color."+d, null); 229 254 for (int i = 0; i < colors.getRowCount(); ++i) { 230 255 String key = (String)colors.getValueAt(i, 0);
Note:
See TracChangeset
for help on using the changeset viewer.