You are viewing a plain text version of this content. The canonical link for it is here.
Posted to muse-dev@ws.apache.org by wi...@apache.org on 2005/08/24 03:12:41 UTC

svn commit: r239497 - in /webservices/muse/trunk/src/examples/ieeedemo/client/src/org/apache/interop/common/ui/xmleditorkit: ./ HTMLKit.java JavaKit.java PlainKit.java

Author: wire
Date: Tue Aug 23 18:12:36 2005
New Revision: 239497

URL: http://svn.apache.org/viewcvs?rev=239497&view=rev
Log:
New Editor Kits

Added:
    webservices/muse/trunk/src/examples/ieeedemo/client/src/org/apache/interop/common/ui/xmleditorkit/
    webservices/muse/trunk/src/examples/ieeedemo/client/src/org/apache/interop/common/ui/xmleditorkit/HTMLKit.java
    webservices/muse/trunk/src/examples/ieeedemo/client/src/org/apache/interop/common/ui/xmleditorkit/JavaKit.java
    webservices/muse/trunk/src/examples/ieeedemo/client/src/org/apache/interop/common/ui/xmleditorkit/PlainKit.java

Added: webservices/muse/trunk/src/examples/ieeedemo/client/src/org/apache/interop/common/ui/xmleditorkit/HTMLKit.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/ieeedemo/client/src/org/apache/interop/common/ui/xmleditorkit/HTMLKit.java?rev=239497&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/ieeedemo/client/src/org/apache/interop/common/ui/xmleditorkit/HTMLKit.java (added)
+++ webservices/muse/trunk/src/examples/ieeedemo/client/src/org/apache/interop/common/ui/xmleditorkit/HTMLKit.java Tue Aug 23 18:12:36 2005
@@ -0,0 +1,129 @@
+package org.apache.interop.common.ui.xmleditorkit;
+
+import java.util.Map;
+import java.awt.event.KeyEvent;
+import java.awt.event.InputEvent;
+import java.awt.event.ActionEvent;
+import javax.swing.Action;
+import javax.swing.KeyStroke;
+import javax.swing.text.Caret;
+import javax.swing.text.Document;
+import javax.swing.text.TextAction;
+import javax.swing.text.JTextComponent;
+import javax.swing.text.html.parser.*;
+import org.netbeans.editor.*;
+import org.netbeans.editor.ext.*;
+import org.netbeans.editor.ext.html.*;
+
+/**
+* Editor kit implementation for HTML content type
+*
+* @author Miloslav Metelka
+* @version 0.01
+*/
+
+public class HTMLKit extends ExtKit {
+
+    static final long serialVersionUID =-1381945567613910297L;
+
+    public static final String HTML_MIME_TYPE = "text/html"; // NOI18N
+
+    public static final String shiftInsertBreakAction = "shift-insert-break"; // NOI18N
+
+    static {
+        Settings.addInitializer( new HTMLSettingsInitializer( HTMLKit.class ) );
+        Settings.addInitializer( new SaHTMLSettingsInitializer() );
+        Settings.reset();
+    }
+
+    public HTMLKit() {
+        super();
+        //DTD myDTD = new DTDcreator().createDTD( "My" );
+    }
+
+    protected void initDocument(BaseDocument doc)
+    {
+        super.initDocument(doc);
+        JavaKit.JKitUndoManager mgr = new JavaKit.JKitUndoManager(doc);
+        doc.putProperty(BaseDocument.UNDO_MANAGER_PROP,mgr); 
+        doc.addUndoableEditListener(mgr);
+    }
+    public String getContentType() {
+        return HTML_MIME_TYPE;
+    }
+
+    /** Create new instance of syntax coloring scanner
+    * @param doc document to operate on. It can be null in the cases the syntax
+    *   creation is not related to the particular document
+    */
+    public Syntax createSyntax(Document doc) {
+        return new HTMLSyntax();
+    }
+
+    /** Create syntax support */
+    public SyntaxSupport createSyntaxSupport(BaseDocument doc) {
+        return new HTMLSyntaxSupport(doc);
+    }
+
+    public Completion createCompletion(ExtEditorUI extEditorUI) {
+        return new HTMLCompletion(extEditorUI);
+    }
+
+    protected Action[] createActions() {
+        Action[] HTMLActions = new Action[] {
+                                   //new ExtDefaultKeyTypedAction(),
+                                   new HTMLShiftBreakAction()
+                               };
+
+//       System.out.println("\n\n\nCreating actions!!!!!!!!");
+
+        return TextAction.augmentList(super.createActions(), HTMLActions);
+    }
+
+
+    public static class HTMLShiftBreakAction extends BaseAction {
+
+        static final long serialVersionUID =4004043376345356061L;
+
+        public HTMLShiftBreakAction() {
+            super( shiftInsertBreakAction, ABBREV_RESET
+                  | MAGIC_POSITION_RESET | UNDO_MERGE_RESET);
+        }
+
+        public void actionPerformed(ActionEvent evt, JTextComponent target) {
+            if (target != null) {
+                Completion completion = ExtUtilities.getCompletion(target);
+                if (completion != null && completion.isPaneVisible()) {
+                    if (completion.substituteText( true )) {
+                        completion.setPaneVisible(false);
+                    } else {
+                        completion.refresh(false);
+                    }
+                }
+            }
+        }
+
+    }
+
+    private static class SaHTMLSettingsInitializer extends Settings.AbstractInitializer {
+        public SaHTMLSettingsInitializer() {
+            super( "sa-html-settings-initializer" );
+        }
+
+        public void updateSettingsMap(Class kitClass, Map settingsMap) {
+            if (kitClass == HTMLKit.class) {
+                SettingsUtil.updateListSetting(settingsMap, SettingsNames.KEY_BINDING_LIST, getHTMLKeyBindings());
+            }
+        }
+
+        public MultiKeyBinding[] getHTMLKeyBindings() {
+            return new MultiKeyBinding[] {
+                new MultiKeyBinding(
+                    KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_MASK),
+                    HTMLKit.shiftInsertBreakAction
+                )
+            };
+        }
+    }
+
+}

