Skip to content

Commit f2618b2

Browse files
committed
Add TestBuilder Selection layer
1 parent 88f1d8d commit f2618b2

File tree

10 files changed

+146
-9
lines changed

10 files changed

+146
-9
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public class AppColors {
4141
public static final Color BACKGROUND_ERROR = Color.PINK;
4242
public static final Color TAB_FOCUS = UIManager.getColor ("TabbedPane.highlight" );
4343

44+
public static final Color GEOM_SELECT_LINE_CLR = new Color(0, 204, 204, 200);
45+
public static final Color GEOM_SELECT_FILL_CLR = new Color(150, 255, 255, 100);
46+
4447

4548

4649
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ public class AppStrings {
9595

9696
public static final String LYR_INDICATORS = "Indicators";
9797

98+
public static final String LYR_LABEL_SELECTION = "Selection";
99+
100+
public static final String TIP_SELECT_ELEMENTS = "Select Elements";
101+
98102

99103

100104

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,16 @@ public void actionPerformed(ActionEvent e)
257257
}
258258
});
259259

260+
JToggleButton selectComponentButton = createToggleButton(
261+
AppStrings.TIP_SELECT_ELEMENTS,
262+
new ImageIcon(this.getClass().getResource("Select.png")),
263+
new java.awt.event.ActionListener() {
264+
public void actionPerformed(ActionEvent e)
265+
{
266+
controller().modeSelectComponent();
267+
}
268+
});
269+
260270
deleteVertexButton = createToggleButton(
261271
AppStrings.TIP_DELETE_VERTEX_COMPONENT,
262272
new ImageIcon(this.getClass().getResource("DeleteVertex.png")),
@@ -276,6 +286,7 @@ public void actionPerformed(ActionEvent e) {
276286
,btnMove
277287
,deleteVertexButton
278288
,infoButton
289+
,selectComponentButton
279290
,extractComponentButton
280291
);
281292

@@ -290,6 +301,7 @@ public void actionPerformed(ActionEvent e) {
290301
strut(20),
291302
zoomButton,
292303
infoButton,
304+
selectComponentButton,
293305
extractComponentButton,
294306

295307
strut(20),

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,14 @@ public void setLayerFocus(LayerItemPanel layerItem) {
210210
}
211211
layerItem.setFocusLayer(true);
212212
Layer layer = layerItem.getLayer();
213-
boolean isModifiable = ! JTSTestBuilder.model().isLayerFixed(layer);
214213
showTabLayerStyle(layer.getName());
215-
lyrStylePanel.setLayer(layer, isModifiable);
214+
lyrStylePanel.setLayer(layer, layer.isModifiable());
216215
focusLayer = layer;
217216
updateButtons(focusLayer);
218217
}
219218

220219
private void updateButtons(Layer lyr) {
221-
boolean isModifiable = ! JTSTestBuilder.model().isLayerFixed(lyr);
220+
boolean isModifiable = lyr.isModifiable();
222221

223222
// every layer is copyable
224223
btnCopy.setEnabled(true);
@@ -338,6 +337,7 @@ public boolean isFocusLayer() {
338337
public void update() {
339338
LayerStyleSwatchControl.update(swatch, layer);
340339
lblName.setText( layer.getName());
340+
lblName.setForeground(layer.hasGeometry() ? Color.BLACK : Color.GRAY);
341341
}
342342

343343
private void uiInit() throws Exception {
@@ -392,6 +392,8 @@ public void mouseClicked(MouseEvent e)
392392
namePanel.addMouseListener(new HighlightMouseListener(this));
393393

394394
namePanel.add(lblName);
395+
396+
update();
395397
}
396398

397399
private void layerVisAction() {

modules/app/src/main/java/org/locationtech/jtstest/testbuilder/controller/JTSTestBuilderController.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.locationtech.jtstest.testbuilder.ui.tools.PanTool;
4545
import org.locationtech.jtstest.testbuilder.ui.tools.PointTool;
4646
import org.locationtech.jtstest.testbuilder.ui.tools.RectangleTool;
47+
import org.locationtech.jtstest.testbuilder.ui.tools.SelectComponentTool;
4748
import org.locationtech.jtstest.testbuilder.ui.tools.StreamPolygonTool;
4849
import org.locationtech.jtstest.testbuilder.ui.tools.Tool;
4950
import org.locationtech.jtstest.testbuilder.ui.tools.ZoomTool;
@@ -147,6 +148,7 @@ public void extractComponentsToTestCase(Geometry aoi, boolean isSegments)
147148
if (comp == null)
148149
return;
149150
model().addCase(comp);
151+
model().setSelection(comp[0]);
150152
JTSTestBuilderFrame.instance().updateTestCases();
151153
toolbar().selectZoomButton();
152154
modeZoomIn();
@@ -162,6 +164,27 @@ public void copyComponentToClipboard(Coordinate pt)
162164
SwingUtil.copyToClipboard(comp, false);
163165
}
164166

167+
public void selectComponents(Geometry aoi)
168+
{
169+
LayerList lyrList = model().getLayers();
170+
Geometry[] comp;
171+
comp = lyrList.getComponents(aoi);
172+
if (comp == null) {
173+
model().clearSelection();
174+
}
175+
else {
176+
//TODO: allow selecting from A or B when enabled
177+
if (comp[0] != null) {
178+
model().setSelection(comp[0]);
179+
}
180+
else {
181+
model().setSelection(comp[1]);
182+
}
183+
}
184+
geometryViewChanged();
185+
}
186+
187+
165188
public void setFocusGeometry(int index) {
166189
model().getGeometryEditModel().setEditGeomIndex(index);
167190
toolbar().setFocusGeometry(index);
@@ -274,6 +297,10 @@ public void modeExtractComponent() {
274297
setTool(ExtractComponentTool.getInstance());
275298
}
276299

300+
public void modeSelectComponent() {
301+
setTool(SelectComponentTool.getInstance());
302+
}
303+
277304
public void modeDeleteVertex() {
278305
setTool(DeleteByBoxTool.getInstance());
279306
}

modules/app/src/main/java/org/locationtech/jtstest/testbuilder/model/Layer.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class Layer
2323
private String name = "";
2424
private GeometryContainer geomCont;
2525
private boolean isEnabled = true;
26+
private boolean isModifiable = true;
2627

2728
private LayerStyle layerStyle;
2829
private BasicStyle initStyle = null;
@@ -31,6 +32,11 @@ public Layer(String name) {
3132
this.name = name;
3233
}
3334

35+
public Layer(String name, boolean isModifiable) {
36+
this.name = name;
37+
this.isModifiable = isModifiable;
38+
}
39+
3440
public Layer(String name, GeometryContainer source, BasicStyle style) {
3541
this.name = name;
3642
setSource(source);
@@ -50,6 +56,10 @@ public void setName(String name) {
5056
this.name = name;
5157
}
5258

59+
public boolean isModifiable() {
60+
return isModifiable;
61+
}
62+
5363
public String getNameInfo() {
5464
if (geomCont.getGeometry() == null) return getName();
5565
return getName()

modules/app/src/main/java/org/locationtech/jtstest/testbuilder/model/LayerList.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public static LayerList create(LayerList l1, LayerList l2, LayerList l3) {
4444
public static final int LYR_A = 0;
4545
public static final int LYR_B = 1;
4646
public static final int LYR_RESULT = 2;
47+
public static final int LYR_SELECT = 3;
4748

4849
private List<Layer> layers = new ArrayList<Layer>();
4950

@@ -52,9 +53,10 @@ public LayerList()
5253
}
5354

5455
void initFixed() {
55-
layers.add(new Layer(AppStrings.GEOM_LABEL_A));
56-
layers.add(new Layer(AppStrings.GEOM_LABEL_B));
57-
layers.add(new Layer(AppStrings.GEOM_LABEL_RESULT));
56+
layers.add(new Layer(AppStrings.GEOM_LABEL_A, false));
57+
layers.add(new Layer(AppStrings.GEOM_LABEL_B, false));
58+
layers.add(new Layer(AppStrings.GEOM_LABEL_RESULT, false));
59+
layers.add(new Layer(AppStrings.LYR_LABEL_SELECTION, false));
5860
}
5961

6062
public int size() { return layers.size(); }
@@ -87,6 +89,11 @@ public Geometry getComponent(Coordinate pt, double tolerance)
8789
return null;
8890
}
8991

92+
public Geometry[] getComponents(Geometry aoi)
93+
{
94+
return getComponents(aoi, false);
95+
}
96+
9097
public Geometry[] getComponents(Geometry aoi, boolean isSegments)
9198
{
9299
Geometry comp[] = new Geometry[2];

modules/app/src/main/java/org/locationtech/jtstest/testbuilder/model/TestBuilderModel.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ private void initLayers()
159159

160160
layerList.getLayer(LayerList.LYR_A).setSource(geomCont0);
161161
layerList.getLayer(LayerList.LYR_B).setSource(geomCont1);
162+
//layerList.getLayer(LayerList.LYR_SELECT).setSource(new ListGeometryContainer());
162163

163164
if (geomEditModel != null)
164165
layerList.getLayer(LayerList.LYR_RESULT).setSource(
@@ -175,6 +176,10 @@ private void initLayers()
175176
Layer lyrR = layerList.getLayer(LayerList.LYR_RESULT);
176177
lyrR.setGeometryStyle(new BasicStyle(AppColors.GEOM_RESULT_LINE_CLR,
177178
AppColors.GEOM_RESULT_FILL_CLR));
179+
180+
Layer lyrSel = layerList.getLayer(LayerList.LYR_SELECT);
181+
lyrSel.setGeometryStyle(new BasicStyle(AppColors.GEOM_SELECT_LINE_CLR,
182+
AppColors.GEOM_SELECT_FILL_CLR));
178183
}
179184

180185
public void pasteGeometry(int geomIndex) throws Exception {
@@ -600,11 +605,22 @@ else if (layerListTop.contains(lyr)) {
600605
}
601606
layerListTop.moveDown(lyr);
602607
}
603-
604608
}
605609

606-
public boolean isLayerFixed(Layer lyr) {
607-
return layerList.contains(lyr);
610+
public void setSelection(Geometry geometry) {
611+
Layer lyr = layerList.getLayer(LayerList.LYR_SELECT);
612+
lyr.setGeometry(geometry);
613+
}
614+
615+
public void addSelection(Geometry geometry) {
616+
Layer lyr = layerList.getLayer(LayerList.LYR_SELECT);
617+
ListGeometryContainer src = (ListGeometryContainer) lyr.getSource();
618+
src.add(geometry);
619+
}
620+
621+
public void clearSelection() {
622+
Layer lyr = layerList.getLayer(LayerList.LYR_SELECT);
623+
lyr.getSource().clear();
608624
}
609625

610626

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (c) 2016 Vivid Solutions.
3+
*
4+
* All rights reserved. This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* and Eclipse Distribution License v. 1.0 which accompanies this distribution.
7+
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v20.html
8+
* and the Eclipse Distribution License is available at
9+
*
10+
* http://www.eclipse.org/org/documents/edl-v10.php.
11+
*/
12+
package org.locationtech.jtstest.testbuilder.ui.tools;
13+
14+
import java.awt.Cursor;
15+
import java.awt.event.MouseEvent;
16+
17+
import org.locationtech.jts.geom.Coordinate;
18+
import org.locationtech.jts.geom.Envelope;
19+
import org.locationtech.jts.geom.Geometry;
20+
import org.locationtech.jtstest.testbuilder.JTSTestBuilder;
21+
22+
/**
23+
* Selects components of a geometry
24+
* @version 1.7
25+
*/
26+
public class SelectComponentTool extends BoxBandTool {
27+
private static SelectComponentTool singleton = null;
28+
29+
public static SelectComponentTool getInstance() {
30+
if (singleton == null)
31+
singleton = new SelectComponentTool();
32+
return singleton;
33+
}
34+
35+
private SelectComponentTool() {
36+
super(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
37+
}
38+
39+
protected void gestureFinished()
40+
{
41+
JTSTestBuilder.controller().selectComponents(getBox());
42+
}
43+
44+
public void mouseClicked(MouseEvent e) {
45+
Geometry box = getBox(e);
46+
JTSTestBuilder.controller().selectComponents(box);
47+
}
48+
49+
private Geometry getBox(MouseEvent e) {
50+
Coordinate pt = toModelSnapped(e.getPoint());
51+
Envelope env = new Envelope(pt);
52+
Geometry box = JTSTestBuilder.getGeometryFactory().toGeometry(env);
53+
return box;
54+
}
55+
56+
}
1.36 KB
Loading

0 commit comments

Comments
 (0)