mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-18 07:52:14 +01:00
Added InstallerTableCell.setJTextPaneDimensionToFitContainedText
This commit is contained in:
parent
1f564d6709
commit
cb6514e4bb
@ -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());
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user