Changeset 1221 in josm for trunk/src/org


Ignore:
Timestamp:
2009-01-09T09:42:46+01:00 (15 years ago)
Author:
stoecker
Message:

cleanup color handling

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java

    r1169 r1221  
    8282
    8383        //putValue("help", "Action/AddNode/Autnode");
    84         selectedColor = Main.pref.getColor(marktr("selected"), Color.YELLOW);
     84        selectedColor = Main.pref.getColor(marktr("selected"), Color.red);
    8585
    8686        drawHelperLine = Main.pref.getBoolean("draw.helper-line", true);
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java

    r1186 r1221  
    7979        putValue("help", "Action/Extrude/Extrude");
    8080        initialMoveDelay = Main.pref.getInteger("edit.initial-move-delay",200);
    81         selectedColor = Main.pref.getColor(marktr("selected"), Color.YELLOW);
     81        selectedColor = Main.pref.getColor(marktr("selected"), Color.red);
    8282    }
    8383
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r1180 r1221  
    183183    }
    184184
     185    synchronized public TreeMap<String, String> getAllColors() {
     186        final TreeMap<String,String> all = new TreeMap<String,String>();
     187        for (final Entry<String,String> e : defaults.entrySet())
     188            if (e.getKey().startsWith("color."))
     189                all.put(e.getKey().substring(6), e.getValue());
     190        for (final Entry<String,String> e : properties.entrySet())
     191            if (e.getKey().startsWith("color."))
     192                all.put(e.getKey().substring(6), e.getValue());
     193        for (final Entry<String,String> e : override.entrySet())
     194            if (e.getKey().startsWith("color."))
     195                if (e.getValue() == null)
     196                    all.remove(e.getKey().substring(6));
     197                else
     198                    all.put(e.getKey().substring(6), e.getValue());
     199        return all;
     200    }
     201
    185202    synchronized public Map<String, String> getDefaults() {
    186203        return defaults;
     
    345362     */
    346363    synchronized public Color getColor(String colName, Color def) {
    347         String colStr = get("color."+colName);
    348         if (colStr.equals("")) {
    349             put("color."+colName, ColorHelper.color2html(def));
    350             return def;
    351         }
    352         return ColorHelper.html2color(colStr);
     364        return getColor(colName, null, def);
    353365    }
    354366
     
    362374     */
    363375    synchronized public Color getColor(String colName, String specName, Color def) {
    364         String colStr = get("color."+specName);
     376        putDefault("color."+colName, ColorHelper.color2html(def));
     377        String colStr = specName != null ? get("color."+specName) : "";
    365378        if(colStr.equals(""))
    366         {
    367379            colStr = get("color."+colName);
    368             if (colStr.equals("")) {
    369                 put("color."+colName, ColorHelper.color2html(def));
    370                 return def;
    371             }
    372         }
    373         putDefault("color."+colName, ColorHelper.color2html(def));
    374         return ColorHelper.html2color(colStr);
     380        return colStr.equals("") ? def : ColorHelper.html2color(colStr);
    375381    }
    376382
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/MapPaintVisitor.java

    r1215 r1221  
    752752                g.drawRect(p.x - radius, p.y - radius, size, size);
    753753
    754                         String name = getNodeName(n);
    755                         if (name!=null /* && annotate */)
    756                         {
    757                                 g.setColor(textColor);
    758                                 Font defaultFont = g.getFont();
    759                                 g.setFont (orderFont);
    760                                 g.drawString (name, p.x+radius+2, p.y+radius+2);
    761                                 g.setFont(defaultFont);
    762                         }
    763         }
     754            String name = getNodeName(n);
     755            if (name!=null /* && annotate */)
     756            {
     757                g.setColor(textColor);
     758                Font defaultFont = g.getFont();
     759                g.setFont (orderFont);
     760                g.drawString (name, p.x+radius+2, p.y+radius+2);
     761                g.setFont(defaultFont);
     762            }
     763        }
     764    }
     765
     766    public void getColors()
     767    {
     768        super.getColors();
     769        untaggedColor = Main.pref.getColor(marktr("untagged"),Color.GRAY);
     770        textColor = Main.pref.getColor (marktr("text"), Color.WHITE);
    764771    }
    765772
     
    767774    // Shows areas before non-areas
    768775    public void visitAll(DataSet data, Boolean virtual) {
    769        
    770                 boolean profiler = Main.pref.getBoolean("mappaint.profiler",false);
    771                 long profilerStart = java.lang.System.currentTimeMillis();
    772                 long profilerLast = profilerStart;
    773                 int profilerN;
    774                 if(profiler)
    775                 {
    776                         System.out.println("Mappaint Profiler");
    777                 }
    778                
     776
     777        boolean profiler = Main.pref.getBoolean("mappaint.profiler",false);
     778        long profilerStart = java.lang.System.currentTimeMillis();
     779        long profilerLast = profilerStart;
     780        int profilerN;
     781        if(profiler)
     782        {
     783            System.out.println("Mappaint Profiler");
     784        }
     785
    779786        getSettings(virtual);
    780         untaggedColor = Main.pref.getColor(marktr("untagged"),Color.GRAY);
    781         textColor = Main.pref.getColor (marktr("text"), Color.WHITE);
    782787        useRealWidth = Main.pref.getBoolean("mappaint.useRealWidth",false);
    783788        zoomLevelDisplay = Main.pref.getBoolean("mappaint.zoomLevelDisplay",false);
     
    795800        selectedCall = false;
    796801
    797                 if(profiler)
    798                 {
    799                         System.out.format("Prepare  : %4dms\n", (java.lang.System.currentTimeMillis()-profilerLast));
    800                         profilerLast = java.lang.System.currentTimeMillis();
    801                 }
    802                
     802        if(profiler)
     803        {
     804            System.out.format("Prepare  : %4dms\n", (java.lang.System.currentTimeMillis()-profilerLast));
     805            profilerLast = java.lang.System.currentTimeMillis();
     806        }
     807
    803808        if (fillAreas && styles.hasAreas()) {
    804809            Collection<Way> noAreaWays = new LinkedList<Way>();
    805810
    806                         /*** RELATIONS ***/
    807                         profilerN = 0;
     811            /*** RELATIONS ***/
     812            profilerN = 0;
    808813            for (final Relation osm : data.relations)
    809814            {
    810815                if(!osm.deleted && !osm.incomplete)
    811                                 {
     816                {
    812817                    osm.visit(this);
    813                                         profilerN++;
    814                                 }
    815             }
    816 
    817                         if(profiler)
    818                         {
    819                                 System.out.format("Relations: %4dms, n=%d\n", (java.lang.System.currentTimeMillis()-profilerLast), profilerN);
    820                                 profilerLast = java.lang.System.currentTimeMillis();
    821                         }
    822                        
    823                         /*** AREAS ***/
    824                         profilerN = 0;
     818                    profilerN++;
     819                }
     820            }
     821
     822            if(profiler)
     823            {
     824                System.out.format("Relations: %4dms, n=%d\n", (java.lang.System.currentTimeMillis()-profilerLast), profilerN);
     825                profilerLast = java.lang.System.currentTimeMillis();
     826            }
     827
     828            /*** AREAS ***/
     829            profilerN = 0;
    825830            for (final Way osm : data.ways)
    826831            {
     
    836841            }
    837842            alreadyDrawnAreas = null;
    838                        
    839                         if(profiler)
    840                         {
    841                                 System.out.format("Areas    : %4dms, n=%d\n",  (java.lang.System.currentTimeMillis()-profilerLast), profilerN);
    842                                 profilerLast = java.lang.System.currentTimeMillis();
    843                         }
    844 
    845                         /*** WAYS ***/
    846                         profilerN = 0;
     843
     844            if(profiler)
     845            {
     846                System.out.format("Areas    : %4dms, n=%d\n",  (java.lang.System.currentTimeMillis()-profilerLast), profilerN);
     847                profilerLast = java.lang.System.currentTimeMillis();
     848            }
     849
     850            /*** WAYS ***/
     851            profilerN = 0;
    847852            fillAreas = false;
    848853            for (final OsmPrimitive osm : noAreaWays)
     
    851856                profilerN++;
    852857            }
    853                        
    854                         if(profiler)
    855                         {
    856                                 System.out.format("Ways     : %4dms, n=%d\n", (java.lang.System.currentTimeMillis()-profilerLast), profilerN);
    857                                 profilerLast = java.lang.System.currentTimeMillis();
    858                         }
     858
     859            if(profiler)
     860            {
     861                System.out.format("Ways     : %4dms, n=%d\n", (java.lang.System.currentTimeMillis()-profilerLast), profilerN);
     862                profilerLast = java.lang.System.currentTimeMillis();
     863            }
    859864        }
    860865        else
    861866        {
    862                         /*** WAYS (filling disabled)  ***/                     
    863                         profilerN = 0;
     867            /*** WAYS (filling disabled)  ***/
     868            profilerN = 0;
    864869            for (final OsmPrimitive osm : data.ways)
    865870                if (!osm.incomplete && !osm.deleted && !osm.selected)
    866                                 {
     871                {
    867872                    osm.visit(this);
    868873                    profilerN++;
    869                                 }
    870                                        
    871                         if(profiler)
    872                         {
    873                                 System.out.format("Ways     : %4dms, n=%d\n", (java.lang.System.currentTimeMillis()-profilerLast), profilerN);
    874                                 profilerLast = java.lang.System.currentTimeMillis();
    875                         }
    876         }
    877 
    878                 /*** SELECTED  ***/
     874                }
     875
     876            if(profiler)
     877            {
     878                System.out.format("Ways     : %4dms, n=%d\n", (java.lang.System.currentTimeMillis()-profilerLast), profilerN);
     879                profilerLast = java.lang.System.currentTimeMillis();
     880            }
     881        }
     882
     883        /*** SELECTED  ***/
    879884        selectedCall = true;
    880                 profilerN = 0;
     885        profilerN = 0;
    881886        for (final OsmPrimitive osm : data.getSelected()) {
    882887            if (!osm.incomplete && !osm.deleted
    883888            && !(osm instanceof Node) && !alreadyDrawn.contains(osm))
    884                         {
     889            {
    885890                osm.visit(this);
    886                                 profilerN++;
    887                         }
    888         }
    889                
    890                 if(profiler)
    891                 {
    892                         System.out.format("Selected : %4dms, n=%d\n", (java.lang.System.currentTimeMillis()-profilerLast), profilerN);
    893                         profilerLast = java.lang.System.currentTimeMillis();
    894                 }
    895 
    896                 /*** DISPLAY CACHED SEGMENTS (WAYS) NOW ***/
     891                profilerN++;
     892            }
     893        }
     894
     895        if(profiler)
     896        {
     897            System.out.format("Selected : %4dms, n=%d\n", (java.lang.System.currentTimeMillis()-profilerLast), profilerN);
     898            profilerLast = java.lang.System.currentTimeMillis();
     899        }
     900
     901        /*** DISPLAY CACHED SEGMENTS (WAYS) NOW ***/
    897902        displaySegments();
    898                 /*System.out.println("display segments " + (java.lang.System.currentTimeMillis()-profilerLast) + "ms");
    899                 profilerLast = java.lang.System.currentTimeMillis();*/
    900 
    901                 /*** NODES ***/
    902                 profilerN = 0;
     903        /*System.out.println("display segments " + (java.lang.System.currentTimeMillis()-profilerLast) + "ms");
     904        profilerLast = java.lang.System.currentTimeMillis();*/
     905
     906        /*** NODES ***/
     907        profilerN = 0;
    903908        for (final OsmPrimitive osm : data.nodes)
    904909            if (!osm.incomplete && !osm.deleted && !alreadyDrawn.contains(osm))
    905910            {
    906911                osm.visit(this);
    907                                 profilerN++;
    908                         }
    909                                
    910                 if(profiler)
    911                 {
    912                         System.out.format("Nodes    : %4dms, n=%d\n", (java.lang.System.currentTimeMillis()-profilerLast), profilerN);
    913                         profilerLast = java.lang.System.currentTimeMillis();
    914                 }
     912                profilerN++;
     913            }
     914
     915        if(profiler)
     916        {
     917            System.out.format("Nodes    : %4dms, n=%d\n", (java.lang.System.currentTimeMillis()-profilerLast), profilerN);
     918            profilerLast = java.lang.System.currentTimeMillis();
     919        }
    915920
    916921        alreadyDrawn = null;
    917922
    918                 /*** VIRTUAL  ***/
     923        /*** VIRTUAL  ***/
    919924        if (virtualNodeSize != 0)
    920925        {
    921                         profilerN = 0;
     926            profilerN = 0;
    922927            currentColor = nodeColor;
    923928            for (final OsmPrimitive osm : data.ways)
    924929                if (!osm.incomplete && !osm.deleted)
    925                                 {
     930                {
    926931                    visitVirtual((Way)osm);
    927                                         profilerN++;
    928                                 }
    929                                        
    930                         if(profiler)
    931                         {
    932                                 System.out.format("Virtual  : %4dms, n=%d\n", (java.lang.System.currentTimeMillis()-profilerLast), profilerN);
    933                                 profilerLast = java.lang.System.currentTimeMillis();
    934                         }
    935            
    936                         displaySegments(null);
    937                         /*System.out.println("display segments virtual " + (java.lang.System.currentTimeMillis()-profilerLast) + "ms");
    938                         profilerLast = java.lang.System.currentTimeMillis();*/
    939         }
    940                
    941                 if(profiler)
    942                 {
    943                         System.out.format("All      : %4dms\n", (profilerLast-profilerStart));
    944                 }
     932                    profilerN++;
     933                }
     934
     935            if(profiler)
     936            {
     937                System.out.format("Virtual  : %4dms, n=%d\n", (java.lang.System.currentTimeMillis()-profilerLast), profilerN);
     938                profilerLast = java.lang.System.currentTimeMillis();
     939            }
     940
     941            displaySegments(null);
     942            /*System.out.println("display segments virtual " + (java.lang.System.currentTimeMillis()-profilerLast) + "ms");
     943            profilerLast = java.lang.System.currentTimeMillis();*/
     944        }
     945
     946        if(profiler)
     947        {
     948            System.out.format("All      : %4dms\n", (profilerLast-profilerStart));
     949        }
    945950    }
    946951
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java

    r1216 r1221  
    8585    Rectangle bbox = new Rectangle();
    8686
    87     protected void getSettings(Boolean virtual) {
    88         inactiveColor = Main.pref.getColor(marktr("inactive"), Color.DARK_GRAY);
    89         selectedColor = Main.pref.getColor(marktr("selected"), Color.WHITE);
    90         nodeColor = Main.pref.getColor(marktr("node"), Color.RED);
     87    public void getColors()
     88    {
     89        inactiveColor = Main.pref.getColor(marktr("inactive"), Color.darkGray);
     90        selectedColor = Main.pref.getColor(marktr("selected"), Color.red);
     91        nodeColor = Main.pref.getColor(marktr("node"), Color.yellow);
    9192        dfltWayColor = Main.pref.getColor(marktr("way"), darkblue);
    9293        relationColor = Main.pref.getColor(marktr("relation"), teal);
     
    9495        incompleteColor = Main.pref.getColor(marktr("incomplete way"), darkerblue);
    9596        backgroundColor = Main.pref.getColor(marktr("background"), Color.BLACK);
     97    }
     98
     99    protected void getSettings(Boolean virtual) {
    96100        showDirectionArrow = Main.pref.getBoolean("draw.segment.direction");
    97101        showRelevantDirectionsOnly = Main.pref.getBoolean("draw.segment.relevant_directions_only", true);
  • trunk/src/org/openstreetmap/josm/gui/MapScaler.java

    r1169 r1221  
    3131        String text = dist > 1000 ? (Math.round(dist/100)/10.0)+" km" : Math.round(dist*10)/10+" m";
    3232        Rectangle2D bound = g.getFontMetrics().getStringBounds(text, g);
    33         g.setColor(Main.pref.getColor(marktr("scale"), Color.white));
     33        g.setColor(getColor());
    3434        g.drawLine(0, 5, 99, 5);
    3535        g.drawLine(0, 0, 0, 10);
     
    4141    }
    4242
     43    static public Color getColor()
     44    {
     45        return Main.pref.getColor(marktr("scale"), Color.white);
     46    }
     47
    4348    public String helpTopic() {
    4449        return "MapView/Scaler";
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java

    r1169 r1221  
    137137    }
    138138
     139    static public Color getColor()
     140    {
     141        return Main.pref.getColor(marktr("conflict"), Color.gray);
     142    }
     143
    139144    /**
    140145     * Paint all conflicts that can be expressed on the main window.
    141146     */
    142147    public void paintConflicts(final Graphics g, final NavigatableComponent nc) {
    143         Color preferencesColor = Main.pref.getColor("conflict", Color.gray);
    144         if (preferencesColor.equals(Color.BLACK))
     148        Color preferencesColor = getColor();
     149        if (preferencesColor.equals(Main.pref.getColor(marktr("background"), Color.black)))
    145150            return;
    146151        g.setColor(preferencesColor);
  • trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java

    r1210 r1221  
    108108    }
    109109
     110    static public Color getColor(String name)
     111    {
     112        return Main.pref.getColor(marktr("gps point"), name != null ? "layer "+name : null, Color.gray);
     113    }
     114
    110115    @Override public Component[] getMenuEntries() {
    111116        JMenuItem line = new JMenuItem(tr("Customize line drawing"), ImageProvider.get("mapmode/addsegment"));
     
    142147        color.addActionListener(new ActionListener() {
    143148            public void actionPerformed(ActionEvent e) {
    144                 JColorChooser c = new JColorChooser(Main.pref.getColor(marktr("gps point"), "layer "+name, Color.gray));
     149                JColorChooser c = new JColorChooser(getColor(name));
    145150                Object[] options = new Object[]{tr("OK"), tr("Cancel"), tr("Default")};
    146151                int answer = JOptionPane.showOptionDialog(Main.parent, c, tr("Choose a color"), JOptionPane.OK_CANCEL_OPTION,
     
    370375         ****************************************************************/
    371376        // Long startTime = System.currentTimeMillis();
    372         Color neutralColor = Main.pref.getColor(marktr("gps point"), "layer "+name, Color.GRAY);
     377        Color neutralColor = getColor(name);
    373378        boolean forceLines = Main.pref.getBoolean("draw.rawgps.lines.force");                     // also draw lines between points belonging to different segments
    374379        boolean direction = Main.pref.getBoolean("draw.rawgps.direction");                        // draw direction arrows on the lines
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java

    r1195 r1221  
    147147    }
    148148
     149    static public Color getColor(String name)
     150    {
     151        return Main.pref.getColor(marktr("gps marker"), name != null ? "layer "+name : null, Color.gray);
     152    }
     153
    149154    @Override public void paint(Graphics g, MapView mv) {
    150155        boolean mousePressedTmp = mousePressed;
     
    152157        String mkrTextShow = Main.pref.get("marker.show "+name, "show");
    153158
    154         g.setColor(Main.pref.getColor(marktr("gps marker"), "layer "+name, Color.gray));
     159        g.setColor(getColor(name));
    155160
    156161        for (Marker mkr : data) {
     
    191196        color.addActionListener(new ActionListener(){
    192197            public void actionPerformed(ActionEvent e) {
    193                 JColorChooser c = new JColorChooser(Main.pref.getColor(marktr("gps marker"), "layer "+name, Color.gray));
     198                JColorChooser c = new JColorChooser(getColor(name));
    194199                Object[] options = new Object[]{tr("OK"), tr("Cancel"), tr("Default")};
    195200                int answer = JOptionPane.showOptionDialog(Main.parent, c, tr("Choose a color"), JOptionPane.OK_CANCEL_OPTION,
  • trunk/src/org/openstreetmap/josm/gui/preferences/ColorPreference.java

    r1180 r1221  
    3333
    3434import org.openstreetmap.josm.Main;
    35 import org.openstreetmap.josm.data.osm.visitor.SimplePaintVisitor;
     35import org.openstreetmap.josm.data.osm.visitor.MapPaintVisitor;
     36import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;
     37import org.openstreetmap.josm.gui.layer.GpxLayer;
    3638import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     39import org.openstreetmap.josm.gui.MapScaler;
     40import org.openstreetmap.josm.gui.dialogs.ConflictDialog;
    3741import org.openstreetmap.josm.tools.ColorHelper;
    3842import org.openstreetmap.josm.tools.GBC;
     
    9599
    96100    public void addGui(final PreferenceDialog gui) {
    97         // initial fill with colors from preferences:
    98         Map<String,String> prefColorMap = new TreeMap<String, String>(Main.pref.getAllPrefix("color."));
    99         fixColorPrefixes(prefColorMap);
    100         Map<String,String> colorMap = new TreeMap<String, String>();
    101         for(String key : prefColorMap.keySet()) {
    102             colorMap.put(key.substring("color.".length()), prefColorMap.get(key));
    103         }
    104         setColorModel(colorMap);
     101        fixColorPrefixes();
     102        setColorModel(Main.pref.getAllColors());
    105103
    106104        colors = new JTable(tableModel) {
     
    153151     * Add all missing color entries.
    154152     */
    155     private void fixColorPrefixes(Map<String, String> prefColorMap) {
    156         String[] cp = {
    157             marktr("background"), ColorHelper.color2html(Color.black),
    158             marktr("node"), ColorHelper.color2html(Color.red),
    159             marktr("way"), ColorHelper.color2html(SimplePaintVisitor.darkblue),
    160             marktr("incomplete way"), ColorHelper.color2html(SimplePaintVisitor.darkerblue),
    161             marktr("relation"), ColorHelper.color2html(SimplePaintVisitor.teal),
    162             marktr("selected"), ColorHelper.color2html(Color.white),
    163             marktr("gps marker"), ColorHelper.color2html(Color.gray),
    164             marktr("gps point"), ColorHelper.color2html(Color.gray),
    165             marktr("conflict"), ColorHelper.color2html(Color.gray),
    166             marktr("scale"), ColorHelper.color2html(Color.white),
    167             marktr("inactive"), ColorHelper.color2html(Color.darkGray),
    168         };
    169         for (int i = 0; i < cp.length/2; ++i)
    170         {
    171             if (!Main.pref.hasKey("color."+cp[i*2]))
    172                 Main.pref.put("color."+cp[i*2], cp[i*2+1]);
    173             Main.pref.putDefault("color."+cp[i*2], cp[i*2+1]);
    174         }
     153    private void fixColorPrefixes() {
     154        (new MapPaintVisitor()).getColors();
     155        MarkerLayer.getColor(null);
     156        MapScaler.getColor();
     157        ConflictDialog.getColor();
    175158    }
    176159
Note: See TracChangeset for help on using the changeset viewer.