Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: openfuture/editxml/applet/MainPanel.java


1   package openfuture.editxml.applet;
2   
3   /*
4    * This library is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Lesser General Public
6    * License as published by the Free Software Foundation; either
7    * version 2 of the License, or (at your option) any later version.<p>
8    *
9    * This library is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   * Lesser General Public License for more details.<p>
13   *
14   * You should have received a copy of the GNU Lesser General Public
15   * License along with this library; if not, write to the Free Software
16   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA<br>
17   * http://www.gnu.org/copyleft/lesser.html
18   */
19  
20  import java.io.IOException;
21  import java.util.Locale;
22  import java.util.ResourceBundle;
23  import javax.swing.JEditorPane;
24  import javax.swing.JTabbedPane;
25  import javax.swing.text.Document;
26  import openfuture.util.misc.DocumentHistory;
27  
28  /**
29   * Configuration Management Information: 
30   * -------------------------------------
31   * $Id: MainPanel.java,v 1.5 2001/09/29 18:05:12 wreissen Exp $
32   *
33   * Version History:
34   * ----------------
35   * $Log: MainPanel.java,v $
36   * Revision 1.5  2001/09/29 18:05:12  wreissen
37   * undo handling moved to class DocumentHistory
38   *
39   * Revision 1.4  2001/09/24 21:33:33  wreissen
40   * TextEditorPanel replaces the JEditorPanel as the text editor.
41   *
42   * Revision 1.3  2001/07/22 09:23:56  wreissen
43   * - resource bundle usage added
44   * - HTML editor events integrated
45   *
46   * Revision 1.2  2001/07/08 20:27:00  wreissen
47   * access to the editors added.
48   *
49   * Revision 1.1.1.1  2001/07/08 18:29:29  wreissen
50   * initial version registered ad SourceForge
51   *
52   *
53   */
54  
55  /**
56   * Panel holding the for the XML editors.<p>
57   *
58   *
59   * Created: Sun Jul 01 22:44:10 2001
60   *
61   * @author <a href="mailto: wolfgang@openfuture.de">Wolfgang Reissenberger</a>
62   * @version $Revision: 1.5 $
63   */
64  
65  public class MainPanel extends JTabbedPane {
66  
67      protected JEditorPane htmlEditor;
68      protected TextEditorPanel textEditor;
69  
70      public static String HTML_EDITOR = "HTML Editor";
71  
72      /**
73       * Creates a new <code>MainPanel</code> instance.
74       *
75       * @param controller the controller of this panel
76       * @param resourceBundle the current resource bundle
77       * @param locale the current locale
78       * @param imagedirURL URL of the image directory
79       */
80      public MainPanel (RootController controller, ResourceBundle resourceBundle,
81            Locale locale, String imagedirURL) {
82    super();
83    init(controller, resourceBundle, locale, imagedirURL);
84      }
85  
86      /**
87       * Initialize the panel.
88       *
89       * @param rootController the root controller of this panel
90       * @param resourceBundle the current resource bundle
91       * @param locale the current locale
92       * @param imagedirURL URL of the image directory
93       */
94      public void init(RootController rootController,
95           ResourceBundle resourceBundle,
96           Locale locale, String imagedirURL) {
97  
98    setHtmlEditor(new JEditorPane("text/html", "Welcome to <strong>Edit XML</strong>."));
99    getHtmlEditor().setEditable(false);
100   getHtmlEditor().setName(HTML_EDITOR);
101 
102   EditorController controller = new EditorController(this, resourceBundle,
103                  rootController);
104 
105   TextEditorPanel textEditorPanel = new TextEditorPanel(controller,
106                     resourceBundle,
107                     locale,
108                     imagedirURL);
109   setTextEditor(textEditorPanel);
110 
111   this.addTab(resourceBundle.getString("title.texteditor"), textEditorPanel);
112   this.addTab(resourceBundle.getString("title.htmleditor"), getHtmlEditor());
113 
114   getModel().addChangeListener(controller);
115     }
116 
117     /**
118      * Set the content of the editor panels.
119      *
120      * @param content editor content
121      */
122     public void setContent(String content) {
123   getHtmlEditor().setText(content);
124   getTextEditor().setText(EditorController.extractHtmlBody(getHtmlEditor().getText()));
125   
126     }
127 
128     /**
129      * Retrieve the content of the editor panel
130      *
131      * @return HTML fragment as textual content
132      */
133     public String getContent() {
134   return(getTextEditor().getEditor().getText());
135     }
136 
137 
138     /**
139      * Set the document of the editor panels.
140      *
141      * @param document editor document
142      */
143     public void setDocumentHistory(DocumentHistory history) {
144   //
145   getTextEditor().setDocumentHistory(history);
146   getHtmlEditor().setText(getContent());
147   
148     }
149 
150     /**
151      * Retrieve the text document of the editor panel
152      *
153      * @return the panel's document
154      */
155     public DocumentHistory getDocumentHistory() {
156   return(getTextEditor().getDocumentHistory());
157     }
158 
159 
160     /**
161      * Refresh the display. Actually calls 
162      * {@link openfuture.editxml.applet.TextEditorPanel#refreshView()
163      *        TextEditorPanel.refreshView()}
164      *
165      */
166     public void refreshView() {
167   getTextEditor().refreshView();
168     }
169 
170 
171     /**
172      * Get the value of textEditor.
173      * @return value of textEditor.
174      */
175     public TextEditorPanel getTextEditor() {
176   return textEditor;
177     }
178     
179     /**
180      * Set the value of textEditor.
181      * @param v  Value to assign to textEditor.
182      */
183     public void setTextEditor(TextEditorPanel  v) {
184   this.textEditor = v;
185     }
186     
187     /**
188      * Get the value of htmlEditor.
189      * @return value of htmlEditor.
190      */
191     public JEditorPane getHtmlEditor() {
192   return htmlEditor;
193     }
194 
195     /**
196      * Set the value of htmlEditor.
197      * @param v  Value to assign to htmlEditor.
198      */
199     public void setHtmlEditor(JEditorPane  v) {
200   this.htmlEditor = v;
201     }
202 
203 }// MainPanel