Revision: 5712 http://sourceforge.net/p/jump-pilot/code/5712 Author: ma15569 Date: 2018-03-14 09:05:39 +0000 (Wed, 14 Mar 2018) Log Message: ----------- * Smal enhancement on AdditionalResul Frame, JSplitPanel divider and added dxf export for plot (only on jFileChooser, not yer working) * Moved Statistics>Plot>(All) and Statistic>Classify attributes output plot into AdditionalResul Frame
Modified Paths: -------------- core/trunk/ChangeLog core/trunk/src/org/openjump/core/ui/plugin/tools/statistics/ClassifyAttributesPlugIn.java core/trunk/src/org/openjump/core/ui/plugin/tools/statistics/CreateBarPlotPlugIn.java core/trunk/src/org/openjump/core/ui/plugin/tools/statistics/CreateHistogramPlugIn.java core/trunk/src/org/openjump/core/ui/plugin/tools/statistics/CreateScatterPlotPlugIn.java core/trunk/src/org/openjump/sextante/gui/additionalResults/AdditionalResultsFrame.java Modified: core/trunk/ChangeLog =================================================================== --- core/trunk/ChangeLog 2018-03-12 15:33:11 UTC (rev 5711) +++ core/trunk/ChangeLog 2018-03-14 09:05:39 UTC (rev 5712) @@ -5,6 +5,12 @@ * Changes.txt updated until here ********************************************** +2018-03-14 Giuseppe Aruta + * Smal enhancement on AdditionalResul Frame, JSplitPanel divider and + added dxf export for plot (only on jFileChooser, not yer working) + * Moved Statistics>Plot>(All) and Statistic>Classify attributes output + plot into AdditionalResul Frame + 2018-03-12 Giuseppe Aruta * Activated Additional Result framemork: outputs other than vector or raster are loaded as objects into a convenient frame where user can Modified: core/trunk/src/org/openjump/core/ui/plugin/tools/statistics/ClassifyAttributesPlugIn.java =================================================================== --- core/trunk/src/org/openjump/core/ui/plugin/tools/statistics/ClassifyAttributesPlugIn.java 2018-03-12 15:33:11 UTC (rev 5711) +++ core/trunk/src/org/openjump/core/ui/plugin/tools/statistics/ClassifyAttributesPlugIn.java 2018-03-14 09:05:39 UTC (rev 5712) @@ -34,7 +34,6 @@ ***********************************************/ package org.openjump.core.ui.plugin.tools.statistics; -import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; @@ -43,11 +42,11 @@ import javax.swing.DefaultComboBoxModel; import javax.swing.JComboBox; -import javax.swing.JInternalFrame; import org.openjump.core.apitools.FeatureSchemaTools; import org.openjump.core.attributeoperations.Classifier1D; import org.openjump.core.ui.plot.Plot2DPanelOJ; +import org.openjump.sextante.gui.additionalResults.AdditionalResults; import com.vividsolutions.jump.I18N; import com.vividsolutions.jump.feature.AttributeType; @@ -72,19 +71,20 @@ import com.vividsolutions.jump.workbench.ui.plugin.FeatureInstaller; //TODO: remove for other classification plugins the "save" option (taken from histogram plugin) -public class ClassifyAttributesPlugIn extends AbstractPlugIn implements ThreadedPlugIn{ +public class ClassifyAttributesPlugIn extends AbstractPlugIn implements + ThreadedPlugIn { private MultiInputDialog dialog; - - private String sideBarText = "Classifies attribute data with the chosen method.\n" + - "The result is added as new field to the attribute table."; + + private String sideBarText = "Classifies attribute data with the chosen method.\n" + + "The result is added as new field to the attribute table."; private String CLASSIFIER = "select classification method"; private String T2 = "number of classes"; private String CLAYER = "select layer"; private String ATTRIBUTE = "select attribute"; - private String OPTIMIZEWITHKMEANS = "optimize with k-means" ; + private String OPTIMIZEWITHKMEANS = "optimize with k-means"; private String PROCESSNULLASZERO = "process null as zero"; - + private String sClassbreaks = "class breaks"; private String sDatapoints = "data points"; private String sCount = "count"; @@ -93,387 +93,454 @@ private String sDisplayBreaks = "Display Breaks"; private String sClassifying = "classifying"; private String sAddingField = "adding field"; - + private Layer selLayer = null; - private int ranges = 7; + private int ranges = 7; private FeatureCollection fc = null; private String selAttribute = null; private String selClassifier = null; private Boolean useKmeans = false; private boolean nullAsZero = false; - + private String sName = "Classify Attributes"; - private String sWarning = "problems appeared"; - private String sNotEnoughValuesWarning = "valid values is not enough"; + private String sWarning = "problems appeared"; + private String sNotEnoughValuesWarning = "valid values is not enough"; private String sWrongDataType = "Wrong datatype of chosen attribute"; private String sNoAttributeChoosen = "No attribute choosen"; - + private Plot2DPanelOJ plot; - + /** - * this method is called on the startup by JUMP/OpenJUMP. - * We set here the menu entry for calling the function. + * this method is called on the startup by JUMP/OpenJUMP. We set here the + * menu entry for calling the function. */ + @Override public void initialize(PlugInContext context) throws Exception { - sideBarText = I18N.get("org.openjump.core.ui.plugin.tools.statistics.ClassifyAttributesPlugin.descriptiontext"); - CLASSIFIER = I18N.get("org.openjump.core.ui.plugin.tools.statistics.ClassifyAttributesPlugin.Select-classification-method"); - T2 = I18N.get("org.openjump.core.ui.plugin.tools.statistics.ClassifyAttributesPlugin.Number-of-classes"); + sideBarText = I18N + .get("org.openjump.core.ui.plugin.tools.statistics.ClassifyAttributesPlugin.descriptiontext"); + CLASSIFIER = I18N + .get("org.openjump.core.ui.plugin.tools.statistics.ClassifyAttributesPlugin.Select-classification-method"); + T2 = I18N + .get("org.openjump.core.ui.plugin.tools.statistics.ClassifyAttributesPlugin.Number-of-classes"); CLAYER = GenericNames.SELECT_LAYER; ATTRIBUTE = GenericNames.SELECT_ATTRIBUTE; - OPTIMIZEWITHKMEANS = I18N.get("org.openjump.core.ui.plugin.tools.statistics.ClassifyAttributesPlugin.Optimize-with-k-means"); - PROCESSNULLASZERO = I18N.get("org.openjump.core.ui.plugin.tools.statistics.ClassifyAttributesPlugin.Process-null-as-zero"); - sClassbreaks = I18N.get("org.openjump.core.ui.plugin.tools.statistics.ClassifyAttributesPlugin.class-breaks"); - sDatapoints = I18N.get("org.openjump.core.ui.plugin.tools.statistics.ClassifyAttributesPlugin.data-points"); - sCount = I18N.get("org.openjump.core.ui.plugin.tools.statistics.CreateHistogramPlugIn.count"); - sHistogram = I18N.get("org.openjump.core.ui.plugin.tools.statistics.CreateHistogramPlugIn.Histogram-Plot"); - sCalculateBreaks = I18N.get("org.openjump.core.ui.plugin.tools.statistics.ClassifyAttributesPlugin.Calculating-Breaks"); - sDisplayBreaks = I18N.get("org.openjump.core.ui.plugin.tools.statistics.ClassifyAttributesPlugin.Displaying-Breaks"); - sClassifying = I18N.get("org.openjump.core.ui.plugin.tools.statistics.ClassifyAttributesPlugin.classifying"); - sAddingField = I18N.get("org.openjump.core.ui.plugin.tools.statistics.ClassifyAttributesPlugin.create-output-field"); - sName = I18N.get("org.openjump.core.ui.plugin.tools.statistics.ClassifyAttributesPlugin.Classify-Attribute"); - sWarning = I18N.get("org.openjump.core.ui.plugin.tools.statistics.ClassifyAttributesPlugin.Error-during-classification"); - sNotEnoughValuesWarning = I18N.get("org.openjump.core.ui.plugin.tools.statistics.ClassifyAttributesPlugin.Not-enough-values"); - sWrongDataType = I18N.get("org.openjump.core.ui.plugin.tools.statistics.CreateBarPlotPlugIn.Wrong-datatype-of-chosen-attribute"); - sNoAttributeChoosen = I18N.get("org.openjump.core.ui.plugin.tools.statistics.ClassifyAttributesPlugin.No-attribute-choosen"); - - FeatureInstaller featureInstaller = new FeatureInstaller(context.getWorkbenchContext()); - featureInstaller.addMainMenuPlugin( - this, - new String[] {MenuNames.TOOLS, MenuNames.STATISTICS}, - this.sName + "...", //name methode .getName recieved by AbstractPlugIn - false, //checkbox - null, //icon - createEnableCheck(context.getWorkbenchContext())); //enable check + OPTIMIZEWITHKMEANS = I18N + .get("org.openjump.core.ui.plugin.tools.statistics.ClassifyAttributesPlugin.Optimize-with-k-means"); + PROCESSNULLASZERO = I18N + .get("org.openjump.core.ui.plugin.tools.statistics.ClassifyAttributesPlugin.Process-null-as-zero"); + sClassbreaks = I18N + .get("org.openjump.core.ui.plugin.tools.statistics.ClassifyAttributesPlugin.class-breaks"); + sDatapoints = I18N + .get("org.openjump.core.ui.plugin.tools.statistics.ClassifyAttributesPlugin.data-points"); + sCount = I18N + .get("org.openjump.core.ui.plugin.tools.statistics.CreateHistogramPlugIn.count"); + sHistogram = I18N + .get("org.openjump.core.ui.plugin.tools.statistics.CreateHistogramPlugIn.Histogram-Plot"); + sCalculateBreaks = I18N + .get("org.openjump.core.ui.plugin.tools.statistics.ClassifyAttributesPlugin.Calculating-Breaks"); + sDisplayBreaks = I18N + .get("org.openjump.core.ui.plugin.tools.statistics.ClassifyAttributesPlugin.Displaying-Breaks"); + sClassifying = I18N + .get("org.openjump.core.ui.plugin.tools.statistics.ClassifyAttributesPlugin.classifying"); + sAddingField = I18N + .get("org.openjump.core.ui.plugin.tools.statistics.ClassifyAttributesPlugin.create-output-field"); + sName = I18N + .get("org.openjump.core.ui.plugin.tools.statistics.ClassifyAttributesPlugin.Classify-Attribute"); + sWarning = I18N + .get("org.openjump.core.ui.plugin.tools.statistics.ClassifyAttributesPlugin.Error-during-classification"); + sNotEnoughValuesWarning = I18N + .get("org.openjump.core.ui.plugin.tools.statistics.ClassifyAttributesPlugin.Not-enough-values"); + sWrongDataType = I18N + .get("org.openjump.core.ui.plugin.tools.statistics.CreateBarPlotPlugIn.Wrong-datatype-of-chosen-attribute"); + sNoAttributeChoosen = I18N + .get("org.openjump.core.ui.plugin.tools.statistics.ClassifyAttributesPlugin.No-attribute-choosen"); + final FeatureInstaller featureInstaller = new FeatureInstaller( + context.getWorkbenchContext()); + featureInstaller.addMainMenuPlugin(this, new String[] { + MenuNames.TOOLS, MenuNames.STATISTICS }, sName + "...", // name + // methode + // .getName + // recieved + // by + // AbstractPlugIn + false, // checkbox + null, // icon + createEnableCheck(context.getWorkbenchContext())); // enable + // check + } - + /** * This method is used to define when the menu entry is activated or - * disabled. In this example we allow the menu entry to be usable only - * if one layer exists. + * disabled. In this example we allow the menu entry to be usable only if + * one layer exists. */ - public static MultiEnableCheck createEnableCheck(WorkbenchContext workbenchContext) { - EnableCheckFactory checkFactory = new EnableCheckFactory(workbenchContext); + public static MultiEnableCheck createEnableCheck( + WorkbenchContext workbenchContext) { + final EnableCheckFactory checkFactory = new EnableCheckFactory( + workbenchContext); return new MultiEnableCheck() - .add(checkFactory.createWindowWithAssociatedTaskFrameMustBeActiveCheck()) + .add(checkFactory + .createWindowWithAssociatedTaskFrameMustBeActiveCheck()) .add(checkFactory.createAtLeastNLayersMustExistCheck(1)); } - + /** * this function is called by JUMP/OpenJUMP if one clicks on the menu entry. - * It is called before the "run" method and useful to do all the GUI /user-input things - * In this example we call two additional methods {@link #setDialogValues(MultiInputDialog, PlugInContext)} - * and {@link #getDialogValues(MultiInputDialog)} to obtain the Layer and the buffer radius by the user. + * It is called before the "run" method and useful to do all the GUI + * /user-input things In this example we call two additional methods + * {@link #setDialogValues(MultiInputDialog, PlugInContext)} and + * {@link #getDialogValues(MultiInputDialog)} to obtain the Layer and the + * buffer radius by the user. */ - public boolean execute(PlugInContext context) throws Exception{ - - this.reportNothingToUndoYet(context); - - dialog = new MultiInputDialog( - context.getWorkbenchFrame(), sName, true); - this.setDialogValues(dialog, context); - GUIUtil.centreOnWindow(dialog); - dialog.setVisible(true); - if (! dialog.wasOKPressed()) { return false; } - this.getDialogValues(dialog); - + @Override + public boolean execute(PlugInContext context) throws Exception { + + reportNothingToUndoYet(context); + + dialog = new MultiInputDialog(context.getWorkbenchFrame(), sName, true); + setDialogValues(dialog, context); + GUIUtil.centreOnWindow(dialog); + dialog.setVisible(true); + if (!dialog.wasOKPressed()) { + return false; + } + getDialogValues(dialog); + return true; } - - public void run(TaskMonitor monitor, PlugInContext context) throws Exception { - //-- get the LM because when the Histogram will be shown, the app. focus - // will change and context.addLayer will not work (null pointer exc.) - // [mmichaud 2012-04-09] to completely resolve this problem, the new - // JInternalFrame is added after addLayer method has been called - LayerManager currentLM = context.getLayerManager(); - monitor.allowCancellationRequests(); - if (this.selAttribute == null) { - context.getWorkbenchFrame().warnUser(I18N.get(sNoAttributeChoosen)); - return; - } - javax.swing.JInternalFrame internalFrame = context.getWorkbenchFrame().getActiveInternalFrame(); - FeatureDataset result = classifyAndCreatePlot(monitor, context); - context.getWorkbenchFrame().activateFrame(internalFrame); - if (result == null) { - context.getWorkbenchFrame().warnUser(I18N.get(sNotEnoughValuesWarning)); - } - else if(result.size() > 0){ - String name = this.selAttribute + "_" + this.selClassifier; - currentLM.addLayer(StandardCategoryNames.WORKING, name, result); - JInternalFrame frame = new JInternalFrame(this.sHistogram); - frame.setLayout(new BorderLayout()); - frame.add(plot, BorderLayout.CENTER); - frame.setClosable(true); - frame.setResizable(true); - frame.setMaximizable(true); - frame.setSize(450, 450); - context.getWorkbenchFrame().addInternalFrame(frame); + + @Override + public void run(TaskMonitor monitor, PlugInContext context) + throws Exception { + // -- get the LM because when the Histogram will be shown, the app. + // focus + // will change and context.addLayer will not work (null pointer exc.) + // [mmichaud 2012-04-09] to completely resolve this problem, the new + // JInternalFrame is added after addLayer method has been called + final LayerManager currentLM = context.getLayerManager(); + monitor.allowCancellationRequests(); + if (selAttribute == null) { + context.getWorkbenchFrame().warnUser(I18N.get(sNoAttributeChoosen)); + return; + } + final javax.swing.JInternalFrame internalFrame = context + .getWorkbenchFrame().getActiveInternalFrame(); + final FeatureDataset result = classifyAndCreatePlot(monitor, context); + context.getWorkbenchFrame().activateFrame(internalFrame); + if (result == null) { + context.getWorkbenchFrame().warnUser( + I18N.get(sNotEnoughValuesWarning)); + } else if (result.size() > 0) { + final String name = selAttribute + "_" + selClassifier; + currentLM.addLayer(StandardCategoryNames.WORKING, name, result); + AdditionalResults.addAdditionalResultAndShow(sHistogram, plot); + + /* + * JInternalFrame frame = new JInternalFrame(this.sHistogram); + * frame.setLayout(new BorderLayout()); frame.add(plot, + * BorderLayout.CENTER); frame.setClosable(true); + * frame.setResizable(true); frame.setMaximizable(true); + * frame.setSize(450, 450); + * context.getWorkbenchFrame().addInternalFrame(frame); + */ plot = null; - } - else{ - context.getWorkbenchFrame().warnUser(sWarning); - } - } - + } else { + context.getWorkbenchFrame().warnUser(sWarning); + } + } + private void setDialogValues(MultiInputDialog dialog, PlugInContext context) { - - dialog.setSideBarDescription(sideBarText); - - dialog.addLayerComboBox(CLAYER, context.getCandidateLayer(0), context.getLayerManager()); - - List<String> listNumAttributes = FeatureSchemaTools - .getFieldsFromLayerWithoutGeometryAndString(context.getCandidateLayer(0)); - Object valAttribute = listNumAttributes.size()>0?listNumAttributes.iterator().next():null; - final JComboBox<String> jcb_attribute = dialog - .addComboBox(this.ATTRIBUTE, valAttribute, listNumAttributes, this.ATTRIBUTE); - if (listNumAttributes.size() == 0) jcb_attribute.setEnabled(false); - - List listClassifiers = Classifier1D.getAvailableClassificationMethods(); - Object valClassifier = listNumAttributes.size()>0?listNumAttributes.iterator().next():null; - dialog.addComboBox(this.CLASSIFIER, valClassifier, listClassifiers, this.CLASSIFIER); - - dialog.addIntegerField(T2, this.ranges, 6, T2); - - dialog.addCheckBox(this.OPTIMIZEWITHKMEANS, false); - - dialog.addCheckBox(this.PROCESSNULLASZERO, false); - + + dialog.setSideBarDescription(sideBarText); + + dialog.addLayerComboBox(CLAYER, context.getCandidateLayer(0), + context.getLayerManager()); + + final List<String> listNumAttributes = FeatureSchemaTools + .getFieldsFromLayerWithoutGeometryAndString(context + .getCandidateLayer(0)); + final Object valAttribute = listNumAttributes.size() > 0 ? listNumAttributes + .iterator().next() : null; + final JComboBox<String> jcb_attribute = dialog.addComboBox(ATTRIBUTE, + valAttribute, listNumAttributes, ATTRIBUTE); + if (listNumAttributes.size() == 0) { + jcb_attribute.setEnabled(false); + } + + final List listClassifiers = Classifier1D + .getAvailableClassificationMethods(); + final Object valClassifier = listNumAttributes.size() > 0 ? listNumAttributes + .iterator().next() : null; + dialog.addComboBox(CLASSIFIER, valClassifier, listClassifiers, + CLASSIFIER); + + dialog.addIntegerField(T2, ranges, 6, T2); + + dialog.addCheckBox(OPTIMIZEWITHKMEANS, false); + + dialog.addCheckBox(PROCESSNULLASZERO, false); + dialog.getComboBox(CLAYER).addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { - List<String> list = getFieldsFromLayerWithoutGeometryAndString(); + final List<String> list = getFieldsFromLayerWithoutGeometryAndString(); if (list.size() == 0) { - jcb_attribute.setModel(new DefaultComboBoxModel<>(new String[0])); + jcb_attribute.setModel(new DefaultComboBoxModel<>( + new String[0])); jcb_attribute.setEnabled(false); - } - else { - jcb_attribute.setModel(new DefaultComboBoxModel<>(list.toArray(new String[0]))); + } else { + jcb_attribute.setModel(new DefaultComboBoxModel<>(list + .toArray(new String[0]))); jcb_attribute.setEnabled(true); } } - }); - } + }); + } private void getDialogValues(MultiInputDialog dialog) { - this.ranges = dialog.getInteger(T2); - this.selLayer = dialog.getLayer(CLAYER); - this.fc = this.selLayer.getFeatureCollectionWrapper(); - this.selAttribute = dialog.getText(ATTRIBUTE); - this.selClassifier = dialog.getText(this.CLASSIFIER); - this.useKmeans = dialog.getBoolean(this.OPTIMIZEWITHKMEANS); - this.nullAsZero = dialog.getBoolean(this.PROCESSNULLASZERO); + ranges = dialog.getInteger(T2); + selLayer = dialog.getLayer(CLAYER); + fc = selLayer.getFeatureCollectionWrapper(); + selAttribute = dialog.getText(ATTRIBUTE); + selClassifier = dialog.getText(CLASSIFIER); + useKmeans = dialog.getBoolean(OPTIMIZEWITHKMEANS); + nullAsZero = dialog.getBoolean(PROCESSNULLASZERO); } - - private FeatureDataset classifyAndCreatePlot(TaskMonitor monitor, final PlugInContext context) throws Exception { - - monitor.report(this.sCalculateBreaks); - //=============== get DATA and prepare ==============/ - FeatureSchema fs = this.fc.getFeatureSchema(); + + private FeatureDataset classifyAndCreatePlot(TaskMonitor monitor, + final PlugInContext context) throws Exception { + + monitor.report(sCalculateBreaks); + // =============== get DATA and prepare ==============/ + final FeatureSchema fs = fc.getFeatureSchema(); AttributeType type; - if ((fs.getAttributeType(this.selAttribute) == AttributeType.DOUBLE) || - (fs.getAttributeType(this.selAttribute) == AttributeType.INTEGER)){ - //-- move on - type = fs.getAttributeType(this.selAttribute); - } - else{ - //System.out.println("ClassifyAttributesPlugIn: wrong datatype of chosen attribute"); - context.getWorkbenchFrame().warnUser(sWrongDataType); + if ((fs.getAttributeType(selAttribute) == AttributeType.DOUBLE) + || (fs.getAttributeType(selAttribute) == AttributeType.INTEGER)) { + // -- move on + type = fs.getAttributeType(selAttribute); + } else { + // System.out.println("ClassifyAttributesPlugIn: wrong datatype of chosen attribute"); + context.getWorkbenchFrame().warnUser(sWrongDataType); return null; } - - int size = getFeatureCollectionSize(this.fc, this.selAttribute, this.nullAsZero); + + final int size = getFeatureCollectionSize(fc, selAttribute, nullAsZero); if (size < 3) { return null; } - this.ranges = Math.min(this.ranges, size); - - - double[] data = new double[size]; - double[][] plotdata = new double[2][size]; //for drawing 1-D scatter plot - int[] fID = new int[size]; + ranges = Math.min(ranges, size); + + final double[] data = new double[size]; + final double[][] plotdata = new double[2][size]; // for drawing 1-D + // scatter plot + final int[] fID = new int[size]; int i = 0; - for (Iterator iter = fc.iterator(); iter.hasNext();) { - Feature f = (Feature) iter.next(); - if (f.getAttribute(this.selAttribute)==null && !nullAsZero) continue; + for (final Iterator iter = fc.iterator(); iter.hasNext();) { + final Feature f = (Feature) iter.next(); + if (f.getAttribute(selAttribute) == null && !nullAsZero) { + continue; + } fID[i] = f.getID(); plotdata[1][i] = 1; - Object val = f.getAttribute(this.selAttribute); - if (type == AttributeType.DOUBLE){ - if (val == null) data[i] = 0.0; - else data[i] = (Double)val; + final Object val = f.getAttribute(selAttribute); + if (type == AttributeType.DOUBLE) { + if (val == null) { + data[i] = 0.0; + } else { + data[i] = (Double) val; + } + } else if (type == AttributeType.INTEGER) { + if (val == null) { + data[i] = 0; + } else { + data[i] = (Integer) val; + } } - else if (type == AttributeType.INTEGER){ - if (val == null) data[i] = 0; - else data[i] = (Integer)val; - } plotdata[0][i] = data[i]; i++; - } + } /* - //-- some testdata - double[][] plotdata2 = new double[2][8]; - double[] data2 = { -2, 4, 6, 5, 0, 10, 7, 1 }; - double[] axis2 = { 1, 1, 1, 1, 1, 1, 1, 1 }; - plotdata2[0] = data2; - plotdata2[1] = axis2; - */ - - if(monitor.isCancelRequested()){ - return null; + * //-- some testdata double[][] plotdata2 = new double[2][8]; double[] + * data2 = { -2, 4, 6, 5, 0, 10, 7, 1 }; double[] axis2 = { 1, 1, 1, 1, + * 1, 1, 1, 1 }; plotdata2[0] = data2; plotdata2[1] = axis2; + */ + + if (monitor.isCancelRequested()) { + return null; } - - //=============== find breaks according to chosen method ==============/ + + // =============== find breaks according to chosen method + // ==============/ double[] limits = null; - - if (this.useKmeans == false){ - if (this.selClassifier == Classifier1D.EQUAL_NUMBER){ - limits = Classifier1D.classifyEqualNumber(data, this.ranges); - } - else if(this.selClassifier == Classifier1D.EQUAL_RANGE){ - limits = Classifier1D.classifyEqualRange(data, this.ranges); - } - else if(this.selClassifier == Classifier1D.MEAN_STDEV){ - limits = Classifier1D.classifyMeanStandardDeviation(data, this.ranges); - } - else if(this.selClassifier == Classifier1D.MAX_BREAKS){ - limits = Classifier1D.classifyMaxBreaks(data, this.ranges); - } - else if(this.selClassifier == Classifier1D.JENKS_BREAKS){ - limits = Classifier1D.classifyNaturalBreaks(data, this.ranges); - } + + if (useKmeans == false) { + if (selClassifier == Classifier1D.EQUAL_NUMBER) { + limits = Classifier1D.classifyEqualNumber(data, ranges); + } else if (selClassifier == Classifier1D.EQUAL_RANGE) { + limits = Classifier1D.classifyEqualRange(data, ranges); + } else if (selClassifier == Classifier1D.MEAN_STDEV) { + limits = Classifier1D.classifyMeanStandardDeviation(data, + ranges); + } else if (selClassifier == Classifier1D.MAX_BREAKS) { + limits = Classifier1D.classifyMaxBreaks(data, ranges); + } else if (selClassifier == Classifier1D.JENKS_BREAKS) { + limits = Classifier1D.classifyNaturalBreaks(data, ranges); + } + } else { + if (selClassifier == Classifier1D.EQUAL_NUMBER) { + limits = Classifier1D.classifyKMeansOnExistingBreaks(data, + ranges, 3); + } else if (selClassifier == Classifier1D.EQUAL_RANGE) { + limits = Classifier1D.classifyKMeansOnExistingBreaks(data, + ranges, 2); + } else if (selClassifier == Classifier1D.MEAN_STDEV) { + limits = Classifier1D.classifyKMeansOnExistingBreaks(data, + ranges, 4); + } else if (selClassifier == Classifier1D.MAX_BREAKS) { + limits = Classifier1D.classifyKMeansOnExistingBreaks(data, + ranges, 1); + } else if (selClassifier == Classifier1D.JENKS_BREAKS) { + limits = Classifier1D.classifyKMeansOnExistingBreaks(data, + ranges, 5); + } } - else{ - if (this.selClassifier == Classifier1D.EQUAL_NUMBER){ - limits = Classifier1D.classifyKMeansOnExistingBreaks(data, this.ranges, 3); - } - else if(this.selClassifier == Classifier1D.EQUAL_RANGE){ - limits = Classifier1D.classifyKMeansOnExistingBreaks(data, this.ranges, 2 ); - } - else if(this.selClassifier == Classifier1D.MEAN_STDEV){ - limits = Classifier1D.classifyKMeansOnExistingBreaks(data, this.ranges, 4 ); - } - else if(this.selClassifier == Classifier1D.MAX_BREAKS){ - limits = Classifier1D.classifyKMeansOnExistingBreaks(data, this.ranges, 1 ); - } - else if(this.selClassifier == Classifier1D.JENKS_BREAKS){ - limits = Classifier1D.classifyKMeansOnExistingBreaks(data, this.ranges, 5 ); - } + + if (monitor.isCancelRequested()) { + return null; } - - if(monitor.isCancelRequested()){ - return null; - } - - monitor.report(this.sDisplayBreaks); - //=============== plot data and class breaks ==============/ - //-- do display here - in case we later want to allow interactive editing of the limits - - //-- reformat limits + + monitor.report(sDisplayBreaks); + // =============== plot data and class breaks ==============/ + // -- do display here - in case we later want to allow interactive + // editing of the limits + + // -- reformat limits double[][] limits2show = new double[2][limits.length]; - //-- due to bug in jmathplot add limits twice if only three classes = 2breaks are sought - if (limits.length == 2){ - limits2show = new double[2][limits.length*2]; + // -- due to bug in jmathplot add limits twice if only three classes = + // 2breaks are sought + if (limits.length == 2) { + limits2show = new double[2][limits.length * 2]; } for (int j = 0; j < limits.length; j++) { - limits2show[0][j]= limits[j]; //x-axis - limits2show[1][j]= Math.floor(i/(4.0*this.ranges)); //y-axis, estimate height of "bar" from number of items - //limits2show[1][j]= 1; - //-- due to bug in jmathplot add limits twice if only three classes are sought - if (limits.length == 2){ - limits2show[0][limits.length+j]= limits[j]; - limits2show[1][limits.length+j]= Math.floor(i/(4.0*this.ranges)); + limits2show[0][j] = limits[j]; // x-axis + limits2show[1][j] = Math.floor(i / (4.0 * ranges)); // y-axis, + // estimate + // height of + // "bar" from + // number of + // items + // limits2show[1][j]= 1; + // -- due to bug in jmathplot add limits twice if only three classes + // are sought + if (limits.length == 2) { + limits2show[0][limits.length + j] = limits[j]; + limits2show[1][limits.length + j] = Math.floor(i + / (4.0 * ranges)); } } - - //=============== plot data and class breaks ==============/ - //-- create plots - /*final Plot2DPanelOJ*/ plot = new Plot2DPanelOJ(); - plot.addHistogramPlotOJ(this.selAttribute, data, this.ranges*3, context, selLayer, this.selAttribute); - plot.addScatterPlotOJ(this.sDatapoints, plotdata, fID, context, this.selLayer); - plot.addBarPlot(this.sClassbreaks, limits2show); + + // =============== plot data and class breaks ==============/ + // -- create plots + /* final Plot2DPanelOJ */plot = new Plot2DPanelOJ(); + plot.addHistogramPlotOJ(selAttribute, data, ranges * 3, context, + selLayer, selAttribute); + plot.addScatterPlotOJ(sDatapoints, plotdata, fID, context, selLayer); + plot.addBarPlot(sClassbreaks, limits2show); plot.plotToolBar.setVisible(true); - plot.setAxisLabel(0, this.selAttribute); - plot.setAxisLabel(1, this.sCount); + plot.setAxisLabel(0, selAttribute); + plot.setAxisLabel(1, sCount); plot.addLegend("SOUTH"); - + // [mmichaud 2012-04-09] Moved in run method after the addLayer method // to avoid the problem of the focus change - - //JInternalFrame frame = new JInternalFrame(this.sHistogram); - //frame.setLayout(new BorderLayout()); - //frame.add(plot, BorderLayout.CENTER); - //frame.setClosable(true); - //frame.setResizable(true); - //frame.setMaximizable(true); - //frame.setSize(450, 450); - //frame.setVisible(true); - - //context.getWorkbenchFrame().addInternalFrame(frame); - - //=============== classify data ==============/ - if(monitor.isCancelRequested()){ - return null; + + // JInternalFrame frame = new JInternalFrame(this.sHistogram); + // frame.setLayout(new BorderLayout()); + // frame.add(plot, BorderLayout.CENTER); + // frame.setClosable(true); + // frame.setResizable(true); + // frame.setMaximizable(true); + // frame.setSize(450, 450); + // frame.setVisible(true); + + // context.getWorkbenchFrame().addInternalFrame(frame); + + // =============== classify data ==============/ + if (monitor.isCancelRequested()) { + return null; } - monitor.report(this.sClassifying); - int[] classes = Classifier1D.classifyData(data, limits); - //double[] classes = org.math.array.StatisticSample.one(data.length); - //context.getWorkbenchFrame().warnUser("classification not yet implemented"); - - //=============== add field ==============/ - if(monitor.isCancelRequested()){ - return null; + monitor.report(sClassifying); + final int[] classes = Classifier1D.classifyData(data, limits); + // double[] classes = org.math.array.StatisticSample.one(data.length); + // context.getWorkbenchFrame().warnUser("classification not yet implemented"); + + // =============== add field ==============/ + if (monitor.isCancelRequested()) { + return null; } - monitor.report(sAddingField); - - FeatureDataset fd; - ArrayList<Feature> outData = new ArrayList<>(); - FeatureSchema targetFSnew = null; - int count=0; - Iterator iterp = fc.iterator(); - String attname = this.selAttribute + "_" + this.selClassifier; - while(iterp.hasNext()){ - //count=count+1; -// if(monitor != null){ -// monitor.report("item: " + count + " of " + size); -// } - Feature p = (Feature)iterp.next(); - Object val = p.getAttribute(this.selAttribute); - if (val == null && !this.nullAsZero) continue; - else count++; - if (count == 1){ - FeatureSchema targetFs = p.getSchema(); - targetFSnew = FeatureSchemaTools.copyFeatureSchema(targetFs); - if (targetFSnew.hasAttribute(attname)){ - //attribute will be overwriten - } - else{ - //add attribute - targetFSnew.addAttribute(attname, AttributeType.INTEGER); - } - } - //-- evaluate value for every polygon - Feature fcopy = FeatureSchemaTools.copyFeature(p, targetFSnew); - //fcopy.setAttribute(this.selClassifier, new Integer(classes[count-1])); - fcopy.setAttribute(attname, classes[count-1]); - outData.add(fcopy); - } - fd = new FeatureDataset(targetFSnew); - fd.addAll(outData); + monitor.report(sAddingField); + + FeatureDataset fd; + final ArrayList<Feature> outData = new ArrayList<>(); + FeatureSchema targetFSnew = null; + int count = 0; + final Iterator iterp = fc.iterator(); + final String attname = selAttribute + "_" + selClassifier; + while (iterp.hasNext()) { + // count=count+1; + // if(monitor != null){ + // monitor.report("item: " + count + " of " + size); + // } + final Feature p = (Feature) iterp.next(); + final Object val = p.getAttribute(selAttribute); + if (val == null && !nullAsZero) { + continue; + } else { + count++; + } + if (count == 1) { + final FeatureSchema targetFs = p.getSchema(); + targetFSnew = FeatureSchemaTools.copyFeatureSchema(targetFs); + if (targetFSnew.hasAttribute(attname)) { + // attribute will be overwriten + } else { + // add attribute + targetFSnew.addAttribute(attname, AttributeType.INTEGER); + } + } + // -- evaluate value for every polygon + final Feature fcopy = FeatureSchemaTools + .copyFeature(p, targetFSnew); + // fcopy.setAttribute(this.selClassifier, new + // Integer(classes[count-1])); + fcopy.setAttribute(attname, classes[count - 1]); + outData.add(fcopy); + } + fd = new FeatureDataset(targetFSnew); + fd.addAll(outData); return fd; } - - private int getFeatureCollectionSize(FeatureCollection fc, String attribute, boolean nullAsZero) { + + private int getFeatureCollectionSize(FeatureCollection fc, + String attribute, boolean nullAsZero) { int size = 0; - for (Iterator it = fc.iterator(); it.hasNext();) { - Feature f = (Feature) it.next(); - if (nullAsZero || f.getAttribute(attribute)!=null) size++; + for (final Iterator it = fc.iterator(); it.hasNext();) { + final Feature f = (Feature) it.next(); + if (nullAsZero || f.getAttribute(attribute) != null) { + size++; + } } return size; } - + private List<String> getFieldsFromLayerWithoutGeometryAndString() { - return FeatureSchemaTools.getFieldsFromLayerWithoutGeometryAndString(dialog.getLayer(CLAYER)); + return FeatureSchemaTools + .getFieldsFromLayerWithoutGeometryAndString(dialog + .getLayer(CLAYER)); } - + } Modified: core/trunk/src/org/openjump/core/ui/plugin/tools/statistics/CreateBarPlotPlugIn.java =================================================================== --- core/trunk/src/org/openjump/core/ui/plugin/tools/statistics/CreateBarPlotPlugIn.java 2018-03-12 15:33:11 UTC (rev 5711) +++ core/trunk/src/org/openjump/core/ui/plugin/tools/statistics/CreateBarPlotPlugIn.java 2018-03-14 09:05:39 UTC (rev 5712) @@ -37,7 +37,6 @@ ***********************************************/ package org.openjump.core.ui.plugin.tools.statistics; -import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.List; @@ -44,10 +43,9 @@ import javax.swing.DefaultComboBoxModel; import javax.swing.JComboBox; -import javax.swing.JInternalFrame; -import com.vividsolutions.jump.workbench.ui.*; import org.openjump.core.ui.plot.Plot2DPanelOJ; +import org.openjump.sextante.gui.additionalResults.AdditionalResults; import com.vividsolutions.jump.I18N; import com.vividsolutions.jump.feature.AttributeType; @@ -62,125 +60,159 @@ import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck; import com.vividsolutions.jump.workbench.plugin.PlugInContext; import com.vividsolutions.jump.workbench.plugin.ThreadedPlugIn; +import com.vividsolutions.jump.workbench.ui.AttributeTypeFilter; +import com.vividsolutions.jump.workbench.ui.GUIUtil; +import com.vividsolutions.jump.workbench.ui.GenericNames; +import com.vividsolutions.jump.workbench.ui.MenuNames; +import com.vividsolutions.jump.workbench.ui.MultiInputDialog; import com.vividsolutions.jump.workbench.ui.plugin.FeatureInstaller; -public class CreateBarPlotPlugIn extends AbstractPlugIn implements ThreadedPlugIn{ +public class CreateBarPlotPlugIn extends AbstractPlugIn implements + ThreadedPlugIn { private String sBarPlot = "Bar-Plot"; private String sNthfeature = "n-th feature"; - + private String CLAYER = "select layer"; private String ATTRIBUTE = "select attribute"; - private Layer selLayer = null; + private Layer selLayer = null; private String selAttribute = null; private String sName = "Create Bar Plot"; private String sWrongDataType = "Wrong datatype of chosen attribute"; /** - * this method is called on the startup by JUMP/OpenJUMP. - * We set here the menu entry for calling the function. + * this method is called on the startup by JUMP/OpenJUMP. We set here the + * menu entry for calling the function. */ - public void initialize(PlugInContext context) throws Exception { - - ATTRIBUTE = GenericNames.SELECT_ATTRIBUTE; - CLAYER = GenericNames.SELECT_LAYER; - sBarPlot = I18N.get("org.openjump.core.ui.plugin.tools.statistics.CreateBarPlotPlugIn.Bar-Plot"); - sNthfeature = I18N.get("org.openjump.core.ui.plugin.tools.statistics.CreateBarPlotPlugIn.n-th-feature"); - sName = I18N.get("org.openjump.core.ui.plugin.tools.statistics.CreateBarPlotPlugIn"); - sWrongDataType = I18N.get("org.openjump.core.ui.plugin.tools.statistics.CreateBarPlotPlugIn.Wrong-datatype-of-chosen-attribute"); - - FeatureInstaller featureInstaller = new FeatureInstaller(context.getWorkbenchContext()); - featureInstaller.addMainMenuPlugin( - this, - new String[] {MenuNames.TOOLS, MenuNames.STATISTICS, MenuNames.PLOT }, - this.sName + "...", - false, //checkbox - null, //icon - createEnableCheck(context.getWorkbenchContext())); + @Override + public void initialize(PlugInContext context) throws Exception { - } - + ATTRIBUTE = GenericNames.SELECT_ATTRIBUTE; + CLAYER = GenericNames.SELECT_LAYER; + sBarPlot = I18N + .get("org.openjump.core.ui.plugin.tools.statistics.CreateBarPlotPlugIn.Bar-Plot"); + sNthfeature = I18N + .get("org.openjump.core.ui.plugin.tools.statistics.CreateBarPlotPlugIn.n-th-feature"); + sName = I18N + .get("org.openjump.core.ui.plugin.tools.statistics.CreateBarPlotPlugIn"); + sWrongDataType = I18N + .get("org.openjump.core.ui.plugin.tools.statistics.CreateBarPlotPlugIn.Wrong-datatype-of-chosen-attribute"); + + final FeatureInstaller featureInstaller = new FeatureInstaller( + context.getWorkbenchContext()); + featureInstaller.addMainMenuPlugin(this, new String[] { + MenuNames.TOOLS, MenuNames.STATISTICS, MenuNames.PLOT }, sName + + "...", false, // checkbox + null, // icon + createEnableCheck(context.getWorkbenchContext())); + + } + /** * This method is used to define when the menu entry is activated or - * disabled. In this example we allow the menu entry to be usable only - * if one layer exists. + * disabled. In this example we allow the menu entry to be usable only if + * one layer exists. */ - public static MultiEnableCheck createEnableCheck(WorkbenchContext workbenchContext) { - EnableCheckFactory checkFactory = new EnableCheckFactory(workbenchContext); + public static MultiEnableCheck createEnableCheck( + WorkbenchContext workbenchContext) { + final EnableCheckFactory checkFactory = new EnableCheckFactory( + workbenchContext); return new MultiEnableCheck() - .add(checkFactory.createAtLeastNLayersMustExistCheck(1)) - .add(checkFactory.createWindowWithAssociatedTaskFrameMustBeActiveCheck()); + .add(checkFactory.createAtLeastNLayersMustExistCheck(1)) + .add(checkFactory + .createWindowWithAssociatedTaskFrameMustBeActiveCheck()); } - + /** * this function is called by JUMP/OpenJUMP if one clicks on the menu entry. - * It is called before the "run" method and useful to do all the GUI /user-input things - * In this example we call two additional methods {@link #setDialogValues(MultiInputDialog, PlugInContext)} - * and {@link #getDialogValues(MultiInputDialog)} to obtain the Layer and the buffer radius by the user. + * It is called before the "run" method and useful to do all the GUI + * /user-input things In this example we call two additional methods + * {@link #setDialogValues(MultiInputDialog, PlugInContext)} and + * {@link #getDialogValues(MultiInputDialog)} to obtain the Layer and the + * buffer radius by the user. */ - public boolean execute(PlugInContext context) throws Exception{ - - this.reportNothingToUndoYet(context); - - MultiInputDialog dialog = new MultiInputDialog( + @Override + public boolean execute(PlugInContext context) throws Exception { + + reportNothingToUndoYet(context); + + final MultiInputDialog dialog = new MultiInputDialog( context.getWorkbenchFrame(), sName, true); - this.setDialogValues(dialog, context); - GUIUtil.centreOnWindow(dialog); - dialog.setVisible(true); - if (! dialog.wasOKPressed()) { return false; } - this.getDialogValues(dialog); - + setDialogValues(dialog, context); + GUIUtil.centreOnWindow(dialog); + dialog.setVisible(true); + if (!dialog.wasOKPressed()) { + return false; + } + getDialogValues(dialog); + return true; } - - public void run(TaskMonitor monitor, PlugInContext context) throws Exception { - createPlot(context, this.selLayer); - - } - - private void setDialogValues(final MultiInputDialog dialog, PlugInContext context) { - dialog.addLayerComboBox(CLAYER, context.getCandidateLayer(0), context.getLayerManager()); - - List<String> list = AttributeTypeFilter.NUMERIC_FILTER.filter(context.getCandidateLayer(0)); - String val = list.size()>0?list.get(0):null; - final JComboBox<String> jcb_attribute = dialog.addComboBox(ATTRIBUTE, val, list, ATTRIBUTE); - if (list.size() == 0) jcb_attribute.setEnabled(false); + @Override + public void run(TaskMonitor monitor, PlugInContext context) + throws Exception { + createPlot(context, selLayer); + } + + private void setDialogValues(final MultiInputDialog dialog, + PlugInContext context) { + + dialog.addLayerComboBox(CLAYER, context.getCandidateLayer(0), + context.getLayerManager()); + + final List<String> list = AttributeTypeFilter.NUMERIC_FILTER + .filter(context.getCandidateLayer(0)); + final String val = list.size() > 0 ? list.get(0) : null; + final JComboBox<String> jcb_attribute = dialog.addComboBox(ATTRIBUTE, + val, list, ATTRIBUTE); + if (list.size() == 0) { + jcb_attribute.setEnabled(false); + } + dialog.getComboBox(CLAYER).addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { - List<String> list = AttributeTypeFilter.NUMERIC_FILTER.filter(dialog.getLayer(CLAYER)); + final List<String> list = AttributeTypeFilter.NUMERIC_FILTER + .filter(dialog.getLayer(CLAYER)); if (list.size() == 0) { - jcb_attribute.setModel(new DefaultComboBoxModel<>(new String[0])); + jcb_attribute.setModel(new DefaultComboBoxModel<>( + new String[0])); jcb_attribute.setEnabled(false); } - jcb_attribute.setModel(new DefaultComboBoxModel<>(list.toArray(new String[0]))); + jcb_attribute.setModel(new DefaultComboBoxModel<>(list + .toArray(new String[0]))); } - }); - } + }); + } private void getDialogValues(MultiInputDialog dialog) { - this.selLayer = dialog.getLayer(CLAYER); - this.selAttribute = dialog.getText(ATTRIBUTE); - } - - private boolean createPlot(final PlugInContext context, Layer selLayer) throws Exception { + selLayer = dialog.getLayer(CLAYER); + selAttribute = dialog.getText(ATTRIBUTE); + } - FeatureCollection fc = selLayer.getFeatureCollectionWrapper(); - FeatureSchema fs = fc.getFeatureSchema(); - AttributeType type = fs.getAttributeType(selAttribute); - if (type != AttributeType.DOUBLE && type != AttributeType.INTEGER && type != AttributeType.LONG) { + private boolean createPlot(final PlugInContext context, Layer selLayer) + throws Exception { + + final FeatureCollection fc = selLayer.getFeatureCollectionWrapper(); + final FeatureSchema fs = fc.getFeatureSchema(); + final AttributeType type = fs.getAttributeType(selAttribute); + if (type != AttributeType.DOUBLE && type != AttributeType.INTEGER + && type != AttributeType.LONG) { context.getWorkbenchFrame().warnUser(sWrongDataType); return false; } - - double[] data = new double[fc.size()]; - int[] fID = new int[fc.size()]; - int i=0; - for (Feature f : fc.getFeatures()) { - Object val = f.getAttribute(this.selAttribute); - if (val == null) continue; + + final double[] data = new double[fc.size()]; + final int[] fID = new int[fc.size()]; + int i = 0; + for (final Feature f : fc.getFeatures()) { + final Object val = f.getAttribute(selAttribute); + if (val == null) { + continue; + } if (val instanceof Number) { data[i] = ((Number) val).doubleValue(); fID[i] = f.getID(); @@ -187,29 +219,29 @@ i++; } } - double[] data2 = new double[i]; - System.arraycopy(data,0,data2,0,i); - int[] fID2 = new int[i]; - System.arraycopy(fID,0,fID2,0,i); + final double[] data2 = new double[i]; + System.arraycopy(data, 0, data2, 0, i); + final int[] fID2 = new int[i]; + System.arraycopy(fID, 0, fID2, 0, i); - final Plot2DPanelOJ plot = new Plot2DPanelOJ(); - plot.addBarPlotOJ(this.selAttribute, data2, fID2, context, selLayer); + final Plot2DPanelOJ plot = new Plot2DPanelOJ(); + plot.addBarPlotOJ(selAttribute, data2, fID2, context, selLayer); plot.plotToolBar.setVisible(true); plot.setAxisLabel(0, sNthfeature); - plot.setAxisLabel(1, this.selAttribute); - + plot.setAxisLabel(1, selAttribute); + + AdditionalResults.addAdditionalResultAndShow(sBarPlot, plot); // FrameView fv = new FrameView(plot); // -- replace the upper line by: - JInternalFrame frame = new JInternalFrame(this.sBarPlot); - frame.setLayout(new BorderLayout()); - frame.add(plot, BorderLayout.CENTER); - frame.setClosable(true); - frame.setResizable(true); - frame.setMaximizable(true); - frame.setSize(450, 450); - frame.setVisible(true); - - context.getWorkbenchFrame().addInternalFrame(frame); + /* + * JInternalFrame frame = new JInternalFrame(this.sBarPlot); + * frame.setLayout(new BorderLayout()); frame.add(plot, + * BorderLayout.CENTER); frame.setClosable(true); + * frame.setResizable(true); frame.setMaximizable(true); + * frame.setSize(450, 450); frame.setVisible(true); + * + * context.getWorkbenchFrame().addInternalFrame(frame); + */ return true; } Modified: core/trunk/src/org/openjump/core/ui/plugin/tools/statistics/CreateHistogramPlugIn.java =================================================================== --- core/trunk/src/org/openjump/core/ui/plugin/tools/statistics/CreateHistogramPlugIn.java 2018-03-12 15:33:11 UTC (rev 5711) +++ core/trunk/src/org/openjump/core/ui/plugin/tools/statistics/CreateHistogramPlugIn.java 2018-03-14 09:05:39 UTC (rev 5712) @@ -27,7 +27,6 @@ */ package org.openjump.core.ui.plugin.tools.statistics; -import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.List; @@ -34,10 +33,9 @@ import javax.swing.DefaultComboBoxModel; import javax.swing.JComboBox; -import javax.swing.JInternalFrame; -import com.vividsolutions.jump.workbench.ui.*; import org.openjump.core.ui.plot.Plot2DPanelOJ; +import org.openjump.sextante.gui.additionalResults.AdditionalResults; import com.vividsolutions.jump.I18N; import com.vividsolutions.jump.feature.AttributeType; @@ -52,160 +50,192 @@ import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck; import com.vividsolutions.jump.workbench.plugin.PlugInContext; import com.vividsolutions.jump.workbench.plugin.ThreadedPlugIn; +import com.vividsolutions.jump.workbench.ui.AttributeTypeFilter; +import com.vividsolutions.jump.workbench.ui.GUIUtil; +import com.vividsolutions.jump.workbench.ui.GenericNames; +import com.vividsolutions.jump.workbench.ui.MenuNames; +import com.vividsolutions.jump.workbench.ui.MultiInputDialog; import com.vividsolutions.jump.workbench.ui.plugin.FeatureInstaller; /** * - * created on 19.10.2007 - * @author sstein + * created on 19.10.2007 + * + * @author sstein */ -public class CreateHistogramPlugIn extends AbstractPlugIn implements ThreadedPlugIn{ +public class CreateHistogramPlugIn extends AbstractPlugIn implements + ThreadedPlugIn { private String sHistogram = "Histogram"; private String sCount = "count"; - private String T2 ="number of ranges"; + private String T2 = "number of ranges"; private String CLAYER = "select layer"; private String ATTRIBUTE = "select attribute"; private Layer selLayer = null; - private int ranges = 7; + private int ranges = 7; private String selAttribute = null; private String sName = "Create Histogram Plot"; private String sWrongDataType = "Wrong datatype of chosen attribute"; /** - * this method is called on the startup by JUMP/OpenJUMP. - * We set here the menu entry for calling the function. + * this method is called on the startup by JUMP/OpenJUMP. We set here the + * menu entry for calling the function. */ + @Override public void initialize(PlugInContext context) throws Exception { - - + ATTRIBUTE = GenericNames.SELECT_ATTRIBUTE; - T2 = I18N.get("org.openjump.core.ui.plugin.tools.statistics.CreateHistogramPlugIn.Number-of-ranges"); + T2 = I18N + .get("org.openjump.core.ui.plugin.tools.statistics.CreateHistogramPlugIn.Number-of-ranges"); CLAYER = GenericNames.SELECT_LAYER; - sHistogram = I18N.get("org.openjump.core.ui.plugin.tools.statistics.CreateHistogramPlugIn.Histogram-Plot"); - sCount = I18N.get("org.openjump.core.ui.plugin.tools.statistics.CreateHistogramPlugIn.count"); - sName = I18N.get("org.openjump.core.ui.plugin.tools.statistics.CreateHistogramPlugIn"); - sWrongDataType = I18N.get("org.openjump.core.ui.plugin.tools.statistics.CreateBarPlotPlugIn.Wrong-datatype-of-chosen-attribute"); - - FeatureInstaller featureInstaller = new FeatureInstaller(context.getWorkbenchContext()); - featureInstaller.addMainMenuPlugin( - this, - new String[] {MenuNames.TOOLS, MenuNames.STATISTICS, MenuNames.PLOT }, - this.sName + "...", - false, //checkbox - null, //icon - createEnableCheck(context.getWorkbenchContext())); + sHistogram = I18N + .get("org.openjump.core.ui.plugin.tools.statistics.CreateHistogramPlugIn.Histogram-Plot"); + sCount = I18N + .get("org.openjump.core.ui.plugin.tools.statistics.CreateHistogramPlugIn.count"); + sName = I18N + .get("org.openjump.core.ui.plugin.tools.statistics.CreateHistogramPlugIn"); + sWrongDataType = I18N + .get("org.openjump.core.ui.plugin.tools.statistics.CreateBarPlotPlugIn.Wrong-datatype-of-chosen-attribute"); + + final FeatureInstaller featureInstaller = new FeatureInstaller( + context.getWorkbenchContext()); + featureInstaller.addMainMenuPlugin(this, new String[] { + MenuNames.TOOLS, MenuNames.STATISTICS, MenuNames.PLOT }, sName + + "...", false, // checkbox + null, // icon + createEnableCheck(context.getWorkbenchContext())); } - - + /** * This method is used to define when the menu entry is activated or - * disabled. In this example we allow the menu entry to be usable only - * if one layer exists. + * disabled. In this example we allow the menu entry to be usable only if + * one layer exists. */ - public static MultiEnableCheck createEnableCheck(WorkbenchContext workbenchContext) { - EnableCheckFactory checkFactory = new EnableCheckFactory(workbenchContext); + public static MultiEnableCheck createEnableCheck( + WorkbenchContext workbenchContext) { + final EnableCheckFactory checkFactory = new EnableCheckFactory( + workbenchContext); return new MultiEnableCheck() - .add(checkFactory.createAtLeastNLayersMustExistCheck(1)) - .add(checkFactory.createWindowWithAssociatedTaskFrameMustBeActiveCheck()); + .add(checkFactory.createAtLeastNLayersMustExistCheck(1)) + .add(checkFactory + .createWindowWithAssociatedTaskFrameMustBeActiveCheck()); } - + /** * this function is called by JUMP/OpenJUMP if one clicks on the menu entry. - * It is called before the "run" method and useful to do all the GUI /user-input things - * In this example we call two additional methods {@link #setDialogValues(MultiInputDialog, PlugInContext)} - * and {@link #getDialogValues(MultiInputDialog)} to obtain the Layer and the buffer radius by the user. + * It is called before the "run" method and useful to do all the GUI + * /user-input things In this example we call two additional methods + * {@link #setDialogValues(MultiInputDialog, PlugInContext)} and + * {@link #getDialogValues(MultiInputDialog)} to obtain the Layer and the + * buffer radius by the user. */ - public boolean execute(PlugInContext context) throws Exception{ - - this.reportNothingToUndoYet(context); - - MultiInputDialog dialog = new MultiInputDialog( - context.getWorkbenchFrame(),sName, true); - this.setDialogValues(dialog, context); - GUIUtil.centreOnWindow(dialog); - dialog.setVisible(true); - if (! dialog.wasOKPressed()) { return false; } - this.getDialogValues(dialog); - + @Override + public boolean execute(PlugInContext context) throws Exception { + + reportNothingToUndoYet(context); + + final MultiInputDialog dialog = new MultiInputDialog( + context.getWorkbenchFrame(), sName, true); + setDialogValues(dialog, context); + GUIUtil.centreOnWindow(dialog); + dialog.setVisible(true); + if (!dialog.wasOKPressed()) { + return false; + } + getDialogValues(dialog); + return true; } - - public void run(TaskMonitor monitor, PlugInContext context) throws Exception { - createHistogram(context, this.selLayer); - - } - - private void setDialogValues(final MultiInputDialog dialog, PlugInContext context) - { - dialog.addLayerComboBox(CLAYER, context.getCandidateLayer(0), context.getLayerManager()); - - List<String> list = AttributeTypeFilter.NUMERIC_FILTER.filter(context.getCandidateLayer(0)); - Object val = list.size()>0?list.iterator().next():null; - final JComboBox<String> jcb_attribute = dialog.addComboBox(ATTRIBUTE, val, list, ATTRIBUTE); - if (list.size() == 0) jcb_attribute.setEnabled(false); - dialog.addIntegerField(T2, this.ranges, 6, T2); - + + @Override + public void run(TaskMonitor monitor, PlugInContext context) + throws Exception { + createHistogram(context, selLayer); + + } + + private void setDialogValues(final MultiInputDialog dialog, + PlugInContext context) { + dialog.addLayerComboBox(CLAYER, context.getCandidateLayer(0), + context.getLayerManager()); + + final List<String> list = AttributeTypeFilter.NUMERIC_FILTER + .filter(context.getCandidateLayer(0)); + final Object val = list.size() > 0 ? list.iterator().next() : null; + final JComboBox<String> jcb_attribute = dialog.addComboBox(ATTRIBUTE, + val, list, ATTRIBUTE); + if (list.size() == 0) { + jcb_attribute.setEnabled(false); + } + dialog.addIntegerField(T2, ranges, 6, T2); + dialog.getComboBox(CLAYER).addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { - List<String> list = AttributeTypeFilter.NUMERIC_FILTER.filter(dialog.getLayer(CLAYER)); + final List<String> list = AttributeTypeFilter.NUMERIC_FILTER + .filter(dialog.getLayer(CLAYER)); if (list.size() == 0) { - jcb_attribute.setModel(new DefaultComboBoxModel<>(new String[0])); + jcb_attribute.setModel(new DefaultComboBoxModel<>( + new String[0])); jcb_attribute.setEnabled(false); } - jcb_attribute.setModel(new DefaultComboBoxModel<>(list.toArray(new String[0]))); + jcb_attribute.setModel(new DefaultComboBoxModel<>(list + .toArray(new String[0]))); } - }); - } + }); + } private void getDialogValues(MultiInputDialog dialog) { - this.ranges = dialog.getInteger(T2); - this.selLayer = dialog.getLayer(CLAYER); - this.selAttribute = dialog.getText(ATTRIBUTE); - } - - private boolean createHistogram(final PlugInContext context, Layer selLayer) throws Exception { + ranges = dialog.getInteger(T2); + selLayer = dialog.getLayer(CLAYER); + selAttribute = dialog.getText(ATTRIBUTE); + } - FeatureCollection fc = selLayer.getFeatureCollectionWrapper(); - FeatureSchema fs = fc.getFeatureSchema(); - AttributeType type = fs.getAttributeType(selAttribute); - if (type != AttributeType.DOUBLE && type != AttributeType.INTEGER && type != AttributeType.LONG) { - context.getWorkbenchFrame().warnUser(sWrongDataType); + private boolean createHistogram(final PlugInContext context, Layer selLayer) + throws Exception { + + final FeatureCollection fc = selLayer.getFeatureCollectionWrapper(); + final FeatureSchema fs = fc.getFeatureSchema(); + final AttributeType type = fs.getAttributeType(selAttribute); + if (type != AttributeType.DOUBLE && type != AttributeType.INTEGER + && type != AttributeType.LONG) { + context.getWorkbenchFrame().warnUser(sWrongDataType); return false; } - - double[] data = new double[fc.size()]; - int i=0; - for (Feature f : fc.getFeatures()) { - Object val = f.getAttribute(this.selAttribute); + + final double[] data = new double[fc.size()]; + int i = 0; + for (final Feature f : fc.getFeatures()) { + final Object val = f.getAttribute(selAttribute); if (val instanceof Number) { data[i] = ((Number) val).doubleValue(); i++; } } - double[] data2 = new double[i]; - System.arraycopy(data,0,data2,0,i); + final double[] data2 = new double[i]; + System.arraycopy(data, 0, data2, 0, i); final Plot2DPanelOJ plot = new Plot2DPanelOJ(); - plot.addHistogramPlotOJ(selAttribute, data2, ranges, context, selLayer, selAttribute); + plot.addHistogramPlotOJ(selAttribute, data2, ranges, context, selLayer, + selAttribute); plot.plotToolBar.setVisible(true); plot.setAxisLabel(0, selAttribute); plot.setAxisLabel(1, sCount); - + + AdditionalResults.addAdditionalResultAndShow(sHistogram, plot); // FrameView fv = new FrameView(plot); // -- replace the upper line by: - JInternalFrame frame = new JInternalFrame(sHistogram); - frame.setLayout(new BorderLayout()); - frame.add(plot, BorderLayout.CENTER); - frame.setClosable(true); - frame.setResizable(true); - frame.setMaximizable(true); - frame.setSize(450, 450); - frame.setVisible(true); - - context.getWorkbenchFrame().addInternalFrame(frame); + /* + * JInternalFrame frame = new JInternalFrame(sHistogram); + * frame.setLayout(new BorderLayout()); frame.add(plot, + * BorderLayout.CENTER); frame.setClosable(true); + * frame.setResizable(true); frame.setMaximizable(true); + * frame.setSize(450, 450); frame.setVisible(true); + * + * context.getWorkbenchFrame().addInternalFrame(frame); + */ return true; } Modified: core/trunk/src/org/openjump/core/ui/plugin/tools/statistics/CreateScatterPlotPlugIn.java =================================================================== --- core/trunk/src/org/openjump/core/ui/plugin/tools/statistics/CreateScatterPlotPlugIn.java 2018-03-12 15:33:11 UTC (rev 5711) +++ core/trunk/src/org/openjump/core/ui/plugin/tools/statistics/CreateScatterPlotPlugIn.java 2018-03-14 09:05:39 UTC (rev 5712) @@ -37,18 +37,15 @@ ***********************************************/ package org.openjump.core.ui.plugin.tools.statistics; -import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.util.Iterator; import java.util.List; import javax.swing.DefaultComboBoxModel; import javax.swing.JComboBox; -import javax.swing.JInternalFrame; -import com.vividsolutions.jump.workbench.ui.*; import org.openjump.core.ui.plot.Plot2DPanelOJ; +import org.openjump.sextante.gui.additionalResults.AdditionalResults; import com.vividsolutions.jump.I18N; import com.vividsolutions.jump.feature.AttributeType; @@ -63,174 +60,213 @@ import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck; import com.vividsolutions.jump.workbench.plugin.PlugInContext; import com.vividsolutions.jump.workbench.plugin.ThreadedPlugIn; +import com.vividsolutions.jump.workbench.ui.AttributeTypeFilter; +import com.vividsolutions.jump.workbench.ui.GUIUtil; +import com.vividsolutions.jump.workbench.ui.GenericNames; +import com.vividsolutions.jump.workbench.ui.MenuNames; +import com.vividsolutions.jump.workbench.ui.MultiInputDialog; import com.vividsolutions.jump.workbench.ui.plugin.FeatureInstaller; -public class CreateScatterPlotPlugIn extends AbstractPlugIn implements ThreadedPlugIn{ +public class CreateScatterPlotPlugIn extends AbstractPlugIn implements + ThreadedPlugIn { private String sScatterPlot = "Scatter-Plot"; - + private String CLAYER = "select layer"; private String ATTRIBUTEA = "Select-attribute-for-east-axis"; private String ATTRIBUTEB = "Select-attribute-for-north-axis"; - private Layer selLayer = null; + private Layer selLayer = null; private FeatureCollection fc = null; private String selAttributeA = null; private String selAttributeB = null; private String sName = "Create Scatter Plot"; private String sWrongDataType = "Wrong datatype of chosen attribute"; - + /** - * this method is called on the startup by JUMP/OpenJUMP. - * We set here the menu entry for calling the function. + * this method is called on the startup by JUMP/OpenJUMP. We set here the + * menu entry for calling the function. */ - public void initialize(PlugInContext context) throws Exception { - - ATTRIBUTEA = I18N.get("org.openjump.core.ui.plugin.tools.statistics.CreateScatterPlotPlugIn.Select-attribute-for-east-axis"); - ATTRIBUTEB = I18N.get("org.openjump.core.ui.plugin.tools.statistics.CreateScatterPlotPlugIn.Select-attribute-for-north-axis"); + @Override + public void initialize(PlugInContext context) throws Exception { + + ATTRIBUTEA = I18N + .get("org.openjump.core.ui.plugin.tools.statistics.CreateScatterPlotPlugIn.Select-attribute-for-east-axis"); + ATTRIBUTEB = I18N + .get("org.openjump.core.ui.plugin.tools.statistics.CreateScatterPlotPlugIn.Select-attribute-for-north-axis"); CLAYER = GenericNames.SELECT_LAYER; - sScatterPlot = I18N.get("org.openjump.core.ui.plugin.tools.statistics.CreateScatterPlotPlugIn.Scatter-Plot"); - sName = I18N.get("org.openjump.core.ui.plugin.tools.statistics.CreateScatterPlotPlugIn"); - sWrongDataType = I18N.get("org.openjump.core.ui.plugin.tools.statistics.CreateBarPlotPlugIn.Wrong-datatype-of-chosen-attribute"); - - FeatureInstaller featureInstaller = new FeatureInstaller(context.getWorkbenchContext()); - featureInstaller.addMainMenuPlugin( - this, - new String[] {MenuNames.TOOLS, MenuNames.STATISTICS, MenuNames.PLOT }, - this.sName + "...", - false, //checkbox - null, //icon - createEnableCheck(context.getWorkbenchContext())); - } - + sScatterPlot = I18N + .get("org.openjump.core.ui.plugin.tools.statistics.CreateScatterPlotPlugIn.Scatter-Plot"); + sName = I18N + .get("org.openjump.core.ui.plugin.tools.statistics.CreateScatterPlotPlugIn"); + sWrongDataType = I18N + .get("org.openjump.core.ui.plugin.tools.statistics.CreateBarPlotPlugIn.Wrong-datatype-of-chosen-attribute"); + + final FeatureInstaller featureInstaller = new FeatureInstaller( + context.getWorkbenchContext()); + featureInstaller.addMainMenuPlugin(this, new String[] { + MenuNames.TOOLS, MenuNames.STATISTICS, MenuNames.PLOT }, sName + + "...", false, // checkbox + null, // icon + createEnableCheck(context.getWorkbenchContext())); + } + /** * This method is used to define when the menu entry is activated or - * disabled. In this example we allow the menu entry to be usable only - * if one layer exists. + * disabled. In this example we allow the menu entry to be usable only if + * one layer exists. */ - public static MultiEnableCheck createEnableCheck(WorkbenchContext workbenchContext) { - EnableCheckFactory checkFactory = new EnableCheckFactory(workbenchContext); + public static MultiEnableCheck createEnableCheck( + WorkbenchContext workbenchContext) { + final EnableCheckFactory checkFactory = new EnableCheckFactory( + workbenchContext); return new MultiEnableCheck() - .add(checkFactory.createAtLeastNLayersMustExistCheck(1)) - .add(checkFactory.createWindowWithAssociatedTaskFrameMustBeActiveCheck()); + .add(checkFactory.createAtLeastNLayersMustExistCheck(1)) + .add(checkFactory + .createWindowWithAssociatedTaskFrameMustBeActiveCheck()); } - + /** * this function is called by JUMP/OpenJUMP if one clicks on the menu entry. - * It is called before the "run" method and useful to do all the GUI /user-input things - * In this example we call two additional methods {@link #setDialogValues(MultiInputDialog, PlugInContext)} - * and {@link #getDialogValues(MultiInputDialog)} to obtain the Layer and the buffer radius by the user. + * It is called before the "run" method and useful to do all the GUI + * /user-input things In this example we call two additional methods + * {@link #setDialogValues(MultiInputDialog, PlugInContext)} and + * {@link #getDialogValues(MultiInputDialog)} to obtain the Layer and the + * buffer radius by the user. */ - public boolean execute(PlugInContext context) throws Exception{ - - this.reportNothingToUndoYet(context); - - MultiInputDialog dialog = new MultiInputDialog( + @Override + public boolean execute(PlugInContext context) throws Exception { + + reportNothingToUndoYet(context); + + final MultiInputDialog dialog = new MultiInputDialog( context.getWorkbenchFrame(), sName, true); - this.setDialogValues(dialog, context); - GUIUtil.centreOnWindow(dialog); - dialog.setVisible(true); - if (! dialog.wasOKPressed()) { return false; } - this.getDialogValues(dialog); - + setDialogValues(dialog, context); + GUIUtil.centreOnWindow(dialog); + dialog.setVisible(true); + if (!dialog.wasOKPressed()) { + return false; + } + getDialogValues(dialog); + return true; } - - public void run(TaskMonitor monitor, PlugInContext context) throws Exception { - createPlot(context, this.selLayer); - - } - - private void setDialogValues(final MultiInputDialog dialog, PlugInContext context) { - dialog.addLayerComboBox(CLAYER, context.getCandidateLayer(0), context.getLayerManager()); - - List<String> attributes = AttributeTypeFilter.NUMERIC_FILTER.filter(context.getCandidateLayer(0)); - String attA = attributes.size()>0?attributes.get(0):null; - String attB = attributes.size()>0?attributes.get(0):null; - final JComboBox<String> jcb_attributeA = dialog.addComboBox(ATTRIBUTEA, attA, attributes ,ATTRIBUTEA); - if (attributes.size() == 0) jcb_attributeA.setEnabled(false); - final JComboBox<String> jcb_attributeB = dialog.addComboBox(ATTRIBUTEB, attB, attributes, ATTRIBUTEB); - if (attributes.size() == 0) jcb_attributeB.setEnabled(false); - + @Override + public void run(TaskMonitor monitor, PlugInContext context) + throws Exception { + createPlot(context, selLayer); + + } + + private void setDialogValues(final MultiInputDialog dialog, + PlugInContext context) { + + dialog.addLayerComboBox(CLAYER, context.getCandidateLayer(0), + context.getLayerManager()); + + final List<String> attributes = AttributeTypeFilter.NUMERIC_FILTER + .filter(context.getCandidateLayer(0)); + final String attA = attributes.size() > 0 ? attributes.get(0) : null; + final String attB = attributes.size() > 0 ? attributes.get(0) : null; + final JComboBox<String> jcb_attributeA = dialog.addComboBox(ATTRIBUTEA, + attA, attributes, ATTRIBUTEA); + if (attributes.size() == 0) { + jcb_attributeA.setEnabled(false); + } + final JComboBox<String> jcb_attributeB = dialog.addComboBox(ATTRIBUTEB, + attB, attributes, ATTRIBUTEB); + if (attributes.size() == 0) { + jcb_attributeB.setEnabled(false); + } + dialog.getComboBox(CLAYER).addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { - List<String> list = AttributeTypeFilter.NUMERIC_FILTER.filter(dialog.getLayer(CLAYER)); + final List<String> list = AttributeTypeFilter.NUMERIC_FILTER + .filter(dialog.getLayer(CLAYER)); if (list.size() == 0) { - jcb_attributeA.setModel(new DefaultComboBoxModel<>(new String[0])); + jcb_attributeA.setModel(new DefaultComboBoxModel<>( + new String[0])); jcb_attributeA.setEnabled(false); } - jcb_attributeA.setModel(new DefaultComboBoxModel<>(list.toArray(new String[0]))); - } + jcb_attributeA.setModel(new DefaultComboBoxModel<>(list + .toArray(new String[0]))); + } }); dialog.getComboBox(CLAYER).addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { - List<String> list = AttributeTypeFilter.NUMERIC_FILTER.filter(dialog.getLayer(CLAYER)); + final List<String> list = AttributeTypeFilter.NUMERIC_FILTER + .filter(dialog.getLayer(CLAYER)); if (list.size() == 0) { - jcb_attributeB.setModel(new DefaultComboBoxModel<>(new String[0])); + jcb_attributeB.setModel(new DefaultComboBoxModel<>( + new String[0])); jcb_attributeB.setEnabled(false); } - jcb_attributeB.setModel(new DefaultComboBoxModel<>(list.toArray(new String[0]))); - } - }); + jcb_attributeB.setModel(new DefaultComboBoxModel<>(list + .toArray(new String[0]))); + } + }); - } + } private void getDialogValues(MultiInputDialog dialog) { - this.selLayer = dialog.getLayer(CLAYER); - this.fc = this.selLayer.getFeatureCollectionWrapper(); - this.selAttributeA = dialog.getText(ATTRIBUTEA); - this.selAttributeB = dialog.getText(ATTRIBUTEB); - } - - private boolean createPlot(final PlugInContext context, Layer selLayer) throws Exception { - - FeatureSchema fs = this.fc.getFeatureSchema(); - AttributeType typeA = fs.getAttributeType(this.selAttributeA); - AttributeType typeB = fs.getAttributeType(this.selAttributeB); + selLayer = dialog.getLayer(CLAYER); + fc = selLayer.getFeatureCollectionWrapper(); + selAttributeA = dialog.getText(ATTRIBUTEA); + selAttributeB = dialog.getText(ATTRIBUTEB); + } + + private boolean createPlot(final PlugInContext context, Layer selLayer) + throws Exception { + + final FeatureSchema fs = fc.getFeatureSchema(); + final AttributeType typeA = fs.getAttributeType(selAttributeA); + final AttributeType typeB = fs.getAttributeType(selAttributeB); if ((typeA != AttributeType.DOUBLE && typeA != AttributeType.INTEGER && typeA != AttributeType.LONG) - || - (typeB != AttributeType.DOUBLE && typeB != AttributeType.INTEGER && typeB != AttributeType.LONG)) { - context.getWorkbenchFrame().warnUser(sWrongDataType); + || (typeB != AttributeType.DOUBLE + && typeB != AttributeType.INTEGER && typeB != AttributeType.LONG)) { + context.getWorkbenchFrame().warnUser(sWrongDataType); return false; } - - double[][] data = new double[2][this.fc.size()]; - int[] fID = new int[this.fc.size()]; - int i=0; - for (Feature f : fc.getFeatures()) { + + final double[][] data = new double[2][fc.size()]; + final int[] fID = new int[fc.size()]; + int i = 0; + for (final Feature f : fc.getFeatures()) { fID[i] = f.getID(); - Object valA = f.getAttribute(this.selAttributeA); - Object valB = f.getAttribute(this.selAttributeB); + final Object valA = f.getAttribute(selAttributeA); + final Object valB = f.getAttribute(selAttributeB); if (valA instanceof Number) { // triplecheck as typeA is numeric - data[0][i] = ((Number)valA).doubleValue(); + data[0][i] = ((Number) valA).doubleValue(); } if (valB instanceof Number) { // triplecheck as typeB is numeric - data[1][i] = ((Number)valB).doubleValue(); + data[1][i] = ((Number) valB).doubleValue(); } i++; - } + } final Plot2DPanelOJ plot = new Plot2DPanelOJ(); plot.addScatterPlotOJ(sScatterPlot, data, fID, context, selLayer); plot.plotToolBar.setVisible(true); - plot.setAxisLabel(0, this.selAttributeA); - plot.setAxisLabel(1, this.selAttributeB); - + plot.setAxisLabel(0, selAttributeA); + plot.setAxisLabel(1, selAttributeB); + + AdditionalResults.addAdditionalResultAndShow(sScatterPlot, plot); // FrameView fv = new FrameView(plot); // -- replace the upper line by: - JInternalFrame frame = new JInternalFrame(sScatterPlot); - frame.setLayout(new BorderLayout()); - frame.add(plot, BorderLayout.CENTER); - frame.setClosable(true); - frame.setResizable(true); - frame.setMaximizable(true); - frame.setSize(450, 450); - frame.setVisible(true); - - context.getWorkbenchFrame().addInternalFrame(frame); + /* + * JInternalFrame frame = new JInternalFrame(sScatterPlot); + * frame.setLayout(new BorderLayout()); frame.add(plot, + * BorderLayout.CENTER); frame.setClosable(true); + * frame.setResizable(true); frame.setMaximizable(true); + * frame.setSize(450, 450); frame.setVisible(true); + * + * context.getWorkbenchFrame().addInternalFrame(frame); + */ return true; } - + } Modified: core/trunk/src/org/openjump/sextante/gui/additionalResults/AdditionalResultsFrame.java =================================================================== --- core/trunk/src/org/openjump/sextante/gui/additionalResults/AdditionalResultsFrame.java 2018-03-12 15:33:11 UTC (rev 5711) +++ core/trunk/src/org/openjump/sextante/gui/additionalResults/AdditionalResultsFrame.java 2018-03-14 09:05:39 UTC (rev 5712) @@ -109,8 +109,8 @@ private JMenuItem menuItemRemove; private JMenuItem menuItemRename; - private static int FILE_BROWSER_WIDTH = 800; - private static int FILE_BROWSER_HEIGHT = 600; + private static int FILE_BROWSER_WIDTH = 600; + private static int FILE_BROWSER_HEIGHT = 400; private static String LAST_DIR = null; // --da rimuovere @@ -126,7 +126,7 @@ setIconifiable(true); setMaximizable(true); - setSize(800, 500); + setSize(900, 700); setLayer(JLayeredPane.MODAL_LAYER); } @@ -148,15 +148,16 @@ } try { { - setPreferredSize(new java.awt.Dimension(700, 350)); - this.setSize(new java.awt.Dimension(700, 350)); + setPreferredSize(new Dimension(900, 450)); + this.setSize(new Dimension(900, 450)); { jSplitPane = new JSplitPane(); - + jSplitPane.setDividerSize(9); + jSplitPane.setContinuousLayout(true); + jSplitPane.setOneTouchExpandable(true); + jSplitPane.setDividerLocation(200); panel.add(jSplitPane, BorderLayout.CENTER); - // --Da rimuovere - // panel.add(okCancelApplyPanel, BorderLayout.SOUTH); panel.add(getOKSavePanel(), BorderLayout.SOUTH); { @@ -203,7 +204,7 @@ ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); jScrollPane.setPreferredSize(new Dimension(200, 450)); - jScrollPane.setMinimumSize(new Dimension(200, 450)); + // jScrollPane.setMinimumSize(new Dimension(200, 450)); jScrollPane.setMaximumSize(new Dimension(200, 450)); } { @@ -363,9 +364,17 @@ protected void save() { final JFileChooser fc = new GUIUtil.FileChooserWithOverwritePrompting(); + // fc.setPreferredSize(new Dimension(FILE_BROWSER_WIDTH, + // FILE_BROWSER_HEIGHT)); final File filedir = new File((String) PersistentBlackboardPlugIn.get( JUMPWorkbench.getInstance().getContext()).get( FILE_CHOOSER_DIRECTORY_KEY)); + FileNameExtensionFilter filter; + if (LAST_DIR != null) { + fc.setCurrentDirectory(new File(LAST_DIR)); + } else { + fc.setCurrentDirectory(filedir); + } final File file; if (m_Path != null) { try { @@ -378,14 +387,6 @@ final FeatureCollectionPanel panel = (FeatureCollectionPanel) c; final FeatureCollection fcoll = panel .getFeatureCollection(); - fc.setPreferredSize(new Dimension(FILE_BROWSER_WIDTH, - FILE_BROWSER_HEIGHT)); - if (LAST_DIR != null) { - fc.setCurrentDirectory(new File(LAST_DIR)); - } else { - fc.setCurrentDirectory(filedir); - } - FileNameExtensionFilter filter; if (LayerableUtil.isMixedGeometryType(fcoll)) { filter = new FileNameExtensionFilter("JML", "jml"); } else { @@ -394,8 +395,8 @@ fc.setFileFilter(filter); fc.addChoosableFileFilter(filter); final int returnVal = fc.showSaveDialog(this); - FILE_BROWSER_WIDTH = fc.getWidth(); - FILE_BROWSER_HEIGHT = fc.getHeight(); + // FILE_BROWSER_WIDTH = fc.getWidth(); + // FILE_BROWSER_HEIGHT = fc.getHeight(); if (returnVal == JFileChooser.APPROVE_OPTION) { if (LayerableUtil.isMixedGeometryType(fcoll)) { file = new File(fc.getSelectedFile() + ".jml"); @@ -406,23 +407,13 @@ } saved(file); } - } else - - if (c instanceof JScrollPane) { + } else if (c instanceof JScrollPane) { final JScrollPane pane = (JScrollPane) c; final Component view = pane.getViewport().getView(); if (view instanceof JTextPane) { final JTextPane text = (JTextPane) pane.getViewport() .getView(); - fc.setPreferredSize(new Dimension(FILE_BROWSER_WIDTH, - FILE_BROWSER_HEIGHT)); - if (LAST_DIR != null) { - fc.setCurrentDirectory(new File(LAST_DIR)); - } else { - fc.setCurrentDirectory(filedir); - } - final FileNameExtensionFilter filter = new FileNameExtensionFilter( - "HTML", "html"); + filter = new FileNameExtensionFilter("HTML", "html"); fc.setFileFilter(filter); fc.addChoosableFileFilter(filter); final int returnVal = fc.showSaveDialog(this); @@ -446,15 +437,7 @@ } } else if (view instanceof JLabel) { final String text = ((JLabel) view).getText(); - fc.setPreferredSize(new Dimension(FILE_BROWSER_WIDTH, - FILE_BROWSER_HEIGHT)); - if (LAST_DIR != null) { - fc.setCurrentDirectory(new File(LAST_DIR)); - } else { - fc.setCurrentDirectory(filedir); - } - final FileNameExtensionFilter filter = new FileNameExtensionFilter( - "HTML", "html"); + filter = new FileNameExtensionFilter("HTML", "html"); fc.setFileFilter(filter); fc.addChoosableFileFilter(filter); final int returnVal = fc.showSaveDialog(this); @@ -478,15 +461,7 @@ } } else if (view instanceof JTextArea) { final String text = ((JLabel) view).getText(); - fc.setPreferredSize(new Dimension(FILE_BROWSER_WIDTH, - FILE_BROWSER_HEIGHT)); - if (LAST_DIR != null) { - fc.setCurrentDirectory(new File(LAST_DIR)); - } else { - fc.setCurrentDirectory(filedir); - } - final FileNameExtensionFilter filter = new FileNameExtensionFilter( - "HTML", "html"); + filter = new FileNameExtensionFilter("HTML", "html"); fc.setFileFilter(filter); fc.addChoosableFileFilter(filter); final int returnVal = fc.showSaveDialog(this); @@ -511,15 +486,8 @@ } else if (view instanceof JTable) { final JTable table = (JTable) pane.getViewport() .getView(); - fc.setPreferredSize(new Dimension(FILE_BROWSER_WIDTH, - FILE_BROWSER_HEIGHT)); - if (LAST_DIR != null) { - fc.setCurrentDirectory(new File(LAST_DIR)); - } else { - fc.setCurrentDirectory(filedir); - } - final FileNameExtensionFilter filter = new FileNameExtensionFilter( - "Comma-Separated Values (csv)", "cvs"); + filter = new FileNameExtensionFilter( + "Comma-Separated Values (csv)", "csv"); fc.setFileFilter(filter); fc.addChoosableFileFilter(filter); final int returnVal = fc.showSaveDialog(this); @@ -559,15 +527,20 @@ } } else if (c instanceof PlotPanel) { final PlotPanel panel = (PlotPanel) c; - fc.setPreferredSize(new Dimension(FILE_BROWSER_WIDTH, - FILE_BROWSER_HEIGHT)); - if (LAST_DIR != null) { - fc.setCurrentDirectory(new File(LAST_DIR)); - } else { - fc.setCurrentDirectory(filedir); + // final JFileChooser chooser = + // SaveGUI.getFileChooser(panel); + // chooser.showSaveDialog(this); + + filter = new FileNameExtensionFilter( + "Portable Network Graphics (png)", "png"); + final FileNameExtensionFilter filter2 = new FileNameExtensionFilter( + "Drawing Interchange Format(dxf)", "dxf"); + + if (oad.getDescription() + .contains( + I18N.get("org.openjump.core.ui.plugin.raster.ProfileGraphTool.Profile-Plot"))) { + fc.setFileFilter(filter2); } - final FileNameExtensionFilter filter = new FileNameExtensionFilter( - "Portable Network Graphics (png)", "png"); fc.setFileFilter(filter); fc.addChoosableFileFilter(filter); final int returnVal = fc.showSaveDialog(this); @@ -574,22 +547,21 @@ FILE_BROWSER_WIDTH = fc.getWidth(); FILE_BROWSER_HEIGHT = fc.getHeight(); if (returnVal == JFileChooser.APPROVE_OPTION) { - file = new File(fc.getSelectedFile() + ".png"); - LAST_DIR = file.getParent(); - panel.toGraphicFile(file); - saved(file); + if (fc.getFileFilter().equals(filter)) { + file = new File(fc.getSelectedFile() + ".png"); + LAST_DIR = file.getParent(); + panel.toGraphicFile(file); + saved(file); + } else if (fc.getFileFilter().equals(filter2)) { + + JUMPWorkbench.getInstance().getFrame() + .warnUser("Test: not yet implemented"); + } } + } else if (c instanceof JTable) { final JTable table = (JTable) c; - - fc.setPreferredSize(new Dimension(FILE_BROWSER_WIDTH, - FILE_BROWSER_HEIGHT)); - if (LAST_DIR != null) { - fc.setCurrentDirectory(new File(LAST_DIR)); - } else { - fc.setCurrentDirectory(filedir); - } - final FileNameExtensionFilter filter = new FileNameExtensionFilter( + filter = new FileNameExtensionFilter( "Comma-Separated Values (csv)", "cvs"); fc.setFileFilter(filter); fc.addChoosableFileFilter(filter); @@ -630,16 +602,7 @@ } else if (c instanceof HTMLPanel) { final HTMLPanel panel = (HTMLPanel) c; final String text = panel.lastString(); - fc.setPreferredSize(new Dimension(FILE_BROWSER_WIDTH, - FILE_BROWSER_HEIGHT)); - if (LAST_DIR != null) { - fc.setCurrentDirectory(new File(LAST_DIR)); - } else { - fc.setCurrentDirectory(filedir); - } - - final FileNameExtensionFilter filter = new FileNameExtensionFilter( - "HTML", "html"); + filter = new FileNameExtensionFilter("HTML", "html"); fc.setFileFilter(filter); fc.addChoosableFileFilter(filter); final int returnVal = fc.showSaveDialog(this); @@ -668,14 +631,7 @@ BufferedImage.TYPE_INT_RGB); final Graphics2D g = bi.createGraphics(); panel.paint(g); - fc.setPreferredSize(new Dimension(FILE_BROWSER_WIDTH, - FILE_BROWSER_HEIGHT)); - if (LAST_DIR != null) { - fc.setCurrentDirectory(new File(LAST_DIR)); - } else { - fc.setCurrentDirectory(filedir); - } - final FileNameExtensionFilter filter = new FileNameExtensionFilter( + filter = new FileNameExtensionFilter( "Portable Network Graphics (png)", "png"); fc.setFileFilter(filter); fc.addChoosableFileFilter(filter); ------------------------------------------------------------------------------ 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