KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > multiview > XmlMultiViewElement


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.multiview;
21
22 import java.awt.Toolkit JavaDoc;
23 import org.openide.text.CloneableEditor;
24 import org.openide.text.NbDocument;
25 import org.openide.actions.SaveAction;
26 import org.openide.util.actions.SystemAction;
27 import org.openide.util.lookup.ProxyLookup;
28 import javax.swing.*;
29 import javax.swing.text.Document JavaDoc;
30 import java.awt.event.KeyEvent JavaDoc;
31 import java.awt.event.InputEvent JavaDoc;
32
33 /**
34  * XmlMultiviewElement.java
35  *
36  * Created on October 5, 2004, 1:35 PM
37  * @author mkuchtiak
38  */

39 public class XmlMultiViewElement extends AbstractMultiViewElement implements java.io.Serializable JavaDoc {
40     static final long serialVersionUID = -326467724916080580L;
41
42     private transient CloneableEditor xmlEditor;
43     private transient javax.swing.JComponent JavaDoc toolbar;
44
45     /** Creates a new instance of XmlMultiviewElement */
46     public XmlMultiViewElement() {
47     }
48
49     /** Creates a new instance of XmlMultiviewElement */
50     public XmlMultiViewElement(XmlMultiViewDataObject dObj) {
51         super(dObj);
52     }
53
54     public void componentDeactivated() {
55     }
56
57     public void componentHidden() {
58     }
59
60     public void componentActivated() {
61     }
62
63     public void componentShowing() {
64     }
65
66     public org.openide.util.Lookup getLookup() {
67         return new ProxyLookup(new org.openide.util.Lookup[] {
68             dObj.getNodeDelegate().getLookup()
69         });
70     }
71
72     public javax.swing.JComponent JavaDoc getToolbarRepresentation() {
73         if (toolbar == null) {
74             final JEditorPane editorPane = getXmlEditor().getEditorPane();
75             if (editorPane!= null) {
76                 final Document doc = editorPane.getDocument();
77                 if (doc instanceof NbDocument.CustomToolbar) {
78                     toolbar = ((NbDocument.CustomToolbar) doc).createToolbar(editorPane);
79                 }
80             }
81             if (toolbar == null) {
82                 // attempt to create own toolbar??
83
toolbar = new javax.swing.JPanel JavaDoc();
84             }
85         }
86         return toolbar;
87     }
88
89     public javax.swing.JComponent JavaDoc getVisualRepresentation() {
90         return getXmlEditor();
91     }
92
93     private CloneableEditor getXmlEditor() {
94         if (xmlEditor == null) {
95             xmlEditor = dObj.getEditorSupport().createCloneableEditor();
96             final ActionMap map = xmlEditor.getActionMap();
97             SaveAction act = (SaveAction) SystemAction.get(SaveAction.class);
98             KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
99             xmlEditor.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(stroke, "save"); //NOI18N
100
map.put("save", act); //NOI18N
101
}
102         return xmlEditor;
103     }
104 }
105
Popular Tags