Package com.mxgraph.view

Examples of com.mxgraph.view.mxGraph


    {
      if (e.getSource() instanceof mxGraphComponent)
      {
        mxGraphComponent graphComponent = (mxGraphComponent) e
            .getSource();
        mxGraph graph = graphComponent.getGraph();
        mxIGraphModel model = graph.getModel();

        Object source = null;
        Object target = null;

        Object[] cells = graph.getSelectionCells();

        for (int i = 0; i < cells.length; i++)
        {
          if (model.isVertex(cells[i]))
          {
            if (source == null)
            {
              source = cells[i];
            }
            else if (target == null)
            {
              target = cells[i];
            }
          }

          if (source != null && target != null)
          {
            break;
          }
        }

        if (source != null && target != null)
        {
          int steps = graph.getChildEdges(graph.getDefaultParent()).length;
          Object[] path = mxGraphAnalysis.getInstance()
              .getShortestPath(graph, source, target,
                  new mxDistanceCostFunction(), steps,
                  directed);
          graph.setSelectionCells(path);
        }
        else
        {
          JOptionPane.showMessageDialog(graphComponent,
              mxResources.get("noSourceAndTargetSelected"));
View Full Code Here


     *
     */
    protected void openVdx(BasicGraphEditor editor, File file,
        Document document)
    {
      mxGraph graph = editor.getGraphComponent().getGraph();

      // Replaces file extension with .mxe
      String filename = file.getName();
      filename = filename.substring(0, filename.length() - 4) + ".mxe";

      if (new File(filename).exists()
          && JOptionPane.showConfirmDialog(editor,
              mxResources.get("overwriteExistingFile")) != JOptionPane.YES_OPTION)
      {
        return;
      }

      ((mxGraphModel) graph.getModel()).clear();
      mxVdxCodec.decode(document, graph);
      editor.getGraphComponent().zoomAndCenter();
      editor.setCurrentFile(new File(lastDir + "/" + filename));
    }
View Full Code Here

     *
     */
    protected void openGD(BasicGraphEditor editor, File file,
        mxGdDocument document)
    {
      mxGraph graph = editor.getGraphComponent().getGraph();

      // Replaces file extension with .mxe
      String filename = file.getName();
      filename = filename.substring(0, filename.length() - 4) + ".mxe";

      if (new File(filename).exists()
          && JOptionPane.showConfirmDialog(editor,
              mxResources.get("overwriteExistingFile")) != JOptionPane.YES_OPTION)
      {
        return;
      }

      ((mxGraphModel) graph.getModel()).clear();
      mxGdCodec.decode(document, graph);
      editor.getGraphComponent().zoomAndCenter();
      editor.setCurrentFile(new File(lastDir + "/" + filename));
    }
View Full Code Here

      {
        if (!editor.isModified()
            || JOptionPane.showConfirmDialog(editor,
                mxResources.get("loseChanges")) == JOptionPane.YES_OPTION)
        {
          mxGraph graph = editor.getGraphComponent().getGraph();

          if (graph != null)
          {
            String wd = (lastDir != null) ? lastDir : System
                .getProperty("user.dir");

            JFileChooser fc = new JFileChooser(wd);

            // Adds file filter for supported file format
            DefaultFileFilter defaultFilter = new DefaultFileFilter(
                ".mxe", mxResources.get("allSupportedFormats")
                    + " (.mxe, .png, .vdx)")
            {

              public boolean accept(File file)
              {
                String lcase = file.getName().toLowerCase();

                return super.accept(file)
                    || lcase.endsWith(".png")
                    || lcase.endsWith(".vdx");
              }
            };
            fc.addChoosableFileFilter(defaultFilter);

            fc.addChoosableFileFilter(new DefaultFileFilter(".mxe",
                "mxGraph Editor " + mxResources.get("file")
                    + " (.mxe)"));
            fc.addChoosableFileFilter(new DefaultFileFilter(".png",
                "PNG+XML  " + mxResources.get("file")
                    + " (.png)"));

            // Adds file filter for VDX import
            fc.addChoosableFileFilter(new DefaultFileFilter(".vdx",
                "XML Drawing  " + mxResources.get("file")
                    + " (.vdx)"));

            // Adds file filter for GD import
            fc.addChoosableFileFilter(new DefaultFileFilter(".txt",
                "Graph Drawing  " + mxResources.get("file")
                    + " (.txt)"));

            fc.setFileFilter(defaultFilter);

            int rc = fc.showDialog(null,
                mxResources.get("openFile"));

            if (rc == JFileChooser.APPROVE_OPTION)
            {
              lastDir = fc.getSelectedFile().getParent();

              try
              {
                if (fc.getSelectedFile().getAbsolutePath()
                    .toLowerCase().endsWith(".png"))
                {
                  openXmlPng(editor, fc.getSelectedFile());
                }
                else if (fc.getSelectedFile().getAbsolutePath()
                    .toLowerCase().endsWith(".txt"))
                {
                  mxGdDocument document = new mxGdDocument();
                  document.parse(mxUtils.readFile(fc
                      .getSelectedFile()
                      .getAbsolutePath()));
                  openGD(editor, fc.getSelectedFile(),
                      document);
                }
                else
                {
                  Document document = mxUtils
                      .parseXml(mxUtils.readFile(fc
                          .getSelectedFile()
                          .getAbsolutePath()));

                  if (fc.getSelectedFile().getAbsolutePath()
                      .toLowerCase().endsWith(".vdx"))
                  {
                    openVdx(editor, fc.getSelectedFile(),
                        document);
                  }
                  else
                  {
                    mxCodec codec = new mxCodec(document);
                    codec.decode(
                        document.getDocumentElement(),
                        graph.getModel());
                    editor.setCurrentFile(fc
                        .getSelectedFile());
                  }

                  resetEditor(editor);
View Full Code Here

    /**
     *
     */
    public void actionPerformed(ActionEvent e)
    {
      mxGraph graph = mxGraphActions.getGraph(e);

      if (graph != null)
      {
        graph.toggleCellStyles(key, defaultValue);
      }
    }
View Full Code Here

    /**
     *
     */
    public void actionPerformed(ActionEvent e)
    {
      mxGraph graph = mxGraphActions.getGraph(e);

      if (graph != null && !graph.isSelectionEmpty())
      {
        graph.getModel().beginUpdate();
        try
        {
          // Checks the orientation of the alignment to use the correct constants
          if (labelPosition.equals(mxConstants.ALIGN_LEFT)
              || labelPosition.equals(mxConstants.ALIGN_CENTER)
              || labelPosition.equals(mxConstants.ALIGN_RIGHT))
          {
            graph.setCellStyles(mxConstants.STYLE_LABEL_POSITION,
                labelPosition);
            graph.setCellStyles(mxConstants.STYLE_ALIGN, alignment);
          }
          else
          {
            graph.setCellStyles(
                mxConstants.STYLE_VERTICAL_LABEL_POSITION,
                labelPosition);
            graph.setCellStyles(mxConstants.STYLE_VERTICAL_ALIGN,
                alignment);
          }
        }
        finally
        {
          graph.getModel().endUpdate();
        }
      }
    }
View Full Code Here

    /**
     *
     */
    public void actionPerformed(ActionEvent e)
    {
      mxGraph graph = mxGraphActions.getGraph(e);

      if (graph != null && !graph.isSelectionEmpty())
      {
        graph.setCellStyle(value);
      }
    }
View Full Code Here

    /**
     *
     */
    public void actionPerformed(ActionEvent e)
    {
      mxGraph graph = mxGraphActions.getGraph(e);

      if (graph != null && !graph.isSelectionEmpty())
      {
        graph.setCellStyles(key, value);
      }
    }
View Full Code Here

     */
    public void actionPerformed(ActionEvent e)
    {
      if (e.getSource() instanceof Component)
      {
        mxGraph graph = mxGraphActions.getGraph(e);

        if (graph != null && !graph.isSelectionEmpty())
        {
          String value = (String) JOptionPane.showInputDialog(
              (Component) e.getSource(),
              mxResources.get("value"), message,
              JOptionPane.PLAIN_MESSAGE, null, null, "");

          if (value != null)
          {
            if (value.equals(mxConstants.NONE))
            {
              value = null;
            }

            graph.setCellStyles(key, value);
          }
        }
      }
    }
View Full Code Here

    /**
     *
     */
    public void actionPerformed(ActionEvent e)
    {
      mxGraph graph = mxGraphActions.getGraph(e);

      if (graph != null && !graph.isSelectionEmpty())
      {
        graph.alignCells(align);
      }
    }
View Full Code Here

TOP

Related Classes of com.mxgraph.view.mxGraph

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.