Skip to content

Commit 2e0afdc

Browse files
committed
2x icons and rid of the ugly border in the completion panel (processing#3906)
1 parent 340051f commit 2e0afdc

4 files changed

Lines changed: 85 additions & 58 deletions

File tree

app/src/processing/app/ui/EditorFooter.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
import processing.app.Mode;
4343
import processing.app.Sketch;
44+
import processing.app.contrib.ContributionManager;
4445

4546

4647
/**
@@ -70,7 +71,9 @@ public class EditorFooter extends Box {
7071

7172
Color[] textColor = new Color[2];
7273
Color[] tabColor = new Color[2];
74+
7375
Color updateColor;
76+
int updateLeft, updateRight;
7477

7578
Editor editor;
7679

@@ -188,6 +191,9 @@ public void mousePressed(MouseEvent e) {
188191
repaint();
189192
}
190193
}
194+
if (x > updateLeft) {
195+
ContributionManager.openUpdates();
196+
}
191197
}
192198
});
193199
}
@@ -297,7 +303,8 @@ private void drawUpdates(Graphics2D g2) {
297303
g2.drawString(updatesStr, (int) (ex + (diameter - countWidth)/2), baseline);
298304
double updatesWidth = font.getStringBounds(updateLabel, frc).getWidth();
299305
g2.setColor(textColor[UNSELECTED]);
300-
g2.drawString(updateLabel, (int) (ex - updatesWidth - GAP), baseline);
306+
updateLeft = (int) (ex - updatesWidth - GAP);
307+
g2.drawString(updateLabel, updateLeft, baseline);
301308
}
302309
}
303310

app/src/processing/app/ui/Toolkit.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -489,25 +489,22 @@ static public ImageIcon getLibIcon(String filename) {
489489
}
490490

491491

492-
/**
493-
* Get an image icon with hi-dpi support. Pulls 1x or 2x versions of the
494-
* file depending on the display type, but sizes them based on 1x.
495-
*/
496-
static public ImageIcon getLibIconX(String base) {
497-
return getLibIconX(base, 0);
492+
static public ImageIcon getIconX(File dir, String base) {
493+
return getIconX(dir, base, 0);
498494
}
499495

500496

501497
/**
502498
* Get an icon of the format base-NN.png where NN is the size, but if it's
503499
* a hidpi display, get the NN*2 version automatically, sized at NN
504500
*/
505-
static public ImageIcon getLibIconX(String base, int size) {
501+
static public ImageIcon getIconX(File dir, String base, int size) {
506502
final int scale = Toolkit.highResDisplay() ? 2 : 1;
507503
String filename = (size == 0) ?
508504
(base + "-" + scale + "x.png") :
509505
(base + "-" + (size*scale) + ".png");
510-
File file = Platform.getContentFile("lib/" + filename);
506+
// File file = Platform.getContentFile("lib/" + filename);
507+
File file = new File(dir, filename);
511508
if (!file.exists()) {
512509
// System.err.println("does not exist: " + file);
513510
return null;
@@ -536,6 +533,20 @@ public synchronized void paintIcon(Component c, Graphics g, int x, int y) {
536533
}
537534

538535

536+
/**
537+
* Get an image icon with hi-dpi support. Pulls 1x or 2x versions of the
538+
* file depending on the display type, but sizes them based on 1x.
539+
*/
540+
static public ImageIcon getLibIconX(String base) {
541+
return getLibIconX(base, 0);
542+
}
543+
544+
545+
static public ImageIcon getLibIconX(String base, int size) {
546+
return getIconX(Platform.getContentFile("lib"), base, size);
547+
}
548+
549+
539550
static List<Image> iconImages;
540551

541552

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

Lines changed: 48 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,27 @@
2121
package processing.mode.java.pdex;
2222

2323
import java.awt.BorderLayout;
24-
import java.awt.Color;
2524
import java.awt.Component;
26-
import java.awt.Dimension;
2725
import java.awt.FontMetrics;
28-
import java.awt.Graphics;
29-
import java.awt.Graphics2D;
3026
import java.awt.Point;
31-
import java.awt.Rectangle;
3227
import java.awt.event.MouseAdapter;
3328
import java.awt.event.MouseEvent;
29+
import java.io.File;
3430

3531
import javax.swing.DefaultListModel;
3632
import javax.swing.ImageIcon;
37-
import javax.swing.JButton;
38-
import javax.swing.JComponent;
3933
import javax.swing.JLabel;
4034
import javax.swing.JList;
4135
import javax.swing.JPopupMenu;
4236
import javax.swing.JScrollPane;
4337
import 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;
4938
import javax.swing.text.BadLocationException;
5039

5140
import processing.app.Base;
5241
import processing.app.Messages;
5342
import processing.app.Mode;
5443
import processing.app.syntax.JEditTextArea;
44+
import processing.app.ui.Toolkit;
5545
import 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) {

todo.txt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ X https://github.com/processing/processing/issues/3518
2121
X https://github.com/processing/processing/pull/3896
2222
X https://github.com/processing/processing/pull/3901
2323
o total number of updates available is not correct? (may be fixed)
24+
o ArrayIndexOutOfBoundsException freak out when clicking the header line
25+
o think this was on name, with libraries, but not sure
26+
X should be fixed with the updates from Jakub
2427

2528
gui
2629
X distinguish errors and warnings
@@ -57,6 +60,11 @@ X implement custom tooltip for error/warning hover
5760
X applies to both MarkerColumn and JavaTextAreaPainter
5861
X make gutter of console match error list
5962
X https://github.com/processing/processing/issues/3904
63+
o bring back the # of updates on the update tab
64+
o use this instead of the 'icon' stuff?
65+
o or in addition, since only the 'updates' tab has it
66+
X https://github.com/processing/processing/issues/3855
67+
X for updates available, have it be clickable to open the manager
6068

6169
earlier/cleaning
6270
X list with contrib types separated is really wonky
@@ -82,10 +90,11 @@ _ mouse events (i.e. toggle breakpoint) seem to be firing twice
8290
3.0 final
8391
_ https://github.com/processing/processing/milestones/3.0%20final
8492
_ fix the design of the completions window
85-
_ remove extra border around the outside
93+
X remove extra border around the outside
8694
_ change font
8795
_ change selection highlight color
8896
_ put some margin around it
97+
X add 2x version of the icons
8998
_ https://github.com/processing/processing/issues/3906
9099
_ import suggestions box needs design review
91100
_ https://github.com/processing/processing/issues/3407
@@ -94,11 +103,6 @@ _ easy to do inside JavaTextAreaPainter.paintSquiggle()
94103

95104

96105
manager / 3.0 final
97-
_ bring back the # of updates on the update tab
98-
_ use this instead of the 'icon' stuff?
99-
_ or in addition, since only the 'updates' tab has it
100-
_ https://github.com/processing/processing/issues/3855
101-
_ for updates available, have it be clickable to open the manager
102106
_ ugly white gap at the top of scroll bar
103107
_ the table header doesn't extend far enough
104108
_ scrolling "past" top/bottom causes the screen to jiggle (OS X and Trackpad)
@@ -126,8 +130,6 @@ _ https://github.com/processing/processing/issues/136
126130
manager / post 3.0
127131
_ Examples window closes and re-opens during library install/remove
128132
_ https://github.com/processing/processing/issues/3304
129-
_ ArrayIndexOutOfBoundsException freak out when clicking the header line
130-
_ think this was on name, with libraries, but not sure
131133
_ CM - Icon instead of an "X" for the "could not connect" message
132134
_ https://github.com/processing/processing/issues/3706
133135

0 commit comments

Comments
 (0)