2121package processing .mode .java .pdex ;
2222
2323import java .awt .BorderLayout ;
24- import java .awt .Color ;
2524import java .awt .Component ;
26- import java .awt .Dimension ;
2725import java .awt .FontMetrics ;
28- import java .awt .Graphics ;
29- import java .awt .Graphics2D ;
3026import java .awt .Point ;
31- import java .awt .Rectangle ;
3227import java .awt .event .MouseAdapter ;
3328import java .awt .event .MouseEvent ;
29+ import java .io .File ;
3430
3531import javax .swing .DefaultListModel ;
3632import javax .swing .ImageIcon ;
37- import javax .swing .JButton ;
38- import javax .swing .JComponent ;
3933import javax .swing .JLabel ;
4034import javax .swing .JList ;
4135import javax .swing .JPopupMenu ;
4236import javax .swing .JScrollPane ;
4337import javax .swing .ListSelectionModel ;
44- import javax .swing .Painter ;
45- import javax .swing .UIDefaults ;
46- import javax .swing .UIManager ;
47- import javax .swing .plaf .InsetsUIResource ;
48- import javax .swing .plaf .basic .BasicScrollBarUI ;
4938import javax .swing .text .BadLocationException ;
5039
5140import processing .app .Base ;
5241import processing .app .Messages ;
5342import processing .app .Mode ;
5443import processing .app .syntax .JEditTextArea ;
44+ import processing .app .ui .Toolkit ;
5545import processing .mode .java .JavaEditor ;
5646
5747
@@ -117,15 +107,43 @@ public CompletionPanel(final JEditTextArea textarea,
117107 this .subWord = subWord ;
118108 }
119109
120- loadIcons ();
110+ if (classIcon == null ) {
111+ File dir = new File (editor .getMode ().getFolder (), "theme/completion" );
112+ classIcon = Toolkit .getIconX (dir , "class_obj" );
113+ methodIcon = Toolkit .getIconX (dir , "methpub_obj" );
114+ fieldIcon = Toolkit .getIconX (dir , "field_protected_obj" );
115+ localVarIcon = Toolkit .getIconX (dir , "field_default_obj" );
116+ }
117+
121118 popupMenu = new JPopupMenu ();
122119 popupMenu .removeAll ();
123120 popupMenu .setOpaque (false );
124121 popupMenu .setBorder (null );
125122
126123 scrollPane = new JScrollPane ();
127- styleScrollPane ();
128- scrollPane .setViewportView (completionList = createSuggestionList (position , items ));
124+ // styleScrollPane();
125+ //scrollPane.setViewportView(completionList = createSuggestionList(position, items));
126+ completionList = new JList <CompletionCandidate >(items ) {
127+ {
128+ setSelectionMode (ListSelectionModel .SINGLE_SELECTION );
129+ setSelectedIndex (0 );
130+ addMouseListener (new MouseAdapter () {
131+ @ Override
132+ public void mouseClicked (MouseEvent e ) {
133+ if (e .getClickCount () == 2 ) {
134+ insertSelection (MOUSE_COMPLETION );
135+ setInvisible ();
136+ }
137+ }
138+ });
139+ setCellRenderer (new CustomListRenderer ());
140+ setFocusable (false );
141+ }
142+ };
143+ scrollPane .setViewportView (completionList );
144+ // remove an ugly multi-line border around it
145+ scrollPane .setBorder (null );
146+
129147 popupMenu .add (scrollPane , BorderLayout .CENTER );
130148 popupMenu .setPopupSize (calcWidth (), calcHeight (items .getSize ())); //TODO: Eradicate this evil
131149 popupMenu .setFocusable (false );
@@ -138,17 +156,7 @@ public CompletionPanel(final JEditTextArea textarea,
138156 }
139157
140158
141- private void loadIcons () {
142- if (classIcon == null ) {
143- Mode mode = editor .getMode ();
144- classIcon = mode .loadIcon ("theme/completion/class_obj.png" );
145- methodIcon = mode .loadIcon ("theme/completion/methpub_obj.png" );
146- fieldIcon = mode .loadIcon ("theme/completion/field_protected_obj.png" );
147- localVarIcon = mode .loadIcon ("theme/completion/field_default_obj.png" );
148- }
149- }
150-
151-
159+ /*
152160 private void styleScrollPane() {
153161 String laf = UIManager.getLookAndFeel().getID();
154162 if (!laf.equals("Nimbus") && !laf.equals("Windows")) return;
@@ -205,6 +213,7 @@ static private JButton createZeroButton() {
205213 return jbutton;
206214 }
207215 }
216+ */
208217
209218
210219 public boolean isVisible () {
@@ -270,7 +279,6 @@ private int calcWidth() {
270279 * @param position
271280 * @param items
272281 * @return
273- */
274282 private JList<CompletionCandidate> createSuggestionList(final int position,
275283 final DefaultListModel<CompletionCandidate> items) {
276284
@@ -291,6 +299,7 @@ public void mouseClicked(MouseEvent e) {
291299 list.setFocusable(false);
292300 return list;
293301 }
302+ */
294303
295304
296305 /*
@@ -333,8 +342,8 @@ protected boolean insertSelection(int completionSource) {
333342 try {
334343 // If user types 'abc.', subword becomes '.' and null is returned
335344 String currentSubword = fetchCurrentSubword ();
336- int currentSubwordLen = currentSubword == null ? 0 : currentSubword
337- .length ();
345+ int currentSubwordLen =
346+ ( currentSubword == null ) ? 0 : currentSubword .length ();
338347 //logE(currentSubword + " <= subword,len => " + currentSubword.length());
339348 String selectedSuggestion =
340349 completionList .getSelectedValue ().getCompletionString ();
@@ -346,13 +355,12 @@ protected boolean insertSelection(int completionSource) {
346355 }
347356
348357 String completionString =
349- completionList .getSelectedValue ().getCompletionString ();
358+ completionList .getSelectedValue ().getCompletionString ();
350359 if (selectedSuggestion .endsWith (" )" )) { // the case of single param methods
351360 // selectedSuggestion = ")";
352361 if (completionString .endsWith (" )" )) {
353- completionString = completionString .substring (0 , completionString
354- .length () - 2 )
355- + ")" ;
362+ completionString =
363+ completionString .substring (0 , completionString .length () - 2 ) + ")" ;
356364 }
357365 }
358366
@@ -365,20 +373,19 @@ protected boolean insertSelection(int completionSource) {
365373 }
366374 }
367375
368- Messages .loge (subWord + " <= subword, Inserting suggestion=> "
369- + selectedSuggestion + " Current sub: " + currentSubword );
376+ Messages .loge (subWord + " <= subword, Inserting suggestion=> " +
377+ selectedSuggestion + " Current sub: " + currentSubword );
370378 if (currentSubword .length () > 0 ) {
371379 textarea .getDocument ().remove (insertionPosition - currentSubwordLen ,
372380 currentSubwordLen );
373381 }
374382
375- textarea .getDocument ()
376- .insertString (insertionPosition - currentSubwordLen ,
377- completionString , null );
383+ textarea .getDocument ().insertString (insertionPosition - currentSubwordLen ,
384+ completionString , null );
378385 if (selectedSuggestion .endsWith (")" ) && !selectedSuggestion .endsWith ("()" )) {
379386 // place the caret between '( and first ','
380387 int x = selectedSuggestion .indexOf (',' );
381- if (x == -1 ) {
388+ if (x == -1 ) {
382389 // the case of single param methods, containing no ','
383390 textarea .setCaretPosition (textarea .getCaretPosition () - 1 ); // just before ')'
384391 } else {
@@ -395,12 +402,12 @@ protected boolean insertSelection(int completionSource) {
395402 setInvisible ();
396403 }
397404
398- if (mouseClickOnOverloadedMethods ) {
405+ if (mouseClickOnOverloadedMethods ) {
399406 // See #2755
400407 ((JavaTextArea ) editor .getTextArea ()).fetchPhrase ();
401408 }
402-
403409 return true ;
410+
404411 } catch (BadLocationException e1 ) {
405412 e1 .printStackTrace ();
406413 } catch (Exception e ) {
0 commit comments