KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > jawe > TextPreview


1 package org.enhydra.jawe;
2
3 import org.enhydra.jawe.graph.*;
4 import org.enhydra.jawe.xml.*;
5 import org.enhydra.jawe.xml.panels.*;
6 import org.enhydra.jawe.misc.*;
7
8 import org.jgraph.JGraph;
9 import org.jgraph.graph.*;
10 import org.jgraph.event.*;
11
12 import java.awt.*;
13 import java.awt.event.*;
14 import java.beans.*;
15 import java.net.URL JavaDoc;
16 import java.util.*;
17
18 import javax.swing.*;
19 import javax.swing.undo.*;
20 import javax.swing.event.*;
21 import javax.swing.tree.*;
22 import javax.swing.text.*;
23
24 import java.io.*;
25 import org.enhydra.jawe.actions.*;
26 import org.enhydra.jawe.*;
27 import org.enhydra.jawe.xml.elements.Package;
28
29 /**
30  * Represents text view in JaWE main window.
31  * @author Zoran Milakovic zoran@prozone.co.yu
32  * @version 1.0
33  */

34 public class TextPreview
35     extends XMLPanel {
36
37    private AbstractEditor editor;
38    private Component currentPane;
39    private JTextPane rightPaneCurrent;
40    private JScrollPane scrollPane = new JScrollPane();
41    private JMenuBar menuBar;
42    TextTreePanel treePanel;
43
44    public TextPreview( AbstractEditor editor ) {
45       super( editor.getGraph().getXMLPackage(), 2, "", XMLPanel.BOX_LAYOUT, true, false );
46       rightPaneCurrent = new JTextPane();
47       this.rightPaneCurrent.setBackground(Color.lightGray);
48       rightPaneCurrent.setSize( 500, 500 );
49       this.editor = editor;
50       treePanel = new TextTreePanel(
51           editor.getGraph().getXMLPackage(),
52           this,
53           ResourceManager.getLanguageDependentString( "PackageAndExternalPackagesXPDLKey" ) );
54       this.currentPane = createCenterComponent();
55       add( this.currentPane );
56    }
57
58
59    /**
60     * Create the center component of this panel. This creates a scroll-
61     * pane for the current graph variable and stores the scrollpane
62     * in the scrollPane variable.
63     */

64    protected Component createCenterComponent() {
65 // org.enhydra.jawe.xml.elements.Package
66
// xmlPackage = this.editor.getGraph().getXMLPackage();
67

68 // ( ( TextTreeModel )this.treePanel.getTreeModel() ).setRoot(
69
// editor.getGraph().getXMLPackage().getNode() );
70
//
71
// XMLUtil.initExpand(
72
// this.treePanel.getTree(),
73
// this.treePanel.getTree().getPathForLocation( 0, 0 )
74
// );
75
//
76
// //root node is always expanded
77
// XMLElement root = ( XMLElement ) ( ( ToNameMutableTreeNode )
78
// this.treePanel.getTree().getPathForLocation( 0, 0 ).
79
// getLastPathComponent() ).getUserObject();
80
// root.setCollapsed( false );
81

82       this.refreshView();
83
84       BarFactory barFactory = new BarFactory(editor);
85       barFactory.createViewActions(rightPaneCurrent);
86       menuBar = barFactory.createTextViewMenubar("Text_menu");
87
88       JPanel centerPane = new JPanel(new BorderLayout(5,5));
89
90       JSplitPane splitPane = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT );
91       splitPane.setLeftComponent( treePanel );
92       scrollPane.setViewportView( rightPaneCurrent );
93       splitPane.setRightComponent( scrollPane );
94       splitPane.setDividerLocation( 0.3 );
95
96       centerPane.add(menuBar, BorderLayout.NORTH);
97       centerPane.add(splitPane, BorderLayout.CENTER);
98       return centerPane;
99    }
100
101    public void refreshView() {
102       try {
103
104          ( ( TextTreeModel )this.treePanel.getTreeModel() ).setRoot(
105              editor.getGraph().getXMLPackage().getNode() );
106
107 //find out which nodes are expanded
108
XMLUtil.initExpand(
109              this.treePanel.getTree(),
110              this.treePanel.getTree().getPathForLocation( 0, 0 )
111              );
112
113 //root node is always expanded
114
XMLElement root = ( XMLElement ) ( ( ToNameMutableTreeNode )
115                                             this.treePanel.getTree().getPathForLocation( 0, 0 ).
116                                             getLastPathComponent() ).getUserObject();
117          root.setCollapsed( false );
118
119       }
120       catch ( Exception JavaDoc ex ) {
121          ex.printStackTrace();
122       }
123    }
124
125    public void display( XMLElement element ) {
126       try {
127
128          this.rightPaneCurrent.setEditable( false );
129          this.rightPaneCurrent.setFont( new Font( "Verdana", Font.PLAIN, 12 ) );
130          StyledDocument doc = this.rightPaneCurrent.getStyledDocument();
131          doc.remove(0, doc.getLength());
132          this.rightPaneCurrent.setText( element.getPrintDescription(doc) );
133 // element.getPrintDescription(doc);
134
// this.rightPaneCurrent.setDocument(doc);
135
this.rightPaneCurrent.setCaretPosition( 0 );
136
137       }
138       catch ( Exception JavaDoc ex ) {
139          ex.printStackTrace();
140       }
141    }
142
143    public TextTreePanel getTextTreePanel() {
144      return treePanel;
145    }
146
147    public JMenuBar getMenuBar() {
148       return menuBar;
149    }
150
151 }
152
Popular Tags