From 7d625181f6cd622acfadfff0583c858773b4c395 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Tue, 1 Oct 2019 14:57:28 +0200 Subject: [PATCH] In the board/library manager, create the description component only once Previously,`makeNewDescription` was called in the constructor and then again later in the `update` method (board manager) or later in the constructor (library manager) to recreate the description JTextPane so it can be filled with text. In all cases, the pane would be created equal, so there is no point in recreating it. Now, it is created only once and stored in an instance variable for later reference. Additionally, `makeNewDescription` now only creates the JTextPane, the constructor handles adding it (like for other components). This change slightly simplifies code, but also prepares for allowing to change the description text color externally in a later commit. For the library manager it is not currently strictly needed to have an instance variable (since the description is only used inside the constructor), but the instance variable is added for consistency and to prepare for this same upcoming change. --- .../ui/ContributedLibraryTableCellJPanel.java | 9 +++------ .../ui/ContributedPlatformTableCellJPanel.java | 10 +++------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellJPanel.java b/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellJPanel.java index a9a8a39f4..560c9889b 100644 --- a/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellJPanel.java +++ b/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellJPanel.java @@ -33,6 +33,7 @@ public class ContributedLibraryTableCellJPanel extends JPanel { final JPanel buttonsPanel; final JPanel inactiveButtonsPanel; final JLabel statusLabel; + final JTextPane description; private final String moreInfoLbl = tr("More info"); public ContributedLibraryTableCellJPanel(JTable parentTable, Object value, @@ -68,7 +69,8 @@ public class ContributedLibraryTableCellJPanel extends JPanel { versionToInstallChooser .setMinimumSize(new Dimension((int)versionToInstallChooser.getPreferredSize().getWidth() + 50, (int)versionToInstallChooser.getPreferredSize().getHeight())); - makeNewDescription(); + description = makeNewDescription(); + add(description); buttonsPanel = new JPanel(); buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS)); @@ -112,7 +114,6 @@ public class ContributedLibraryTableCellJPanel extends JPanel { add(Box.createVerticalStrut(15)); ContributedLibraryReleases releases = (ContributedLibraryReleases) value; - JTextPane description = makeNewDescription(); // FIXME: happens on macosx, don't know why if (releases == null) @@ -231,9 +232,6 @@ public class ContributedLibraryTableCellJPanel extends JPanel { // TODO Make this a method of Theme private JTextPane makeNewDescription() { - if (getComponentCount() > 0) { - remove(0); - } JTextPane description = new JTextPane(); description.setInheritsPopupMenu(true); Insets margin = description.getMargin(); @@ -259,7 +257,6 @@ public class ContributedLibraryTableCellJPanel extends JPanel { } }); // description.addKeyListener(new DelegatingKeyListener(parentTable)); - add(description, 0); return description; } diff --git a/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellJPanel.java b/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellJPanel.java index 9575d12e6..2f42a9026 100644 --- a/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellJPanel.java +++ b/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellJPanel.java @@ -66,6 +66,7 @@ public class ContributedPlatformTableCellJPanel extends JPanel { final JPanel buttonsPanel; final JPanel inactiveButtonsPanel; final JLabel statusLabel; + final JTextPane description; private final String moreInfoLbl = tr("More Info"); private final String onlineHelpLbl = tr("Online Help"); @@ -108,7 +109,8 @@ public class ContributedPlatformTableCellJPanel extends JPanel { versionToInstallChooser .setMaximumSize(versionToInstallChooser.getPreferredSize()); - makeNewDescription(); + description = makeNewDescription(); + add(description); buttonsPanel = new JPanel(); buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS)); @@ -178,8 +180,6 @@ public class ContributedPlatformTableCellJPanel extends JPanel { void update(JTable parentTable, Object value, boolean hasBuiltInRelease) { ContributedPlatformReleases releases = (ContributedPlatformReleases) value; - JTextPane description = makeNewDescription(); - // FIXME: happens on macosx, don't know why if (releases == null) { return; @@ -273,9 +273,6 @@ public class ContributedPlatformTableCellJPanel extends JPanel { } private JTextPane makeNewDescription() { - if (getComponentCount() > 0) { - remove(0); - } JTextPane description = new JTextPane(); description.setInheritsPopupMenu(true); Insets margin = description.getMargin(); @@ -299,7 +296,6 @@ public class ContributedPlatformTableCellJPanel extends JPanel { Base.openURL(e.getDescription()); } }); - add(description, 0); return description; }