* 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
* RSTALanguageSupport.License.txt file for details.
package org.fife.rsta.ac.c;
import javax.swing.ImageIcon;
import javax.swing.JList;
import org.fife.ui.autocomplete.Completion;
import org.fife.ui.autocomplete.CompletionCellRenderer;
import org.fife.ui.autocomplete.EmptyIcon;
import org.fife.ui.autocomplete.FunctionCompletion;
import org.fife.ui.autocomplete.VariableCompletion;
* The cell renderer used for the C programming language.
class CCellRenderer extends CompletionCellRenderer {
private Icon variableIcon;
private Icon functionIcon;
emptyIcon = new EmptyIcon(16); // Should be done first
variableIcon = getIcon("var.png");
functionIcon = getIcon("function.png");
* @param resource The icon to retrieve. This should either be a file,
* or a resource loadable by the current ClassLoader.
private Icon getIcon(String resource) {
URL url = getClass().getResource(resource); // Should never be null
return url!=null ? new ImageIcon(url) : emptyIcon;
protected void prepareForOtherCompletion(JList list,
Completion c, int index, boolean selected, boolean hasFocus) {
super.prepareForOtherCompletion(list, c, index, selected, hasFocus);
protected void prepareForVariableCompletion(JList list,
VariableCompletion vc, int index, boolean selected,
super.prepareForVariableCompletion(list, vc, index, selected,
protected void prepareForFunctionCompletion(JList list,
FunctionCompletion fc, int index, boolean selected,
super.prepareForFunctionCompletion(list, fc, index, selected,