Skip to content

Commit 76068c9

Browse files
committed
*TableCellEditor now extends JPanel
1 parent 015f658 commit 76068c9

6 files changed

+50
-51
lines changed

app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCell.java

+21-21
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@
2727
import cc.arduino.contributions.ui.InstallerTableCell;
2828
import processing.app.Base;
2929

30-
public class ContributedLibraryTableCell {
30+
public class ContributedLibraryTableCell extends JPanel {
3131

32-
protected final JPanel panel;
3332
protected final JButton installButton;
3433
protected final Component installButtonPlaceholder;
3534
protected final JComboBox downgradeChooser;
@@ -40,6 +39,9 @@ public class ContributedLibraryTableCell {
4039
protected final JLabel statusLabel;
4140

4241
public ContributedLibraryTableCell() {
42+
super();
43+
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
44+
4345
installButton = new JButton(tr("Install"));
4446
int width = installButton.getPreferredSize().width;
4547
installButtonPlaceholder = Box.createRigidArea(new Dimension(width, 1));
@@ -60,10 +62,7 @@ public ContributedLibraryTableCell() {
6062
versionToInstallChooser
6163
.setMaximumSize(versionToInstallChooser.getPreferredSize());
6264

63-
panel = new JPanel();
64-
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
65-
66-
makeNewDescription(panel);
65+
makeNewDescription();
6766

6867
buttonsPanel = new JPanel();
6968
buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS));
@@ -82,7 +81,7 @@ public ContributedLibraryTableCell() {
8281
buttonsPanel.add(Box.createHorizontalStrut(5));
8382
buttonsPanel.add(Box.createHorizontalStrut(15));
8483

85-
panel.add(buttonsPanel);
84+
add(buttonsPanel);
8685

8786
inactiveButtonsPanel = new JPanel();
8887
inactiveButtonsPanel
@@ -97,16 +96,16 @@ public ContributedLibraryTableCell() {
9796
inactiveButtonsPanel.add(statusLabel);
9897
inactiveButtonsPanel.add(Box.createHorizontalStrut(15));
9998

100-
panel.add(inactiveButtonsPanel);
99+
add(inactiveButtonsPanel);
101100

102-
panel.add(Box.createVerticalStrut(15));
101+
add(Box.createVerticalStrut(15));
103102
}
104103

105-
void update(JTable parentTable, Object value, boolean isSelected,
106-
int row, boolean hasBuiltInRelease) {
104+
void update(JTable parentTable, Object value, boolean isSelected, int row,
105+
boolean hasBuiltInRelease) {
107106
ContributedLibraryReleases releases = (ContributedLibraryReleases) value;
108107

109-
JTextPane description = makeNewDescription(panel);
108+
JTextPane description = makeNewDescription();
110109

111110
// FIXME: happens on macosx, don't know why
112111
if (releases == null)
@@ -196,20 +195,21 @@ void update(JTable parentTable, Object value, boolean isSelected,
196195
// See:
197196
// http://stackoverflow.com/questions/3081210/how-to-set-jtextarea-to-have-height-that-matches-the-size-of-a-text-it-contains
198197
int width = parentTable.getBounds().width;
199-
InstallerTableCell.setJTextPaneDimensionToFitContainedText(description, width);
198+
InstallerTableCell.setJTextPaneDimensionToFitContainedText(description,
199+
width);
200200

201201
if (isSelected) {
202-
panel.setBackground(parentTable.getSelectionBackground());
203-
panel.setForeground(parentTable.getSelectionForeground());
202+
setBackground(parentTable.getSelectionBackground());
203+
setForeground(parentTable.getSelectionForeground());
204204
} else {
205-
panel.setBackground(parentTable.getBackground());
206-
panel.setForeground(parentTable.getForeground());
205+
setBackground(parentTable.getBackground());
206+
setForeground(parentTable.getForeground());
207207
}
208208
}
209209

210-
private static JTextPane makeNewDescription(JPanel panel) {
211-
if (panel.getComponentCount() > 0) {
212-
panel.remove(0);
210+
private JTextPane makeNewDescription() {
211+
if (getComponentCount() > 0) {
212+
remove(0);
213213
}
214214
JTextPane description = new JTextPane();
215215
description.setInheritsPopupMenu(true);
@@ -235,7 +235,7 @@ private static JTextPane makeNewDescription(JPanel panel) {
235235
}
236236
});
237237
// description.addKeyListener(new DelegatingKeyListener(parentTable));
238-
panel.add(description, 0);
238+
add(description, 0);
239239
return description;
240240
}
241241

app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellEditor.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ public Component getTableCellEditorComponent(JTable table, Object value,
135135
.setVisible(installed == null && uninstalledReleases.size() > 1);
136136

137137
editorCell.update(table, value, true, row, !installedBuiltIn.isEmpty());
138-
editorCell.panel.setBackground(new Color(218, 227, 227)); // #dae3e3
139-
return editorCell.panel;
138+
editorCell.setBackground(new Color(218, 227, 227)); // #dae3e3
139+
return editorCell;
140140
}
141141

142142
@Override

app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellRenderer.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,18 @@ public Component getTableCellRendererComponent(JTable table, Object value,
4848
cell.update(table, value, isSelected, row, false);
4949

5050
if (row % 2 == 0) {
51-
cell.panel.setBackground(new Color(236, 241, 241)); // #ecf1f1
51+
cell.setBackground(new Color(236, 241, 241)); // #ecf1f1
5252
} else {
53-
cell.panel.setBackground(new Color(255, 255, 255));
53+
cell.setBackground(new Color(255, 255, 255));
5454
}
5555

56-
int height = new Double(cell.panel.getPreferredSize().getHeight())
56+
int height = new Double(cell.getPreferredSize().getHeight())
5757
.intValue();
5858
if (table.getRowHeight(row) < height) {
5959
table.setRowHeight(row, height);
6060
}
6161

62-
return cell.panel;
62+
return cell;
6363
}
6464

6565
}

app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCell.java

+17-18
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,8 @@
5959
import processing.app.Base;
6060

6161
@SuppressWarnings("serial")
62-
public class ContributedPlatformTableCell {
62+
public class ContributedPlatformTableCell extends JPanel {
6363

64-
final JPanel panel;
6564
final JButton installButton;
6665
final JButton removeButton;
6766
final Component removeButtonPlaceholder;
@@ -74,6 +73,9 @@ public class ContributedPlatformTableCell {
7473
final JLabel statusLabel;
7574

7675
public ContributedPlatformTableCell() {
76+
super();
77+
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
78+
7779
{
7880
installButton = new JButton(tr("Install"));
7981
int width = installButton.getPreferredSize().width;
@@ -102,10 +104,7 @@ public ContributedPlatformTableCell() {
102104
versionToInstallChooser
103105
.setMaximumSize(versionToInstallChooser.getPreferredSize());
104106

105-
panel = new JPanel();
106-
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
107-
108-
makeNewDescription(panel);
107+
makeNewDescription();
109108

110109
buttonsPanel = new JPanel();
111110
buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS));
@@ -126,7 +125,7 @@ public ContributedPlatformTableCell() {
126125
buttonsPanel.add(Box.createHorizontalStrut(5));
127126
buttonsPanel.add(Box.createHorizontalStrut(15));
128127

129-
panel.add(buttonsPanel);
128+
add(buttonsPanel);
130129

131130
inactiveButtonsPanel = new JPanel();
132131
inactiveButtonsPanel
@@ -141,16 +140,16 @@ public ContributedPlatformTableCell() {
141140
inactiveButtonsPanel.add(statusLabel);
142141
inactiveButtonsPanel.add(Box.createHorizontalStrut(15));
143142

144-
panel.add(inactiveButtonsPanel);
143+
add(inactiveButtonsPanel);
145144

146-
panel.add(Box.createVerticalStrut(15));
145+
add(Box.createVerticalStrut(15));
147146
}
148147

149148
void update(JTable parentTable, Object value, boolean isSelected, int row,
150149
boolean hasBuiltInRelease) {
151150
ContributionIndexTableModel.ContributedPlatformReleases releases = (ContributionIndexTableModel.ContributedPlatformReleases) value;
152151

153-
JTextPane description = makeNewDescription(panel);
152+
JTextPane description = makeNewDescription();
154153

155154
// FIXME: happens on macosx, don't know why
156155
if (releases == null) {
@@ -239,17 +238,17 @@ void update(JTable parentTable, Object value, boolean isSelected, int row,
239238
width);
240239

241240
if (isSelected) {
242-
panel.setBackground(parentTable.getSelectionBackground());
243-
panel.setForeground(parentTable.getSelectionForeground());
241+
setBackground(parentTable.getSelectionBackground());
242+
setForeground(parentTable.getSelectionForeground());
244243
} else {
245-
panel.setBackground(parentTable.getBackground());
246-
panel.setForeground(parentTable.getForeground());
244+
setBackground(parentTable.getBackground());
245+
setForeground(parentTable.getForeground());
247246
}
248247
}
249248

250-
private static JTextPane makeNewDescription(JPanel panel) {
251-
if (panel.getComponentCount() > 0) {
252-
panel.remove(0);
249+
private JTextPane makeNewDescription() {
250+
if (getComponentCount() > 0) {
251+
remove(0);
253252
}
254253
JTextPane description = new JTextPane();
255254
description.setInheritsPopupMenu(true);
@@ -274,7 +273,7 @@ private static JTextPane makeNewDescription(JPanel panel) {
274273
Base.openURL(e.getDescription());
275274
}
276275
});
277-
panel.add(description, 0);
276+
add(description, 0);
278277
return description;
279278
}
280279

app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellEditor.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ public Component getTableCellEditorComponent(JTable table, Object value,
132132
.setVisible(installed == null && uninstalledReleases.size() > 1);
133133

134134
editorCell.update(table, value, true, row, !installedBuiltIn.isEmpty());
135-
editorCell.panel.setBackground(new Color(218, 227, 227)); // #dae3e3
136-
return editorCell.panel;
135+
editorCell.setBackground(new Color(218, 227, 227)); // #dae3e3
136+
return editorCell;
137137
}
138138

139139
@Override

app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellRenderer.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,18 @@ public Component getTableCellRendererComponent(JTable table, Object value,
4747

4848
cell.update(table, value, isSelected, row, false);
4949
if (row % 2 == 0) {
50-
cell.panel.setBackground(new Color(236, 241, 241)); // #ecf1f1
50+
cell.setBackground(new Color(236, 241, 241)); // #ecf1f1
5151
} else {
52-
cell.panel.setBackground(new Color(255, 255, 255));
52+
cell.setBackground(new Color(255, 255, 255));
5353
}
5454

55-
int height = new Double(cell.panel.getPreferredSize().getHeight())
55+
int height = new Double(cell.getPreferredSize().getHeight())
5656
.intValue();
5757
if (table.getRowHeight(row) < height) {
5858
table.setRowHeight(row, height);
5959
}
6060

61-
return cell.panel;
61+
return cell;
6262
}
6363

6464
}

0 commit comments

Comments
 (0)