1 19 package org.netbeans.modules.xml.core.text; 20 21 import java.io.ObjectInput ; 22 import java.io.ObjectOutput ; 23 import java.io.IOException ; 24 import java.awt.event.FocusEvent ; 25 import java.awt.event.FocusListener ; 26 import java.beans.PropertyChangeEvent ; 27 import java.beans.PropertyChangeListener ; 28 import javax.swing.JEditorPane ; 29 import javax.swing.event.CaretEvent ; 30 import javax.swing.event.CaretListener ; 31 32 33 import org.openide.loaders.DataObject; 34 import org.openide.windows.CloneableTopComponent; 35 import org.openide.windows.Workspace; 36 import org.openide.windows.Mode; 37 import org.openide.windows.WindowManager; 38 import org.openide.text.CloneableEditor; 39 import org.openide.text.CloneableEditorSupport; 40 41 50 public class TextEditorComponent extends CloneableEditor { 51 52 53 private static final long serialVersionUID =5983822115073046891L; 54 55 56 private TextEditorSupport support; 57 58 59 private CaretListener caretListener; 60 61 62 66 67 public TextEditorComponent () { 68 super(); 69 } 70 71 72 public TextEditorComponent (TextEditorSupport editor) { 73 super (editor); 74 initialize(); 75 dockIntoEditorMode(); 76 } 77 78 79 83 88 89 private void initialize () { 90 91 putClientProperty("PersistenceType", "OnlyOpened"); 95 support = (TextEditorSupport)cloneableEditorSupport(); caretListener = new CaretListener () { 97 public void caretUpdate (CaretEvent e) { 98 support.restartTimer (true); 99 } 100 }; 101 if (pane != null) { pane.addFocusListener (new FocusListener () { 103 public void focusGained (FocusEvent e) { 104 } 105 public void focusLost (FocusEvent e) { 106 support.syncDocument (true); 107 } 108 }); 109 } 110 } 118 119 121 private void dockIntoEditorMode () { 122 Workspace current = WindowManager.getDefault().getCurrentWorkspace(); 124 Mode editorMode = current.findMode (CloneableEditorSupport.EDITOR_MODE); 125 if ( editorMode != null ) { 126 editorMode.dockInto (this); 127 } 128 } 129 130 137 145 146 150 protected void componentActivated () { 151 pane.addCaretListener (caretListener); 152 super.componentActivated(); 153 } 154 155 160 protected void componentDeactivated () { 161 pane.removeCaretListener (caretListener); 162 super.componentDeactivated(); 163 } 164 165 168 public void readExternal (ObjectInput in) throws IOException , ClassNotFoundException { 169 if ( Util.THIS.isLoggable() ) Util.THIS.debug ("TextEditorComponent.readExternal()"); 171 super.readExternal (in); 172 173 if ( Util.THIS.isLoggable() ) Util.THIS.debug (" .readExternal(): support = " + cloneableEditorSupport()); 175 initialize(); 176 177 if ( Util.THIS.isLoggable() ) Util.THIS.debug ("\tdone."); } 179 180 184 public void writeExternal (ObjectOutput out) throws IOException { 185 if ( Util.THIS.isLoggable() ) Util.THIS.debug ("TextEditorComponent.writeExternal(): support = " + cloneableEditorSupport()); 187 super.writeExternal (out); 188 189 if ( Util.THIS.isLoggable() ) Util.THIS.debug("\tdone."); } 191 192 } 193 | Popular Tags |