Package com.acelet.s.workflow

Source Code of com.acelet.s.workflow.JGraphEditorFactoryEx

/* 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.util.*;
import javax.swing.*;
import javax.swing.event.*;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import com.jgraph.editor.JGraphEditorFactory;
import com.jgraph.editor.JGraphEditorKit;
import com.jgraph.editor.JGraphEditorTool;
import com.jgraph.editor.factory.JGraphEditorDiagramPane;
import com.jgraph.editor.factory.JGraphEditorFactoryMethod;
import com.jgraph.editor.factory.JGraphEditorToolbox;
import com.jgraph.pad.action.JGraphpadEditAction;
import org.jgraph.JGraph;
import org.jgraph.graph.DefaultEdge;
import org.jgraph.graph.DefaultGraphCell;
import org.jgraph.graph.DefaultPort;
import org.jgraph.graph.GraphLayoutCache;

import com.acelet.lib.*;

public class JGraphEditorFactoryEx extends JGraphEditorFactory implements ActionListener {
  JMenuItem idMenuItem;
  JMenuItem propertiesMenuItem;
  JMenuItem cutMenuItem;
  JMenuItem copyMenuItem;
  JMenuItem pasteMenuItem;

  public JGraphEditorFactoryEx(JGraphEditorKit kit) {
    super(kit);
  }

  public void actionPerformed(ActionEvent event) {
    try {
      Object source = event.getSource();
      if (source == propertiesMenuItem) {
        editCell();
      }
    } catch(Throwable ex) {
      InfoBox.exhibit(null, InfoBox.OK, ex);
    }
  }

  protected void configureMenuBar(Container menu, Node configuration) {
    super.configureMenuBar(menu, configuration);

    if (configuration != null) {
      String key = getKey(configuration);
      if (menu instanceof JMenu)
        menu.setName(key);
    }
  }   

  public JPopupMenu createPopupMenu(Node configuration) {
    JPopupMenu menu = new JPopupMenu();

    if (SelectedCell.isDefaultGraphCellSelected() == false)
      return menu;

    LoadFile loadFile = new LoadFile();
    ImageIcon idIcon = loadFile.receiveImageIcon("id.gif");
    ImageIcon propertiesIcon = loadFile.receiveImageIcon("properties.gif");

    JPopupMenu originalMenu = super.createPopupMenu(configuration);
    for (int i = 0; i < originalMenu.getComponentCount(); i++) {
      Component component = originalMenu.getComponent(i);
      if (component instanceof JMenuItem) {
        JMenuItem menuItem = (JMenuItem) component;
        Action action = menuItem.getAction();
        String actionName = String.valueOf(action.getValue(Action.NAME));

        if (actionName.equals(JGraphpadEditAction.NAME_EDIT)) {
          idMenuItem = menuItem;
          idMenuItem.addActionListener(this);
          idMenuItem.setText(Phrase.get("TX_ID"));
          idMenuItem.setIcon(idIcon);
        } else if (actionName.equals(JGraphpadEditAction.NAME_CUT)) {
          cutMenuItem = menuItem;
          cutMenuItem.addActionListener(this);
          cutMenuItem.setText(Phrase.get("TX_CUT"));
        } else if (actionName.equals(JGraphpadEditAction.NAME_COPY)) {
          copyMenuItem = menuItem;
          copyMenuItem.addActionListener(this);
          copyMenuItem.setText(Phrase.get("TX_COPY"));
        }
      }
    }

    propertiesMenuItem = new JMenuItem(Phrase.get("TX_PROPERTIES"), propertiesIcon);
    propertiesMenuItem.addActionListener(this);

   
    menu.add(propertiesMenuItem);

    if (WorkflowPanel.readOnly == false) {
      menu.addSeparator();
      menu.add(cutMenuItem);
      menu.add(copyMenuItem);
    }

    return menu;
  }

  protected AbstractButton createToolboxButton(JGraphEditorTool tool) {
    AbstractButton button = new JToggleButton();
    String name = tool.getName();
    button.setName(name);
    configureAbstractButton(button, tool.getName());
    return button;
  }

  void editCell() throws Exception {
    if (SelectedCell.isSelectedCellActionCell()) {
      JGraph graph = Util.getCurrentGraph();
      if (graph == null)
        return;

      ActionPropertiesPanel actionPropertiesPanel = new ActionPropertiesPanel(graph);
      if (actionPropertiesPanel.getReady() == false)
        return;
     
      Window window = getParentWindow();
      if (window instanceof JDialog)
        new CommonDlg((JDialog) window, Phrase.get("TX_ACTION_PROPERTIES"), actionPropertiesPanel);
      else
        new CommonDlg((JFrame) window, Phrase.get("TX_ACTION_PROPERTIES"), actionPropertiesPanel);
    } else
      idMenuItem.doClick();
  }

  public Window getParentWindow() {
    Component component =
      KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();
    return SwingUtilities.windowForComponent(component);
  }

  void setActionProperties() throws Exception {
  }

}
TOP

Related Classes of com.acelet.s.workflow.JGraphEditorFactoryEx

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.