Skip to content

Commit e425b96

Browse files
committed
Add layer style palette Spectrum Third
1 parent bc449d1 commit e425b96

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

modules/app/src/main/java/org/locationtech/jtstest/testbuilder/LayerStylePanel.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ public void stateChanged(ChangeEvent e) {
580580
}
581581

582582
//-----------------------------------------
583-
static String[] paletteNames = { "Basic", "Varying", "Spectrum", "Spectrum Random" };
583+
static String[] paletteNames = { "Basic", "Varying", "Spectrum", "Spectrum Random", "Spectrum Third" };
584584

585585
private static int getPaletteType(JComboBox comboPal) {
586586
String palName = (String)comboPal.getSelectedItem();
@@ -589,6 +589,7 @@ private static int getPaletteType(JComboBox comboPal) {
589589
if (palName.equalsIgnoreCase(paletteNames[1])) paletteType = Palette.TYPE_VARY;
590590
if (palName.equalsIgnoreCase(paletteNames[2])) paletteType = Palette.TYPE_SPECTRUM;
591591
if (palName.equalsIgnoreCase(paletteNames[3])) paletteType = Palette.TYPE_SPECTRUM_RANDOM;
592+
if (palName.equalsIgnoreCase(paletteNames[4])) paletteType = Palette.TYPE_SPECTRUM_THIRD;
592593
return paletteType;
593594
}
594595

@@ -597,6 +598,7 @@ private static void setPaletteType(JComboBox comboPal, int paletteType) {
597598
if (paletteType == Palette.TYPE_VARY) index = 1;
598599
if (paletteType == Palette.TYPE_SPECTRUM) index = 2;
599600
if (paletteType == Palette.TYPE_SPECTRUM_RANDOM) index = 3;
601+
if (paletteType == Palette.TYPE_SPECTRUM_THIRD) index = 4;
600602
comboPal.setSelectedIndex(index);
601603
}
602604

modules/app/src/main/java/org/locationtech/jtstest/testbuilder/ui/style/Palette.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,19 @@ public class Palette {
2222
public static final int TYPE_VARY = 2;
2323
public static final int TYPE_SPECTRUM = 3;
2424
public static final int TYPE_SPECTRUM_RANDOM = 4;
25+
public static final int TYPE_SPECTRUM_THIRD = 5;
2526

2627
private static final float BRIGHT_RANGE = 0.1f;
2728
private static final float SAT_RANGE = 0.2f;
2829

2930
public static HSBPalette customPalette(int paletteType, Color clrBase, int numHues) {
30-
HSBPalette pal = null;
31+
3132
float sat = ColorUtil.getSaturation(clrBase);
3233
float bright = ColorUtil.getBrightness(clrBase);
34+
float hue = ColorUtil.getHue(clrBase);
35+
36+
HSBPalette pal = null;
3337
if (TYPE_VARY == paletteType) {
34-
float hue = ColorUtil.getHue(clrBase);
3538
pal = new HSBPalette(5, hue, HSBPalette.HUE_WIDTH / 2,
3639
3, sat - SAT_RANGE/2, sat + SAT_RANGE/2,
3740
3, bright - BRIGHT_RANGE/2, bright + BRIGHT_RANGE/2
@@ -43,6 +46,9 @@ else if (TYPE_SPECTRUM == paletteType) {
4346
else if (TYPE_SPECTRUM_RANDOM == paletteType) {
4447
return HSBPalette.createSpectrumIncremental(0.23f, sat, bright);
4548
}
49+
else if (TYPE_SPECTRUM_THIRD == paletteType) {
50+
return HSBPalette.createSpectrumRange(numHues, 0.333f, hue, sat, bright);
51+
}
4652
return pal;
4753
}
4854

modules/app/src/main/java/org/locationtech/jtstest/util/HSBPalette.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ public static HSBPalette createSpectrumIncremental(float hInc, float s, float b)
4444
return pal;
4545
}
4646

47+
public static HSBPalette createSpectrumRange(int numHue, float hueRange, float h, float s, float b) {
48+
return new HSBPalette(numHue, h, hueRange,
49+
1, s, s,
50+
1, b, b
51+
);
52+
}
53+
4754
private void setHueInc(float hInc) {
4855
this.hInc = hInc;
4956
}
@@ -74,7 +81,7 @@ public HSBPalette(
7481
this.numB = numB;
7582
this.hBase = hBase;
7683
this.hRange = hRange;
77-
this.h1 = hBase - hRange / 2;
84+
this.h1 = hBase;
7885
this.sLo = sLo;
7986
this.bLo = bLo;
8087
// TODO: make this mod 1

0 commit comments

Comments
 (0)