- Timestamp:
- 2017-01-19T23:23:35+01:00 (8 years ago)
- 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 29 29 import java.util.List; 30 30 31 import javax.swing.ImageIcon; 32 31 33 import org.openstreetmap.josm.Main; 32 34 import org.openstreetmap.josm.data.SystemOfMeasurement; … … 154 156 155 157 // 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); 160 159 161 160 private void setupColors() { … … 166 165 dateScale = ColorScale.createHSBScale(256).addTitle(tr("Time")); 167 166 directionScale = ColorScale.createCyclicScale(256).setIntervalCount(4).addTitle(tr("Direction")); 168 heatMapLutColor = heatMapLutUserColor;169 167 170 168 systemOfMeasurementChanged(null, null); … … 514 512 515 513 // 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); 538 518 539 519 // force redraw of image … … 783 763 784 764 /** 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 /** 785 797 * Creates a linear distributed colormap by linear blending between colors 786 798 * @param colors 1..n colors … … 790 802 791 803 // 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; 811 805 812 806 // access it via raw interface 813 final Raster imgRaster = img.getData();807 final Raster imgRaster = createImageGradientMap(tableSize, 1, colors).getData(); 814 808 815 809 // the pixel storage … … 825 819 826 820 // get next single pixel 827 imgRaster.getDataElements( (int) (i * (double) img.getWidth() / tableSize), 0, pixel);821 imgRaster.getDataElements(i, 0, pixel); 828 822 829 823 // get color and map … … 923 917 924 918 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))); 925 961 } 926 962 -
trunk/src/org/openstreetmap/josm/gui/preferences/display/GPXSettingsPanel.java
r11474 r11483 5 5 import static org.openstreetmap.josm.tools.I18n.trc; 6 6 7 import java.awt.Color; 7 8 import java.awt.Component; 8 9 import java.awt.GridBagLayout; … … 20 21 import org.openstreetmap.josm.Main; 21 22 import org.openstreetmap.josm.actions.ExpertToggleAction; 23 import org.openstreetmap.josm.gui.layer.gpx.GpxDrawHelper; 22 24 import org.openstreetmap.josm.gui.layer.markerlayer.Marker; 23 25 import org.openstreetmap.josm.gui.layer.markerlayer.Marker.TemplateEntryProperty; … … 56 58 private final JRadioButton colorTypeDilution = new JRadioButton(tr("Dilution of Position (red = high, green = low, if available)")); 57 59 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)")); 59 61 private final JRadioButton colorTypeNone = new JRadioButton(tr("Single Color (can be customized for named layers)")); 60 62 private final JRadioButton colorTypeGlobal = new JRadioButton(tr("Use global settings")); … … 260 262 261 263 colorTypeHeatMapTune.setToolTipText(tr("Selects the color schema for heat map.")); 264 JLabel colorTypeHeatIconLabel = new JLabel(); 262 265 263 266 add(Box.createVerticalGlue(), GBC.eol().insets(0, 20, 0, 0)); … … 274 277 add(colorTypeTime, GBC.eol().insets(40, 0, 0, 0)); 275 278 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 }); 277 289 278 290 ExpertToggleAction.addVisibilitySwitcher(colorTypeDirection);
Note:
See TracChangeset
for help on using the changeset viewer.