Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/arduino/Arduino.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCristian Maglie <c.maglie@bcmi-labs.cc>2017-06-07 19:53:59 +0300
committerMartino Facchin <m.facchin@arduino.cc>2020-04-07 15:09:06 +0300
commitfae321cd99da8715b36272cb643d81970abb8da9 (patch)
tree6214999eafea38a3793c58c2dcaed8b2d5e2f3cd
parent42930e22b0c1ff8350fadfe6c89da048c7f15fab (diff)
Added CompletionsRenderer
-rw-r--r--app/src/cc/arduino/autocomplete/CompletionType.java36
-rw-r--r--app/src/cc/arduino/autocomplete/CompletionsRenderer.java168
-rw-r--r--app/src/cc/arduino/autocomplete/icons/class.gifbin0 -> 586 bytes
-rw-r--r--app/src/cc/arduino/autocomplete/icons/enum.gifbin0 -> 361 bytes
-rw-r--r--app/src/cc/arduino/autocomplete/icons/error.gifbin0 -> 339 bytes
-rw-r--r--app/src/cc/arduino/autocomplete/icons/field_default_obj.gifbin0 -> 118 bytes
-rw-r--r--app/src/cc/arduino/autocomplete/icons/field_public_obj.gifbin0 -> 124 bytes
-rw-r--r--app/src/cc/arduino/autocomplete/icons/function.gifbin0 -> 193 bytes
-rw-r--r--app/src/cc/arduino/autocomplete/icons/function_static.gifbin0 -> 331 bytes
-rw-r--r--app/src/cc/arduino/autocomplete/icons/int_obj.gifbin0 -> 574 bytes
-rw-r--r--app/src/cc/arduino/autocomplete/icons/jdoc_tag_obj.gifbin0 -> 323 bytes
-rw-r--r--app/src/cc/arduino/autocomplete/icons/static_co.gifbin0 -> 107 bytes
-rw-r--r--app/src/cc/arduino/autocomplete/icons/template_obj.gifbin0 -> 359 bytes
-rw-r--r--app/src/cc/arduino/autocomplete/icons/variable.gifbin0 -> 176 bytes
-rw-r--r--app/src/cc/arduino/autocomplete/icons/variable_local.gifbin0 -> 152 bytes
-rw-r--r--app/src/cc/arduino/autocomplete/icons/variable_static.gifbin0 -> 188 bytes
-rw-r--r--app/src/processing/app/EditorTab.java2
-rw-r--r--app/src/processing/app/syntax/SketchTextArea.java1
18 files changed, 207 insertions, 0 deletions
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 = "<html><nobr>";
+
+ private static Map<CompletionType, Icon> iconsTypes = new HashMap<CompletionType, Icon>();
+
+ 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 "<font color='" + color + "'>" + text + "</font>";
+ }
+
+} \ 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
--- /dev/null
+++ b/app/src/cc/arduino/autocomplete/icons/class.gif
Binary files 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
--- /dev/null
+++ b/app/src/cc/arduino/autocomplete/icons/enum.gif
Binary files 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
--- /dev/null
+++ b/app/src/cc/arduino/autocomplete/icons/error.gif
Binary files 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
--- /dev/null
+++ b/app/src/cc/arduino/autocomplete/icons/field_default_obj.gif
Binary files 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
--- /dev/null
+++ b/app/src/cc/arduino/autocomplete/icons/field_public_obj.gif
Binary files 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
--- /dev/null
+++ b/app/src/cc/arduino/autocomplete/icons/function.gif
Binary files 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
--- /dev/null
+++ b/app/src/cc/arduino/autocomplete/icons/function_static.gif
Binary files 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
--- /dev/null
+++ b/app/src/cc/arduino/autocomplete/icons/int_obj.gif
Binary files 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
--- /dev/null
+++ b/app/src/cc/arduino/autocomplete/icons/jdoc_tag_obj.gif
Binary files 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
--- /dev/null
+++ b/app/src/cc/arduino/autocomplete/icons/static_co.gif
Binary files 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
--- /dev/null
+++ b/app/src/cc/arduino/autocomplete/icons/template_obj.gif
Binary files 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
--- /dev/null
+++ b/app/src/cc/arduino/autocomplete/icons/variable.gif
Binary files 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
--- /dev/null
+++ b/app/src/cc/arduino/autocomplete/icons/variable_local.gif
Binary files 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
--- /dev/null
+++ b/app/src/cc/arduino/autocomplete/icons/variable_static.gif
Binary files 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());