mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-17 06:52:18 +01:00
Applying code inspection suggestions
This commit is contained in:
parent
dae6e4fff7
commit
03a66b1035
@ -34,7 +34,6 @@ import cc.arduino.contributions.filters.InstalledPredicate;
|
||||
import cc.arduino.contributions.packages.ContributedPackage;
|
||||
import cc.arduino.contributions.packages.ContributedPlatform;
|
||||
import cc.arduino.view.Event;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
@ -73,12 +72,7 @@ public class BuiltInCoreIsNewerCheck implements Runnable {
|
||||
return;
|
||||
}
|
||||
|
||||
LinkedList<ContributedPlatform> contributedPlatforms = Lists.newLinkedList(Iterables.concat(Collections2.transform(BaseNoGui.indexer.getPackages(), new Function<ContributedPackage, List<ContributedPlatform>>() {
|
||||
@Override
|
||||
public List<ContributedPlatform> apply(ContributedPackage input) {
|
||||
return input.getPlatforms();
|
||||
}
|
||||
})));
|
||||
LinkedList<ContributedPlatform> contributedPlatforms = Lists.newLinkedList(Iterables.concat(Collections2.transform(BaseNoGui.indexer.getPackages(), ContributedPackage::getPlatforms)));
|
||||
|
||||
List<ContributedPlatform> installedBuiltInPlatforms = contributedPlatforms.stream().filter(new InstalledPredicate()).filter(new BuiltInPredicate()).collect(Collectors.toList());
|
||||
if (installedBuiltInPlatforms.size() != 1) {
|
||||
@ -96,18 +90,15 @@ public class BuiltInCoreIsNewerCheck implements Runnable {
|
||||
}
|
||||
|
||||
if (VersionHelper.valueOf(installedBuiltIn.getParsedVersion()).greaterThan(VersionHelper.valueOf(installedNotBuiltIn.getParsedVersion()))) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PreferencesData.setInteger("builtin_platform_is_newer", BaseNoGui.REVISION);
|
||||
assert base.hasActiveEditor();
|
||||
int chosenOption = JOptionPane.showConfirmDialog(base.getActiveEditor(), I18n.format(_("The IDE includes an updated {0} package, but you're using an older one.\nDo you want to upgrade {0}?"), installedBuiltIn.getName()), I18n.format(_("A newer {0} package is available"), installedBuiltIn.getName()), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
||||
if (chosenOption == JOptionPane.YES_OPTION) {
|
||||
Action openBoardsManager = base.getOpenBoardsManager();
|
||||
Event event = new Event(base.getActiveEditor(), ActionEvent.ACTION_PERFORMED, installedBuiltIn.getName());
|
||||
event.getPayload().put("filterText", installedBuiltIn.getName());
|
||||
openBoardsManager.actionPerformed(event);
|
||||
}
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
PreferencesData.setInteger("builtin_platform_is_newer", BaseNoGui.REVISION);
|
||||
assert base.hasActiveEditor();
|
||||
int chosenOption = JOptionPane.showConfirmDialog(base.getActiveEditor(), I18n.format(_("The IDE includes an updated {0} package, but you're using an older one.\nDo you want to upgrade {0}?"), installedBuiltIn.getName()), I18n.format(_("A newer {0} package is available"), installedBuiltIn.getName()), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
||||
if (chosenOption == JOptionPane.YES_OPTION) {
|
||||
Action openBoardsManager = base.getOpenBoardsManager();
|
||||
Event event = new Event(base.getActiveEditor(), ActionEvent.ACTION_PERFORMED, installedBuiltIn.getName());
|
||||
event.getPayload().put("filterText", installedBuiltIn.getName());
|
||||
openBoardsManager.actionPerformed(event);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -29,7 +29,6 @@
|
||||
|
||||
package cc.arduino.contributions.libraries.ui;
|
||||
|
||||
import cc.arduino.contributions.DownloadableContribution;
|
||||
import cc.arduino.contributions.DownloadableContributionVersionComparator;
|
||||
import cc.arduino.contributions.VersionComparator;
|
||||
import cc.arduino.contributions.filters.BuiltInPredicate;
|
||||
@ -39,22 +38,18 @@ import cc.arduino.contributions.libraries.filters.OnlyUpstreamReleasePredicate;
|
||||
import cc.arduino.contributions.ui.InstallerTableCell;
|
||||
import cc.arduino.contributions.ui.listeners.DelegatingKeyListener;
|
||||
import cc.arduino.utils.ReverseComparator;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Lists;
|
||||
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 java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@ -65,59 +60,43 @@ import static processing.app.I18n.format;
|
||||
@SuppressWarnings("serial")
|
||||
public class ContributedLibraryTableCell extends InstallerTableCell {
|
||||
|
||||
private JPanel panel;
|
||||
private JButton installButton;
|
||||
private Component installButtonPlaceholder;
|
||||
private final JPanel panel;
|
||||
private final JButton installButton;
|
||||
private final Component installButtonPlaceholder;
|
||||
private JComboBox downgradeChooser;
|
||||
private JComboBox versionToInstallChooser;
|
||||
private JButton downgradeButton;
|
||||
private JPanel buttonsPanel;
|
||||
private JPanel inactiveButtonsPanel;
|
||||
private JLabel statusLabel;
|
||||
private final JComboBox versionToInstallChooser;
|
||||
private final JButton downgradeButton;
|
||||
private final JPanel buttonsPanel;
|
||||
private final JPanel inactiveButtonsPanel;
|
||||
private final JLabel statusLabel;
|
||||
|
||||
public ContributedLibraryTableCell() {
|
||||
{
|
||||
installButton = new JButton(_("Install"));
|
||||
installButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onInstall(editorValue.getSelected(), editorValue.getInstalled());
|
||||
}
|
||||
});
|
||||
installButton.addActionListener(e -> onInstall(editorValue.getSelected(), editorValue.getInstalled()));
|
||||
int width = installButton.getPreferredSize().width;
|
||||
installButtonPlaceholder = Box.createRigidArea(new Dimension(width, 1));
|
||||
}
|
||||
|
||||
downgradeButton = new JButton(_("Install"));
|
||||
downgradeButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ContributedLibrary selected = (ContributedLibrary) downgradeChooser.getSelectedItem();
|
||||
onInstall(selected, editorValue.getInstalled());
|
||||
}
|
||||
downgradeButton.addActionListener(e -> {
|
||||
ContributedLibrary 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);
|
||||
}
|
||||
downgradeChooser.addItemListener(e -> {
|
||||
Object selectVersionItem = downgradeChooser.getItemAt(0);
|
||||
boolean disableDowngrade = (e.getItem() == selectVersionItem);
|
||||
downgradeButton.setEnabled(!disableDowngrade);
|
||||
});
|
||||
|
||||
versionToInstallChooser = new JComboBox();
|
||||
versionToInstallChooser.addItem("-");
|
||||
versionToInstallChooser.setMaximumSize(versionToInstallChooser.getPreferredSize());
|
||||
versionToInstallChooser.addItemListener(new ItemListener() {
|
||||
@Override
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
editorValue.select((ContributedLibrary) versionToInstallChooser.getSelectedItem());
|
||||
}
|
||||
});
|
||||
versionToInstallChooser.addItemListener(e -> editorValue.select((ContributedLibrary) versionToInstallChooser.getSelectedItem()));
|
||||
|
||||
panel = new JPanel();
|
||||
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
||||
@ -186,12 +165,9 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
|
||||
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());
|
||||
}
|
||||
description.addHyperlinkListener(e -> {
|
||||
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
|
||||
Base.openURL(e.getDescription());
|
||||
}
|
||||
});
|
||||
description.addKeyListener(new DelegatingKeyListener(parentTable));
|
||||
@ -255,7 +231,7 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
|
||||
uninstalledReleases.addAll(installedBuiltIn);
|
||||
}
|
||||
|
||||
Collections.sort(uninstalledReleases, new ReverseComparator<DownloadableContribution>(new DownloadableContributionVersionComparator()));
|
||||
Collections.sort(uninstalledReleases, new ReverseComparator<>(new DownloadableContributionVersionComparator()));
|
||||
|
||||
downgradeChooser.removeAllItems();
|
||||
downgradeChooser.addItem(_("Select version"));
|
||||
@ -264,32 +240,23 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
|
||||
final List<ContributedLibrary> uninstalledNewerReleases = Lists.newLinkedList();
|
||||
|
||||
final VersionComparator versionComparator = new VersionComparator();
|
||||
Lists.newLinkedList(Lists.transform(uninstalledReleases, new Function<ContributedLibrary, ContributedLibrary>() {
|
||||
@Override
|
||||
public ContributedLibrary apply(ContributedLibrary input) {
|
||||
if (installed == null || versionComparator.greaterThan(installed.getParsedVersion(), input.getParsedVersion())) {
|
||||
uninstalledPreviousReleases.add(input);
|
||||
} else {
|
||||
uninstalledNewerReleases.add(input);
|
||||
}
|
||||
|
||||
return input;
|
||||
Lists.newLinkedList(Lists.transform(uninstalledReleases, input -> {
|
||||
if (installed == null || versionComparator.greaterThan(installed.getParsedVersion(), input.getParsedVersion())) {
|
||||
uninstalledPreviousReleases.add(input);
|
||||
} else {
|
||||
uninstalledNewerReleases.add(input);
|
||||
}
|
||||
|
||||
return input;
|
||||
}));
|
||||
for (ContributedLibrary release : uninstalledNewerReleases) {
|
||||
downgradeChooser.addItem(release);
|
||||
}
|
||||
for (ContributedLibrary release : uninstalledPreviousReleases) {
|
||||
downgradeChooser.addItem(release);
|
||||
}
|
||||
uninstalledNewerReleases.forEach(downgradeChooser::addItem);
|
||||
uninstalledPreviousReleases.forEach(downgradeChooser::addItem);
|
||||
|
||||
downgradeChooser.setVisible(installed != null && (!uninstalledPreviousReleases.isEmpty() || uninstalledNewerReleases.size() > 1));
|
||||
downgradeButton.setVisible(installed != null && (!uninstalledPreviousReleases.isEmpty() || uninstalledNewerReleases.size() > 1));
|
||||
|
||||
versionToInstallChooser.removeAllItems();
|
||||
for (ContributedLibrary release : uninstalledReleases) {
|
||||
versionToInstallChooser.addItem(release);
|
||||
}
|
||||
uninstalledReleases.forEach(versionToInstallChooser::addItem);
|
||||
versionToInstallChooser.setVisible(installed == null && uninstalledReleases.size() > 1);
|
||||
|
||||
Component component = getUpdatedCellComponent(value, true, row, !installedBuiltIn.isEmpty());
|
||||
@ -310,14 +277,12 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
|
||||
ContributedLibrary selected = releases.getSelected();
|
||||
ContributedLibrary installed = releases.getInstalled();
|
||||
|
||||
boolean removable, installable, upgradable;
|
||||
boolean installable, upgradable;
|
||||
if (installed == null) {
|
||||
installable = true;
|
||||
removable = false;
|
||||
upgradable = false;
|
||||
} else {
|
||||
installable = false;
|
||||
removable = !installed.isReadOnly() && !hasBuiltInRelease;
|
||||
upgradable = new DownloadableContributionVersionComparator().compare(selected, installed) > 0;
|
||||
}
|
||||
if (installable) {
|
||||
@ -405,7 +370,7 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
|
||||
return panel;
|
||||
}
|
||||
|
||||
private Timer enabler = new Timer(100, new ActionListener() {
|
||||
private final Timer enabler = new Timer(100, new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
enable(true);
|
||||
|
@ -59,8 +59,8 @@ public class LibrariesIndexTableModel extends FilteredAbstractTableModel<Contrib
|
||||
|
||||
public ContributedLibraryReleases(ContributedLibrary library) {
|
||||
this.name = library.getName();
|
||||
this.versions = new LinkedList<String>();
|
||||
this.releases = new LinkedList<ContributedLibrary>();
|
||||
this.versions = new LinkedList<>();
|
||||
this.releases = new LinkedList<>();
|
||||
this.selected = null;
|
||||
add(library);
|
||||
}
|
||||
@ -112,7 +112,7 @@ public class LibrariesIndexTableModel extends FilteredAbstractTableModel<Contrib
|
||||
}
|
||||
}
|
||||
|
||||
private final List<ContributedLibraryReleases> contributions = new ArrayList<ContributedLibraryReleases>();
|
||||
private final List<ContributedLibraryReleases> contributions = new ArrayList<>();
|
||||
|
||||
private final String[] columnNames = {"Description"};
|
||||
|
||||
@ -267,12 +267,8 @@ public class LibrariesIndexTableModel extends FilteredAbstractTableModel<Contrib
|
||||
|
||||
private void updateContributions() {
|
||||
contributions.clear();
|
||||
for (ContributedLibrary l : indexer.getIndex().getLibraries()) {
|
||||
applyFilterToLibrary(l);
|
||||
}
|
||||
for (ContributedLibrary l : indexer.getInstalledLibraries()) {
|
||||
applyFilterToLibrary(l);
|
||||
}
|
||||
indexer.getIndex().getLibraries().forEach(this::applyFilterToLibrary);
|
||||
indexer.getInstalledLibraries().forEach(this::applyFilterToLibrary);
|
||||
Collections.sort(contributions);
|
||||
}
|
||||
|
||||
|
@ -167,7 +167,7 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibrary> {
|
||||
typeChooser.addItem(new DropdownAllItem());
|
||||
typeChooser.addItem(new DropdownUpdatableLibrariesItem(indexer));
|
||||
typeChooser.addItem(new DropdownInstalledLibraryItem(indexer.getIndex()));
|
||||
java.util.List<String> types = new LinkedList<String>(indexer.getIndex().getTypes());
|
||||
java.util.List<String> types = new LinkedList<>(indexer.getIndex().getTypes());
|
||||
Collections.sort(types, new LibraryTypeComparator());
|
||||
for (String type : types) {
|
||||
typeChooser.addItem(new DropdownLibraryOfTypeItem(type));
|
||||
@ -217,18 +217,15 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibrary> {
|
||||
@Override
|
||||
protected void onUpdatePressed() {
|
||||
super.onUpdatePressed();
|
||||
installerThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
setProgressVisible(true, "");
|
||||
installer.updateIndex();
|
||||
onIndexesUpdated();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
setProgressVisible(false, "");
|
||||
}
|
||||
installerThread = new Thread(() -> {
|
||||
try {
|
||||
setProgressVisible(true, "");
|
||||
installer.updateIndex();
|
||||
onIndexesUpdated();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
setProgressVisible(false, "");
|
||||
}
|
||||
});
|
||||
installerThread.setUncaughtExceptionHandler(new InstallerJDialogUncaughtExceptionHandler(this, noConnectionErrorMessage));
|
||||
@ -237,19 +234,16 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibrary> {
|
||||
|
||||
public void onInstallPressed(final ContributedLibrary lib, final ContributedLibrary replaced) {
|
||||
clearErrorMessage();
|
||||
installerThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
setProgressVisible(true, _("Installing..."));
|
||||
installer.install(lib, replaced);
|
||||
onIndexesUpdated(); // TODO: Do a better job in refreshing only the needed element
|
||||
//getContribModel().updateLibrary(lib);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
setProgressVisible(false, "");
|
||||
}
|
||||
installerThread = new Thread(() -> {
|
||||
try {
|
||||
setProgressVisible(true, _("Installing..."));
|
||||
installer.install(lib, replaced);
|
||||
onIndexesUpdated(); // TODO: Do a better job in refreshing only the needed element
|
||||
//getContribModel().updateLibrary(lib);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
setProgressVisible(false, "");
|
||||
}
|
||||
});
|
||||
installerThread.setUncaughtExceptionHandler(new InstallerJDialogUncaughtExceptionHandler(this, noConnectionErrorMessage));
|
||||
@ -267,19 +261,16 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibrary> {
|
||||
}
|
||||
|
||||
clearErrorMessage();
|
||||
installerThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
setProgressVisible(true, _("Removing..."));
|
||||
installer.remove(lib);
|
||||
onIndexesUpdated(); // TODO: Do a better job in refreshing only the needed element
|
||||
//getContribModel().updateLibrary(lib);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
setProgressVisible(false, "");
|
||||
}
|
||||
installerThread = new Thread(() -> {
|
||||
try {
|
||||
setProgressVisible(true, _("Removing..."));
|
||||
installer.remove(lib);
|
||||
onIndexesUpdated(); // TODO: Do a better job in refreshing only the needed element
|
||||
//getContribModel().updateLibrary(lib);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
setProgressVisible(false, "");
|
||||
}
|
||||
});
|
||||
installerThread.setUncaughtExceptionHandler(new InstallerJDialogUncaughtExceptionHandler(this, noConnectionErrorMessage));
|
||||
|
@ -29,7 +29,6 @@
|
||||
|
||||
package cc.arduino.contributions.packages.ui;
|
||||
|
||||
import cc.arduino.contributions.DownloadableContribution;
|
||||
import cc.arduino.contributions.DownloadableContributionVersionComparator;
|
||||
import cc.arduino.contributions.VersionComparator;
|
||||
import cc.arduino.contributions.filters.BuiltInPredicate;
|
||||
@ -40,22 +39,18 @@ import cc.arduino.contributions.packages.ContributedPlatform;
|
||||
import cc.arduino.contributions.ui.InstallerTableCell;
|
||||
import cc.arduino.contributions.ui.listeners.DelegatingKeyListener;
|
||||
import cc.arduino.utils.ReverseComparator;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Lists;
|
||||
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 java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.stream.Collectors;
|
||||
@ -66,73 +61,52 @@ import static processing.app.I18n.format;
|
||||
@SuppressWarnings("serial")
|
||||
public class ContributedPlatformTableCell extends InstallerTableCell {
|
||||
|
||||
private JPanel panel;
|
||||
private JButton installButton;
|
||||
private JButton removeButton;
|
||||
private Component removeButtonPlaceholder;
|
||||
private Component installButtonPlaceholder;
|
||||
private final JPanel panel;
|
||||
private final JButton installButton;
|
||||
private final JButton removeButton;
|
||||
private final Component removeButtonPlaceholder;
|
||||
private final Component installButtonPlaceholder;
|
||||
private JComboBox downgradeChooser;
|
||||
private JComboBox versionToInstallChooser;
|
||||
private JButton downgradeButton;
|
||||
private JPanel buttonsPanel;
|
||||
private JPanel inactiveButtonsPanel;
|
||||
private JLabel statusLabel;
|
||||
private final JComboBox versionToInstallChooser;
|
||||
private final JButton downgradeButton;
|
||||
private final JPanel buttonsPanel;
|
||||
private final JPanel inactiveButtonsPanel;
|
||||
private final JLabel statusLabel;
|
||||
|
||||
public ContributedPlatformTableCell() {
|
||||
{
|
||||
installButton = new JButton(_("Install"));
|
||||
installButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onInstall(editorValue.getSelected(), editorValue.getInstalled());
|
||||
}
|
||||
});
|
||||
installButton.addActionListener(e -> onInstall(editorValue.getSelected(), editorValue.getInstalled()));
|
||||
int width = installButton.getPreferredSize().width;
|
||||
installButtonPlaceholder = Box.createRigidArea(new Dimension(width, 1));
|
||||
}
|
||||
|
||||
{
|
||||
removeButton = new JButton(_("Remove"));
|
||||
removeButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onRemove(editorValue.getInstalled());
|
||||
}
|
||||
});
|
||||
removeButton.addActionListener(e -> onRemove(editorValue.getInstalled()));
|
||||
int width = removeButton.getPreferredSize().width;
|
||||
removeButtonPlaceholder = Box.createRigidArea(new Dimension(width, 1));
|
||||
}
|
||||
|
||||
downgradeButton = new JButton(_("Install"));
|
||||
downgradeButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ContributedPlatform selected = (ContributedPlatform) downgradeChooser.getSelectedItem();
|
||||
onInstall(selected, editorValue.getInstalled());
|
||||
}
|
||||
downgradeButton.addActionListener(e -> {
|
||||
ContributedPlatform 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);
|
||||
}
|
||||
downgradeChooser.addItemListener(e -> {
|
||||
Object selectVersionItem = downgradeChooser.getItemAt(0);
|
||||
boolean disableDowngrade = (e.getItem() == selectVersionItem);
|
||||
downgradeButton.setEnabled(!disableDowngrade);
|
||||
});
|
||||
|
||||
versionToInstallChooser = new JComboBox();
|
||||
versionToInstallChooser.addItem("-");
|
||||
versionToInstallChooser.setMaximumSize(versionToInstallChooser.getPreferredSize());
|
||||
versionToInstallChooser.addItemListener(new ItemListener() {
|
||||
@Override
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
editorValue.select((ContributedPlatform) versionToInstallChooser.getSelectedItem());
|
||||
}
|
||||
});
|
||||
versionToInstallChooser.addItemListener(e -> editorValue.select((ContributedPlatform) versionToInstallChooser.getSelectedItem()));
|
||||
|
||||
panel = new JPanel();
|
||||
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
||||
@ -203,12 +177,9 @@ public class ContributedPlatformTableCell extends InstallerTableCell {
|
||||
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());
|
||||
}
|
||||
description.addHyperlinkListener(e -> {
|
||||
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
|
||||
Base.openURL(e.getDescription());
|
||||
}
|
||||
});
|
||||
description.addKeyListener(new DelegatingKeyListener(parentTable));
|
||||
@ -263,7 +234,7 @@ public class ContributedPlatformTableCell extends InstallerTableCell {
|
||||
|
||||
final ContributedPlatform installed = editorValue.getInstalled();
|
||||
|
||||
java.util.List<ContributedPlatform> releases = new LinkedList<ContributedPlatform>(editorValue.releases);
|
||||
java.util.List<ContributedPlatform> releases = new LinkedList<>(editorValue.releases);
|
||||
java.util.List<ContributedPlatform> uninstalledReleases = releases.stream().filter(new InstalledPredicate().negate()).collect(Collectors.toList());
|
||||
|
||||
java.util.List<ContributedPlatform> installedBuiltIn = releases.stream().filter(new InstalledPredicate()).filter(new BuiltInPredicate()).collect(Collectors.toList());
|
||||
@ -272,7 +243,7 @@ public class ContributedPlatformTableCell extends InstallerTableCell {
|
||||
uninstalledReleases.addAll(installedBuiltIn);
|
||||
}
|
||||
|
||||
Collections.sort(uninstalledReleases, new ReverseComparator<DownloadableContribution>(new DownloadableContributionVersionComparator()));
|
||||
Collections.sort(uninstalledReleases, new ReverseComparator<>(new DownloadableContributionVersionComparator()));
|
||||
|
||||
downgradeChooser.removeAllItems();
|
||||
downgradeChooser.addItem(_("Select version"));
|
||||
@ -281,32 +252,23 @@ public class ContributedPlatformTableCell extends InstallerTableCell {
|
||||
final java.util.List<ContributedPlatform> uninstalledNewerReleases = Lists.newLinkedList();
|
||||
|
||||
final VersionComparator versionComparator = new VersionComparator();
|
||||
Lists.newLinkedList(Lists.transform(uninstalledReleases, new Function<ContributedPlatform, ContributedPlatform>() {
|
||||
@Override
|
||||
public ContributedPlatform apply(ContributedPlatform input) {
|
||||
if (installed == null || versionComparator.greaterThan(installed.getParsedVersion(), input.getParsedVersion())) {
|
||||
uninstalledPreviousReleases.add(input);
|
||||
} else {
|
||||
uninstalledNewerReleases.add(input);
|
||||
}
|
||||
|
||||
return input;
|
||||
Lists.newLinkedList(Lists.transform(uninstalledReleases, input -> {
|
||||
if (installed == null || versionComparator.greaterThan(installed.getParsedVersion(), input.getParsedVersion())) {
|
||||
uninstalledPreviousReleases.add(input);
|
||||
} else {
|
||||
uninstalledNewerReleases.add(input);
|
||||
}
|
||||
|
||||
return input;
|
||||
}));
|
||||
for (ContributedPlatform release : uninstalledNewerReleases) {
|
||||
downgradeChooser.addItem(release);
|
||||
}
|
||||
for (ContributedPlatform release : uninstalledPreviousReleases) {
|
||||
downgradeChooser.addItem(release);
|
||||
}
|
||||
uninstalledNewerReleases.forEach(downgradeChooser::addItem);
|
||||
uninstalledPreviousReleases.forEach(downgradeChooser::addItem);
|
||||
|
||||
downgradeChooser.setVisible(installed != null && (!uninstalledPreviousReleases.isEmpty() || uninstalledNewerReleases.size() > 1));
|
||||
downgradeButton.setVisible(installed != null && (!uninstalledPreviousReleases.isEmpty() || uninstalledNewerReleases.size() > 1));
|
||||
|
||||
versionToInstallChooser.removeAllItems();
|
||||
for (ContributedPlatform release : uninstalledReleases) {
|
||||
versionToInstallChooser.addItem(release);
|
||||
}
|
||||
uninstalledReleases.forEach(versionToInstallChooser::addItem);
|
||||
versionToInstallChooser.setVisible(installed == null && uninstalledReleases.size() > 1);
|
||||
|
||||
Component component = getUpdatedCellComponent(value, true, row, !installedBuiltIn.isEmpty());
|
||||
@ -412,7 +374,7 @@ public class ContributedPlatformTableCell extends InstallerTableCell {
|
||||
return panel;
|
||||
}
|
||||
|
||||
private Timer enabler = new Timer(100, new ActionListener() {
|
||||
private final Timer enabler = new Timer(100, new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
enable(true);
|
||||
|
@ -59,8 +59,8 @@ public class ContributionIndexTableModel extends FilteredAbstractTableModel<Cont
|
||||
public ContributedPlatformReleases(ContributedPlatform platform) {
|
||||
this.packager = platform.getParentPackage();
|
||||
this.arch = platform.getArchitecture();
|
||||
this.releases = new LinkedList<ContributedPlatform>();
|
||||
this.versions = new LinkedList<String>();
|
||||
this.releases = new LinkedList<>();
|
||||
this.versions = new LinkedList<>();
|
||||
add(platform);
|
||||
}
|
||||
|
||||
@ -108,11 +108,11 @@ public class ContributionIndexTableModel extends FilteredAbstractTableModel<Cont
|
||||
}
|
||||
}
|
||||
|
||||
private List<ContributedPlatformReleases> contributions = new ArrayList<ContributedPlatformReleases>();
|
||||
private final List<ContributedPlatformReleases> contributions = new ArrayList<>();
|
||||
|
||||
private String[] columnNames = {"Description"};
|
||||
private final String[] columnNames = {"Description"};
|
||||
|
||||
private Class<?>[] columnTypes = {ContributedPlatform.class};
|
||||
private final Class<?>[] columnTypes = {ContributedPlatform.class};
|
||||
|
||||
private ContributionsIndexer indexer;
|
||||
|
||||
|
@ -148,19 +148,16 @@ public class ContributionManagerUI extends InstallerJDialog {
|
||||
@Override
|
||||
public void onUpdatePressed() {
|
||||
super.onUpdatePressed();
|
||||
installerThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
setProgressVisible(true, "");
|
||||
List<String> downloadedPackageIndexFiles = installer.updateIndex();
|
||||
installer.deleteUnknownFiles(downloadedPackageIndexFiles);
|
||||
onIndexesUpdated();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
setProgressVisible(false, "");
|
||||
}
|
||||
installerThread = new Thread(() -> {
|
||||
try {
|
||||
setProgressVisible(true, "");
|
||||
List<String> downloadedPackageIndexFiles = installer.updateIndex();
|
||||
installer.deleteUnknownFiles(downloadedPackageIndexFiles);
|
||||
onIndexesUpdated();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
setProgressVisible(false, "");
|
||||
}
|
||||
});
|
||||
installerThread.setUncaughtExceptionHandler(new InstallerJDialogUncaughtExceptionHandler(this, noConnectionErrorMessage));
|
||||
@ -169,24 +166,21 @@ public class ContributionManagerUI extends InstallerJDialog {
|
||||
|
||||
public void onInstallPressed(final ContributedPlatform platformToInstall, final ContributedPlatform platformToRemove) {
|
||||
clearErrorMessage();
|
||||
installerThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
List<String> errors = new LinkedList<String>();
|
||||
try {
|
||||
setProgressVisible(true, _("Installing..."));
|
||||
errors.addAll(installer.install(platformToInstall));
|
||||
if (platformToRemove != null && !platformToRemove.isReadOnly()) {
|
||||
errors.addAll(installer.remove(platformToRemove));
|
||||
}
|
||||
onIndexesUpdated();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
setProgressVisible(false, "");
|
||||
if (!errors.isEmpty()) {
|
||||
setErrorMessage(errors.get(0));
|
||||
}
|
||||
installerThread = new Thread(() -> {
|
||||
List<String> errors = new LinkedList<>();
|
||||
try {
|
||||
setProgressVisible(true, _("Installing..."));
|
||||
errors.addAll(installer.install(platformToInstall));
|
||||
if (platformToRemove != null && !platformToRemove.isReadOnly()) {
|
||||
errors.addAll(installer.remove(platformToRemove));
|
||||
}
|
||||
onIndexesUpdated();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
setProgressVisible(false, "");
|
||||
if (!errors.isEmpty()) {
|
||||
setErrorMessage(errors.get(0));
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -204,18 +198,15 @@ public class ContributionManagerUI extends InstallerJDialog {
|
||||
}
|
||||
}
|
||||
|
||||
installerThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
setProgressVisible(true, _("Removing..."));
|
||||
installer.remove(platform);
|
||||
onIndexesUpdated();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
setProgressVisible(false, "");
|
||||
}
|
||||
installerThread = new Thread(() -> {
|
||||
try {
|
||||
setProgressVisible(true, _("Removing..."));
|
||||
installer.remove(platform);
|
||||
onIndexesUpdated();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
setProgressVisible(false, "");
|
||||
}
|
||||
});
|
||||
installerThread.setUncaughtExceptionHandler(new InstallerJDialogUncaughtExceptionHandler(this, noConnectionErrorMessage));
|
||||
|
@ -45,7 +45,7 @@ public class DropdownAllCoresItem implements DropdownItem<ContributedPlatform> {
|
||||
|
||||
@Override
|
||||
public Predicate<ContributedPlatform> getFilterPredicate() {
|
||||
return new NoopPredicate<ContributedPlatform>();
|
||||
return new NoopPredicate<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -44,7 +44,7 @@ public class DropdownAllItem implements DropdownItem<DownloadableContribution> {
|
||||
|
||||
@Override
|
||||
public Predicate<DownloadableContribution> getFilterPredicate() {
|
||||
return new NoopPredicate<DownloadableContribution>();
|
||||
return new NoopPredicate<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -102,7 +102,7 @@ public class FilterJTextField extends JTextField {
|
||||
// Empty
|
||||
}
|
||||
|
||||
public void updateStyle() {
|
||||
private void updateStyle() {
|
||||
if (showingHint) {
|
||||
setText(filterHint);
|
||||
setForeground(Color.gray);
|
||||
|
@ -34,7 +34,6 @@ import cc.arduino.contributions.VersionComparator;
|
||||
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
@ -45,14 +44,9 @@ public abstract class FilteredAbstractTableModel<T> extends AbstractTableModel {
|
||||
abstract public void updateIndexFilter(String[] filters, Stream<Predicate<T>> additionalFilters);
|
||||
|
||||
protected static <T extends DownloadableContribution> T getLatestOf(List<T> contribs) {
|
||||
contribs = new LinkedList<T>(contribs);
|
||||
contribs = new LinkedList<>(contribs);
|
||||
final VersionComparator versionComparator = new VersionComparator();
|
||||
Collections.sort(contribs, new Comparator<T>() {
|
||||
@Override
|
||||
public int compare(T contrib1, T contrib2) {
|
||||
return versionComparator.compare(contrib1.getParsedVersion(), contrib2.getParsedVersion());
|
||||
}
|
||||
});
|
||||
Collections.sort(contribs, (contrib1, contrib2) -> versionComparator.compare(contrib1.getParsedVersion(), contrib2.getParsedVersion()));
|
||||
|
||||
if (contribs.isEmpty()) {
|
||||
return null;
|
||||
|
@ -170,12 +170,7 @@ public abstract class InstallerJDialog<T> extends JDialog {
|
||||
|
||||
{
|
||||
JButton cancelButton = new JButton(_("Cancel"));
|
||||
cancelButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
onCancelPressed();
|
||||
}
|
||||
});
|
||||
cancelButton.addActionListener(arg0 -> onCancelPressed());
|
||||
|
||||
progressBox = Box.createHorizontalBox();
|
||||
progressBox.add(progressBar);
|
||||
@ -183,21 +178,13 @@ public abstract class InstallerJDialog<T> extends JDialog {
|
||||
progressBox.add(cancelButton);
|
||||
|
||||
dismissErrorMessageButton = new JButton(_("OK"));
|
||||
dismissErrorMessageButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
clearErrorMessage();
|
||||
setErrorMessageVisible(false);
|
||||
}
|
||||
dismissErrorMessageButton.addActionListener(arg0 -> {
|
||||
clearErrorMessage();
|
||||
setErrorMessageVisible(false);
|
||||
});
|
||||
|
||||
closeButton = new JButton(_("Close"));
|
||||
closeButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
InstallerJDialog.this.dispatchEvent(new WindowEvent(InstallerJDialog.this, WindowEvent.WINDOW_CLOSING));
|
||||
}
|
||||
});
|
||||
closeButton.addActionListener(arg0 -> InstallerJDialog.this.dispatchEvent(new WindowEvent(InstallerJDialog.this, WindowEvent.WINDOW_CLOSING)));
|
||||
|
||||
errorMessageBox = Box.createHorizontalBox();
|
||||
errorMessageBox.add(Box.createHorizontalGlue());
|
||||
@ -222,19 +209,9 @@ public abstract class InstallerJDialog<T> extends JDialog {
|
||||
|
||||
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
||||
|
||||
Base.registerWindowCloseKeys(getRootPane(), new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
InstallerJDialog.this.dispatchEvent(new WindowEvent(InstallerJDialog.this, WindowEvent.WINDOW_CLOSING));
|
||||
}
|
||||
});
|
||||
Base.registerWindowCloseKeys(getRootPane(), e -> InstallerJDialog.this.dispatchEvent(new WindowEvent(InstallerJDialog.this, WindowEvent.WINDOW_CLOSING)));
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
onUpdatePressed();
|
||||
}
|
||||
});
|
||||
SwingUtilities.invokeLater(InstallerJDialog.this::onUpdatePressed);
|
||||
}
|
||||
|
||||
public void updateIndexFilter(String[] filters, Predicate<T>... additionalFilters) {
|
||||
|
@ -50,12 +50,9 @@ public class InstallerJDialogUncaughtExceptionHandler implements Thread.Uncaught
|
||||
errorMessage = connectionErrorMessage;
|
||||
}
|
||||
final String finalErrorMessage = errorMessage;
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
System.err.println(finalErrorMessage);
|
||||
e.printStackTrace();
|
||||
}
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
System.err.println(finalErrorMessage);
|
||||
e.printStackTrace();
|
||||
});
|
||||
parent.setErrorMessage(finalErrorMessage);
|
||||
}
|
||||
|
@ -39,8 +39,6 @@ import java.nio.file.Files;
|
||||
import java.nio.file.LinkOption;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
import static processing.app.I18n.format;
|
||||
@ -98,20 +96,17 @@ public class DownloadableContributionsDownloader {
|
||||
|
||||
public void download(URL url, File tmpFile, Progress progress, String statusText) throws Exception {
|
||||
FileDownloader downloader = new FileDownloader(url, tmpFile);
|
||||
downloader.addObserver(new Observer() {
|
||||
@Override
|
||||
public void update(Observable o, Object arg) {
|
||||
FileDownloader me = (FileDownloader) o;
|
||||
String msg = "";
|
||||
if (me.getDownloadSize() != null) {
|
||||
long downloaded = (me.getInitialSize() + me.getDownloaded()) / 1000;
|
||||
long total = (me.getInitialSize() + me.getDownloadSize()) / 1000;
|
||||
msg = format(_("Downloaded {0}kb of {1}kb."), downloaded, total);
|
||||
}
|
||||
progress.setStatus(statusText + " " + msg);
|
||||
progress.setProgress(me.getProgress());
|
||||
onProgress(progress);
|
||||
downloader.addObserver((o, arg) -> {
|
||||
FileDownloader me = (FileDownloader) o;
|
||||
String msg = "";
|
||||
if (me.getDownloadSize() != null) {
|
||||
long downloaded = (me.getInitialSize() + me.getDownloaded()) / 1000;
|
||||
long total = (me.getInitialSize() + me.getDownloadSize()) / 1000;
|
||||
msg = format(_("Downloaded {0}kb of {1}kb."), downloaded, total);
|
||||
}
|
||||
progress.setStatus(statusText + " " + msg);
|
||||
progress.setProgress(me.getProgress());
|
||||
onProgress(progress);
|
||||
});
|
||||
downloader.download();
|
||||
if (!downloader.isCompleted()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user