Changeset 11483 in josm


Ignore:
Timestamp:
2017-01-19T23:23:35+01:00 (7 years ago)
Author:
Don-vip
Message:

fix #14247 - add icon as a visual indication of chosen gpx heatmap (patch by kidelo)

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java

    r11482 r11483  
    2929import java.util.List;
    3030
     31import javax.swing.ImageIcon;
     32
    3133import org.openstreetmap.josm.Main;
    3234import org.openstreetmap.josm.data.SystemOfMeasurement;
     
    154156
    155157    // user defined heatmap color
    156     private Color[] heatMapLutUserColor = createColorLut(Color.BLACK, Color.WHITE);
    157 
    158     // heat map color in use
    159     private Color[] heatMapLutColor;
     158    private Color[] heatMapLutColor = createColorLut(Color.BLACK, Color.WHITE);
    160159
    161160    private void setupColors() {
     
    166165        dateScale = ColorScale.createHSBScale(256).addTitle(tr("Time"));
    167166        directionScale = ColorScale.createCyclicScale(256).setIntervalCount(4).addTitle(tr("Direction"));
    168         heatMapLutColor = heatMapLutUserColor;
    169167
    170168        systemOfMeasurementChanged(null, null);
     
    514512
    515513        // heat mode
    516         if (ColorMode.HEATMAP == colored && neutralColor != null) {
    517 
    518             // generate new user color map
    519             heatMapLutUserColor = createColorLut(Color.BLACK, neutralColor.darker(),
    520                                                  neutralColor, neutralColor.brighter(), Color.WHITE);
    521 
    522             // decide what, keep order is sync with setting on GUI
    523             Color[][] lut = {
    524                     heatMapLutUserColor,
    525                     heatMapLutColorJosmInferno,
    526                     heatMapLutColorJosmViridis,
    527                     heatMapLutColorJosmBrown2Green,
    528                     heatMapLutColorJosmRed2Blue
    529             };
    530 
    531             // select by index
    532             if (heatMapDrawColorTableIdx < lut.length) {
    533                 heatMapLutColor = lut[ heatMapDrawColorTableIdx ];
    534             } else {
    535                 // fallback
    536                 heatMapLutColor = heatMapLutUserColor;
    537             }
     514        if (ColorMode.HEATMAP == colored) {
     515
     516            // generate and get new user color map
     517            heatMapLutColor = selectColorMap(neutralColor != null ? neutralColor : Color.WHITE, heatMapDrawColorTableIdx);
    538518
    539519            // force redraw of image
     
    783763
    784764    /**
     765     * Generates a linear gradient map image
     766     *
     767     * @param width  image width
     768     * @param height image height
     769     * @param colors 1..n color descriptions
     770     * @return image object
     771     */
     772    protected static BufferedImage createImageGradientMap(int width, int height, Color... colors) {
     773
     774        // create image an paint object
     775        final BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
     776        final Graphics2D g = img.createGraphics();
     777
     778        float[] fract = new float[ colors.length ];
     779
     780        // distribute fractions (define position of color in map)
     781        for (int i = 0; i < colors.length; ++i) {
     782            fract[i] = i * (1.0f / colors.length);
     783        }
     784
     785        // draw the gradient map
     786        LinearGradientPaint gradient = new LinearGradientPaint(0, 0, width, height, fract, colors,
     787                                                               MultipleGradientPaint.CycleMethod.NO_CYCLE);
     788        g.setPaint(gradient);
     789        g.fillRect(0, 0, width, height);
     790        g.dispose();
     791
     792        // access it via raw interface
     793        return img;
     794    }
     795
     796    /**
    785797     * Creates a linear distributed colormap by linear blending between colors
    786798     * @param colors 1..n colors
     
    790802
    791803        // number of lookup entries
    792         int tableSize = 256;
    793 
    794         // create image an paint object
    795         BufferedImage img = new BufferedImage(tableSize, 1, BufferedImage.TYPE_INT_RGB);
    796         Graphics2D g = img.createGraphics();
    797 
    798         float[] fract = new float[ colors.length ];
    799 
    800         // distribute fractions (define position of color in map)
    801         for (int i = 0; i < colors.length; ++i) {
    802             fract[i] = i * (1.0f / colors.length);
    803         }
    804 
    805         // draw the gradient map
    806         LinearGradientPaint gradient = new LinearGradientPaint(0, 0, tableSize, 1, fract, colors,
    807                                                                MultipleGradientPaint.CycleMethod.NO_CYCLE);
    808         g.setPaint(gradient);
    809         g.fillRect(0, 0, tableSize, 1);
    810         g.dispose();
     804        final int tableSize = 256;
    811805
    812806        // access it via raw interface
    813         final Raster imgRaster = img.getData();
     807        final Raster imgRaster = createImageGradientMap(tableSize, 1, colors).getData();
    814808
    815809        // the pixel storage
     
    825819
    826820            // get next single pixel
    827             imgRaster.getDataElements((int) (i * (double) img.getWidth() / tableSize), 0, pixel);
     821            imgRaster.getDataElements(i, 0, pixel);
    828822
    829823            // get color and map
     
    923917
    924918        return createColorLut(colorList.toArray(new Color[ colorList.size() ]));
     919    }
     920
     921    /**
     922     * Returns the next user color map
     923     *
     924     * @param userColor - default or fallback user color
     925     * @param tableIdx  - selected user color index
     926     * @return color array
     927     */
     928    protected static Color[] selectColorMap(Color userColor, int tableIdx) {
     929
     930        // generate new user color map
     931        Color[] nextUserColor = createColorLut(Color.BLACK, userColor.darker(),
     932                                               userColor, userColor.brighter(), Color.WHITE);
     933
     934        // decide what, keep order is sync with setting on GUI
     935        Color[][] lut = {
     936                nextUserColor,
     937                heatMapLutColorJosmInferno,
     938                heatMapLutColorJosmViridis,
     939                heatMapLutColorJosmBrown2Green,
     940                heatMapLutColorJosmRed2Blue
     941        };
     942
     943        // select by index
     944        if (tableIdx < lut.length) {
     945            nextUserColor = lut[ tableIdx ];
     946        }
     947
     948        return nextUserColor;
     949    }
     950
     951    /**
     952     * Generates a Icon
     953     *
     954     * @param userColor selected user color
     955     * @param tableIdx tabled index
     956     * @param size size of the image
     957     * @return a image icon that shows the
     958     */
     959    public static ImageIcon getColorMapImageIcon(Color userColor, int tableIdx, int size) {
     960        return new ImageIcon(createImageGradientMap(size, size, selectColorMap(userColor, tableIdx)));
    925961    }
    926962
  • trunk/src/org/openstreetmap/josm/gui/preferences/display/GPXSettingsPanel.java

    r11474 r11483  
    55import static org.openstreetmap.josm.tools.I18n.trc;
    66
     7import java.awt.Color;
    78import java.awt.Component;
    89import java.awt.GridBagLayout;
     
    2021import org.openstreetmap.josm.Main;
    2122import org.openstreetmap.josm.actions.ExpertToggleAction;
     23import org.openstreetmap.josm.gui.layer.gpx.GpxDrawHelper;
    2224import org.openstreetmap.josm.gui.layer.markerlayer.Marker;
    2325import org.openstreetmap.josm.gui.layer.markerlayer.Marker.TemplateEntryProperty;
     
    5658    private final JRadioButton colorTypeDilution = new JRadioButton(tr("Dilution of Position (red = high, green = low, if available)"));
    5759    private final JRadioButton colorTypeTime = new JRadioButton(tr("Track date"));
    58     private final JRadioButton colorTypeHeatMap = new JRadioButton(tr("Heat Map (dark = few tracks, bright = many tracks)"));
     60    private final JRadioButton colorTypeHeatMap = new JRadioButton(tr("Heat Map (dark = few, bright = many)"));
    5961    private final JRadioButton colorTypeNone = new JRadioButton(tr("Single Color (can be customized for named layers)"));
    6062    private final JRadioButton colorTypeGlobal = new JRadioButton(tr("Use global settings"));
     
    260262
    261263        colorTypeHeatMapTune.setToolTipText(tr("Selects the color schema for heat map."));
     264        JLabel colorTypeHeatIconLabel = new JLabel();
    262265
    263266        add(Box.createVerticalGlue(), GBC.eol().insets(0, 20, 0, 0));
     
    274277        add(colorTypeTime, GBC.eol().insets(40, 0, 0, 0));
    275278        add(colorTypeHeatMap, GBC.std().insets(40, 0, 0, 0));
    276         add(colorTypeHeatMapTune, GBC.eop().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
     279        add(colorTypeHeatIconLabel, GBC.std().insets(5, 0, 0, 5));
     280        add(colorTypeHeatMapTune, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
     281
     282        colorTypeHeatMapTune.addPropertyChangeListener(e -> {
     283            // get image size of environment
     284            final int iconSize = (int) colorTypeHeatMapTune.getPreferredSize().getHeight();
     285            // ask the GPX draw for the correct color of that layer
     286            final Color color = GpxDrawHelper.DEFAULT_COLOR.getChildColor(layerName != null ? layerName : "").get();
     287            colorTypeHeatIconLabel.setIcon(GpxDrawHelper.getColorMapImageIcon(color, colorTypeHeatMapTune.getSelectedIndex(), iconSize));
     288        });
    277289
    278290        ExpertToggleAction.addVisibilitySwitcher(colorTypeDirection);
Note: See TracChangeset for help on using the changeset viewer.