6262 * Panel that expands and gives a brief overview of a library when clicked.
6363 */
6464class 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 );
0 commit comments