mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-16 11:21:18 +03:00
Cores Installer UI refactor (WIP)
This commit is contained in:
committed by
Federico Fissore
parent
56b9fd7d93
commit
1f564d6709
@ -28,6 +28,8 @@
|
|||||||
*/
|
*/
|
||||||
package cc.arduino.libraries.contributions.ui;
|
package cc.arduino.libraries.contributions.ui;
|
||||||
|
|
||||||
|
import static processing.app.I18n._;
|
||||||
|
|
||||||
import java.awt.Dialog;
|
import java.awt.Dialog;
|
||||||
import java.awt.Frame;
|
import java.awt.Frame;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -133,13 +135,13 @@ public class LibraryManagerUI extends InstallerJDialog {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
setProgressVisible(true);
|
setProgressVisible(true, "");
|
||||||
installer.updateIndex();
|
installer.updateIndex();
|
||||||
onIndexesUpdated();
|
onIndexesUpdated();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
} finally {
|
||||||
setProgressVisible(false);
|
setProgressVisible(false, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -151,13 +153,13 @@ public class LibraryManagerUI extends InstallerJDialog {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
setProgressVisible(true);
|
setProgressVisible(true, _("Installing..."));
|
||||||
installer.install(lib);
|
installer.install(lib);
|
||||||
getContribModel().updateLibrary(lib);
|
getContribModel().updateLibrary(lib);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
} finally {
|
||||||
setProgressVisible(false);
|
setProgressVisible(false, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -169,13 +171,13 @@ public class LibraryManagerUI extends InstallerJDialog {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
setProgressVisible(true);
|
setProgressVisible(true, _("Removing..."));
|
||||||
installer.remove(lib);
|
installer.remove(lib);
|
||||||
getContribModel().updateLibrary(lib);
|
getContribModel().updateLibrary(lib);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
} finally {
|
||||||
setProgressVisible(false);
|
setProgressVisible(false, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -33,17 +33,21 @@ import static processing.app.I18n.format;
|
|||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Dimension;
|
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
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.ItemListener;
|
||||||
|
|
||||||
import javax.swing.Box;
|
import javax.swing.Box;
|
||||||
import javax.swing.BoxLayout;
|
import javax.swing.BoxLayout;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JComboBox;
|
||||||
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JTable;
|
import javax.swing.JTable;
|
||||||
import javax.swing.JTextPane;
|
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;
|
||||||
@ -62,9 +66,16 @@ public class ContributedPlatformTableCell extends InstallerTableCell {
|
|||||||
|
|
||||||
private JPanel panel;
|
private JPanel panel;
|
||||||
private JTextPane description;
|
private JTextPane description;
|
||||||
|
|
||||||
|
private JPanel buttonsPanel;
|
||||||
private JButton installButton;
|
private JButton installButton;
|
||||||
|
private JComboBox downgradeChooser;
|
||||||
|
private JButton downgradeButton;
|
||||||
private JButton removeButton;
|
private JButton removeButton;
|
||||||
private Component removeButtonPlaceholder;
|
private Component removeButtonStrut;
|
||||||
|
|
||||||
|
private JPanel inactiveButtonsPanel;
|
||||||
|
private JLabel statusLabel;
|
||||||
|
|
||||||
public ContributedPlatformTableCell() {
|
public ContributedPlatformTableCell() {
|
||||||
description = new JTextPane();
|
description = new JTextPane();
|
||||||
@ -110,19 +121,74 @@ public class ContributedPlatformTableCell extends InstallerTableCell {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
int width = removeButton.getPreferredSize().width;
|
downgradeButton = new JButton(_("Install"));
|
||||||
removeButtonPlaceholder = Box.createRigidArea(new Dimension(width, 1));
|
downgradeButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
ContributedPlatform selected;
|
||||||
|
selected = (ContributedPlatform) 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(Box.createHorizontalStrut(5));
|
buttonsPanel = new JPanel();
|
||||||
panel.add(removeButton);
|
buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS));
|
||||||
panel.add(removeButtonPlaceholder);
|
buttonsPanel.setOpaque(false);
|
||||||
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 h = installButton.getMinimumSize().height;
|
||||||
|
inactiveButtonsPanel.add(Box.createVerticalStrut(h));
|
||||||
|
inactiveButtonsPanel.add(Box.createGlue());
|
||||||
|
|
||||||
|
statusLabel = new JLabel(" ");
|
||||||
|
inactiveButtonsPanel.add(statusLabel);
|
||||||
|
|
||||||
|
inactiveButtonsPanel.add(Box.createGlue());
|
||||||
|
inactiveButtonsPanel.add(Box.createVerticalStrut(h));
|
||||||
|
|
||||||
|
panel.add(inactiveButtonsPanel);
|
||||||
|
}
|
||||||
|
|
||||||
|
panel.add(Box.createVerticalStrut(10));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onRemove(ContributedPlatform contributedPlatform) {
|
protected void onRemove(ContributedPlatform contributedPlatform) {
|
||||||
@ -138,6 +204,8 @@ public class ContributedPlatformTableCell extends InstallerTableCell {
|
|||||||
boolean hasFocus, int row,
|
boolean hasFocus, int row,
|
||||||
int column) {
|
int column) {
|
||||||
parentTable = table;
|
parentTable = table;
|
||||||
|
setEnabled(false);
|
||||||
|
|
||||||
Component panel = getUpdatedCellComponent(value, isSelected, row);
|
Component panel = getUpdatedCellComponent(value, isSelected, row);
|
||||||
return panel;
|
return panel;
|
||||||
}
|
}
|
||||||
@ -156,6 +224,20 @@ public class ContributedPlatformTableCell extends InstallerTableCell {
|
|||||||
int column) {
|
int column) {
|
||||||
parentTable = table;
|
parentTable = table;
|
||||||
editorValue = (ContributedPlatformReleases) value;
|
editorValue = (ContributedPlatformReleases) value;
|
||||||
|
setEnabled(true);
|
||||||
|
|
||||||
|
downgradeChooser.removeAllItems();
|
||||||
|
downgradeChooser.addItem(_("Select version"));
|
||||||
|
boolean visible = false;
|
||||||
|
for (ContributedPlatform 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,30 +265,24 @@ public class ContributedPlatformTableCell extends InstallerTableCell {
|
|||||||
installButton.setVisible(installable || upgradable);
|
installButton.setVisible(installable || upgradable);
|
||||||
|
|
||||||
removeButton.setVisible(removable);
|
removeButton.setVisible(removable);
|
||||||
removeButtonPlaceholder.setVisible(!removable);
|
removeButtonStrut.setVisible(removable);
|
||||||
|
|
||||||
String desc = "<html><body>";
|
String desc = "<html><body>";
|
||||||
desc += "<b>" + selectedPlatform.getName() + "</b>";
|
desc += "<b>" + selectedPlatform.getName() + "</b>";
|
||||||
String author = selectedPlatform.getParentPackage().getMaintainer();
|
String author = selectedPlatform.getParentPackage().getMaintainer();
|
||||||
String url = selectedPlatform.getParentPackage().getWebsiteURL();
|
String url = selectedPlatform.getParentPackage().getWebsiteURL();
|
||||||
if (author != null && !author.isEmpty()) {
|
if (author != null && !author.isEmpty()) {
|
||||||
desc += format(" by <a href=\"{0}\">{1}</a>", url, author);
|
desc += " " + format("by <a href=\"{0}\">{1}</a>", url, author);
|
||||||
|
}
|
||||||
|
if (removable) {
|
||||||
|
desc += " " + format(_("version <b>{0}</b>"), installedPlatform.getVersion());
|
||||||
}
|
}
|
||||||
desc += "<br />";
|
|
||||||
desc += "<br />";
|
desc += "<br />";
|
||||||
|
|
||||||
desc += _("Boards contributed in this package:") + "<br />";
|
desc += _("Boards included in this package:") + "<br />";
|
||||||
for (ContributedBoard board : selectedPlatform.getBoards())
|
for (ContributedBoard board : selectedPlatform.getBoards())
|
||||||
desc += format("- {0}<br />", board.getName());
|
desc += format("{0}, ", board.getName());
|
||||||
desc += "<br />";
|
desc = desc.substring(0, desc.lastIndexOf(',')) + ".<br />";
|
||||||
desc += format(_("Available version: <b>{0}</b>"),
|
|
||||||
selectedPlatform.getVersion());
|
|
||||||
desc += "<br />";
|
|
||||||
if (removable) {
|
|
||||||
desc += format(_("Installed version: <b>{0}</b>"),
|
|
||||||
installedPlatform.getVersion());
|
|
||||||
}
|
|
||||||
desc += "<br />";
|
|
||||||
desc += "</body></html>";
|
desc += "</body></html>";
|
||||||
description.setText(desc);
|
description.setText(desc);
|
||||||
description.setBackground(Color.WHITE);
|
description.setBackground(Color.WHITE);
|
||||||
@ -222,12 +298,33 @@ public class ContributedPlatformTableCell 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();
|
||||||
|
}
|
||||||
|
buttonsPanel.setVisible(enabled);
|
||||||
|
inactiveButtonsPanel.setVisible(!enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void enable(boolean enabled) {
|
||||||
installButton.setEnabled(enabled);
|
installButton.setEnabled(enabled);
|
||||||
removeButton.setEnabled(enabled);
|
removeButton.setEnabled(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setStatus(String status) {
|
||||||
|
statusLabel.setText(status);
|
||||||
|
}
|
||||||
|
|
||||||
public void invalidate() {
|
public void invalidate() {
|
||||||
panel.invalidate();
|
panel.invalidate();
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
*/
|
*/
|
||||||
package cc.arduino.packages.contributions.ui;
|
package cc.arduino.packages.contributions.ui;
|
||||||
|
|
||||||
|
import static processing.app.I18n._;
|
||||||
import cc.arduino.packages.contributions.ContributedPlatform;
|
import cc.arduino.packages.contributions.ContributedPlatform;
|
||||||
import cc.arduino.packages.contributions.ContributionInstaller;
|
import cc.arduino.packages.contributions.ContributionInstaller;
|
||||||
import cc.arduino.packages.contributions.ContributionsIndexer;
|
import cc.arduino.packages.contributions.ContributionsIndexer;
|
||||||
@ -132,13 +133,13 @@ public class ContributionManagerUI extends InstallerJDialog {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
setProgressVisible(true);
|
setProgressVisible(true, "");
|
||||||
installer.updateIndex();
|
installer.updateIndex();
|
||||||
onIndexesUpdated();
|
onIndexesUpdated();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
} finally {
|
||||||
setProgressVisible(false);
|
setProgressVisible(false, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -151,7 +152,7 @@ public class ContributionManagerUI extends InstallerJDialog {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
setProgressVisible(true);
|
setProgressVisible(true, _("Installing..."));
|
||||||
installer.install(platformToInstall);
|
installer.install(platformToInstall);
|
||||||
if (platformToRemove != null) {
|
if (platformToRemove != null) {
|
||||||
installer.remove(platformToRemove);
|
installer.remove(platformToRemove);
|
||||||
@ -159,7 +160,7 @@ public class ContributionManagerUI extends InstallerJDialog {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
} finally {
|
||||||
setProgressVisible(false);
|
setProgressVisible(false, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -172,12 +173,12 @@ public class ContributionManagerUI extends InstallerJDialog {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
setProgressVisible(true);
|
setProgressVisible(true, _("Removing..."));
|
||||||
installer.remove(platform);
|
installer.remove(platform);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
} finally {
|
||||||
setProgressVisible(false);
|
setProgressVisible(false, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -205,7 +205,7 @@ public abstract class InstallerJDialog extends JDialog {
|
|||||||
progressPanel.add(updateBox);
|
progressPanel.add(updateBox);
|
||||||
pane.add(progressPanel, BorderLayout.SOUTH);
|
pane.add(progressPanel, BorderLayout.SOUTH);
|
||||||
}
|
}
|
||||||
setProgressVisible(false);
|
setProgressVisible(false, "");
|
||||||
|
|
||||||
setMinimumSize(new Dimension(600, 450));
|
setMinimumSize(new Dimension(600, 450));
|
||||||
|
|
||||||
@ -219,7 +219,7 @@ public abstract class InstallerJDialog extends JDialog {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProgressVisible(boolean visible) {
|
public void setProgressVisible(boolean visible, String status) {
|
||||||
progressBox.setVisible(visible);
|
progressBox.setVisible(visible);
|
||||||
|
|
||||||
filterField.setEnabled(!visible);
|
filterField.setEnabled(!visible);
|
||||||
@ -228,7 +228,8 @@ public abstract class InstallerJDialog extends JDialog {
|
|||||||
updateBox.setVisible(!visible);
|
updateBox.setVisible(!visible);
|
||||||
updateBox.setEnabled(!visible);
|
updateBox.setEnabled(!visible);
|
||||||
cellEditor.setEnabled(!visible);
|
cellEditor.setEnabled(!visible);
|
||||||
|
cellEditor.setStatus(status);
|
||||||
|
|
||||||
if (visible && contribTable.isEditing()) {
|
if (visible && contribTable.isEditing()) {
|
||||||
TableCellEditor editor = contribTable.getCellEditor();
|
TableCellEditor editor = contribTable.getCellEditor();
|
||||||
if (editor != null)
|
if (editor != null)
|
||||||
|
@ -39,4 +39,8 @@ public abstract class InstallerTableCell extends AbstractCellEditor implements
|
|||||||
// Empty
|
// Empty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setStatus(String s) {
|
||||||
|
// Empty
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -87,4 +87,8 @@ public abstract class ContributedPlatform extends DownloadableContribution {
|
|||||||
this.parentPackage = parentPackage;
|
this.parentPackage = parentPackage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return getVersion();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user