A wrapEditorComponent
method has been added to
+ CloneableEditorSupport allowing to wrap the editor component
+ in another component.
Line.SHOW_TOFRONT
Index: manifest.mf
===================================================================
RCS file: /cvs/openide/text/manifest.mf,v
retrieving revision 1.4
diff -u -r1.4 manifest.mf
--- manifest.mf 29 Apr 2005 02:30:59 -0000 1.4
+++ manifest.mf 13 Jul 2005 12:35:35 -0000
@@ -1,5 +1,5 @@
Manifest-Version: 1.0
OpenIDE-Module: org.openide.text
-OpenIDE-Module-Specification-Version: 6.2
+OpenIDE-Module-Specification-Version: 6.3
OpenIDE-Module-Localizing-Bundle: org/openide/text/Bundle.properties
Index: src/org/openide/text/CloneableEditor.java
===================================================================
RCS file: /cvs/openide/text/src/org/openide/text/CloneableEditor.java,v
retrieving revision 1.4
diff -u -r1.4 CloneableEditor.java
--- src/org/openide/text/CloneableEditor.java 4 Jun 2005 05:16:54 -0000 1.4
+++ src/org/openide/text/CloneableEditor.java 13 Jul 2005 12:35:35 -0000
@@ -225,13 +225,13 @@
); // NOI18N
}
- add(customComponent, BorderLayout.CENTER);
+ add(support.wrapEditorComponent(customComponent), BorderLayout.CENTER);
} else { // not custom editor
// remove default JScrollPane border, borders are provided by window system
JScrollPane noBorderPane = new JScrollPane(pane);
pane.setBorder(null);
- add(noBorderPane, BorderLayout.CENTER);
+ add(support.wrapEditorComponent(noBorderPane), BorderLayout.CENTER);
}
if (doc instanceof NbDocument.CustomToolbar) {
Index: src/org/openide/text/CloneableEditorSupport.java
===================================================================
RCS file: /cvs/openide/text/src/org/openide/text/CloneableEditorSupport.java,v
retrieving revision 1.4
diff -u -r1.4 CloneableEditorSupport.java
--- src/org/openide/text/CloneableEditorSupport.java 7 Jul 2005 14:52:38 -0000 1.4
+++ src/org/openide/text/CloneableEditorSupport.java 13 Jul 2005 12:35:35 -0000
@@ -12,6 +12,7 @@
*/
package org.openide.text;
+import java.awt.Component;
import org.openide.DialogDisplayer;
import org.openide.ErrorManager;
import org.openide.NotifyDescriptor;
@@ -966,6 +967,26 @@
initializeCloneableEditor(ed);
return ed;
+ }
+
+ /**
+ * Wraps the editor component in a custom component, allowing for creating
+ * more complicated user interfaces which contain the editor UI in
+ * an arbitrary place.
+ *
+ * The default implementation merely returns the passed
+ * editorComponent
parameter.
editorComponent
or
+ * editorComponent
itself.
+ *
+ * @since 6.3
+ */
+ protected Component wrapEditorComponent(Component editorComponent) {
+ return editorComponent;
}
/** Should test whether all data is saved, and if not, prompt the user
Index: test/unit/src/org/openide/text/CloneableEditorSupportTest.java
===================================================================
RCS file: /cvs/openide/text/test/unit/src/org/openide/text/CloneableEditorSupportTest.java,v
retrieving revision 1.1
diff -u -r1.1 CloneableEditorSupportTest.java
--- test/unit/src/org/openide/text/CloneableEditorSupportTest.java 22 Apr 2005 09:44:28 -0000 1.1
+++ test/unit/src/org/openide/text/CloneableEditorSupportTest.java 13 Jul 2005 12:35:35 -0000
@@ -157,6 +157,14 @@
assertGC ("Document can dissapear", ref);
}
+ /**
+ * Tests that the placeEditorComponent method returns the passed
+ * parameter (doesn't place the passed component in some additional UI).
+ */
+ public void testPlaceEditorComponent() {
+ javax.swing.JPanel panel = new javax.swing.JPanel();
+ assertSame(support.wrapEditorComponent(panel), panel);
+ }
private void compareStreamWithString(InputStream is, String s) throws Exception{
int i;
Index: test/unit/src/org/openide/text/NbLikeEditorKit.java
===================================================================
RCS file: /cvs/openide/text/test/unit/src/org/openide/text/NbLikeEditorKit.java,v
retrieving revision 1.1
diff -u -r1.1 NbLikeEditorKit.java
--- test/unit/src/org/openide/text/NbLikeEditorKit.java 22 Apr 2005 09:44:30 -0000 1.1
+++ test/unit/src/org/openide/text/NbLikeEditorKit.java 13 Jul 2005 12:35:35 -0000
@@ -24,12 +24,12 @@
*
* @author Jaroslav Tulach
*/
-final class NbLikeEditorKit extends DefaultEditorKit {
+class NbLikeEditorKit extends DefaultEditorKit {
public javax.swing.text.Document createDefaultDocument() {
return new Doc ();
}
- private final class Doc extends PlainDocument
+ class Doc extends PlainDocument
implements NbDocument.WriteLockable, StyledDocument {
// implements NbDocument.PositionBiasable, NbDocument.WriteLockable,
// NbDocument.Printable, NbDocument.CustomEditor, NbDocument.CustomToolbar, NbDocument.Annotatable {
Index: test/unit/src/org/openide/text/WrapEditorComponentTest.java
===================================================================
RCS file: test/unit/src/org/openide/text/WrapEditorComponentTest.java
diff -N test/unit/src/org/openide/text/WrapEditorComponentTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ test/unit/src/org/openide/text/WrapEditorComponentTest.java 13 Jul 2005 12:35:35 -0000
@@ -0,0 +1,227 @@
+/*
+ * 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-2005 Sun
+ * Microsystems, Inc. All Rights Reserved.
+ */
+
+package org.openide.text;
+
+import java.awt.BorderLayout;
+import java.awt.Component;
+import javax.swing.JEditorPane;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.text.Document;
+import javax.swing.text.EditorKit;
+import org.netbeans.junit.NbTestCase;
+import org.openide.util.Lookup;
+import org.openide.windows.CloneableTopComponent;
+
+/**
+ * Tests that the CloneableEditorSupport.wrapEditorComponent() method
+ * is called by CloneableEditor and its result value used.
+ *
+ * @author Andrei Badea
+ */
+public class WrapEditorComponentTest extends NbTestCase
+implements CloneableEditorSupport.Env {
+
+ private String content = "";
+ private boolean valid = true;
+ private boolean modified = false;
+ private java.util.Date date = new java.util.Date ();
+
+ private WrapEditorComponentCES support;
+
+ public WrapEditorComponentTest(String s) {
+ super(s);
+ }
+
+ protected void setUp() {
+ support = new WrapEditorComponentCES(this, Lookup.EMPTY);
+ }
+
+ protected boolean runInEQ() {
+ return true;
+ }
+
+ /**
+ * Tests the wrapEditorComponent() method is called for a default editor.
+ */
+ public void testWrapEditorComponentInDefaultEditor() {
+ searchForWrapperComponent();
+ }
+
+ /**
+ * Tests the wrapEditorComponent() method is called for a custom editor
+ */
+ public void testWrapEditorComponentInCustomEditor() {
+ // first make the support return a document which has a custom editor
+ support.setEditorKit(new NbLikeEditorKitWithCustomEditor());
+
+ searchForWrapperComponent();
+ }
+
+ /**
+ * Helper method which opens the support and searches for the wrapper
+ * component.
+ */
+ private void searchForWrapperComponent() {
+ support.open();
+
+ CloneableEditor ed = (CloneableEditor)support.getRef ().getAnyComponent();
+ Component component = ed.getEditorPane();
+
+ boolean found = false;
+ while (component != ed) {
+ if (WrapEditorComponentCES.WRAPPER_NAME.equals(component.getName())) {
+ found = true;
+ break;
+ }
+ component = component.getParent();
+ }
+
+ assertTrue("The panel containing the editor was not found in the TopComponent.", found);
+
+ support.close();
+ }
+
+ //
+ // Implementation of the CloneableEditorSupport.Env
+ //
+
+ public synchronized void addPropertyChangeListener(java.beans.PropertyChangeListener l) {
+ }
+
+ public synchronized void removePropertyChangeListener(java.beans.PropertyChangeListener l) {
+ }
+
+ public synchronized void addVetoableChangeListener(java.beans.VetoableChangeListener l) {
+ }
+
+ public void removeVetoableChangeListener(java.beans.VetoableChangeListener l) {
+ }
+
+ public org.openide.windows.CloneableOpenSupport findCloneableOpenSupport() {
+ return support;
+ }
+
+ public String getMimeType() {
+ return "text/plain";
+ }
+
+ public java.util.Date getTime() {
+ return date;
+ }
+
+ public java.io.InputStream inputStream() throws java.io.IOException {
+ return new java.io.ByteArrayInputStream (content.getBytes ());
+ }
+ public java.io.OutputStream outputStream() throws java.io.IOException {
+ class ContentStream extends java.io.ByteArrayOutputStream {
+ public void close () throws java.io.IOException {
+ super.close ();
+ content = new String (toByteArray ());
+ }
+ }
+
+ return new ContentStream ();
+ }
+
+ public boolean isValid() {
+ return valid;
+ }
+
+ public boolean isModified() {
+ return modified;
+ }
+
+ public void markModified() throws java.io.IOException {
+ modified = true;
+ }
+
+ public void unmarkModified() {
+ modified = false;
+ }
+
+ /**
+ * Implementation of the CES which overrides the wrapEditorComponent()
+ * method, wrapping the editor in a component named WRAPPER_NAME.
+ */
+ private static final class WrapEditorComponentCES extends CloneableEditorSupport {
+
+ public static final String WRAPPER_NAME = "panelWrappingTheEditor";
+
+ private EditorKit kit;
+
+ public WrapEditorComponentCES(Env env, Lookup l) {
+ super(env, l);
+ }
+
+ protected Component wrapEditorComponent(Component editorComponent) {
+ JPanel panel = new JPanel(new BorderLayout());
+ panel.setName(WRAPPER_NAME);
+ panel.add(editorComponent, BorderLayout.CENTER);
+ return panel;
+ }
+
+ protected EditorKit createEditorKit() {
+ if (kit != null) {
+ return kit;
+ } else {
+ return super.createEditorKit();
+ }
+ }
+
+ public void setEditorKit(EditorKit kit) {
+ this.kit = kit;
+ }
+
+ public CloneableTopComponent.Ref getRef () {
+ return allEditors;
+ }
+
+ protected String messageName() {
+ return "Name";
+ }
+
+ protected String messageOpened() {
+ return "Opened";
+ }
+
+ protected String messageOpening() {
+ return "Opening";
+ }
+
+ protected String messageSave() {
+ return "Save";
+ }
+
+ protected String messageToolTip() {
+ return "ToolTip";
+ }
+ }
+
+ private final static class NbLikeEditorKitWithCustomEditor extends NbLikeEditorKit {
+
+ public Document createDefaultDocument() {
+ return new CustomDoc();
+ }
+
+ private final class CustomDoc extends Doc implements NbDocument.CustomEditor {
+
+ public Component createEditor(JEditorPane j) {
+ JScrollPane result = new JScrollPane();
+ result.add(j);
+ return result;
+ }
+ }
+ }
+}