Changeset 1424 in josm


Ignore:
Timestamp:
Feb 17, 2009 7:00:17 PM (4 years ago)
Author:
stoecker
Message:

fixed #2181

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r1332 r1424  
    417417    } 
    418418 
     419    synchronized public Color getDefaultColor(String colName) { 
     420        String colStr = defaults.get("color."+colName); 
     421        return colStr.equals("") ? null : ColorHelper.html2color(colStr); 
     422    } 
     423 
    419424    synchronized public boolean putColor(String colName, Color val) { 
    420425        return put("color."+colName, val != null ? ColorHelper.color2html(val) : null); 
  • trunk/src/org/openstreetmap/josm/gui/preferences/ColorPreference.java

    r1415 r1424  
    1818import java.util.Vector; 
    1919 
     20import javax.swing.Box; 
    2021import javax.swing.JButton; 
    2122import javax.swing.JColorChooser; 
     
    148149                int sel = colors.getSelectedRow(); 
    149150                JColorChooser chooser = new JColorChooser((Color)colors.getValueAt(sel, 1)); 
    150                 int answer = JOptionPane.showConfirmDialog(gui, chooser, tr("Choose a color for {0}", colors.getValueAt(sel, 0)), JOptionPane.OK_CANCEL_OPTION); 
     151                int answer = JOptionPane.showConfirmDialog(gui, chooser, 
     152                tr("Choose a color for {0}", getName((String)colors.getValueAt(sel, 0))), 
     153                JOptionPane.OK_CANCEL_OPTION); 
    151154                if (answer == JOptionPane.OK_OPTION) 
    152155                    colors.setValueAt(chooser.getColor(), sel, 1); 
     156            } 
     157        }); 
     158        JButton defaultSet = new JButton(tr("Set to default")); 
     159        defaultSet.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                String name = (String)colors.getValueAt(sel, 0); 
     167                Color c = Main.pref.getDefaultColor(name); 
     168                if (c != null) 
     169                    colors.setValueAt(c, sel, 1); 
     170            } 
     171        }); 
     172        JButton defaultAll = new JButton(tr("Set all to default")); 
     173        defaultAll.addActionListener(new ActionListener(){ 
     174            public void actionPerformed(ActionEvent e) { 
     175                for(int i = 0; i < colors.getRowCount(); ++i) 
     176                { 
     177                  String name = (String)colors.getValueAt(i, 0); 
     178                  Color c = Main.pref.getDefaultColor(name); 
     179                  if (c != null) 
     180                      colors.setValueAt(c, i, 1); 
     181                } 
    153182            } 
    154183        }); 
     
    161190        scrollpane.setBorder(BorderFactory.createEmptyBorder( 0, 0, 0, 0 )); 
    162191        panel.add(scrollpane, GBC.eol().fill(GBC.BOTH)); 
    163         panel.add(colorEdit, GBC.eol().anchor(GBC.EAST)); 
     192        JPanel buttonPanel = new JPanel(new GridBagLayout()); 
     193        panel.add(buttonPanel, GBC.eol().insets(5,0,5,5).fill(GBC.HORIZONTAL)); 
     194        buttonPanel.add(Box.createHorizontalGlue(), GBC.std().fill(GBC.HORIZONTAL)); 
     195        buttonPanel.add(colorEdit, GBC.std().insets(0,5,0,0)); 
     196        buttonPanel.add(defaultSet, GBC.std().insets(5,5,5,0)); 
     197        buttonPanel.add(defaultAll, GBC.std().insets(0,5,0,0)); 
    164198        gui.displaycontent.addTab(tr("Colors"), panel); 
    165199    } 
Note: See TracChangeset for help on using the changeset viewer.