Revision: 5823 http://sourceforge.net/p/jump-pilot/code/5823 Author: michaudm Date: 2018-06-02 18:56:35 +0000 (Sat, 02 Jun 2018) Log Message: ----------- Clean code : remove deprecated methods, use foreach loops, generics...
Modified Paths: -------------- core/trunk/src/de/latlon/deejump/plugin/manager/ExtensionManagerPlugIn.java core/trunk/src/org/openjump/core/ui/plugin/layer/ChangeLayerableNamePlugIn.java core/trunk/src/org/openjump/core/ui/plugin/layer/ExtractLayerInFence.java core/trunk/src/org/openjump/core/ui/plugin/mousemenu/NodeFeaturesPlugIn.java core/trunk/src/org/openjump/core/ui/plugin/mousemenu/SplitFeaturesPlugIn.java core/trunk/src/org/openjump/core/ui/plugin/tools/Dissolve2PlugIn.java core/trunk/src/org/openjump/core/ui/plugin/tools/JoinWithArcPlugIn.java Modified: core/trunk/src/de/latlon/deejump/plugin/manager/ExtensionManagerPlugIn.java =================================================================== --- core/trunk/src/de/latlon/deejump/plugin/manager/ExtensionManagerPlugIn.java 2018-06-02 18:54:52 UTC (rev 5822) +++ core/trunk/src/de/latlon/deejump/plugin/manager/ExtensionManagerPlugIn.java 2018-06-02 18:56:35 UTC (rev 5823) @@ -37,11 +37,10 @@ } public void initialize(PlugInContext context) throws Exception { - context.getFeatureInstaller().addMainMenuItem( + context.getFeatureInstaller().addMainMenuPlugin( // [Michael Michaud 2007-03-23] Change MenuNames.TOOLS to MenuNames.CUSTOMIZE - this, MenuNames.CUSTOMIZE, - this.getName(), null, - null); + this, new String[]{MenuNames.CUSTOMIZE}, + this.getName(), false, null, null); } } Modified: core/trunk/src/org/openjump/core/ui/plugin/layer/ChangeLayerableNamePlugIn.java =================================================================== --- core/trunk/src/org/openjump/core/ui/plugin/layer/ChangeLayerableNamePlugIn.java 2018-06-02 18:54:52 UTC (rev 5822) +++ core/trunk/src/org/openjump/core/ui/plugin/layer/ChangeLayerableNamePlugIn.java 2018-06-02 18:56:35 UTC (rev 5823) @@ -25,8 +25,6 @@ */ public class ChangeLayerableNamePlugIn extends AbstractPlugIn { - //private EnableCheck enableCheck; - @Override public void initialize(PlugInContext context) throws Exception { WorkbenchContext workbenchContext = context.getWorkbenchContext(); @@ -34,19 +32,19 @@ // Install in main menu FeatureInstaller installer = new FeatureInstaller(workbenchContext); - installer.addMainMenuItem(this, + installer.addMainMenuPlugin(this, new String[] { MenuNames.LAYER }, getName() + "...", false, null, enableCheck); // Install in layerName popup menu JPopupMenu popupMenu = workbenchContext.getWorkbench().getFrame() .getLayerNamePopupMenu(); - installer.addPopupMenuItem(popupMenu, this, getName() + "{pos:5}", + installer.addPopupMenuPlugin(popupMenu, this, getName() + "{pos:5}", false, null, enableCheck); // INstall in WMSLayerName popup menu popupMenu = workbenchContext.getWorkbench().getFrame() .getWMSLayerNamePopupMenu(); - installer.addPopupMenuItem(popupMenu, this, getName() + "{pos:6}", + installer.addPopupMenuPlugin(popupMenu, this, getName() + "{pos:6}", false, null, enableCheck); } @@ -80,11 +78,7 @@ } return true; } - - /** - * @param workbenchContext - * @return an enable check - */ + public EnableCheck createEnableCheck(WorkbenchContext workbenchContext) { //if (enableCheck != null) return enableCheck; EnableCheckFactory enableCheckFactory = new EnableCheckFactory(workbenchContext); Modified: core/trunk/src/org/openjump/core/ui/plugin/layer/ExtractLayerInFence.java =================================================================== --- core/trunk/src/org/openjump/core/ui/plugin/layer/ExtractLayerInFence.java 2018-06-02 18:54:52 UTC (rev 5822) +++ core/trunk/src/org/openjump/core/ui/plugin/layer/ExtractLayerInFence.java 2018-06-02 18:56:35 UTC (rev 5823) @@ -53,7 +53,6 @@ import com.vividsolutions.jump.workbench.plugin.PlugInContext; import com.vividsolutions.jump.workbench.ui.MenuNames; import com.vividsolutions.jump.workbench.ui.images.IconLoader; -import com.vividsolutions.jump.workbench.ui.plugin.FeatureInstaller; public class ExtractLayerInFence extends AbstractPlugIn { @@ -65,10 +64,6 @@ } public void initialize(PlugInContext context) throws Exception { - WorkbenchContext workbenchContext = context.getWorkbenchContext(); - FeatureInstaller featureInstaller = new FeatureInstaller( - workbenchContext); - context.getFeatureInstaller().addMainMenuPlugin(this, new String[] {MenuNames.EDIT, MenuNames.EXTRACT}, Modified: core/trunk/src/org/openjump/core/ui/plugin/mousemenu/NodeFeaturesPlugIn.java =================================================================== --- core/trunk/src/org/openjump/core/ui/plugin/mousemenu/NodeFeaturesPlugIn.java 2018-06-02 18:54:52 UTC (rev 5822) +++ core/trunk/src/org/openjump/core/ui/plugin/mousemenu/NodeFeaturesPlugIn.java 2018-06-02 18:56:35 UTC (rev 5823) @@ -59,7 +59,7 @@ public static final ImageIcon ICON = IconLoader.icon("node_features.png"); - NoderPlugIn noder = new NoderPlugIn(); + private NoderPlugIn noder = new NoderPlugIn(); public NodeFeaturesPlugIn() { } @@ -66,7 +66,7 @@ public void initialize(PlugInContext context) throws Exception { FeatureInstaller featureInstaller = new FeatureInstaller(context.getWorkbenchContext()); JPopupMenu popupMenu = context.getLayerViewPanel().popupMenu(); - featureInstaller.addPopupMenuItem(popupMenu, + featureInstaller.addPopupMenuPlugin(popupMenu, this, new String[]{noder.getName()}, getName(), @@ -89,9 +89,7 @@ monitor.allowCancellationRequests(); monitor.report(I18N.get("jump.plugin.edit.NoderPlugIn.noding-input")); - - final Layer layer = context.getLayerNamePanel().chooseEditableLayer(); - + noder.setUseSelected(true); noder.setFindIntersections(false); noder.setLineProcessor(NoderPlugIn.Processor.NODE); @@ -100,8 +98,6 @@ noder.setInterpolatedZDp(3); noder.run(monitor, context); - - if (monitor.isCancelRequested()) return; } } Modified: core/trunk/src/org/openjump/core/ui/plugin/mousemenu/SplitFeaturesPlugIn.java =================================================================== --- core/trunk/src/org/openjump/core/ui/plugin/mousemenu/SplitFeaturesPlugIn.java 2018-06-02 18:54:52 UTC (rev 5822) +++ core/trunk/src/org/openjump/core/ui/plugin/mousemenu/SplitFeaturesPlugIn.java 2018-06-02 18:56:35 UTC (rev 5823) @@ -37,11 +37,8 @@ import com.vividsolutions.jump.workbench.*; import com.vividsolutions.jump.workbench.model.Layer; import com.vividsolutions.jump.workbench.plugin.*; -import com.vividsolutions.jump.workbench.ui.*; import com.vividsolutions.jump.workbench.ui.plugin.*; -import java.util.Properties; import javax.swing.ImageIcon; -import javax.swing.JMenuItem; import javax.swing.JPopupMenu; import org.openjump.core.ui.images.IconLoader; import org.openjump.core.ui.plugin.AbstractThreadedUiPlugIn; @@ -60,7 +57,7 @@ public static final ImageIcon ICON = IconLoader.icon("split_features.png"); - NoderPlugIn noder = new NoderPlugIn(); + private NoderPlugIn noder = new NoderPlugIn(); public SplitFeaturesPlugIn() { } @@ -67,7 +64,7 @@ public void initialize(PlugInContext context) throws Exception { FeatureInstaller featureInstaller = new FeatureInstaller(context.getWorkbenchContext()); JPopupMenu popupMenu = context.getLayerViewPanel().popupMenu(); - featureInstaller.addPopupMenuItem(popupMenu, + featureInstaller.addPopupMenuPlugin(popupMenu, this, new String[]{noder.getName()}, getName(), @@ -90,9 +87,7 @@ monitor.allowCancellationRequests(); monitor.report(I18N.get("jump.plugin.edit.NoderPlugIn.noding-input")); - - final Layer layer = context.getLayerNamePanel().chooseEditableLayer(); - + noder.setUseSelected(true); noder.setFindIntersections(false); noder.setLineProcessor(NoderPlugIn.Processor.SPLIT); @@ -101,8 +96,6 @@ noder.setInterpolatedZDp(3); noder.run(monitor, context); - - if (monitor.isCancelRequested()) return; } } Modified: core/trunk/src/org/openjump/core/ui/plugin/tools/Dissolve2PlugIn.java =================================================================== --- core/trunk/src/org/openjump/core/ui/plugin/tools/Dissolve2PlugIn.java 2018-06-02 18:54:52 UTC (rev 5822) +++ core/trunk/src/org/openjump/core/ui/plugin/tools/Dissolve2PlugIn.java 2018-06-02 18:56:35 UTC (rev 5823) @@ -107,7 +107,6 @@ final KeyOptionPanel keyOptionPanel, final AggregateOptionPanel aggregateOptionPanel) throws Exception { - //dialog.setSideBarImage(IconLoader.icon("dissolve_layer_icon.gif")); dialog.setSideBarDescription(DESCRIPTION); dialog.addSeparator(); @@ -144,13 +143,15 @@ public void itemStateChanged(ItemEvent itemEvent) { if (itemEvent.getStateChange() == ItemEvent.SELECTED) { layer = (Layer)layerComboBox.getSelectedItem(); - FeatureSchema schema = layer.getFeatureCollectionWrapper().getFeatureSchema(); - try { - keyOptionPanel.setSchema(schema); - aggregateOptionPanel.setSchema(schema); - updateControls(dialog, keyOptionPanel, aggregateOptionPanel); - } catch(Exception ex) { - throw new RuntimeException(ex); + if (layer != null) { + FeatureSchema schema = layer.getFeatureCollectionWrapper().getFeatureSchema(); + try { + keyOptionPanel.setSchema(schema); + aggregateOptionPanel.setSchema(schema); + updateControls(dialog, keyOptionPanel, aggregateOptionPanel); + } catch (Exception ex) { + throw new RuntimeException(ex); + } } } } @@ -165,7 +166,7 @@ layer = dialog.getLayer(SOURCE_LAYER); FeatureSchema schema = layer.getFeatureCollectionWrapper().getFeatureSchema(); List<String> keyAttributes = new ArrayList<>(keyOptionPanel.getKeyAttributes()); - List<AttributeAggregator> aggregators = new ArrayList<AttributeAggregator>(); + List<AttributeAggregator> aggregators = new ArrayList<>(); aggregators.add(new AttributeAggregator( schema.getAttributeName(schema.getGeometryIndex()), (Aggregator)dialog.getComboBox(GEOMETRY_AGGREGATOR).getSelectedItem(), @@ -283,7 +284,7 @@ class KeyAttributePanel extends JPanel { final KeyOptionPanel keyOptionPanel; final FeatureSchema schema; - final JComboBox jcbInputAttributeName; + final JComboBox<String> jcbInputAttributeName; final JButton jbRemove; KeyAttributePanel(final KeyOptionPanel keyOptionPanel, @@ -292,7 +293,7 @@ setLayout(new FlowLayout()); this.keyOptionPanel = keyOptionPanel; this.schema = schema; - jcbInputAttributeName = new JComboBox(); + jcbInputAttributeName = new JComboBox<>(); for (int i = 0 ; i < schema.getAttributeCount() ; i++) { jcbInputAttributeName.addItem(schema.getAttributeName(i)); } @@ -309,9 +310,10 @@ if (keyOptionPanel.getKeyAttributes().size() > 1) { keyOptionPanel.getKeyAttributesPanel().remove(KeyAttributePanel.this); SwingUtilities.getWindowAncestor(keyOptionPanel).pack(); - } else { - //TODO throw message } + //else { + //TODO throw message ? + //} } }); @@ -320,7 +322,12 @@ } public String getAttribute() { - return jcbInputAttributeName.getSelectedItem().toString(); + Object selection = jcbInputAttributeName.getSelectedItem(); + if (selection != null) { + return selection.toString(); + } else { + return null; + } } private String pickKeyAttribute(FeatureSchema schema, Set<String> set) throws Exception { @@ -406,15 +413,19 @@ for (Component component : components) { if (component instanceof AttributeAggregatePanel) { AttributeAggregatePanel aap = (AttributeAggregatePanel) component; - String inputName = aap.jcbInputAttributeName.getSelectedItem().toString(); - String outputName = aap.jtfOutputAttributeName.getText(); - Aggregator agg = ((Aggregator) aap.jcbAggregators.getSelectedItem()).clone(); - agg.setIgnoreNull(aap.jcbIgnoreNull.isSelected()); - if (aap.jtfParameter.isEnabled() && agg.getParameters().size() > 0) { - agg.setParameter(agg.getParameters().iterator().next().toString(), aap.jtfParameter.getText()); + Object selectedAttributeName = aap.jcbInputAttributeName.getSelectedItem(); + Object selectedAggregator = aap.jcbAggregators.getSelectedItem(); + if (selectedAttributeName != null && selectedAggregator != null) { + String inputName = selectedAttributeName.toString(); + String outputName = aap.jtfOutputAttributeName.getText(); + Aggregator agg = ((Aggregator)selectedAggregator).clone(); + agg.setIgnoreNull(aap.jcbIgnoreNull.isSelected()); + if (aap.jtfParameter.isEnabled() && agg.getParameters().size() > 0) { + agg.setParameter(agg.getParameters().iterator().next().toString(), aap.jtfParameter.getText()); + } + AttributeAggregator aggregator = new AttributeAggregator(inputName, agg, outputName); + aggregators.add(aggregator); } - AttributeAggregator aggregator = new AttributeAggregator(inputName, agg, outputName); - aggregators.add(aggregator); } } } @@ -428,8 +439,8 @@ final FeatureSchema schema; JTextField jtfOutputAttributeName; - JComboBox jcbInputAttributeName; - JComboBox jcbAggregators; + JComboBox<String> jcbInputAttributeName; + JComboBox<Aggregator> jcbAggregators; JCheckBox jcbIgnoreNull; JTextField jtfParameter; JButton jbRemove; @@ -443,24 +454,29 @@ jtfOutputAttributeName = new JTextField(); jtfOutputAttributeName.setPreferredSize(LARGE); - jcbInputAttributeName = new JComboBox(); + jcbInputAttributeName = new JComboBox<>(); for (int i = 0 ; i < schema.getAttributeCount() ; i++) { if (i == schema.getGeometryIndex()) continue; jcbInputAttributeName.addItem(schema.getAttributeName(i)); } - String defaultAttribute = jcbInputAttributeName.getSelectedItem().toString(); + String defaultAttribute = null; + if (jcbInputAttributeName.getSelectedItem() != null) { + defaultAttribute = jcbInputAttributeName.getSelectedItem().toString(); + } jtfOutputAttributeName.setText(defaultAttribute); jcbInputAttributeName.setPreferredSize(LARGE); - jcbAggregators = new JComboBox(Aggregators.getAggregators(schema.getAttributeType(defaultAttribute)).values().toArray()); + jcbAggregators = new JComboBox<>( + Aggregators.getAggregators(schema.getAttributeType(defaultAttribute)) + .values().toArray(new Aggregator[0])); jcbAggregators.setPreferredSize(LARGE); Aggregator aggregator = (Aggregator)jcbAggregators.getSelectedItem(); jcbIgnoreNull = new JCheckBox(); jcbIgnoreNull.setPreferredSize(MEDIUM); - jcbIgnoreNull.setSelected(aggregator.ignoreNull()); + jcbIgnoreNull.setSelected(aggregator == null || aggregator.ignoreNull()); jtfParameter = new JTextField(","); - jtfParameter.setEditable(aggregator.getParameters().size() > 0); + jtfParameter.setEditable(aggregator != null && aggregator.getParameters().size() > 0); jtfParameter.setPreferredSize(NARROW); jbRemove = new JButton(); jbRemove.setIcon(IconLoader.icon("remove.gif")); @@ -471,10 +487,13 @@ @Override public void actionPerformed(ActionEvent e) { AttributeType type = schema.getAttributeType(jcbInputAttributeName.getSelectedItem().toString()); - jcbAggregators.setModel(new DefaultComboBoxModel(Aggregators.getAggregators(type).values().toArray())); + jcbAggregators.setModel(new DefaultComboBoxModel<>( + Aggregators.getAggregators(type).values().toArray(new Aggregator[0]))); Aggregator agg = (Aggregator)jcbAggregators.getSelectedItem(); - jcbIgnoreNull.setSelected(agg.ignoreNull()); - jtfParameter.setEditable(agg.getParameters().size() > 0); + if (agg != null) { + jcbIgnoreNull.setSelected(agg.ignoreNull()); + jtfParameter.setEditable(agg.getParameters().size() > 0); + } jtfOutputAttributeName.setText(jcbInputAttributeName.getSelectedItem().toString()); } }); @@ -483,8 +502,10 @@ @Override public void actionPerformed(ActionEvent e) { Aggregator agg = (Aggregator)jcbAggregators.getSelectedItem(); - jcbIgnoreNull.setSelected(agg.ignoreNull()); - jtfParameter.setEditable(agg.getParameters().size() > 0); + if (agg != null) { + jcbIgnoreNull.setSelected(agg.ignoreNull()); + jtfParameter.setEditable(agg.getParameters().size() > 0); + } } }); @@ -502,8 +523,8 @@ add(jcbIgnoreNull); add(jtfParameter); add(jbRemove); + } - } } Modified: core/trunk/src/org/openjump/core/ui/plugin/tools/JoinWithArcPlugIn.java =================================================================== --- core/trunk/src/org/openjump/core/ui/plugin/tools/JoinWithArcPlugIn.java 2018-06-02 18:54:52 UTC (rev 5822) +++ core/trunk/src/org/openjump/core/ui/plugin/tools/JoinWithArcPlugIn.java 2018-06-02 18:56:35 UTC (rev 5823) @@ -63,6 +63,7 @@ import com.vividsolutions.jump.workbench.ui.MultiInputDialog; public class JoinWithArcPlugIn extends AbstractPlugIn { + private WorkbenchContext workbenchContext; private final static String sJoinWithArc = I18N.get("org.openjump.core.ui.plugin.tools.JoinWithArcPlugIn.Join-With-Arc"); @@ -73,13 +74,16 @@ private final static String sFeaturesMustBeSelected= I18N.get("org.openjump.core.ui.plugin.tools.JoinWithArcPlugIn.features-must-be-selected"); private final static String RADIUS = I18N.get("org.openjump.core.ui.plugin.tools.JoinWithArcPlugIn.Radius"); - private MultiInputDialog dialog; private double arcRadius = 50.0; public void initialize(PlugInContext context) throws Exception { workbenchContext = context.getWorkbenchContext(); - context.getFeatureInstaller().addMainMenuItem(this, new String[] { MenuNames.TOOLS, MenuNames.TOOLS_EDIT_GEOMETRY }, getName(), false, null, this.createEnableCheck(workbenchContext)); + context.getFeatureInstaller().addMainMenuPlugin( + this, + new String[] { MenuNames.TOOLS, MenuNames.TOOLS_EDIT_GEOMETRY }, + getName(), + false, null, this.createEnableCheck(workbenchContext)); } public String getName() { @@ -134,10 +138,9 @@ } } - if (fillet != null) - { + if (fillet != null) { Feature currFeature = (Feature) selectedFeatures.iterator().next(); - Feature newFeature = (Feature) currFeature.clone(); + Feature newFeature = currFeature.clone(true); newFeature.setGeometry(fillet); Collection selectedCategories = context.getLayerNamePanel().getSelectedCategories(); LayerManager layerManager = context.getLayerManager(); @@ -193,31 +196,28 @@ double n = W.y * (P3.x - P1.x) - W.x * (P3.y - P1.y); double d = W.y * V.x - W.x * V.y; - if (d != 0.0) - { + if (d != 0.0) { double t1 = n / d; - Coordinate E = new Coordinate((P1.x + V.x * t1),(P1.y + V.y * t1)); - return E; + return new Coordinate((P1.x + V.x * t1),(P1.y + V.y * t1)); } - else - { + else { return null; } } - private LineString MakeRoundCorner(Coordinate A, Coordinate B, Coordinate C, Coordinate D, double r, boolean arcOnly) - { - MathVector Gv = new MathVector(); + private LineString MakeRoundCorner(Coordinate A, Coordinate B, Coordinate C, Coordinate D, + double r, boolean arcOnly) { + MathVector Gv; MathVector Hv; MathVector Fv; Coordinate E = Intersect(A, B, C, D); //vector solution - if (E != null) //non-parallel lines - { + if (E != null) { //non-parallel lines + MathVector Ev = new MathVector(E); - if (E.distance(B) > E.distance(A)) //find longest distance from intersection - { //these equations assume B and D are closest to the intersection + if (E.distance(B) > E.distance(A)) { //find longest distance from intersection + //these equations assume B and D are closest to the intersection //reverse points Coordinate temp = A; A = B; @@ -224,8 +224,8 @@ B = temp; } - if (E.distance(D) > E.distance(C)) //find longest distance from intersection - { //these equations assume B and D are closest to the intersection + if (E.distance(D) > E.distance(C)) {//find longest distance from intersection + //these equations assume B and D are closest to the intersection //reverse points Coordinate temp = C; C = D; @@ -237,8 +237,7 @@ double alpha = Av.vectorBetween(Ev).angleRad(Cv.vectorBetween(Ev)) / 2.0; //we only need the half angle double h1 = Math.abs(r / Math.sin(alpha)); //from definition of sine solved for h - if ((h1 * h1 - r * r) >= 0) - { + if ((h1 * h1 - r * r) >= 0) { double d1 = Math.sqrt(h1 * h1 - r * r); //pythagorean theorem} double theta = Math.PI / 2.0 - alpha; //sum of triangle interior angles = 180 degrees theta = theta * 2.0; //we only need the double angle} @@ -248,8 +247,7 @@ Hv = Ev.add(Cv.vectorBetween(Ev).unit().scale(d1)); Fv = Ev.add(Gv.vectorBetween(Ev).rotateRad(alpha).unit().scale(h1)); - if (Math.abs(Fv.distance(Hv) - Fv.distance(Gv)) > 1.0) //rotated the wrong dirction - { + if (Math.abs(Fv.distance(Hv) - Fv.distance(Gv)) > 1.0) {//rotated the wrong dirction Fv = Ev.add(Gv.vectorBetween(Ev).rotateRad(-alpha).unit().scale(h1)); theta = -theta; } @@ -263,19 +261,17 @@ return new GeometryFactory().createLineString(coordinates.toCoordinateArray()); } } - return null; + return null; } - private LineString filletTwoLineStrings(LineString ls1, LineString ls2) - { + private LineString filletTwoLineStrings(LineString ls1, LineString ls2) { Coordinate A = ls1.getCoordinateN(0); Coordinate B = ls1.getCoordinateN(1); Coordinate C = ls2.getCoordinateN(0); Coordinate D = ls2.getCoordinateN(1); LineString lineString = MakeRoundCorner(A, B, C, D, arcRadius, false); - if (lineString != null) - { + if (lineString != null) { CoordinateList coordinates = new CoordinateList(); coordinates.add(lineString.getCoordinates(), false); return new GeometryFactory().createLineString(coordinates.toCoordinateArray()); @@ -290,15 +286,13 @@ CoordinateList filletCoordinates = new CoordinateList(); filletCoordinates.add(ls.getCoordinateN(0)); - for (int i = 0; i <= ls.getNumPoints() - 3; i++) - { + for (int i = 0; i <= ls.getNumPoints() - 3; i++) { Coordinate A = ls.getCoordinateN(i); Coordinate B = ls.getCoordinateN(i+1); Coordinate C = ls.getCoordinateN(i+1); //copy B Coordinate D = ls.getCoordinateN(i+2); LineString lineString = MakeRoundCorner(A, B, C, D, arcRadius, true); - if (!lineString.isEmpty()) - { + if (lineString != null && !lineString.isEmpty()) { filletCoordinates.add(lineString.getCoordinates(), false, false); } } @@ -315,14 +309,15 @@ CoordinateList filletCoordinates = new CoordinateList(); - for (int i = 0; i <= ls.getNumPoints() - 3; i++) - { + for (int i = 0; i <= ls.getNumPoints() - 3; i++) { Coordinate A = ls.getCoordinateN(i); Coordinate B = ls.getCoordinateN(i+1); Coordinate C = ls.getCoordinateN(i+1); //copy B Coordinate D = ls.getCoordinateN(i+2); LineString lineString = MakeRoundCorner(A, B, C, D, arcRadius, true); - filletCoordinates.add(lineString.getCoordinates(), false, false); + if (lineString != null) { + filletCoordinates.add(lineString.getCoordinates(), false, false); + } } Coordinate A = ls.getCoordinateN(ls.getNumPoints() - 2); //second to last @@ -330,8 +325,10 @@ Coordinate C = ls.getCoordinateN(0); Coordinate D = ls.getCoordinateN(1); LineString lineString = MakeRoundCorner(A, B, C, D, arcRadius, true); - filletCoordinates.add(lineString.getCoordinates(), false, false); - filletCoordinates.add(filletCoordinates.getCoordinate(0)); + if (lineString != null) { + filletCoordinates.add(lineString.getCoordinates(), false, false); + filletCoordinates.add(filletCoordinates.getCoordinate(0)); + } return new GeometryFactory().createPolygon( new GeometryFactory().createLinearRing(filletCoordinates.toCoordinateArray()),null); } @@ -346,7 +343,9 @@ Coordinate C = ring.getCoordinateN(i+1); //copy B Coordinate D = ring.getCoordinateN(i+2); LineString lineString = MakeRoundCorner(A, B, C, D, arcRadius, true); - filletCoordinates.add(lineString.getCoordinates(), false, false); + if (lineString != null) { + filletCoordinates.add(lineString.getCoordinates(), false, false); + } } Coordinate A = ring.getCoordinateN(ring.getNumPoints() - 2); //second to last @@ -354,8 +353,10 @@ Coordinate C = ring.getCoordinateN(0); Coordinate D = ring.getCoordinateN(1); LineString lineString = MakeRoundCorner(A, B, C, D, arcRadius, true); - filletCoordinates.add(lineString.getCoordinates(), false, false); - filletCoordinates.add(filletCoordinates.getCoordinate(0)); + if (lineString != null) { + filletCoordinates.add(lineString.getCoordinates(), false, false); + filletCoordinates.add(filletCoordinates.getCoordinate(0)); + } return new GeometryFactory().createLinearRing(filletCoordinates.toCoordinateArray()); } } ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Jump-pilot-devel mailing list Jump-pilot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel