php.smarty/src/org/netbeans/modules/php/smarty/editor/utlis/LexerUtils.java
author Martin Fousek <marfous@netbeans.org>
Thu, 03 Mar 2011 00:03:37 +0100
changeset 17309 60f4cc6038b3
parent 16264 0bcd1b2b366f
child 17329 54d8f8c364b0
permissions -rw-r--r--
removing UI freezing by change of default Smarty delimiters
marfous@16211
     1
/*
marfous@16211
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
marfous@16211
     3
 *
marfous@16211
     4
 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
marfous@16211
     5
 *
marfous@16211
     6
 * The contents of this file are subject to the terms of either the GNU
marfous@16211
     7
 * General Public License Version 2 only ("GPL") or the Common
marfous@16211
     8
 * Development and Distribution License("CDDL") (collectively, the
marfous@16211
     9
 * "License"). You may not use this file except in compliance with the
marfous@16211
    10
 * License. You can obtain a copy of the License at
marfous@16211
    11
 * http://www.netbeans.org/cddl-gplv2.html
marfous@16211
    12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
marfous@16211
    13
 * specific language governing permissions and limitations under the
marfous@16211
    14
 * License.  When distributing the software, include this License Header
marfous@16211
    15
 * Notice in each file and include the License file at
marfous@16211
    16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
marfous@16211
    17
 * particular file as subject to the "Classpath" exception as provided
marfous@16211
    18
 * by Sun in the GPL Version 2 section of the License file that
marfous@16211
    19
 * accompanied this code. If applicable, add the following below the
marfous@16211
    20
 * License Header, with the fields enclosed by brackets [] replaced by
marfous@16211
    21
 * your own identifying information:
marfous@16211
    22
 * "Portions Copyrighted [year] [name of copyright owner]"
marfous@16211
    23
 *
marfous@16211
    24
 * If you wish your version of this file to be governed by only the CDDL
marfous@16211
    25
 * or only the GPL Version 2, indicate your decision by adding
marfous@16211
    26
 * "[Contributor] elects to include this software in this distribution
marfous@16211
    27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
marfous@16211
    28
 * single choice of license, a recipient has the option to distribute
marfous@16211
    29
 * your version of this file under either the CDDL, the GPL Version 2 or
marfous@16211
    30
 * to extend the choice of license to its licensees as provided above.
marfous@16211
    31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
marfous@16211
    32
 * Version 2 license, then the option applies only if the new code is
marfous@16211
    33
 * made subject to such option by the copyright holder.
marfous@16211
    34
 *
marfous@16211
    35
 * Contributor(s):
marfous@16211
    36
 *
marfous@16211
    37
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
marfous@16211
    38
 */
marfous@16211
    39
package org.netbeans.modules.php.smarty.editor.utlis;
marfous@16211
    40
marfous@16264
    41
import javax.swing.text.Document;
marfous@17309
    42
import org.netbeans.modules.editor.NbEditorDocument;
marfous@16264
    43
import org.netbeans.modules.php.smarty.editor.TplKit;
marfous@16264
    44
import org.netbeans.spi.lexer.MutableTextInput;
marfous@16264
    45
import org.openide.text.CloneableEditor;
marfous@16264
    46
import org.openide.windows.TopComponent;
marfous@16264
    47
import org.openide.windows.WindowManager;
marfous@16211
    48
marfous@16211
    49
/**
marfous@16211
    50
 *
marfous@16211
    51
 * @author Martin Fousek
marfous@16211
    52
 */
marfous@16211
    53
public class LexerUtils {
marfous@16211
    54
marfous@16211
    55
    public static final boolean isVariablePart(int character) {
marfous@16211
    56
        return Character.isJavaIdentifierPart(character);
marfous@16211
    57
    }
marfous@16211
    58
marfous@16211
    59
    public static final boolean isWS(int character) {
marfous@16211
    60
        if (Character.isWhitespace(character)) {
marfous@16211
    61
            return true;
marfous@16211
    62
        }
marfous@16211
    63
        return false;
marfous@16211
    64
    }
marfous@16211
    65
marfous@16264
    66
    public static final void relexerOpenedTpls() {
marfous@16264
    67
        WindowManager.getDefault().invokeWhenUIReady(new Runnable() {
marfous@16264
    68
marfous@16264
    69
            @Override
marfous@16264
    70
            public void run() {
marfous@16264
    71
                TopComponent[] topComponents = WindowManager.getDefault().getOpenedTopComponents(WindowManager.getDefault().findMode("editor"));
marfous@16264
    72
                for (TopComponent topComponent : topComponents) {
marfous@16264
    73
                    if (topComponent instanceof CloneableEditor) {
marfous@17309
    74
                        final Document doc = ((CloneableEditor) topComponent).getEditorPane().getDocument();
marfous@16264
    75
                        if (((CloneableEditor) topComponent).getEditorPane().getEditorKit() instanceof TplKit) {
marfous@16264
    76
                            ((TplKit) ((CloneableEditor) topComponent).getEditorPane().getEditorKit()).initLexerColoringListener(doc);
marfous@16264
    77
                        }
marfous@17309
    78
                        NbEditorDocument nbdoc = (NbEditorDocument) doc;
marfous@17309
    79
                        nbdoc.runAtomic(new Runnable() {
marfous@17309
    80
marfous@17309
    81
                            @Override
marfous@17309
    82
                            public void run() {
marfous@17309
    83
                                MutableTextInput mti = (MutableTextInput) doc.getProperty(MutableTextInput.class);
marfous@17309
    84
                                if (mti != null) {
marfous@17309
    85
                                    mti.tokenHierarchyControl().rebuild();
marfous@17309
    86
                                }
marfous@17309
    87
                            }
marfous@17309
    88
                        });
marfous@16264
    89
                    }
marfous@16264
    90
                }
marfous@16264
    91
            }
marfous@16264
    92
        });
marfous@16264
    93
    }
marfous@16211
    94
}