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,23 @@ + + + Allow more detailed customization of whether popup menu or dialog + is displayed to select visible columns. + + + + + +

Added ETable.setColumnSelectionPopupOn(int mouseButton, Boolean popup), + ETable.isColumnSelectionPopupOn(int mouseButton) and + ETable.showColumnSelectionDialog() methods. +

+
+ + +
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,10 +253,13 @@ */ private static TableColumnSelector defaultColumnSelector; - /** - * The column selection corner can use either dialog or popup menu. - */ - private boolean popupUsedFromTheCorner; + private final Object columnSelectionPopupLock = new Object(); + private Boolean[] columnSelectionPopup = new Boolean[] { + null, // no button + Boolean.FALSE, // dialog on left-click + null, // no action on middle button + Boolean.TRUE, // popup on right-click + }; private boolean columnHidingAllowed = true; @@ -1054,8 +1057,11 @@ b.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent me) { - if (me.getButton() == MouseEvent.BUTTON3) { + Boolean isPopup = isColumnSelectionPopupOn(me.getButton()); + if (Boolean.TRUE.equals(isPopup)) { ColumnSelectionPanel.showColumnSelectionPopup(b, ETable.this); + } else if (Boolean.FALSE.equals(isPopup)) { + ColumnSelectionPanel.showColumnSelectionDialog(ETable.this); } } }); @@ -2246,14 +2252,19 @@ } /** - * 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) { + if (me.getButton() != MouseEvent.BUTTON1) { + Boolean isPopup = isColumnSelectionPopupOn(me.getButton()); + if (Boolean.TRUE.equals(isPopup)) { + ColumnSelectionPanel.showColumnSelectionPopup (me.getComponent (), me.getX(), me.getY(), ETable.this); + } else if (Boolean.FALSE.equals(isPopup)) { + ColumnSelectionPanel.showColumnSelectionDialog(ETable.this); + } ColumnSelectionPanel.showColumnSelectionPopup (me.getComponent (), me.getX(), me.getY(), ETable.this); } } @@ -2266,8 +2277,13 @@ 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 + Boolean isPopup = isColumnSelectionPopupOn(MouseEvent.BUTTON3); + if (Boolean.TRUE.equals(isPopup)) { + ColumnSelectionPanel.showColumnSelectionPopup (me.getComponent (), me.getX(), me.getY(), ETable.this); + } else if (Boolean.FALSE.equals(isPopup)) { + ColumnSelectionPanel.showColumnSelectionDialog(ETable.this); + } return; } TableColumn resColumn = getResizingColumn(me.getPoint()); @@ -2673,16 +2689,86 @@ /** * 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 (columnSelectionPopupLock) { + Boolean popupUsedFromTheCorner = columnSelectionPopup[1]; + return (popupUsedFromTheCorner != null) ? popupUsedFromTheCorner.booleanValue() : false; + } } /** - * 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 #setColumnSelectionPopupOn(int, java.lang.Boolean)} + * with arguments 3 and popupUsedFromTheCorner. + * + * @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 (columnSelectionPopupLock) { + columnSelectionPopup[1] = popupUsedFromTheCorner ? Boolean.TRUE : Boolean.FALSE; + } + } + + /** + * Test if the popup with column selection menu or column selection dialog + * is displayed as a response to the mouse event.
+ * 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 Boolean.TRUE when popup menu is displayed, + * Boolean.FALSE when dialog is displayed, + * null when nothing is displayed. + * @since 1.17 + */ + public Boolean isColumnSelectionPopupOn(int mouseButton) { + if (mouseButton < 0) { + throw new IllegalArgumentException("Button = "+mouseButton); + } + synchronized (columnSelectionPopupLock) { + if (mouseButton >= columnSelectionPopup.length) { + return null; + } + return columnSelectionPopup[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 popup Boolean.TRUE when popup menu should be displayed, + * Boolean.FALSE when dialog should be displayed, + * null when nothing should be displayed. + * @since 1.17 + */ + public void setColumnSelectionPopupOn(int mouseButton, Boolean popup) { + if (mouseButton < 0) { + throw new IllegalArgumentException("Button = "+mouseButton); + } + synchronized (columnSelectionPopupLock) { + if (mouseButton >= columnSelectionPopup.length) { + Boolean[] csp = new Boolean[mouseButton + 1]; + System.arraycopy(columnSelectionPopup, 0, csp, 0, columnSelectionPopup.length); + columnSelectionPopup = csp; + } + columnSelectionPopup[mouseButton] = popup; + } + } + + /** + * Shows dialog that allows to show/hide columns. + * @since 1.17 + */ + public final void showColumnSelectionDialog() { + ColumnSelectionPanel.showColumnSelectionDialog(this); } /**