1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-01 12:24:14 +01:00

Add on-hover selection on Board/Library manager

User testing on skilled devs showed that "buttons appear on click" behaviour is far from being understood.
Accessibility features (like moving with Arrow keys) should be untouched.
This commit is contained in:
Martino Facchin 2017-10-02 16:29:07 +02:00
parent a47e62627c
commit 60f267745b
7 changed files with 56 additions and 8 deletions

View File

@ -76,9 +76,12 @@ public class ContributedLibraryTableCellEditor extends InstallerTableCell {
ContributedLibrary lib = (ContributedLibrary) chooser.getSelectedItem();
onInstall(lib, editorValue.getInstalled());
});
editorCell.versionToInstallChooser.addItemListener(e -> editorValue
.select((ContributedLibrary) editorCell.versionToInstallChooser
.getSelectedItem()));
editorCell.versionToInstallChooser.addActionListener(e -> {
editorValue.select((ContributedLibrary) editorCell.versionToInstallChooser.getSelectedItem());
if (editorCell.versionToInstallChooser.getSelectedIndex() != 0) {
InstallerTableCell.dropdownSelected(true);
}
});
setEnabled(true);

View File

@ -54,10 +54,13 @@ public class ContributedLibraryTableCellJPanel extends JPanel {
downgradeChooser.addItem("-");
downgradeChooser.setMaximumSize(new Dimension((int)downgradeChooser.getPreferredSize().getWidth() + 50, (int)downgradeChooser.getPreferredSize().getHeight()));
downgradeChooser.setMinimumSize(new Dimension((int)downgradeChooser.getPreferredSize().getWidth() + 50, (int)downgradeChooser.getPreferredSize().getHeight()));
downgradeChooser.addItemListener(e -> {
downgradeChooser.addActionListener(e -> {
Object selectVersionItem = downgradeChooser.getItemAt(0);
boolean disableDowngrade = (e.getItem() == selectVersionItem);
boolean disableDowngrade = (downgradeChooser.getSelectedItem() == selectVersionItem);
downgradeButton.setEnabled(!disableDowngrade);
if (!disableDowngrade) {
InstallerTableCell.dropdownSelected(true);
}
});
versionToInstallChooser = new JComboBox();

View File

@ -117,6 +117,7 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibrary> {
@Override
public void actionPerformed(ActionEvent event) {
DropdownItem<ContributedLibrary> selected = (DropdownItem<ContributedLibrary>) typeChooser.getSelectedItem();
previousRowAtPoint = -1;
if (typeFilter == null || !typeFilter.equals(selected)) {
typeFilter = selected.getFilterPredicate();
if (contribTable.getCellEditor() != null) {

View File

@ -74,9 +74,12 @@ public class ContributedPlatformTableCellEditor extends InstallerTableCell {
.getSelectedItem();
onInstall(selected, value.getInstalled());
});
cell.versionToInstallChooser.addItemListener(e -> value
.select((ContributedPlatform) cell.versionToInstallChooser
.getSelectedItem()));
cell.versionToInstallChooser.addActionListener(e -> {
value.select((ContributedPlatform) cell.versionToInstallChooser.getSelectedItem());
if (cell.versionToInstallChooser.getSelectedIndex() != 0) {
InstallerTableCell.dropdownSelected(true);
}
});
setEnabled(true);

View File

@ -98,6 +98,9 @@ public class ContributedPlatformTableCellJPanel extends JPanel {
Object selectVersionItem = downgradeChooser.getItemAt(0);
boolean disableDowngrade = (e.getItem() == selectVersionItem);
downgradeButton.setEnabled(!disableDowngrade);
if (!disableDowngrade) {
InstallerTableCell.dropdownSelected(true);
}
});
versionToInstallChooser = new JComboBox();

View File

@ -43,6 +43,8 @@ import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.util.function.Predicate;
import java.util.stream.Stream;
@ -88,6 +90,8 @@ public abstract class InstallerJDialog<T> extends JDialog {
private final JButton closeButton;
private final JButton dismissErrorMessageButton;
protected int previousRowAtPoint = -1;
abstract protected FilteredAbstractTableModel<T> createContribModel();
abstract protected TableCellRenderer createCellRenderer();
@ -118,6 +122,7 @@ public abstract class InstallerJDialog<T> extends JDialog {
filterField = new FilterJTextField(tr("Filter your search...")) {
@Override
protected void onFilter(String[] _filters) {
previousRowAtPoint = -1;
filters = _filters;
if (contribTable.getCellEditor() != null) {
contribTable.getCellEditor().stopCellEditing();
@ -167,6 +172,25 @@ public abstract class InstallerJDialog<T> extends JDialog {
}
});
contribTable.addMouseMotionListener(new MouseMotionListener() {
public void mouseDragged(MouseEvent e) {}
public void mouseMoved(MouseEvent e) {
// avoid firing edits events until the mouse changes cell or the user is back on the cell after selecting a dropdown
int rowAtPoint = contribTable.rowAtPoint(e.getPoint());
if (!InstallerTableCell.isDropdownSelected() && rowAtPoint != previousRowAtPoint) {
contribTable.editCellAt(rowAtPoint, 0);
previousRowAtPoint = rowAtPoint;
InstallerTableCell.dropdownSelected(false);
}
if (InstallerTableCell.isDropdownSelected() && rowAtPoint == previousRowAtPoint) {
// back to the original cell, can drop dropdown selector lock
InstallerTableCell.dropdownSelected(false);
}
}
});
{
TableColumnModel tcm = contribTable.getColumnModel();
TableColumn col = tcm.getColumn(0);
@ -286,6 +310,7 @@ public abstract class InstallerJDialog<T> extends JDialog {
@Override
public void actionPerformed(ActionEvent event) {
DropdownItem<T> selected = (DropdownItem<T>) categoryChooser.getSelectedItem();
previousRowAtPoint = -1;
if (categoryFilter == null || !categoryFilter.equals(selected)) {
categoryFilter = selected.getFilterPredicate();
if (contribTable.getCellEditor() != null) {

View File

@ -41,6 +41,16 @@ public abstract class InstallerTableCell extends AbstractCellEditor implements T
abstract public void setEnabled(boolean b);
private static boolean dropdownSelected = false;
public static boolean isDropdownSelected( ) {
return dropdownSelected;
}
public static void dropdownSelected(boolean b) {
dropdownSelected = b;
}
abstract public void setStatus(String s);
public static void setJTextPaneDimensionToFitContainedText(JTextPane jTextPane, int width) {