3333import java .awt .event .MouseEvent ;
3434
3535import javax .swing .DefaultListModel ;
36+ import javax .swing .ImageIcon ;
3637import javax .swing .JButton ;
3738import javax .swing .JComponent ;
3839import javax .swing .JLabel ;
4950import javax .swing .text .BadLocationException ;
5051
5152import processing .app .Base ;
53+ import processing .app .Mode ;
5254import processing .app .syntax .JEditTextArea ;
5355import processing .mode .java .JavaEditor ;
54- import processing .mode .java .JavaMode ;
5556
5657
57- /**
58- * Manages the actual suggestion popup that gets displayed
59- * @author Manindra Moharana <me@mkmoharana.com>
60- */
6158public class CompletionPanel {
62-
6359 /**
6460 * The completion list generated by ASTGenerator
6561 */
@@ -93,6 +89,11 @@ public class CompletionPanel {
9389
9490 private boolean horizontalScrollBarVisible = false ;
9591
92+ static public ImageIcon classIcon ;
93+ static public ImageIcon fieldIcon ;
94+ static public ImageIcon methodIcon ;
95+ static public ImageIcon localVarIcon ;
96+
9697
9798 /**
9899 * Triggers the completion popup
@@ -103,19 +104,23 @@ public class CompletionPanel {
103104 * @param location - Point location where popup list is to be displayed
104105 * @param dedit
105106 */
106- public CompletionPanel (final JEditTextArea textarea , int position , String subWord ,
107- DefaultListModel <CompletionCandidate > items , final Point location , JavaEditor editor ) {
107+ public CompletionPanel (final JEditTextArea textarea ,
108+ int position , String subWord ,
109+ DefaultListModel <CompletionCandidate > items ,
110+ final Point location , JavaEditor editor ) {
108111 this .textarea = (JavaTextArea ) textarea ;
109112 this .editor = editor ;
110113 this .insertionPosition = position ;
111- if (subWord .indexOf ('.' ) != -1 )
114+ if (subWord .indexOf ('.' ) != -1 ) {
112115 this .subWord = subWord .substring (subWord .lastIndexOf ('.' ) + 1 );
113- else
116+ } else {
114117 this .subWord = subWord ;
118+ }
115119 popupMenu = new JPopupMenu ();
116120 popupMenu .removeAll ();
117121 popupMenu .setOpaque (false );
118122 popupMenu .setBorder (null );
123+
119124 scrollPane = new JScrollPane ();
120125 styleScrollPane ();
121126 scrollPane .setViewportView (completionList = createSuggestionList (position , items ));
@@ -125,6 +130,18 @@ public CompletionPanel(final JEditTextArea textarea, int position, String subWor
125130 textarea .requestFocusInWindow ();
126131 popupMenu .show (textarea , location .x , textarea .getBaseline (0 , 0 ) + location .y );
127132 //log("Suggestion shown: " + System.currentTimeMillis());
133+ loadIcons ();
134+ }
135+
136+
137+ private void loadIcons () {
138+ if (classIcon == null ) {
139+ Mode mode = editor .getMode ();
140+ classIcon = mode .loadIcon ("theme/completion/icon_class_obj.png" );
141+ methodIcon = mode .loadIcon ("theme/completion/icon_methpub_obj.png" );
142+ fieldIcon = mode .loadIcon ("theme/completion/icon_field_protected_obj.png" );
143+ localVarIcon = mode .loadIcon ("theme/completion/icon_field_default_obj.png" );
144+ }
128145 }
129146
130147
@@ -203,7 +220,7 @@ private int calcHeight(int itemCount) {
203220 int maxHeight = 250 ;
204221 FontMetrics fm = textarea .getGraphics ().getFontMetrics ();
205222 float itemHeight = Math .max ((fm .getHeight () + (fm .getDescent ()) * 0.5f ),
206- JavaMode . classIcon .getIconHeight () * 1.2f );
223+ classIcon .getIconHeight () * 1.2f );
207224
208225 if (horizontalScrollBarVisible ) {
209226 itemCount ++;
@@ -237,7 +254,7 @@ private int calcWidth() {
237254 }
238255 int w = Math .min ((int ) min , maxWidth );
239256 horizontalScrollBarVisible = (w == maxWidth );
240- w += JavaMode . classIcon .getIconWidth (); // add icon width too!
257+ w += classIcon .getIconWidth (); // add icon width too!
241258 w += fm .stringWidth (" " ); // a bit of offset
242259 //log("popup width " + w);
243260 return w ; // popup menu width
@@ -535,19 +552,19 @@ public Component getListCellRendererComponent(JList<?> list, Object value,
535552 CompletionCandidate cc = (CompletionCandidate ) value ;
536553 switch (cc .getType ()) {
537554 case CompletionCandidate .LOCAL_VAR :
538- label .setIcon (JavaMode . localVarIcon );
555+ label .setIcon (localVarIcon );
539556 break ;
540557 case CompletionCandidate .LOCAL_FIELD :
541558 case CompletionCandidate .PREDEF_FIELD :
542- label .setIcon (JavaMode . fieldIcon );
559+ label .setIcon (fieldIcon );
543560 break ;
544561 case CompletionCandidate .LOCAL_METHOD :
545562 case CompletionCandidate .PREDEF_METHOD :
546- label .setIcon (JavaMode . methodIcon );
563+ label .setIcon (methodIcon );
547564 break ;
548565 case CompletionCandidate .LOCAL_CLASS :
549566 case CompletionCandidate .PREDEF_CLASS :
550- label .setIcon (JavaMode . classIcon );
567+ label .setIcon (classIcon );
551568 break ;
552569
553570 default :
0 commit comments