mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-13 10:29:35 +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;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class LibrariesIndexTableModel extends FilteredAbstractTableModel<ContributedLibrary> {
|
||||
|
||||
public class LibrariesIndexTableModel
|
||||
extends FilteredAbstractTableModel<ContributedLibrary> {
|
||||
|
||||
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;
|
||||
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();
|
||||
selectedFilters = filters;
|
||||
update();
|
||||
@ -66,7 +67,7 @@ public class LibrariesIndexTableModel extends FilteredAbstractTableModel<Contrib
|
||||
* @param string
|
||||
* @param filters
|
||||
* @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[]) {
|
||||
if (string == null) {
|
||||
@ -154,7 +155,8 @@ public class LibrariesIndexTableModel extends FilteredAbstractTableModel<Contrib
|
||||
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)) {
|
||||
return;
|
||||
}
|
||||
@ -190,9 +192,12 @@ public class LibrariesIndexTableModel extends FilteredAbstractTableModel<Contrib
|
||||
|
||||
private void updateContributions() {
|
||||
contributions.clear();
|
||||
BaseNoGui.librariesIndexer.getIndex().getLibraries().forEach(this::applyFilterToLibrary);
|
||||
BaseNoGui.librariesIndexer.getInstalledLibraries().forEach(this::applyFilterToLibrary);
|
||||
Collections.sort(contributions, new ContributedLibraryReleasesComparator("Arduino"));
|
||||
BaseNoGui.librariesIndexer.getIndex().getLibraries()
|
||||
.forEach(this::applyFilterToLibrary);
|
||||
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 Component removeButtonPlaceholder;
|
||||
final Component installButtonPlaceholder;
|
||||
JComboBox downgradeChooser;
|
||||
final JComboBox downgradeChooser;
|
||||
final JComboBox versionToInstallChooser;
|
||||
final JButton downgradeButton;
|
||||
final JPanel buttonsPanel;
|
||||
|
@ -35,6 +35,7 @@ import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.swing.JTable;
|
||||
@ -50,44 +51,42 @@ import cc.arduino.utils.ReverseComparator;
|
||||
@SuppressWarnings("serial")
|
||||
public class ContributedPlatformTableCellEditor extends InstallerTableCell {
|
||||
|
||||
private ContributedPlatformTableCell editorCell;
|
||||
private ContributedPlatformReleases editorValue;
|
||||
private ContributedPlatformTableCell cell;
|
||||
private ContributedPlatformReleases value;
|
||||
|
||||
@Override
|
||||
public Object getCellEditorValue() {
|
||||
return editorValue;
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getTableCellEditorComponent(JTable table, Object value,
|
||||
public Component getTableCellEditorComponent(JTable table, Object _value,
|
||||
boolean isSelected, int row,
|
||||
int column) {
|
||||
editorCell = new ContributedPlatformTableCell();
|
||||
editorCell.installButton
|
||||
.addActionListener(e -> onInstall(editorValue.getSelected(),
|
||||
editorValue.getInstalled()));
|
||||
editorCell.removeButton
|
||||
.addActionListener(e -> onRemove(editorValue.getInstalled()));
|
||||
editorCell.downgradeButton.addActionListener(e -> {
|
||||
ContributedPlatform selected = (ContributedPlatform) editorCell.downgradeChooser
|
||||
value = (ContributedPlatformReleases) _value;
|
||||
|
||||
cell = new ContributedPlatformTableCell();
|
||||
cell.installButton.addActionListener(e -> onInstall(value.getSelected(),
|
||||
value.getInstalled()));
|
||||
cell.removeButton.addActionListener(e -> onRemove(value.getInstalled()));
|
||||
cell.downgradeButton.addActionListener(e -> {
|
||||
ContributedPlatform selected = (ContributedPlatform) cell.downgradeChooser
|
||||
.getSelectedItem();
|
||||
onInstall(selected, editorValue.getInstalled());
|
||||
onInstall(selected, value.getInstalled());
|
||||
});
|
||||
editorCell.versionToInstallChooser.addItemListener(e -> editorValue
|
||||
.select((ContributedPlatform) editorCell.versionToInstallChooser
|
||||
cell.versionToInstallChooser.addItemListener(e -> value
|
||||
.select((ContributedPlatform) cell.versionToInstallChooser
|
||||
.getSelectedItem()));
|
||||
|
||||
editorValue = (ContributedPlatformReleases) value;
|
||||
setEnabled(true);
|
||||
|
||||
final ContributedPlatform installed = editorValue.getInstalled();
|
||||
final ContributedPlatform installed = value.getInstalled();
|
||||
|
||||
java.util.List<ContributedPlatform> releases = new LinkedList<>(
|
||||
editorValue.releases);
|
||||
java.util.List<ContributedPlatform> uninstalledReleases = releases.stream()
|
||||
List<ContributedPlatform> releases = new LinkedList<>(value.releases);
|
||||
List<ContributedPlatform> uninstalledReleases = releases.stream()
|
||||
.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())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@ -98,11 +97,11 @@ public class ContributedPlatformTableCellEditor extends InstallerTableCell {
|
||||
Collections.sort(uninstalledReleases, new ReverseComparator<>(
|
||||
new DownloadableContributionVersionComparator()));
|
||||
|
||||
editorCell.downgradeChooser.removeAllItems();
|
||||
editorCell.downgradeChooser.addItem(tr("Select version"));
|
||||
cell.downgradeChooser.removeAllItems();
|
||||
cell.downgradeChooser.addItem(tr("Select version"));
|
||||
|
||||
final java.util.List<ContributedPlatform> uninstalledPreviousReleases = new LinkedList<>();
|
||||
final java.util.List<ContributedPlatform> uninstalledNewerReleases = new LinkedList<>();
|
||||
final List<ContributedPlatform> uninstalledPreviousReleases = new LinkedList<>();
|
||||
final List<ContributedPlatform> uninstalledNewerReleases = new LinkedList<>();
|
||||
|
||||
final VersionComparator versionComparator = new VersionComparator();
|
||||
uninstalledReleases.stream().forEach(input -> {
|
||||
@ -114,35 +113,32 @@ public class ContributedPlatformTableCellEditor extends InstallerTableCell {
|
||||
uninstalledNewerReleases.add(input);
|
||||
}
|
||||
});
|
||||
uninstalledNewerReleases.forEach(editorCell.downgradeChooser::addItem);
|
||||
uninstalledPreviousReleases.forEach(editorCell.downgradeChooser::addItem);
|
||||
uninstalledNewerReleases.forEach(cell.downgradeChooser::addItem);
|
||||
uninstalledPreviousReleases.forEach(cell.downgradeChooser::addItem);
|
||||
|
||||
editorCell.downgradeChooser
|
||||
.setVisible(installed != null
|
||||
&& (!uninstalledPreviousReleases.isEmpty()
|
||||
|| uninstalledNewerReleases.size() > 1));
|
||||
editorCell.downgradeButton
|
||||
.setVisible(installed != null
|
||||
&& (!uninstalledPreviousReleases.isEmpty()
|
||||
|| uninstalledNewerReleases.size() > 1));
|
||||
boolean downgradeVisible = installed != null
|
||||
&& (!uninstalledPreviousReleases.isEmpty()
|
||||
|| uninstalledNewerReleases.size() > 1);
|
||||
cell.downgradeChooser.setVisible(downgradeVisible);
|
||||
cell.downgradeButton.setVisible(downgradeVisible);
|
||||
|
||||
editorCell.versionToInstallChooser.removeAllItems();
|
||||
uninstalledReleases.forEach(editorCell.versionToInstallChooser::addItem);
|
||||
editorCell.versionToInstallChooser
|
||||
cell.versionToInstallChooser.removeAllItems();
|
||||
uninstalledReleases.forEach(cell.versionToInstallChooser::addItem);
|
||||
cell.versionToInstallChooser
|
||||
.setVisible(installed == null && uninstalledReleases.size() > 1);
|
||||
|
||||
editorCell.update(table, value, true, !installedBuiltIn.isEmpty());
|
||||
editorCell.setBackground(new Color(218, 227, 227)); // #dae3e3
|
||||
return editorCell;
|
||||
cell.update(table, _value, true, !installedBuiltIn.isEmpty());
|
||||
cell.setBackground(new Color(218, 227, 227)); // #dae3e3
|
||||
return cell;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enabled) {
|
||||
editorCell.setButtonsVisible(enabled);
|
||||
cell.setButtonsVisible(enabled);
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
editorCell.statusLabel.setText(status);
|
||||
cell.statusLabel.setText(status);
|
||||
}
|
||||
|
||||
protected void onRemove(ContributedPlatform contributedPlatform) {
|
||||
|
@ -29,8 +29,6 @@
|
||||
|
||||
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.ContributedPackage;
|
||||
import cc.arduino.contributions.packages.ContributedPlatform;
|
||||
@ -48,17 +46,20 @@ public class ContributionIndexTableModel
|
||||
extends FilteredAbstractTableModel<ContributedPlatform> {
|
||||
|
||||
private final List<ContributedPlatformReleases> contributions = new ArrayList<>();
|
||||
private final String[] columnNames = { "Description" };
|
||||
private final Class<?>[] columnTypes = { ContributedPlatform.class };
|
||||
|
||||
private final String[] columnNames = {"Description"};
|
||||
|
||||
private final Class<?>[] columnTypes = {ContributedPlatform.class};
|
||||
|
||||
public void updateIndexFilter(String[] filters, Stream<Predicate<ContributedPlatform>> additionalFilters) {
|
||||
public void updateIndexFilter(String[] filters,
|
||||
Stream<Predicate<ContributedPlatform>> additionalFilters) {
|
||||
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 (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)) {
|
||||
continue;
|
||||
}
|
||||
@ -77,7 +78,7 @@ public class ContributionIndexTableModel
|
||||
* @param string
|
||||
* @param set
|
||||
* @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[]) {
|
||||
if (set == null)
|
||||
|
Loading…
x
Reference in New Issue
Block a user