lib/core installer: scrolling with arrow keys almost works

This commit is contained in:
Federico Fissore 2015-03-23 12:57:52 +01:00
parent 8922541898
commit 3fb3774627
5 changed files with 100 additions and 14 deletions

View File

@ -35,6 +35,7 @@ import cc.arduino.contributions.libraries.ContributedLibraryComparator;
import cc.arduino.contributions.libraries.filters.BuiltInPredicate;
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.base.Predicates;
@ -73,7 +74,6 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
private JComboBox versionToInstallChooser;
private JButton downgradeButton;
private JPanel buttonsPanel;
private Component removeButtonStrut;
private JPanel inactiveButtonsPanel;
private JLabel statusLabel;
@ -155,8 +155,7 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
buttonsPanel.add(installButton);
buttonsPanel.add(Box.createHorizontalStrut(5));
buttonsPanel.add(removeButton);
removeButtonStrut = Box.createHorizontalStrut(5);
buttonsPanel.add(removeButtonStrut);
buttonsPanel.add(Box.createHorizontalStrut(5));
buttonsPanel.add(Box.createHorizontalStrut(15));
panel.add(buttonsPanel);
@ -211,6 +210,7 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
}
}
});
description.addKeyListener(new DelegatingKeyListener(parentTable));
panel.add(description, 0);
return description;
}

View File

@ -34,6 +34,7 @@ import cc.arduino.contributions.packages.ContributedBoard;
import cc.arduino.contributions.packages.ContributedPlatform;
import cc.arduino.contributions.packages.ContributedPlatformComparator;
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.base.Predicates;
@ -71,7 +72,6 @@ public class ContributedPlatformTableCell extends InstallerTableCell {
private JComboBox versionToInstallChooser;
private JButton downgradeButton;
private JPanel buttonsPanel;
private Component removeButtonStrut;
private JPanel inactiveButtonsPanel;
private JLabel statusLabel;
@ -153,8 +153,7 @@ public class ContributedPlatformTableCell extends InstallerTableCell {
buttonsPanel.add(installButton);
buttonsPanel.add(Box.createHorizontalStrut(5));
buttonsPanel.add(removeButton);
removeButtonStrut = Box.createHorizontalStrut(5);
buttonsPanel.add(removeButtonStrut);
buttonsPanel.add(Box.createHorizontalStrut(5));
buttonsPanel.add(Box.createHorizontalStrut(15));
panel.add(buttonsPanel);
@ -209,6 +208,7 @@ public class ContributedPlatformTableCell extends InstallerTableCell {
}
}
});
description.addKeyListener(new DelegatingKeyListener(parentTable));
panel.add(description, 0);
return description;
}

View File

@ -28,6 +28,7 @@
*/
package cc.arduino.contributions.ui;
import cc.arduino.contributions.ui.listeners.AbstractKeyListener;
import com.google.common.base.Predicate;
import processing.app.Base;
import processing.app.Theme;
@ -39,6 +40,7 @@ import javax.swing.table.TableColumnModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import static cc.arduino.contributions.packages.ui.ContributionIndexTableModel.DESCRIPTION_COL;
@ -78,8 +80,6 @@ public abstract class InstallerJDialog<T> extends JDialog {
protected Box errorMessageBox;
private final JLabel errorMessage;
protected InstallerTableCell cellEditor;
public InstallerJDialog(Frame parent, String title, ModalityType applicationModal, String noConnectionErrorMessage) {
super(parent, title, applicationModal);
this.noConnectionErrorMessage = noConnectionErrorMessage;
@ -104,7 +104,9 @@ public abstract class InstallerJDialog<T> extends JDialog {
@Override
protected void onFilter(String[] _filters) {
filters = _filters;
cellEditor.stopCellEditing();
if (contribTable.getCellEditor() != null) {
contribTable.getCellEditor().stopCellEditing();
}
contribModel.updateIndexFilter(categoryFilter, filters);
}
};
@ -130,13 +132,23 @@ public abstract class InstallerJDialog<T> extends JDialog {
contribTable.setIntercellSpacing(new Dimension(0, 1));
contribTable.setShowVerticalLines(false);
contribTable.setSelectionBackground(Theme.getColor("status.notice.bgcolor"));
contribTable.addKeyListener(new AbstractKeyListener() {
@Override
public void keyReleased(KeyEvent keyEvent) {
if (keyEvent.getKeyCode() != keyEvent.VK_DOWN && keyEvent.getKeyCode() != KeyEvent.VK_UP) {
return;
}
contribTable.editCellAt(contribTable.getSelectedRow(), contribTable.getSelectedColumn());
}
});
{
TableColumnModel tcm = contribTable.getColumnModel();
TableColumn col = tcm.getColumn(DESCRIPTION_COL);
col.setCellRenderer(createCellRenderer());
cellEditor = createCellEditor();
col.setCellEditor(cellEditor);
col.setCellEditor(createCellEditor());
col.setResizable(true);
}
@ -241,8 +253,10 @@ public abstract class InstallerJDialog<T> extends JDialog {
categoryChooser.setEnabled(!visible);
contribTable.setEnabled(!visible);
errorMessageBox.setVisible(false);
cellEditor.setEnabled(!visible);
cellEditor.setStatus(status);
if (contribTable.getCellEditor() != null) {
((InstallerTableCell) contribTable.getCellEditor()).setEnabled(!visible);
((InstallerTableCell) contribTable.getCellEditor()).setStatus(status);
}
}
protected ActionListener categoryChooserActionListener = new ActionListener() {
@ -252,7 +266,9 @@ public abstract class InstallerJDialog<T> extends JDialog {
DropdownItem<T> selected = (DropdownItem<T>) categoryChooser.getSelectedItem();
if (categoryFilter == null || !categoryFilter.equals(selected)) {
categoryFilter = selected.getFilterPredicate();
cellEditor.stopCellEditing();
if (contribTable.getCellEditor() != null) {
contribTable.getCellEditor().stopCellEditing();
}
contribModel.updateIndexFilter(categoryFilter, filters);
}
}

View File

@ -0,0 +1,23 @@
package cc.arduino.contributions.ui.listeners;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
public abstract class AbstractKeyListener implements KeyListener {
@Override
public void keyTyped(KeyEvent keyEvent) {
}
@Override
public void keyPressed(KeyEvent keyEvent) {
}
@Override
public void keyReleased(KeyEvent keyEvent) {
}
}

View File

@ -0,0 +1,47 @@
package cc.arduino.contributions.ui.listeners;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
public class DelegatingKeyListener implements KeyListener {
private final Component delegate;
public DelegatingKeyListener(Component delegate) {
this.delegate = delegate;
}
@Override
public void keyTyped(final KeyEvent keyEvent) {
if (delegate.getKeyListeners() == null) {
return;
}
for (KeyListener listener : delegate.getKeyListeners()) {
listener.keyTyped(keyEvent);
}
}
@Override
public void keyPressed(KeyEvent keyEvent) {
if (delegate.getKeyListeners() == null) {
return;
}
for (KeyListener listener : delegate.getKeyListeners()) {
listener.keyPressed(keyEvent);
}
}
@Override
public void keyReleased(KeyEvent keyEvent) {
if (delegate.getKeyListeners() == null) {
return;
}
for (KeyListener listener : delegate.getKeyListeners()) {
listener.keyReleased(keyEvent);
}
}
}