Lines 253-266
Link Here
|
253 |
*/ |
253 |
*/ |
254 |
private static TableColumnSelector defaultColumnSelector; |
254 |
private static TableColumnSelector defaultColumnSelector; |
255 |
|
255 |
|
256 |
/** |
256 |
private final Object columnSelectionOnMouseClickLock = new Object(); |
257 |
* The column selection corner can use either dialog or popup menu. |
257 |
private ColumnSelection[] columnSelectionOnMouseClick = new ColumnSelection[] { |
258 |
*/ |
258 |
ColumnSelection.NO_SELECTION, // no button |
259 |
private boolean popupUsedFromTheCorner; |
259 |
ColumnSelection.DIALOG, // dialog on left-click |
|
|
260 |
ColumnSelection.NO_SELECTION, // no action on middle button |
261 |
ColumnSelection.POPUP, // popup on right-click |
262 |
}; |
260 |
|
263 |
|
261 |
private boolean columnHidingAllowed = true; |
264 |
private boolean columnHidingAllowed = true; |
262 |
|
265 |
|
263 |
/** |
266 |
/** |
|
|
267 |
* The visible column selection methods. |
268 |
*/ |
269 |
public enum ColumnSelection { |
270 |
NO_SELECTION, POPUP, DIALOG |
271 |
} |
272 |
|
273 |
/** |
264 |
* Constructs a default <code>JTable</code> that is initialized with a default |
274 |
* Constructs a default <code>JTable</code> that is initialized with a default |
265 |
* data model, a default column model, and a default selection |
275 |
* data model, a default column model, and a default selection |
266 |
* model. |
276 |
* model. |
Lines 1054-1061
Link Here
|
1054 |
b.addMouseListener(new MouseAdapter() { |
1064 |
b.addMouseListener(new MouseAdapter() { |
1055 |
@Override |
1065 |
@Override |
1056 |
public void mouseClicked(MouseEvent me) { |
1066 |
public void mouseClicked(MouseEvent me) { |
1057 |
if (me.getButton() == MouseEvent.BUTTON3) { |
1067 |
ColumnSelection cs = getColumnSelectionOn(me.getButton()); |
1058 |
ColumnSelectionPanel.showColumnSelectionPopup(b, ETable.this); |
1068 |
switch (cs) { |
|
|
1069 |
case POPUP: |
1070 |
ColumnSelectionPanel.showColumnSelectionPopup (b, ETable.this); |
1071 |
break; |
1072 |
case DIALOG: |
1073 |
ColumnSelectionPanel.showColumnSelectionDialog(ETable.this); |
1074 |
break; |
1059 |
} |
1075 |
} |
1060 |
} |
1076 |
} |
1061 |
}); |
1077 |
}); |
Lines 2245-2260
Link Here
|
2245 |
} |
2261 |
} |
2246 |
} |
2262 |
} |
2247 |
|
2263 |
|
|
|
2264 |
private void showColumnSelection(MouseEvent me) { |
2265 |
ColumnSelection cs = getColumnSelectionOn(me.getButton()); |
2266 |
switch (cs) { |
2267 |
case POPUP: |
2268 |
ColumnSelectionPanel.showColumnSelectionPopup (me.getComponent (), me.getX(), me.getY(), ETable.this); |
2269 |
break; |
2270 |
case DIALOG: |
2271 |
ColumnSelectionPanel.showColumnSelectionDialog(ETable.this); |
2272 |
break; |
2273 |
} |
2274 |
} |
2275 |
|
2248 |
/** |
2276 |
/** |
2249 |
* Mouse listener attached to the JTableHeader of this table. Single |
2277 |
* Mouse listener attached to the scroll pane of this table, handles the case |
2250 |
* click on the table header should trigger sorting on that column. |
2278 |
* when no columns are displayed. |
2251 |
* Double click on the column divider automatically resizes the column. |
|
|
2252 |
*/ |
2279 |
*/ |
2253 |
private class ColumnSelectionMouseListener extends MouseAdapter { |
2280 |
private class ColumnSelectionMouseListener extends MouseAdapter { |
2254 |
@Override |
2281 |
@Override |
2255 |
public void mouseClicked(MouseEvent me) { |
2282 |
public void mouseClicked(MouseEvent me) { |
2256 |
if (me.getButton() == MouseEvent.BUTTON3) { |
2283 |
if (me.getButton() != MouseEvent.BUTTON1) { |
2257 |
ColumnSelectionPanel.showColumnSelectionPopup (me.getComponent (), me.getX(), me.getY(), ETable.this); |
2284 |
showColumnSelection(me); |
2258 |
} |
2285 |
} |
2259 |
} |
2286 |
} |
2260 |
} |
2287 |
} |
Lines 2266-2273
Link Here
|
2266 |
private class HeaderMouseListener extends MouseAdapter { |
2293 |
private class HeaderMouseListener extends MouseAdapter { |
2267 |
@Override |
2294 |
@Override |
2268 |
public void mouseClicked(MouseEvent me) { |
2295 |
public void mouseClicked(MouseEvent me) { |
2269 |
if (me.getButton() == MouseEvent.BUTTON3) { |
2296 |
if (me.getButton() == MouseEvent.BUTTON3) { // Other buttons are reserved for sorting |
2270 |
ColumnSelectionPanel.showColumnSelectionPopup (me.getComponent (), me.getX(), me.getY(), ETable.this); |
2297 |
showColumnSelection(me); |
2271 |
return; |
2298 |
return; |
2272 |
} |
2299 |
} |
2273 |
TableColumn resColumn = getResizingColumn(me.getPoint()); |
2300 |
TableColumn resColumn = getResizingColumn(me.getPoint()); |
Lines 2673-2688
Link Here
|
2673 |
|
2700 |
|
2674 |
/** |
2701 |
/** |
2675 |
* The column selection corner can use either dialog or popup menu. |
2702 |
* The column selection corner can use either dialog or popup menu. |
|
|
2703 |
* |
2704 |
* @return <code>true</code>, when left mouse click invokes a popup menu, |
2705 |
* or <code>false</code>, when left mouse click opens a dialog for column selection. |
2676 |
*/ |
2706 |
*/ |
2677 |
public boolean isPopupUsedFromTheCorner() { |
2707 |
public boolean isPopupUsedFromTheCorner() { |
2678 |
return popupUsedFromTheCorner; |
2708 |
synchronized (columnSelectionOnMouseClickLock) { |
|
|
2709 |
ColumnSelection cs = columnSelectionOnMouseClick[1]; |
2710 |
return cs == ColumnSelection.POPUP; |
2711 |
} |
2679 |
} |
2712 |
} |
2680 |
|
2713 |
|
2681 |
/** |
2714 |
/** |
2682 |
* The column selection corner can use either dialog or popup menu. |
2715 |
* The column selection corner can use either dialog or popup menu.<br/> |
|
|
2716 |
* This method is equivalent to {@link #setColumnSelectionOn(int, org.netbeans.swing.etable.ETable.ColumnSelection)} |
2717 |
* with arguments <code>1</code> and appropriate column selection constant. |
2718 |
* |
2719 |
* @param popupUsedFromTheCorner When <code>true</code>, left mouse click invokes a popup menu, |
2720 |
* when <code>false</code>, left mouse click opens a dialog for column selection. |
2683 |
*/ |
2721 |
*/ |
2684 |
public void setPopupUsedFromTheCorner(boolean popupUsedFromTheCorner) { |
2722 |
public void setPopupUsedFromTheCorner(boolean popupUsedFromTheCorner) { |
2685 |
this.popupUsedFromTheCorner = popupUsedFromTheCorner; |
2723 |
synchronized (columnSelectionOnMouseClickLock) { |
|
|
2724 |
columnSelectionOnMouseClick[1] = popupUsedFromTheCorner ? ColumnSelection.POPUP : ColumnSelection.DIALOG; |
2725 |
} |
2726 |
} |
2727 |
|
2728 |
/** |
2729 |
* Get the column selection method, that is displayed as a response to the |
2730 |
* mouse event. A popup with column selection menu, or column selection |
2731 |
* dialog can be displayed.<br/> |
2732 |
* By default, popup menu is displayed on button3 mouse click |
2733 |
* and dialog or popup menu is displayed on the corner |
2734 |
* button1 mouse action, depending on the value of {@link #isPopupUsedFromTheCorner()} |
2735 |
* |
2736 |
* @param mouseButton The button of the mouse event |
2737 |
* @return The column selection method. |
2738 |
* @since 1.17 |
2739 |
*/ |
2740 |
public ColumnSelection getColumnSelectionOn(int mouseButton) { |
2741 |
if (mouseButton < 0) { |
2742 |
throw new IllegalArgumentException("Button = "+mouseButton); |
2743 |
} |
2744 |
synchronized (columnSelectionOnMouseClickLock) { |
2745 |
if (mouseButton >= columnSelectionOnMouseClick.length) { |
2746 |
return null; |
2747 |
} |
2748 |
return columnSelectionOnMouseClick[mouseButton]; |
2749 |
} |
2750 |
} |
2751 |
|
2752 |
/** |
2753 |
* Set if popup with column selection menu or column selection dialog |
2754 |
* should be displayed as a response to the mouse event.<br/> |
2755 |
* |
2756 |
* @param mouseButton The button of the mouse event |
2757 |
* @param selection The column selection method. |
2758 |
* @since 1.17 |
2759 |
*/ |
2760 |
public void setColumnSelectionOn(int mouseButton, ColumnSelection selection) { |
2761 |
if (mouseButton < 0) { |
2762 |
throw new IllegalArgumentException("Button = "+mouseButton); |
2763 |
} |
2764 |
synchronized (columnSelectionOnMouseClickLock) { |
2765 |
if (mouseButton >= columnSelectionOnMouseClick.length) { |
2766 |
ColumnSelection[] csp = new ColumnSelection[mouseButton + 1]; |
2767 |
System.arraycopy(columnSelectionOnMouseClick, 0, csp, 0, columnSelectionOnMouseClick.length); |
2768 |
columnSelectionOnMouseClick = csp; |
2769 |
} |
2770 |
columnSelectionOnMouseClick[mouseButton] = selection; |
2771 |
} |
2772 |
} |
2773 |
|
2774 |
/** |
2775 |
* Shows dialog that allows to show/hide columns. |
2776 |
* @since 1.17 |
2777 |
*/ |
2778 |
public final void showColumnSelectionDialog() { |
2779 |
ColumnSelectionPanel.showColumnSelectionDialog(this); |
2686 |
} |
2780 |
} |
2687 |
|
2781 |
|
2688 |
/** |
2782 |
/** |