mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-14 11:29:26 +01:00
Making contrib table rows set the right height since the beginning, with no need to fix that later
This commit is contained in:
parent
6b5244eafe
commit
639824e516
@ -28,12 +28,12 @@
|
|||||||
*/
|
*/
|
||||||
package cc.arduino.contributions.libraries.ui;
|
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.ContributedLibrary;
|
||||||
import cc.arduino.contributions.libraries.ContributedLibraryComparator;
|
import cc.arduino.contributions.libraries.ContributedLibraryComparator;
|
||||||
import cc.arduino.contributions.libraries.filters.BuiltInPredicate;
|
import cc.arduino.contributions.libraries.filters.BuiltInPredicate;
|
||||||
import cc.arduino.contributions.filters.InstalledPredicate;
|
|
||||||
import cc.arduino.contributions.libraries.filters.OnlyUpstreamReleasePredicate;
|
import cc.arduino.contributions.libraries.filters.OnlyUpstreamReleasePredicate;
|
||||||
import cc.arduino.contributions.VersionComparator;
|
|
||||||
import cc.arduino.contributions.ui.InstallerTableCell;
|
import cc.arduino.contributions.ui.InstallerTableCell;
|
||||||
import cc.arduino.utils.ReverseComparator;
|
import cc.arduino.utils.ReverseComparator;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
@ -65,7 +65,6 @@ import static processing.app.I18n.format;
|
|||||||
public class ContributedLibraryTableCell extends InstallerTableCell {
|
public class ContributedLibraryTableCell extends InstallerTableCell {
|
||||||
|
|
||||||
private JPanel panel;
|
private JPanel panel;
|
||||||
private JTextPane description;
|
|
||||||
private JButton installButton;
|
private JButton installButton;
|
||||||
private JButton removeButton;
|
private JButton removeButton;
|
||||||
private Component removeButtonPlaceholder;
|
private Component removeButtonPlaceholder;
|
||||||
@ -79,33 +78,6 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
|
|||||||
private JLabel statusLabel;
|
private JLabel statusLabel;
|
||||||
|
|
||||||
public ContributedLibraryTableCell() {
|
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 = new JButton(_("Install"));
|
||||||
installButton.addActionListener(new ActionListener() {
|
installButton.addActionListener(new ActionListener() {
|
||||||
@ -164,7 +136,7 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
|
|||||||
panel = new JPanel();
|
panel = new JPanel();
|
||||||
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
||||||
|
|
||||||
panel.add(description);
|
makeNewDescription(panel);
|
||||||
|
|
||||||
{
|
{
|
||||||
buttonsPanel = new JPanel();
|
buttonsPanel = new JPanel();
|
||||||
@ -209,6 +181,40 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
|
|||||||
panel.add(Box.createVerticalStrut(15));
|
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) {
|
protected void onRemove(ContributedLibrary selected) {
|
||||||
// Empty
|
// Empty
|
||||||
}
|
}
|
||||||
@ -230,6 +236,11 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
|
|||||||
component.setBackground(new Color(255, 255, 255));
|
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;
|
return component;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -304,6 +315,8 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
|
|||||||
private Component getUpdatedCellComponent(Object value, boolean isSelected, int row, boolean hasBuiltInRelease) {
|
private Component getUpdatedCellComponent(Object value, boolean isSelected, int row, boolean hasBuiltInRelease) {
|
||||||
LibrariesIndexTableModel.ContributedLibraryReleases releases = (LibrariesIndexTableModel.ContributedLibraryReleases) value;
|
LibrariesIndexTableModel.ContributedLibraryReleases releases = (LibrariesIndexTableModel.ContributedLibraryReleases) value;
|
||||||
|
|
||||||
|
JTextPane description = makeNewDescription(panel);
|
||||||
|
|
||||||
//FIXME: happens on macosx, don't know why
|
//FIXME: happens on macosx, don't know why
|
||||||
if (releases == null) {
|
if (releases == null) {
|
||||||
return panel;
|
return panel;
|
||||||
|
@ -84,7 +84,6 @@ public class LibraryManagerUI extends InstallerJDialog {
|
|||||||
|
|
||||||
public void setIndexer(LibrariesIndexer indexer) {
|
public void setIndexer(LibrariesIndexer indexer) {
|
||||||
this.indexer = indexer;
|
this.indexer = indexer;
|
||||||
getContribModel().removeTableModelListener(tableModelListener);
|
|
||||||
categoryChooser.removeActionListener(categoryChooserActionListener);
|
categoryChooser.removeActionListener(categoryChooserActionListener);
|
||||||
|
|
||||||
// TODO: Remove setIndexer and make getContribModel
|
// TODO: Remove setIndexer and make getContribModel
|
||||||
@ -94,7 +93,6 @@ public class LibraryManagerUI extends InstallerJDialog {
|
|||||||
categoryFilter = null;
|
categoryFilter = null;
|
||||||
categoryChooser.removeAllItems();
|
categoryChooser.removeAllItems();
|
||||||
|
|
||||||
getContribModel().addTableModelListener(tableModelListener);
|
|
||||||
categoryChooser.addActionListener(categoryChooserActionListener);
|
categoryChooser.addActionListener(categoryChooserActionListener);
|
||||||
|
|
||||||
// Load categories
|
// Load categories
|
||||||
|
@ -42,7 +42,6 @@ import com.google.common.collect.Lists;
|
|||||||
import processing.app.Base;
|
import processing.app.Base;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.Timer;
|
|
||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
import javax.swing.event.HyperlinkEvent;
|
import javax.swing.event.HyperlinkEvent;
|
||||||
import javax.swing.event.HyperlinkListener;
|
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.HTMLDocument;
|
||||||
import javax.swing.text.html.StyleSheet;
|
import javax.swing.text.html.StyleSheet;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.List;
|
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.ItemEvent;
|
import java.awt.event.ItemEvent;
|
||||||
import java.awt.event.ItemListener;
|
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._;
|
||||||
import static processing.app.I18n.format;
|
import static processing.app.I18n.format;
|
||||||
@ -64,7 +63,6 @@ import static processing.app.I18n.format;
|
|||||||
public class ContributedPlatformTableCell extends InstallerTableCell {
|
public class ContributedPlatformTableCell extends InstallerTableCell {
|
||||||
|
|
||||||
private JPanel panel;
|
private JPanel panel;
|
||||||
private JTextPane description;
|
|
||||||
private JButton installButton;
|
private JButton installButton;
|
||||||
private JButton removeButton;
|
private JButton removeButton;
|
||||||
private Component removeButtonPlaceholder;
|
private Component removeButtonPlaceholder;
|
||||||
@ -78,33 +76,6 @@ public class ContributedPlatformTableCell extends InstallerTableCell {
|
|||||||
private JLabel statusLabel;
|
private JLabel statusLabel;
|
||||||
|
|
||||||
public ContributedPlatformTableCell() {
|
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 = new JButton(_("Install"));
|
||||||
installButton.addActionListener(new ActionListener() {
|
installButton.addActionListener(new ActionListener() {
|
||||||
@ -163,7 +134,7 @@ public class ContributedPlatformTableCell extends InstallerTableCell {
|
|||||||
panel = new JPanel();
|
panel = new JPanel();
|
||||||
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
||||||
|
|
||||||
panel.add(description);
|
makeNewDescription(panel);
|
||||||
|
|
||||||
{
|
{
|
||||||
buttonsPanel = new JPanel();
|
buttonsPanel = new JPanel();
|
||||||
@ -208,6 +179,40 @@ public class ContributedPlatformTableCell extends InstallerTableCell {
|
|||||||
panel.add(Box.createVerticalStrut(15));
|
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) {
|
protected void onRemove(ContributedPlatform contributedPlatform) {
|
||||||
// Empty
|
// Empty
|
||||||
}
|
}
|
||||||
@ -229,6 +234,11 @@ public class ContributedPlatformTableCell extends InstallerTableCell {
|
|||||||
component.setBackground(new Color(255, 255, 255));
|
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;
|
return component;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,6 +313,8 @@ public class ContributedPlatformTableCell extends InstallerTableCell {
|
|||||||
private Component getUpdatedCellComponent(Object value, boolean isSelected, int row, boolean hasBuiltInRelease) {
|
private Component getUpdatedCellComponent(Object value, boolean isSelected, int row, boolean hasBuiltInRelease) {
|
||||||
ContributionIndexTableModel.ContributedPlatformReleases releases = (ContributionIndexTableModel.ContributedPlatformReleases) value;
|
ContributionIndexTableModel.ContributedPlatformReleases releases = (ContributionIndexTableModel.ContributedPlatformReleases) value;
|
||||||
|
|
||||||
|
JTextPane description = makeNewDescription(panel);
|
||||||
|
|
||||||
//FIXME: happens on macosx, don't know why
|
//FIXME: happens on macosx, don't know why
|
||||||
if (releases == null) {
|
if (releases == null) {
|
||||||
return panel;
|
return panel;
|
||||||
|
@ -80,7 +80,6 @@ public class ContributionManagerUI extends InstallerJDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setIndexer(ContributionsIndexer indexer) {
|
public void setIndexer(ContributionsIndexer indexer) {
|
||||||
getContribModel().removeTableModelListener(tableModelListener);
|
|
||||||
categoryChooser.removeActionListener(categoryChooserActionListener);
|
categoryChooser.removeActionListener(categoryChooserActionListener);
|
||||||
|
|
||||||
getContribModel().setIndex(indexer.getIndex());
|
getContribModel().setIndex(indexer.getIndex());
|
||||||
@ -90,7 +89,6 @@ public class ContributionManagerUI extends InstallerJDialog {
|
|||||||
|
|
||||||
filterField.setEnabled(getContribModel().getRowCount() > 0);
|
filterField.setEnabled(getContribModel().getRowCount() > 0);
|
||||||
|
|
||||||
getContribModel().addTableModelListener(tableModelListener);
|
|
||||||
categoryChooser.addActionListener(categoryChooserActionListener);
|
categoryChooser.addActionListener(categoryChooserActionListener);
|
||||||
|
|
||||||
// Enable categories combo only if there are two or more choices
|
// Enable categories combo only if there are two or more choices
|
||||||
|
@ -66,18 +66,6 @@ public abstract class InstallerJDialog<T> extends JDialog {
|
|||||||
protected JTable contribTable;
|
protected JTable contribTable;
|
||||||
// Model behind the table
|
// Model behind the table
|
||||||
protected FilteredAbstractTableModel contribModel;
|
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();
|
abstract protected FilteredAbstractTableModel createContribModel();
|
||||||
|
|
||||||
@ -259,17 +247,6 @@ public abstract class InstallerJDialog<T> extends JDialog {
|
|||||||
cellEditor.setStatus(status);
|
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() {
|
protected ActionListener categoryChooserActionListener = new ActionListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user