mirror of
https://github.com/SuspiciousActivity/ByteEdit.git
synced 2026-08-13 17:56:17 +00:00
Fixes and updates
This commit is contained in:
1 parent
d1710ea6a5
commit
fb4da77359
211 files changed
+45363
-45571
No files matched your search
@@ -26,8 +26,8 @@ import javax.swing.text.View;
|
||||
|
||||
/**
|
||||
* A cell renderer that adds some pizazz when rendering the standard
|
||||
* {@link Completion} types, like Eclipse and NetBeans do. Specifically,
|
||||
* this renderer handles:
|
||||
* {@link Completion} types, like Eclipse and NetBeans do. Specifically, this
|
||||
* renderer handles:
|
||||
*
|
||||
* <ul>
|
||||
* <li>{@link FunctionCompletion}s</li>
|
||||
@@ -41,20 +41,20 @@ import javax.swing.text.View;
|
||||
* @version 1.0
|
||||
*/
|
||||
public class CompletionCellRenderer extends DefaultListCellRenderer {
|
||||
|
||||
|
||||
/**
|
||||
* The alternating background color, or <code>null</code> if alternating
|
||||
* row colors should not be used.
|
||||
* The alternating background color, or <code>null</code> if alternating row
|
||||
* colors should not be used.
|
||||
*/
|
||||
private static Color altBG;
|
||||
/**
|
||||
* The font to use when rendering items, or <code>null</code> if the
|
||||
* list's default font should be used.
|
||||
* The font to use when rendering items, or <code>null</code> if the list's
|
||||
* default font should be used.
|
||||
*/
|
||||
private Font font;
|
||||
/**
|
||||
* Whether to display the types of fields and return types of functions
|
||||
* in the completion text.
|
||||
* Whether to display the types of fields and return types of functions in the
|
||||
* completion text.
|
||||
*/
|
||||
private boolean showTypes;
|
||||
/**
|
||||
@@ -92,33 +92,32 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
|
||||
* words.
|
||||
*/
|
||||
private static final String PREFIX = "<html><nobr>";
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public CompletionCellRenderer() {
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor. This is primarily a hook for Substance, or any other
|
||||
* Look and Feel whose renderers look drastically different than standard
|
||||
* Constructor. This is primarily a hook for Substance, or any other Look and
|
||||
* Feel whose renderers look drastically different than standard
|
||||
* <code>DefaultListCellRenderer</code>s. Everything except for the text
|
||||
* rendering will be done by the delegate. In almost all scenarios, you
|
||||
* will want to use the no-argument constructor instead of this one.
|
||||
* rendering will be done by the delegate. In almost all scenarios, you will
|
||||
* want to use the no-argument constructor instead of this one.
|
||||
*
|
||||
* @param delegate
|
||||
* The delegate renderer.
|
||||
* @param delegate The delegate renderer.
|
||||
* @see #delegateToSubstanceRenderer()
|
||||
*/
|
||||
public CompletionCellRenderer(DefaultListCellRenderer delegate) {
|
||||
setDelegateRenderer(delegate);
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates the icon to use if no icon is found for a specific completion.
|
||||
* The default implementation returns a 16x16 empty icon.
|
||||
* Creates the icon to use if no icon is found for a specific completion. The
|
||||
* default implementation returns a 16x16 empty icon.
|
||||
*
|
||||
* @return The icon.
|
||||
* @see #getEmptyIcon()
|
||||
@@ -126,34 +125,32 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
|
||||
protected Icon createEmptyIcon() {
|
||||
return new EmptyIcon(16);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a decent "parameter" color based on the current default
|
||||
* foreground color.
|
||||
* Returns a decent "parameter" color based on the current default foreground
|
||||
* color.
|
||||
*
|
||||
* @return The parameter color to use.
|
||||
*/
|
||||
private String createParamColor() {
|
||||
return Util.isLightForeground(getForeground()) ? Util.getHexString(Util.getHyperlinkForeground()) : "#aa0077";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a decent "type" color based on the current default foreground
|
||||
* color.
|
||||
* Returns a decent "type" color based on the current default foreground color.
|
||||
*
|
||||
* @return The type color to use.
|
||||
*/
|
||||
private String createTypeColor() {
|
||||
return "#808080";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Attempts to delegate rendering to a Substance cell renderer. This
|
||||
* should only be called if Substance is known to be on the classpath.
|
||||
* Attempts to delegate rendering to a Substance cell renderer. This should only
|
||||
* be called if Substance is known to be on the classpath.
|
||||
*
|
||||
* @throws Exception
|
||||
* If Substance is not on the classpath, or some other
|
||||
* error occurs creating the Substance cell renderer.
|
||||
* @throws Exception If Substance is not on the classpath, or some other error
|
||||
* occurs creating the Substance cell renderer.
|
||||
* @see Util#getUseSubstanceRenderers()
|
||||
* @see #setDelegateRenderer(DefaultListCellRenderer)
|
||||
*/
|
||||
@@ -162,7 +159,7 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
|
||||
DefaultListCellRenderer delegate = (DefaultListCellRenderer) clazz.newInstance();
|
||||
setDelegateRenderer(delegate);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the background color to use on alternating lines.
|
||||
*
|
||||
@@ -173,7 +170,7 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
|
||||
public static Color getAlternateBackground() {
|
||||
return altBG;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the delegate renderer, or <code>null</code> if there is none.
|
||||
*
|
||||
@@ -183,21 +180,21 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
|
||||
public DefaultListCellRenderer getDelegateRenderer() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the font used when rendering completions.
|
||||
*
|
||||
* @return The font. If this is <code>null</code>, then the default list
|
||||
* font is used.
|
||||
* @return The font. If this is <code>null</code>, then the default list font is
|
||||
* used.
|
||||
* @see #setDisplayFont(Font)
|
||||
*/
|
||||
public Font getDisplayFont() {
|
||||
return font;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the icon to use if no icon is found for a specific completion.
|
||||
* This icon is lazily created if necessary.
|
||||
* Returns the icon to use if no icon is found for a specific completion. This
|
||||
* icon is lazily created if necessary.
|
||||
*
|
||||
* @return The icon.
|
||||
* @see #createEmptyIcon()
|
||||
@@ -208,13 +205,12 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
|
||||
}
|
||||
return emptyIcon;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns an icon.
|
||||
*
|
||||
* @param resource
|
||||
* The icon to retrieve. This should either be a file,
|
||||
* or a resource loadable by the current ClassLoader.
|
||||
* @param resource The icon to retrieve. This should either be a file, or a
|
||||
* resource loadable by the current ClassLoader.
|
||||
* @return The icon.
|
||||
*/
|
||||
protected Icon getIcon(String resource) {
|
||||
@@ -229,23 +225,19 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
|
||||
}
|
||||
return url != null ? new ImageIcon(url) : null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the renderer.
|
||||
*
|
||||
* @param list
|
||||
* The list of choices being rendered.
|
||||
* @param value
|
||||
* The {@link Completion} being rendered.
|
||||
* @param index
|
||||
* The index into <code>list</code> being rendered.
|
||||
* @param selected
|
||||
* Whether the item is selected.
|
||||
* @param hasFocus
|
||||
* Whether the item has focus.
|
||||
* @param list The list of choices being rendered.
|
||||
* @param value The {@link Completion} being rendered.
|
||||
* @param index The index into <code>list</code> being rendered.
|
||||
* @param selected Whether the item is selected.
|
||||
* @param hasFocus Whether the item has focus.
|
||||
*/
|
||||
@Override
|
||||
public Component getListCellRendererComponent(JList list, Object value, int index, boolean selected, boolean hasFocus) {
|
||||
public Component getListCellRendererComponent(JList list, Object value, int index, boolean selected,
|
||||
boolean hasFocus) {
|
||||
super.getListCellRendererComponent(list, value, index, selected, hasFocus);
|
||||
if (font != null) {
|
||||
setFont(font); // Overrides super's setFont(list.getFont()).
|
||||
@@ -282,10 +274,10 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether the types of fields and return types of methods are
|
||||
* shown in the completion text.
|
||||
* Returns whether the types of fields and return types of methods are shown in
|
||||
* the completion text.
|
||||
*
|
||||
* @return Whether to show the types.
|
||||
* @see #setShowTypes(boolean)
|
||||
@@ -293,7 +285,7 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
|
||||
public boolean getShowTypes() {
|
||||
return showTypes;
|
||||
}
|
||||
|
||||
|
||||
private void init() {
|
||||
// setDisplayFont(new Font("Monospaced", Font.PLAIN, 12));
|
||||
setShowTypes(true);
|
||||
@@ -301,7 +293,7 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
|
||||
paramColor = createParamColor();
|
||||
paintTextR = new Rectangle();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
// super.paintComponent(g);
|
||||
@@ -342,22 +334,18 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prepares this renderer to display a function completion.
|
||||
*
|
||||
* @param list
|
||||
* The list of choices being rendered.
|
||||
* @param fc
|
||||
* The completion to render.
|
||||
* @param index
|
||||
* The index into <code>list</code> being rendered.
|
||||
* @param selected
|
||||
* Whether the item is selected.
|
||||
* @param hasFocus
|
||||
* Whether the item has focus.
|
||||
* @param list The list of choices being rendered.
|
||||
* @param fc The completion to render.
|
||||
* @param index The index into <code>list</code> being rendered.
|
||||
* @param selected Whether the item is selected.
|
||||
* @param hasFocus Whether the item has focus.
|
||||
*/
|
||||
protected void prepareForFunctionCompletion(JList list, FunctionCompletion fc, int index, boolean selected, boolean hasFocus) {
|
||||
protected void prepareForFunctionCompletion(JList list, FunctionCompletion fc, int index, boolean selected,
|
||||
boolean hasFocus) {
|
||||
StringBuilder sb = new StringBuilder(PREFIX);
|
||||
sb.append(fc.getName());
|
||||
char paramListStart = fc.getProvider().getParameterListStart();
|
||||
@@ -404,41 +392,32 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
|
||||
}
|
||||
setText(sb.toString());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prepares this renderer to display a markup tag completion.
|
||||
*
|
||||
* @param list
|
||||
* The list of choices being rendered.
|
||||
* @param mc
|
||||
* The completion to render.
|
||||
* @param index
|
||||
* The index into <code>list</code> being rendered.
|
||||
* @param selected
|
||||
* Whether the item is selected.
|
||||
* @param hasFocus
|
||||
* Whether the item has focus.
|
||||
* @param list The list of choices being rendered.
|
||||
* @param mc The completion to render.
|
||||
* @param index The index into <code>list</code> being rendered.
|
||||
* @param selected Whether the item is selected.
|
||||
* @param hasFocus Whether the item has focus.
|
||||
*/
|
||||
protected void prepareForMarkupTagCompletion(JList list, MarkupTagCompletion mc, int index, boolean selected, boolean hasFocus) {
|
||||
protected void prepareForMarkupTagCompletion(JList list, MarkupTagCompletion mc, int index, boolean selected,
|
||||
boolean hasFocus) {
|
||||
StringBuilder sb = new StringBuilder(PREFIX);
|
||||
sb.append(mc.getName());
|
||||
setText(sb.toString());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prepares this renderer to display a completion not specifically handled
|
||||
* elsewhere.
|
||||
*
|
||||
* @param list
|
||||
* The list of choices being rendered.
|
||||
* @param c
|
||||
* The completion to render.
|
||||
* @param index
|
||||
* The index into <code>list</code> being rendered.
|
||||
* @param selected
|
||||
* Whether the item is selected.
|
||||
* @param hasFocus
|
||||
* Whether the item has focus.
|
||||
* @param list The list of choices being rendered.
|
||||
* @param c The completion to render.
|
||||
* @param index The index into <code>list</code> being rendered.
|
||||
* @param selected Whether the item is selected.
|
||||
* @param hasFocus Whether the item has focus.
|
||||
*/
|
||||
protected void prepareForOtherCompletion(JList list, Completion c, int index, boolean selected, boolean hasFocus) {
|
||||
StringBuilder sb = new StringBuilder(PREFIX);
|
||||
@@ -458,22 +437,18 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
|
||||
}
|
||||
setText(sb.toString());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prepares this renderer to display a template completion.
|
||||
*
|
||||
* @param list
|
||||
* The list of choices being rendered.
|
||||
* @param tc
|
||||
* The completion to render.
|
||||
* @param index
|
||||
* The index into <code>list</code> being rendered.
|
||||
* @param selected
|
||||
* Whether the item is selected.
|
||||
* @param hasFocus
|
||||
* Whether the item has focus.
|
||||
* @param list The list of choices being rendered.
|
||||
* @param tc The completion to render.
|
||||
* @param index The index into <code>list</code> being rendered.
|
||||
* @param selected Whether the item is selected.
|
||||
* @param hasFocus Whether the item has focus.
|
||||
*/
|
||||
protected void prepareForTemplateCompletion(JList list, TemplateCompletion tc, int index, boolean selected, boolean hasFocus) {
|
||||
protected void prepareForTemplateCompletion(JList list, TemplateCompletion tc, int index, boolean selected,
|
||||
boolean hasFocus) {
|
||||
StringBuilder sb = new StringBuilder(PREFIX);
|
||||
sb.append(tc.getInputText());
|
||||
String definition = tc.getShortDescription();
|
||||
@@ -489,22 +464,18 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
|
||||
}
|
||||
setText(sb.toString());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prepares this renderer to display a variable completion.
|
||||
*
|
||||
* @param list
|
||||
* The list of choices being rendered.
|
||||
* @param vc
|
||||
* The completion to render.
|
||||
* @param index
|
||||
* The index into <code>list</code> being rendered.
|
||||
* @param selected
|
||||
* Whether the item is selected.
|
||||
* @param hasFocus
|
||||
* Whether the item has focus.
|
||||
* @param list The list of choices being rendered.
|
||||
* @param vc The completion to render.
|
||||
* @param index The index into <code>list</code> being rendered.
|
||||
* @param selected Whether the item is selected.
|
||||
* @param hasFocus Whether the item has focus.
|
||||
*/
|
||||
protected void prepareForVariableCompletion(JList list, VariableCompletion vc, int index, boolean selected, boolean hasFocus) {
|
||||
protected void prepareForVariableCompletion(JList list, VariableCompletion vc, int index, boolean selected,
|
||||
boolean hasFocus) {
|
||||
StringBuilder sb = new StringBuilder(PREFIX);
|
||||
sb.append(vc.getName());
|
||||
if (getShowTypes() && vc.getType() != null) {
|
||||
@@ -519,81 +490,73 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
|
||||
}
|
||||
setText(sb.toString());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the background color to use on alternating lines.
|
||||
*
|
||||
* @param altBG
|
||||
* The new alternate background color. If this is
|
||||
* <code>null</code>, alternating lines will not use different
|
||||
* background colors.
|
||||
* @param altBG The new alternate background color. If this is
|
||||
* <code>null</code>, alternating lines will not use different
|
||||
* background colors.
|
||||
* @see #getAlternateBackground()
|
||||
*/
|
||||
public static void setAlternateBackground(Color altBG) {
|
||||
CompletionCellRenderer.altBG = altBG;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the delegate renderer. Most users will never use this method; it
|
||||
* is primarily a hook for Substance and other Look and Feels whose
|
||||
* renderers look drastically different from the standard
|
||||
* <code>DefaultListCellRenderer</code>.
|
||||
* Sets the delegate renderer. Most users will never use this method; it is
|
||||
* primarily a hook for Substance and other Look and Feels whose renderers look
|
||||
* drastically different from the standard <code>DefaultListCellRenderer</code>.
|
||||
*
|
||||
* @param delegate
|
||||
* The new delegate renderer. If this is <code>null</code>,
|
||||
* the default rendering of this component is used.
|
||||
* @param delegate The new delegate renderer. If this is <code>null</code>, the
|
||||
* default rendering of this component is used.
|
||||
* @see #getDelegateRenderer()
|
||||
* @see #delegateToSubstanceRenderer()
|
||||
*/
|
||||
public void setDelegateRenderer(DefaultListCellRenderer delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the font to use when rendering completion items.
|
||||
*
|
||||
* @param font
|
||||
* The font to use. If this is <code>null</code>, then
|
||||
* the default list font is used.
|
||||
* @param font The font to use. If this is <code>null</code>, then the default
|
||||
* list font is used.
|
||||
* @see #getDisplayFont()
|
||||
*/
|
||||
public void setDisplayFont(Font font) {
|
||||
this.font = font;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the icon to display based off of a completion, falling back to the
|
||||
* empty icon if the completion has no icon.
|
||||
* Sets the icon to display based off of a completion, falling back to the empty
|
||||
* icon if the completion has no icon.
|
||||
*
|
||||
* @param completion
|
||||
* The completion to check.
|
||||
* @param completion The completion to check.
|
||||
* @see #setIconWithDefault(Completion, Icon)
|
||||
*/
|
||||
protected void setIconWithDefault(Completion completion) {
|
||||
setIconWithDefault(completion, getEmptyIcon());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the icon to display based off of a completion, falling back to a
|
||||
* default icon if the completion has no icon.
|
||||
* Sets the icon to display based off of a completion, falling back to a default
|
||||
* icon if the completion has no icon.
|
||||
*
|
||||
* @param completion
|
||||
* The completion to check.
|
||||
* @param defaultIcon
|
||||
* The icon to use if <code>completion</code> does not
|
||||
* specify an icon.
|
||||
* @param completion The completion to check.
|
||||
* @param defaultIcon The icon to use if <code>completion</code> does not
|
||||
* specify an icon.
|
||||
* @see #setIconWithDefault(Completion)
|
||||
*/
|
||||
protected void setIconWithDefault(Completion completion, Icon defaultIcon) {
|
||||
Icon icon = completion.getIcon();
|
||||
setIcon(icon != null ? icon : (defaultIcon != null ? defaultIcon : emptyIcon));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the color to use for function arguments.
|
||||
*
|
||||
* @param color
|
||||
* The color to use. This is ignored if <code>null</code>.
|
||||
* @param color The color to use. This is ignored if <code>null</code>.
|
||||
* @see #setTypeColor(Color)
|
||||
*/
|
||||
public void setParamColor(Color color) {
|
||||
@@ -601,27 +564,25 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
|
||||
paramColor = Util.getHexString(color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets whether the types of fields and return types of methods are
|
||||
* shown in the completion text.
|
||||
* Sets whether the types of fields and return types of methods are shown in the
|
||||
* completion text.
|
||||
*
|
||||
* @param show
|
||||
* Whether to show the types.
|
||||
* @param show Whether to show the types.
|
||||
* @see #getShowTypes()
|
||||
*/
|
||||
public void setShowTypes(boolean show) {
|
||||
this.showTypes = show;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the color to use for function/field types. Note that if
|
||||
* {@link #getShowTypes()} returns <code>false</code>, this property
|
||||
* effectively does nothing.
|
||||
* {@link #getShowTypes()} returns <code>false</code>, this property effectively
|
||||
* does nothing.
|
||||
*
|
||||
* @param color
|
||||
* The color to use for types. This is ignored if
|
||||
* <code>null</code>.
|
||||
* @param color The color to use for types. This is ignored if
|
||||
* <code>null</code>.
|
||||
* @see #setShowTypes(boolean)
|
||||
* @see #setParamColor(Color)
|
||||
*/
|
||||
@@ -630,7 +591,7 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
|
||||
typeColor = Util.getHexString(color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Overridden to update our delegate, if necessary.
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user