Skip to content

Commit 8620e37

Browse files
cmaglielmihalkovic
authored andcommitted
Some minor cosmetics
1 parent 840a2ea commit 8620e37

File tree

4 files changed

+68
-66
lines changed

4 files changed

+68
-66
lines changed

app/src/cc/arduino/contributions/libraries/ui/LibrariesIndexTableModel.java

+15-10
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,20 @@
4141
import java.util.stream.Stream;
4242

4343
@SuppressWarnings("serial")
44-
public class LibrariesIndexTableModel extends FilteredAbstractTableModel<ContributedLibrary> {
45-
44+
public class LibrariesIndexTableModel
45+
extends FilteredAbstractTableModel<ContributedLibrary> {
4646

4747
private final List<ContributedLibraryReleases> contributions = new ArrayList<>();
4848

49-
private final String[] columnNames = {"Description"};
49+
private final String[] columnNames = { "Description" };
5050

51-
private final Class<?>[] columnTypes = {ContributedPlatform.class};
51+
private final Class<?>[] columnTypes = { ContributedPlatform.class };
5252

5353
Predicate<ContributedLibrary> selectedCategoryFilter = null;
5454
String selectedFilters[] = null;
5555

56-
public void updateIndexFilter(String filters[], Stream<Predicate<ContributedLibrary>> additionalFilters) {
56+
public void updateIndexFilter(String filters[],
57+
Stream<Predicate<ContributedLibrary>> additionalFilters) {
5758
selectedCategoryFilter = additionalFilters.reduce(Predicate::and).get();
5859
selectedFilters = filters;
5960
update();
@@ -66,7 +67,7 @@ public void updateIndexFilter(String filters[], Stream<Predicate<ContributedLibr
6667
* @param string
6768
* @param filters
6869
* @return <b>true<b> if all the strings in <b>set</b> are contained in
69-
* <b>string</b>.
70+
* <b>string</b>.
7071
*/
7172
private boolean stringContainsAll(String string, String filters[]) {
7273
if (string == null) {
@@ -154,7 +155,8 @@ private void applyFilterToLibrary(ContributedLibrary lib) {
154155
return;
155156
}
156157

157-
String compoundTargetSearchText = lib.getName() + "\n" + lib.getParagraph() + "\n" + lib.getSentence();
158+
String compoundTargetSearchText = lib.getName() + "\n" + lib.getParagraph()
159+
+ "\n" + lib.getSentence();
158160
if (!stringContainsAll(compoundTargetSearchText, selectedFilters)) {
159161
return;
160162
}
@@ -190,9 +192,12 @@ public void updateLibrary(ContributedLibrary lib) {
190192

191193
private void updateContributions() {
192194
contributions.clear();
193-
BaseNoGui.librariesIndexer.getIndex().getLibraries().forEach(this::applyFilterToLibrary);
194-
BaseNoGui.librariesIndexer.getInstalledLibraries().forEach(this::applyFilterToLibrary);
195-
Collections.sort(contributions, new ContributedLibraryReleasesComparator("Arduino"));
195+
BaseNoGui.librariesIndexer.getIndex().getLibraries()
196+
.forEach(this::applyFilterToLibrary);
197+
BaseNoGui.librariesIndexer.getInstalledLibraries()
198+
.forEach(this::applyFilterToLibrary);
199+
Collections.sort(contributions,
200+
new ContributedLibraryReleasesComparator("Arduino"));
196201
}
197202

198203
}

app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCell.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public class ContributedPlatformTableCell extends JPanel {
6565
final JButton removeButton;
6666
final Component removeButtonPlaceholder;
6767
final Component installButtonPlaceholder;
68-
JComboBox downgradeChooser;
68+
final JComboBox downgradeChooser;
6969
final JComboBox versionToInstallChooser;
7070
final JButton downgradeButton;
7171
final JPanel buttonsPanel;

app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCellEditor.java

+41-45
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.awt.Component;
3636
import java.util.Collections;
3737
import java.util.LinkedList;
38+
import java.util.List;
3839
import java.util.stream.Collectors;
3940

4041
import javax.swing.JTable;
@@ -50,44 +51,42 @@
5051
@SuppressWarnings("serial")
5152
public class ContributedPlatformTableCellEditor extends InstallerTableCell {
5253

53-
private ContributedPlatformTableCell editorCell;
54-
private ContributedPlatformReleases editorValue;
54+
private ContributedPlatformTableCell cell;
55+
private ContributedPlatformReleases value;
5556

5657
@Override
5758
public Object getCellEditorValue() {
58-
return editorValue;
59+
return value;
5960
}
6061

6162
@Override
62-
public Component getTableCellEditorComponent(JTable table, Object value,
63+
public Component getTableCellEditorComponent(JTable table, Object _value,
6364
boolean isSelected, int row,
6465
int column) {
65-
editorCell = new ContributedPlatformTableCell();
66-
editorCell.installButton
67-
.addActionListener(e -> onInstall(editorValue.getSelected(),
68-
editorValue.getInstalled()));
69-
editorCell.removeButton
70-
.addActionListener(e -> onRemove(editorValue.getInstalled()));
71-
editorCell.downgradeButton.addActionListener(e -> {
72-
ContributedPlatform selected = (ContributedPlatform) editorCell.downgradeChooser
66+
value = (ContributedPlatformReleases) _value;
67+
68+
cell = new ContributedPlatformTableCell();
69+
cell.installButton.addActionListener(e -> onInstall(value.getSelected(),
70+
value.getInstalled()));
71+
cell.removeButton.addActionListener(e -> onRemove(value.getInstalled()));
72+
cell.downgradeButton.addActionListener(e -> {
73+
ContributedPlatform selected = (ContributedPlatform) cell.downgradeChooser
7374
.getSelectedItem();
74-
onInstall(selected, editorValue.getInstalled());
75+
onInstall(selected, value.getInstalled());
7576
});
76-
editorCell.versionToInstallChooser.addItemListener(e -> editorValue
77-
.select((ContributedPlatform) editorCell.versionToInstallChooser
77+
cell.versionToInstallChooser.addItemListener(e -> value
78+
.select((ContributedPlatform) cell.versionToInstallChooser
7879
.getSelectedItem()));
7980

80-
editorValue = (ContributedPlatformReleases) value;
8181
setEnabled(true);
8282

83-
final ContributedPlatform installed = editorValue.getInstalled();
83+
final ContributedPlatform installed = value.getInstalled();
8484

85-
java.util.List<ContributedPlatform> releases = new LinkedList<>(
86-
editorValue.releases);
87-
java.util.List<ContributedPlatform> uninstalledReleases = releases.stream()
85+
List<ContributedPlatform> releases = new LinkedList<>(value.releases);
86+
List<ContributedPlatform> uninstalledReleases = releases.stream()
8887
.filter(new InstalledPredicate().negate()).collect(Collectors.toList());
8988

90-
java.util.List<ContributedPlatform> installedBuiltIn = releases.stream()
89+
List<ContributedPlatform> installedBuiltIn = releases.stream()
9190
.filter(new InstalledPredicate()).filter(new BuiltInPredicate())
9291
.collect(Collectors.toList());
9392

@@ -98,11 +97,11 @@ public Component getTableCellEditorComponent(JTable table, Object value,
9897
Collections.sort(uninstalledReleases, new ReverseComparator<>(
9998
new DownloadableContributionVersionComparator()));
10099

101-
editorCell.downgradeChooser.removeAllItems();
102-
editorCell.downgradeChooser.addItem(tr("Select version"));
100+
cell.downgradeChooser.removeAllItems();
101+
cell.downgradeChooser.addItem(tr("Select version"));
103102

104-
final java.util.List<ContributedPlatform> uninstalledPreviousReleases = new LinkedList<>();
105-
final java.util.List<ContributedPlatform> uninstalledNewerReleases = new LinkedList<>();
103+
final List<ContributedPlatform> uninstalledPreviousReleases = new LinkedList<>();
104+
final List<ContributedPlatform> uninstalledNewerReleases = new LinkedList<>();
106105

107106
final VersionComparator versionComparator = new VersionComparator();
108107
uninstalledReleases.stream().forEach(input -> {
@@ -114,35 +113,32 @@ public Component getTableCellEditorComponent(JTable table, Object value,
114113
uninstalledNewerReleases.add(input);
115114
}
116115
});
117-
uninstalledNewerReleases.forEach(editorCell.downgradeChooser::addItem);
118-
uninstalledPreviousReleases.forEach(editorCell.downgradeChooser::addItem);
119-
120-
editorCell.downgradeChooser
121-
.setVisible(installed != null
122-
&& (!uninstalledPreviousReleases.isEmpty()
123-
|| uninstalledNewerReleases.size() > 1));
124-
editorCell.downgradeButton
125-
.setVisible(installed != null
126-
&& (!uninstalledPreviousReleases.isEmpty()
127-
|| uninstalledNewerReleases.size() > 1));
128-
129-
editorCell.versionToInstallChooser.removeAllItems();
130-
uninstalledReleases.forEach(editorCell.versionToInstallChooser::addItem);
131-
editorCell.versionToInstallChooser
116+
uninstalledNewerReleases.forEach(cell.downgradeChooser::addItem);
117+
uninstalledPreviousReleases.forEach(cell.downgradeChooser::addItem);
118+
119+
boolean downgradeVisible = installed != null
120+
&& (!uninstalledPreviousReleases.isEmpty()
121+
|| uninstalledNewerReleases.size() > 1);
122+
cell.downgradeChooser.setVisible(downgradeVisible);
123+
cell.downgradeButton.setVisible(downgradeVisible);
124+
125+
cell.versionToInstallChooser.removeAllItems();
126+
uninstalledReleases.forEach(cell.versionToInstallChooser::addItem);
127+
cell.versionToInstallChooser
132128
.setVisible(installed == null && uninstalledReleases.size() > 1);
133129

134-
editorCell.update(table, value, true, !installedBuiltIn.isEmpty());
135-
editorCell.setBackground(new Color(218, 227, 227)); // #dae3e3
136-
return editorCell;
130+
cell.update(table, _value, true, !installedBuiltIn.isEmpty());
131+
cell.setBackground(new Color(218, 227, 227)); // #dae3e3
132+
return cell;
137133
}
138134

139135
@Override
140136
public void setEnabled(boolean enabled) {
141-
editorCell.setButtonsVisible(enabled);
137+
cell.setButtonsVisible(enabled);
142138
}
143139

144140
public void setStatus(String status) {
145-
editorCell.statusLabel.setText(status);
141+
cell.statusLabel.setText(status);
146142
}
147143

148144
protected void onRemove(ContributedPlatform contributedPlatform) {

app/src/cc/arduino/contributions/packages/ui/ContributionIndexTableModel.java

+11-10
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929

3030
package cc.arduino.contributions.packages.ui;
3131

32-
import cc.arduino.contributions.DownloadableContributionBuiltInAtTheBottomComparator;
33-
import cc.arduino.contributions.filters.InstalledPredicate;
3432
import cc.arduino.contributions.packages.ContributedBoard;
3533
import cc.arduino.contributions.packages.ContributedPackage;
3634
import cc.arduino.contributions.packages.ContributedPlatform;
@@ -48,17 +46,20 @@ public class ContributionIndexTableModel
4846
extends FilteredAbstractTableModel<ContributedPlatform> {
4947

5048
private final List<ContributedPlatformReleases> contributions = new ArrayList<>();
49+
private final String[] columnNames = { "Description" };
50+
private final Class<?>[] columnTypes = { ContributedPlatform.class };
5151

52-
private final String[] columnNames = {"Description"};
53-
54-
private final Class<?>[] columnTypes = {ContributedPlatform.class};
55-
56-
public void updateIndexFilter(String[] filters, Stream<Predicate<ContributedPlatform>> additionalFilters) {
52+
public void updateIndexFilter(String[] filters,
53+
Stream<Predicate<ContributedPlatform>> additionalFilters) {
5754
contributions.clear();
58-
Predicate<ContributedPlatform> filter = additionalFilters.reduce(Predicate::and).get();
55+
Predicate<ContributedPlatform> filter = additionalFilters
56+
.reduce(Predicate::and).get();
5957
for (ContributedPackage pack : BaseNoGui.indexer.getPackages()) {
6058
for (ContributedPlatform platform : pack.getPlatforms()) {
61-
String compoundTargetSearchText = platform.getName() + "\n" + platform.getBoards().stream().map(ContributedBoard::getName).collect(Collectors.joining(" "));
59+
String compoundTargetSearchText = platform.getName() + "\n"
60+
+ platform.getBoards().stream()
61+
.map(ContributedBoard::getName)
62+
.collect(Collectors.joining(" "));
6263
if (!filter.test(platform)) {
6364
continue;
6465
}
@@ -77,7 +78,7 @@ public void updateIndexFilter(String[] filters, Stream<Predicate<ContributedPlat
7778
* @param string
7879
* @param set
7980
* @return <b>true<b> if all the strings in <b>set</b> are contained in
80-
* <b>string</b>.
81+
* <b>string</b>.
8182
*/
8283
private boolean stringContainsAll(String string, String set[]) {
8384
if (set == null)

0 commit comments

Comments
 (0)