KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mc4j > console > swing > editor > xml > JEditorTest


1 /*
2  * Copyright 2002-2004 Greg Hinkle
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.mc4j.console.swing.editor.xml;
18
19 /**
20  * @author Greg Hinkle (ghinkle@users.sourceforge.net), Nov 16, 2004
21  * @version $Revision: 570 $($Author: ghinkl $ / $Date: 2006-04-12 15:14:16 -0400 (Wed, 12 Apr 2006) $)
22  */

23
24 import javax.swing.*;
25 import javax.swing.text.StyledEditorKit JavaDoc;
26 import java.awt.*;
27 import java.io.File JavaDoc;
28 import java.io.FileReader JavaDoc;
29 import java.io.IOException JavaDoc;
30
31 public class JEditorTest extends JPanel {
32
33     public JEditorTest(File JavaDoc file)
34         throws IOException JavaDoc {
35         //KeywordManager.loadKeywordFiles();
36
StyledEditorKit JavaDoc kit = null;
37         if (file.getName().toLowerCase().endsWith(".xml")) {
38             kit = new XMLStyleTokens.Kit();
39         }
40
41         JEditorPane editor = new JEditorPane();
42         editor.setEditorKit(kit);
43         editor.read(new FileReader JavaDoc(file), null);
44
45         ((EditorDocument)editor.getDocument()).setValidating(true);
46
47         setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
48         setLayout(new GridLayout());
49         add(new JScrollPane(editor));
50     }
51
52     public static void main(String JavaDoc[] args)
53         throws IOException JavaDoc {
54         File JavaDoc file = new File JavaDoc("org/mc4j/console/swing/editor/xml/BasicMBean.xml");
55         JFrame frame = new JFrame("JEditor Test");
56         frame.getContentPane().setLayout(new BorderLayout());
57         frame.getContentPane().add(new JEditorTest(file),BorderLayout.CENTER);
58         frame.setSize(700, 550);
59         frame.setVisible(true);
60         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
61     }
62 }
63
Popular Tags