1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-30 19:52:13 +01:00

Added InstallerTableCell.setJTextPaneDimensionToFitContainedText

This commit is contained in:
Federico Fissore 2015-02-25 16:13:19 +01:00
parent 1f564d6709
commit cb6514e4bb
3 changed files with 49 additions and 54 deletions

View File

@ -28,35 +28,24 @@
*/ */
package cc.arduino.libraries.contributions.ui; 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.ContributedLibrary;
import cc.arduino.libraries.contributions.ui.LibrariesIndexTableModel.ContributedLibraryReleases; import cc.arduino.libraries.contributions.ui.LibrariesIndexTableModel.ContributedLibraryReleases;
import cc.arduino.ui.InstallerTableCell; 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") @SuppressWarnings("serial")
public class ContributedLibraryTableCell extends InstallerTableCell { public class ContributedLibraryTableCell extends InstallerTableCell {
@ -252,18 +241,7 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
int width = parentTable.getBounds().width; int width = parentTable.getBounds().width;
width -= installButtonPlaceholder.getPreferredSize().width; width -= installButtonPlaceholder.getPreferredSize().width;
width -= removeButtonPlaceholder.getPreferredSize().width; width -= removeButtonPlaceholder.getPreferredSize().width;
Dimension minimalSize = new Dimension(width, 10); setJTextPaneDimensionToFitContainedText(description, width);
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);
}
if (isSelected) { if (isSelected) {
panel.setBackground(parentTable.getSelectionBackground()); panel.setBackground(parentTable.getSelectionBackground());

View File

@ -171,19 +171,18 @@ public class ContributedPlatformTableCell extends InstallerTableCell {
{ {
inactiveButtonsPanel = new JPanel(); inactiveButtonsPanel = new JPanel();
inactiveButtonsPanel.setLayout(new BoxLayout(inactiveButtonsPanel, inactiveButtonsPanel.setLayout(new BoxLayout(inactiveButtonsPanel, BoxLayout.X_AXIS));
BoxLayout.X_AXIS));
inactiveButtonsPanel.setOpaque(false); inactiveButtonsPanel.setOpaque(false);
int h = installButton.getMinimumSize().height; int height = installButton.getMinimumSize().height;
inactiveButtonsPanel.add(Box.createVerticalStrut(h)); inactiveButtonsPanel.add(Box.createVerticalStrut(height));
inactiveButtonsPanel.add(Box.createGlue()); inactiveButtonsPanel.add(Box.createGlue());
statusLabel = new JLabel(" "); statusLabel = new JLabel(" ");
inactiveButtonsPanel.add(statusLabel); inactiveButtonsPanel.add(statusLabel);
inactiveButtonsPanel.add(Box.createGlue()); inactiveButtonsPanel.add(Box.createGlue());
inactiveButtonsPanel.add(Box.createVerticalStrut(h)); inactiveButtonsPanel.add(Box.createVerticalStrut(height));
panel.add(inactiveButtonsPanel); panel.add(inactiveButtonsPanel);
} }
@ -295,6 +294,9 @@ public class ContributedPlatformTableCell extends InstallerTableCell {
panel.setForeground(parentTable.getForeground()); panel.setForeground(parentTable.getForeground());
} }
int width = parentTable.getBounds().width;
setJTextPaneDimensionToFitContainedText(description, width);
return panel; return panel;
} }

View File

@ -28,19 +28,34 @@
*/ */
package cc.arduino.ui; package cc.arduino.ui;
import javax.swing.AbstractCellEditor; import javax.swing.*;
import javax.swing.table.TableCellEditor; import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer; import javax.swing.table.TableCellRenderer;
import javax.swing.text.BadLocationException;
import java.awt.*;
public abstract class InstallerTableCell extends AbstractCellEditor implements public abstract class InstallerTableCell extends AbstractCellEditor implements TableCellEditor, TableCellRenderer {
TableCellEditor, TableCellRenderer {
public void setEnabled(boolean b) { public void setEnabled(boolean b) {
// Empty
} }
public void setStatus(String s) { 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);
}
} }
} }