diff --git a/o.n.swing.outline/apichanges.xml b/o.n.swing.outline/apichanges.xml --- a/o.n.swing.outline/apichanges.xml +++ b/o.n.swing.outline/apichanges.xml @@ -199,6 +199,24 @@ + + + Allow more detailed customization of whether popup menu or dialog + is displayed to select visible columns. + + + + + +

Added enumeration ETable.ColumnSelection and methods: + ETable.setColumnSelectionOn(int mouseButton, ColumnSelection selection, + ETable.getColumnSelectionOn(int mouseButton) and + ETable.showColumnSelectionDialog(). +

+
+ + +
diff --git a/o.n.swing.outline/manifest.mf b/o.n.swing.outline/manifest.mf --- a/o.n.swing.outline/manifest.mf +++ b/o.n.swing.outline/manifest.mf @@ -1,5 +1,5 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.swing.outline OpenIDE-Module-Localizing-Bundle: org/netbeans/swing/outline/Bundle.properties -OpenIDE-Module-Specification-Version: 1.16 +OpenIDE-Module-Specification-Version: 1.17 diff --git a/o.n.swing.outline/src/org/netbeans/swing/etable/ETable.java b/o.n.swing.outline/src/org/netbeans/swing/etable/ETable.java --- a/o.n.swing.outline/src/org/netbeans/swing/etable/ETable.java +++ b/o.n.swing.outline/src/org/netbeans/swing/etable/ETable.java @@ -253,14 +253,24 @@ */ private static TableColumnSelector defaultColumnSelector; - /** - * The column selection corner can use either dialog or popup menu. - */ - private boolean popupUsedFromTheCorner; + private final Object columnSelectionOnMouseClickLock = new Object(); + private ColumnSelection[] columnSelectionOnMouseClick = new ColumnSelection[] { + ColumnSelection.NO_SELECTION, // no button + ColumnSelection.DIALOG, // dialog on left-click + ColumnSelection.NO_SELECTION, // no action on middle button + ColumnSelection.POPUP, // popup on right-click + }; private boolean columnHidingAllowed = true; /** + * The visible column selection methods. + */ + public enum ColumnSelection { + NO_SELECTION, POPUP, DIALOG + } + + /** * Constructs a default JTable that is initialized with a default * data model, a default column model, and a default selection * model. @@ -1054,8 +1064,14 @@ b.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent me) { - if (me.getButton() == MouseEvent.BUTTON3) { - ColumnSelectionPanel.showColumnSelectionPopup(b, ETable.this); + ColumnSelection cs = getColumnSelectionOn(me.getButton()); + switch (cs) { + case POPUP: + ColumnSelectionPanel.showColumnSelectionPopup (b, ETable.this); + break; + case DIALOG: + ColumnSelectionPanel.showColumnSelectionDialog(ETable.this); + break; } } }); @@ -2245,16 +2261,27 @@ } } + private void showColumnSelection(MouseEvent me) { + ColumnSelection cs = getColumnSelectionOn(me.getButton()); + switch (cs) { + case POPUP: + ColumnSelectionPanel.showColumnSelectionPopup (me.getComponent (), me.getX(), me.getY(), ETable.this); + break; + case DIALOG: + ColumnSelectionPanel.showColumnSelectionDialog(ETable.this); + break; + } + } + /** - * Mouse listener attached to the JTableHeader of this table. Single - * click on the table header should trigger sorting on that column. - * Double click on the column divider automatically resizes the column. + * Mouse listener attached to the scroll pane of this table, handles the case + * when no columns are displayed. */ private class ColumnSelectionMouseListener extends MouseAdapter { @Override public void mouseClicked(MouseEvent me) { - if (me.getButton() == MouseEvent.BUTTON3) { - ColumnSelectionPanel.showColumnSelectionPopup (me.getComponent (), me.getX(), me.getY(), ETable.this); + if (me.getButton() != MouseEvent.BUTTON1) { + showColumnSelection(me); } } } @@ -2266,8 +2293,8 @@ private class HeaderMouseListener extends MouseAdapter { @Override public void mouseClicked(MouseEvent me) { - if (me.getButton() == MouseEvent.BUTTON3) { - ColumnSelectionPanel.showColumnSelectionPopup (me.getComponent (), me.getX(), me.getY(), ETable.this); + if (me.getButton() == MouseEvent.BUTTON3) { // Other buttons are reserved for sorting + showColumnSelection(me); return; } TableColumn resColumn = getResizingColumn(me.getPoint()); @@ -2673,16 +2700,83 @@ /** * The column selection corner can use either dialog or popup menu. + * + * @return true, when left mouse click invokes a popup menu, + * or false, when left mouse click opens a dialog for column selection. */ public boolean isPopupUsedFromTheCorner() { - return popupUsedFromTheCorner; + synchronized (columnSelectionOnMouseClickLock) { + ColumnSelection cs = columnSelectionOnMouseClick[1]; + return cs == ColumnSelection.POPUP; + } } /** - * The column selection corner can use either dialog or popup menu. + * The column selection corner can use either dialog or popup menu.
+ * This method is equivalent to {@link #setColumnSelectionOn(int, org.netbeans.swing.etable.ETable.ColumnSelection)} + * with arguments 1 and appropriate column selection constant. + * + * @param popupUsedFromTheCorner When true, left mouse click invokes a popup menu, + * when false, left mouse click opens a dialog for column selection. */ public void setPopupUsedFromTheCorner(boolean popupUsedFromTheCorner) { - this.popupUsedFromTheCorner = popupUsedFromTheCorner; + synchronized (columnSelectionOnMouseClickLock) { + columnSelectionOnMouseClick[1] = popupUsedFromTheCorner ? ColumnSelection.POPUP : ColumnSelection.DIALOG; + } + } + + /** + * Get the column selection method, that is displayed as a response to the + * mouse event. A popup with column selection menu, or column selection + * dialog can be displayed.
+ * By default, popup menu is displayed on button3 mouse click + * and dialog or popup menu is displayed on the corner + * button1 mouse action, depending on the value of {@link #isPopupUsedFromTheCorner()} + * + * @param mouseButton The button of the mouse event + * @return The column selection method. + * @since 1.17 + */ + public ColumnSelection getColumnSelectionOn(int mouseButton) { + if (mouseButton < 0) { + throw new IllegalArgumentException("Button = "+mouseButton); + } + synchronized (columnSelectionOnMouseClickLock) { + if (mouseButton >= columnSelectionOnMouseClick.length) { + return null; + } + return columnSelectionOnMouseClick[mouseButton]; + } + } + + /** + * Set if popup with column selection menu or column selection dialog + * should be displayed as a response to the mouse event.
+ * + * @param mouseButton The button of the mouse event + * @param selection The column selection method. + * @since 1.17 + */ + public void setColumnSelectionOn(int mouseButton, ColumnSelection selection) { + if (mouseButton < 0) { + throw new IllegalArgumentException("Button = "+mouseButton); + } + synchronized (columnSelectionOnMouseClickLock) { + if (mouseButton >= columnSelectionOnMouseClick.length) { + ColumnSelection[] csp = new ColumnSelection[mouseButton + 1]; + System.arraycopy(columnSelectionOnMouseClick, 0, csp, 0, columnSelectionOnMouseClick.length); + columnSelectionOnMouseClick = csp; + } + columnSelectionOnMouseClick[mouseButton] = selection; + } + } + + /** + * Shows dialog that allows to show/hide columns. + * @since 1.17 + */ + public final void showColumnSelectionDialog() { + ColumnSelectionPanel.showColumnSelectionDialog(this); } /**