01: /*
02: * $Id: JGraphpadCodecPlugin.java,v 1.1.1.1 2005/08/04 11:21:58 gaudenz Exp $
03: * Copyright (c) 2001-2005, Gaudenz Alder
04: *
05: * All rights reserved.
06: *
07: * See LICENSE file for license details. If you are unable to locate
08: * this file please contact info (at) jgraph (dot) com.
09: */
10: package com.jgraph.codecplugin;
11:
12: import java.io.IOException;
13:
14: import javax.xml.parsers.ParserConfigurationException;
15:
16: import org.jgraph.JGraph;
17: import org.jgraph.graph.CellView;
18: import org.jgraph.graph.GraphModel;
19: import org.w3c.dom.Node;
20: import org.xml.sax.SAXException;
21:
22: import com.jgraph.JGraphEditor;
23: import com.jgraph.JGraphpad;
24: import com.jgraph.editor.JGraphEditorPlugin;
25: import com.jgraph.editor.JGraphEditorResources;
26: import com.jgraph.editor.JGraphEditorSettings;
27:
28: /**
29: * Plugin for exporting JGraphpad files to various formats, namely HTML image
30: * maps, GXL and Graphviz.
31: */
32: public class JGraphpadCodecPlugin implements JGraphEditorPlugin {
33:
34: /**
35: * Defines the path to the UI configuration to be merged into the existing
36: * UI configuration.
37: */
38: public static String PATH_UICONFIG = "/com/jgraph/codecplugin/resources/ui.xml";
39:
40: /**
41: * Adds resource bundles.
42: */
43: static {
44: JGraphEditorResources
45: .addBundles(new String[] { "com.jgraph.codecplugin.resources.strings" });
46: }
47:
48: /**
49: * Utilitiy method used by some of the codecs to determine whether a cell is
50: * a vertex. This implementation takes into account the current collapsed
51: * state.
52: *
53: * @param graph
54: * The graph that contains the cell.
55: * @param cell
56: * The cell to be checked.
57: * @return Returns true if <code>cell</code> is a vertex.
58: */
59: public static boolean isVertex(JGraph graph, Object cell) {
60: GraphModel model = graph.getModel();
61: CellView view = graph.getGraphLayoutCache().getMapping(cell,
62: false);
63: return view != null && view.isLeaf() && !model.isEdge(cell)
64: && !model.isPort(cell);
65: }
66:
67: /**
68: * Initializes the plugin by registering all factory methods and action
69: * bundles and merging the UI configuration into the main configuration.
70: *
71: * @param editor
72: * The enclosing editor for the plugin.
73: * @param configuration
74: * The object to configure the plugin with.
75: */
76: public void initialize(JGraphEditor editor, Node configuration)
77: throws ParserConfigurationException, SAXException,
78: IOException {
79: editor.getKit().addBundle(
80: new JGraphpadCodecAction.AllActions(editor));
81: editor.getSettings().add(
82: JGraphpad.NAME_UICONFIG,
83: JGraphEditorSettings.parse(JGraphEditorResources
84: .getInputStream(PATH_UICONFIG)));
85: }
86:
87: }
|