1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-18 07:52:14 +01:00

Fixed glitch in "Boards Installer" GUI

This commit is contained in:
Cristian Maglie 2014-05-16 01:08:32 +02:00 committed by Federico Fissore
parent fe2d087ebd
commit 1aab726750
3 changed files with 56 additions and 52 deletions

View File

@ -121,7 +121,6 @@ public class ContributionIndexTableModel extends AbstractTableModel {
public void setIndex(ContributionsIndex _index) { public void setIndex(ContributionsIndex _index) {
index = _index; index = _index;
updateIndexFilter(null, null);
} }
public void updateIndexFilter(String category, String filters[]) { public void updateIndexFilter(String category, String filters[]) {

View File

@ -39,7 +39,6 @@ import java.awt.Dimension;
import java.awt.Frame; import java.awt.Frame;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import javax.swing.Box; import javax.swing.Box;
@ -108,24 +107,13 @@ public class ContributionManagerUI extends JDialog {
categoryChooser = new JComboBox(); categoryChooser = new JComboBox();
categoryChooser.setMaximumRowCount(20); categoryChooser.setMaximumRowCount(20);
categoryChooser.addActionListener(new ActionListener() { categoryChooser.setEnabled(false);
@Override
public void actionPerformed(ActionEvent arg0) {
String selected = (String) categoryChooser.getSelectedItem();
if (category == null || !category.equals(selected)) {
category = selected;
cellEditor.stopCellEditing();
contribModel.updateIndexFilter(category, filters);
}
}
});
setCategories(new ArrayList<String>());
filterField = new FilterJTextField(_("Filter your search...")) { filterField = new FilterJTextField(_("Filter your search...")) {
@Override @Override
protected void onFilter(String[] _filters) { protected void onFilter(String[] _filters) {
filters = _filters; filters = _filters;
cellEditor.stopCellEditing();
contribModel.updateIndexFilter(category, filters); contribModel.updateIndexFilter(category, filters);
} }
}; };
@ -223,28 +211,44 @@ public class ContributionManagerUI extends JDialog {
} }
} }
setMinimumSize(new Dimension(500, 400)); setMinimumSize(new Dimension(600, 450));
doLayout();
contribModel.addTableModelListener(new TableModelListener() {
@Override
public void tableChanged(final TableModelEvent arg0) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
updateCellsHeight(arg0);
}
});
}
});
} }
public void setIndexer(ContributionsIndexer indexer) { private TableModelListener tableModelListener = new TableModelListener() {
contribModel.setIndex(indexer.getIndex()); @Override
setCategories(indexer.getIndex().getCategories()); public void tableChanged(final TableModelEvent arg0) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
updateCellsHeight(arg0);
}
});
}
};
// Create installer with his dialog public void setIndexer(ContributionsIndexer indexer) {
contribModel.removeTableModelListener(tableModelListener);
categoryChooser.removeActionListener(categoryChooserActionListener);
contribModel.setIndex(indexer.getIndex());
category = null;
categoryChooser.removeAllItems();
filterField.setEnabled(contribModel.getRowCount() > 0);
contribModel.addTableModelListener(tableModelListener);
categoryChooser.addActionListener(categoryChooserActionListener);
// Enable categories combo only if there are two or more choices
Collection<String> categories = indexer.getIndex().getCategories();
int count = categories.size();
categoryChooser.setEnabled(count > 1);
for (String s : categories)
categoryChooser.addItem(s);
// Create ConstributionInstaller tied with the provided index
installer = new ContributionInstaller(indexer); installer = new ContributionInstaller(indexer);
installer.setListener(new ContributionInstaller.Listener() { installer.setListener(new ContributionInstaller.Listener() {
@Override @Override
@ -254,24 +258,17 @@ public class ContributionManagerUI extends JDialog {
}); });
} }
public void setCategories(Collection<String> categories) { ActionListener categoryChooserActionListener = new ActionListener() {
category = null; @Override
categoryChooser.removeAllItems(); public void actionPerformed(ActionEvent arg0) {
for (String s : categories) String selected = (String) categoryChooser.getSelectedItem();
categoryChooser.addItem(s); if (category == null || !category.equals(selected)) {
category = selected;
// Disable if only one possible choice cellEditor.stopCellEditing();
boolean single = categories.size() == 1; contribModel.updateIndexFilter(category, filters);
categoryChooser.setEnabled(!single); }
}
// Show if there is at lease one possible choice };
boolean show = !categories.isEmpty();
categoryStrut1.setVisible(show);
categoryLabel.setVisible(show);
categoryStrut2.setVisible(show);
categoryChooser.setVisible(show);
categoryStrut3.setVisible(show);
}
public void setProgressVisible(boolean visible) { public void setProgressVisible(boolean visible) {
progressBox.setVisible(visible); progressBox.setVisible(visible);

View File

@ -83,12 +83,20 @@ public class FilterJTextField extends JTextField {
}); });
} }
private String lastFilter = "";
private void applyFilter() { private void applyFilter() {
String filter = showingHint ? "" : getText(); String filter = showingHint ? "" : getText();
filter = filter.toLowerCase(); filter = filter.toLowerCase();
// Replace anything but 0-9, a-z, or : with a space // Replace anything but 0-9, a-z, or : with a space
filter = filter.replaceAll("[^\\x30-\\x39^\\x61-\\x7a^\\x3a]", " "); filter = filter.replaceAll("[^\\x30-\\x39^\\x61-\\x7a^\\x3a]", " ");
// Fire event only if the filter is changed
if (filter.equals(lastFilter))
return;
lastFilter = filter;
onFilter(filter.split(" ")); onFilter(filter.split(" "));
} }