mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-07 01:54:26 +01:00
Libraries Installer UI refactor
This commit is contained in:
parent
f833ff84a7
commit
2c234a09f1
@ -28,24 +28,38 @@
|
|||||||
*/
|
*/
|
||||||
package cc.arduino.libraries.contributions.ui;
|
package cc.arduino.libraries.contributions.ui;
|
||||||
|
|
||||||
import cc.arduino.libraries.contributions.ContributedLibrary;
|
import static processing.app.I18n._;
|
||||||
import cc.arduino.libraries.contributions.ui.LibrariesIndexTableModel.ContributedLibraryReleases;
|
import static processing.app.I18n.format;
|
||||||
import cc.arduino.ui.InstallerTableCell;
|
|
||||||
import processing.app.Base;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
import java.awt.Color;
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Insets;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.ItemEvent;
|
||||||
|
import java.awt.event.ItemListener;
|
||||||
|
|
||||||
|
import javax.swing.Box;
|
||||||
|
import javax.swing.BoxLayout;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JComboBox;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JTable;
|
||||||
|
import javax.swing.JTextPane;
|
||||||
|
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;
|
||||||
import javax.swing.text.Document;
|
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.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
|
|
||||||
import static processing.app.I18n._;
|
import processing.app.Base;
|
||||||
import static processing.app.I18n.format;
|
import cc.arduino.libraries.contributions.ContributedLibrary;
|
||||||
|
import cc.arduino.libraries.contributions.ui.LibrariesIndexTableModel.ContributedLibraryReleases;
|
||||||
|
import cc.arduino.ui.InstallerTableCell;
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class ContributedLibraryTableCell extends InstallerTableCell {
|
public class ContributedLibraryTableCell extends InstallerTableCell {
|
||||||
@ -56,6 +70,12 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
|
|||||||
private JButton removeButton;
|
private JButton removeButton;
|
||||||
private Component removeButtonPlaceholder;
|
private Component removeButtonPlaceholder;
|
||||||
private Component installButtonPlaceholder;
|
private Component installButtonPlaceholder;
|
||||||
|
private JComboBox downgradeChooser;
|
||||||
|
private JButton downgradeButton;
|
||||||
|
private JPanel buttonsPanel;
|
||||||
|
private Component removeButtonStrut;
|
||||||
|
private JPanel inactiveButtonsPanel;
|
||||||
|
private JLabel statusLabel;
|
||||||
|
|
||||||
public ContributedLibraryTableCell() {
|
public ContributedLibraryTableCell() {
|
||||||
description = new JTextPane();
|
description = new JTextPane();
|
||||||
@ -109,17 +129,74 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
|
|||||||
removeButtonPlaceholder = Box.createRigidArea(new Dimension(width, 1));
|
removeButtonPlaceholder = Box.createRigidArea(new Dimension(width, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
downgradeButton = new JButton(_("Install"));
|
||||||
|
downgradeButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
ContributedLibrary selected;
|
||||||
|
selected = (ContributedLibrary) downgradeChooser.getSelectedItem();
|
||||||
|
onInstall(selected);//, editorValue.getInstalled());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
downgradeChooser = new JComboBox();
|
||||||
|
downgradeChooser.addItem("-");
|
||||||
|
downgradeChooser.setMaximumSize(downgradeChooser.getPreferredSize());
|
||||||
|
downgradeChooser.addItemListener(new ItemListener() {
|
||||||
|
@Override
|
||||||
|
public void itemStateChanged(ItemEvent e) {
|
||||||
|
Object selectVersionItem = downgradeChooser.getItemAt(0);
|
||||||
|
boolean disableDowngrade = (e.getItem() == selectVersionItem);
|
||||||
|
downgradeButton.setEnabled(!disableDowngrade);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
panel = new JPanel();
|
panel = new JPanel();
|
||||||
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
|
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
||||||
|
|
||||||
panel.add(description);
|
panel.add(description);
|
||||||
panel.add(Box.createHorizontalStrut(5));
|
|
||||||
panel.add(installButton);
|
{
|
||||||
panel.add(installButtonPlaceholder);
|
buttonsPanel = new JPanel();
|
||||||
panel.add(Box.createHorizontalStrut(5));
|
buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS));
|
||||||
panel.add(removeButton);
|
buttonsPanel.setOpaque(false);
|
||||||
panel.add(removeButtonPlaceholder);
|
|
||||||
panel.add(Box.createHorizontalStrut(5));
|
buttonsPanel.add(Box.createHorizontalStrut(20));
|
||||||
|
buttonsPanel.add(downgradeChooser);
|
||||||
|
buttonsPanel.add(Box.createHorizontalStrut(5));
|
||||||
|
buttonsPanel.add(downgradeButton);
|
||||||
|
|
||||||
|
buttonsPanel.add(Box.createHorizontalGlue());
|
||||||
|
|
||||||
|
buttonsPanel.add(installButton);
|
||||||
|
buttonsPanel.add(Box.createHorizontalStrut(5));
|
||||||
|
buttonsPanel.add(removeButton);
|
||||||
|
removeButtonStrut = Box.createHorizontalStrut(5);
|
||||||
|
buttonsPanel.add(removeButtonStrut);
|
||||||
|
buttonsPanel.add(Box.createHorizontalStrut(15));
|
||||||
|
|
||||||
|
panel.add(buttonsPanel);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
inactiveButtonsPanel = new JPanel();
|
||||||
|
inactiveButtonsPanel.setLayout(new BoxLayout(inactiveButtonsPanel, BoxLayout.X_AXIS));
|
||||||
|
inactiveButtonsPanel.setOpaque(false);
|
||||||
|
|
||||||
|
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(height));
|
||||||
|
|
||||||
|
panel.add(inactiveButtonsPanel);
|
||||||
|
}
|
||||||
|
|
||||||
|
panel.add(Box.createVerticalStrut(10));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onRemove(ContributedLibrary contributedPlatform) {
|
protected void onRemove(ContributedLibrary contributedPlatform) {
|
||||||
@ -135,6 +212,7 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
|
|||||||
boolean hasFocus, int row,
|
boolean hasFocus, int row,
|
||||||
int column) {
|
int column) {
|
||||||
parentTable = table;
|
parentTable = table;
|
||||||
|
setEnabled(false);
|
||||||
return getUpdatedCellComponent(value, isSelected, row);
|
return getUpdatedCellComponent(value, isSelected, row);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,6 +230,20 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
|
|||||||
int column) {
|
int column) {
|
||||||
parentTable = table;
|
parentTable = table;
|
||||||
editorValue = (ContributedLibraryReleases) value;
|
editorValue = (ContributedLibraryReleases) value;
|
||||||
|
setEnabled(true);
|
||||||
|
|
||||||
|
downgradeChooser.removeAllItems();
|
||||||
|
downgradeChooser.addItem(_("Select version"));
|
||||||
|
boolean visible = false;
|
||||||
|
for (ContributedLibrary release : editorValue.releases) {
|
||||||
|
if (release.isInstalled())
|
||||||
|
continue;
|
||||||
|
downgradeChooser.addItem(release);
|
||||||
|
visible = true;
|
||||||
|
}
|
||||||
|
downgradeChooser.setVisible(visible);
|
||||||
|
downgradeButton.setVisible(visible);
|
||||||
|
|
||||||
return getUpdatedCellComponent(value, true, row);
|
return getUpdatedCellComponent(value, true, row);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,62 +277,62 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
|
|||||||
String website = selectedLib.getWebsite();
|
String website = selectedLib.getWebsite();
|
||||||
String sentence = selectedLib.getSentence();
|
String sentence = selectedLib.getSentence();
|
||||||
String paragraph = selectedLib.getParagraph();
|
String paragraph = selectedLib.getParagraph();
|
||||||
String availableVer = selectedLib.getVersion();
|
// String availableVer = selectedLib.getVersion();
|
||||||
String url = selectedLib.getUrl();
|
String url = selectedLib.getUrl();
|
||||||
|
|
||||||
String midcolor = isSelected ? "#000000" : "#888888";
|
String midcolor = isSelected ? "#000000" : "#888888";
|
||||||
|
|
||||||
String desc = "<html><body>";
|
String desc = "<html><body>";
|
||||||
// Library name
|
|
||||||
desc += format("<b><font size=\"+1\">{0}</font></b>", name);
|
|
||||||
|
|
||||||
|
// Library name...
|
||||||
|
desc += format("<b>{0}</b> ", name);
|
||||||
|
if (installedLib != null && installedLib.isReadOnly()) {
|
||||||
|
desc += "Built-In ";
|
||||||
|
}
|
||||||
|
|
||||||
|
// ...author...
|
||||||
desc += format("<font color=\"{0}\">", midcolor);
|
desc += format("<font color=\"{0}\">", midcolor);
|
||||||
|
|
||||||
if (author != null && !author.isEmpty()) {
|
if (author != null && !author.isEmpty()) {
|
||||||
desc += format(" by <a href=\"{0}\">{1}</a>", website, author);
|
desc += format(" by <a href=\"{0}\">{1}</a>", website, author);
|
||||||
}
|
}
|
||||||
desc += "<br />";
|
|
||||||
|
|
||||||
if (sentence != null) {
|
|
||||||
desc += format("<b>{0}</b><br />", sentence);
|
|
||||||
if (paragraph != null && !paragraph.isEmpty())
|
|
||||||
desc += format("{0}<br />", paragraph);
|
|
||||||
desc += "<br />";
|
|
||||||
}
|
|
||||||
|
|
||||||
desc += "</font>"; // close midcolor
|
|
||||||
|
|
||||||
// If the selected lib is available from repository...
|
|
||||||
if (url != null) {
|
|
||||||
desc += format(_("Available version: <b>{0}</b>"), availableVer);
|
|
||||||
removeButton.setText(_("Remove"));
|
|
||||||
} else {
|
|
||||||
removeButton.setText(_("Delete"));
|
|
||||||
}
|
|
||||||
desc += "<br />";
|
|
||||||
|
|
||||||
|
// ...version.
|
||||||
if (installedLib != null) {
|
if (installedLib != null) {
|
||||||
String installedVer = installedLib.getVersion();
|
String installedVer = installedLib.getVersion();
|
||||||
if (installedVer == null)
|
if (installedVer == null)
|
||||||
installedVer = "Legacy";
|
desc += " " + _("Version unknown");
|
||||||
desc += format(_("Installed version: <b>{0}</b>"), installedVer);
|
else
|
||||||
if (installedLib.isReadOnly())
|
desc += " " + format(_("Version <b>{0}</b>"), installedVer);
|
||||||
desc += " " + _("(Bundled)");
|
} else {
|
||||||
|
// not installed...
|
||||||
|
}
|
||||||
|
desc += "</font><br />";
|
||||||
|
|
||||||
|
// Description
|
||||||
|
if (sentence != null) {
|
||||||
|
desc += format("<b>{0}</b> ", sentence);
|
||||||
|
if (paragraph != null && !paragraph.isEmpty())
|
||||||
|
desc += format("{0}", paragraph);
|
||||||
|
desc += "<br />";
|
||||||
}
|
}
|
||||||
desc += "<br />";
|
|
||||||
|
|
||||||
desc += "</body></html>";
|
desc += "</body></html>";
|
||||||
description.setText(desc);
|
description.setText(desc);
|
||||||
description.setBackground(Color.WHITE);
|
description.setBackground(Color.WHITE);
|
||||||
|
|
||||||
|
// If the selected lib is available from repository...
|
||||||
|
if (url != null) {
|
||||||
|
removeButton.setText(_("Remove"));
|
||||||
|
} else {
|
||||||
|
removeButton.setText(_("Delete"));
|
||||||
|
}
|
||||||
|
|
||||||
// for modelToView to work, the text area has to be sized. It doesn't
|
// for modelToView to work, the text area has to be sized. It doesn't
|
||||||
// matter if it's visible or not.
|
// matter if it's visible or not.
|
||||||
|
|
||||||
// See:
|
// See:
|
||||||
// http://stackoverflow.com/questions/3081210/how-to-set-jtextarea-to-have-height-that-matches-the-size-of-a-text-it-contains
|
// http://stackoverflow.com/questions/3081210/how-to-set-jtextarea-to-have-height-that-matches-the-size-of-a-text-it-contains
|
||||||
int width = parentTable.getBounds().width;
|
int width = parentTable.getBounds().width;
|
||||||
width -= installButtonPlaceholder.getPreferredSize().width;
|
|
||||||
width -= removeButtonPlaceholder.getPreferredSize().width;
|
|
||||||
setJTextPaneDimensionToFitContainedText(description, width);
|
setJTextPaneDimensionToFitContainedText(description, width);
|
||||||
|
|
||||||
if (isSelected) {
|
if (isSelected) {
|
||||||
@ -254,8 +346,27 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
|
|||||||
return panel;
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Timer enabler = new Timer(100, new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
enable(true);
|
||||||
|
enabler.stop();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setEnabled(boolean enabled) {
|
public void setEnabled(boolean enabled) {
|
||||||
|
enable(false);
|
||||||
|
if (enabled) {
|
||||||
|
enabler.start();
|
||||||
|
} else {
|
||||||
|
enabler.stop();
|
||||||
|
}
|
||||||
|
buttonsPanel.setVisible(enabled);
|
||||||
|
inactiveButtonsPanel.setVisible(!enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void enable(boolean enabled) {
|
||||||
installButton.setEnabled(enabled);
|
installButton.setEnabled(enabled);
|
||||||
removeButton.setEnabled(enabled);
|
removeButton.setEnabled(enabled);
|
||||||
}
|
}
|
||||||
|
@ -155,7 +155,8 @@ public class LibraryManagerUI extends InstallerJDialog {
|
|||||||
try {
|
try {
|
||||||
setProgressVisible(true, _("Installing..."));
|
setProgressVisible(true, _("Installing..."));
|
||||||
installer.install(lib);
|
installer.install(lib);
|
||||||
getContribModel().updateLibrary(lib);
|
onIndexesUpdated(); // TODO: Do a better job in refreshing only the needed element
|
||||||
|
//getContribModel().updateLibrary(lib);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -173,7 +174,8 @@ public class LibraryManagerUI extends InstallerJDialog {
|
|||||||
try {
|
try {
|
||||||
setProgressVisible(true, _("Removing..."));
|
setProgressVisible(true, _("Removing..."));
|
||||||
installer.remove(lib);
|
installer.remove(lib);
|
||||||
getContribModel().updateLibrary(lib);
|
onIndexesUpdated(); // TODO: Do a better job in refreshing only the needed element
|
||||||
|
//getContribModel().updateLibrary(lib);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -284,7 +284,10 @@ public class ContributedPlatformTableCell extends InstallerTableCell {
|
|||||||
desc = desc.substring(0, desc.lastIndexOf(',')) + ".<br />";
|
desc = desc.substring(0, desc.lastIndexOf(',')) + ".<br />";
|
||||||
desc += "</body></html>";
|
desc += "</body></html>";
|
||||||
description.setText(desc);
|
description.setText(desc);
|
||||||
description.setBackground(Color.WHITE);
|
//description.setBackground(Color.WHITE);
|
||||||
|
|
||||||
|
int width = parentTable.getBounds().width;
|
||||||
|
setJTextPaneDimensionToFitContainedText(description, width);
|
||||||
|
|
||||||
if (isSelected) {
|
if (isSelected) {
|
||||||
panel.setBackground(parentTable.getSelectionBackground());
|
panel.setBackground(parentTable.getSelectionBackground());
|
||||||
@ -294,9 +297,6 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ public abstract class InstallerTableCell extends AbstractCellEditor implements T
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Rectangle r = jTextPane.modelToView(jTextPane.getDocument().getLength());
|
Rectangle r = jTextPane.modelToView(jTextPane.getDocument().getLength());
|
||||||
r.height += jTextPane.modelToView(0).y; // add margins
|
//r.height += jTextPane.modelToView(0).y; // add margins
|
||||||
Dimension d = new Dimension(minimumDimension.width, r.y + r.height);
|
Dimension d = new Dimension(minimumDimension.width, r.y + r.height);
|
||||||
jTextPane.setPreferredSize(d);
|
jTextPane.setPreferredSize(d);
|
||||||
} catch (BadLocationException e) {
|
} catch (BadLocationException e) {
|
||||||
|
@ -109,6 +109,10 @@ public abstract class ContributedLibrary extends DownloadableContribution {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
return getVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String info() {
|
||||||
String res = "";
|
String res = "";
|
||||||
res += " ContributedLibrary : " + getName() + "\n";
|
res += " ContributedLibrary : " + getName() + "\n";
|
||||||
res += " author : " + getAuthor() + "\n";
|
res += " author : " + getAuthor() + "\n";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user