From 91f18dff243b246afce7a501301739e50f19239b Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 29 Dec 2015 14:14:52 +0100 Subject: [PATCH] Factored out ContributedLibraryTableCell.update(...) method --- .../ui/ContributedLibraryTableCell.java | 28 +++++++++---------- .../ui/ContributedLibraryTableCellEditor.java | 3 +- .../ContributedLibraryTableCellRenderer.java | 8 ++---- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCell.java b/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCell.java index 3645149f8..671489a97 100644 --- a/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCell.java +++ b/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCell.java @@ -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()); diff --git a/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellEditor.java b/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellEditor.java index f825210b6..4ab9d4b5f 100644 --- a/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellEditor.java +++ b/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellEditor.java @@ -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; } diff --git a/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellRenderer.java b/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellRenderer.java index 1613d7aaf..ffee3b24e 100644 --- a/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellRenderer.java +++ b/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellRenderer.java @@ -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); }