Changeset 4322
- Timestamp:
- 2003-05-23T16:53:57+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/gui/MetaEditPane.java
r4309 r4322 467 467 table.setColumnSelectionAllowed(false); 468 468 469 // The default JTable doesn't quite have the desired properties - when a 470 // table cell is clicked on, the table is scrolled so the cell is as 471 // visible as possible. This means that the left-most cells can become 472 // hidden. To fix this, the MouseInputHandler in BasicTableUI is removed 473 // as a MouseListener on the table, and a very slightly altered copy is 474 // added in its place (TableMouseInputHandler). 475 MouseListener[] mls = table.getMouseListeners(); 476 for (int i = 0; i < mls.length; i++) { 477 // Remove the instances of MouseInputHandler 478 if (mls[i].toString().startsWith("javax.swing.plaf.basic.BasicTableUI$MouseInputHandler@")) { 479 table.removeMouseListener(mls[i]); 480 } 481 } 482 // Add the slightly-altered mouse listener 483 table.addMouseListener(new TableMouseInputHandler()); 484 469 485 JScrollPane table_scroll = new JScrollPane(table); 470 486 table_scroll.getViewport().setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false)); … … 792 808 } 793 809 810 811 /** A direct copy of javax.swing.plaf.basic.BasicTableUI$MouseInputHandler, except for one change in adjustFocusAndSelection(). The purpose of this change is to always keep the left-most cells of the table row selected visible. */ 812 private class TableMouseInputHandler implements MouseInputListener 813 { 814 // Component receiving mouse events during editing. 815 // May not be editorComponent. 816 private Component dispatchComponent; 817 private boolean selectedOnPress; 818 819 // The Table's mouse listener methods. 820 821 public void mouseClicked(MouseEvent e) {} 822 823 private void setDispatchComponent(MouseEvent e) { 824 Component editorComponent = table.getEditorComponent(); 825 Point p = e.getPoint(); 826 Point p2 = SwingUtilities.convertPoint(table, p, editorComponent); 827 dispatchComponent = SwingUtilities.getDeepestComponentAt(editorComponent, 828 p2.x, p2.y); 829 } 830 831 private boolean repostEvent(MouseEvent e) { 832 // Check for isEditing() in case another event has 833 // caused the editor to be removed. See bug #4306499. 834 if (dispatchComponent == null || !table.isEditing()) { 835 return false; 836 } 837 MouseEvent e2 = SwingUtilities.convertMouseEvent(table, e, dispatchComponent); 838 dispatchComponent.dispatchEvent(e2); 839 return true; 840 } 841 842 private void setValueIsAdjusting(boolean flag) { 843 table.getSelectionModel().setValueIsAdjusting(flag); 844 table.getColumnModel().getSelectionModel().setValueIsAdjusting(flag); 845 } 846 847 private boolean shouldIgnore(MouseEvent e) { 848 return e.isConsumed() || (!(SwingUtilities.isLeftMouseButton(e) && table.isEnabled())); 849 } 850 851 public void mousePressed(MouseEvent e) { 852 if (e.isConsumed()) { 853 selectedOnPress = false; 854 return; 855 } 856 selectedOnPress = true; 857 adjustFocusAndSelection(e); 858 } 859 860 void adjustFocusAndSelection(MouseEvent e) { 861 if (shouldIgnore(e)) { 862 return; 863 } 864 865 Point p = e.getPoint(); 866 int row = table.rowAtPoint(p); 867 int column = table.columnAtPoint(p); 868 // The autoscroller can generate drag events outside the Table's range. 869 if ((column == -1) || (row == -1)) { 870 return; 871 } 872 873 if (table.editCellAt(row, column, e)) { 874 setDispatchComponent(e); 875 repostEvent(e); 876 } 877 else if (table.isRequestFocusEnabled()) { 878 table.requestFocus(); 879 } 880 881 CellEditor editor = table.getCellEditor(); 882 if (editor == null || editor.shouldSelectCell(e)) { 883 boolean adjusting = (e.getID() == MouseEvent.MOUSE_PRESSED) ? true : false; 884 setValueIsAdjusting(adjusting); 885 table.changeSelection(row, 0, e.isControlDown(), e.isShiftDown()); 886 // table.changeSelection(row, column, e.isControlDown(), e.isShiftDown()); 887 } 888 } 889 890 public void mouseReleased(MouseEvent e) { 891 if (selectedOnPress) { 892 if (shouldIgnore(e)) { 893 return; 894 } 895 896 repostEvent(e); 897 dispatchComponent = null; 898 setValueIsAdjusting(false); 899 } else { 900 adjustFocusAndSelection(e); 901 } 902 } 903 904 905 public void mouseEntered(MouseEvent e) {} 906 907 public void mouseExited(MouseEvent e) {} 908 909 // The Table's mouse motion listener methods. 910 911 public void mouseMoved(MouseEvent e) {} 912 913 public void mouseDragged(MouseEvent e) { 914 if (shouldIgnore(e)) { 915 return; 916 } 917 918 repostEvent(e); 919 920 CellEditor editor = table.getCellEditor(); 921 if (editor == null || editor.shouldSelectCell(e)) { 922 Point p = e.getPoint(); 923 int row = table.rowAtPoint(p); 924 int column = table.columnAtPoint(p); 925 // The autoscroller can generate drag events outside the Table's range. 926 if ((column == -1) || (row == -1)) { 927 return; 928 } 929 table.changeSelection(row, column, false, true); 930 } 931 } 932 } 933 934 794 935 /** A listener for right mouse button clicks over the collection tree. */ 795 936 private class RightButtonListener
Note:
See TracChangeset
for help on using the changeset viewer.