Skip to content

Commit 7674e85

Browse files
cmaglielmihalkovic
authored andcommitted
Factored out ContributedLibraryTableCell.update(...) method
1 parent b2486b2 commit 7674e85

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

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

+14-16
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,17 @@
2929

3030
public class ContributedLibraryTableCell extends JPanel {
3131

32-
protected final JButton installButton;
33-
protected final Component installButtonPlaceholder;
34-
protected final JComboBox downgradeChooser;
35-
protected final JComboBox versionToInstallChooser;
36-
protected final JButton downgradeButton;
37-
protected final JPanel buttonsPanel;
38-
protected final JPanel inactiveButtonsPanel;
39-
protected final JLabel statusLabel;
40-
41-
public ContributedLibraryTableCell() {
32+
final JButton installButton;
33+
final Component installButtonPlaceholder;
34+
final JComboBox downgradeChooser;
35+
final JComboBox versionToInstallChooser;
36+
final JButton downgradeButton;
37+
final JPanel buttonsPanel;
38+
final JPanel inactiveButtonsPanel;
39+
final JLabel statusLabel;
40+
41+
public ContributedLibraryTableCell(JTable parentTable, Object value,
42+
boolean isSelected) {
4243
super();
4344
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
4445

@@ -99,11 +100,8 @@ public ContributedLibraryTableCell() {
99100
add(inactiveButtonsPanel);
100101

101102
add(Box.createVerticalStrut(15));
102-
}
103103

104-
void update(JTable parentTable, Object value, boolean isSelected) {
105104
ContributedLibraryReleases releases = (ContributedLibraryReleases) value;
106-
107105
JTextPane description = makeNewDescription();
108106

109107
// FIXME: happens on macosx, don't know why
@@ -193,9 +191,9 @@ void update(JTable parentTable, Object value, boolean isSelected) {
193191

194192
// See:
195193
// http://stackoverflow.com/questions/3081210/how-to-set-jtextarea-to-have-height-that-matches-the-size-of-a-text-it-contains
196-
int width = parentTable.getBounds().width;
197-
InstallerTableCell.setJTextPaneDimensionToFitContainedText(description,
198-
width);
194+
InstallerTableCell
195+
.setJTextPaneDimensionToFitContainedText(description,
196+
parentTable.getBounds().width);
199197

200198
if (isSelected) {
201199
setBackground(parentTable.getSelectionBackground());

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public Component getTableCellEditorComponent(JTable table, Object value,
6767
int column) {
6868
editorValue = (ContributedLibraryReleases) value;
6969

70-
editorCell = new ContributedLibraryTableCell();
70+
editorCell = new ContributedLibraryTableCell(table, value, true);
7171
editorCell.installButton
7272
.addActionListener(e -> onInstall(editorValue.getSelected(),
7373
editorValue.getInstalled()));
@@ -134,7 +134,6 @@ public Component getTableCellEditorComponent(JTable table, Object value,
134134
editorCell.versionToInstallChooser
135135
.setVisible(installed == null && uninstalledReleases.size() > 1);
136136

137-
editorCell.update(table, value, true);
138137
editorCell.setBackground(new Color(218, 227, 227)); // #dae3e3
139138
return editorCell;
140139
}

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

+3-5
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,17 @@ public Component getTableCellRendererComponent(JTable table, Object value,
4242
boolean isSelected,
4343
boolean hasFocus, int row,
4444
int column) {
45-
46-
ContributedLibraryTableCell cell = new ContributedLibraryTableCell();
45+
ContributedLibraryTableCell cell = new ContributedLibraryTableCell(table,
46+
value, isSelected);
4747
cell.setButtonsVisible(false);
48-
cell.update(table, value, isSelected);
4948

5049
if (row % 2 == 0) {
5150
cell.setBackground(new Color(236, 241, 241)); // #ecf1f1
5251
} else {
5352
cell.setBackground(new Color(255, 255, 255));
5453
}
5554

56-
int height = new Double(cell.getPreferredSize().getHeight())
57-
.intValue();
55+
int height = new Double(cell.getPreferredSize().getHeight()).intValue();
5856
if (table.getRowHeight(row) < height) {
5957
table.setRowHeight(row, height);
6058
}

0 commit comments

Comments
 (0)