|
62 | 62 | * Panel that expands and gives a brief overview of a library when clicked. |
63 | 63 | */ |
64 | 64 | class DetailPanel extends JPanel { |
| 65 | + Base base; |
| 66 | + |
65 | 67 | static public final String REMOVE_RESTART_MESSAGE = |
66 | 68 | String.format("<i>%s</i>", Language.text("contrib.messages.remove_restart")); |
67 | 69 |
|
@@ -104,7 +106,9 @@ public Contribution getContrib() { |
104 | 106 | private JButton installRemoveButton; |
105 | 107 | private JPopupMenu contextMenu; |
106 | 108 | private JMenuItem openFolder; |
| 109 | + |
107 | 110 | private JPanel barButtonCardPane; |
| 111 | + private CardLayout barButtonCardLayout; |
108 | 112 |
|
109 | 113 | private ActionListener removeActionListener; |
110 | 114 | private ActionListener installActionListener; |
@@ -123,17 +127,17 @@ public Contribution getContrib() { |
123 | 127 | } |
124 | 128 |
|
125 | 129 | listPanel = contributionListPanel; |
| 130 | + // TODO this accessor is dreadful |
| 131 | + base = listPanel.contributionTab.editor.getBase(); |
126 | 132 | barButtonCardPane = new JPanel(); |
127 | 133 |
|
128 | 134 | enableHyperlinks = false; |
129 | 135 | alreadySelected = false; |
130 | 136 | conditionalHyperlinkOpener = new HyperlinkListener() { |
131 | 137 | public void hyperlinkUpdate(HyperlinkEvent e) { |
132 | 138 | 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()); |
137 | 141 | } |
138 | 142 | } |
139 | 143 | } |
@@ -228,26 +232,19 @@ private void addPaneComponents() { |
228 | 232 | if (UIManager.getLookAndFeel().getID().equals("Nimbus")) { |
229 | 233 | descriptionPane.setBackground(new Color(0, 0, 0, 0)); |
230 | 234 | } |
231 | | -// stripTextSelectionListeners(descriptionBlock); |
232 | 235 |
|
233 | 236 | descriptionPane.setBorder(new EmptyBorder(4, 7, 7, 7)); |
234 | 237 | descriptionPane.setHighlighter(null); |
235 | 238 | add(descriptionPane, BorderLayout.CENTER); |
236 | 239 |
|
237 | | - JPanel updateBox = new JPanel(); //new BoxLayout(filterPanel, BoxLayout.X_AXIS) |
| 240 | + JPanel updateBox = new JPanel(); |
238 | 241 | updateBox.setLayout(new BorderLayout()); |
239 | 242 |
|
240 | 243 | notificationLabel = new JLabel(); |
241 | 244 | notificationLabel.setInheritsPopupMenu(true); |
242 | 245 | notificationLabel.setVisible(false); |
243 | 246 | 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)); |
249 | 247 | notificationLabel.setFont(Toolkit.getSansFont(12, Font.PLAIN)); |
250 | | -// stripTextSelectionListeners(notificationBlock); |
251 | 248 |
|
252 | 249 | { |
253 | 250 | updateButton = new JButton("Update"); |
@@ -279,7 +276,8 @@ public void actionPerformed(ActionEvent e) { |
279 | 276 | rightPane.setMinimumSize(new Dimension(DetailPanel.BUTTON_WIDTH, 1)); |
280 | 277 | add(rightPane, BorderLayout.EAST); |
281 | 278 |
|
282 | | - barButtonCardPane.setLayout(new CardLayout()); |
| 279 | + barButtonCardLayout = new CardLayout(); |
| 280 | + barButtonCardPane.setLayout(barButtonCardLayout); |
283 | 281 | barButtonCardPane.setInheritsPopupMenu(true); |
284 | 282 | barButtonCardPane.setOpaque(false); |
285 | 283 | barButtonCardPane.setMinimumSize(new Dimension(DetailPanel.BUTTON_WIDTH, 1)); |
@@ -312,16 +310,14 @@ public void actionPerformed(ActionEvent e) { |
312 | 310 |
|
313 | 311 | JPanel barPane = new JPanel(); |
314 | 312 | barPane.setOpaque(false); |
315 | | -// barPane.add(installProgressBar); |
316 | 313 |
|
317 | 314 | JPanel buttonPane = new JPanel(); |
318 | 315 | buttonPane.setOpaque(false); |
319 | 316 | buttonPane.add(installRemoveButton); |
320 | 317 |
|
321 | 318 | barButtonCardPane.add(buttonPane, BUTTON_CONSTRAINT); |
322 | 319 | barButtonCardPane.add(barPane, PROGRESS_BAR_CONSTRAINT); |
323 | | - |
324 | | - ((CardLayout) barButtonCardPane.getLayout()).show(barButtonCardPane, BUTTON_CONSTRAINT); |
| 320 | + barButtonCardLayout.show(barButtonCardPane, BUTTON_CONSTRAINT); |
325 | 321 |
|
326 | 322 | rightPane.add(barButtonCardPane); |
327 | 323 |
|
@@ -355,7 +351,6 @@ private void reorganizePaneComponents() { |
355 | 351 | rightPane.setMinimumSize(new Dimension(DetailPanel.BUTTON_WIDTH, 1)); |
356 | 352 | add(rightPane, BorderLayout.EAST); |
357 | 353 |
|
358 | | - |
359 | 354 | if (updateButton.isVisible() && !removeInProgress && !contrib.isDeletionFlagged()) { |
360 | 355 | JPanel updateRemovePanel = new JPanel(); |
361 | 356 | updateRemovePanel.setLayout(new FlowLayout()); |
@@ -368,21 +363,18 @@ private void reorganizePaneComponents() { |
368 | 363 | JPanel barPane = new JPanel(); |
369 | 364 | barPane.setOpaque(false); |
370 | 365 | barPane.setInheritsPopupMenu(true); |
371 | | -// barPane.add(installProgressBar); |
372 | 366 | rightPane.add(barPane); |
373 | 367 |
|
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 { |
379 | 372 | updateBox.add(updateButton, BorderLayout.EAST); |
380 | 373 | barButtonCardPane.removeAll(); |
381 | 374 |
|
382 | 375 | JPanel barPane = new JPanel(); |
383 | 376 | barPane.setOpaque(false); |
384 | 377 | barPane.setInheritsPopupMenu(true); |
385 | | -// barPane.add(installProgressBar); |
386 | 378 |
|
387 | 379 | JPanel buttonPane = new JPanel(); |
388 | 380 | buttonPane.setOpaque(false); |
@@ -391,34 +383,33 @@ private void reorganizePaneComponents() { |
391 | 383 |
|
392 | 384 | barButtonCardPane.add(buttonPane, BUTTON_CONSTRAINT); |
393 | 385 | 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 | + } |
399 | 391 | rightPane.add(barButtonCardPane); |
400 | 392 | } |
401 | 393 |
|
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); |
408 | 400 | } |
409 | 401 |
|
410 | 402 |
|
411 | 403 | private void setExpandListener(Component component, |
412 | 404 | 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 | + } |
422 | 413 | } |
423 | 414 | } |
424 | 415 | } |
@@ -427,8 +418,9 @@ private void setExpandListener(Component component, |
427 | 418 | private void blurContributionPanel(Component component) { |
428 | 419 | component.setFocusable(false); |
429 | 420 | component.setEnabled(false); |
430 | | - if (component instanceof JComponent) |
| 421 | + if (component instanceof JComponent) { |
431 | 422 | ((JComponent) component).setToolTipText(INCOMPATIBILITY_BLUR); |
| 423 | + } |
432 | 424 | if (component instanceof Container) { |
433 | 425 | for (Component child : ((Container) component).getComponents()) { |
434 | 426 | blurContributionPanel(child); |
@@ -589,10 +581,11 @@ public void cancelAction() { |
589 | 581 | resetInstallProgressBarState(); |
590 | 582 | installRemoveButton.setEnabled(!contrib.isUpdateFlagged()); |
591 | 583 |
|
592 | | - ((CardLayout) barButtonCardPane.getLayout()).show(barButtonCardPane, BUTTON_CONSTRAINT); |
| 584 | + barButtonCardLayout.show(barButtonCardPane, BUTTON_CONSTRAINT); |
593 | 585 | installInProgress = false; |
594 | | - if(updateInProgress) |
| 586 | + if (updateInProgress) { |
595 | 587 | updateInProgress = !updateInProgress; |
| 588 | + } |
596 | 589 | updateButton.setVisible(contribListing.hasUpdates(contrib) && !contrib.isUpdateFlagged()); |
597 | 590 | setSelected(true); |
598 | 591 | } |
@@ -607,10 +600,11 @@ public void finishedAction() { |
607 | 600 | if (isError()) { |
608 | 601 | listPanel.contributionTab.statusPanel.setErrorMessage(Language.text("contrib.download_error")); |
609 | 602 | } |
610 | | - ((CardLayout) barButtonCardPane.getLayout()).show(barButtonCardPane, BUTTON_CONSTRAINT); |
| 603 | + barButtonCardLayout.show(barButtonCardPane, BUTTON_CONSTRAINT); |
611 | 604 | installInProgress = false; |
612 | | - if(updateInProgress) |
| 605 | + if (updateInProgress) { |
613 | 606 | updateInProgress = !updateInProgress; |
| 607 | + } |
614 | 608 | updateButton.setVisible(contribListing.hasUpdates(contrib) && !contrib.isUpdateFlagged()); |
615 | 609 | setSelected(true); |
616 | 610 | } |
@@ -620,35 +614,19 @@ public void cancelAction() { |
620 | 614 | } |
621 | 615 | }; |
622 | 616 |
|
623 | | - ContributionManager.downloadAndInstall(listPanel.contributionTab.editor.getBase(), |
624 | | - downloadUrl, ad, |
| 617 | + ContributionManager.downloadAndInstall(base, downloadUrl, ad, |
625 | 618 | downloadProgress, installProgress, |
626 | 619 | listPanel.contributionTab.statusPanel); |
627 | 620 |
|
628 | 621 | } catch (MalformedURLException e) { |
629 | 622 | Messages.showWarning(Language.text("contrib.errors.install_failed"), |
630 | 623 | Language.text("contrib.errors.malformed_url"), e); |
631 | 624 | // not sure why we'd re-enable the button if it had an error... |
632 | | -// installRemoveButton.setEnabled(true); |
| 625 | + //installRemoveButton.setEnabled(true); |
633 | 626 | } |
634 | 627 | } |
635 | 628 |
|
636 | 629 |
|
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 | | - |
652 | 630 | protected void resetInstallProgressBarState() { |
653 | 631 | installProgressBar.setString(Language.text("contrib.progress.starting")); |
654 | 632 | installProgressBar.setIndeterminate(false); |
@@ -763,14 +741,15 @@ static String toHtmlLinks(String stringIn) { |
763 | 741 | * Sets coloring based on whether installed or not; |
764 | 742 | * also makes ugly blue HTML links into the specified color (black). |
765 | 743 | */ |
766 | | - static void setForegroundStyle(JTextPane textPane, boolean installed, boolean selected) { |
| 744 | + static void setForegroundStyle(JTextPane textPane, |
| 745 | + boolean installed, boolean selected) { |
767 | 746 | Document doc = textPane.getDocument(); |
768 | 747 | if (doc instanceof HTMLDocument) { |
769 | 748 | HTMLDocument html = (HTMLDocument) doc; |
770 | 749 | StyleSheet stylesheet = html.getStyleSheet(); |
771 | 750 |
|
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"; |
774 | 753 | stylesheet.addRule("body { color:" + c + "; }"); |
775 | 754 | stylesheet.addRule("a { color:" + c + "; }"); |
776 | 755 | } |
@@ -784,7 +763,7 @@ static void setTextStyle(JTextPane textPane) { |
784 | 763 | StyleSheet stylesheet = html.getStyleSheet(); |
785 | 764 | stylesheet.addRule("body { " + |
786 | 765 | " margin: 0; padding: 0;" + |
787 | | - " font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;" + |
| 766 | + " font-family: " + Toolkit.getSansFontName() + ", Arial, Helvetica, sans-serif;" + |
788 | 767 | " font-size: 100%;" + "font-size: 0.95em; " + |
789 | 768 | "}"); |
790 | 769 | } |
@@ -808,7 +787,7 @@ static void setSelectionStyle(JTextPane textPane, boolean selected) { |
808 | 787 | public void install() { |
809 | 788 | listPanel.contributionTab.statusPanel.clearMessage(); |
810 | 789 | installInProgress = true; |
811 | | - ((CardLayout) barButtonCardPane.getLayout()).show(barButtonCardPane, PROGRESS_BAR_CONSTRAINT); |
| 790 | + barButtonCardLayout.show(barButtonCardPane, PROGRESS_BAR_CONSTRAINT); |
812 | 791 | if (contrib instanceof AvailableContribution) { |
813 | 792 | installContribution((AvailableContribution) contrib); |
814 | 793 | contribListing.replaceContribution(contrib, contrib); |
@@ -817,7 +796,6 @@ public void install() { |
817 | 796 |
|
818 | 797 |
|
819 | 798 | public void update() { |
820 | | - |
821 | 799 | listPanel.contributionTab.statusPanel.clearMessage(); |
822 | 800 | updateInProgress = true; |
823 | 801 | if (contrib.getType().requiresRestart()) { |
@@ -851,12 +829,7 @@ public void cancelAction() { |
851 | 829 | boolean isModeActive = false; |
852 | 830 | if (contrib.getType() == ContributionType.MODE) { |
853 | 831 | 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(); |
858 | 832 | for (Editor e : base.getEditors()) { |
859 | | - //Editor e = iter.next(); |
860 | 833 | if (e.getMode().equals(m.getMode())) { |
861 | 834 | isModeActive = true; |
862 | 835 | break; |
@@ -872,8 +845,7 @@ public void cancelAction() { |
872 | 845 | } |
873 | 846 | }; |
874 | 847 | ((LocalContribution) contrib) |
875 | | - .removeContribution(listPanel.contributionTab.editor.getBase(), |
876 | | - progress, listPanel.contributionTab.statusPanel); |
| 848 | + .removeContribution(base, progress, listPanel.contributionTab.statusPanel); |
877 | 849 | } else { |
878 | 850 | updateButton.setEnabled(false); |
879 | 851 | installRemoveButton.setEnabled(false); |
|