public boolean execute(PlugInContext context) throws Exception {
   Collection<Layer> layersWithoutDataSource = layersWithoutDataSource(context.getTask());
   if (layersWithoutDataSource.size() == 0) {
     context.getWorkbenchFrame().warnUser(WARN_USER);
     return false;
   } else {
     int ret = fileChooser.showSaveDialog(context.getWorkbenchFrame());
     if (ret == JFileChooser.APPROVE_OPTION) {
       return execute(context, layersWithoutDataSource, fileChooser.getSelectedFile());
     }
   }
   return false;
 }
  public boolean execute(PlugInContext context) throws Exception {
    if (context.getLayerViewPanel() == null) {
      return false;
    }
    try {
      if (app.getBlackboard().get("temporalincidents") != null)
        app.getBlackboard().put("temporalincidents", new ArrayList<IdEdgeNetworkBean>());

      // JOptionPane.showMessageDialog(app.getMainFrame(),I18N.get("temporalIncidents","routeengine.temporalincidents.remove.removed"));
    } catch (Exception e) {
      context
          .getLayerViewPanel()
          .getContext()
          .warnUser(I18N.get("temporalIncidents", "routeengine.temporalincidents.remove.error"));
      return false;
    }
    JOptionPane.showMessageDialog(
        context.getWorkbenchFrame(),
        I18N.get("temporalIncidents", "routeengine.temporalincidents.remove.removed"));
    context
        .getLayerViewPanel()
        .getContext()
        .setStatusMessage(
            I18N.get("temporalIncidents", "routeengine.temporalincidents.remove.removed"));
    return true;
  }
 public boolean execute(PlugInContext context) throws Exception {
   try {
     CursorTool circleTool =
         DrawConstrainedCircleTool.create((LayerNamePanelProxy) context.getActiveInternalFrame());
     context.getLayerViewPanel().setCurrentCursorTool(circleTool);
     return true;
   } catch (Exception e) {
     context.getWorkbenchFrame().warnUser(errorSeeOutputWindow);
     context.getWorkbenchFrame().getOutputFrame().createNewDocument();
     context
         .getWorkbenchFrame()
         .getOutputFrame()
         .addText("DrawConstrainedCircleTool Exception:" + e.toString());
     return false;
   }
 }
  @Override
  public boolean execute(PlugInContext context) throws Exception {
    Blackboard bb = get(context.getWorkbenchContext());
    WorkbenchFrame wbframe = context.getWorkbenchFrame();

    String fileName = (String) bb.get("ArcMapStylePlugin.filename");

    File am2sld = findArcMap2SLD(wbframe, bb);
    if (am2sld == null) {
      return false;
    }

    ProcessBuilder pb = new ProcessBuilder(am2sld.toString());
    pb.start().waitFor(); // unfortunately, the code seems to always be
    // zero

    showMessageDialog(
        wbframe,
        get(
            "org.openjump.core.ui.plugin.style.ImportArcMapStylePlugIn.Must-Select-Location-Of-SLD"),
        get("org.openjump.core.ui.plugin.style.ImportSLDPlugIn.Question"),
        INFORMATION_MESSAGE);

    JFileChooser chooser = new JFileChooser();

    if (fileName != null) {
      chooser.setCurrentDirectory(new File(fileName).getParentFile());
    }

    int res = chooser.showOpenDialog(context.getWorkbenchFrame());
    if (res == APPROVE_OPTION) {
      File f = chooser.getSelectedFile();
      if (!f.exists()) {
        return false;
      }
      bb.put("ArcMapStylePlugin.filename", f.getAbsoluteFile().toString());

      DocumentBuilderFactory dbf = newInstance();
      dbf.setNamespaceAware(true);
      Document doc = dbf.newDocumentBuilder().parse(f);

      importSLD(doc, context);
    }

    return false;
  }
Esempio n. 5
0
 public boolean execute(PlugInContext context) throws Exception {
   ((LayerManagerProxy)
           context.getWorkbenchContext().getWorkbench().getFrame().getActiveInternalFrame())
       .getLayerManager()
       .getUndoableEditReceiver()
       .getUndoManager()
       .undo();
   // Exclude the plug-in's activity from the undo history [Jon Aquino]
   reportNothingToUndoYet(context);
   context.getWorkbenchFrame().getToolBar().updateEnabledState();
   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, I added the
   // new JInternalFrame is added after the addLayer method has been called
   this.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;
     this.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);
     plot = null;
   } else {
     context.getWorkbenchFrame().warnUser(sWarning);
   }
 }
  public boolean execute(PlugInContext context, Collection<Layer> collection, File dir)
      throws Exception {
    MultiInputDialog dialog =
        new MultiInputDialog(context.getWorkbenchFrame(), LAYERS_WITHOUT_DATASOURCE, true);

    String tooltip =
        "<html>"
            + java.util.Arrays.toString(collection.toArray(new Object[0])).replaceAll(",", "<br>")
            + "</html>";

    dialog
        .addSubTitle(
            I18N.getMessage(
                "org.openjump.core.ui.plugin.file.SaveLayersWithoutDataSourcePlugIn.layers-without-datasource",
                new Object[] {new Integer(collection.size())}))
        .setToolTipText(tooltip);
    dialog
        .addLabel(
            I18N.get(
                "org.openjump.core.ui.plugin.file.SaveLayersWithoutDataSourcePlugIn.hover-the-label-to-see-the-list"))
        .setToolTipText(tooltip);
    dialog.addRadioButton(DONOTSAVE, "ACTION", true, "");
    dialog.addRadioButton(SAVEASJML, "ACTION", false, "");
    dialog.addRadioButton(SAVEASSHP, "ACTION", false, "");

    GUIUtil.centreOnWindow(dialog);
    dialog.setVisible(true);
    if (dialog.wasOKPressed()) {
      if (dialog.getBoolean(DONOTSAVE)) {
        return false;
      } else {
        // File dir = FileUtil.removeExtensionIfAny(task);
        dir.mkdir();
        for (Layer layer : collection) {
          String ext = null;
          DataSource dataSource = null;
          if (dialog.getBoolean(SAVEASJML)) {
            ext = "jml";
            dataSource =
                new com.vividsolutions.jump.io.datasource.StandardReaderWriterFileDataSource.JML();
          } else if (dialog.getBoolean(SAVEASSHP)) {
            ext = "shp";
            dataSource =
                new com.vividsolutions.jump.io.datasource.StandardReaderWriterFileDataSource
                    .Shapefile();
          }
          saveLayer(layer, dir, dataSource, ext);
        }
        return true;
      }
    } else return false;
  }
  /**
   * 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.
   */
  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);

    return true;
  }