Added: webservices/muse/trunk/src/examples/ieeedemo/client/src/org/apache/interop/common/ui/xmleditorkit/JavaKit.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/ieeedemo/client/src/org/apache/interop/common/ui/xmleditorkit/JavaKit.java?rev=239497&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/ieeedemo/client/src/org/apache/interop/common/ui/xmleditorkit/JavaKit.java (added)
+++ webservices/muse/trunk/src/examples/ieeedemo/client/src/org/apache/interop/common/ui/xmleditorkit/JavaKit.java Tue Aug 23 18:12:36 2005
@@ -0,0 +1,398 @@
+/*
+ *                 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-2000 Sun
+ * Microsystems, Inc. All Rights Reserved.
+ */
+
+package org.apache.interop.common.ui.xmleditorkit;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.InputEvent;
+import java.awt.event.KeyEvent;
+import java.io.File;
+import java.util.Map;
+
+import javax.swing.Action;
+import javax.swing.KeyStroke;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
+import javax.swing.text.JTextComponent;
+import javax.swing.text.TextAction;
+import javax.swing.undo.CannotUndoException;
+import javax.swing.undo.UndoManager;
+import javax.swing.undo.UndoableEdit;
+
+import org.netbeans.editor.ActionFactory;
+import org.netbeans.editor.BaseAction;
+import org.netbeans.editor.BaseDocument;
+import org.netbeans.editor.BaseKit;
+import org.netbeans.editor.EditorUI;
+import org.netbeans.editor.Formatter;
+import org.netbeans.editor.MultiKeyBinding;
+import org.netbeans.editor.Settings;
+import org.netbeans.editor.SettingsNames;
+import org.netbeans.editor.SettingsUtil;
+import org.netbeans.editor.Syntax;
+import org.netbeans.editor.SyntaxSupport;
+import org.netbeans.editor.Utilities;
+import org.netbeans.editor.ext.Completion;
+import org.netbeans.editor.ext.ExtEditorUI;
+import org.netbeans.editor.ext.ExtKit;
+import org.netbeans.editor.ext.java.JavaCompletion;
+import org.netbeans.editor.ext.java.JavaDrawLayerFactory;
+import org.netbeans.editor.ext.java.JavaFormatter;
+import org.netbeans.editor.ext.java.JavaSettingsInitializer;
+import org.netbeans.editor.ext.java.JavaSyntax;
+import org.netbeans.editor.ext.java.JavaSyntaxSupport;
+
+/**
+* Java editor kit with appropriate document
+*
+* @author Miloslav Metelka
+* @version 1.00
+*/
+
+public class JavaKit extends ExtKit {
+
+    public static final String JAVA_MIME_TYPE = "text/x-java"; // NOI18N
+
+    private static final String[] getSetIsPrefixes = new String[] {
+                "get", "set", "is"
+            };
+
+    /** Switch first letter of word to capital and insert 'get'
+    * at word begining.
+    */
+    public static final String makeGetterAction = "make-getter"; // NOI18N
+
+    /** Switch first letter of word to capital and insert 'set'
+    * at word begining.
+    */
+    public static final String makeSetterAction = "make-setter"; // NOI18N
+
+    /** Switch first letter of word to capital and insert 'is'
+    * at word begining.
+    */
+    public static final String makeIsAction = "make-is"; // NOI18N
+
+    /** Debug source and line number */
+    public static final String abbrevDebugLineAction = "abbrev-debug-line"; // NOI18N
+
+    static final long serialVersionUID =-5445829962533684922L;
+
+    static {
+        Settings.addInitializer( new JavaSettingsInitializer( JavaKit.class ) );
+        Settings.addInitializer( new SaJavaSettingsInitializer() );
+        Settings.reset();
+/*
+        ResourceBundle settings = ResourceBundle.getBundle( "settings" );
+        String jcPath = null;
+        try {
+            jcPath = settings.getString( "Java_Completion" );
+        } catch( MissingResourceException exc ) {}
+
+        if( jcPath != null ) {
+            JCBaseFinder finder = new JCBaseFinder();
+            JCFileProvider provider = new JCFileProvider( jcPath );
+            //testing... inserted by Simeon
+            String openPath = "d:\\NbBuild001\\system\\ParserDB\\OpenAPIs";
+            JCFileProvider provider2 = new JCFileProvider(openPath);
+            finder.append( provider );
+            finder.append(provider2);
+            JavaCompletion.setFinder( finder );
+        }
+ */
+    }
+    
+/*protected void addAction(JTextComponent target, JPopupMenu popupMenu,
+        String actionName) 
+    {
+        System.out.println("Adding action - " + actionName);
+        super.addAction(target,popupMenu,actionName);
+    }*/
+    
+    public String getContentType() {
+        return JAVA_MIME_TYPE;
+    }
+
+    /** Create new instance of syntax coloring scanner
+    * @param doc document to operate on. It can be null in the cases the syntax
+    *   creation is not related to the particular document
+    */
+    public Syntax createSyntax(Document doc) {
+        return new JavaSyntax();
+    }
+
+    /** Create syntax support */
+    public SyntaxSupport createSyntaxSupport(BaseDocument doc) {
+        return new JavaSyntaxSupport(doc);
+    }
+
+    public Completion createCompletion(ExtEditorUI extEditorUI) {
+        return new JavaCompletion(extEditorUI);
+    }
+
+    /** Create the formatter appropriate for this kit */
+    public Formatter createFormatter() {
+        return new JavaFormatter(this.getClass());
+    }
+
+    protected EditorUI createEditorUI() {
+        return new ExtEditorUI();
+    }
+
+    protected void initDocument(BaseDocument doc) {
+        doc.addLayer(new JavaDrawLayerFactory.JavaLayer(),
+                JavaDrawLayerFactory.JAVA_LAYER_VISIBILITY);
+        doc.addDocumentListener(new JavaDrawLayerFactory.LParenWatcher());
+        JKitUndoManager mgr = new JKitUndoManager(doc);
+        doc.putProperty(BaseDocument.UNDO_MANAGER_PROP,mgr); 
+        doc.addUndoableEditListener(mgr);
+    }
+
+    protected Action[] createActions() {
+        Action[] javaActions = new Action[] {
+                                   new JavaDefaultKeyTypedAction(),
+                                   new PrefixMakerAction(makeGetterAction, "get", getSetIsPrefixes),
+                                   new PrefixMakerAction(makeSetterAction, "set", getSetIsPrefixes),
+                                   new PrefixMakerAction(makeIsAction, "is", getSetIsPrefixes),
+                                   new AbbrevDebugLineAction(),
+                                   new NbUndoAction(),
+                                   new NbRedoAction()
+                               };
+//       System.out.println("\n\n\nCreating actions!!!!!!!!");
+        return TextAction.augmentList(super.createActions(), javaActions);
+    }
+
+
+    public static class JavaDefaultKeyTypedAction extends ExtDefaultKeyTypedAction {
+
+        protected void checkIndentHotChars(JTextComponent target, String typedText) {
+            boolean reindent = false;
+
+            BaseDocument doc = Utilities.getDocument(target);
+            int dotPos = target.getCaret().getDot();
+            if (doc != null) {
+                /* Check whether the user has written the ending 'e'
+                 * of the first 'else' on the line.
+                 */
+                if ("e".equals(typedText)) {
+                    try {
+                        int fnw = Utilities.getRowFirstNonWhite(doc, dotPos);
+                        if (fnw >= 0 && fnw + 4 == dotPos
+                            && "else".equals(doc.getText(fnw, 4))
+                        ) {
+                            reindent = true;
+                        }
+                    } catch (BadLocationException e) {
+                    }
+
+                } else if (":".equals(typedText)) {
+                    try {
+                        int fnw = Utilities.getRowFirstNonWhite(doc, dotPos);
+                        if (fnw >= 0 && fnw + 4 <= doc.getLength()
+                            && "case".equals(doc.getText(fnw, 4))
+                        ) {
+                            reindent = true;
+                        }
+                    } catch (BadLocationException e) {
+                    }
+                }
+
+                // Reindent the line if necessary
+                if (reindent) {
+                    try {
+                        Utilities.reformatLine(doc, dotPos);
+                    } catch (BadLocationException e) {
+                    }
+                }
+            }
+
+            super.checkIndentHotChars(target, typedText);
+        }
+
+    }
+
+
+
+    public static class AbbrevDebugLineAction extends BaseAction {
+
+        public AbbrevDebugLineAction() {
+            super(abbrevDebugLineAction);
+        }
+
+        public void actionPerformed(ActionEvent evt, JTextComponent target) {
+            if (target != null) {
+                if (!target.isEditable() || !target.isEnabled()) {
+                    target.getToolkit().beep();
+                    return;
+                }
+                BaseDocument doc = (BaseDocument)target.getDocument();
+                StringBuffer sb = new StringBuffer("System.err.println(\""); // NOI18N
+                File file = (File)doc.getProperty( "file" );
+                if (file != null) {
+                    sb.append( file.getAbsolutePath() );
+                    sb.append(':');
+                }
+                try {
+                    sb.append(Utilities.getLineOffset(doc, target.getCaret().getDot()) + 1);
+                } catch (BadLocationException e) {
+                }
+                sb.append(' ');
+
+                BaseKit kit = Utilities.getKit(target);
+                Action a = kit.getActionByName(BaseKit.insertContentAction);
+                if (a != null) {
+                    Utilities.performAction(
+                        a,
+                        new ActionEvent(target, ActionEvent.ACTION_PERFORMED, sb.toString()),
+                        target
+                    );
+                }
+            }
+        }
+    }
+
+
+    private static class SaJavaSettingsInitializer extends Settings.AbstractInitializer {
+        public SaJavaSettingsInitializer() {
+            super( "sa-java-settings-initializer" );
+        }
+
+
+
+        public void updateSettingsMap(Class kitClass, Map settingsMap) {
+            if (kitClass == JavaKit.class) {
+                SettingsUtil.updateListSetting(settingsMap, SettingsNames.KEY_BINDING_LIST, getJavaKeyBindings());
+            }
+
+        }
+
+        public MultiKeyBinding[] getJavaKeyBindings() {
+            return new MultiKeyBinding[] {
+               new MultiKeyBinding(
+                   new KeyStroke[] {
+                       KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.ALT_MASK),
+                       KeyStroke.getKeyStroke(KeyEvent.VK_G, 0)
+                   },
+                   JavaKit.makeGetterAction
+               ),
+               new MultiKeyBinding(
+                   new KeyStroke[] {
+                       KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.ALT_MASK),
+                       KeyStroke.getKeyStroke(KeyEvent.VK_S, 0)
+                   },
+                   JavaKit.makeSetterAction
+               ),
+               new MultiKeyBinding(
+                   new KeyStroke[] {
+                       KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.ALT_MASK),
+                       KeyStroke.getKeyStroke(KeyEvent.VK_I, 0)
+                   },
+                   JavaKit.makeIsAction
+               ),
+               new MultiKeyBinding(
+                   KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.ALT_MASK),
+                   JavaKit.abbrevDebugLineAction
+               )
+            };
+        }
+    }
+         public static class NbUndoAction extends ActionFactory.UndoAction {
+
+        public void actionPerformed(ActionEvent evt, JTextComponent target) {
+            /*if (NbEditorUtilities.getTopManager() != null) {
+                // Delegate to system undo action
+                UndoAction ua = (UndoAction)SystemAction.get(UndoAction.class);
+                if (ua != null && ua.isEnabled()) {
+                    ua.actionPerformed(evt);
+                }
+
+            } else {*/
+                super.actionPerformed(evt, target);
+                //System.out.println("Undo Action!!");                
+            //}
+        }
+
+    }
+
+    public static class NbRedoAction extends ActionFactory.RedoAction {
+
+        public void actionPerformed(ActionEvent evt, JTextComponent target) {
+            /*if (NbEditorUtilities.getTopManager() != null) {
+                // Delegate to system redo action
+                RedoAction ra = (RedoAction)SystemAction.get(RedoAction.class);
+                if (ra != null && ra.isEnabled()) {
+                    ra.actionPerformed(evt);
+                }
+
+            } else {*/
+                super.actionPerformed(evt, target);
+                //System.out.println("Redo Action!!");
+            //}
+        }
+
+
+    }
+    
+    public static class JKitUndoManager extends UndoManager
+    {
+        private Document m_doc;
+        public JKitUndoManager(Document doc)
+        {
+            super();
+            m_doc = doc;
+        }
+        
+        public synchronized boolean addEdit(UndoableEdit anEdit)
+        {
+            boolean bEdit = super.addEdit(anEdit);
+            if(bEdit)
+            {
+//                SaveStatusChangeSupport ssc = (SaveStatusChangeSupport)m_doc.getProperty(NBEditorBean.SAVE_CHANGE);
+//                if(ssc != null)
+//                    ssc.fireSaveStatusChange(new SaveStatusChangeEvent(this,true));
+            }
+            return bEdit;
+        }
+        
+        public synchronized void undo() throws CannotUndoException
+        {
+            try
+            {
+                super.undo();
+            }
+            catch(CannotUndoException ex)
+            {
+//                 SaveStatusChangeSupport ssc = (SaveStatusChangeSupport)m_doc.getProperty(NBEditorBean.SAVE_CHANGE);
+//                 if(ssc != null)
+//                    ssc.fireSaveStatusChange(new SaveStatusChangeEvent(this,false));
+//                 throw new CannotUndoException();
+            }
+            if(!canUndo())
+            {
+//                SaveStatusChangeSupport ssc = (SaveStatusChangeSupport)m_doc.getProperty(NBEditorBean.SAVE_CHANGE);
+//                 if(ssc != null)
+//                    ssc.fireSaveStatusChange(new SaveStatusChangeEvent(this,false));
+            }
+        }
+        
+        /*public synchronized void discardAllEdits()
+        {
+            super.discardAllEdits();
+            SaveStatusChangeSupport ssc = (SaveStatusChangeSupport)m_doc.getProperty(NBEditorBean.SAVE_CHANGE);
+                 if(ssc != null)
+                    ssc.fireSaveStatusChange(new SaveStatusChangeEvent(this,false));
+        }*/
+    }
+            
+}
+        
+   

