diff --git a/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCell.java b/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCell.java index 56e5114c9..198ee83f6 100644 --- a/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCell.java +++ b/app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCell.java @@ -28,12 +28,12 @@ */ package cc.arduino.contributions.libraries.ui; +import cc.arduino.contributions.VersionComparator; +import cc.arduino.contributions.filters.InstalledPredicate; import cc.arduino.contributions.libraries.ContributedLibrary; import cc.arduino.contributions.libraries.ContributedLibraryComparator; import cc.arduino.contributions.libraries.filters.BuiltInPredicate; -import cc.arduino.contributions.filters.InstalledPredicate; import cc.arduino.contributions.libraries.filters.OnlyUpstreamReleasePredicate; -import cc.arduino.contributions.VersionComparator; import cc.arduino.contributions.ui.InstallerTableCell; import cc.arduino.utils.ReverseComparator; import com.google.common.base.Function; @@ -65,7 +65,6 @@ import static processing.app.I18n.format; public class ContributedLibraryTableCell extends InstallerTableCell { private JPanel panel; - private JTextPane description; private JButton installButton; private JButton removeButton; private Component removeButtonPlaceholder; @@ -79,33 +78,6 @@ public class ContributedLibraryTableCell extends InstallerTableCell { private JLabel statusLabel; public ContributedLibraryTableCell() { - description = new JTextPane(); - description.setInheritsPopupMenu(true); - Insets margin = description.getMargin(); - margin.bottom = 0; - description.setMargin(margin); - description.setContentType("text/html"); - Document doc = description.getDocument(); - if (doc instanceof HTMLDocument) { - HTMLDocument html = (HTMLDocument) doc; - StyleSheet stylesheet = html.getStyleSheet(); - stylesheet.addRule("body { margin: 0; padding: 0;" - + "font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;" - + "font-size: 100%;" + "font-size: 0.95em; }"); - } - description.setOpaque(false); - description.setBorder(new EmptyBorder(4, 7, 7, 7)); - description.setHighlighter(null); - description.setEditable(false); - description.addHyperlinkListener(new HyperlinkListener() { - @Override - public void hyperlinkUpdate(HyperlinkEvent e) { - if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { - Base.openURL(e.getDescription()); - } - } - }); - { installButton = new JButton(_("Install")); installButton.addActionListener(new ActionListener() { @@ -164,7 +136,7 @@ public class ContributedLibraryTableCell extends InstallerTableCell { panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); - panel.add(description); + makeNewDescription(panel); { buttonsPanel = new JPanel(); @@ -209,6 +181,40 @@ public class ContributedLibraryTableCell extends InstallerTableCell { panel.add(Box.createVerticalStrut(15)); } + private JTextPane makeNewDescription(JPanel panel) { + if (panel.getComponentCount() > 0) { + panel.remove(0); + } + JTextPane description = new JTextPane(); + description.setInheritsPopupMenu(true); + Insets margin = description.getMargin(); + margin.bottom = 0; + description.setMargin(margin); + description.setContentType("text/html"); + Document doc = description.getDocument(); + if (doc instanceof HTMLDocument) { + HTMLDocument html = (HTMLDocument) doc; + StyleSheet stylesheet = html.getStyleSheet(); + stylesheet.addRule("body { margin: 0; padding: 0;" + + "font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;" + + "font-size: 100%;" + "font-size: 0.95em; }"); + } + description.setOpaque(false); + description.setBorder(new EmptyBorder(4, 7, 7, 7)); + description.setHighlighter(null); + description.setEditable(false); + description.addHyperlinkListener(new HyperlinkListener() { + @Override + public void hyperlinkUpdate(HyperlinkEvent e) { + if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { + Base.openURL(e.getDescription()); + } + } + }); + panel.add(description, 0); + return description; + } + protected void onRemove(ContributedLibrary selected) { // Empty } @@ -230,6 +236,11 @@ public class ContributedLibraryTableCell extends InstallerTableCell { component.setBackground(new Color(255, 255, 255)); } + int height = new Double(component.getPreferredSize().getHeight()).intValue(); + if (table.getRowHeight(row) < height) { + table.setRowHeight(row, height); + } + return component; } @@ -304,6 +315,8 @@ public class ContributedLibraryTableCell extends InstallerTableCell { private Component getUpdatedCellComponent(Object value, boolean isSelected, int row, boolean hasBuiltInRelease) { LibrariesIndexTableModel.ContributedLibraryReleases releases = (LibrariesIndexTableModel.ContributedLibraryReleases) value; + JTextPane description = makeNewDescription(panel); + //FIXME: happens on macosx, don't know why if (releases == null) { return panel; diff --git a/app/src/cc/arduino/contributions/libraries/ui/LibraryManagerUI.java b/app/src/cc/arduino/contributions/libraries/ui/LibraryManagerUI.java index 0b4e7ae9b..3aac99ba0 100644 --- a/app/src/cc/arduino/contributions/libraries/ui/LibraryManagerUI.java +++ b/app/src/cc/arduino/contributions/libraries/ui/LibraryManagerUI.java @@ -84,7 +84,6 @@ public class LibraryManagerUI extends InstallerJDialog { public void setIndexer(LibrariesIndexer indexer) { this.indexer = indexer; - getContribModel().removeTableModelListener(tableModelListener); categoryChooser.removeActionListener(categoryChooserActionListener); // TODO: Remove setIndexer and make getContribModel @@ -94,7 +93,6 @@ public class LibraryManagerUI extends InstallerJDialog { categoryFilter = null; categoryChooser.removeAllItems(); - getContribModel().addTableModelListener(tableModelListener); categoryChooser.addActionListener(categoryChooserActionListener); // Load categories diff --git a/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCell.java b/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCell.java index da1c38708..ff151e616 100644 --- a/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCell.java +++ b/app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCell.java @@ -42,7 +42,6 @@ import com.google.common.collect.Lists; import processing.app.Base; import javax.swing.*; -import javax.swing.Timer; import javax.swing.border.EmptyBorder; import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener; @@ -50,12 +49,12 @@ import javax.swing.text.Document; import javax.swing.text.html.HTMLDocument; import javax.swing.text.html.StyleSheet; import java.awt.*; -import java.awt.List; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; -import java.util.*; +import java.util.Collections; +import java.util.LinkedList; import static processing.app.I18n._; import static processing.app.I18n.format; @@ -64,7 +63,6 @@ import static processing.app.I18n.format; public class ContributedPlatformTableCell extends InstallerTableCell { private JPanel panel; - private JTextPane description; private JButton installButton; private JButton removeButton; private Component removeButtonPlaceholder; @@ -78,33 +76,6 @@ public class ContributedPlatformTableCell extends InstallerTableCell { private JLabel statusLabel; public ContributedPlatformTableCell() { - description = new JTextPane(); - description.setInheritsPopupMenu(true); - Insets margin = description.getMargin(); - margin.bottom = 0; - description.setMargin(margin); - description.setContentType("text/html"); - Document doc = description.getDocument(); - if (doc instanceof HTMLDocument) { - HTMLDocument html = (HTMLDocument) doc; - StyleSheet stylesheet = html.getStyleSheet(); - stylesheet.addRule("body { margin: 0; padding: 0;" - + "font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;" - + "font-size: 100%;" + "font-size: 0.95em; }"); - } - description.setOpaque(false); - description.setBorder(new EmptyBorder(4, 7, 7, 7)); - description.setHighlighter(null); - description.setEditable(false); - description.addHyperlinkListener(new HyperlinkListener() { - @Override - public void hyperlinkUpdate(HyperlinkEvent e) { - if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { - Base.openURL(e.getDescription()); - } - } - }); - { installButton = new JButton(_("Install")); installButton.addActionListener(new ActionListener() { @@ -163,7 +134,7 @@ public class ContributedPlatformTableCell extends InstallerTableCell { panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); - panel.add(description); + makeNewDescription(panel); { buttonsPanel = new JPanel(); @@ -208,6 +179,40 @@ public class ContributedPlatformTableCell extends InstallerTableCell { panel.add(Box.createVerticalStrut(15)); } + private JTextPane makeNewDescription(JPanel panel) { + if (panel.getComponentCount() > 0) { + panel.remove(0); + } + JTextPane description = new JTextPane(); + description.setInheritsPopupMenu(true); + Insets margin = description.getMargin(); + margin.bottom = 0; + description.setMargin(margin); + description.setContentType("text/html"); + Document doc = description.getDocument(); + if (doc instanceof HTMLDocument) { + HTMLDocument html = (HTMLDocument) doc; + StyleSheet stylesheet = html.getStyleSheet(); + stylesheet.addRule("body { margin: 0; padding: 0;" + + "font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;" + + "font-size: 100%;" + "font-size: 0.95em; }"); + } + description.setOpaque(false); + description.setBorder(new EmptyBorder(4, 7, 7, 7)); + description.setHighlighter(null); + description.setEditable(false); + description.addHyperlinkListener(new HyperlinkListener() { + @Override + public void hyperlinkUpdate(HyperlinkEvent e) { + if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { + Base.openURL(e.getDescription()); + } + } + }); + panel.add(description, 0); + return description; + } + protected void onRemove(ContributedPlatform contributedPlatform) { // Empty } @@ -229,6 +234,11 @@ public class ContributedPlatformTableCell extends InstallerTableCell { component.setBackground(new Color(255, 255, 255)); } + int height = new Double(component.getPreferredSize().getHeight()).intValue(); + if (table.getRowHeight(row) < height) { + table.setRowHeight(row, height); + } + return component; } @@ -303,6 +313,8 @@ public class ContributedPlatformTableCell extends InstallerTableCell { private Component getUpdatedCellComponent(Object value, boolean isSelected, int row, boolean hasBuiltInRelease) { ContributionIndexTableModel.ContributedPlatformReleases releases = (ContributionIndexTableModel.ContributedPlatformReleases) value; + JTextPane description = makeNewDescription(panel); + //FIXME: happens on macosx, don't know why if (releases == null) { return panel; diff --git a/app/src/cc/arduino/contributions/packages/ui/ContributionManagerUI.java b/app/src/cc/arduino/contributions/packages/ui/ContributionManagerUI.java index 67f87d70f..5bd4a98ac 100644 --- a/app/src/cc/arduino/contributions/packages/ui/ContributionManagerUI.java +++ b/app/src/cc/arduino/contributions/packages/ui/ContributionManagerUI.java @@ -80,7 +80,6 @@ public class ContributionManagerUI extends InstallerJDialog { } public void setIndexer(ContributionsIndexer indexer) { - getContribModel().removeTableModelListener(tableModelListener); categoryChooser.removeActionListener(categoryChooserActionListener); getContribModel().setIndex(indexer.getIndex()); @@ -90,7 +89,6 @@ public class ContributionManagerUI extends InstallerJDialog { filterField.setEnabled(getContribModel().getRowCount() > 0); - getContribModel().addTableModelListener(tableModelListener); categoryChooser.addActionListener(categoryChooserActionListener); // Enable categories combo only if there are two or more choices diff --git a/app/src/cc/arduino/contributions/ui/InstallerJDialog.java b/app/src/cc/arduino/contributions/ui/InstallerJDialog.java index c8798ee38..77d5e3892 100644 --- a/app/src/cc/arduino/contributions/ui/InstallerJDialog.java +++ b/app/src/cc/arduino/contributions/ui/InstallerJDialog.java @@ -66,18 +66,6 @@ public abstract class InstallerJDialog extends JDialog { protected JTable contribTable; // Model behind the table protected FilteredAbstractTableModel contribModel; - // Default table model listener - protected TableModelListener tableModelListener = new TableModelListener() { - @Override - public void tableChanged(final TableModelEvent event) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - updateCellsHeight(event); - } - }); - } - }; abstract protected FilteredAbstractTableModel createContribModel(); @@ -259,17 +247,6 @@ public abstract class InstallerJDialog extends JDialog { cellEditor.setStatus(status); } - private void updateCellsHeight(TableModelEvent e) { - int first = e.getFirstRow(); - int last = Math.min(e.getLastRow(), contribTable.getRowCount() - 1); - for (int row = first; row <= last; row++) { - TableCellRenderer editor = createCellRenderer(); - Component comp = contribTable.prepareRenderer(editor, row, 0); - int height = comp.getPreferredSize().height; - contribTable.setRowHeight(row, height); - } - } - protected ActionListener categoryChooserActionListener = new ActionListener() { @Override