Factored out ContributedLibraryTableCell.update(...) method

This commit is contained in:
Cristian Maglie 2015-12-29 14:14:52 +01:00
parent 71eb3c3ab2
commit 91f18dff24
3 changed files with 17 additions and 22 deletions

View File

@ -29,16 +29,17 @@ import processing.app.Base;
public class ContributedLibraryTableCell extends JPanel {
protected final JButton installButton;
protected final Component installButtonPlaceholder;
protected final JComboBox downgradeChooser;
protected final JComboBox versionToInstallChooser;
protected final JButton downgradeButton;
protected final JPanel buttonsPanel;
protected final JPanel inactiveButtonsPanel;
protected final JLabel statusLabel;
final JButton installButton;
final Component installButtonPlaceholder;
final JComboBox downgradeChooser;
final JComboBox versionToInstallChooser;
final JButton downgradeButton;
final JPanel buttonsPanel;
final JPanel inactiveButtonsPanel;
final JLabel statusLabel;
public ContributedLibraryTableCell() {
public ContributedLibraryTableCell(JTable parentTable, Object value,
boolean isSelected) {
super();
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
@ -99,11 +100,8 @@ public class ContributedLibraryTableCell extends JPanel {
add(inactiveButtonsPanel);
add(Box.createVerticalStrut(15));
}
void update(JTable parentTable, Object value, boolean isSelected) {
ContributedLibraryReleases releases = (ContributedLibraryReleases) value;
JTextPane description = makeNewDescription();
// FIXME: happens on macosx, don't know why
@ -193,9 +191,9 @@ public class ContributedLibraryTableCell extends JPanel {
// See:
// http://stackoverflow.com/questions/3081210/how-to-set-jtextarea-to-have-height-that-matches-the-size-of-a-text-it-contains
int width = parentTable.getBounds().width;
InstallerTableCell.setJTextPaneDimensionToFitContainedText(description,
width);
InstallerTableCell
.setJTextPaneDimensionToFitContainedText(description,
parentTable.getBounds().width);
if (isSelected) {
setBackground(parentTable.getSelectionBackground());

View File

@ -67,7 +67,7 @@ public class ContributedLibraryTableCellEditor extends InstallerTableCell {
int column) {
editorValue = (ContributedLibraryReleases) value;
editorCell = new ContributedLibraryTableCell();
editorCell = new ContributedLibraryTableCell(table, value, true);
editorCell.installButton
.addActionListener(e -> onInstall(editorValue.getSelected(),
editorValue.getInstalled()));
@ -134,7 +134,6 @@ public class ContributedLibraryTableCellEditor extends InstallerTableCell {
editorCell.versionToInstallChooser
.setVisible(installed == null && uninstalledReleases.size() > 1);
editorCell.update(table, value, true);
editorCell.setBackground(new Color(218, 227, 227)); // #dae3e3
return editorCell;
}

View File

@ -42,10 +42,9 @@ public class ContributedLibraryTableCellRenderer implements TableCellRenderer {
boolean isSelected,
boolean hasFocus, int row,
int column) {
ContributedLibraryTableCell cell = new ContributedLibraryTableCell();
ContributedLibraryTableCell cell = new ContributedLibraryTableCell(table,
value, isSelected);
cell.setButtonsVisible(false);
cell.update(table, value, isSelected);
if (row % 2 == 0) {
cell.setBackground(new Color(236, 241, 241)); // #ecf1f1
@ -53,8 +52,7 @@ public class ContributedLibraryTableCellRenderer implements TableCellRenderer {
cell.setBackground(new Color(255, 255, 255));
}
int height = new Double(cell.getPreferredSize().getHeight())
.intValue();
int height = new Double(cell.getPreferredSize().getHeight()).intValue();
if (table.getRowHeight(row) < height) {
table.setRowHeight(row, height);
}