Changeset 11483 in josm for trunk/src/org/openstreetmap/josm/gui/layer/gpx
- Timestamp:
- 2017-01-19T23:23:35+01:00 (7 years ago)
- File:
-
- 1 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
Note:
See TracChangeset
for help on using the changeset viewer.