diff --git a/app/src/cc/arduino/libraries/contributions/ui/ContributedLibraryTableCell.java b/app/src/cc/arduino/libraries/contributions/ui/ContributedLibraryTableCell.java index 2a1290fee..3a66450b0 100644 --- a/app/src/cc/arduino/libraries/contributions/ui/ContributedLibraryTableCell.java +++ b/app/src/cc/arduino/libraries/contributions/ui/ContributedLibraryTableCell.java @@ -28,35 +28,24 @@ */ package cc.arduino.libraries.contributions.ui; -import static processing.app.I18n._; -import static processing.app.I18n.format; - -import java.awt.Color; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.Insets; -import java.awt.Rectangle; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.Box; -import javax.swing.BoxLayout; -import javax.swing.JButton; -import javax.swing.JPanel; -import javax.swing.JTable; -import javax.swing.JTextPane; -import javax.swing.border.EmptyBorder; -import javax.swing.event.HyperlinkEvent; -import javax.swing.event.HyperlinkListener; -import javax.swing.text.BadLocationException; -import javax.swing.text.Document; -import javax.swing.text.html.HTMLDocument; -import javax.swing.text.html.StyleSheet; - -import processing.app.Base; import cc.arduino.libraries.contributions.ContributedLibrary; import cc.arduino.libraries.contributions.ui.LibrariesIndexTableModel.ContributedLibraryReleases; import cc.arduino.ui.InstallerTableCell; +import processing.app.Base; + +import javax.swing.*; +import javax.swing.border.EmptyBorder; +import javax.swing.event.HyperlinkEvent; +import javax.swing.event.HyperlinkListener; +import javax.swing.text.Document; +import javax.swing.text.html.HTMLDocument; +import javax.swing.text.html.StyleSheet; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import static processing.app.I18n._; +import static processing.app.I18n.format; @SuppressWarnings("serial") public class ContributedLibraryTableCell extends InstallerTableCell { @@ -252,18 +241,7 @@ public class ContributedLibraryTableCell extends InstallerTableCell { int width = parentTable.getBounds().width; width -= installButtonPlaceholder.getPreferredSize().width; width -= removeButtonPlaceholder.getPreferredSize().width; - Dimension minimalSize = new Dimension(width, 10); - description.setPreferredSize(minimalSize); - description.setSize(minimalSize); - - try { - Rectangle r = description.modelToView(description.getDocument().getLength()); - r.height += description.modelToView(0).y; // add margins - Dimension d = new Dimension(minimalSize.width, r.y + r.height); - description.setPreferredSize(d); - } catch (BadLocationException e) { - throw new RuntimeException(e); - } + setJTextPaneDimensionToFitContainedText(description, width); if (isSelected) { panel.setBackground(parentTable.getSelectionBackground()); diff --git a/app/src/cc/arduino/packages/contributions/ui/ContributedPlatformTableCell.java b/app/src/cc/arduino/packages/contributions/ui/ContributedPlatformTableCell.java index 41ec42995..f109e141f 100644 --- a/app/src/cc/arduino/packages/contributions/ui/ContributedPlatformTableCell.java +++ b/app/src/cc/arduino/packages/contributions/ui/ContributedPlatformTableCell.java @@ -142,12 +142,12 @@ public class ContributedPlatformTableCell extends InstallerTableCell { downgradeButton.setEnabled(!disableDowngrade); } }); - + panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); panel.add(description); - + { buttonsPanel = new JPanel(); buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS)); @@ -168,22 +168,21 @@ public class ContributedPlatformTableCell extends InstallerTableCell { panel.add(buttonsPanel); } - + { inactiveButtonsPanel = new JPanel(); - inactiveButtonsPanel.setLayout(new BoxLayout(inactiveButtonsPanel, - BoxLayout.X_AXIS)); + inactiveButtonsPanel.setLayout(new BoxLayout(inactiveButtonsPanel, BoxLayout.X_AXIS)); inactiveButtonsPanel.setOpaque(false); - int h = installButton.getMinimumSize().height; - inactiveButtonsPanel.add(Box.createVerticalStrut(h)); + int height = installButton.getMinimumSize().height; + inactiveButtonsPanel.add(Box.createVerticalStrut(height)); inactiveButtonsPanel.add(Box.createGlue()); - + statusLabel = new JLabel(" "); inactiveButtonsPanel.add(statusLabel); - + inactiveButtonsPanel.add(Box.createGlue()); - inactiveButtonsPanel.add(Box.createVerticalStrut(h)); + inactiveButtonsPanel.add(Box.createVerticalStrut(height)); panel.add(inactiveButtonsPanel); } @@ -295,6 +294,9 @@ public class ContributedPlatformTableCell extends InstallerTableCell { panel.setForeground(parentTable.getForeground()); } + int width = parentTable.getBounds().width; + setJTextPaneDimensionToFitContainedText(description, width); + return panel; } @@ -305,7 +307,7 @@ public class ContributedPlatformTableCell extends InstallerTableCell { enabler.stop(); } }); - + @Override public void setEnabled(boolean enabled) { enable(false); diff --git a/app/src/cc/arduino/ui/InstallerTableCell.java b/app/src/cc/arduino/ui/InstallerTableCell.java index 57e49b34b..ae297f8f7 100644 --- a/app/src/cc/arduino/ui/InstallerTableCell.java +++ b/app/src/cc/arduino/ui/InstallerTableCell.java @@ -28,19 +28,34 @@ */ package cc.arduino.ui; -import javax.swing.AbstractCellEditor; +import javax.swing.*; import javax.swing.table.TableCellEditor; import javax.swing.table.TableCellRenderer; +import javax.swing.text.BadLocationException; +import java.awt.*; -public abstract class InstallerTableCell extends AbstractCellEditor implements - TableCellEditor, TableCellRenderer { +public abstract class InstallerTableCell extends AbstractCellEditor implements TableCellEditor, TableCellRenderer { public void setEnabled(boolean b) { - // Empty } public void setStatus(String s) { - // Empty + } + + protected void setJTextPaneDimensionToFitContainedText(JTextPane jTextPane, int width) { + Dimension minimumDimension = new Dimension(width, 10); + jTextPane.setPreferredSize(minimumDimension); + jTextPane.setSize(minimumDimension); + + try { + Rectangle r = jTextPane.modelToView(jTextPane.getDocument().getLength()); + r.height += jTextPane.modelToView(0).y; // add margins + Dimension d = new Dimension(minimumDimension.width, r.y + r.height); + jTextPane.setPreferredSize(d); + } catch (BadLocationException e) { + throw new RuntimeException(e); + } + } }