Changeset 4230 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2011-07-13T10:41:01+02:00 (13 years ago)
Author:
stoecker
Message:

allow to color the entries in layer list dialog according to assigned layer drawing color

Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
1 deleted
8 edited

Legend:

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

    r4200 r4230  
    290290    }
    291291
     292    synchronized public boolean getBoolean(final String key, final String specName, final boolean def) {
     293        putDefault(key, Boolean.toString(def));
     294        String skey = key+"."+specName;
     295        if(properties.containsKey(skey))
     296            return Boolean.parseBoolean(properties.get(skey));
     297        return properties.containsKey(key) ? Boolean.parseBoolean(properties.get(key)) : def;
     298    }
     299
    292300    /**
    293301     * Set a value for a certain setting. The changed setting is saved
     
    608616    }
    609617
     618    synchronized public int getInteger(String key, String specName, int def) {
     619        putDefault(key, Integer.toString(def));
     620        String v = get(key+"."+specName);
     621        if(null == v)
     622            v = get(key);
     623        if(null == v)
     624            return def;
     625
     626        try {
     627            return Integer.parseInt(v);
     628        } catch(NumberFormatException e) {
     629            // fall out
     630        }
     631        return def;
     632    }
     633
    610634    synchronized public long getLong(String key, long def) {
    611635        putDefault(key, Long.toString(def));
  • trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java

    r4191 r4230  
    55
    66import java.awt.BorderLayout;
     7import java.awt.Color;
    78import java.awt.Component;
    89import java.awt.Dimension;
     
    821822    }
    822823
    823     private static class LayerNameCellRenderer extends DefaultTableCellRenderer {
     824    private class LayerNameCellRenderer extends DefaultTableCellRenderer {
    824825
    825826        protected boolean isActiveLayer(Layer layer) {
     
    838839            if (isActiveLayer(layer)) {
    839840                label.setFont(label.getFont().deriveFont(Font.BOLD));
     841            }
     842            if(Main.pref.getBoolean("dialog.layer.colorname", true)) {
     843                Color c = layer.getColor(false);
     844                if(c != null) {
     845                    Color oc = null;
     846                    for(Layer l : model.getLayers()) {
     847                        oc = l.getColor(false);
     848                        if(oc != null) {
     849                            if(oc.equals(c))
     850                                oc = null;
     851                            else
     852                                break;
     853                        }
     854                    }
     855                    if(oc == null) /* not more than one color, don't use coloring */
     856                        c = null;
     857                }
     858                /* Setting foreground properly handles null as default! */
     859                label.setForeground(c);
    840860            }
    841861            label.setIcon(layer.getIcon());
     
    12311251         * Never null, but can be empty.
    12321252         */
    1233         protected List<Layer> getLayers() {
     1253        public List<Layer> getLayers() {
    12341254            if (Main.map == null || Main.map.mapView == null)
    12351255                return Collections.<Layer>emptyList();
  • trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListPopup.java

    r3753 r4230  
    1919import org.openstreetmap.josm.gui.layer.Layer;
    2020import org.openstreetmap.josm.gui.layer.Layer.LayerAction;
     21import org.openstreetmap.josm.gui.layer.Layer.MultiLayerAction;
    2122import org.openstreetmap.josm.gui.layer.Layer.SeparatorLayerAction;
    2223import org.openstreetmap.josm.tools.ImageProvider;
     
    5960                } else if (a instanceof LayerAction && ((LayerAction)a).supportLayers(selectedLayers)) {
    6061                    separatorAdded = false;
     62                    if(a instanceof MultiLayerAction)
     63                        a = ((MultiLayerAction)a).getMultiLayerAction(selectedLayers);
    6164                    actions.add(a);
    6265                }
     
    6669                separatorAdded = false;
    6770                for (Action a: selectedLayers.get(i).getMenuEntries()) {
    68                     if (a instanceof LayerAction && ((LayerAction)a).supportLayers(selectedLayers) && !actions.contains(a)) {
     71                    if (a instanceof LayerAction && !(a instanceof MultiLayerAction)
     72                    && ((LayerAction)a).supportLayers(selectedLayers) && !actions.contains(a)) {
    6973                        if (!separatorAdded) {
    7074                            separatorAdded = true;
  • trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java

    r4208 r4230  
    1010import java.awt.BasicStroke;
    1111import java.awt.Color;
     12import java.awt.Component;
    1213import java.awt.Dimension;
    1314import java.awt.Graphics2D;
     
    3435import javax.swing.ButtonGroup;
    3536import javax.swing.Icon;
    36 import javax.swing.JColorChooser;
    3737import javax.swing.JFileChooser;
    3838import javax.swing.JLabel;
    3939import javax.swing.JList;
     40import javax.swing.JMenuItem;
    4041import javax.swing.JOptionPane;
    4142import javax.swing.JPanel;
     
    219220    }
    220221
    221     static public Color getColor(String name) {
    222         return Main.pref.getColor(marktr("gps point"), name != null ? "layer " + name : null, Color.gray);
     222    @Override
     223    public Color getColor(boolean ignoreCustom) {
     224        Color c = Main.pref.getColor(marktr("gps point"), "layer " + getName(), Color.gray);
     225
     226        return ignoreCustom || getColorMode() == colorModes.none ? c : null;
     227    }
     228
     229    public colorModes getColorMode() {
     230        try {
     231            return colorModes.values()[Main.pref.getInteger("draw.rawgps.colors", "layer "+getName(), 0)];
     232        } catch (Exception e) {
     233        }
     234        return colorModes.none;
     235    }
     236
     237    /* for preferences */
     238    static public Color getGenericColor() {
     239        return Main.pref.getColor(marktr("gps point"), Color.gray);
    223240    }
    224241
     
    230247                LayerListDialog.getInstance().createDeleteLayerAction(),
    231248                SeparatorLayerAction.INSTANCE,
    232                 new CustomizeColor(),
    233                 new CustomizeLineDrawing(),
     249                new CustomizeColor(this),
     250                new CustomizeLineDrawing(this),
    234251                new ConvertToDataLayerAction(),
    235252                SeparatorLayerAction.INSTANCE,
     
    243260                new LayerSaveAction(this),
    244261                new LayerSaveAsAction(this),
    245                 new CustomizeColor(),
    246                 new CustomizeLineDrawing(),
     262                new CustomizeColor(this),
     263                new CustomizeLineDrawing(this),
    247264                new ImportImages(),
    248265                new ImportAudio(),
     
    375392         ****************************************************************/
    376393        // Long startTime = System.currentTimeMillis();
    377         Color neutralColor = getColor(getName());
     394        Color neutralColor = getColor(true);
    378395        // also draw lines between points belonging to different segments
    379         boolean forceLines = Main.pref.getBoolean("draw.rawgps.lines.force");
     396        boolean forceLines = Main.pref.getBoolean("draw.rawgps.lines.force", "layer "+getName(), false);
    380397        // draw direction arrows on the lines
    381         boolean direction = Main.pref.getBoolean("draw.rawgps.direction");
     398        boolean direction = Main.pref.getBoolean("draw.rawgps.direction", "layer "+getName(), false);
    382399        // don't draw lines if longer than x meters
    383         int lineWidth = Main.pref.getInteger("draw.rawgps.linewidth",0);
     400        int lineWidth = Main.pref.getInteger("draw.rawgps.linewidth", "layer "+getName(), 0);
    384401
    385402        int maxLineLength;
     403        boolean lines;
    386404        if (this.isLocalFile) {
    387             maxLineLength = Main.pref.getInteger("draw.rawgps.max-line-length.local", -1);
     405            maxLineLength = Main.pref.getInteger("draw.rawgps.max-line-length.local", "layer "+getName(), -1);
     406            lines = Main.pref.getBoolean("draw.rawgps.lines.local", "layer "+getName(), true);
    388407        } else {
    389             maxLineLength = Main.pref.getInteger("draw.rawgps.max-line-length", 200);
    390         }
    391         // draw line between points, global setting
    392         boolean lines = (Main.pref.getBoolean("draw.rawgps.lines", true) || (Main.pref
    393                 .getBoolean("draw.rawgps.lines.localfiles") && this.isLocalFile));
    394         String linesKey = "draw.rawgps.lines.layer " + getName();
    395         // draw lines, per-layer setting
    396         if (Main.pref.hasKey(linesKey)) {
    397             lines = Main.pref.getBoolean(linesKey);
     408            maxLineLength = Main.pref.getInteger("draw.rawgps.max-line-length", "layer "+getName(), 200);
     409            lines = Main.pref.getBoolean("draw.rawgps.lines", "layer "+getName(), true);
    398410        }
    399411        // paint large dots for points
    400         boolean large = Main.pref.getBoolean("draw.rawgps.large");
    401         boolean hdopcircle = Main.pref.getBoolean("draw.rawgps.hdopcircle", true);
     412        boolean large = Main.pref.getBoolean("draw.rawgps.large", "layer "+getName(), false);
     413        int largesize = Main.pref.getInteger("draw.rawgps.large.size", "layer "+getName(), 3);
     414        boolean hdopcircle = Main.pref.getBoolean("draw.rawgps.hdopcircle", "layer "+getName(), false);
    402415        // color the lines
    403         colorModes colored = colorModes.none;
    404         try {
    405             colored = colorModes.values()[Main.pref.getInteger("draw.rawgps.colors", 0)];
    406         } catch (Exception e) {
    407         }
     416        colorModes colored = getColorMode();
    408417        // paint direction arrow with alternate math. may be faster
    409         boolean alternatedirection = Main.pref.getBoolean("draw.rawgps.alternatedirection");
     418        boolean alternatedirection = Main.pref.getBoolean("draw.rawgps.alternatedirection", "layer "+getName(), false);
    410419        // don't draw arrows nearer to each other than this
    411         int delta = Main.pref.getInteger("draw.rawgps.min-arrow-distance", 40);
     420        int delta = Main.pref.getInteger("draw.rawgps.min-arrow-distance", "layer "+getName(), 40);
    412421        // allows to tweak line coloring for different speed levels.
    413         int colorTracksTune = Main.pref.getInteger("draw.rawgps.colorTracksTune", 45);
     422        int colorTracksTune = Main.pref.getInteger("draw.rawgps.colorTracksTune", "layer "+getName(), 45);
    414423
    415424        if(lineWidth != 0)
     
    640649                }
    641650                if (large) {
    642                     g.fillRect(screen.x-1, screen.y-1, 3, 3);
     651                    g.fillRect(screen.x-1, screen.y-1, largesize, largesize);
    643652                }
    644653            } // end for trkpnt
     
    12961305    }
    12971306
    1298     private class CustomizeLineDrawing extends AbstractAction {
    1299 
    1300         CustomizeLineDrawing() {
     1307    private class CustomizeLineDrawing extends AbstractAction implements LayerAction, MultiLayerAction {
     1308        List<Layer> layers;
     1309
     1310        public CustomizeLineDrawing(List<Layer> l) {
     1311            this();
     1312            layers = l;
     1313        }
     1314
     1315        public CustomizeLineDrawing(Layer l) {
     1316            this();
     1317            layers = new LinkedList<Layer>();
     1318            layers.add(l);
     1319        }
     1320
     1321        private CustomizeLineDrawing() {
    13011322            super(tr("Customize line drawing"), ImageProvider.get("mapmode/addsegment"));
     1323        }
     1324
     1325        @Override
     1326        public boolean supportLayers(List<Layer> layers) {
     1327            for(Layer layer: layers) {
     1328                if(!(layer instanceof GpxLayer))
     1329                    return false;
     1330            }
     1331            return true;
     1332        }
     1333
     1334        @Override
     1335        public Component createMenuComponent() {
     1336            return new JMenuItem(this);
     1337        }
     1338
     1339        @Override
     1340        public Action getMultiLayerAction(List<Layer> layers) {
     1341            return new CustomizeLineDrawing(layers);
    13021342        }
    13031343
    13041344        @Override
    13051345        public void actionPerformed(ActionEvent e) {
     1346            /* FIXME: Add all the other GPX settings here as well. Unify with DrawingPreferences
     1347               Each option should be able to "use global settings". Attention with the handling
     1348               of local layer for the two local layer options! */
    13061349            JRadioButton[] r = new JRadioButton[3];
    13071350            r[0] = new JRadioButton(tr("Use global settings."));
     
    13141357                panel.add(b);
    13151358            }
    1316             String propName = "draw.rawgps.lines.layer " + getName();
     1359            String propbase = isLocalFile ? "draw.rawgps.lines.local" : "draw.rawgps.lines";
     1360            String propName = propbase + ".layer " + layers.get(0).getName();
    13171361            if (Main.pref.hasKey(propName)) {
    13181362                group.setSelected(r[Main.pref.getBoolean(propName) ? 1 : 2].getModel(), true);
     
    13291373                // continue
    13301374            }
    1331             if (group.getSelection() == r[0].getModel()) {
    1332                 Main.pref.put(propName, null);
    1333             } else {
    1334                 Main.pref.put(propName, group.getSelection() == r[1].getModel());
     1375            for(Layer layer : layers) {
     1376                propName = propbase + ".layer " + layer.getName();
     1377                if (group.getSelection() == r[0].getModel()) {
     1378                    Main.pref.put(propName, null);
     1379                } else {
     1380                    Main.pref.put(propName, group.getSelection() == r[1].getModel());
     1381                }
    13351382            }
    13361383            Main.map.repaint();
    13371384        }
    1338     }
    1339 
    1340     private class CustomizeColor extends AbstractAction {
    1341 
    1342         public CustomizeColor() {
    1343             super(tr("Customize Color"), ImageProvider.get("colorchooser"));
    1344             putValue("help", ht("/Action/LayerCustomizeColor"));
    1345         }
    1346 
    1347         @Override
    1348         public void actionPerformed(ActionEvent e) {
    1349             JColorChooser c = new JColorChooser(getColor(getName()));
    1350             Object[] options = new Object[] { tr("OK"), tr("Cancel"), tr("Default") };
    1351             int answer = JOptionPane.showOptionDialog(
    1352                     Main.parent,
    1353                     c,
    1354                     tr("Choose a color"),
    1355                     JOptionPane.OK_CANCEL_OPTION,
    1356                     JOptionPane.PLAIN_MESSAGE,
    1357                     null,
    1358                     options, options[0]
    1359             );
    1360             switch (answer) {
    1361             case 0:
    1362                 Main.pref.putColor("layer " + getName(), c.getColor());
    1363                 break;
    1364             case 1:
    1365                 return;
    1366             case 2:
    1367                 Main.pref.putColor("layer " + getName(), null);
    1368                 break;
    1369             }
    1370             Main.map.repaint();
    1371         }
    1372 
    13731385    }
    13741386
  • trunk/src/org/openstreetmap/josm/gui/layer/Layer.java

    r4183 r4230  
    55import static org.openstreetmap.josm.tools.I18n.tr;
    66
     7import java.awt.Color;
    78import java.awt.Component;
    89import java.awt.Graphics2D;
     
    5354    }
    5455
     56    public interface MultiLayerAction {
     57        Action getMultiLayerAction(List<Layer> layers);
     58    }
     59
     60
    5561    /**
    5662     * Special class that can be returned by getMenuEntries when JSeparator needs to be created
     
    128134     */
    129135    abstract public Icon getIcon();
     136
     137    /**
     138     * Return a Color for this layer. Return null when no color specified.
     139     * @param ignoreCustom Custom color should return null, as no default color
     140     *      is used. When this is true, then even for custom coloring the base
     141     *      color is returned - mainly for layer internal use.
     142     */
     143    public Color getColor(boolean ignoreCustom) {
     144        return null;
     145    }
    130146
    131147    /**
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java

    r3754 r4230  
    2424import javax.swing.Icon;
    2525import javax.swing.JCheckBoxMenuItem;
    26 import javax.swing.JColorChooser;
    2726import javax.swing.JOptionPane;
    2827import javax.swing.SwingUtilities;
     
    3938import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
    4039import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
     40import org.openstreetmap.josm.gui.layer.CustomizeColor;
    4141import org.openstreetmap.josm.gui.layer.GpxLayer;
    4242import org.openstreetmap.josm.gui.layer.Layer;
     
    149149    }
    150150
    151     static public Color getColor(String name)
     151    @Override
     152    public Color getColor(boolean ignoreCustom)
    152153    {
     154        String name = getName();
    153155        return Main.pref.getColor(marktr("gps marker"), name != null ? "layer "+name : null, Color.gray);
     156    }
     157
     158    /* for preferences */
     159    static public Color getGenericColor()
     160    {
     161        return Main.pref.getColor(marktr("gps marker"), Color.gray);
    154162    }
    155163
    156164    @Override public void paint(Graphics2D g, MapView mv, Bounds box) {
    157165        boolean showTextOrIcon = isTextOrIconShown();
    158         g.setColor(getColor(getName()));
     166        g.setColor(getColor(true));
    159167
    160168        if (mousePressed) {
     
    203211        components.add(LayerListDialog.getInstance().createDeleteLayerAction());
    204212        components.add(SeparatorLayerAction.INSTANCE);
    205         components.add(new CustomizeColor());
     213        components.add(new CustomizeColor(this));
    206214        components.add(SeparatorLayerAction.INSTANCE);
    207215        components.add(new SynchronizeAudio());
     
    396404        }
    397405
    398 
    399406        @Override
    400407        public boolean supportLayers(List<Layer> layers) {
    401408            return layers.size() == 1 && layers.get(0) instanceof MarkerLayer;
    402         }
    403     }
    404 
    405     private class CustomizeColor extends AbstractAction {
    406 
    407         public CustomizeColor() {
    408             super(tr("Customize Color"), ImageProvider.get("colorchooser"));
    409             putValue("help", ht("/Action/LayerCustomizeColor"));
    410         }
    411 
    412         @Override
    413         public void actionPerformed(ActionEvent e) {
    414             JColorChooser c = new JColorChooser(getColor(getName()));
    415             Object[] options = new Object[]{tr("OK"), tr("Cancel"), tr("Default")};
    416             int answer = JOptionPane.showOptionDialog(
    417                     Main.parent,
    418                     c,
    419                     tr("Choose a color"),
    420                     JOptionPane.OK_CANCEL_OPTION,
    421                     JOptionPane.PLAIN_MESSAGE,
    422                     null,
    423                     options,
    424                     options[0]
    425             );
    426             switch (answer) {
    427             case 0:
    428                 Main.pref.putColor("layer "+getName(), c.getColor());
    429                 break;
    430             case 1:
    431                 return;
    432             case 2:
    433                 Main.pref.putColor("layer "+getName(), null);
    434                 break;
    435             }
    436             Main.map.repaint();
    437409        }
    438410    }
  • trunk/src/org/openstreetmap/josm/gui/preferences/ColorPreference.java

    r4162 r4230  
    249249        ConflictColors.getColors();
    250250        Severity.getColors();
    251         MarkerLayer.getColor(null);
    252         GpxLayer.getColor(null);
     251        MarkerLayer.getGenericColor();
     252        GpxLayer.getGenericColor();
    253253        OsmDataLayer.getOutsideColor();
    254254        ImageryLayer.getFadeColor();
  • trunk/src/org/openstreetmap/josm/gui/preferences/DrawingPreference.java

    r4208 r4230  
    8383
    8484        /* ensure that default is in data base */
    85         Boolean lf = Main.pref.getBoolean("draw.rawgps.lines.localfiles", false);
     85        Boolean lf = Main.pref.getBoolean("draw.rawgps.lines.local", true);
    8686        if(Main.pref.getBoolean("draw.rawgps.lines", true)) {
    8787            drawRawGpsLinesAll.setSelected(true);
     
    158158
    159159        // hdopCircleGpsPoints
    160         hdopCircleGpsPoints.setSelected(Main.pref.getBoolean("draw.rawgps.hdopcircle", true));
     160        hdopCircleGpsPoints.setSelected(Main.pref.getBoolean("draw.rawgps.hdopcircle", false));
    161161        hdopCircleGpsPoints.setToolTipText(tr("Draw a circle form HDOP value."));
    162162        panel.add(hdopCircleGpsPoints, GBC.eop().insets(20,0,0,0));
     
    296296        Main.pref.put("draw.data.area_outline_only", outlineOnly.isSelected());
    297297        Main.pref.put("draw.rawgps.lines", drawRawGpsLinesAll.isSelected());
    298         Main.pref.put("draw.rawgps.lines.localfiles", drawRawGpsLinesLocal.isSelected());
     298        Main.pref.put("draw.rawgps.lines.local", drawRawGpsLinesAll.isSelected() || drawRawGpsLinesLocal.isSelected());
    299299        Main.pref.put("draw.rawgps.max-line-length", drawRawGpsMaxLineLength.getText());
    300300        Main.pref.put("draw.rawgps.max-line-length.local", drawRawGpsMaxLineLengthLocal.getText());
Note: See TracChangeset for help on using the changeset viewer.