Added: webservices/muse/trunk/src/examples/ieeedemo/client/src/org/apache/interop/common/ui/xmleditorkit/PlainKit.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/ieeedemo/client/src/org/apache/interop/common/ui/xmleditorkit/PlainKit.java?rev=239497&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/ieeedemo/client/src/org/apache/interop/common/ui/xmleditorkit/PlainKit.java (added)
+++ webservices/muse/trunk/src/examples/ieeedemo/client/src/org/apache/interop/common/ui/xmleditorkit/PlainKit.java Tue Aug 23 18:12:36 2005
@@ -0,0 +1,57 @@
+/*
+ *                 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-2000 Sun
+ * Microsystems, Inc. All Rights Reserved.
+ */
+
+package org.apache.interop.common.ui.xmleditorkit;
+
+import javax.swing.text.Caret;
+import javax.swing.text.Document;
+import org.netbeans.editor.BaseDocument;
+import org.netbeans.editor.Syntax;
+import org.netbeans.editor.SyntaxSupport;
+import org.netbeans.editor.ext.ExtSyntaxSupport;
+import org.netbeans.editor.ext.ExtKit;
+import org.netbeans.editor.ext.plain.PlainSyntax;
+
+/**
+* Editor kit used to edit the plain text.
+*
+* @author Miloslav Metelka
+* @version 1.00
+*/
+
+public class PlainKit extends ExtKit {
+
+    public static final String PLAIN_MIME_TYPE = "text/plain"; // NOI18N
+    
+    protected void initDocument(BaseDocument doc)
+    {
+        super.initDocument(doc);
+        JavaKit.JKitUndoManager mgr = new JavaKit.JKitUndoManager(doc);
+        doc.putProperty(BaseDocument.UNDO_MANAGER_PROP,mgr); 
+        doc.addUndoableEditListener(mgr);
+    }
+        
+    public String getContentType() {
+        return PLAIN_MIME_TYPE;
+    }
+
+    public Syntax createSyntax(Document doc) {
+        return new PlainSyntax();
+    }
+
+    public SyntaxSupport createSyntaxSupport(BaseDocument doc) {
+        return new ExtSyntaxSupport(doc);
+    }
+
+}
+



---------------------------------------------------------------------
To unsubscribe, e-mail: muse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-dev-help@ws.apache.org