From 06f6b0ed8c59f55058d3448fdbfc22769935fbf7 Mon Sep 17 00:00:00 2001 From: Martin Davis Date: Tue, 18 Aug 2020 12:15:58 -0700 Subject: [PATCH 1/8] Add TestBuilder layer style palette control Signed-off-by: Martin Davis --- .../testbuilder/JTSTestBuilderMenuBar.java | 41 ----------------- .../jtstest/testbuilder/LayerStylePanel.java | 40 ++++++++++++++++- .../controller/JTSTestBuilderController.java | 5 --- .../testbuilder/model/DisplayParameters.java | 13 ------ .../testbuilder/model/TestBuilderModel.java | 25 +++++++---- .../testbuilder/ui/render/LayerRenderer.java | 43 +++--------------- .../testbuilder/ui/style/LayerStyle.java | 9 +++- .../jtstest/testbuilder/ui/style/Palette.java | 45 +++++++++++++++++++ 8 files changed, 116 insertions(+), 105 deletions(-) create mode 100644 modules/app/src/main/java/org/locationtech/jtstest/testbuilder/ui/style/Palette.java diff --git a/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/JTSTestBuilderMenuBar.java b/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/JTSTestBuilderMenuBar.java index b3b71b46c1..8f509a2ede 100644 --- a/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/JTSTestBuilderMenuBar.java +++ b/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/JTSTestBuilderMenuBar.java @@ -15,15 +15,12 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import javax.swing.ButtonGroup; import javax.swing.JCheckBoxMenuItem; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JRadioButtonMenuItem; -import org.locationtech.jtstest.testbuilder.model.DisplayParameters; - public class JTSTestBuilderMenuBar { JMenuBar jMenuBar1 = new JMenuBar(); @@ -129,31 +126,6 @@ public void actionPerformed(ActionEvent e) { } }); - final JMenuItem basicFillMenuItem = menuItemRadio("Basic Fill", true, - new ActionListener() { - public void actionPerformed(ActionEvent e) { - JTSTestBuilder.controller().setFillType(DisplayParameters.FILL_BASIC); - } - }); - final JMenuItem varyFillMenuItem = menuItemRadio("Varying Fill", false, - new ActionListener() { - public void actionPerformed(ActionEvent e) { - JTSTestBuilder.controller().setFillType(DisplayParameters.FILL_VARY); - } - }); - final JMenuItem rainbowFillMenuItem = menuItemRadio("Rainbow Fill", false, - new ActionListener() { - public void actionPerformed(ActionEvent e) { - JTSTestBuilder.controller().setFillType(DisplayParameters.FILL_RAINBOW); - } - }); - final JMenuItem rainbowRandomFillMenuItem = menuItemRadio("Random Rainbow Fill", false, - new ActionListener() { - public void actionPerformed(ActionEvent e) { - JTSTestBuilder.controller().setFillType(DisplayParameters.FILL_RAINBOW_RANDOM); - } - }); - menuLoadXmlTestFolder.setText("Open XML Folder(s)..."); menuLoadXmlTestFolder.addActionListener( new java.awt.event.ActionListener() { @@ -184,13 +156,6 @@ public void actionPerformed(ActionEvent e) { //jMenuOptions.setText("Options"); //jMenuTools.setText("Tools"); - ButtonGroup fillGroup = new ButtonGroup(); - fillGroup.add(basicFillMenuItem); - fillGroup.add(varyFillMenuItem); - fillGroup.add(rainbowFillMenuItem); - fillGroup.add(rainbowRandomFillMenuItem); - basicFillMenuItem.setSelected(true); - jMenuFile.add(menuLoadXmlTestFile); jMenuFile.add(menuLoadXmlTestFolder); jMenuFile.add(saveAsXmlMenuItem); @@ -206,12 +171,6 @@ public void actionPerformed(ActionEvent e) { //========================== jMenuView.setText("View"); - jMenuView.add(basicFillMenuItem); - jMenuView.add(varyFillMenuItem); - jMenuView.add(rainbowFillMenuItem); - jMenuView.add(rainbowRandomFillMenuItem); - - jMenuView.addSeparator(); jMenuView.add(menuViewText); jMenuView.add(menuViewGeometry); //========================== diff --git a/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/LayerStylePanel.java b/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/LayerStylePanel.java index 15327bedc9..adff3436bb 100644 --- a/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/LayerStylePanel.java +++ b/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/LayerStylePanel.java @@ -21,12 +21,12 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import javax.swing.AbstractButton; import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JCheckBox; +import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; @@ -44,6 +44,7 @@ import org.locationtech.jtstest.testbuilder.ui.SwingUtil; import org.locationtech.jtstest.testbuilder.ui.style.BasicStyle; import org.locationtech.jtstest.testbuilder.ui.style.LayerStyle; +import org.locationtech.jtstest.testbuilder.ui.style.Palette; public class LayerStylePanel extends JPanel { private Layer layer; @@ -78,6 +79,7 @@ public class LayerStylePanel extends JPanel { private JSpinner spinnerOffsetSize; private SpinnerNumberModel offsetSizeModel; private JCheckBox cbEndpoint; + private JComboBox comboPalette; public LayerStylePanel() { @@ -112,6 +114,7 @@ public void setLayer(Layer layer, boolean isModifiable) { cbOrient.setSelected(layer.getLayerStyle().isOrientations()); cbStructure.setSelected(layer.getLayerStyle().isOrientations()); lineWidthModel.setValue(geomStyle().getStrokeWidth()); + setPaletteType(comboPalette, layer.getLayerStyle().getFillType()); updateStyleControls(); } @@ -425,6 +428,21 @@ public void actionPerformed(ActionEvent arg0) { //============================================= + + comboPalette = new JComboBox(paletteNames); + comboPalette.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + JComboBox cb = (JComboBox)e.getSource(); + int fillType = getPaletteType(cb); + layer.getLayerStyle().setFillType(fillType); + JTSTestBuilder.controller().geometryViewChanged(); + } + }); + addRow("", new JLabel("Palette"), comboPalette); + + //============================================= + + cbLabel = new JCheckBox(); //cbLabel.setToolTipText(AppStrings.TIP_STYLE_VERTEX_ENABLE); cbLabel.setAlignmentX(Component.LEFT_ALIGNMENT); @@ -468,6 +486,26 @@ public void stateChanged(ChangeEvent e) { return containerPanel; } + static String[] paletteNames = { "Basic", "Varying", "Rainbow", "Rainbow Random" }; + + private static int getPaletteType(JComboBox comboPal) { + String palName = (String)comboPal.getSelectedItem(); + + int paletteType = Palette.TYPE_BASIC; + if (palName.equalsIgnoreCase(paletteNames[1])) paletteType = Palette.TYPE_VARY; + if (palName.equalsIgnoreCase(paletteNames[2])) paletteType = Palette.TYPE_RAINBOW; + if (palName.equalsIgnoreCase(paletteNames[3])) paletteType = Palette.TYPE_RAINBOW_RANDOM; + return paletteType; + } + + private static void setPaletteType(JComboBox comboPal, int paletteType) { + int index = 0; + if (paletteType == Palette.TYPE_VARY) index = 1; + if (paletteType == Palette.TYPE_RAINBOW) index = 2; + if (paletteType == Palette.TYPE_RAINBOW_RANDOM) index = 3; + comboPal.setSelectedIndex(index); + } + protected static Color lineColorFromFill(Color clr) { return ColorUtil.saturate(clr, 1); //return clr.darker(); diff --git a/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/controller/JTSTestBuilderController.java b/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/controller/JTSTestBuilderController.java index 9fe00b066e..5874c93dbb 100644 --- a/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/controller/JTSTestBuilderController.java +++ b/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/controller/JTSTestBuilderController.java @@ -81,11 +81,6 @@ public GeometryEditModel geomEditModel() { return JTSTestBuilder.model().getGeometryEditModel(); } - public void setFillType(int fillType) { - DisplayParameters.setFillType(fillType); - geometryViewChanged(); - } - public void geometryViewChanged() { getGeometryEditPanel().updateView(); diff --git a/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/model/DisplayParameters.java b/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/model/DisplayParameters.java index b9cacb6d30..7fb1bc3319 100644 --- a/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/model/DisplayParameters.java +++ b/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/model/DisplayParameters.java @@ -46,19 +46,6 @@ public static double getTopologyStretchSize() { public static int MAX_DISPLAY_POINTS = 2000; - public static final int FILL_BASIC = 1; - public static final int FILL_VARY = 2; - public static final int FILL_RAINBOW = 3; - public static final int FILL_RAINBOW_RANDOM = 4; - private static int fillType = FILL_BASIC; - - public static int fillType() { - return fillType; - } - - public static void setFillType(int type) { - fillType = type; - } } diff --git a/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/model/TestBuilderModel.java b/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/model/TestBuilderModel.java index 2199caf904..a990b54df4 100644 --- a/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/model/TestBuilderModel.java +++ b/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/model/TestBuilderModel.java @@ -12,22 +12,31 @@ package org.locationtech.jtstest.testbuilder.model; -import java.io.*; -import java.util.*; - -import org.locationtech.jts.geom.*; -import org.locationtech.jts.io.*; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +import org.locationtech.jts.geom.Geometry; +import org.locationtech.jts.geom.GeometryFactory; +import org.locationtech.jts.geom.PrecisionModel; +import org.locationtech.jts.io.ParseException; +import org.locationtech.jts.io.WKTReader; +import org.locationtech.jts.io.WKTWriter; import org.locationtech.jts.math.MathUtil; import org.locationtech.jts.util.Assert; import org.locationtech.jtstest.test.TestCaseList; import org.locationtech.jtstest.test.Testable; -import org.locationtech.jtstest.testbuilder.AppConstants; import org.locationtech.jtstest.testbuilder.GeometryDepiction; -import org.locationtech.jtstest.testbuilder.ui.*; +import org.locationtech.jtstest.testbuilder.ui.SwingUtil; import org.locationtech.jtstest.testbuilder.ui.style.BasicStyle; import org.locationtech.jtstest.testrunner.TestReader; import org.locationtech.jtstest.testrunner.TestRun; -import org.locationtech.jtstest.util.*; +import org.locationtech.jtstest.util.ExceptionFormatter; +import org.locationtech.jtstest.util.StringUtil; import org.locationtech.jtstest.util.io.IOUtil; import org.locationtech.jtstest.util.io.MultiFormatReader; diff --git a/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/ui/render/LayerRenderer.java b/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/ui/render/LayerRenderer.java index 1eed665d0b..4b5f82af5f 100644 --- a/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/ui/render/LayerRenderer.java +++ b/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/ui/render/LayerRenderer.java @@ -12,18 +12,16 @@ package org.locationtech.jtstest.testbuilder.ui.render; -import java.awt.Color; import java.awt.Graphics2D; import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.geom.GeometryCollection; -import org.locationtech.jtstest.testbuilder.model.DisplayParameters; import org.locationtech.jtstest.testbuilder.model.GeometryContainer; import org.locationtech.jtstest.testbuilder.model.Layer; -import org.locationtech.jtstest.testbuilder.ui.ColorUtil; import org.locationtech.jtstest.testbuilder.ui.Viewport; import org.locationtech.jtstest.testbuilder.ui.style.BasicStyle; import org.locationtech.jtstest.testbuilder.ui.style.LayerStyle; +import org.locationtech.jtstest.testbuilder.ui.style.Palette; import org.locationtech.jtstest.testbuilder.ui.style.Style; import org.locationtech.jtstest.util.HSBPalette; @@ -79,7 +77,7 @@ private void render(Graphics2D g, Viewport viewport, Geometry geometry, Layer la // for maximum rendering speed this needs to be checked for each component if (! viewport.intersectsInModel(geometry.getEnvelopeInternal())) return; - if (DisplayParameters.FILL_BASIC == DisplayParameters.fillType()) { + if (Palette.TYPE_BASIC == layer.getLayerStyle().getFillType()) { renderGeom(g, viewport, geometry, layer.getLayerStyle()); } else { @@ -91,7 +89,9 @@ private void renderCustomFill(Graphics2D g, Viewport viewport, Geometry gc, Layer layer ) throws Exception { int numGeom = gc.getNumGeometries(); - HSBPalette pal = customPalette(layer.getGeometryStyle().getFillColor(), numGeom); + HSBPalette pal = Palette.customPalette( + layer.getLayerStyle().getFillType(), + layer.getGeometryStyle().getFillColor(), numGeom); /** * Render each element separately. * Otherwise it is not possible to render both filled and non-filled @@ -100,7 +100,7 @@ private void renderCustomFill(Graphics2D g, Viewport viewport, */ for (int i = 0; i < numGeom; i++) { if (isCancelled) return; - BasicStyle customFill = paletteFill(i, pal, layer.getGeometryStyle()); + BasicStyle customFill = Palette.paletteFill(i, pal, layer.getGeometryStyle()); Style st = new LayerStyle(customFill, layer.getLayerStyle().getDecoratorStyle()); renderGeom(g, viewport, gc.getGeometryN(i), st); } @@ -121,36 +121,7 @@ private void renderGeom(Graphics2D g, Viewport viewport, Geometry geometry, Styl } } - private static final HSBPalette PAL_RAINBOW_INCREMENTAL = HSBPalette.createRainbowIncremental(0.396f, 0.4f, 1); - - private static HSBPalette customPalette(Color clrBase, int numHues) { - HSBPalette pal = null; - if (DisplayParameters.FILL_VARY == DisplayParameters.fillType()) { - float hue = ColorUtil.getHue(clrBase); - pal = new HSBPalette(5, hue, 0.1f, - 3, 0.3f, 0.7f, - 3, 0.8f, 0.9f - ); - } - else if (DisplayParameters.FILL_RAINBOW == DisplayParameters.fillType()) { - return HSBPalette.createRainbow(numHues, 0.4f, 1); - } - else if (DisplayParameters.FILL_RAINBOW_RANDOM == DisplayParameters.fillType()) { - return PAL_RAINBOW_INCREMENTAL; - } - return pal; - } - - private static BasicStyle paletteFill(int i, HSBPalette pal, BasicStyle style) { - Color clrBase = style.getFillColor(); - int alpha = clrBase.getAlpha(); - Color clr = pal.color(i, alpha); - BasicStyle st = style.copy(); - st.setFillColor(clr); - return st; - } - - public void cancel() + public void cancel() { isCancelled = true; } diff --git a/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/ui/style/LayerStyle.java b/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/ui/style/LayerStyle.java index 9ec3c23ecf..aeba7e57ee 100644 --- a/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/ui/style/LayerStyle.java +++ b/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/ui/style/LayerStyle.java @@ -20,7 +20,6 @@ import org.locationtech.jts.linearref.LengthIndexedLine; import org.locationtech.jts.operation.buffer.BufferParameters; import org.locationtech.jts.operation.buffer.OffsetCurveBuilder; -import org.locationtech.jtstest.testbuilder.model.DisplayParameters; import org.locationtech.jtstest.testbuilder.ui.ColorUtil; import org.locationtech.jtstest.testbuilder.ui.Viewport; @@ -32,6 +31,7 @@ public class LayerStyle implements Style { private StyleList decoratorStyle; private VertexStyle vertexStyle; private DataLabelStyle labelStyle; + private int fillType = Palette.TYPE_BASIC; private StyleGroup orientStyle; private StyleGroup structureStyle; @@ -128,6 +128,13 @@ private void update(LayerStyle layerStyle) { setEndpoints(layerStyle.isEndpoints()); } + public int getFillType() { + return fillType; + } + public void setFillType(int fillType) { + this.fillType = fillType; + } + public void setColor(Color color) { segArrowStyle.setColor( ColorUtil.lighter(color,0.8) ); lineArrowStyle.setColor( ColorUtil.lighter(color,0.5) ); diff --git a/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/ui/style/Palette.java b/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/ui/style/Palette.java new file mode 100644 index 0000000000..14925c0954 --- /dev/null +++ b/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/ui/style/Palette.java @@ -0,0 +1,45 @@ +package org.locationtech.jtstest.testbuilder.ui.style; + +import java.awt.Color; + +import org.locationtech.jtstest.testbuilder.ui.ColorUtil; +import org.locationtech.jtstest.util.HSBPalette; + +public class Palette { + + public static final int TYPE_BASIC = 1; + public static final int TYPE_VARY = 2; + public static final int TYPE_RAINBOW = 3; + public static final int TYPE_RAINBOW_RANDOM = 4; + + private static final HSBPalette PAL_RAINBOW_INCREMENTAL = HSBPalette.createRainbowIncremental(0.396f, 0.4f, 1); + + public static HSBPalette customPalette(int paletteType, Color clrBase, int numHues) { + HSBPalette pal = null; + if (TYPE_VARY == paletteType) { + float hue = ColorUtil.getHue(clrBase); + pal = new HSBPalette(5, hue, 0.1f, + 3, 0.3f, 0.7f, + 3, 0.8f, 0.9f + ); + } + else if (TYPE_RAINBOW == paletteType) { + return HSBPalette.createRainbow(numHues, 0.4f, 1); + } + else if (TYPE_RAINBOW_RANDOM == paletteType) { + return PAL_RAINBOW_INCREMENTAL; + } + return pal; + } + + public static BasicStyle paletteFill(int i, HSBPalette pal, BasicStyle style) { + Color clrBase = style.getFillColor(); + int alpha = clrBase.getAlpha(); + Color clr = pal.color(i, alpha); + BasicStyle st = style.copy(); + st.setFillColor(clr); + return st; + } + + +} From c661627bd6c87f8c582cdeccc64da1611e4d9b30 Mon Sep 17 00:00:00 2001 From: Martin Davis Date: Wed, 19 Aug 2020 15:45:22 -0700 Subject: [PATCH 2/8] Add TestBuilder line style palette control Signed-off-by: Martin Davis --- .../jtstest/testbuilder/AppStrings.java | 2 ++ .../jtstest/testbuilder/LayerListPanel.java | 4 +++- .../jtstest/testbuilder/LayerStylePanel.java | 24 +++++++++++++++---- .../jtstest/testbuilder/ui/ColorUtil.java | 10 ++++++++ .../testbuilder/ui/render/LayerRenderer.java | 22 ++++++++++++++--- .../jtstest/testbuilder/ui/style/Palette.java | 14 +++++------ 6 files changed, 59 insertions(+), 17 deletions(-) diff --git a/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/AppStrings.java b/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/AppStrings.java index d5002d18b7..cb30eb8024 100644 --- a/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/AppStrings.java +++ b/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/AppStrings.java @@ -83,5 +83,7 @@ public class AppStrings { public static final String TIP_STYLE_VERTEX_LABEL_ENABLE = "Show vertex labels"; + public static final String TIP_STYLE_PALETTE = "Palette type used for Lines or Fills.
Layer color determines base hue and lightness "; + } diff --git a/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/LayerListPanel.java b/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/LayerListPanel.java index bb6b7d04bb..0dcfc40cb3 100644 --- a/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/LayerListPanel.java +++ b/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/LayerListPanel.java @@ -154,7 +154,9 @@ public void actionPerformed(ActionEvent e) { //add(lyrStylePanel, BorderLayout.CENTER); //tabFunctions.setBackground(jTabbedPane1.getBackground()); - tabPane.add(lyrStylePanel, LBL_LAYER); + JScrollPane scrollPane = new JScrollPane(); + scrollPane.getViewport().add(lyrStylePanel, null); + tabPane.add(scrollPane, LBL_LAYER); tabPane.add(viewStylePanel, LBL_VIEW); add(tabPane, BorderLayout.CENTER); } diff --git a/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/LayerStylePanel.java b/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/LayerStylePanel.java index adff3436bb..e961a48a70 100644 --- a/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/LayerStylePanel.java +++ b/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/LayerStylePanel.java @@ -268,7 +268,7 @@ public void colorChanged(Color clr) { } } ); - JButton btnVertexSynch = SwingUtil.createButton("^", "Synch Vertex Color", new ActionListener() { + JButton btnVertexSynch = createSynchButton("^", "Synch Vertex Color", new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (layer == null) return; Color clr = ColorControl.getColor(btnLineColor); @@ -306,7 +306,7 @@ public void stateChanged(ChangeEvent e) { } } }); - addRow("Line", cbStroked, btnLineColor, btnVertexSynch, spinnerLineWidth, sliderLineAlpha); + addRow("Line", cbStroked, btnLineColor, btnVertexSynch, sliderLineAlpha, spinnerLineWidth); //============================================= cbDashed = new JCheckBox(); @@ -415,7 +415,7 @@ public void colorChanged(Color clr) { } } ); - JButton btnLineSynch = SwingUtil.createButton("^", "Synch Line Color", new ActionListener() { + JButton btnLineSynch = createSynchButton("^", "Synch Line Color", new ActionListener() { public void actionPerformed(ActionEvent arg0) { Color clr = lineColorFromFill( ColorControl.getColor(btnFillColor)); geomStyle().setLineColor(clr ); @@ -428,7 +428,6 @@ public void actionPerformed(ActionEvent arg0) { //============================================= - comboPalette = new JComboBox(paletteNames); comboPalette.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -438,7 +437,8 @@ public void actionPerformed(ActionEvent e) { JTSTestBuilder.controller().geometryViewChanged(); } }); - addRow("", new JLabel("Palette"), comboPalette); + comboPalette.setToolTipText(AppStrings.TIP_STYLE_PALETTE); + addRow("Palette", comboPalette); //============================================= @@ -511,8 +511,22 @@ protected static Color lineColorFromFill(Color clr) { //return clr.darker(); } + private JButton createSynchButton(String lbl, String tip, ActionListener actionListener) { + JButton btn = SwingUtil.createButton(lbl, tip, actionListener); + btn.setMargin(new Insets(0, 0, 0, 0)); + Dimension dim = new Dimension(16, 20); + btn.setMinimumSize(dim); + btn.setPreferredSize(dim); + btn.setMaximumSize(dim); + return btn; + } + private JSlider createOpacitySlider(ChangeListener changeListener) { JSlider slide = new JSlider(JSlider.HORIZONTAL, 0, 255, 150); + Dimension dim = new Dimension(80, 20); + slide.setMinimumSize(dim); + slide.setPreferredSize(dim); + slide.setMaximumSize(dim); slide.addChangeListener(changeListener); slide.setMajorTickSpacing(32); slide.setPaintTicks(true); diff --git a/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/ui/ColorUtil.java b/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/ui/ColorUtil.java index f4f1a0fc35..bce8f0264e 100644 --- a/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/ui/ColorUtil.java +++ b/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/ui/ColorUtil.java @@ -64,6 +64,16 @@ public static float getHue(Color clr) { return hsb[0]; } + public static float getSaturation(Color clr) { + float[] hsb = Color.RGBtoHSB(clr.getRed(), clr.getGreen(), clr.getBlue(), null); + return hsb[1]; + } + + public static float getBrightness(Color clr) { + float[] hsb = Color.RGBtoHSB(clr.getRed(), clr.getGreen(), clr.getBlue(), null); + return hsb[2]; + } + public static Color setAlpha(Color clr, int alpha) { return new Color(clr.getRed(), clr.getGreen(), clr.getBlue(), alpha); } diff --git a/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/ui/render/LayerRenderer.java b/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/ui/render/LayerRenderer.java index 4b5f82af5f..030252d5ad 100644 --- a/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/ui/render/LayerRenderer.java +++ b/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/ui/render/LayerRenderer.java @@ -12,6 +12,7 @@ package org.locationtech.jtstest.testbuilder.ui.render; +import java.awt.Color; import java.awt.Graphics2D; import org.locationtech.jts.geom.Geometry; @@ -89,9 +90,15 @@ private void renderCustomFill(Graphics2D g, Viewport viewport, Geometry gc, Layer layer ) throws Exception { int numGeom = gc.getNumGeometries(); + boolean isLinear = gc.getDimension() == 1; + Color clrBase = layer.getGeometryStyle().getFillColor(); + if (isLinear) { + clrBase = layer.getGeometryStyle().getLineColor(); + } + HSBPalette pal = Palette.customPalette( layer.getLayerStyle().getFillType(), - layer.getGeometryStyle().getFillColor(), numGeom); + clrBase, numGeom); /** * Render each element separately. * Otherwise it is not possible to render both filled and non-filled @@ -100,8 +107,17 @@ private void renderCustomFill(Graphics2D g, Viewport viewport, */ for (int i = 0; i < numGeom; i++) { if (isCancelled) return; - BasicStyle customFill = Palette.paletteFill(i, pal, layer.getGeometryStyle()); - Style st = new LayerStyle(customFill, layer.getLayerStyle().getDecoratorStyle()); + BasicStyle customStyle = layer.getGeometryStyle().copy(); + if (isLinear) { + Color clr = Palette.paletteColor(i, pal, layer.getGeometryStyle().getLineColor()); + customStyle.setLineColor(clr); + } + else { + Color clr = Palette.paletteColor(i, pal, layer.getGeometryStyle().getFillColor()); + customStyle.setFillColor(clr); + } + + Style st = new LayerStyle(customStyle, layer.getLayerStyle().getDecoratorStyle()); renderGeom(g, viewport, gc.getGeometryN(i), st); } } diff --git a/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/ui/style/Palette.java b/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/ui/style/Palette.java index 14925c0954..05e29bf520 100644 --- a/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/ui/style/Palette.java +++ b/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/ui/style/Palette.java @@ -16,6 +16,8 @@ public class Palette { public static HSBPalette customPalette(int paletteType, Color clrBase, int numHues) { HSBPalette pal = null; + float sat = 0.6f; //ColorUtil.getSaturation(clrBase); + float bright = ColorUtil.getBrightness(clrBase); if (TYPE_VARY == paletteType) { float hue = ColorUtil.getHue(clrBase); pal = new HSBPalette(5, hue, 0.1f, @@ -24,22 +26,18 @@ public static HSBPalette customPalette(int paletteType, Color clrBase, int numHu ); } else if (TYPE_RAINBOW == paletteType) { - return HSBPalette.createRainbow(numHues, 0.4f, 1); + return HSBPalette.createRainbow(numHues, sat, bright); } else if (TYPE_RAINBOW_RANDOM == paletteType) { - return PAL_RAINBOW_INCREMENTAL; + return HSBPalette.createRainbowIncremental(0.396f, sat, bright); } return pal; } - public static BasicStyle paletteFill(int i, HSBPalette pal, BasicStyle style) { - Color clrBase = style.getFillColor(); + public static Color paletteColor(int i, HSBPalette pal, Color clrBase) { int alpha = clrBase.getAlpha(); Color clr = pal.color(i, alpha); - BasicStyle st = style.copy(); - st.setFillColor(clr); - return st; + return clr; } - } From 144fb58c4b7bb793ed042e89f72190992f01c4fa Mon Sep 17 00:00:00 2001 From: Martin Davis Date: Wed, 19 Aug 2020 15:47:30 -0700 Subject: [PATCH 3/8] Update JTS_Version_History.md --- doc/JTS_Version_History.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/JTS_Version_History.md b/doc/JTS_Version_History.md index ee21b6293a..c04df377b7 100644 --- a/doc/JTS_Version_History.md +++ b/doc/JTS_Version_History.md @@ -36,6 +36,12 @@ Distributions for older JTS versions can be obtained at the * Fix `IndexedPointInAreaLocator` thread-safety (#572) * Fix `WKTReader` to handle MultiPoints containing `EMPTY` (#575) +## JTS TestBuilder + +### Functionality Improvements + +* Add per-Layer palette control for Strokes and Fills + ## JTS TestRunner ### Functionality Improvements From aa8a6a42711f48fbce40b7674cf8aeeee0436b20 Mon Sep 17 00:00:00 2001 From: Jody Garnett Date: Wed, 26 Aug 2020 10:30:28 -0700 Subject: [PATCH 4/8] Adjust reverse and reverseInternal visibility and type narrowing (#582) * Adjust reverse and reverseInternal visibility and type narrowing This change addresses an unintended consequence where the visibility of these methods as implemented by geometry subclasses was inconsistent. * Restore LinearRing reverseInternal visibility to protected Signed-off-by: Jody Garnett --- .../org/locationtech/jts/geom/GeometryCollection.java | 9 ++++----- .../main/java/org/locationtech/jts/geom/LineString.java | 7 +++---- .../main/java/org/locationtech/jts/geom/LinearRing.java | 7 +++---- .../java/org/locationtech/jts/geom/MultiLineString.java | 5 ++--- .../main/java/org/locationtech/jts/geom/MultiPoint.java | 4 ++++ .../java/org/locationtech/jts/geom/MultiPolygon.java | 5 ++--- .../src/main/java/org/locationtech/jts/geom/Point.java | 7 +++---- .../src/main/java/org/locationtech/jts/geom/Polygon.java | 7 +++---- 8 files changed, 24 insertions(+), 27 deletions(-) diff --git a/modules/core/src/main/java/org/locationtech/jts/geom/GeometryCollection.java b/modules/core/src/main/java/org/locationtech/jts/geom/GeometryCollection.java index ff8b4127d5..be615b11b0 100644 --- a/modules/core/src/main/java/org/locationtech/jts/geom/GeometryCollection.java +++ b/modules/core/src/main/java/org/locationtech/jts/geom/GeometryCollection.java @@ -279,20 +279,19 @@ protected int getTypeCode() { * The order of the components in the collection are not reversed. * * @return a {@link GeometryCollection} in the reverse order - * @deprecated */ - public Geometry reverse() { - return super.reverse(); + public GeometryCollection reverse() { + return (GeometryCollection) super.reverse(); } - protected Geometry reverseInternal() + protected GeometryCollection reverseInternal() { int numGeometries = geometries.length; Collection reversed = new ArrayList<>(numGeometries); for (int i = 0; i < numGeometries; i++) { reversed.add(geometries[i].reverse()); } - return getFactory().buildGeometry(reversed); + return (GeometryCollection) getFactory().buildGeometry(reversed); } } diff --git a/modules/core/src/main/java/org/locationtech/jts/geom/LineString.java b/modules/core/src/main/java/org/locationtech/jts/geom/LineString.java index d44074f929..ca0eeb8a74 100644 --- a/modules/core/src/main/java/org/locationtech/jts/geom/LineString.java +++ b/modules/core/src/main/java/org/locationtech/jts/geom/LineString.java @@ -179,13 +179,12 @@ public Geometry getBoundary() { * order of this objects * * @return a {@link LineString} with coordinates in the reverse order - * @deprecated */ - public Geometry reverse() { - return super.reverse(); + public LineString reverse() { + return (LineString) super.reverse(); } - protected Geometry reverseInternal() + protected LineString reverseInternal() { CoordinateSequence seq = points.copy(); CoordinateSequences.reverse(seq); diff --git a/modules/core/src/main/java/org/locationtech/jts/geom/LinearRing.java b/modules/core/src/main/java/org/locationtech/jts/geom/LinearRing.java index e4b7400fb4..25aa6e6f85 100644 --- a/modules/core/src/main/java/org/locationtech/jts/geom/LinearRing.java +++ b/modules/core/src/main/java/org/locationtech/jts/geom/LinearRing.java @@ -132,13 +132,12 @@ protected LinearRing copyInternal() { return new LinearRing(points.copy(), factory); } - /** @deprecated */ - public Geometry reverse() + protected LinearRing reverse() { - return super.reverse(); + return (LinearRing) super.reverse(); } - public Geometry reverseInternal() { + public LinearRing reverseInternal() { CoordinateSequence seq = points.copy(); CoordinateSequences.reverse(seq); return getFactory().createLinearRing(seq); diff --git a/modules/core/src/main/java/org/locationtech/jts/geom/MultiLineString.java b/modules/core/src/main/java/org/locationtech/jts/geom/MultiLineString.java index 8c40bcef59..08c684614f 100644 --- a/modules/core/src/main/java/org/locationtech/jts/geom/MultiLineString.java +++ b/modules/core/src/main/java/org/locationtech/jts/geom/MultiLineString.java @@ -102,10 +102,9 @@ public Geometry getBoundary() * are reversed. * * @return a {@link MultiLineString} in the reverse order - * @deprecated */ - public Geometry reverse() { - return super.reverse(); + public MultiLineString reverse() { + return (MultiLineString) super.reverse(); } protected MultiLineString copyInternal() { diff --git a/modules/core/src/main/java/org/locationtech/jts/geom/MultiPoint.java b/modules/core/src/main/java/org/locationtech/jts/geom/MultiPoint.java index 08e604cf01..37f0c00f0a 100644 --- a/modules/core/src/main/java/org/locationtech/jts/geom/MultiPoint.java +++ b/modules/core/src/main/java/org/locationtech/jts/geom/MultiPoint.java @@ -76,6 +76,10 @@ public Geometry getBoundary() { return getFactory().createGeometryCollection(); } + public MultiPoint reverse() { + return (MultiPoint) super.reverse(); + } + public boolean isValid() { return true; } diff --git a/modules/core/src/main/java/org/locationtech/jts/geom/MultiPolygon.java b/modules/core/src/main/java/org/locationtech/jts/geom/MultiPolygon.java index fd7ef4dbb6..a4281512e7 100644 --- a/modules/core/src/main/java/org/locationtech/jts/geom/MultiPolygon.java +++ b/modules/core/src/main/java/org/locationtech/jts/geom/MultiPolygon.java @@ -119,10 +119,9 @@ public boolean equalsExact(Geometry other, double tolerance) { * The order of the components in the collection are not reversed. * * @return a MultiPolygon in the reverse order - * @deprecated */ - public Geometry reverse() { - return super.reverse(); + public MultiPolygon reverse() { + return (MultiPolygon) super.reverse(); } protected MultiPolygon copyInternal() { diff --git a/modules/core/src/main/java/org/locationtech/jts/geom/Point.java b/modules/core/src/main/java/org/locationtech/jts/geom/Point.java index 9aa3408e64..6114c9b136 100644 --- a/modules/core/src/main/java/org/locationtech/jts/geom/Point.java +++ b/modules/core/src/main/java/org/locationtech/jts/geom/Point.java @@ -190,12 +190,11 @@ protected Point copyInternal() { return new Point(coordinates.copy(), factory); } - /** @deprecated */ - public Geometry reverse() { - return super.reverse(); + public Point reverse() { + return (Point) super.reverse(); } - protected Geometry reverseInternal() + protected Point reverseInternal() { return getFactory().createPoint(coordinates.copy()); } diff --git a/modules/core/src/main/java/org/locationtech/jts/geom/Polygon.java b/modules/core/src/main/java/org/locationtech/jts/geom/Polygon.java index 131c35efef..e0e1251e59 100644 --- a/modules/core/src/main/java/org/locationtech/jts/geom/Polygon.java +++ b/modules/core/src/main/java/org/locationtech/jts/geom/Polygon.java @@ -417,12 +417,11 @@ private void normalize(LinearRing ring, boolean clockwise) { CoordinateSequences.reverse(seq); } - /** @deprecated */ - public Geometry reverse() { - return super.reverse(); + public Polygon reverse() { + return (Polygon) super.reverse(); } - protected Geometry reverseInternal() + protected Polygon reverseInternal() { LinearRing shell = (LinearRing) getExteriorRing().reverse(); LinearRing[] holes = new LinearRing[getNumInteriorRing()]; From 94f7dcd7cb6073248573faa46295bb9b31309de3 Mon Sep 17 00:00:00 2001 From: Jody Garnett Date: Wed, 26 Aug 2020 16:10:17 -0700 Subject: [PATCH 5/8] resolve visbility mistake with LinearRing reverse() method Signed-off-by: Jody Garnett --- .../src/main/java/org/locationtech/jts/geom/LinearRing.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/src/main/java/org/locationtech/jts/geom/LinearRing.java b/modules/core/src/main/java/org/locationtech/jts/geom/LinearRing.java index 25aa6e6f85..4fea60ac2f 100644 --- a/modules/core/src/main/java/org/locationtech/jts/geom/LinearRing.java +++ b/modules/core/src/main/java/org/locationtech/jts/geom/LinearRing.java @@ -132,7 +132,7 @@ protected LinearRing copyInternal() { return new LinearRing(points.copy(), factory); } - protected LinearRing reverse() + public LinearRing reverse() { return (LinearRing) super.reverse(); } From 641dd5e60a446fa476dffcdfa3e91ac875955304 Mon Sep 17 00:00:00 2001 From: Martin Davis Date: Wed, 26 Aug 2020 18:51:11 -0700 Subject: [PATCH 6/8] Update JTS_Version_History.md --- doc/JTS_Version_History.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/JTS_Version_History.md b/doc/JTS_Version_History.md index c04df377b7..b9eb19d509 100644 --- a/doc/JTS_Version_History.md +++ b/doc/JTS_Version_History.md @@ -35,6 +35,7 @@ Distributions for older JTS versions can be obtained at the * Fix `IndexedPointInAreaLocator` thread-safety (#572) * Fix `WKTReader` to handle MultiPoints containing `EMPTY` (#575) +* Fix compile regression by removing deprecation on geometry `reverse` methods (#582) ## JTS TestBuilder From bcb9100e8c5069a123623ce16b715847127f07f4 Mon Sep 17 00:00:00 2001 From: Martin Davis Date: Thu, 27 Aug 2020 08:07:04 -0700 Subject: [PATCH 7/8] Update JTS_Version_History.md --- doc/JTS_Version_History.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/JTS_Version_History.md b/doc/JTS_Version_History.md index b9eb19d509..bda2f662dc 100644 --- a/doc/JTS_Version_History.md +++ b/doc/JTS_Version_History.md @@ -35,7 +35,7 @@ Distributions for older JTS versions can be obtained at the * Fix `IndexedPointInAreaLocator` thread-safety (#572) * Fix `WKTReader` to handle MultiPoints containing `EMPTY` (#575) -* Fix compile regression by removing deprecation on geometry `reverse` methods (#582) +* Fix API compile regression by removing deprecation on geometry `reverse` methods (#582) ## JTS TestBuilder From dd18e99125490cba9d3fb31b36bfc85a3f4a3347 Mon Sep 17 00:00:00 2001 From: Martin Davis Date: Thu, 27 Aug 2020 09:59:49 -0700 Subject: [PATCH 8/8] Use better increment for TestBuilder rainbow palette. Signed-off-by: Martin Davis --- .../org/locationtech/jtstest/testbuilder/ui/style/Palette.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/ui/style/Palette.java b/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/ui/style/Palette.java index 05e29bf520..a59a737e11 100644 --- a/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/ui/style/Palette.java +++ b/modules/app/src/main/java/org/locationtech/jtstest/testbuilder/ui/style/Palette.java @@ -29,7 +29,7 @@ else if (TYPE_RAINBOW == paletteType) { return HSBPalette.createRainbow(numHues, sat, bright); } else if (TYPE_RAINBOW_RANDOM == paletteType) { - return HSBPalette.createRainbowIncremental(0.396f, sat, bright); + return HSBPalette.createRainbowIncremental(0.23f, sat, bright); } return pal; }