📄 gpgraphpad.java
字号:
/*
* @(#)GPGraphpad.java 1.2 11/11/02
*
* Copyright (C) 2001 Gaudenz Alder
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package org.jgraph;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Frame;
import java.awt.event.ContainerListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.beans.PropertyVetoException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Hashtable;
import javax.swing.Action;
import javax.swing.ActionMap;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JMenuBar;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.UIManager;
import org.jgraph.graph.GraphModel;
import org.jgraph.graph.GraphUndoManager;
import org.jgraph.pad.DefaultGraphModelFileFormatXML;
import org.jgraph.pad.DefaultGraphModelProvider;
import org.jgraph.pad.GPBarFactory;
import org.jgraph.pad.GPConfiguration;
import org.jgraph.pad.GPDocument;
import org.jgraph.pad.GPGraph;
import org.jgraph.pad.GPGraphTools;
import org.jgraph.pad.GPInternalFrame;
import org.jgraph.pad.GPLogConsole;
import org.jgraph.pad.GPStatusBar;
import org.jgraph.pad.GraphModelFileFormat;
import org.jgraph.pad.GraphModelProvider;
import org.jgraph.pad.GraphModelProviderRegistry;
import org.jgraph.pad.actions.*;
import org.jgraph.pad.resources.ImageLoader;
import org.jgraph.pad.resources.Translator;
import org.jgraph.utils.Utilities;
import org.jgraph.utils.gui.GPFrame;
import org.jgpd.jgraph.*;
import org.jgpd.UI.Actions.ProcessProperties;
import org.jgpd.UI.Dialogs.*;
import org.jgpd.io.*;
import org.jgpd.io.jbpm.io.FileExportJBPMProcessXML;
/**
*
* @author Gaudenz Alder
* @author Sven Luzar
* @version 1.3.2 Actions moved to an own package
* @version 1.0 1/1/02
*/
public class GPGraphpad extends JPanel {
/** Pointer to enclosing JGraphpad applet, if any
*/
public transient JGraphpad applet;
/** Application Icon. From resource file.
*/
public static ImageIcon applicationIcon;
/** Application Icon. From resource file.
*/
protected static ImageIcon logoIcon;
/** Application Title. From resource file.
*/
protected static String appTitle;
/** Default entry size
*/
protected static int entrySize = 60;
/** Key for the Registry to save and load
* the frame width for the graphpad frame
*/
protected static String FRAME_WIDTH = "FrameWidth";
/** Key for the Registry to save and load
* the frame height for the graphpad frame
*/
protected static String FRAME_HEIGHT = "FrameHeight";
/** Key for the Registry to save and load
* the frame state for the graphpad frame
*/
protected static String FRAME_STATE = "FrameState";
/** Key for the Registry to save and load
* the frame x position for the graphpad frame
*/
protected static String FRAME_X = "FrameX";
/** Key for the Registry to save and load
* the frame y position for the graphpad frame
*/
protected static String FRAME_Y = "FrameY";
/** Boolean for the visible state of
* the toolbars
*/
protected boolean toolBarsVisible = true;
/** Global instance for some graph tool implementations.
* */
protected static GPGraphTools graphTools = new GPGraphTools();
/** Log console for the System in and out
* messages
*/
protected GPLogConsole logger = new GPLogConsole (
appTitle, applicationIcon.getImage(),
new Boolean(Translator.getString(
"Error.makeLogDlgVisibleOnError")).booleanValue());
/** Desktoppane for the internal frames
*/
protected JDesktopPane desktop = new JDesktopPane();
/** Contains the mapping between GPDocument objects
* and GPInternalFrames.
*
*/
protected Hashtable doc2InternalFrame = new Hashtable();
/** A factory for the menu, tool and popup bars
*
*/
protected GPBarFactory barFactory = new GPBarFactory(this);
/** The current Toolbar for this graphpad
*/
protected JPanel toolBarMainPanel = new JPanel(new BorderLayout());
/** The current Toolbar for this graphpad
*/
protected JPanel toolBarInnerPanel;
/** The current Menubar for this graphpad
*/
protected JMenuBar menubar;
/** The current Statusbar for this Graphpad instance
*/
protected GPStatusBar statusbar;
/** ActionMap contains all default Actions for
* this application
*
*/
protected ActionMap defaultActionMap = new ActionMap();
/** The main Panel with the status bar
* and the desktop pane
*/
protected JPanel mainPanel = new JPanel(new BorderLayout());
/** ActionMap contains the current ActionMap.
*
*/
protected ActionMap currentActionMap = defaultActionMap;
protected JGpdMarqueeHandler marqueeHandler = new JGpdMarqueeHandler(this);
protected GPConfiguration configuration = null;
/** Creates a new default instance
*/
public GPGraphpad() {
this(null);
}
/** Creates a new default instance
*/
public GPGraphpad(JGraphpad applet) {
this(null, applet);
}
/** Creates a new instance with the
* configuration from the config object.
*
* @param config The configuration object.
*/
public GPGraphpad(GPConfiguration config, JGraphpad applet) {
super(true);
setApplet(applet);
// procedure the configuration object
configuration = config;
// set the user actionmap if possible
if (config != null && config.getActionMap() != null) {
currentActionMap = config.getActionMap();
currentActionMap.setParent(defaultActionMap);
}
// set the look and feel
try {
// Kunststoff makes scrolling extremely sluggish
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception exc) {
try {
UIManager.setLookAndFeel(
UIManager.getCrossPlatformLookAndFeelClassName());
} catch (Exception exc2) {
System.err.println("Error loading L&F: " + exc);
}
}
setBorder(BorderFactory.createEtchedBorder());
setLayout(new BorderLayout());
// create the statusbar
createStatusBar();
// use and fill the action map
fillDefaultActionMap();
// set my reference to the actions
setMe4Actions();
// build the menu and the toolbar
menubar = barFactory.createMenubar();
toolBarInnerPanel = barFactory.createToolBars(toolBarMainPanel);
setToolBarsVisible(true);
add(BorderLayout.NORTH, menubar);
add(BorderLayout.CENTER, mainPanel);
add(BorderLayout.SOUTH, statusbar);
JFrame frame = createFrame();
frame.setIconImage(applicationIcon.getImage());
frame.setTitle(appTitle);
frame.getContentPane().add(this);
frame.addWindowListener(new AppCloser(frame));
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
// don't pack use the stored size
//frame.pack();
frame.show();
update();
}
/** GPGraphpad uses the static initializer now.
* Please do not use this method.
* We will delete the method in one of the
* next versions.
*
* @deprecated
*/
public static void init() {
}
/**
* The initializes the common values
*
*/
static {
try {
String vers = System.getProperty("java.version");
if (vers.compareTo("1.4") < 0) {
//TODO: need to open a dialog with instructions, if NOT HEADLESS
System.out.println(
"WARNING: SanBPMN must be run with a "
+ "1.4 or higher version VM");
}
appTitle = Translator.getString("Title");
// Logo
String iconName = Translator.getString("Logo");
logoIcon = ImageLoader.getImageIcon(iconName);
// Icon
iconName = Translator.getString("Icon");
applicationIcon = ImageLoader.getImageIcon(iconName);
} catch (Throwable t) {
System.out.println("uncaught exception: " + t);
t.printStackTrace();
}
}
/** Creates a frame for this Graphpad panel
*
*/
protected JFrame createFrame() {
/*
JFrame frame = new JFrameP() {
public String getInstanceID() {
return this.getClass().getName();
}
public String getNameSpace() {
return "JGraphPad";
}
};
*/
GPFrame gpframe = new GPFrame();
gpframe.setName("MainGraphpad");
return gpframe;
}
/**
*/
public void fillDefaultActionMap() {
for (int i = 0; i < defaultActions.length; i++) {
defaultActionMap.put(
defaultActions[i].getValue(Action.NAME),
defaultActions[i]);
}
}
protected void setMe4Actions() {
Object[] keys;
keys = defaultActionMap.allKeys();
for (int i = 0; i < keys.length; i++) {
Action a = defaultActionMap.get(keys[i]);
if (a instanceof AbstractActionDefault) {
AbstractActionDefault ad = (AbstractActionDefault) a;
if (ad.getGraphpad() == null)
ad.setGraphpad(this);
}
}
if (currentActionMap == defaultActionMap)
return;
keys = currentActionMap.allKeys();
for (int i = 0; i < keys.length; i++) {
Action a = currentActionMap.get(keys[i]);
if (a instanceof AbstractActionDefault) {
AbstractActionDefault ad = (AbstractActionDefault) a;
if (ad.getGraphpad() == null)
ad.setGraphpad(this);
}
}
}
/** Returns the current Action Map
*/
public ActionMap getCurrentActionMap() {
return currentActionMap;
}
/**
* To shutdown when run as an application. This is a
* fairly lame implementation. A more self-respecting
* implementation would at least check to see if a save
* was needed.
*/
protected final class AppCloser extends WindowAdapter {
Frame frame;
AppCloser(Frame f) {
frame = f;
}
public void windowClosing(WindowEvent e) {
// run the action
currentActionMap
.get(Utilities.getClassNameWithoutPackage(FileExit.class))
.actionPerformed(null);
//System.exit(0);
}
}
/**
* Find the hosting frame, for the file-chooser dialog.
*/
public Frame getFrame() {
for (Container p = getParent(); p != null; p = p.getParent()) {
if (p instanceof Frame) {
return (Frame) p;
}
}
return null;
}
public JMenuBar getMenubar() {
return menubar;
}
/**
* Create a status bar
*/
protected GPStatusBar createStatusBar() {
statusbar = new GPStatusBar();
return statusbar;
}
public GPStatusBar getStatusBar() {
return statusbar;
}
/** Show a dialog with the given error message.
* */
public void error(String message) {
JOptionPane.showMessageDialog(
this,
message,
appTitle,
JOptionPane.ERROR_MESSAGE);
}
// --- actions -----------------------------------
/**
* Actions defined by the Graphpad class
*/
protected Action[] defaultActions =
{
new EditCell(this),
new EditCopy(this),
new EditCut(this),
new EditDelete(this),
new EditFind(this),
new EditFindAgain(this),
// change#1 new EditInsertIntoLibrary(this),
new EditPaste(this),
new EditRedo(this),
new EditUndo(this),
new FileClose(this),
new FileExit(this),
new FileImportGXL(this),
new FileImportSimple(this),
new FileExportGraphviz(this),
new FileExportImageMap(this),
new FileExportJBPMProcessXML(this),
// new FileExportJBPMPAR(this), FIXME TODO db
new FileExportJPG(this),
new FileExportGIF(this),
new FileExportPNG(this),
new FileExportGXL(this),
new FileSharingShare(this),
new FileSharingConnect(this),
// change#1 new FileLibraryClose(this),
// change#1 new FileLibraryNew(this),
// change#1 new FileLibraryOpen(this),
// change#1 new FileLibraryOpenURL(this),
// change#1 new FileLibraryRename(this),
// change#1 new FileLibrarySaveAs(this),
new FileNew(this),
new FileNewView(this),
new FileOpen(this),
new FileOpenURL(this),
new FilePageFormat(this),
new FilePrint(this),
new FileSave(this),
new FileSaveAs(this),
new ProcessProperties(this),
new FormatAlignMiddle(this),
new FormatAlignBottom(this),
new FormatAlignCenter(this),
new FormatAlignLeft(this),
new FormatAlignRight(this),
new FormatAlignTop(this),
new FormatBorderColor(this),
new FormatBorderColorList(this),
new FormatBorderNo(this),
new FormatFillColor(this),
new FormatFillColorList(this),
new FormatFillNo(this),
new FormatShapeImage(this),
new FormatShapeImageURL(this),
new FormatShapeNoImage(this),
new FormatLineBezier(this),
new FormatLineColor(this),
new FormatLineColorList(this),
new FormatLineEndList(this),
new FormatLineOrthogonal(this),
new FormatLinePattern(this),
new FormatLinePatternList(this),
new FormatLineQuadratic(this),
new FormatLineStartList(this),
new FormatLineWidth(this),
new FormatLineWidthList(this),
new FormatLockNotBendable(this),
new FormatLockNotConnectable(this),
new FormatLockNotDisconnectable(this),
new FormatLockPosition(this),
new FormatLockSize(this),
new FormatLockValue(this),
new FormatReverse(this),
new FormatRoutingNo(this),
new FormatRoutingSimple(this),
new FormatSizeAuto(this),
new FormatSizeManual(this),
new FormatStyleEndSize(this),
new FormatStyleNoStartEnd(this),
new FormatStyleStartSize(this),
new FormatTextFont(this),
new FormatTextFontColor(this),
new FormatTextFontColorList(this),
new FormatTextFontSize(this),
new FormatTextFontSizeList(this),
new FormatTextFontStyleBold(this),
new FormatTextFontStyleItalic(this),
new FormatTextFontStyleNormal(this),
new FormatTextFontStyleUnderline(this),
new FormatTextPositionBottom(this),
new FormatTextPositionCenter(this),
new FormatTextPositionLeft(this),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -