diff --git a/app/src/cc/arduino/autocomplete/CompletionType.java b/app/src/cc/arduino/autocomplete/CompletionType.java new file mode 100644 index 000000000..12584da09 --- /dev/null +++ b/app/src/cc/arduino/autocomplete/CompletionType.java @@ -0,0 +1,36 @@ +/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + * This file is part of Arduino. + * + * Copyright 2015 Ricardo JL Rufino (ricardo@criativasoft.com.br) + * Copyright 2015 Arduino LLC + * + * Arduino is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * As a special exception, you may use this file as part of a free software + * library without restriction. Specifically, if other files instantiate + * templates or use macros or inline functions from this file, or you compile + * this file and link it with other files to produce an executable, this + * file does not by itself cause the resulting executable to be covered by + * the GNU General Public License. This exception does not however + * invalidate any other reasons why the executable file might be covered by + * the GNU General Public License. + */ +package cc.arduino.autocomplete; + +public enum CompletionType { + LIBRARY, CLASS, ENUM, STRUCT, LOCAL_VAR, STATIC_VAR, VARIABLE, FUNCTION, TEMPLATE, ERROR +} diff --git a/app/src/cc/arduino/autocomplete/CompletionsRenderer.java b/app/src/cc/arduino/autocomplete/CompletionsRenderer.java new file mode 100644 index 000000000..aed8099a8 --- /dev/null +++ b/app/src/cc/arduino/autocomplete/CompletionsRenderer.java @@ -0,0 +1,168 @@ +/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ +/* + * This file is part of Arduino. + * + * Copyright 2015 Ricardo JL Rufino (ricardo@criativasoft.com.br) + * Copyright 2015 Arduino LLC + * + * Arduino is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * As a special exception, you may use this file as part of a free software + * library without restriction. Specifically, if other files instantiate + * templates or use macros or inline functions from this file, or you compile + * this file and link it with other files to produce an executable, this + * file does not by itself cause the resulting executable to be covered by + * the GNU General Public License. This exception does not however + * invalidate any other reasons why the executable file might be covered by + * the GNU General Public License. + */ +package cc.arduino.autocomplete; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Font; +import java.util.HashMap; +import java.util.Map; + +import javax.swing.DefaultListCellRenderer; +import javax.swing.Icon; +import javax.swing.ImageIcon; +import javax.swing.JList; + +import org.fife.ui.autocomplete.BasicCompletion; +import org.fife.ui.autocomplete.FunctionCompletion; +import org.fife.ui.autocomplete.ShorthandCompletion; +import org.fife.ui.autocomplete.TemplateCompletion; +import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; + +//import br.com.criativasoft.cpluslibparser.metadata.TElement; +//import br.com.criativasoft.cpluslibparser.metadata.TFunction; + +/** + * Class responsible for formatting the elements of the autocomplete list + */ +public class CompletionsRenderer extends DefaultListCellRenderer { + + private static final long serialVersionUID = 1L; + + private static final Color HIGHLIGHT_COLOR = new Color(74, 144, 217); + + private static final String GRAY = "#A0A0A0"; + private static final String LIGHT_BLUE = "#008080"; + + /** + * Keeps the HTML descriptions from "wrapping" in the list, which cuts off + * words. + */ + private static final String PREFIX = ""; + + private static Map iconsTypes = new HashMap(); + + static { + iconsTypes.put(CompletionType.CLASS, getIcon("class.gif")); + iconsTypes.put(CompletionType.ENUM, getIcon("enum.gif")); + iconsTypes.put(CompletionType.VARIABLE, getIcon("variable.gif")); + iconsTypes.put(CompletionType.LOCAL_VAR, getIcon("variable_local.gif")); + iconsTypes.put(CompletionType.STATIC_VAR, getIcon("variable_static.gif")); + iconsTypes.put(CompletionType.FUNCTION, getIcon("function.gif")); + iconsTypes.put(CompletionType.ERROR, getIcon("error.gif")); + iconsTypes.put(CompletionType.TEMPLATE, getIcon("template_obj.gif")); + } + + private static Icon getIcon(String image) { + return new ImageIcon( + CompletionsRenderer.class.getResource("icons/" + image)); + } + + public static Icon getIcon(CompletionType tokenType) { + return iconsTypes.get(tokenType); + } + + public CompletionsRenderer() { + setOpaque(true); + // Font f = Theme.getDefaultFont(); + Font f = RSyntaxTextArea.getDefaultFont(); + setFont(f.deriveFont(f.getStyle() & ~Font.BOLD)); // remove bold. + } + + @Override + public Component getListCellRendererComponent(JList list, Object value, + int index, boolean isSelected, + boolean cellHasFocus) { + + String text = null; + CompletionType tokenType = null; + + // if (value instanceof TElementCompletion) { + // + // TElementCompletion completion = (TElementCompletion) value; + // TElement element = completion.getElement(); + // tokenType = completion.getType(); + // text = element.getHtmlRepresentation(); + // + // } else if (value instanceof TFunctionCompletion) { + // + // TFunctionCompletion completion = (TFunctionCompletion) value; + // TFunction function = completion.getFunction(); + // text = function.getHtmlRepresentation(); + // tokenType = CompletionType.FUNCTION; + // + // } else + if (value instanceof ShorthandCompletion) { + text = ((ShorthandCompletion) value).getShortDescription(); + tokenType = CompletionType.TEMPLATE; + } else if (value instanceof FunctionCompletion) { + text = ((FunctionCompletion) value).getShortDescription(); + tokenType = CompletionType.FUNCTION; + } else if (value instanceof BasicCompletion) { + text = ((BasicCompletion) value).getInputText(); + if (((BasicCompletion) value).getShortDescription() != null) { + text = ((BasicCompletion) value).getShortDescription(); + } + } else if (value instanceof TemplateCompletion) { + TemplateCompletion template = (TemplateCompletion) value; + text = font(template.getInputText(), LIGHT_BLUE) + + font(" - " + template.getDefinitionString(), GRAY); + } + + if (text == null) { + text = value.toString(); + } + + // Find Icon + if (tokenType != null) { + setIcon(iconsTypes.get(tokenType)); + } else { + setIcon(iconsTypes.get(CompletionType.TEMPLATE)); + } + + if (isSelected) { + setText(text.replaceAll("\\<[^>]*>", "")); + setBackground(HIGHLIGHT_COLOR); + setForeground(Color.white); + } else { + setText(PREFIX + text); + setBackground(Color.white); + setForeground(Color.black); + } + + return this; + } + + private String font(String text, String color) { + return "" + text + ""; + } + +} \ No newline at end of file diff --git a/app/src/cc/arduino/autocomplete/icons/class.gif b/app/src/cc/arduino/autocomplete/icons/class.gif new file mode 100644 index 000000000..e4c2a836f Binary files /dev/null and b/app/src/cc/arduino/autocomplete/icons/class.gif differ diff --git a/app/src/cc/arduino/autocomplete/icons/enum.gif b/app/src/cc/arduino/autocomplete/icons/enum.gif new file mode 100644 index 000000000..15535f52f Binary files /dev/null and b/app/src/cc/arduino/autocomplete/icons/enum.gif differ diff --git a/app/src/cc/arduino/autocomplete/icons/error.gif b/app/src/cc/arduino/autocomplete/icons/error.gif new file mode 100644 index 000000000..0bc60689c Binary files /dev/null and b/app/src/cc/arduino/autocomplete/icons/error.gif differ diff --git a/app/src/cc/arduino/autocomplete/icons/field_default_obj.gif b/app/src/cc/arduino/autocomplete/icons/field_default_obj.gif new file mode 100644 index 000000000..6929d3d13 Binary files /dev/null and b/app/src/cc/arduino/autocomplete/icons/field_default_obj.gif differ diff --git a/app/src/cc/arduino/autocomplete/icons/field_public_obj.gif b/app/src/cc/arduino/autocomplete/icons/field_public_obj.gif new file mode 100644 index 000000000..d4cb4254d Binary files /dev/null and b/app/src/cc/arduino/autocomplete/icons/field_public_obj.gif differ diff --git a/app/src/cc/arduino/autocomplete/icons/function.gif b/app/src/cc/arduino/autocomplete/icons/function.gif new file mode 100644 index 000000000..7d24707ee Binary files /dev/null and b/app/src/cc/arduino/autocomplete/icons/function.gif differ diff --git a/app/src/cc/arduino/autocomplete/icons/function_static.gif b/app/src/cc/arduino/autocomplete/icons/function_static.gif new file mode 100644 index 000000000..e02dc6356 Binary files /dev/null and b/app/src/cc/arduino/autocomplete/icons/function_static.gif differ diff --git a/app/src/cc/arduino/autocomplete/icons/int_obj.gif b/app/src/cc/arduino/autocomplete/icons/int_obj.gif new file mode 100644 index 000000000..2ebc46e1d Binary files /dev/null and b/app/src/cc/arduino/autocomplete/icons/int_obj.gif differ diff --git a/app/src/cc/arduino/autocomplete/icons/jdoc_tag_obj.gif b/app/src/cc/arduino/autocomplete/icons/jdoc_tag_obj.gif new file mode 100644 index 000000000..c43c5d51c Binary files /dev/null and b/app/src/cc/arduino/autocomplete/icons/jdoc_tag_obj.gif differ diff --git a/app/src/cc/arduino/autocomplete/icons/static_co.gif b/app/src/cc/arduino/autocomplete/icons/static_co.gif new file mode 100644 index 000000000..6119fb446 Binary files /dev/null and b/app/src/cc/arduino/autocomplete/icons/static_co.gif differ diff --git a/app/src/cc/arduino/autocomplete/icons/template_obj.gif b/app/src/cc/arduino/autocomplete/icons/template_obj.gif new file mode 100644 index 000000000..fdde5fbb9 Binary files /dev/null and b/app/src/cc/arduino/autocomplete/icons/template_obj.gif differ diff --git a/app/src/cc/arduino/autocomplete/icons/variable.gif b/app/src/cc/arduino/autocomplete/icons/variable.gif new file mode 100644 index 000000000..f4a1ea150 Binary files /dev/null and b/app/src/cc/arduino/autocomplete/icons/variable.gif differ diff --git a/app/src/cc/arduino/autocomplete/icons/variable_local.gif b/app/src/cc/arduino/autocomplete/icons/variable_local.gif new file mode 100644 index 000000000..8adce9541 Binary files /dev/null and b/app/src/cc/arduino/autocomplete/icons/variable_local.gif differ diff --git a/app/src/cc/arduino/autocomplete/icons/variable_static.gif b/app/src/cc/arduino/autocomplete/icons/variable_static.gif new file mode 100644 index 000000000..c63eb8506 Binary files /dev/null and b/app/src/cc/arduino/autocomplete/icons/variable_static.gif differ diff --git a/app/src/processing/app/EditorTab.java b/app/src/processing/app/EditorTab.java index 9765ba4f6..dee774e2d 100644 --- a/app/src/processing/app/EditorTab.java +++ b/app/src/processing/app/EditorTab.java @@ -67,6 +67,7 @@ import org.fife.ui.rtextarea.RTextScrollPane; import cc.arduino.UpdatableBoardsLibsFakeURLsHandler; import cc.arduino.autocomplete.ClangCompletionProvider; +import cc.arduino.autocomplete.CompletionsRenderer; import processing.app.helpers.DocumentTextChangeListener; import processing.app.syntax.ArduinoTokenMakerFactory; import processing.app.syntax.PdeKeywords; @@ -129,6 +130,7 @@ public class EditorTab extends JPanel implements SketchFile.TextStorage { ac.setShowDescWindow(false); ac.setAutoCompleteSingleChoices(true); ac.setParameterAssistanceEnabled(true); + ac.setListCellRenderer(new CompletionsRenderer()); // ac.setParamChoicesRenderer(new CompletionsRenderer()); // ac.setListCellRenderer(new CompletionsRenderer()); ac.install(textarea); diff --git a/app/src/processing/app/syntax/SketchTextArea.java b/app/src/processing/app/syntax/SketchTextArea.java index 060409ba5..7801f1a0c 100644 --- a/app/src/processing/app/syntax/SketchTextArea.java +++ b/app/src/processing/app/syntax/SketchTextArea.java @@ -117,6 +117,7 @@ import processing.app.helpers.OSUtils; * @author Ricardo JL Rufino (ricardo@criativasoft.com.br) * @since 1.6.4 */ +@SuppressWarnings("unused") public class SketchTextArea extends RSyntaxTextArea { private final static Logger LOG = Logger.getLogger(SketchTextArea.class.getName());