Package com.mxgraph.view

Examples of com.mxgraph.view.mxGraph


   */
  protected Object[] importCells(mxGraphComponent graphComponent,
      mxGraphTransferable gt, double dx, double dy)
  {
    Object target = getDropTarget(graphComponent, gt);
    mxGraph graph = graphComponent.getGraph();
    Object[] cells = gt.getCells();

    cells = graphComponent.getImportableCells(cells);

    if (graph.isSplitEnabled() && graph.isSplitTarget(target, cells))
    {
      graph.splitEdge(target, cells, dx, dy);
    }
    else
    {
      cells = graphComponent.importCells(cells, dx, dy, target, location);
      graph.setSelectionCells(cells);
    }

    return cells;
  }
View Full Code Here


   * @param g
   *            The graphics to paint the ruler to.
   */
  public void paintComponent(Graphics g)
  {
    mxGraph graph = graphComponent.getGraph();
    Rectangle clip = g.getClipBounds();
    updateIncrementAndUnits();

    // Fills clipping area with background.
    if (activelength > 0 && inactiveBackground != null)
    {
      g.setColor(inactiveBackground);
    }
    else
    {
      g.setColor(getBackground());
    }

    g.fillRect(clip.x, clip.y, clip.width, clip.height);

    // Draws the active region.
    g.setColor(getBackground());
    Point2D p = new Point2D.Double(activeoffset, activelength);

    if (orientation == ORIENTATION_HORIZONTAL)
    {
      g.fillRect((int) p.getX(), clip.y, (int) p.getY(), clip.height);
    }
    else
    {
      g.fillRect(clip.x, (int) p.getX(), clip.width, (int) p.getY());
    }

    double left = clip.getX();
    double top = clip.getY();
    double right = left + clip.getWidth();
    double bottom = top + clip.getHeight();

    // Fetches some global display state information
    mxPoint trans = graph.getView().getTranslate();
    double scale = graph.getView().getScale();
    double tx = trans.getX() * scale;
    double ty = trans.getY() * scale;

    // Sets the distance of the grid lines in pixels
    double stepping = increment;
View Full Code Here

         */
        public void actionPerformed(ActionEvent e)
        {
          mxGraphComponent graphComponent = editor
              .getGraphComponent();
          mxGraph graph = graphComponent.getGraph();
          boolean enabled = !graph.isGridEnabled();

          graph.setGridEnabled(enabled);
          graphComponent.setGridVisible(enabled);
          graphComponent.repaint();
          setSelected(enabled);
        }
      });
