|
What this is
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-2004 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.editor.ext.java; import java.awt.Color; import java.awt.Component; import java.util.ArrayList; import java.util.List; import javax.swing.text.BadLocationException; import javax.swing.text.JTextComponent; import org.netbeans.editor.BaseDocument; import org.netbeans.editor.Formatter; import org.netbeans.editor.ext.CompletionQuery; import org.netbeans.editor.ext.ExtFormatter; /** * * @author Martin Roskanin */ public abstract class JCResultItem implements CompletionQuery.ResultItem{ Object associatedObject; private static final Color KEYWORD_COLOR = Color.darkGray; private static final Color TYPE_COLOR = Color.black; public JCResultItem(Object associatedObject){ this.associatedObject = associatedObject; } public abstract String getItemText(); protected abstract Component getPaintComponent(boolean isSelected); public Object getAssociatedObject(){ return associatedObject; } protected String getReplaceText() { return getItemText(); } public boolean substituteCommonText(JTextComponent c, int offset, int len, int subLen) { // [PENDING] not enough info in parameters... // commonText // substituteExp return false; } public boolean substituteText(JTextComponent c, int offset, int len, boolean shift) { BaseDocument doc = (BaseDocument)c.getDocument(); String text = getReplaceText(); int selectionStartOffset = -1; int selectionEndOffset = -1; if (text != null) { // Update the text doc.atomicLock(); try { String textToReplace = doc.getText(offset, len); if (text.equals(textToReplace)) return false; doc.remove(offset, len); doc.insertString(offset, text, null); if (selectionStartOffset >= 0) { c.select(offset + selectionStartOffset, offset + selectionEndOffset); } } catch (BadLocationException e) { // Can't update } finally { doc.atomicUnlock(); } } return true; } public java.awt.Component getPaintComponent(javax.swing.JList list, boolean isSelected, boolean cellHasFocus) { Component ret; ret = getPaintComponent(isSelected); if (ret==null) return null; if (isSelected) { ret.setBackground(list.getSelectionBackground()); ret.setForeground(list.getSelectionForeground()); } else { ret.setBackground(list.getBackground()); ret.setForeground(list.getForeground()); } ret.getAccessibleContext().setAccessibleName(getItemText()); ret.getAccessibleContext().setAccessibleDescription(getItemText()); return ret; } protected Color getTypeColor(JCClass cls) { String s = cls.getName(); return (JavaCompletion.isPrimitiveClassName(s)) ? KEYWORD_COLOR : TYPE_COLOR; } protected static String getTypeName(JCType typ) { return typ.getClazz().getName(); } public static class FieldResultItem extends JCResultItem{ private String typeName; private Color typeColor; private String fldName; private int modifiers; private boolean isDeprecated; private static JCPaintComponent.FieldPaintComponent fieldComponent = null; public FieldResultItem(JCField fld){ super(fld); this.fldName = fld.getName(); this.modifiers = fld.getModifiers(); this.typeName = getTypeName(fld.getType()); this.typeColor = getTypeColor(fld.getType().getClazz()); this.isDeprecated = JCUtilities.isDeprecated(fld); } public String getItemText() { return fldName; } protected JCPaintComponent.FieldPaintComponent createPaintComponent(){ return new JCPaintComponent.FieldPaintComponent(); } public java.awt.Component getPaintComponent(boolean isSelected) { if (fieldComponent == null){ fieldComponent = createPaintComponent(); } fieldComponent.setTypeName(typeName); fieldComponent.setName(fldName); fieldComponent.setTypeColor(typeColor); fieldComponent.setModifiers(modifiers); fieldComponent.setSelected(isSelected); fieldComponent.setDeprecated(isDeprecated); return fieldComponent; } } public static class MethodResultItem extends ConstructorResultItem{ private static JCPaintComponent.MethodPaintComponent mtdComponent = null; private String typeName; private Color typeColor; private String mtdName; public MethodResultItem(JCMethod mtd, JCExpression substituteExp){ super(mtd, substituteExp); typeName = getTypeName(mtd.getReturnType()); mtdName = mtd.getName(); typeColor = getTypeColor(mtd.getReturnType().getClazz()); } public String getName(){ return mtdName; } public String getItemText() { return getName(); } protected JCPaintComponent.ConstructorPaintComponent createPaintComponent(){ return new JCPaintComponent.MethodPaintComponent(); } public Component getPaintComponent(boolean isSelected) { if (mtdComponent == null) { mtdComponent = (JCPaintComponent.MethodPaintComponent)createPaintComponent(); } mtdComponent.setName(getName()); mtdComponent.setModifiers(getModifiers()); mtdComponent.setTypeName(typeName); mtdComponent.setTypeColor(typeColor); mtdComponent.setParams(getParams()); mtdComponent.setExceptions(getExceptions()); mtdComponent.setDeprecated(isDeprecated()); mtdComponent.setSelected(isSelected); return mtdComponent; } } public static class ConstructorResultItem extends JCResultItem{ private JCConstructor ctr; private JCExpression substituteExp; private List params = new ArrayList(); private List excs = new ArrayList(); private int modifiers; private boolean isDeprecated; private static JCPaintComponent.ConstructorPaintComponent ctrComponent = null; public ConstructorResultItem(JCConstructor ctr, JCExpression substituteExp){ super(ctr); this.ctr = ctr; this.substituteExp = substituteExp; this.modifiers = ctr.getModifiers(); isDeprecated = JCUtilities.isDeprecated(ctr); JCParameter prms[] = ctr.getParameters(); for (int i=0; i |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
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.