Skip to content

Commit 7d62518

Browse files
matthijskooijmancmaglie
authored andcommitted
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.
1 parent 778f681 commit 7d62518

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

Diff for: app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellJPanel.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class ContributedLibraryTableCellJPanel extends JPanel {
3333
final JPanel buttonsPanel;
3434
final JPanel inactiveButtonsPanel;
3535
final JLabel statusLabel;
36+
final JTextPane description;
3637
private final String moreInfoLbl = tr("More info");
3738

3839
public ContributedLibraryTableCellJPanel(JTable parentTable, Object value,
@@ -68,7 +69,8 @@ public ContributedLibraryTableCellJPanel(JTable parentTable, Object value,
6869
versionToInstallChooser
6970
.setMinimumSize(new Dimension((int)versionToInstallChooser.getPreferredSize().getWidth() + 50, (int)versionToInstallChooser.getPreferredSize().getHeight()));
7071

71-
makeNewDescription();
72+
description = makeNewDescription();
73+
add(description);
7274

7375
buttonsPanel = new JPanel();
7476
buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS));
@@ -112,7 +114,6 @@ public ContributedLibraryTableCellJPanel(JTable parentTable, Object value,
112114
add(Box.createVerticalStrut(15));
113115

114116
ContributedLibraryReleases releases = (ContributedLibraryReleases) value;
115-
JTextPane description = makeNewDescription();
116117

117118
// FIXME: happens on macosx, don't know why
118119
if (releases == null)
@@ -231,9 +232,6 @@ private String setButtonOrLink(JButton button, String desc, String label, String
231232

232233
// TODO Make this a method of Theme
233234
private JTextPane makeNewDescription() {
234-
if (getComponentCount() > 0) {
235-
remove(0);
236-
}
237235
JTextPane description = new JTextPane();
238236
description.setInheritsPopupMenu(true);
239237
Insets margin = description.getMargin();
@@ -259,7 +257,6 @@ private JTextPane makeNewDescription() {
259257
}
260258
});
261259
// description.addKeyListener(new DelegatingKeyListener(parentTable));
262-
add(description, 0);
263260
return description;
264261
}
265262

Diff for: app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellJPanel.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public class ContributedPlatformTableCellJPanel extends JPanel {
6666
final JPanel buttonsPanel;
6767
final JPanel inactiveButtonsPanel;
6868
final JLabel statusLabel;
69+
final JTextPane description;
6970
private final String moreInfoLbl = tr("More Info");
7071
private final String onlineHelpLbl = tr("Online Help");
7172

@@ -108,7 +109,8 @@ public ContributedPlatformTableCellJPanel() {
108109
versionToInstallChooser
109110
.setMaximumSize(versionToInstallChooser.getPreferredSize());
110111

111-
makeNewDescription();
112+
description = makeNewDescription();
113+
add(description);
112114

113115
buttonsPanel = new JPanel();
114116
buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS));
@@ -178,8 +180,6 @@ private String setButtonOrLink(JButton button, String desc, String label, String
178180
void update(JTable parentTable, Object value, boolean hasBuiltInRelease) {
179181
ContributedPlatformReleases releases = (ContributedPlatformReleases) value;
180182

181-
JTextPane description = makeNewDescription();
182-
183183
// FIXME: happens on macosx, don't know why
184184
if (releases == null) {
185185
return;
@@ -273,9 +273,6 @@ void update(JTable parentTable, Object value, boolean hasBuiltInRelease) {
273273
}
274274

275275
private JTextPane makeNewDescription() {
276-
if (getComponentCount() > 0) {
277-
remove(0);
278-
}
279276
JTextPane description = new JTextPane();
280277
description.setInheritsPopupMenu(true);
281278
Insets margin = description.getMargin();
@@ -299,7 +296,6 @@ private JTextPane makeNewDescription() {
299296
Base.openURL(e.getDescription());
300297
}
301298
});
302-
add(description, 0);
303299
return description;
304300
}
305301

0 commit comments

Comments
 (0)