Skip to content

Commit 7a719e1

Browse files
committed
trying to clean up DetailPanel
1 parent 10104cc commit 7a719e1

File tree

6 files changed

+85
-93
lines changed

6 files changed

+85
-93
lines changed

app/src/processing/app/contrib/DetailPanel.java

Lines changed: 52 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
* Panel that expands and gives a brief overview of a library when clicked.
6363
*/
6464
class DetailPanel extends JPanel {
65+
Base base;
66+
6567
static public final String REMOVE_RESTART_MESSAGE =
6668
String.format("<i>%s</i>", Language.text("contrib.messages.remove_restart"));
6769

@@ -104,7 +106,9 @@ public Contribution getContrib() {
104106
private JButton installRemoveButton;
105107
private JPopupMenu contextMenu;
106108
private JMenuItem openFolder;
109+
107110
private JPanel barButtonCardPane;
111+
private CardLayout barButtonCardLayout;
108112

109113
private ActionListener removeActionListener;
110114
private ActionListener installActionListener;
@@ -123,17 +127,17 @@ public Contribution getContrib() {
123127
}
124128

125129
listPanel = contributionListPanel;
130+
// TODO this accessor is dreadful
131+
base = listPanel.contributionTab.editor.getBase();
126132
barButtonCardPane = new JPanel();
127133

128134
enableHyperlinks = false;
129135
alreadySelected = false;
130136
conditionalHyperlinkOpener = new HyperlinkListener() {
131137
public void hyperlinkUpdate(HyperlinkEvent e) {
132138
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
133-
if (enableHyperlinks) {
134-
if (e.getURL() != null) {
135-
Platform.openURL(e.getURL().toString());
136-
}
139+
if (enableHyperlinks && e.getURL() != null) {
140+
Platform.openURL(e.getURL().toString());
137141
}
138142
}
139143
}
@@ -228,26 +232,19 @@ private void addPaneComponents() {
228232
if (UIManager.getLookAndFeel().getID().equals("Nimbus")) {
229233
descriptionPane.setBackground(new Color(0, 0, 0, 0));
230234
}
231-
// stripTextSelectionListeners(descriptionBlock);
232235

233236
descriptionPane.setBorder(new EmptyBorder(4, 7, 7, 7));
234237
descriptionPane.setHighlighter(null);
235238
add(descriptionPane, BorderLayout.CENTER);
236239

237-
JPanel updateBox = new JPanel(); //new BoxLayout(filterPanel, BoxLayout.X_AXIS)
240+
JPanel updateBox = new JPanel();
238241
updateBox.setLayout(new BorderLayout());
239242

240243
notificationLabel = new JLabel();
241244
notificationLabel.setInheritsPopupMenu(true);
242245
notificationLabel.setVisible(false);
243246
notificationLabel.setOpaque(false);
244-
// not needed after changing to JLabel
245-
// notificationBlock.setContentType("text/html");
246-
// notificationBlock.setHighlighter(null);
247-
// setTextStyle(notificationBlock);
248-
// notificationLabel.setFont(new Font("Verdana", Font.ITALIC, 10));
249247
notificationLabel.setFont(Toolkit.getSansFont(12, Font.PLAIN));
250-
// stripTextSelectionListeners(notificationBlock);
251248

252249
{
253250
updateButton = new JButton("Update");
@@ -279,7 +276,8 @@ public void actionPerformed(ActionEvent e) {
279276
rightPane.setMinimumSize(new Dimension(DetailPanel.BUTTON_WIDTH, 1));
280277
add(rightPane, BorderLayout.EAST);
281278

282-
barButtonCardPane.setLayout(new CardLayout());
279+
barButtonCardLayout = new CardLayout();
280+
barButtonCardPane.setLayout(barButtonCardLayout);
283281
barButtonCardPane.setInheritsPopupMenu(true);
284282
barButtonCardPane.setOpaque(false);
285283
barButtonCardPane.setMinimumSize(new Dimension(DetailPanel.BUTTON_WIDTH, 1));
@@ -312,16 +310,14 @@ public void actionPerformed(ActionEvent e) {
312310

313311
JPanel barPane = new JPanel();
314312
barPane.setOpaque(false);
315-
// barPane.add(installProgressBar);
316313

317314
JPanel buttonPane = new JPanel();
318315
buttonPane.setOpaque(false);
319316
buttonPane.add(installRemoveButton);
320317

321318
barButtonCardPane.add(buttonPane, BUTTON_CONSTRAINT);
322319
barButtonCardPane.add(barPane, PROGRESS_BAR_CONSTRAINT);
323-
324-
((CardLayout) barButtonCardPane.getLayout()).show(barButtonCardPane, BUTTON_CONSTRAINT);
320+
barButtonCardLayout.show(barButtonCardPane, BUTTON_CONSTRAINT);
325321

326322
rightPane.add(barButtonCardPane);
327323

@@ -355,7 +351,6 @@ private void reorganizePaneComponents() {
355351
rightPane.setMinimumSize(new Dimension(DetailPanel.BUTTON_WIDTH, 1));
356352
add(rightPane, BorderLayout.EAST);
357353

358-
359354
if (updateButton.isVisible() && !removeInProgress && !contrib.isDeletionFlagged()) {
360355
JPanel updateRemovePanel = new JPanel();
361356
updateRemovePanel.setLayout(new FlowLayout());
@@ -368,21 +363,18 @@ private void reorganizePaneComponents() {
368363
JPanel barPane = new JPanel();
369364
barPane.setOpaque(false);
370365
barPane.setInheritsPopupMenu(true);
371-
// barPane.add(installProgressBar);
372366
rightPane.add(barPane);
373367

374-
if (updateInProgress)
375-
((CardLayout) barButtonCardPane.getLayout()).show(barButtonCardPane, PROGRESS_BAR_CONSTRAINT);
376-
377-
}
378-
else {
368+
if (updateInProgress) {
369+
barButtonCardLayout.show(barButtonCardPane, PROGRESS_BAR_CONSTRAINT);
370+
}
371+
} else {
379372
updateBox.add(updateButton, BorderLayout.EAST);
380373
barButtonCardPane.removeAll();
381374

382375
JPanel barPane = new JPanel();
383376
barPane.setOpaque(false);
384377
barPane.setInheritsPopupMenu(true);
385-
// barPane.add(installProgressBar);
386378

387379
JPanel buttonPane = new JPanel();
388380
buttonPane.setOpaque(false);
@@ -391,34 +383,33 @@ private void reorganizePaneComponents() {
391383

392384
barButtonCardPane.add(buttonPane, BUTTON_CONSTRAINT);
393385
barButtonCardPane.add(barPane, PROGRESS_BAR_CONSTRAINT);
394-
if (installInProgress || removeInProgress || updateInProgress)
395-
((CardLayout) barButtonCardPane.getLayout()).show(barButtonCardPane, PROGRESS_BAR_CONSTRAINT);
396-
else
397-
((CardLayout) barButtonCardPane.getLayout()).show(barButtonCardPane, BUTTON_CONSTRAINT);
398-
386+
if (installInProgress || removeInProgress || updateInProgress) {
387+
barButtonCardLayout.show(barButtonCardPane, PROGRESS_BAR_CONSTRAINT);
388+
} else {
389+
barButtonCardLayout.show(barButtonCardPane, BUTTON_CONSTRAINT);
390+
}
399391
rightPane.add(barButtonCardPane);
400392
}
401393

402-
Dimension d = installProgressBar.getPreferredSize();
403-
Dimension d2 = installRemoveButton.getPreferredSize();
404-
d.width = DetailPanel.BUTTON_WIDTH;
405-
d.height = Math.max(d.height,d2.height);
406-
rightPane.setMinimumSize(d);
407-
rightPane.setPreferredSize(d);
394+
Dimension progressDim = installProgressBar.getPreferredSize();
395+
Dimension installDim = installRemoveButton.getPreferredSize();
396+
progressDim.width = DetailPanel.BUTTON_WIDTH;
397+
progressDim.height = Math.max(progressDim.height, installDim.height);
398+
rightPane.setMinimumSize(progressDim);
399+
rightPane.setPreferredSize(progressDim);
408400
}
409401

410402

411403
private void setExpandListener(Component component,
412404
MouseListener expandListener) {
413-
if (component instanceof JButton) {
414-
// This will confuse the button, causing it to stick on OS X
415-
// https://github.com/processing/processing/issues/3172
416-
return;
417-
}
418-
component.addMouseListener(expandListener);
419-
if (component instanceof Container) {
420-
for (Component child : ((Container) component).getComponents()) {
421-
setExpandListener(child, expandListener);
405+
// If it's a JButton, adding the listener will make this stick on OS X
406+
// https://github.com/processing/processing/issues/3172
407+
if (!(component instanceof JButton)) {
408+
component.addMouseListener(expandListener);
409+
if (component instanceof Container) {
410+
for (Component child : ((Container) component).getComponents()) {
411+
setExpandListener(child, expandListener);
412+
}
422413
}
423414
}
424415
}
@@ -427,8 +418,9 @@ private void setExpandListener(Component component,
427418
private void blurContributionPanel(Component component) {
428419
component.setFocusable(false);
429420
component.setEnabled(false);
430-
if (component instanceof JComponent)
421+
if (component instanceof JComponent) {
431422
((JComponent) component).setToolTipText(INCOMPATIBILITY_BLUR);
423+
}
432424
if (component instanceof Container) {
433425
for (Component child : ((Container) component).getComponents()) {
434426
blurContributionPanel(child);
@@ -589,10 +581,11 @@ public void cancelAction() {
589581
resetInstallProgressBarState();
590582
installRemoveButton.setEnabled(!contrib.isUpdateFlagged());
591583

592-
((CardLayout) barButtonCardPane.getLayout()).show(barButtonCardPane, BUTTON_CONSTRAINT);
584+
barButtonCardLayout.show(barButtonCardPane, BUTTON_CONSTRAINT);
593585
installInProgress = false;
594-
if(updateInProgress)
586+
if (updateInProgress) {
595587
updateInProgress = !updateInProgress;
588+
}
596589
updateButton.setVisible(contribListing.hasUpdates(contrib) && !contrib.isUpdateFlagged());
597590
setSelected(true);
598591
}
@@ -607,10 +600,11 @@ public void finishedAction() {
607600
if (isError()) {
608601
listPanel.contributionTab.statusPanel.setErrorMessage(Language.text("contrib.download_error"));
609602
}
610-
((CardLayout) barButtonCardPane.getLayout()).show(barButtonCardPane, BUTTON_CONSTRAINT);
603+
barButtonCardLayout.show(barButtonCardPane, BUTTON_CONSTRAINT);
611604
installInProgress = false;
612-
if(updateInProgress)
605+
if (updateInProgress) {
613606
updateInProgress = !updateInProgress;
607+
}
614608
updateButton.setVisible(contribListing.hasUpdates(contrib) && !contrib.isUpdateFlagged());
615609
setSelected(true);
616610
}
@@ -620,35 +614,19 @@ public void cancelAction() {
620614
}
621615
};
622616

623-
ContributionManager.downloadAndInstall(listPanel.contributionTab.editor.getBase(),
624-
downloadUrl, ad,
617+
ContributionManager.downloadAndInstall(base, downloadUrl, ad,
625618
downloadProgress, installProgress,
626619
listPanel.contributionTab.statusPanel);
627620

628621
} catch (MalformedURLException e) {
629622
Messages.showWarning(Language.text("contrib.errors.install_failed"),
630623
Language.text("contrib.errors.malformed_url"), e);
631624
// not sure why we'd re-enable the button if it had an error...
632-
// installRemoveButton.setEnabled(true);
625+
//installRemoveButton.setEnabled(true);
633626
}
634627
}
635628

636629

637-
// This doesn't actually seem to work?
638-
/*
639-
static void stripTextSelectionListeners(JEditorPane editorPane) {
640-
for (MouseListener listener : editorPane.getMouseListeners()) {
641-
String className = listener.getClass().getName();
642-
if (className.endsWith("MutableCaretEvent") ||
643-
className.endsWith("DragListener") ||
644-
className.endsWith("BasicCaret")) {
645-
editorPane.removeMouseListener(listener);
646-
}
647-
}
648-
}
649-
*/
650-
651-
652630
protected void resetInstallProgressBarState() {
653631
installProgressBar.setString(Language.text("contrib.progress.starting"));
654632
installProgressBar.setIndeterminate(false);
@@ -763,14 +741,15 @@ static String toHtmlLinks(String stringIn) {
763741
* Sets coloring based on whether installed or not;
764742
* also makes ugly blue HTML links into the specified color (black).
765743
*/
766-
static void setForegroundStyle(JTextPane textPane, boolean installed, boolean selected) {
744+
static void setForegroundStyle(JTextPane textPane,
745+
boolean installed, boolean selected) {
767746
Document doc = textPane.getDocument();
768747
if (doc instanceof HTMLDocument) {
769748
HTMLDocument html = (HTMLDocument) doc;
770749
StyleSheet stylesheet = html.getStyleSheet();
771750

772-
String c = (installed && !selected) ? "#555555" : "#000000"; // slightly grayed when installed
773-
// String c = "#000000"; // just make them both black
751+
// slightly grayed when installed
752+
String c = (installed && !selected) ? "#555555" : "#000000";
774753
stylesheet.addRule("body { color:" + c + "; }");
775754
stylesheet.addRule("a { color:" + c + "; }");
776755
}
@@ -784,7 +763,7 @@ static void setTextStyle(JTextPane textPane) {
784763
StyleSheet stylesheet = html.getStyleSheet();
785764
stylesheet.addRule("body { " +
786765
" margin: 0; padding: 0;" +
787-
" font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;" +
766+
" font-family: " + Toolkit.getSansFontName() + ", Arial, Helvetica, sans-serif;" +
788767
" font-size: 100%;" + "font-size: 0.95em; " +
789768
"}");
790769
}
@@ -808,7 +787,7 @@ static void setSelectionStyle(JTextPane textPane, boolean selected) {
808787
public void install() {
809788
listPanel.contributionTab.statusPanel.clearMessage();
810789
installInProgress = true;
811-
((CardLayout) barButtonCardPane.getLayout()).show(barButtonCardPane, PROGRESS_BAR_CONSTRAINT);
790+
barButtonCardLayout.show(barButtonCardPane, PROGRESS_BAR_CONSTRAINT);
812791
if (contrib instanceof AvailableContribution) {
813792
installContribution((AvailableContribution) contrib);
814793
contribListing.replaceContribution(contrib, contrib);
@@ -817,7 +796,6 @@ public void install() {
817796

818797

819798
public void update() {
820-
821799
listPanel.contributionTab.statusPanel.clearMessage();
822800
updateInProgress = true;
823801
if (contrib.getType().requiresRestart()) {
@@ -851,12 +829,7 @@ public void cancelAction() {
851829
boolean isModeActive = false;
852830
if (contrib.getType() == ContributionType.MODE) {
853831
ModeContribution m = (ModeContribution) contrib;
854-
//Iterator<Editor> iter = listPanel.contribManager.editor.getBase().getEditors().iterator();
855-
//while (iter.hasNext()) {
856-
// TODO there's gotta be a cleaner way to do this accessor
857-
Base base = listPanel.contributionTab.editor.getBase();
858832
for (Editor e : base.getEditors()) {
859-
//Editor e = iter.next();
860833
if (e.getMode().equals(m.getMode())) {
861834
isModeActive = true;
862835
break;
@@ -872,8 +845,7 @@ public void cancelAction() {
872845
}
873846
};
874847
((LocalContribution) contrib)
875-
.removeContribution(listPanel.contributionTab.editor.getBase(),
876-
progress, listPanel.contributionTab.statusPanel);
848+
.removeContribution(base, progress, listPanel.contributionTab.statusPanel);
877849
} else {
878850
updateButton.setEnabled(false);
879851
installRemoveButton.setEnabled(false);

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,8 @@ static public String[] getMonoFontFamilies() {
900900

901901
static public String getMonoFontName() {
902902
if (monoFont == null) {
903-
getMonoFont(12, Font.PLAIN); // load a dummy version
903+
// create a dummy version if the font has never been loaded (rare)
904+
getMonoFont(12, Font.PLAIN);
904905
}
905906
return monoFont.getName();
906907
}
@@ -950,6 +951,15 @@ static public Font getMonoFont(int size, int style) {
950951
}
951952

952953

954+
static public String getSansFontName() {
955+
if (sansFont == null) {
956+
// create a dummy version if the font has never been loaded (rare)
957+
getSansFont(12, Font.PLAIN);
958+
}
959+
return sansFont.getName();
960+
}
961+
962+
953963
static public Font getSansFont(int size, int style) {
954964
if (sansFont == null) {
955965
try {

core/src/processing/core/PApplet.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,7 @@ static public int displayDensity(int display) {
11941194
*
11951195
*/
11961196
public void pixelDensity(int density) {
1197+
println(density + " " + this.pixelDensity);
11971198
if (density != this.pixelDensity) {
11981199
if (insideSettings("pixelDensity", density)) {
11991200
if (density != 1 && density != 2) {
@@ -1205,6 +1206,11 @@ public void pixelDensity(int density) {
12051206
} else {
12061207
this.pixelDensity = density;
12071208
}
1209+
} else {
1210+
System.err.println("not inside settings");
1211+
// this should only be reachable when not running in the PDE,
1212+
// so saying it's a settings()--not just setup()--issue should be ok
1213+
throw new RuntimeException("pixelDensity() can only be used inside settings()");
12081214
}
12091215
}
12101216
}

core/todo.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
andres
55
X automatic detection of POINT and LINE shaders fails
66
X https://github.com/processing/processing/issues/4725
7+
X show warning when frameRate() less than 1 is called with P2D and P3D
8+
X https://github.com/processing/processing/issues/4716
79

810

911
_ TRIANGLE_STRIP not working correctly with createShape() and default renderer

java/src/processing/mode/java/Compiler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ public void close() { }
211211
String suggestion = importSuggestions.get(what);
212212
if (suggestion != null) {
213213
System.err.println("You may need to add \"import " + suggestion + ";\" to the top of your sketch.");
214-
System.err.println("To make sketches more portable, imports that are not part of the Processing API have been removed from Processing 2.0.");
215-
System.err.println("See the changes page for more information: http://wiki.processing.org/w/Changes");
214+
System.err.println("To make sketches more portable, imports that are not part of the Processing API were removed in Processing 2.");
215+
System.err.println("See the changes page for more information: https://github.com/processing/processing/wiki/Changes");
216216
}
217217
}
218218

0 commit comments

Comments
 (0)