Added enumeration ETable.ColumnSelection
and methods:
+ ETable.setColumnSelectionOn(int mouseButton, ColumnSelection selection
,
+ ETable.getColumnSelectionOn(int mouseButton)
and
+ ETable.showColumnSelectionDialog()
.
+
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.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.