Package com.acelet.s.workflow

Source Code of com.acelet.s.workflow.MyToolbox$MyMarqueeRedirector

/* Copyright 1999-2008 Acelet.org. All rights reserved. GPL v2 license */
/** @author Wei Jiang */

package com.acelet.s.workflow;

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.tree.*;
import com.acelet.lib.*;

import org.jgraph.JGraph;
import org.jgraph.graph.AttributeMap;
import org.jgraph.graph.DefaultGraphCell;
import com.jgraph.editor.JGraphEditorKit;
import com.jgraph.editor.JGraphEditorTool;
import com.jgraph.editor.factory.JGraphEditorToolbox;
import com.jgraph.pad.tool.JGraphpadEdgeTool;
import com.jgraph.pad.tool.JGraphpadVertexTool;

public class MyToolbox extends JGraphEditorToolbox {
  static JGraphEditorTool selectTool;
  static JGraphpadEdgeTool edgeTool;
  static JGraphpadEdgeTool orthogonalTool;
  static JGraphpadVertexTool textTool;
  static JGraphpadVertexTool vertexTool;

  Cursor defaultCursor;
  Cursor rectangleCursor;
  Cursor edgeCursor;
  Cursor orthogonalCursor;
  Cursor textCursor;

  public MyToolbox() {
    super();

    redirector = new MyMarqueeRedirector();

    JGraphEditorKit graphEditorKit = WorkflowPanel.graphEditor.getKit();
    selectTool = graphEditorKit.getTool(JGraphpad.NAME_SELECTTOOL);  
    edgeTool = (JGraphpadEdgeTool)
      graphEditorKit.getTool(JGraphpad.NAME_EDGETOOL)
    orthogonalTool = (JGraphpadEdgeTool)
      graphEditorKit.getTool(JGraphpad.NAME_ORTHOGONALEDGETOOL);
    textTool = (JGraphpadVertexTool)
      graphEditorKit.getTool(JGraphpad.NAME_TEXTTOOL)
    vertexTool = (JGraphpadVertexTool)
      graphEditorKit.getTool(JGraphpad.NAME_VERTEXTOOL)

    DefaultGraphCell defaultGraphCell = (DefaultGraphCell) vertexTool.getPrototype();
    AttributeMap vertexAttributes = defaultGraphCell.getAttributes();
    vertexAttributes.put(CellType.CELL_TYPE_KEY, CellType.CELL_TYPE_ACTION);

    LoadFile loadFile = new LoadFile();
    ImageIcon rectangleIcon = loadFile.receiveImageIcon("rectangleCursor.gif");
    ImageIcon edgeIcon = loadFile.receiveImageIcon("edgeCursor.gif");
    ImageIcon orthogonalIcon = loadFile.receiveImageIcon("orthogonalCursor.gif");
    ImageIcon textIcon = loadFile.receiveImageIcon("textCursor.gif");

    Image rectangleImage = rectangleIcon.getImage();
    Image edgeImage = edgeIcon.getImage();
    Image orthogonalImage = orthogonalIcon.getImage();
    Image textImage = textIcon.getImage();

    Toolkit toolkit = Toolkit.getDefaultToolkit();

    defaultCursor = new Cursor(Cursor.DEFAULT_CURSOR);
    rectangleCursor = toolkit.createCustomCursor(rectangleImage, new Point(0, 0), "rectangle");
    edgeCursor = toolkit.createCustomCursor(edgeImage, new Point(0, 0), "edge");
    orthogonalCursor = toolkit.createCustomCursor(orthogonalImage, new Point(0, 0), "orthogonal");
    textCursor = toolkit.createCustomCursor(textImage, new Point(0, 0), "text");
  }

  void reset() {
    setSelectionTool(selectTool);
  }
 
  void setToolCursor(JGraphEditorTool tool) {
    Cursor cursor = null;
    if (tool == edgeTool)
      cursor = edgeCursor;
    else if (tool == orthogonalTool)
      cursor = orthogonalCursor;
    else if (tool == textTool)
      cursor = textCursor;
    else if (tool == vertexTool)
      cursor = rectangleCursor;
    else if (tool == selectTool)
      cursor = defaultCursor;

    getGraph().setCursor(cursor);
  }   

  public void setSelectionTool(JGraphEditorTool selectionTool, JGraph graph) {
    this.selectionTool = selectionTool;
    setGraph(graph);
    setToolCursor(selectionTool);
  }

  public class MyMarqueeRedirector extends MarqueeRedirector {
    public void mouseReleased(MouseEvent event) {
      super.mouseReleased(event);
      setSelectionTool(selectTool);
      graph.setCursor(null);
    }
  }
}
TOP

Related Classes of com.acelet.s.workflow.MyToolbox$MyMarqueeRedirector

TOP
Copyright © 2018 www.massapi.com. 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.