Esempio n. 9
0
  public boolean execute(final PlugInContext context) throws Exception {
    reportNothingToUndoYet(context);
    try {
      context.getWorkbenchFrame().getOutputFrame().createNewDocument();

      if (!new File(MRSIDDECODE).exists()) {
        context.getWorkbenchFrame().warnUser("Error: see output window");
        context.getWorkbenchFrame().getOutputFrame().addText(MRSIDDECODE + " not installed.");
        return false;
      }

      if (!new File(MRSIDINFO).exists()) {
        context.getWorkbenchFrame().warnUser("Error: see output window");
        context.getWorkbenchFrame().getOutputFrame().addText(MRSIDINFO + " not installed.");
        return false;
      }

      JFileChooser fileChooser = new JFileChooser();
      fileChooser = GUIUtil.createJFileChooserWithExistenceChecking();
      fileChooser.setDialogTitle("Open MrSID file");
      fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
      fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
      fileChooser.setMultiSelectionEnabled(true);
      GUIUtil.removeChoosableFileFilters(fileChooser);
      FileFilter fileFilter = GUIUtil.createFileFilter("MrSID Files", new String[] {"sid"});
      fileChooser.addChoosableFileFilter(fileFilter);
      fileChooser.setFileFilter(fileFilter);

      if (JFileChooser.APPROVE_OPTION == fileChooser.showOpenDialog(context.getWorkbenchFrame())) {
        List imageFilenames = new ArrayList();
        File selectedFile = fileChooser.getSelectedFile();
        File[] files = fileChooser.getSelectedFiles();
        for (int i = 0; i < files.length; i++) {
          String filename = files[i].getCanonicalPath();
          imageFilenames.add(filename);
        }

        final SIDLayer layer = new SIDLayer(context, imageFilenames);
        execute(
            new UndoableCommand(getName()) {
              public void execute() {
                Collection selectedCategories = context.getLayerNamePanel().getSelectedCategories();
                context
                    .getLayerManager()
                    .addLayerable(
                        selectedCategories.isEmpty()
                            ? StandardCategoryNames.WORKING
                            : selectedCategories.iterator().next().toString(),
                        layer);
              }

              public void unexecute() {
                context.getLayerManager().remove(layer);
              }
            },
            context);

        return true;
      } else {
        return false;
      }
    } catch (Exception e) {
      context.getWorkbenchFrame().warnUser("Error: see output window");
      context
          .getWorkbenchFrame()
          .getOutputFrame()
          .addText("AddSIDLayerPlugIn Exception:" + e.toString());
      return false;
    }
  }
Esempio n. 10
0
  public boolean execute(PlugInContext context) throws Exception {
    reportNothingToUndoYet(context);
    context.getWorkbenchFrame().addTaskFrame();

    return true;
  }
  private FeatureDataset classifyAndCreatePlot(TaskMonitor monitor, final PlugInContext context)
      throws Exception {

    monitor.report(this.sCalculateBreaks);
    // =============== get DATA and prepare ==============/
    FeatureSchema fs = this.fc.getFeatureSchema();
    AttributeType type = null;
    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);
      return null;
    }

    int size = getFeatureCollectionSize(this.fc, this.selAttribute, this.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];
    int i = 0;
    for (Iterator iter = fc.iterator(); iter.hasNext(); ) {
      Feature f = (Feature) iter.next();
      if (f.getAttribute(this.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).doubleValue();
      } else if (type == AttributeType.INTEGER) {
        if (val == null) data[i] = 0;
        else data[i] = ((Integer) val).intValue();
      }
      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;
    }

    // =============== 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);
      }
    } 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;
    }

    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
    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];
    }
    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));
      }
    }

    // =============== 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.plotToolBar.setVisible(true);
    plot.setAxisLabel(0, this.selAttribute);
    plot.setAxisLabel(1, this.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;
    }
    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(sAddingField);

    FeatureDataset fd = null;
    ArrayList 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, new Integer(classes[count - 1]));
      outData.add(fcopy);
    }
    fd = new FeatureDataset(targetFSnew);
    fd.addAll(outData);
    return fd;
  }