mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-15 12:29:26 +01:00
Some minor cosmetics
This commit is contained in:
parent
2b9483b6e6
commit
a7e22e1958
@ -41,19 +41,20 @@ import java.util.function.Predicate;
|
|||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class LibrariesIndexTableModel extends FilteredAbstractTableModel<ContributedLibrary> {
|
public class LibrariesIndexTableModel
|
||||||
|
extends FilteredAbstractTableModel<ContributedLibrary> {
|
||||||
|
|
||||||
private final List<ContributedLibraryReleases> contributions = new ArrayList<>();
|
private final List<ContributedLibraryReleases> contributions = new ArrayList<>();
|
||||||
|
|
||||||
private final String[] columnNames = {"Description"};
|
private final String[] columnNames = { "Description" };
|
||||||
|
|
||||||
private final Class<?>[] columnTypes = {ContributedPlatform.class};
|
private final Class<?>[] columnTypes = { ContributedPlatform.class };
|
||||||
|
|
||||||
Predicate<ContributedLibrary> selectedCategoryFilter = null;
|
Predicate<ContributedLibrary> selectedCategoryFilter = null;
|
||||||
String selectedFilters[] = null;
|
String selectedFilters[] = null;
|
||||||
|
|
||||||
public void updateIndexFilter(String filters[], Stream<Predicate<ContributedLibrary>> additionalFilters) {
|
public void updateIndexFilter(String filters[],
|
||||||
|
Stream<Predicate<ContributedLibrary>> additionalFilters) {
|
||||||
selectedCategoryFilter = additionalFilters.reduce(Predicate::and).get();
|
selectedCategoryFilter = additionalFilters.reduce(Predicate::and).get();
|
||||||
selectedFilters = filters;
|
selectedFilters = filters;
|
||||||
update();
|
update();
|
||||||
@ -66,7 +67,7 @@ public class LibrariesIndexTableModel extends FilteredAbstractTableModel<Contrib
|
|||||||
* @param string
|
* @param string
|
||||||
* @param filters
|
* @param filters
|
||||||
* @return <b>true<b> if all the strings in <b>set</b> are contained in
|
* @return <b>true<b> if all the strings in <b>set</b> are contained in
|
||||||
* <b>string</b>.
|
* <b>string</b>.
|
||||||
*/
|
*/
|
||||||
private boolean stringContainsAll(String string, String filters[]) {
|
private boolean stringContainsAll(String string, String filters[]) {
|
||||||
if (string == null) {
|
if (string == null) {
|
||||||
@ -154,7 +155,8 @@ public class LibrariesIndexTableModel extends FilteredAbstractTableModel<Contrib
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String compoundTargetSearchText = lib.getName() + "\n" + lib.getParagraph() + "\n" + lib.getSentence();
|
String compoundTargetSearchText = lib.getName() + "\n" + lib.getParagraph()
|
||||||
|
+ "\n" + lib.getSentence();
|
||||||
if (!stringContainsAll(compoundTargetSearchText, selectedFilters)) {
|
if (!stringContainsAll(compoundTargetSearchText, selectedFilters)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -190,9 +192,12 @@ public class LibrariesIndexTableModel extends FilteredAbstractTableModel<Contrib
|
|||||||
|
|
||||||
private void updateContributions() {
|
private void updateContributions() {
|
||||||
contributions.clear();
|
contributions.clear();
|
||||||
BaseNoGui.librariesIndexer.getIndex().getLibraries().forEach(this::applyFilterToLibrary);
|
BaseNoGui.librariesIndexer.getIndex().getLibraries()
|
||||||
BaseNoGui.librariesIndexer.getInstalledLibraries().forEach(this::applyFilterToLibrary);
|
.forEach(this::applyFilterToLibrary);
|
||||||
Collections.sort(contributions, new ContributedLibraryReleasesComparator("Arduino"));
|
BaseNoGui.librariesIndexer.getInstalledLibraries()
|
||||||
|
.forEach(this::applyFilterToLibrary);
|
||||||
|
Collections.sort(contributions,
|
||||||
|
new ContributedLibraryReleasesComparator("Arduino"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ public class ContributedPlatformTableCell extends JPanel {
|
|||||||
final JButton removeButton;
|
final JButton removeButton;
|
||||||
final Component removeButtonPlaceholder;
|
final Component removeButtonPlaceholder;
|
||||||
final Component installButtonPlaceholder;
|
final Component installButtonPlaceholder;
|
||||||
JComboBox downgradeChooser;
|
final JComboBox downgradeChooser;
|
||||||
final JComboBox versionToInstallChooser;
|
final JComboBox versionToInstallChooser;
|
||||||
final JButton downgradeButton;
|
final JButton downgradeButton;
|
||||||
final JPanel buttonsPanel;
|
final JPanel buttonsPanel;
|
||||||
|
@ -35,6 +35,7 @@ import java.awt.Color;
|
|||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.swing.JTable;
|
import javax.swing.JTable;
|
||||||
@ -50,44 +51,42 @@ import cc.arduino.utils.ReverseComparator;
|
|||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class ContributedPlatformTableCellEditor extends InstallerTableCell {
|
public class ContributedPlatformTableCellEditor extends InstallerTableCell {
|
||||||
|
|
||||||
private ContributedPlatformTableCell editorCell;
|
private ContributedPlatformTableCell cell;
|
||||||
private ContributedPlatformReleases editorValue;
|
private ContributedPlatformReleases value;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getCellEditorValue() {
|
public Object getCellEditorValue() {
|
||||||
return editorValue;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Component getTableCellEditorComponent(JTable table, Object value,
|
public Component getTableCellEditorComponent(JTable table, Object _value,
|
||||||
boolean isSelected, int row,
|
boolean isSelected, int row,
|
||||||
int column) {
|
int column) {
|
||||||
editorCell = new ContributedPlatformTableCell();
|
value = (ContributedPlatformReleases) _value;
|
||||||
editorCell.installButton
|
|
||||||
.addActionListener(e -> onInstall(editorValue.getSelected(),
|
cell = new ContributedPlatformTableCell();
|
||||||
editorValue.getInstalled()));
|
cell.installButton.addActionListener(e -> onInstall(value.getSelected(),
|
||||||
editorCell.removeButton
|
value.getInstalled()));
|
||||||
.addActionListener(e -> onRemove(editorValue.getInstalled()));
|
cell.removeButton.addActionListener(e -> onRemove(value.getInstalled()));
|
||||||
editorCell.downgradeButton.addActionListener(e -> {
|
cell.downgradeButton.addActionListener(e -> {
|
||||||
ContributedPlatform selected = (ContributedPlatform) editorCell.downgradeChooser
|
ContributedPlatform selected = (ContributedPlatform) cell.downgradeChooser
|
||||||
.getSelectedItem();
|
.getSelectedItem();
|
||||||
onInstall(selected, editorValue.getInstalled());
|
onInstall(selected, value.getInstalled());
|
||||||
});
|
});
|
||||||
editorCell.versionToInstallChooser.addItemListener(e -> editorValue
|
cell.versionToInstallChooser.addItemListener(e -> value
|
||||||
.select((ContributedPlatform) editorCell.versionToInstallChooser
|
.select((ContributedPlatform) cell.versionToInstallChooser
|
||||||
.getSelectedItem()));
|
.getSelectedItem()));
|
||||||
|
|
||||||
editorValue = (ContributedPlatformReleases) value;
|
|
||||||
setEnabled(true);
|
setEnabled(true);
|
||||||
|
|
||||||
final ContributedPlatform installed = editorValue.getInstalled();
|
final ContributedPlatform installed = value.getInstalled();
|
||||||
|
|
||||||
java.util.List<ContributedPlatform> releases = new LinkedList<>(
|
List<ContributedPlatform> releases = new LinkedList<>(value.releases);
|
||||||
editorValue.releases);
|
List<ContributedPlatform> uninstalledReleases = releases.stream()
|
||||||
java.util.List<ContributedPlatform> uninstalledReleases = releases.stream()
|
|
||||||
.filter(new InstalledPredicate().negate()).collect(Collectors.toList());
|
.filter(new InstalledPredicate().negate()).collect(Collectors.toList());
|
||||||
|
|
||||||
java.util.List<ContributedPlatform> installedBuiltIn = releases.stream()
|
List<ContributedPlatform> installedBuiltIn = releases.stream()
|
||||||
.filter(new InstalledPredicate()).filter(new BuiltInPredicate())
|
.filter(new InstalledPredicate()).filter(new BuiltInPredicate())
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
@ -98,11 +97,11 @@ public class ContributedPlatformTableCellEditor extends InstallerTableCell {
|
|||||||
Collections.sort(uninstalledReleases, new ReverseComparator<>(
|
Collections.sort(uninstalledReleases, new ReverseComparator<>(
|
||||||
new DownloadableContributionVersionComparator()));
|
new DownloadableContributionVersionComparator()));
|
||||||
|
|
||||||
editorCell.downgradeChooser.removeAllItems();
|
cell.downgradeChooser.removeAllItems();
|
||||||
editorCell.downgradeChooser.addItem(tr("Select version"));
|
cell.downgradeChooser.addItem(tr("Select version"));
|
||||||
|
|
||||||
final java.util.List<ContributedPlatform> uninstalledPreviousReleases = new LinkedList<>();
|
final List<ContributedPlatform> uninstalledPreviousReleases = new LinkedList<>();
|
||||||
final java.util.List<ContributedPlatform> uninstalledNewerReleases = new LinkedList<>();
|
final List<ContributedPlatform> uninstalledNewerReleases = new LinkedList<>();
|
||||||
|
|
||||||
final VersionComparator versionComparator = new VersionComparator();
|
final VersionComparator versionComparator = new VersionComparator();
|
||||||
uninstalledReleases.stream().forEach(input -> {
|
uninstalledReleases.stream().forEach(input -> {
|
||||||
@ -114,35 +113,32 @@ public class ContributedPlatformTableCellEditor extends InstallerTableCell {
|
|||||||
uninstalledNewerReleases.add(input);
|
uninstalledNewerReleases.add(input);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
uninstalledNewerReleases.forEach(editorCell.downgradeChooser::addItem);
|
uninstalledNewerReleases.forEach(cell.downgradeChooser::addItem);
|
||||||
uninstalledPreviousReleases.forEach(editorCell.downgradeChooser::addItem);
|
uninstalledPreviousReleases.forEach(cell.downgradeChooser::addItem);
|
||||||
|
|
||||||
editorCell.downgradeChooser
|
boolean downgradeVisible = installed != null
|
||||||
.setVisible(installed != null
|
&& (!uninstalledPreviousReleases.isEmpty()
|
||||||
&& (!uninstalledPreviousReleases.isEmpty()
|
|| uninstalledNewerReleases.size() > 1);
|
||||||
|| uninstalledNewerReleases.size() > 1));
|
cell.downgradeChooser.setVisible(downgradeVisible);
|
||||||
editorCell.downgradeButton
|
cell.downgradeButton.setVisible(downgradeVisible);
|
||||||
.setVisible(installed != null
|
|
||||||
&& (!uninstalledPreviousReleases.isEmpty()
|
|
||||||
|| uninstalledNewerReleases.size() > 1));
|
|
||||||
|
|
||||||
editorCell.versionToInstallChooser.removeAllItems();
|
cell.versionToInstallChooser.removeAllItems();
|
||||||
uninstalledReleases.forEach(editorCell.versionToInstallChooser::addItem);
|
uninstalledReleases.forEach(cell.versionToInstallChooser::addItem);
|
||||||
editorCell.versionToInstallChooser
|
cell.versionToInstallChooser
|
||||||
.setVisible(installed == null && uninstalledReleases.size() > 1);
|
.setVisible(installed == null && uninstalledReleases.size() > 1);
|
||||||
|
|
||||||
editorCell.update(table, value, true, !installedBuiltIn.isEmpty());
|
cell.update(table, _value, true, !installedBuiltIn.isEmpty());
|
||||||
editorCell.setBackground(new Color(218, 227, 227)); // #dae3e3
|
cell.setBackground(new Color(218, 227, 227)); // #dae3e3
|
||||||
return editorCell;
|
return cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setEnabled(boolean enabled) {
|
public void setEnabled(boolean enabled) {
|
||||||
editorCell.setButtonsVisible(enabled);
|
cell.setButtonsVisible(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStatus(String status) {
|
public void setStatus(String status) {
|
||||||
editorCell.statusLabel.setText(status);
|
cell.statusLabel.setText(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onRemove(ContributedPlatform contributedPlatform) {
|
protected void onRemove(ContributedPlatform contributedPlatform) {
|
||||||
|
@ -29,8 +29,6 @@
|
|||||||
|
|
||||||
package cc.arduino.contributions.packages.ui;
|
package cc.arduino.contributions.packages.ui;
|
||||||
|
|
||||||
import cc.arduino.contributions.DownloadableContributionBuiltInAtTheBottomComparator;
|
|
||||||
import cc.arduino.contributions.filters.InstalledPredicate;
|
|
||||||
import cc.arduino.contributions.packages.ContributedBoard;
|
import cc.arduino.contributions.packages.ContributedBoard;
|
||||||
import cc.arduino.contributions.packages.ContributedPackage;
|
import cc.arduino.contributions.packages.ContributedPackage;
|
||||||
import cc.arduino.contributions.packages.ContributedPlatform;
|
import cc.arduino.contributions.packages.ContributedPlatform;
|
||||||
@ -48,17 +46,20 @@ public class ContributionIndexTableModel
|
|||||||
extends FilteredAbstractTableModel<ContributedPlatform> {
|
extends FilteredAbstractTableModel<ContributedPlatform> {
|
||||||
|
|
||||||
private final List<ContributedPlatformReleases> contributions = new ArrayList<>();
|
private final List<ContributedPlatformReleases> contributions = new ArrayList<>();
|
||||||
|
private final String[] columnNames = { "Description" };
|
||||||
|
private final Class<?>[] columnTypes = { ContributedPlatform.class };
|
||||||
|
|
||||||
private final String[] columnNames = {"Description"};
|
public void updateIndexFilter(String[] filters,
|
||||||
|
Stream<Predicate<ContributedPlatform>> additionalFilters) {
|
||||||
private final Class<?>[] columnTypes = {ContributedPlatform.class};
|
|
||||||
|
|
||||||
public void updateIndexFilter(String[] filters, Stream<Predicate<ContributedPlatform>> additionalFilters) {
|
|
||||||
contributions.clear();
|
contributions.clear();
|
||||||
Predicate<ContributedPlatform> filter = additionalFilters.reduce(Predicate::and).get();
|
Predicate<ContributedPlatform> filter = additionalFilters
|
||||||
|
.reduce(Predicate::and).get();
|
||||||
for (ContributedPackage pack : BaseNoGui.indexer.getPackages()) {
|
for (ContributedPackage pack : BaseNoGui.indexer.getPackages()) {
|
||||||
for (ContributedPlatform platform : pack.getPlatforms()) {
|
for (ContributedPlatform platform : pack.getPlatforms()) {
|
||||||
String compoundTargetSearchText = platform.getName() + "\n" + platform.getBoards().stream().map(ContributedBoard::getName).collect(Collectors.joining(" "));
|
String compoundTargetSearchText = platform.getName() + "\n"
|
||||||
|
+ platform.getBoards().stream()
|
||||||
|
.map(ContributedBoard::getName)
|
||||||
|
.collect(Collectors.joining(" "));
|
||||||
if (!filter.test(platform)) {
|
if (!filter.test(platform)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -77,7 +78,7 @@ public class ContributionIndexTableModel
|
|||||||
* @param string
|
* @param string
|
||||||
* @param set
|
* @param set
|
||||||
* @return <b>true<b> if all the strings in <b>set</b> are contained in
|
* @return <b>true<b> if all the strings in <b>set</b> are contained in
|
||||||
* <b>string</b>.
|
* <b>string</b>.
|
||||||
*/
|
*/
|
||||||
private boolean stringContainsAll(String string, String set[]) {
|
private boolean stringContainsAll(String string, String set[]) {
|
||||||
if (set == null)
|
if (set == null)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user