Package org.jgraph

Examples of org.jgraph.JGraph$GraphSelectionRedirector


 
  private final static int   MAX_WIDTH      = 2100;
  private final static int  MAX_HEIGHT      = 2100;

    public static RenderedImage getRenderedImage(ReachabilityGraphPanel editor) {
  JGraph graph = editor.getGraph();
        graph.clearSelection();
        Object[] cells = graph.getRoots();
        BufferedImage image = null;
       
        if (cells.length > 0) {
            Rectangle2D rectangle = graph.getCellBounds(cells);

            graph.setGridVisible(false);
            graph.toScreen(rectangle);

            Dimension dimension = rectangle.getBounds().getSize();
            // Check Dimension, if max size reached, let user know about this and resize graph
            if(dimension.width < MAX_WIDTH && dimension.height < MAX_HEIGHT)
            {
              image = new BufferedImage(dimension.width, dimension.height, BufferedImage.TYPE_INT_RGB);
              Graphics2D graphics = image.createGraphics();
                graphics.translate(-rectangle.getX(), -rectangle.getY());
                graph.paint(graphics);

                graph.setGridVisible(ConfigurationManager.getConfiguration().isShowGrid());  
            }
            else
            {
//              ReferenceProvider mediator = new ReferenceProvider();
              JOptionPane.showMessageDialog(null,
              Messages.getString("QuanlAna.ReachabilityGraph.ExportFailed"), Messages
                  .getString("QuanlAna.ReachabilityGraph.ExportFailed.Title"),
              JOptionPane.ERROR_MESSAGE);
                double g2dWidth = dimension.width;
                double g2dHeight = dimension.height;
                double pageWidth = MAX_WIDTH;
                double pageHeight = MAX_HEIGHT;
                double xScaleFactor = pageWidth / g2dWidth;
                double yScaleFactor = pageHeight / g2dHeight;
              image = new BufferedImage(MAX_WIDTH, MAX_HEIGHT, BufferedImage.TYPE_INT_RGB);
                Graphics2D graphics = image.createGraphics();
                graphics.translate(-rectangle.getX(), -rectangle.getY());
                graphics.scale(xScaleFactor, yScaleFactor);
                graph.paint(graphics);

                graph.setGridVisible(ConfigurationManager.getConfiguration().isShowGrid());
            }
                    
        }
       
        return image;
View Full Code Here


  public Rectangle2D getBounds(CellView value) {
    if (value instanceof EdgeView && value != null) {
      // No need to call setView as getPaintBounds will
      view = (EdgeView) value;
      Rectangle2D r = getPaintBounds(view);
      JGraph graph = null;
      if (this.graph != null) {
        graph = (JGraph)this.graph.get();
      }
      Rectangle2D rect = getLabelBounds(graph, view);
      if (rect != null)
View Full Code Here

  /**
   * Returns the label bounds of the specified view in the given graph.
   */
  public Rectangle2D getLabelBounds(JGraph paintingContext, EdgeView view) {
    if (paintingContext == null && graph != null) {
      JGraph graph = (JGraph)this.graph.get();
      paintingContext = graph;
    }
    // No need to call setView as getLabelPosition will
    String label = (paintingContext != null) ? paintingContext
        .convertValueToString(view) : String.valueOf(view.getCell());
View Full Code Here

   * labels array of the view.
   */
  public Rectangle2D getExtraLabelBounds(JGraph paintingContext,
      EdgeView view, int index) {
    if (paintingContext == null && graph != null) {
      JGraph graph = (JGraph)this.graph.get();
      paintingContext = graph;
    }
    setView(view);
    Object[] labels = GraphConstants
        .getExtraLabels(view.getAllAttributes());
View Full Code Here

    Graphics2D g2 = (Graphics2D) g;
    g2.setStroke(new BasicStroke(1));
    g.setFont((extraLabelFont != null) ? extraLabelFont : getFont());
    Object[] labels = GraphConstants
        .getExtraLabels(view.getAllAttributes());
    JGraph graph = (JGraph) this.graph.get();
    if (labels != null)
    {
      for (int i = 0; i < labels.length; i++)
        paintLabel(g, graph.convertValueToString(labels[i]),
            getExtraLabelPosition(view, i),
            false || !simpleExtraLabels);
    }
    if (graph.getEditingCell() != view.getCell())
    {
      g.setFont(getFont());
      Object label = graph.convertValueToString(view);
      if (label != null)
      {
        paintLabel(g, label.toString(), getLabelPosition(view), true);
      }
    }
View Full Code Here

  // 3. Transfer is passed to importDataImpl for unsupported
  // dataflavors (becaue method may return false, see 1.)
  public boolean importData(JComponent comp, Transferable t) {
    try {
      if (comp instanceof JGraph) {
        JGraph graph = (JGraph) comp;
        GraphModel model = graph.getModel();
        GraphLayoutCache cache = graph.getGraphLayoutCache();
        if (t.isDataFlavorSupported(GraphTransferable.dataFlavor)
            && graph.isEnabled()) {
          // May be null
          Point p = graph.getUI().getInsertionLocation();

          // Get Local Machine Flavor
          Object obj = t
              .getTransferData(GraphTransferable.dataFlavor);
          GraphTransferable gt = (GraphTransferable) obj;

          // Get Transferred Cells
          Object[] cells = gt.getCells();

          // Check if all cells are in the model
          boolean allInModel = true;
          for (int i = 0; i < cells.length && allInModel; i++)
            allInModel = allInModel && model.contains(cells[i]);

          // Count repetitive inserts
          if (in == cells)
            inCount++;
          else
            inCount = (allInModel) ? 1 : 0;
          in = cells;

          // Delegate to handle
          if (p != null && in == out
              && graph.getUI().getHandle() != null) {
            int mod = (graph.getUI().getDropAction() == TransferHandler.COPY) ? InputEvent.CTRL_MASK
                : 0;
            graph.getUI().getHandle().mouseReleased(
                new MouseEvent(comp, 0, 0, mod, p.x, p.y, 1,
                    false));
            return false;
          }

          // Get more Transfer Data
          Rectangle2D bounds = gt.getBounds();
          Map nested = gt.getAttributeMap();
          ConnectionSet cs = gt.getConnectionSet();
          ParentMap pm = gt.getParentMap();

          // Move across models or via clipboard always clones
          if (!allInModel
              || p == null
              || alwaysReceiveAsCopyAction
              || graph.getUI().getDropAction() == TransferHandler.COPY) {

            // Translate cells
            double dx = 0, dy = 0;

            // Cloned via Drag and Drop
            if (nested != null) {
              if (p != null && bounds != null) {
                Point2D insert = graph.fromScreen(graph
                    .snap((Point2D) p.clone()));
                dx = insert.getX() - bounds.getX();
                dy = insert.getY() - bounds.getY();

                // Cloned via Clipboard
              } else {
                Point2D insertPoint = getInsertionOffset(graph,
                    inCount, bounds);
                if (insertPoint != null) {
                  dx = insertPoint.getX();
                  dy = insertPoint.getY();
                }
              }
            }

            handleExternalDrop(graph, cells, nested, cs, pm, dx, dy);

            // Signal sender to remove only if moved between
            // different models
            return (graph.getUI().getDropAction() == TransferHandler.MOVE && !allInModel);
          }

          // We are dealing with a move across multiple views
          // of the same model
          else {

            // Moved via Drag and Drop
            if (p != null) {
              // Scale insertion location
              Point2D insert = graph.fromScreen(graph
                  .snap(new Point(p)));

              // Compute translation vector and translate all
              // attribute maps.
              if (bounds != null && nested != null) {
                double dx = insert.getX() - bounds.getX();
                double dy = insert.getY() - bounds.getY();
                AttributeMap.translate(nested.values(), dx, dy);
              } else if (bounds == null) {

                // Prevents overwriting view-local
                // attributes
                // for known cells. Note: This is because
                // if bounds is null, the caller wants
                // to signal that the bounds were
                // not available, which is typically the
                // case if no graph layout cache
                // is at hand. To avoid overriding the
                // local attributes such as the bounds
                // with the default bounds from the model,
                // we remove all attributes that travel
                // along with the transferable. (Since
                // all cells are already in the model
                // no information is lost by doing this.)
                double gs2 = 2 * graph.getGridSize();
                nested = new Hashtable();
                Map emptyMap = new Hashtable();
                for (int i = 0; i < cells.length; i++) {

                  // This also gives us the chance to
                  // provide useful default location and
                  // resize if there are no useful bounds
                  // that travel along with the cells.
                  if (!model.isEdge(cells[i])
                      && !model.isPort(cells[i])) {

                    // Check if there are useful bounds
                    // defined in the model, otherwise
                    // resize,
                    // because the view does not yet exist.
                    Rectangle2D tmp = graph
                        .getCellBounds(cells[i]);
                    if (tmp == null)
                      tmp = GraphConstants
                          .getBounds(model
                              .getAttributes(cells[i]));

                    // Clone the rectangle to force a
                    // repaint
                    if (tmp != null)
                      tmp = (Rectangle2D) tmp.clone();

                    Hashtable attrs = new Hashtable();
                    Object parent = model
                        .getParent(cells[i]);
                    if (tmp == null) {
                      tmp = new Rectangle2D.Double(p
                          .getX(), p.getY(), gs2 / 2,
                          gs2);
                      GraphConstants.setResize(attrs,
                          true);

                      // Shift
                      p.setLocation(p.getX() + gs2, p
                          .getY()
                          + gs2);
                      graph.snap(p);
                      // If parent processed then childs
                      // are already located
                    } else if (parent == null
                        || !nested
                            .keySet()
                            .contains(
                                model
                                    .getParent(cells[i]))) {
                      CellView view = graph
                          .getGraphLayoutCache()
                          .getMapping(cells[i], false);
                      if (view != null && !view.isLeaf()) {
                        double dx = p.getX()
                            - tmp.getX();
                        double dy = p.getY()
                            - tmp.getY();
                        GraphLayoutCache
                            .translateViews(
                                new CellView[] { view },
                                dx, dy);
                      } else {
                        tmp.setFrame(p.getX(),
                            p.getY(), tmp
                                .getWidth(),
                            tmp.getHeight());
                      }

                      // Shift
                      p.setLocation(p.getX() + gs2, p
                          .getY()
                          + gs2);
                      graph.snap(p);
                    }
                    GraphConstants.setBounds(attrs, tmp);
                    nested.put(cells[i], attrs);
                  } else {
                    nested.put(cells[i], emptyMap);
                  }
                }
              }

              // Edit cells (and make visible)
              cache.edit(nested, null, null, null);
            }

            // Select topmost cells in group-structure
            graph.setSelectionCells(DefaultGraphModel
                .getTopmostCells(model, cells));

            // Don't remove at sender
            return false;
          }
View Full Code Here

import org.woped.editor.controller.vc.EditorVC;

public class ImageExport {

    public static RenderedImage getRenderedImage(EditorVC editor) {
  JGraph graph = editor.getGraph();
        graph.clearSelection();
        Object[] cells = graph.getRoots();
        BufferedImage image = null;
       
        if (cells.length > 0) {
            Rectangle2D rectangle = graph.getCellBounds(cells);

            graph.setGridVisible(false);
            graph.toScreen(rectangle);

            // Create a Buffered Image
            Dimension dimension = rectangle.getBounds().getSize();
            image = new BufferedImage(dimension.width, dimension.height, BufferedImage.TYPE_INT_RGB);
            Graphics2D graphics = image.createGraphics();
            graphics.translate(-rectangle.getX(), -rectangle.getY());
            graph.paint(graphics);

            graph.setGridVisible(ConfigurationManager.getConfiguration().isShowGrid()
              && !editor.isTokenGameEnabled());           
        }
       
        return image;
    }
View Full Code Here

    return createTransferable(graph);
  }

  protected Transferable createTransferable(JComponent c) {
    if (c instanceof JGraph) {
      JGraph graph = (JGraph) c;
      if (!graph.isSelectionEmpty()) {
        return createTransferable(graph, graph.getSelectionCells());
      }
    }
    return null;
  }
View Full Code Here

    return new GraphTransferable(cells, viewAttributes, bounds, cs, pm);
  }

  protected void exportDone(JComponent comp, Transferable data, int action) {
    if (comp instanceof JGraph && data instanceof GraphTransferable) {
      JGraph graph = (JGraph) comp;
      if (action == TransferHandler.MOVE) {
        Object[] cells = ((GraphTransferable) data).getCells();
        graph.getGraphLayoutCache().remove(cells);
      }
      graph.getUI().updateHandle();
      graph.getUI().setInsertionLocation(null);
    }
  }
View Full Code Here

     *
     * @param g
     *            The graphics to paint the navigator to.
     */
    public void paint(Graphics g) {
      JGraph graph = getCurrentGraph();
      JScrollPane scrollPane = getParentScrollPane(graph);
      g.setColor(Color.lightGray);
      g.fillRect(0, 0, getWidth(), getHeight());
      if (scrollPane != null && graph != null) {
        JViewport viewport = scrollPane.getViewport();
        Rectangle rect = viewport.getViewRect();
        double scale = backingGraph.getScale() / graph.getScale();

        Dimension pSize = graph.getSize();
        g.setColor(getBackground());
        g.fillRect(0, 0, (int) (pSize.width * scale),
            (int) (pSize.height * scale));
        g.setColor(Color.WHITE);
        currentViewport.setFrame((int) (rect.getX() * scale),
 
View Full Code Here

TOP

Related Classes of org.jgraph.JGraph$GraphSelectionRedirector

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.