View Full Code Here

    {
      if (e.getSource() instanceof mxGraphComponent)
      {
        mxGraphComponent graphComponent = (mxGraphComponent) e
            .getSource();
        mxGraph graph = graphComponent.getGraph();
        String initial = graph.getModel().getStyle(
            graph.getSelectionCell());
        String value = (String) JOptionPane.showInputDialog(
            graphComponent, mxResources.get("style"),
            mxResources.get("style"), JOptionPane.PLAIN_MESSAGE,
            null, null, initial);

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

    // Stores and updates the frame title
    this.appTitle = appTitle;

    // Stores a reference to the graph and creates the command history
    graphComponent = component;
    final mxGraph graph = graphComponent.getGraph();
    undoManager = createUndoManager();

    // Do not change the scale and translation after files have been loaded
    graph.setResetViewOnRootChange(false);

    // Updates the modified flag if the graph model changes
    graph.getModel().addListener(mxEvent.CHANGE, changeTracker);

    // Adds the command history to the model and view
    graph.getModel().addListener(mxEvent.UNDO, undoHandler);
    graph.getView().addListener(mxEvent.UNDO, undoHandler);

    // Keeps the selection in sync with the command history
    mxIEventListener undoHandler = new mxIEventListener()
    {
      public void invoke(Object source, mxEventObject evt)
      {
        List<mxUndoableChange> changes = ((mxUndoableEdit) evt
            .getProperty("edit")).getChanges();
        graph.setSelectionCells(graph
            .getSelectionCellsForChanges(changes));
      }
    };

    undoManager.addListener(mxEvent.UNDO, undoHandler);
View Full Code Here

    {
      return new AbstractAction(mxResources.get(key))
      {
        public void actionPerformed(ActionEvent e)
        {
          final mxGraph graph = graphComponent.getGraph();
          Object cell = graph.getSelectionCell();

          if (cell == null
              || graph.getModel().getChildCount(cell) == 0)
          {
            cell = graph.getDefaultParent();
          }

          graph.getModel().beginUpdate();
          try
          {
            long t0 = System.currentTimeMillis();
            layout.execute(cell);
            status("Layout: " + (System.currentTimeMillis() - t0)
                + " ms");
          }
          finally
          {
            mxMorphing morph = new mxMorphing(graphComponent, 20,
                1.2, 20);

            morph.addListener(mxEvent.DONE, new mxIEventListener()
            {

              public void invoke(Object sender, mxEventObject evt)
              {
                graph.getModel().endUpdate();
              }

            });

            morph.startAnimation();
View Full Code Here

  {
    mxIGraphLayout layout = null;

    if (ident != null)
    {
      mxGraph graph = graphComponent.getGraph();

      if (ident.equals("verticalHierarchical"))
      {
        layout = new mxHierarchicalLayout(graph);
      }
View Full Code Here

    {
      if (e.getSource() instanceof mxGraphComponent)
      {
        mxGraphComponent graphComponent = (mxGraphComponent) e
            .getSource();
        mxGraph graph = graphComponent.getGraph();
        mxCodec codec = new mxCodec();
        Document doc = mxUtils.loadDocument(EditorActions.class
            .getResource(stylesheet).toString());

        if (doc != null)
        {
          codec.decode(doc.getDocumentElement(),
              graph.getStylesheet());
          graph.refresh();
        }
      }
    }
View Full Code Here

     */
    protected void saveXmlPng(BasicGraphEditor editor, String filename,
        Color bg) throws IOException
    {
      mxGraphComponent graphComponent = editor.getGraphComponent();
      mxGraph graph = graphComponent.getGraph();

      // Creates the image for the PNG file
      BufferedImage image = mxCellRenderer.createBufferedImage(graph,
          null, 1, bg, graphComponent.isAntiAlias(), null,
          graphComponent.getCanvas());

      // Creates the URL-encoded XML data
      mxCodec codec = new mxCodec();
      String xml = URLEncoder.encode(
          mxUtils.getXml(codec.encode(graph.getModel())), "UTF-8");
      mxPngEncodeParam param = mxPngEncodeParam
          .getDefaultEncodeParam(image);
      param.setCompressedText(new String[] { "mxGraphModel", xml });

      // Saves as a PNG file
View Full Code Here

      BasicGraphEditor editor = getEditor(e);

      if (editor != null)
      {
        mxGraphComponent graphComponent = editor.getGraphComponent();
        mxGraph graph = graphComponent.getGraph();
        FileFilter selectedFilter = null;
        DefaultFileFilter xmlPngFilter = new DefaultFileFilter(".png",
            "PNG+XML " + mxResources.get("file") + " (.png)");
        FileFilter vmlFileFilter = new DefaultFileFilter(".html",
            "VML " + mxResources.get("file") + " (.html)");
        String filename = null;
        boolean dialogShown = false;

        if (showDialog || editor.getCurrentFile() == null)
        {
          String wd;

          if (lastDir != null)
          {
            wd = lastDir;
          }
          else if (editor.getCurrentFile() != null)
          {
            wd = editor.getCurrentFile().getParent();
          }
          else
          {
            wd = System.getProperty("user.dir");
          }

          JFileChooser fc = new JFileChooser(wd);

          // Adds the default file format
          FileFilter defaultFilter = xmlPngFilter;
          fc.addChoosableFileFilter(defaultFilter);

          // Adds special vector graphics formats and HTML
          fc.addChoosableFileFilter(new DefaultFileFilter(".mxe",
              "mxGraph Editor " + mxResources.get("file")
                  + " (.mxe)"));
          fc.addChoosableFileFilter(new DefaultFileFilter(".txt",
              "Graph Drawing " + mxResources.get("file")
                  + " (.txt)"));
          fc.addChoosableFileFilter(new DefaultFileFilter(".svg",
              "SVG " + mxResources.get("file") + " (.svg)"));
          fc.addChoosableFileFilter(vmlFileFilter);
          fc.addChoosableFileFilter(new DefaultFileFilter(".html",
              "HTML " + mxResources.get("file") + " (.html)"));

          // Adds a filter for each supported image format
          Object[] imageFormats = ImageIO.getReaderFormatNames();

          // Finds all distinct extensions
          HashSet<String> formats = new HashSet<String>();

          for (int i = 0; i < imageFormats.length; i++)
          {
            String ext = imageFormats[i].toString().toLowerCase();
            formats.add(ext);
          }

          imageFormats = formats.toArray();

          for (int i = 0; i < imageFormats.length; i++)
          {
            String ext = imageFormats[i].toString();
            fc.addChoosableFileFilter(new DefaultFileFilter("."
                + ext, ext.toUpperCase() + " "
                + mxResources.get("file") + " (." + ext + ")"));
          }

          // Adds filter that accepts all supported image formats
          fc.addChoosableFileFilter(new DefaultFileFilter.ImageFileFilter(
              mxResources.get("allImages")));
          fc.setFileFilter(defaultFilter);
          int rc = fc.showDialog(null, mxResources.get("save"));
          dialogShown = true;

          if (rc != JFileChooser.APPROVE_OPTION)
          {
            return;
          }
          else
          {
            lastDir = fc.getSelectedFile().getParent();
          }

          filename = fc.getSelectedFile().getAbsolutePath();
          selectedFilter = fc.getFileFilter();

          if (selectedFilter instanceof DefaultFileFilter)
          {
            String ext = ((DefaultFileFilter) selectedFilter)
                .getExtension();

            if (!filename.toLowerCase().endsWith(ext))
            {
              filename += ext;
            }
          }

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

        try
        {
          String ext = filename
              .substring(filename.lastIndexOf('.') + 1);

          if (ext.equalsIgnoreCase("svg"))
          {
            mxSvgCanvas canvas = (mxSvgCanvas) mxCellRenderer
                .drawCells(graph, null, 1, null,
                    new CanvasFactory()
                    {
                      public mxICanvas createCanvas(
                          int width, int height)
                      {
                        mxSvgCanvas canvas = new mxSvgCanvas(
                            mxUtils.createSvgDocument(
                                width, height));
                        canvas.setEmbedded(true);

                        return canvas;
                      }

                    });

            mxUtils.writeFile(mxUtils.getXml(canvas.getDocument()),
                filename);
          }
          else if (selectedFilter == vmlFileFilter)
          {
            mxUtils.writeFile(mxUtils.getXml(mxCellRenderer
                .createVmlDocument(graph, null, 1, null, null)
                .getDocumentElement()), filename);
          }
          else if (ext.equalsIgnoreCase("html"))
          {
            mxUtils.writeFile(mxUtils.getXml(mxCellRenderer
                .createHtmlDocument(graph, null, 1, null, null)
                .getDocumentElement()), filename);
          }
          else if (ext.equalsIgnoreCase("mxe")
              || ext.equalsIgnoreCase("xml"))
          {
            mxCodec codec = new mxCodec();
            String xml = mxUtils.getXml(codec.encode(graph
                .getModel()));

            mxUtils.writeFile(xml, filename);

            editor.setModified(false);
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.