alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
 * Microsystems, Inc. All Rights Reserved.
 */
package org.netbeans.modules.xml.core.text;

import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.IOException;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JEditorPane;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;


import org.openide.loaders.DataObject;
import org.openide.windows.CloneableTopComponent;
import org.openide.windows.Workspace;
import org.openide.windows.Mode;
import org.openide.windows.WindowManager;
import org.openide.text.CloneableEditor;
import org.openide.text.CloneableEditorSupport;

/**
 * CloneableEditor subclass taking care about listening and delegating these event to
 * support.
 * 

* Listens at: DataObject, caret * * @author Libor Kramolis * @version 0.1 */ public class TextEditorComponent extends CloneableEditor { /** Serial Version UID */ private static final long serialVersionUID =5983822115073046891L; /** The support, subclass of EditorSupport */ private TextEditorSupport support; /** Listener on caret movements */ private CaretListener caretListener; // // init // /** Only for externalization */ public TextEditorComponent () { super(); } /** Creates new editor */ public TextEditorComponent (TextEditorSupport editor) { super (editor); initialize(); dockIntoEditorMode(); } // // itself // // // called from inner class -- to be 1.2 compiler happy // protected void updateName () { // super.updateName(); // } /** Obtain a support for this component */ private void initialize () { //#25368 there is memory leak in window system for default persistence type // anyway remember position only for opened components putClientProperty("PersistenceType", "OnlyOpened"); // NOI18N support = (TextEditorSupport)cloneableEditorSupport(); //(TextEditorSupport)obj.getCookie (TextEditorSupport.class); caretListener = new CaretListener() { public void caretUpdate (CaretEvent e) { support.restartTimer (true); } }; if (pane != null) { //??? what if does not exist pane.addFocusListener (new FocusListener () { public void focusGained (FocusEvent e) { } public void focusLost (FocusEvent e) { support.syncDocument (true); } }); } // support.getDataObject().addPropertyChangeListener (new PropertyChangeListener () { // public void propertyChange (PropertyChangeEvent ev) { // if (DataObject.PROP_NAME.equals (ev.getPropertyName())) { // TextEditorComponent.this.updateName(); // } // } // }); } /** */ private void dockIntoEditorMode () { // dock into editor mode if possible Workspace current = WindowManager.getDefault().getCurrentWorkspace(); Mode editorMode = current.findMode (CloneableEditorSupport.EDITOR_MODE); if ( editorMode != null ) { editorMode.dockInto (this); } } // /** Returns Editor pane for private use. // * @return Editor pane for private use. // */ // private JEditorPane getEditorPane () { // return pane; // } // /* Is called from the clone method to create new component from this one. // * This implementation only clones the object by calling super.clone method. // * @return the copy of this object // */ // protected CloneableTopComponent createClonedObject () { // return support.createTextEditorComponent(); // } /* This method is called when parent window of this component has focus, * and this component is preferred one in it. This implementation adds * performer to the ToggleBreakpointAction. */ protected void componentActivated () { pane.addCaretListener (caretListener); super.componentActivated(); } /* * This method is called when parent window of this component losts focus, * or when this component losts preferrence in the parent window. This * implementation removes performer from the ToggleBreakpointAction. */ protected void componentDeactivated () { pane.removeCaretListener (caretListener); super.componentDeactivated(); } /** Deserialize this top component. * @param in the stream to deserialize from */ public void readExternal (ObjectInput in) throws IOException, ClassNotFoundException { if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("TextEditorComponent.readExternal()"); // NOI18N super.readExternal (in); if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug (" .readExternal(): support = " + cloneableEditorSupport()); // NOI18N initialize(); if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("\tdone."); // NOI18N } /** Serialize this top component. * Subclasses wishing to store state must call the super method, then write to the stream. * @param out the stream to serialize to */ public void writeExternal (ObjectOutput out) throws IOException { if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("TextEditorComponent.writeExternal(): support = " + cloneableEditorSupport()); // NOI18N super.writeExternal (out); if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug("\tdone."); // NOI18N } }

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.