1 19 20 package org.netbeans.modules.xml.multiview; 21 22 import java.awt.Toolkit ; 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 ; 30 import java.awt.event.KeyEvent ; 31 import java.awt.event.InputEvent ; 32 33 39 public class XmlMultiViewElement extends AbstractMultiViewElement implements java.io.Serializable { 40 static final long serialVersionUID = -326467724916080580L; 41 42 private transient CloneableEditor xmlEditor; 43 private transient javax.swing.JComponent toolbar; 44 45 46 public XmlMultiViewElement() { 47 } 48 49 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 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 toolbar = new javax.swing.JPanel (); 84 } 85 } 86 return toolbar; 87 } 88 89 public javax.swing.JComponent 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"); map.put("save", act); } 102 return xmlEditor; 103 } 104 } 105 | Popular Tags |