From b0d2a62b1a7cd2c468328d26a6c7db34b6365bdd Mon Sep 17 00:00:00 2001 From: Ricardo JL Rufino Date: Thu, 21 May 2020 20:30:52 -0300 Subject: [PATCH] Improve LibraryManager Dialog rendering TableCellRender is designed to be reusable, the old implementation created an instance, every time the mouse was over the line. --- .../ui/ContributedLibraryTableCellEditor.java | 6 +-- .../ui/ContributedLibraryTableCellJPanel.java | 37 +++++++++++-------- .../ContributedLibraryTableCellRenderer.java | 10 +++-- 3 files changed, 32 insertions(+), 21 deletions(-) mode change 100644 => 100755 app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellEditor.java mode change 100644 => 100755 app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellJPanel.java mode change 100644 => 100755 app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellRenderer.java diff --git a/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellEditor.java b/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellEditor.java old mode 100644 new mode 100755 index 7c2ecff383f..34d84dbe6db --- a/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellEditor.java +++ b/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellEditor.java @@ -52,7 +52,7 @@ public class ContributedLibraryTableCellEditor extends InstallerTableCell { private ContributedLibraryReleases editorValue; - private ContributedLibraryTableCellJPanel editorCell; + private ContributedLibraryTableCellJPanel editorCell = new ContributedLibraryTableCellJPanel(); @Override public Object getCellEditorValue() { @@ -64,8 +64,8 @@ public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { editorValue = (ContributedLibraryReleases) value; - - editorCell = new ContributedLibraryTableCellJPanel(table, value, true); + + editorCell.update(table, value, isSelected); editorCell.installButton .addActionListener(e -> onInstall(editorValue.getSelected(), editorValue.getInstalled())); diff --git a/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellJPanel.java b/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellJPanel.java old mode 100644 new mode 100755 index 4f8c15f5642..a7520bcee87 --- a/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellJPanel.java +++ b/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellJPanel.java @@ -24,22 +24,25 @@ public class ContributedLibraryTableCellJPanel extends JPanel { - final JButton moreInfoButton; - final JButton installButton; - final Component installButtonPlaceholder; - final JComboBox downgradeChooser; - final JComboBox versionToInstallChooser; - final JButton downgradeButton; - final JPanel buttonsPanel; - final JPanel inactiveButtonsPanel; - final JLabel statusLabel; - final JTextPane description; - final TitledBorder titledBorder; + protected JButton moreInfoButton; + protected JButton installButton; + protected Component installButtonPlaceholder; + protected JComboBox downgradeChooser; + protected JComboBox versionToInstallChooser; + protected JButton downgradeButton; + protected JPanel buttonsPanel; + protected JPanel inactiveButtonsPanel; + protected JLabel statusLabel; + protected JTextPane description; + protected TitledBorder titledBorder; private final String moreInfoLbl = tr("More info"); - - public ContributedLibraryTableCellJPanel(JTable parentTable, Object value, - boolean isSelected) { - super(); + + public ContributedLibraryTableCellJPanel() { + super() ; + initComponents(); + } + + public void initComponents() { setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); // Actual title set below @@ -119,6 +122,10 @@ public ContributedLibraryTableCellJPanel(JTable parentTable, Object value, add(Box.createVerticalStrut(15)); + } + +public void update(JTable parentTable, Object value, boolean isSelected) { + ContributedLibraryReleases releases = (ContributedLibraryReleases) value; // FIXME: happens on macosx, don't know why diff --git a/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellRenderer.java b/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellRenderer.java old mode 100644 new mode 100755 index d107f90208a..a07c9959188 --- a/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellRenderer.java +++ b/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellRenderer.java @@ -36,14 +36,18 @@ import javax.swing.table.TableCellRenderer; @SuppressWarnings("serial") -public class ContributedLibraryTableCellRenderer implements TableCellRenderer { +public class ContributedLibraryTableCellRenderer extends ContributedLibraryTableCellJPanel implements TableCellRenderer { + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { - ContributedLibraryTableCellJPanel cell = new ContributedLibraryTableCellJPanel(table, - value, isSelected); + + update(table, value, isSelected); + + ContributedLibraryTableCellJPanel cell = this; + cell.setButtonsVisible(false); cell.setForeground(Color.BLACK);