Skip to content

Commit aa671f6

Browse files
committed
these don't make sense in Mode
1 parent 63ad988 commit aa671f6

File tree

6 files changed

+33
-35
lines changed

6 files changed

+33
-35
lines changed

java/src/processing/mode/java/JavaMode.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
import java.util.logging.Level;
3030
import java.util.logging.Logger;
3131

32-
import javax.swing.ImageIcon;
33-
3432
import processing.app.*;
3533
import processing.app.ui.Editor;
3634
import processing.app.ui.EditorException;
@@ -52,18 +50,6 @@ public JavaMode(Base base, File folder) {
5250

5351
initLogger();
5452
loadPreferences();
55-
loadIcons();
56-
}
57-
58-
59-
/**
60-
* Needed by code completion panel. See {@link processing.mode.java.pdex.CompletionPanel}
61-
*/
62-
private void loadIcons(){
63-
classIcon = loadIcon("theme/icon_class_obj.png");
64-
methodIcon = loadIcon("theme/icon_methpub_obj.png");
65-
fieldIcon = loadIcon("theme/icon_field_protected_obj.png");
66-
localVarIcon = loadIcon("theme/icon_field_default_obj.png");
6753
}
6854

6955

@@ -339,11 +325,6 @@ void initLogger() {
339325

340326
static volatile public boolean enableTweak = false;
341327

342-
static public ImageIcon classIcon;
343-
static public ImageIcon fieldIcon;
344-
static public ImageIcon methodIcon;
345-
static public ImageIcon localVarIcon;
346-
347328

348329
public void loadPreferences() {
349330
Base.log("Load PDEX prefs");

java/src/processing/mode/java/pdex/CompletionPanel.java

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.awt.event.MouseEvent;
3434

3535
import javax.swing.DefaultListModel;
36+
import javax.swing.ImageIcon;
3637
import javax.swing.JButton;
3738
import javax.swing.JComponent;
3839
import javax.swing.JLabel;
@@ -49,17 +50,12 @@
4950
import javax.swing.text.BadLocationException;
5051

5152
import processing.app.Base;
53+
import processing.app.Mode;
5254
import processing.app.syntax.JEditTextArea;
5355
import 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-
*/
6158
public 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:
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)