Search in sources :

Example 41 with JTextComponent

use of javax.swing.text.JTextComponent in project cayenne by apache.

the class DbRelationshipPathComboBoxEditor method enterPressed.

@Override
protected void enterPressed(JTable table) {
    String dbRelationshipPath = ((JTextComponent) (comboBoxPathChooser).getEditor().getEditorComponent()).getText();
    changeObjEntity(dbRelationshipPath);
    Object currentNode = getCurrentNode(dbRelationshipPath);
    String[] pathStrings = dbRelationshipPath.split(Pattern.quote("."));
    String lastStringInPath = pathStrings[pathStrings.length - 1];
    if (lastStringInPath.equals(ModelerUtil.getObjectName(currentNode)) && currentNode instanceof DbRelationship) {
        if (enterPressedCount == 1) {
            // it is second time enter pressed.. so we will save input data
            enterPressedCount = 0;
            if (table.getCellEditor() != null) {
                table.getCellEditor().stopCellEditing();
                if (dbRelationshipPath.equals(savePath)) {
                    return;
                }
                // we need object target to save it in model
                DbEntity lastEntity = ((DbRelationship) currentNode).getTargetEntity();
                Collection<ObjEntity> objEntities = ((DbRelationship) currentNode).getTargetEntity().getDataMap().getMappedEntities(lastEntity);
                ObjEntity objectTarget = objEntities.isEmpty() ? null : objEntities.iterator().next();
                model.getRelationship(row).setTargetEntityName(objectTarget);
                model.setUpdatedValueAt(dbRelationshipPath, row, REL_TARGET_PATH_COLUMN);
                model.getRelationship(row).setDbRelationshipPath(dbRelationshipPath);
                model.getRelationship(row).setMapKey(null);
            }
            table.repaint();
        }
        enterPressedCount = 1;
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) DbRelationship(org.apache.cayenne.map.DbRelationship) JTextComponent(javax.swing.text.JTextComponent)

Example 42 with JTextComponent

use of javax.swing.text.JTextComponent in project enclojure by EricThorsen.

the class ClojureCodeCompletion_Provider method createTask.

public CompletionTask createTask(int i, final JTextComponent jTextComponent) {
    // try {
    // RT.var("clojure.core", "require").invoke(Symbol.create("test.CodeCompletion.PW.cljcompletion"));
    // } catch (Throwable ex) {
    // Exceptions.printStackTrace(ex);
    // }
    final int ctype = i;
    if (i != CompletionProvider.COMPLETION_QUERY_TYPE && i != CompletionProvider.COMPLETION_ALL_QUERY_TYPE)
        return null;
    return new AsyncCompletionTask(new AsyncCompletionQuery() {

        protected void query(final CompletionResultSet completionResultSet, final Document document, final int caretOffset) {
            final StyledDocument bDoc = (StyledDocument) document;
            int startOffset = -1;
            class Operation implements Runnable {

                boolean showCompletion = false;

                boolean isDotPressed = false;

                String filter = null;

                int startOffset = caretOffset;

                String nameSpace = null;

                String lastAtom = null;

                public void run() {
                    nameSpace = null;
                    lastAtom = null;
                    final Iterator it;
                    final String ret;
                    try {
                        final int lineStartOffset = getRowFirstNonWhite(bDoc, caretOffset);
                        String line;
                        if (caretOffset > lineStartOffset)
                            line = bDoc.getText(lineStartOffset, caretOffset - lineStartOffset);
                        else
                            line = "";
                        int begLine = indexOfSpace(line);
                        String filter = line.substring(begLine);
                        isDotPressed = dotPressed(filter);
                        int layout = getLayout(filter, isDotPressed);
                        begLine = lineStartOffset + begLine;
                        Hashtable processInfo = new Hashtable();
                        processInfo.put("layout", layout);
                        processInfo.put("filter", filter);
                        processInfo.put("begLine", begLine);
                        processInfo.put("isClojure", isClojure);
                        it = processLayout(processInfo);
                        filter = (String) processInfo.get("filter");
                        begLine = (Integer) processInfo.get("begLine");
                        if (it != null) {
                            handleMaps(it, completionResultSet, processInfo, filter, begLine);
                        // 
                        }
                        if ((layout != backSlashAfterParen && layout != backSlashNoParen) && !isDotPressed) {
                            // now add hippie completion results
                            processInfo.put("isClojure", true);
                            processInfo.put("priority", 3);
                            processInfo.put("isMethodOrFunction", true);
                            processInfo.put("source", "Hippie Completion");
                            processInfo.put("isNamespaceOrPackage", false);
                            processInfo.put("isConstructor", false);
                            ArrayList<String> l = getAllHippieMatches(jTextComponent);
                            if (l.size() > 0) {
                                Iterator lit;
                                lit = l.listIterator();
                                while (lit.hasNext()) {
                                    final String listentry = (String) lit.next();
                                    completionResultSet.addItem(new ClojureCodeCompletionItem(listentry, begLine, caretOffset, processInfo));
                                }
                            }
                        }
                        completionResultSet.setAnchorOffset(lineStartOffset);
                        completionResultSet.finish();
                    } catch (BadLocationException ex) {
                        LOG.log(Level.FINEST, ex.getMessage());
                    }
                }

                private String handleNullString(String val) {
                    if (val == null)
                        return "";
                    else
                        return val;
                }

                private Integer handleNullInteger(Integer val) {
                    if (val == null)
                        return 0;
                    else
                        return val;
                }

                private Boolean handleNullBoolean(Boolean val) {
                    if (val == null)
                        return false;
                    else
                        return val;
                }

                private void handleMaps(Iterator iter, CompletionResultSet c, Hashtable pInfo, String filter, int begLine) {
                    Boolean blnCurrentListEmpty = true;
                    if (CurrentList.size() > 0)
                        blnCurrentListEmpty = false;
                    while (iter.hasNext()) {
                        final PersistentArrayMap entry = (PersistentArrayMap) iter.next();
                        if ((blnCurrentListEmpty) && (!gettingMethods))
                            CurrentList.add(entry);
                        String displaystr = (String) entry.get(Keyword.intern(Symbol.create("display")));
                        String fullclassstr = (String) entry.get(Keyword.intern(Symbol.create("fullclassname")));
                        Boolean isClojure = (Boolean) entry.get(Keyword.intern(Symbol.create("isclojure")));
                        Boolean isNamespaceOrPackage = (Boolean) entry.get(Keyword.intern(Symbol.create("isnamespaceorpkg")));
                        Boolean isMethodOrFunction = (Boolean) entry.get(Keyword.intern(Symbol.create("ismethodorfunction")));
                        Boolean isConstructor = (Boolean) entry.get(Keyword.intern(Symbol.create("isconstructor")));
                        String namespace = (String) entry.get(Keyword.intern(Symbol.create("namespace")));
                        String method = (String) entry.get(Keyword.intern(Symbol.create("method")));
                        Integer priority = (Integer) entry.get(Keyword.intern(Symbol.create("priority")));
                        pInfo.put("display", handleNullString(displaystr));
                        pInfo.put("fullclassname", handleNullString(fullclassstr));
                        pInfo.put("isClojure", isClojure);
                        pInfo.put("isNamespaceOrPackage", isNamespaceOrPackage);
                        pInfo.put("isMethodOrFunction", isMethodOrFunction);
                        pInfo.put("namespace", handleNullString(namespace));
                        pInfo.put("method", handleNullString(method));
                        pInfo.put("priority", handleNullInteger(priority));
                        pInfo.put("isConstructor", handleNullBoolean(isConstructor));
                        if (isClojure)
                            pInfo.put("source", "Clojure");
                        else
                            pInfo.put("source", "Java");
                        String origFilter = (String) pInfo.get("origFilter");
                        int layout = (Integer) pInfo.get("layout");
                        if (addFilter) {
                            if (// if this is a java method
                            isMethodOrFunction && (!isClojure)) {
                                if ((filter != null) && (displaystr.startsWith(filter.trim())))
                                    completionResultSet.addItem(new ClojureCodeCompletionItem(displaystr, begLine, caretOffset, pInfo));
                            } else {
                                if (layout != backSlashAfterParen && layout != backSlashNoParen) {
                                    if (isNamespaceOrPackage) {
                                        if ((filter != null) && (displaystr.contains(origFilter.trim())))
                                            completionResultSet.addItem(new ClojureCodeCompletionItem(displaystr, begLine, caretOffset, pInfo));
                                    } else {
                                        if ((filter != null) && (displaystr.contains(filter.trim())))
                                            completionResultSet.addItem(new ClojureCodeCompletionItem(displaystr, begLine, caretOffset, pInfo));
                                    }
                                } else {
                                    if ((filter != null) && (displaystr.startsWith(filter.trim())))
                                        completionResultSet.addItem(new ClojureCodeCompletionItem(displaystr, begLine, caretOffset, pInfo));
                                }
                            }
                        } else
                            completionResultSet.addItem(new ClojureCodeCompletionItem(displaystr, begLine, caretOffset, pInfo));
                    }
                }

                private int getLayout(String filter, boolean isDotPressed) {
                    try {
                        if (filter.startsWith("(")) {
                            filter = filter.substring(1);
                            if (backSlashPressed(filter)) {
                                if ((filter != null) && (filter.trim().length() > 0))
                                    return backSlashAfterParen;
                                else
                                    return -1;
                            } else {
                                if (isDotPressed && (filter != null) && (filter.trim().length() > 0) && Character.isUpperCase(filter.trim().charAt(0))) {
                                    return UppercaseAfterParenWithDot;
                                } else {
                                    if (isDotPressed && (filter != null) && (filter.trim().length() > 0) && (filter.trim().charAt(0) == '.')) {
                                        // get all java methods available
                                        return FirstDotAfterParen;
                                    } else {
                                        if (isDotPressed && (filter != null) && (filter.trim().length() > 0) && Character.isLowerCase(filter.trim().charAt((0))))
                                            return LowercaseAfterParenWithDot;
                                        else {
                                            if ((filter != null) && (filter.trim().length() > 0) && Character.isUpperCase(filter.trim().charAt((0))))
                                                return UppercaseAfterParen;
                                            else
                                                // lowercase
                                                return LowercaseAfterParen;
                                        }
                                    }
                                }
                            }
                        } else // No Paren
                        {
                            if (backSlashPressed(filter)) {
                                if ((filter != null) && (filter.trim().length() > 0))
                                    return backSlashNoParen;
                                else
                                    return -1;
                            } else {
                                if (isDotPressed && (filter != null) && (filter.trim().length() > 0) && Character.isUpperCase(filter.trim().charAt(0))) {
                                    return UppercaseNoParenWithDot;
                                } else {
                                    if (isDotPressed && (filter != null) && (filter.trim().length() > 0) && (filter.trim().charAt(0) == '.')) {
                                        return FirstDotNoParen;
                                    } else {
                                        if (isDotPressed && (filter != null) && (filter.trim().length() > 0) && Character.isLowerCase(filter.trim().charAt((0))))
                                            return LowercaseNoParenWithDot;
                                        else {
                                            if ((filter != null) && (filter.trim().length() > 0) && Character.isUpperCase(filter.trim().charAt((0))))
                                                return UppercaseNoParen;
                                            else
                                                // lowercase
                                                return LowercaseNoParen;
                                        }
                                    }
                                }
                            }
                        }
                    } catch (Exception ex) {
                        Exceptions.printStackTrace(ex);
                    }
                    return -1;
                }

                private Iterator processLayout(Hashtable processInfo) {
                    // private static final int LowercaseAfterParen = 0;
                    // private static final int UppercaseAfterParen = 1;
                    // private static final int LowercaseAfterParenWithDot = 2;
                    // private static final int UppercaseAfterParenWithDot = 3;
                    // private static final int LowercaseNoParen = 4;
                    // private static final int UppercaseNoParen = 5;
                    // private static final int LowercaseNoParenWithDot = 6;
                    // private static final int UppercaseNoParenWithDot = 7;
                    // private static final int FirstDotAfterParen = 8;
                    // private static final int FirstDotNoParen = 9;
                    int layout = (Integer) processInfo.get("layout");
                    String filter = (String) processInfo.get("filter");
                    String begFilter;
                    String origFilter = "";
                    int begLine = (Integer) processInfo.get("begLine");
                    int dotpos;
                    Iterator iter = null;
                    try {
                        filter = filter.trim();
                        switch(layout) {
                            case LowercaseAfterParen:
                                // remove the paranthesis
                                filter = filter.substring(1);
                                origFilter = filter;
                                addFilter = true;
                                iter = getResultsForScenario2(filter);
                                begLine = begLine + 1;
                                break;
                            case UppercaseAfterParen:
                                // remove the paranthesis
                                filter = filter.substring(1);
                                origFilter = filter;
                                addFilter = true;
                                iter = getResultsForScenario2(filter);
                                begLine = begLine + 1;
                                break;
                            case LowercaseAfterParenWithDot:
                                // remove the paranthesis
                                filter = filter.substring(1);
                                origFilter = filter;
                                dotpos = filter.lastIndexOf(".");
                                begFilter = filter.substring(0, dotpos);
                                addFilter = true;
                                // iter=getResultsForScenario1(getClsForFilter(begFilter),begFilter + ".");  //check java classes
                                // check java classes
                                iter = getResultsForScenario1(getClsForFilter(begFilter), origFilter);
                                // iter=getAllClojureNamespaces1(origFilter);
                                filter = filter.substring(dotpos + 1);
                                // filter=origFilter;
                                begLine = begLine + 1;
                                break;
                            case UppercaseAfterParenWithDot:
                                // remove the paranthesis
                                filter = filter.substring(1);
                                origFilter = filter;
                                dotpos = filter.lastIndexOf(".");
                                begFilter = filter.substring(0, dotpos);
                                addFilter = true;
                                // iter=getResultsForScenario1(getClsForFilter(begFilter),begFilter + ".");  //check java classes
                                // check java classes
                                iter = getResultsForScenario1(getClsForFilter(begFilter), origFilter);
                                filter = filter.substring(dotpos + 1);
                                // filter=origFilter;
                                begLine = begLine + 1;
                                break;
                            case backSlashAfterParen:
                                // remove the paranthesis
                                filter = filter.substring(1);
                                origFilter = filter;
                                dotpos = filter.lastIndexOf("/");
                                begFilter = filter.substring(0, dotpos);
                                addFilter = true;
                                iter = getResultsForScenario3(getClsForFilter(begFilter), begFilter);
                                filter = filter.substring(dotpos + 1);
                                begLine = begLine + 1;
                                break;
                            case FirstDotAfterParen:
                                // remove the paranthesis
                                filter = filter.substring(1);
                                origFilter = filter;
                                addFilter = true;
                                if (filter.equalsIgnoreCase("."))
                                    filter = "";
                                else {
                                    dotpos = filter.lastIndexOf(".");
                                    filter = filter.substring(dotpos + 1);
                                }
                                iter = getResultsForScenario4();
                                begLine = begLine + 2;
                                break;
                            case UppercaseNoParen:
                                origFilter = filter;
                                addFilter = true;
                                iter = getResultsForScenario2(filter);
                                break;
                            case UppercaseNoParenWithDot:
                                origFilter = filter;
                                dotpos = filter.lastIndexOf(".");
                                begFilter = filter.substring(0, dotpos);
                                addFilter = true;
                                // iter=getResultsForScenario1(getClsForFilter(begFilter),begFilter + ".");  //check java classes
                                // check java classes
                                iter = getResultsForScenario1(getClsForFilter(begFilter), origFilter);
                                filter = filter.substring(dotpos + 1);
                                // filter=origFilter;
                                break;
                            case FirstDotNoParen:
                                origFilter = filter;
                                addFilter = true;
                                if (filter.equalsIgnoreCase("."))
                                    filter = "";
                                else {
                                    dotpos = filter.lastIndexOf(".");
                                    filter = filter.substring(dotpos + 1);
                                }
                                iter = getResultsForScenario4();
                                begLine = begLine + 1;
                                break;
                            case LowercaseNoParenWithDot:
                                origFilter = filter;
                                dotpos = filter.lastIndexOf(".");
                                begFilter = filter.substring(0, dotpos);
                                addFilter = true;
                                // iter=getResultsForScenario1(getClsForFilter(begFilter),begFilter + ".");  //check java classes
                                // check java classes
                                iter = getResultsForScenario1(getClsForFilter(begFilter), origFilter);
                                filter = filter.substring(dotpos + 1);
                                // filter=origFilter;
                                break;
                            case LowercaseNoParen:
                                origFilter = filter;
                                addFilter = true;
                                iter = getResultsForScenario2(filter);
                                break;
                            case backSlashNoParen:
                                origFilter = filter;
                                dotpos = filter.lastIndexOf("/");
                                begFilter = filter.substring(0, dotpos);
                                addFilter = true;
                                iter = getResultsForScenario3(getClsForFilter(begFilter), begFilter);
                                filter = filter.substring(dotpos + 1);
                                break;
                        }
                        processInfo.put("layout", layout);
                        processInfo.put("filter", filter);
                        processInfo.put("begLine", begLine);
                        processInfo.put("isClojure", isClojure);
                        processInfo.put("origFilter", origFilter);
                        return iter;
                    } catch (Exception ex) {
                        Exceptions.printStackTrace(ex);
                    }
                    return iter;
                }

                private Iterator getiterator() {
                    try {
                        return ((Iterable) getnamesfn.invoke(Symbol.create("clojure.core"))).iterator();
                    } catch (Exception ex) {
                        Exceptions.printStackTrace(ex);
                    }
                    return null;
                }

                private Iterator getclojureiterator() {
                    try {
                        return ((Iterable) getclojurenamesfn.invoke(Symbol.create("clojure.core"))).iterator();
                    } catch (Exception ex) {
                        Exceptions.printStackTrace(ex);
                    }
                    return null;
                }

                private Iterator getclojurefunctionsforns(String nspart) {
                    try {
                        java.lang.Object iter = (getclojurefunctionsfornsfn.invoke(nspart));
                        if (iter != null)
                            return ((Iterable) iter).iterator();
                        else
                            return null;
                    } catch (Exception ex) {
                        Exceptions.printStackTrace(ex);
                        return null;
                    }
                }

                private Iterator getJavaMethods(String classname) {
                    try {
                        return ((Iterable) getjavamethodsfn.invoke(Class.forName(classname))).iterator();
                    } catch (Exception ex) {
                        // Exceptions.printStackTrace(ex);
                        return null;
                    }
                }

                private Iterator getStaticJavaMethods(String classname) {
                    try {
                        return ((Iterable) getstaticjavamethodsfn.invoke(Class.forName(classname))).iterator();
                    } catch (Exception ex) {
                        // Exceptions.printStackTrace(ex);
                        return null;
                    }
                }

                private Iterator getAllJavaMethods() {
                    try {
                        return ((Iterable) getalljavamethodsfn.invoke(Symbol.create("clojure.core"))).iterator();
                    } catch (Exception ex) {
                        // Exceptions.printStackTrace(ex);
                        return null;
                    }
                }

                private Iterator getAllJavaInstanceMethods(String classname) {
                    try {
                        return ((Iterable) getalljavainstancemethodsfn.invoke(Class.forName(classname))).iterator();
                    } catch (Exception ex) {
                        // Exceptions.printStackTrace(ex);
                        return null;
                    }
                }

                private Iterator getAllClojureNamespaces1(String filter) {
                    try {
                        return ((Iterable) getallclojurenamespaces1fn.invoke(1)).iterator();
                    } catch (Exception ex) {
                        // Exceptions.printStackTrace(ex);
                        return null;
                    }
                }

                private Iterator getResultsForScenario1(String classname, String filter) {
                    try {
                        gettingMethods = false;
                        if (ctype == CompletionProvider.COMPLETION_ALL_QUERY_TYPE) {
                            completionResultSet.setHasAdditionalItems(true);
                            getExtLibs = true;
                        } else {
                            completionResultSet.setHasAdditionalItems(false);
                            getExtLibs = false;
                        }
                        Project proj = ReplTopComponent.GetProjectFromDocument(document);
                        if (!getExtLibs) {
                            proj = null;
                            CurrentList = Scenario1List;
                        } else
                            CurrentList = Scenario1ListExtLib;
                        int listSize = CurrentList.size();
                        if (classname == null) {
                            if (listSize > 0)
                                return CurrentList.iterator();
                            else
                                return ((Iterable) getresultsforscenario1fn.invoke(proj, jTextComponent, null, filter)).iterator();
                        } else {
                            gettingMethods = true;
                            return ((Iterable) getresultsforscenario1fn.invoke(proj, jTextComponent, Class.forName(classname), filter)).iterator();
                        }
                    } catch (Exception ex) {
                        // Exceptions.printStackTrace(ex);
                        return null;
                    }
                }

                private Iterator getResultsForScenario2(String filter) {
                    try {
                        gettingMethods = false;
                        if (ctype == CompletionProvider.COMPLETION_ALL_QUERY_TYPE) {
                            completionResultSet.setHasAdditionalItems(true);
                            getExtLibs = true;
                        } else {
                            completionResultSet.setHasAdditionalItems(false);
                            getExtLibs = false;
                        }
                        Project proj = ReplTopComponent.GetProjectFromDocument(document);
                        if (!getExtLibs) {
                            proj = null;
                            CurrentList = Scenario2List;
                        } else
                            CurrentList = Scenario2ListExtLib;
                        int listSize = CurrentList.size();
                        if (listSize > 0)
                            return CurrentList.iterator();
                        else
                            return ((Iterable) getresultsforscenario2fn.invoke(proj, jTextComponent, Symbol.create("clojure.core"), filter)).iterator();
                    } catch (Exception ex) {
                        // Exceptions.printStackTrace(ex);
                        return null;
                    }
                }

                private Iterator getResultsForScenario3(String classname, String filter) {
                    try {
                        gettingMethods = false;
                        CurrentList = Scenario3List;
                        if (classname == null) {
                            gettingMethods = true;
                            return ((Iterable) getresultsforscenario3fn.invoke(null, filter)).iterator();
                        } else {
                            gettingMethods = true;
                            return ((Iterable) getresultsforscenario3fn.invoke(Class.forName(classname), filter)).iterator();
                        }
                    } catch (Exception ex) {
                        // Exceptions.printStackTrace(ex);
                        return null;
                    }
                }

                private Iterator getResultsForScenario4() {
                    try {
                        gettingMethods = false;
                        if (ctype == CompletionProvider.COMPLETION_ALL_QUERY_TYPE) {
                            completionResultSet.setHasAdditionalItems(true);
                            getExtLibs = true;
                        } else {
                            completionResultSet.setHasAdditionalItems(false);
                            getExtLibs = false;
                        }
                        Project proj = ReplTopComponent.GetProjectFromDocument(document);
                        if (!getExtLibs) {
                            proj = null;
                            CurrentList = Scenario4List;
                        } else
                            CurrentList = Scenario4List;
                        int listSize = CurrentList.size();
                        if (listSize > 0)
                            return CurrentList.iterator();
                        else
                            return ((Iterable) getresultsforscenario4fn.invoke(proj)).iterator();
                    } catch (Exception ex) {
                        // Exceptions.printStackTrace(ex);
                        return null;
                    }
                }

                private Iterator getAllJavaClasses() {
                    try {
                        return ((Iterable) getalljavaclassesfn.invoke(jTextComponent)).iterator();
                    } catch (Exception ex) {
                        // Exceptions.printStackTrace(ex);
                        return null;
                    }
                }

                private Iterator getAllJavaClasses(String filter) {
                    try {
                        return ((Iterable) getalljavaclassesbyfilterfn.invoke(jTextComponent, filter)).iterator();
                    } catch (Exception ex) {
                        // Exceptions.printStackTrace(ex);
                        return null;
                    }
                }

                private Iterator getAllClojureNamespaces(String filter) {
                    try {
                        return ((Iterable) getallclojurenamespacesfn.invoke(jTextComponent, filter)).iterator();
                    } catch (Exception ex) {
                        // Exceptions.printStackTrace(ex);
                        return null;
                    }
                }

                private Iterator getFullJavaClasses() {
                    try {
                        return ((Iterable) getfulljavaclassesfn.invoke(Symbol.create("clojure.core"))).iterator();
                    } catch (Exception ex) {
                        Exceptions.printStackTrace(ex);
                    }
                    return null;
                }

                private Iterator getEnclosingFormMap(JTextComponent jTextComponent) {
                    try {
                        return ((Iterable) selectcurrentformfn.invoke(jTextComponent)).iterator();
                    } catch (Exception ex) {
                        Exceptions.printStackTrace(ex);
                    }
                    return null;
                }

                private String getClsForFilter(String filterstr) {
                    Iterator iter;
                    iter = getAllJavaClasses();
                    if (iter != null) {
                        while (iter.hasNext()) {
                            final String entry = (String) iter.next();
                            if ((entry.endsWith("." + filterstr)) || (entry.equals(filterstr)))
                                return entry;
                        }
                        return null;
                    } else
                        return null;
                }

                private boolean containsFilter(Iterator iter, String filter) {
                    try {
                        if (iter != null) {
                            while (iter.hasNext()) {
                                final String entry = (String) iter.next();
                                if ((filter != null) && (entry.startsWith(filter)))
                                    return true;
                            }
                        }
                        return false;
                    } catch (Exception ex) {
                        Exceptions.printStackTrace(ex);
                        return false;
                    }
                }
            }
            Operation oper = new Operation();
            bDoc.render(oper);
        }
    }, jTextComponent);
}
Also used : AsyncCompletionTask(org.netbeans.spi.editor.completion.support.AsyncCompletionTask) Hashtable(java.util.Hashtable) StyledDocument(javax.swing.text.StyledDocument) ArrayList(java.util.ArrayList) CompletionResultSet(org.netbeans.spi.editor.completion.CompletionResultSet) JTextComponent(javax.swing.text.JTextComponent) AsyncCompletionQuery(org.netbeans.spi.editor.completion.support.AsyncCompletionQuery) StyledDocument(javax.swing.text.StyledDocument) Document(javax.swing.text.Document) BadLocationException(javax.swing.text.BadLocationException) Project(org.netbeans.api.project.Project) PersistentArrayMap(clojure.lang.PersistentArrayMap) Iterator(java.util.Iterator) BadLocationException(javax.swing.text.BadLocationException)

Example 43 with JTextComponent

use of javax.swing.text.JTextComponent in project jdk8u_jdk by JetBrains.

the class SynthStyle method getColor.

/**
     * Returns the color for the specified state. This gives precedence to
     * foreground and background of the <code>JComponent</code>. If the
     * <code>Color</code> from the <code>JComponent</code> is not appropriate,
     * or not used, this will invoke <code>getColorForState</code>. Subclasses
     * should generally not have to override this, instead override
     * {@link #getColorForState}.
     *
     * @param context SynthContext identifying requester
     * @param type Type of color being requested.
     * @return Color
     */
public Color getColor(SynthContext context, ColorType type) {
    JComponent c = context.getComponent();
    Region id = context.getRegion();
    if ((context.getComponentState() & SynthConstants.DISABLED) != 0) {
        //text when the label is disabled. This code allows for that.
        if (c instanceof JTextComponent) {
            JTextComponent txt = (JTextComponent) c;
            Color disabledColor = txt.getDisabledTextColor();
            if (disabledColor == null || disabledColor instanceof UIResource) {
                return getColorForState(context, type);
            }
        } else if (c instanceof JLabel && (type == ColorType.FOREGROUND || type == ColorType.TEXT_FOREGROUND)) {
            return getColorForState(context, type);
        }
    }
    // If the developer has specified a color, prefer it. Otherwise, get
    // the color for the state.
    Color color = null;
    if (!id.isSubregion()) {
        if (type == ColorType.BACKGROUND) {
            color = c.getBackground();
        } else if (type == ColorType.FOREGROUND) {
            color = c.getForeground();
        } else if (type == ColorType.TEXT_FOREGROUND) {
            color = c.getForeground();
        }
    }
    if (color == null || color instanceof UIResource) {
        // Then use what we've locally defined
        color = getColorForState(context, type);
    }
    if (color == null) {
        // No color, fallback to that of the widget.
        if (type == ColorType.BACKGROUND || type == ColorType.TEXT_BACKGROUND) {
            return c.getBackground();
        } else if (type == ColorType.FOREGROUND || type == ColorType.TEXT_FOREGROUND) {
            return c.getForeground();
        }
    }
    return color;
}
Also used : JTextComponent(javax.swing.text.JTextComponent) UIResource(javax.swing.plaf.UIResource)

Example 44 with JTextComponent

use of javax.swing.text.JTextComponent in project jdk8u_jdk by JetBrains.

the class SynthScrollPaneUI method installListeners.

/**
     * {@inheritDoc}
     */
@Override
protected void installListeners(JScrollPane c) {
    super.installListeners(c);
    c.addPropertyChangeListener(this);
    if (UIManager.getBoolean("ScrollPane.useChildTextComponentFocus")) {
        viewportViewFocusHandler = new ViewportViewFocusHandler();
        c.getViewport().addContainerListener(viewportViewFocusHandler);
        Component view = c.getViewport().getView();
        if (view instanceof JTextComponent) {
            view.addFocusListener(viewportViewFocusHandler);
        }
    }
}
Also used : JTextComponent(javax.swing.text.JTextComponent) JTextComponent(javax.swing.text.JTextComponent)

Example 45 with JTextComponent

use of javax.swing.text.JTextComponent in project OpenNotebook by jaltekruse.

the class OCButton method associatedAction.

public void associatedAction() {
    if (!textComponentHasFocus()) {
        return;
    }
    JTextComponent currField = getFocusedComponent();
    int caretPos = 0;
    if (currField != null) {
        String currText = currField.getText();
        if (currField.getSelectionStart() == currField.getSelectionEnd()) {
            currText = currField.getText();
            caretPos = currField.getCaretPosition();
            String tempText = currText.substring(0, caretPos);
            tempText += s;
            tempText += currText.substring(caretPos, currText.length());
            currField.setText(tempText);
            currField.requestFocus();
            currField.setCaretPosition(caretPos + s.length());
        } else {
            int selectStart = currField.getSelectionStart();
            int selectEnd = currField.getSelectionEnd();
            String tempText = currText.substring(0, selectStart);
            tempText += s;
            tempText += currText.substring(selectEnd, currText.length());
            currField.setText(tempText);
            currField.requestFocus();
            currField.setCaretPosition(selectStart + s.length());
        }
    }
}
Also used : JTextComponent(javax.swing.text.JTextComponent)

Aggregations

JTextComponent (javax.swing.text.JTextComponent)89 NotNull (org.jetbrains.annotations.NotNull)9 Component (java.awt.Component)7 DocumentEvent (javax.swing.event.DocumentEvent)6 DocumentAdapter (com.intellij.ui.DocumentAdapter)5 Disposable (com.intellij.openapi.Disposable)3 JButton (javax.swing.JButton)3 Project (com.intellij.openapi.project.Project)2 GraphicsConfig (com.intellij.openapi.ui.GraphicsConfig)2 FocusEvent (java.awt.event.FocusEvent)2 KeyEvent (java.awt.event.KeyEvent)2 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Accessible (javax.accessibility.Accessible)2 Action (javax.swing.Action)2 JComboBox (javax.swing.JComboBox)2 JFrame (javax.swing.JFrame)2 JLabel (javax.swing.JLabel)2 JMenuItem (javax.swing.JMenuItem)2