Package com.mxgraph.swing

Examples of com.mxgraph.swing.mxGraphComponent


     */
    public void actionPerformed(ActionEvent e)
    {
      if (e.getSource() instanceof mxGraphComponent)
      {
        mxGraphComponent graphComponent = (mxGraphComponent) e
            .getSource();
        graphComponent.setPageVisible(true);
        graphComponent.setZoomPolicy(zoomPolicy);
      }
    }
View Full Code Here


     */
    public void actionPerformed(ActionEvent e)
    {
      if (e.getSource() instanceof mxGraphComponent)
      {
        mxGraphComponent graphComponent = (mxGraphComponent) e
            .getSource();
        graphComponent.setGridStyle(style);
        graphComponent.repaint();
      }
    }
View Full Code Here

     */
    public void actionPerformed(ActionEvent e)
    {
      if (e.getSource() instanceof mxGraphComponent)
      {
        mxGraphComponent graphComponent = (mxGraphComponent) e
            .getSource();
        Color newColor = JColorChooser.showDialog(graphComponent,
            mxResources.get("gridColor"),
            graphComponent.getGridColor());

        if (newColor != null)
        {
          graphComponent.setGridColor(newColor);
          graphComponent.repaint();
        }
      }
    }
View Full Code Here

     */
    public void actionPerformed(ActionEvent e)
    {
      if (e.getSource() instanceof mxGraphComponent)
      {
        mxGraphComponent graphComponent = (mxGraphComponent) e
            .getSource();
        double scale = this.scale;

        if (scale == 0)
        {
          String value = (String) JOptionPane.showInputDialog(
              graphComponent, mxResources.get("value"),
              mxResources.get("scale") + " (%)",
              JOptionPane.PLAIN_MESSAGE, null, null, "");

          if (value != null)
          {
            scale = Double.parseDouble(value.replace("%", "")) / 100;
          }
        }

        if (scale > 0)
        {
          graphComponent.zoomTo(scale, graphComponent.isCenterZoom());
        }
      }
    }
View Full Code Here

     */
    public void actionPerformed(ActionEvent e)
    {
      if (e.getSource() instanceof mxGraphComponent)
      {
        mxGraphComponent graphComponent = (mxGraphComponent) e
            .getSource();
        PrinterJob pj = PrinterJob.getPrinterJob();
        PageFormat format = pj.pageDialog(graphComponent
            .getPageFormat());

        if (format != null)
        {
          graphComponent.setPageFormat(format);
          graphComponent.zoomAndCenter();
        }
      }
    }
View Full Code Here

     */
    public void actionPerformed(ActionEvent e)
    {
      if (e.getSource() instanceof mxGraphComponent)
      {
        mxGraphComponent graphComponent = (mxGraphComponent) e
            .getSource();
        PrinterJob pj = PrinterJob.getPrinterJob();

        if (pj.printDialog())
        {
          PageFormat pf = graphComponent.getPageFormat();
          Paper paper = new Paper();
          double margin = 36;
          paper.setImageableArea(margin, margin, paper.getWidth()
              - margin * 2, paper.getHeight() - margin * 2);
          pf.setPaper(paper);
 
View Full Code Here

     * Saves XML+PNG format.
     */
    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");
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);
            editor.setCurrentFile(new File(filename));
          }
          else if (ext.equalsIgnoreCase("txt"))
          {
            String content = mxGdCodec.encode(graph)
                .getDocumentString();

            mxUtils.writeFile(content, filename);
          }
          else
          {
            Color bg = null;

            if ((!ext.equalsIgnoreCase("gif") && !ext
                .equalsIgnoreCase("png"))
                || JOptionPane.showConfirmDialog(
                    graphComponent, mxResources
                        .get("transparentBackground")) != JOptionPane.YES_OPTION)
            {
              bg = graphComponent.getBackground();
            }

            if (selectedFilter == xmlPngFilter
                || (editor.getCurrentFile() != null
                    && ext.equalsIgnoreCase("png") && !dialogShown))
            {
              saveXmlPng(editor, filename, bg);
            }
            else
            {
              BufferedImage image = mxCellRenderer
                  .createBufferedImage(graph, null, 1, bg,
                      graphComponent.isAntiAlias(), null,
                      graphComponent.getCanvas());

              if (image != null)
              {
                ImageIO.write(image, ext, new File(filename));
              }
View Full Code Here

     */
    public void actionPerformed(ActionEvent e)
    {
      if (e.getSource() instanceof mxGraphComponent)
      {
        mxGraphComponent graphComponent = (mxGraphComponent) e
            .getSource();
        mxGraph graph = graphComponent.getGraph();
        mxIGraphModel model = graph.getModel();

        Object source = null;
        Object target = null;

View Full Code Here

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

        if (!graph.isSelectionEmpty())
        {
          Color newColor = JColorChooser.showDialog(graphComponent,
              name, null);
View Full Code Here

TOP

Related Classes of com.mxgraph.swing.mxGraphComponent

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.