From fae321cd99da8715b36272cb643d81970abb8da9 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 7 Jun 2017 18:53:59 +0200 Subject: [PATCH] Added CompletionsRenderer --- .../arduino/autocomplete/CompletionType.java | 36 ++++ .../autocomplete/CompletionsRenderer.java | 168 ++++++++++++++++++ .../cc/arduino/autocomplete/icons/class.gif | Bin 0 -> 586 bytes .../cc/arduino/autocomplete/icons/enum.gif | Bin 0 -> 361 bytes .../cc/arduino/autocomplete/icons/error.gif | Bin 0 -> 339 bytes .../autocomplete/icons/field_default_obj.gif | Bin 0 -> 118 bytes .../autocomplete/icons/field_public_obj.gif | Bin 0 -> 124 bytes .../arduino/autocomplete/icons/function.gif | Bin 0 -> 193 bytes .../autocomplete/icons/function_static.gif | Bin 0 -> 331 bytes .../cc/arduino/autocomplete/icons/int_obj.gif | Bin 0 -> 574 bytes .../autocomplete/icons/jdoc_tag_obj.gif | Bin 0 -> 323 bytes .../arduino/autocomplete/icons/static_co.gif | Bin 0 -> 107 bytes .../autocomplete/icons/template_obj.gif | Bin 0 -> 359 bytes .../arduino/autocomplete/icons/variable.gif | Bin 0 -> 176 bytes .../autocomplete/icons/variable_local.gif | Bin 0 -> 152 bytes .../autocomplete/icons/variable_static.gif | Bin 0 -> 188 bytes app/src/processing/app/EditorTab.java | 2 + .../processing/app/syntax/SketchTextArea.java | 1 + 18 files changed, 207 insertions(+) create mode 100644 app/src/cc/arduino/autocomplete/CompletionType.java create mode 100644 app/src/cc/arduino/autocomplete/CompletionsRenderer.java create mode 100644 app/src/cc/arduino/autocomplete/icons/class.gif create mode 100644 app/src/cc/arduino/autocomplete/icons/enum.gif create mode 100644 app/src/cc/arduino/autocomplete/icons/error.gif create mode 100644 app/src/cc/arduino/autocomplete/icons/field_default_obj.gif create mode 100644 app/src/cc/arduino/autocomplete/icons/field_public_obj.gif create mode 100644 app/src/cc/arduino/autocomplete/icons/function.gif create mode 100644 app/src/cc/arduino/autocomplete/icons/function_static.gif create mode 100644 app/src/cc/arduino/autocomplete/icons/int_obj.gif create mode 100644 app/src/cc/arduino/autocomplete/icons/jdoc_tag_obj.gif create mode 100644 app/src/cc/arduino/autocomplete/icons/static_co.gif create mode 100644 app/src/cc/arduino/autocomplete/icons/template_obj.gif create mode 100644 app/src/cc/arduino/autocomplete/icons/variable.gif create mode 100644 app/src/cc/arduino/autocomplete/icons/variable_local.gif create mode 100644 app/src/cc/arduino/autocomplete/icons/variable_static.gif 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 0000000000000000000000000000000000000000..e4c2a836f83e7dc72d29873fded01e7206eba2f5 GIT binary patch literal 586 zcmZ?wbhEHb6krfwc*ekxv!cRsX(Ohwq+z^!{nkw1lu( zDPc2HV&`P7KEHX-jYA>R6T@ewM9fTyo0E0x)!k_2wz@P-Sk|APSoeSzXn7Dfh!ClGm2|QYKe-7h)T#Q@$He9j?`9AQ4ux} zP&?5iq-<&#X{ezXX|J!t&@97aWMj6{+|Gn&T@xp-YRQ`y8=a5yFmmdtZYWsP+AXH8 bqq4{4!~q5-W`Qq@Pi$O#yuX);k--`O+yTtY literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..15535f52f52b20b465a9adbe6c766edffc0a287c GIT binary patch literal 361 zcmZ?wbhEHb6krfwxXQrL6RFS_qtX|v+8?VnAx?clyvD=?%}I&claqBPr|3^fHJF-i zG(E#~Mz+Pw9Lrg`Hna2X<`p~7D{+}$>bjuJePOxB!g9~W)xJw={Fl}SF0Bh(Rv)~w zIbv07^!o0U4ZUfbCS+}yoVRUS(au@ryXI8wo?EkTVdH@%t%sI(9$z=<%(l7bb}YEK zXX%aOTOM9M^8eqz|Ns9pkOCBcvM@3*7%=F7G=coYz}Dt4L*UsZ2Lb-x>=P|h1!TLo zBx{(?ZMm4W`z^y7XK^Kws+nhXx)U|`GaEA_V|tnb zI~QvO=Y%vZB_-(z%}z30f`V!4a~8-YG6)NI>Sr?KIH@r5YHZjb%dQfx!XzXnDkj9V XHQYsnn}=Is^??&7Po4I4WUvMR>jHhA literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..0bc60689c6dcbfb71770789a3c2e98f51f6eecd7 GIT binary patch literal 339 zcmZ?wbhEHb6krfwxXQrrHNWU4 z&?^&f5)>{J;LlXy?-rkKN~SlYRx@jnVRxXubL!4|)qjO}gg>klxZ?TGXw~#-V zU_Y2&N}FX?r*L1YbYiM-aj|xBv2}#Mgo3?-guaA=wSS1Yfrz+)iMWB7#*ml2h^x<; ztIwFU(w+bR{{R30A^8LW0015UEC2ui01yBW000F(peK%GX`X1Rt}L1aL$Vf5mpMgx vG+WO#2NYmJDM}^)l;8n@L?90V%CN9pFcyU&MPO(u48jTlL$uClRtNw)MiWcq literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..e02dc63568c9daad9b02dd9f7772371044579db4 GIT binary patch literal 331 zcmZ?wbhEHb6krfwSgOcyoJp6t!GpEYQ?@5eZ)$@5^aT4E@y>H{yk@8RE-nsRUJ$>k zBxzMa%DUFVjirSf%knpNJ?mXixUIKz`-G;g^&LAJJ9jj8>}+h>+tjkJrDcE1^t~N3 zj!js7e#YwaGq+rt`(e-V|Fi^({{)?jQWHy3QxwWGOEMJPJ$(Zh6o0ZXGBDUP=r8~Q z$fFEw!3X9Sc<4xVD=;vW=rFaMe`cVisy6*>XM@2^IpJ>pbit*3s$BiMgah4r7=6;# t9b}oseC+YV3IjG@UN&)2F>zMjAa)LE5f1iHdx2Cc literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..2ebc46e1d3bc5ff3f095274d451e1c1acac6e8fb GIT binary patch literal 574 zcmZ?wbhEHb6krfwc*ekRbkBpMd+%Mp__82wLw@YKqJ)iw@f(U0Hsn$Z9h7r>-fBhr|0yaoImOGqG@NA&OE%B11e|ducvPA!7Nde1Kf>tC2EKTrV zloGT&HF!m8$jY4Pwb{{Ya$?pLCTz@)TUVO0skvlNXVw0;irw9{`@3rP^)(z^IQ7iB zrI&VYxOL{(lQ_SHnUQPOExqy|3>bzWQ2fcl$iU#tpaXI{C{7sIXE!)EIot8EGPCj7 zHTO7MGjs7y;$pV$?bEXob(|w=r8livQq@e%X}J@Vn1!ljGat99so-*kO{P3T&Fl^= z`~mniQBJ_-+FcD#V3Z)>3Iu| zSFbp;;K0r0NAEs;_vJqrFwhbx{$ycfU{GMt0a*g_69ZdeSG?VSbEa6LMZVaWYr~0K^j^ AH2?qr literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..fdde5fbb95e50851757a749194ce6a3431bb1afb GIT binary patch literal 359 zcmZ?wbhEHb6krfwxXQp#S5Vbd+T2kyvA<>Ew4RM~ChuP`<3xJx%B+Sp`K{~Ax;NKM z+|e|BZ|B^Dy$g@DOoEfOLTT#K6{aU`Bz54qxJl zB|@GpTjyQSSo6|If~%!bfuX>+fBlAvKcbsVUTm4=8k1@Bp`yk$BvY-AEqS4bf{m7o zrj)XDt5U17vZjknd1ZAihrEo7sFZ?&?95rSL|sJ6g}6D{6_=}sxClzAimPr=lTcF? dbPViCtV#GtN}CUpjiL_ literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..f4a1ea1507068ad913d6151b496e2b303bec9dfe GIT binary patch literal 176 zcmZ?wbhEHb6krfwIKsdX(zwmBe0@;cuHd#^aw&_I)0bG5Z?LS`AP_T0C~mH3{5-LQ z`I5;CWKtH%q%M+4StygbP%d?`QpQrX?B(h?%m4rX&wv*w{$ycfU=U@{0jUDn$-t_c zpxT#`IWJ??x}4KN!Og1lb);hTDFLZjLs&~-@&N7aU#yw3L zj6O*!7R)g$izT`gnhO|N#M)YoHf)w*<7u8^I3bd&xuGoJf(!$5!&GOzd?f~J0FXsH AVE_OC literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..c63eb8506b0cac35c06a06baad1cdc84c8003803 GIT binary patch literal 188 zcmZ?wbhEHb6krfwXc1#L&ZH|4Ge;aqxDGOy%7RjY7mPuVGle$PQb+K~# z5~Yl#YT3)xbC#d<^t3GBU|F%jv3z|<