001: /*
002: * $Id: JGraphpadL2FPlugin.java,v 1.1.1.1 2005/08/04 11:21:58 gaudenz Exp $
003: * Copyright (c) 2001-2005, Gaudenz Alder
004: *
005: * All rights reserved.
006: *
007: * See LICENSE file for license details. If you are unable to locate
008: * this file please contact info (at) jgraph (dot) com.
009: */
010: package com.jgraph.l2fplugin;
011:
012: import java.awt.Component;
013:
014: import javax.swing.JTabbedPane;
015:
016: import org.w3c.dom.Node;
017:
018: import com.jgraph.JGraphEditor;
019: import com.jgraph.editor.JGraphEditorFactory;
020: import com.jgraph.editor.JGraphEditorKit;
021: import com.jgraph.editor.JGraphEditorPlugin;
022: import com.jgraph.editor.JGraphEditorResources;
023: import com.jgraph.editor.factory.JGraphEditorFactoryMethod;
024: import com.jgraph.pad.factory.JGraphpadPane;
025:
026: /**
027: * Plugin for using L2FProd in JGraphpad Pro. Adds a property sheet to the
028: * bottom tabs in the main window and a font action to the format menu.
029: */
030: public class JGraphpadL2FPlugin implements JGraphEditorPlugin {
031:
032: /**
033: * Adds resource bundles.
034: */
035: static {
036: JGraphEditorResources
037: .addBundles(new String[] { "com.jgraph.l2fplugin.resources.strings" });
038: }
039:
040: /**
041: * Initializes the plugin by registering all factory methods and action
042: * bundles.
043: *
044: * @param editor
045: * The enclosing editor for the plugin.
046: * @param configuration
047: * The object to configure the plugin with.
048: */
049: public void initialize(JGraphEditor editor, Node configuration) {
050: JGraphEditorKit kit = editor.getKit();
051: kit.addBundle(new JGraphpadL2FAction.AllActions());
052: JGraphEditorFactory factory = editor.getFactory();
053: factory.addMethod(new JGraphpadL2FLibraryPane(editor));
054: factory
055: .addMethod(new JGraphpadL2FPropertySheet.FactoryMethod());
056: editor.getFactory().addMethod(
057: new ExtendedBottomTabFactoryMethod(editor));
058: }
059:
060: /**
061: * Utility class to add the property sheet to the bottom tab of the main
062: * application window. This factory method replaces the original factory
063: * method and keeps a reference to it. When it is invoked it uses the
064: * original factory method to create the original object and then adds its
065: * own tabs to that object before returning it.
066: */
067: public static class ExtendedBottomTabFactoryMethod extends
068: JGraphEditorFactoryMethod {
069:
070: /**
071: * Reference to factory method that was replaced.
072: */
073: protected JGraphEditorFactoryMethod previous = null;
074:
075: /**
076: * References the enclosing editor.
077: */
078: protected JGraphEditor editor;
079:
080: /**
081: * Constructs a new factory method for the specified enclosing editor
082: * using JGraphpadPane.BottomTabFactoryMethod.NAME.
083: *
084: * @param editor
085: * The editor that contains the factory method.
086: */
087: public ExtendedBottomTabFactoryMethod(JGraphEditor editor) {
088: super (JGraphpadPane.BottomTabFactoryMethod.NAME);
089: previous = editor.getFactory().getMethod(
090: JGraphpadPane.BottomTabFactoryMethod.NAME);
091: this .editor = editor;
092: }
093:
094: /*
095: * (non-Javadoc)
096: */
097: public Component createInstance(Node configuration) {
098: if (previous != null) {
099: Component component = previous
100: .createInstance(configuration);
101: if (component instanceof JTabbedPane) {
102: JTabbedPane tabPane = (JTabbedPane) component;
103:
104: Component properties = editor
105: .getFactory()
106: .executeMethod(
107: JGraphpadL2FPropertySheet.FactoryMethod.NAME);
108: if (properties != null)
109: tabPane.addTab(JGraphEditorResources
110: .getString("Properties"), properties);
111: }
112: return component;
113: }
114: return null;
115: }
116:
117: }
118:
119: }
|