Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 04/08/2010
*
* Copyright (C) 2010 Robert Futrell
* robert_futrell at users.sourceforge.net
* http://fifesoft.com/rsyntaxtextarea
*
* This library is distributed under a modified BSD license. See the included
* LICENSE.md file for details.
*/
package org.fife.rsta.ac.java;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.Icon;
import org.fife.ui.autocomplete.CompletionProvider;
import org.fife.ui.autocomplete.ShorthandCompletion;
/**
* A completion for shorthand items that mimics the style seen in Eclipse.
*
* @author Robert Futrell
* @version 1.0
*/
class JavaShorthandCompletion extends ShorthandCompletion implements
JavaSourceCompletion {
private static final Color SHORTHAND_COLOR = new Color(0, 127, 174);
/**
* Constructor.
*
* @param provider The completion provider.
* @param inputText The input text.
* @param replacementText The replacement text.
*/
JavaShorthandCompletion(CompletionProvider provider,
String inputText, String replacementText) {
super(provider, inputText, replacementText);
}
/**
* Constructor.
*
* @param provider The completion provider.
* @param inputText The input text.
* @param replacementText The replacement text.
* @param shortDesc A short description of the completion.
*/
JavaShorthandCompletion(CompletionProvider provider,
String inputText, String replacementText, String shortDesc) {
super(provider, inputText, replacementText, shortDesc);
}
@Override
public Icon getIcon() {
return IconFactory.get().getIcon(IconFactory.TEMPLATE_ICON);
}
/**
* {@inheritDoc}
*/
@Override
public void rendererText(Graphics g, int x, int y, boolean selected) {
renderText(g, getInputText(), getReplacementText(), x, y, selected);
}
/**
* Renders a completion in the style of a short-hand completion.
*
* @param g The graphics context.
* @param input The text the user enters to display this completion.
* @param shortDesc An optional short description of the completion.
* @param x The x-offset at which to paint.
* @param y The y-offset at which to paint.
* @param selected Whether this completion choice is selected.
*/
public static void renderText(Graphics g, String input, String shortDesc,
int x, int y, boolean selected) {
Color orig = g.getColor();
if (!selected && shortDesc!=null) {
g.setColor(SHORTHAND_COLOR);
}
g.drawString(input, x, y);
if (shortDesc!=null) {
x += g.getFontMetrics().stringWidth(input);
if (!selected) {
g.setColor(orig);
}
String temp = " - ";
g.drawString(temp, x, y);
x += g.getFontMetrics().stringWidth(temp);
if (!selected) {
g.setColor(Color.GRAY);
}
g.drawString(shortDesc, x, y);
}
}
}