1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-31 20:52:13 +01:00

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.
This commit is contained in:
Matthijs Kooijman 2019-10-01 14:57:28 +02:00 committed by Cristian Maglie
parent 778f681c2f
commit 7d625181f6
2 changed files with 6 additions and 13 deletions

View File

@ -33,6 +33,7 @@ public class ContributedLibraryTableCellJPanel extends JPanel {
final JPanel buttonsPanel; final JPanel buttonsPanel;
final JPanel inactiveButtonsPanel; final JPanel inactiveButtonsPanel;
final JLabel statusLabel; final JLabel statusLabel;
final JTextPane description;
private final String moreInfoLbl = tr("More info"); private final String moreInfoLbl = tr("More info");
public ContributedLibraryTableCellJPanel(JTable parentTable, Object value, public ContributedLibraryTableCellJPanel(JTable parentTable, Object value,
@ -68,7 +69,8 @@ public class ContributedLibraryTableCellJPanel extends JPanel {
versionToInstallChooser versionToInstallChooser
.setMinimumSize(new Dimension((int)versionToInstallChooser.getPreferredSize().getWidth() + 50, (int)versionToInstallChooser.getPreferredSize().getHeight())); .setMinimumSize(new Dimension((int)versionToInstallChooser.getPreferredSize().getWidth() + 50, (int)versionToInstallChooser.getPreferredSize().getHeight()));
makeNewDescription(); description = makeNewDescription();
add(description);
buttonsPanel = new JPanel(); buttonsPanel = new JPanel();
buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS)); buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS));
@ -112,7 +114,6 @@ public class ContributedLibraryTableCellJPanel extends JPanel {
add(Box.createVerticalStrut(15)); add(Box.createVerticalStrut(15));
ContributedLibraryReleases releases = (ContributedLibraryReleases) value; ContributedLibraryReleases releases = (ContributedLibraryReleases) value;
JTextPane description = makeNewDescription();
// FIXME: happens on macosx, don't know why // FIXME: happens on macosx, don't know why
if (releases == null) if (releases == null)
@ -231,9 +232,6 @@ public class ContributedLibraryTableCellJPanel extends JPanel {
// TODO Make this a method of Theme // TODO Make this a method of Theme
private JTextPane makeNewDescription() { private JTextPane makeNewDescription() {
if (getComponentCount() > 0) {
remove(0);
}
JTextPane description = new JTextPane(); JTextPane description = new JTextPane();
description.setInheritsPopupMenu(true); description.setInheritsPopupMenu(true);
Insets margin = description.getMargin(); Insets margin = description.getMargin();
@ -259,7 +257,6 @@ public class ContributedLibraryTableCellJPanel extends JPanel {
} }
}); });
// description.addKeyListener(new DelegatingKeyListener(parentTable)); // description.addKeyListener(new DelegatingKeyListener(parentTable));
add(description, 0);
return description; return description;
} }

View File

@ -66,6 +66,7 @@ public class ContributedPlatformTableCellJPanel extends JPanel {
final JPanel buttonsPanel; final JPanel buttonsPanel;
final JPanel inactiveButtonsPanel; final JPanel inactiveButtonsPanel;
final JLabel statusLabel; final JLabel statusLabel;
final JTextPane description;
private final String moreInfoLbl = tr("More Info"); private final String moreInfoLbl = tr("More Info");
private final String onlineHelpLbl = tr("Online Help"); private final String onlineHelpLbl = tr("Online Help");
@ -108,7 +109,8 @@ public class ContributedPlatformTableCellJPanel extends JPanel {
versionToInstallChooser versionToInstallChooser
.setMaximumSize(versionToInstallChooser.getPreferredSize()); .setMaximumSize(versionToInstallChooser.getPreferredSize());
makeNewDescription(); description = makeNewDescription();
add(description);
buttonsPanel = new JPanel(); buttonsPanel = new JPanel();
buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS)); 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) { void update(JTable parentTable, Object value, boolean hasBuiltInRelease) {
ContributedPlatformReleases releases = (ContributedPlatformReleases) value; ContributedPlatformReleases releases = (ContributedPlatformReleases) value;
JTextPane description = makeNewDescription();
// FIXME: happens on macosx, don't know why // FIXME: happens on macosx, don't know why
if (releases == null) { if (releases == null) {
return; return;
@ -273,9 +273,6 @@ public class ContributedPlatformTableCellJPanel extends JPanel {
} }
private JTextPane makeNewDescription() { private JTextPane makeNewDescription() {
if (getComponentCount() > 0) {
remove(0);
}
JTextPane description = new JTextPane(); JTextPane description = new JTextPane();
description.setInheritsPopupMenu(true); description.setInheritsPopupMenu(true);
Insets margin = description.getMargin(); Insets margin = description.getMargin();
@ -299,7 +296,6 @@ public class ContributedPlatformTableCellJPanel extends JPanel {
Base.openURL(e.getDescription()); Base.openURL(e.getDescription());
} }
}); });
add(description, 0);
return description; return description;
} }