From 76068c92b4121651f55b6fc4e51bac4847989f1e Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 28 Dec 2015 15:31:52 +0100 Subject: [PATCH] *TableCellEditor now extends JPanel --- .../ui/ContributedLibraryTableCell.java | 42 +++++++++---------- .../ui/ContributedLibraryTableCellEditor.java | 4 +- .../ContributedLibraryTableCellRenderer.java | 8 ++-- .../ui/ContributedPlatformTableCell.java | 35 ++++++++-------- .../ContributedPlatformTableCellEditor.java | 4 +- .../ContributedPlatformTableCellRenderer.java | 8 ++-- 6 files changed, 50 insertions(+), 51 deletions(-) diff --git a/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCell.java b/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCell.java index e3a9c6969..ad4144f63 100644 --- a/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCell.java +++ b/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCell.java @@ -27,9 +27,8 @@ import cc.arduino.contributions.libraries.ContributedLibrary; import cc.arduino.contributions.ui.InstallerTableCell; import processing.app.Base; -public class ContributedLibraryTableCell { +public class ContributedLibraryTableCell extends JPanel { - protected final JPanel panel; protected final JButton installButton; protected final Component installButtonPlaceholder; protected final JComboBox downgradeChooser; @@ -40,6 +39,9 @@ public class ContributedLibraryTableCell { protected final JLabel statusLabel; public ContributedLibraryTableCell() { + super(); + setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + installButton = new JButton(tr("Install")); int width = installButton.getPreferredSize().width; installButtonPlaceholder = Box.createRigidArea(new Dimension(width, 1)); @@ -60,10 +62,7 @@ public class ContributedLibraryTableCell { versionToInstallChooser .setMaximumSize(versionToInstallChooser.getPreferredSize()); - panel = new JPanel(); - panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); - - makeNewDescription(panel); + makeNewDescription(); buttonsPanel = new JPanel(); buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS)); @@ -82,7 +81,7 @@ public class ContributedLibraryTableCell { buttonsPanel.add(Box.createHorizontalStrut(5)); buttonsPanel.add(Box.createHorizontalStrut(15)); - panel.add(buttonsPanel); + add(buttonsPanel); inactiveButtonsPanel = new JPanel(); inactiveButtonsPanel @@ -97,16 +96,16 @@ public class ContributedLibraryTableCell { inactiveButtonsPanel.add(statusLabel); inactiveButtonsPanel.add(Box.createHorizontalStrut(15)); - panel.add(inactiveButtonsPanel); + add(inactiveButtonsPanel); - panel.add(Box.createVerticalStrut(15)); + add(Box.createVerticalStrut(15)); } - void update(JTable parentTable, Object value, boolean isSelected, - int row, boolean hasBuiltInRelease) { + void update(JTable parentTable, Object value, boolean isSelected, int row, + boolean hasBuiltInRelease) { ContributedLibraryReleases releases = (ContributedLibraryReleases) value; - JTextPane description = makeNewDescription(panel); + JTextPane description = makeNewDescription(); // FIXME: happens on macosx, don't know why if (releases == null) @@ -196,20 +195,21 @@ public class ContributedLibraryTableCell { // 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, + width); if (isSelected) { - panel.setBackground(parentTable.getSelectionBackground()); - panel.setForeground(parentTable.getSelectionForeground()); + setBackground(parentTable.getSelectionBackground()); + setForeground(parentTable.getSelectionForeground()); } else { - panel.setBackground(parentTable.getBackground()); - panel.setForeground(parentTable.getForeground()); + setBackground(parentTable.getBackground()); + setForeground(parentTable.getForeground()); } } - private static JTextPane makeNewDescription(JPanel panel) { - if (panel.getComponentCount() > 0) { - panel.remove(0); + private JTextPane makeNewDescription() { + if (getComponentCount() > 0) { + remove(0); } JTextPane description = new JTextPane(); description.setInheritsPopupMenu(true); @@ -235,7 +235,7 @@ public class ContributedLibraryTableCell { } }); // description.addKeyListener(new DelegatingKeyListener(parentTable)); - panel.add(description, 0); + add(description, 0); return description; } diff --git a/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellEditor.java b/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellEditor.java index b199be910..08bfdb854 100644 --- a/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellEditor.java +++ b/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellEditor.java @@ -135,8 +135,8 @@ public class ContributedLibraryTableCellEditor extends InstallerTableCell { .setVisible(installed == null && uninstalledReleases.size() > 1); editorCell.update(table, value, true, row, !installedBuiltIn.isEmpty()); - editorCell.panel.setBackground(new Color(218, 227, 227)); // #dae3e3 - return editorCell.panel; + editorCell.setBackground(new Color(218, 227, 227)); // #dae3e3 + return editorCell; } @Override diff --git a/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellRenderer.java b/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellRenderer.java index 785467584..a472029a3 100644 --- a/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellRenderer.java +++ b/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCellRenderer.java @@ -48,18 +48,18 @@ public class ContributedLibraryTableCellRenderer implements TableCellRenderer { cell.update(table, value, isSelected, row, false); if (row % 2 == 0) { - cell.panel.setBackground(new Color(236, 241, 241)); // #ecf1f1 + cell.setBackground(new Color(236, 241, 241)); // #ecf1f1 } else { - cell.panel.setBackground(new Color(255, 255, 255)); + cell.setBackground(new Color(255, 255, 255)); } - int height = new Double(cell.panel.getPreferredSize().getHeight()) + int height = new Double(cell.getPreferredSize().getHeight()) .intValue(); if (table.getRowHeight(row) < height) { table.setRowHeight(row, height); } - return cell.panel; + return cell; } } diff --git a/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCell.java b/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCell.java index 4ab7c2a5f..34ac5ca0e 100644 --- a/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCell.java +++ b/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCell.java @@ -59,9 +59,8 @@ import cc.arduino.contributions.ui.InstallerTableCell; import processing.app.Base; @SuppressWarnings("serial") -public class ContributedPlatformTableCell { +public class ContributedPlatformTableCell extends JPanel { - final JPanel panel; final JButton installButton; final JButton removeButton; final Component removeButtonPlaceholder; @@ -74,6 +73,9 @@ public class ContributedPlatformTableCell { final JLabel statusLabel; public ContributedPlatformTableCell() { + super(); + setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + { installButton = new JButton(tr("Install")); int width = installButton.getPreferredSize().width; @@ -102,10 +104,7 @@ public class ContributedPlatformTableCell { versionToInstallChooser .setMaximumSize(versionToInstallChooser.getPreferredSize()); - panel = new JPanel(); - panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); - - makeNewDescription(panel); + makeNewDescription(); buttonsPanel = new JPanel(); buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS)); @@ -126,7 +125,7 @@ public class ContributedPlatformTableCell { buttonsPanel.add(Box.createHorizontalStrut(5)); buttonsPanel.add(Box.createHorizontalStrut(15)); - panel.add(buttonsPanel); + add(buttonsPanel); inactiveButtonsPanel = new JPanel(); inactiveButtonsPanel @@ -141,16 +140,16 @@ public class ContributedPlatformTableCell { inactiveButtonsPanel.add(statusLabel); inactiveButtonsPanel.add(Box.createHorizontalStrut(15)); - panel.add(inactiveButtonsPanel); + add(inactiveButtonsPanel); - panel.add(Box.createVerticalStrut(15)); + add(Box.createVerticalStrut(15)); } void update(JTable parentTable, Object value, boolean isSelected, int row, boolean hasBuiltInRelease) { ContributionIndexTableModel.ContributedPlatformReleases releases = (ContributionIndexTableModel.ContributedPlatformReleases) value; - JTextPane description = makeNewDescription(panel); + JTextPane description = makeNewDescription(); // FIXME: happens on macosx, don't know why if (releases == null) { @@ -239,17 +238,17 @@ public class ContributedPlatformTableCell { width); if (isSelected) { - panel.setBackground(parentTable.getSelectionBackground()); - panel.setForeground(parentTable.getSelectionForeground()); + setBackground(parentTable.getSelectionBackground()); + setForeground(parentTable.getSelectionForeground()); } else { - panel.setBackground(parentTable.getBackground()); - panel.setForeground(parentTable.getForeground()); + setBackground(parentTable.getBackground()); + setForeground(parentTable.getForeground()); } } - private static JTextPane makeNewDescription(JPanel panel) { - if (panel.getComponentCount() > 0) { - panel.remove(0); + private JTextPane makeNewDescription() { + if (getComponentCount() > 0) { + remove(0); } JTextPane description = new JTextPane(); description.setInheritsPopupMenu(true); @@ -274,7 +273,7 @@ public class ContributedPlatformTableCell { Base.openURL(e.getDescription()); } }); - panel.add(description, 0); + add(description, 0); return description; } diff --git a/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellEditor.java b/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellEditor.java index b5b2f8f5c..20e8170b8 100644 --- a/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellEditor.java +++ b/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellEditor.java @@ -132,8 +132,8 @@ public class ContributedPlatformTableCellEditor extends InstallerTableCell { .setVisible(installed == null && uninstalledReleases.size() > 1); editorCell.update(table, value, true, row, !installedBuiltIn.isEmpty()); - editorCell.panel.setBackground(new Color(218, 227, 227)); // #dae3e3 - return editorCell.panel; + editorCell.setBackground(new Color(218, 227, 227)); // #dae3e3 + return editorCell; } @Override diff --git a/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellRenderer.java b/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellRenderer.java index 23585dab0..fa0230eb0 100644 --- a/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellRenderer.java +++ b/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellRenderer.java @@ -47,18 +47,18 @@ public class ContributedPlatformTableCellRenderer implements TableCellRenderer { cell.update(table, value, isSelected, row, false); if (row % 2 == 0) { - cell.panel.setBackground(new Color(236, 241, 241)); // #ecf1f1 + cell.setBackground(new Color(236, 241, 241)); // #ecf1f1 } else { - cell.panel.setBackground(new Color(255, 255, 255)); + cell.setBackground(new Color(255, 255, 255)); } - int height = new Double(cell.panel.getPreferredSize().getHeight()) + int height = new Double(cell.getPreferredSize().getHeight()) .intValue(); if (table.getRowHeight(row) < height) { table.setRowHeight(row, height); } - return cell.panel; + return cell; } }