1 7 8 package javax.swing.table; 9 10 import java.util.*; 11 import java.awt.*; 12 import java.awt.event.*; 13 14 import javax.swing.*; 15 import javax.swing.event.*; 16 import javax.swing.plaf.*; 17 import javax.accessibility.*; 18 19 import java.beans.PropertyChangeListener ; 20 21 import java.io.ObjectOutputStream ; 22 import java.io.ObjectInputStream ; 23 import java.io.IOException ; 24 25 26 43 public class JTableHeader extends JComponent implements TableColumnModelListener, Accessible 44 { 45 49 private static final String uiClassID = "TableHeaderUI"; 50 51 58 protected JTable table; 59 60 63 protected TableColumnModel columnModel; 64 65 69 protected boolean reorderingAllowed; 70 71 75 protected boolean resizingAllowed; 76 77 81 85 protected boolean updateTableInRealTime; 86 87 88 transient protected TableColumn resizingColumn; 89 90 91 transient protected TableColumn draggedColumn; 92 93 94 transient protected int draggedDistance; 95 96 100 private TableCellRenderer defaultRenderer; 101 102 106 112 public JTableHeader() { 113 this(null); 114 } 115 116 125 public JTableHeader(TableColumnModel cm) { 126 super(); 127 128 setFocusable(false); 129 130 if (cm == null) 131 cm = createDefaultColumnModel(); 132 setColumnModel(cm); 133 134 initializeLocalVars(); 136 137 updateUI(); 139 } 140 141 145 152 public void setTable(JTable table) { 153 JTable old = this.table; 154 this.table = table; 155 firePropertyChange("table", old, table); 156 } 157 158 162 public JTable getTable() { 163 return table; 164 } 165 166 176 public void setReorderingAllowed(boolean reorderingAllowed) { 177 boolean old = this.reorderingAllowed; 178 this.reorderingAllowed = reorderingAllowed; 179 firePropertyChange("reorderingAllowed", old, reorderingAllowed); 180 } 181 182 190 public boolean getReorderingAllowed() { 191 return reorderingAllowed; 192 } 193 194 204 public void setResizingAllowed(boolean resizingAllowed) { 205 boolean old = this.resizingAllowed; 206 this.resizingAllowed = resizingAllowed; 207 firePropertyChange("resizingAllowed", old, resizingAllowed); 208 } 209 210 218 public boolean getResizingAllowed() { 219 return resizingAllowed; 220 } 221 222 230 public TableColumn getDraggedColumn() { 231 return draggedColumn; 232 } 233 234 244 public int getDraggedDistance() { 245 return draggedDistance; 246 } 247 248 255 public TableColumn getResizingColumn() { 256 return resizingColumn; 257 } 258 259 263 271 public void setUpdateTableInRealTime(boolean flag) { 272 updateTableInRealTime = flag; 273 } 274 275 279 288 public boolean getUpdateTableInRealTime() { 289 return updateTableInRealTime; 290 } 291 292 297 public void setDefaultRenderer(TableCellRenderer defaultRenderer) { 298 this.defaultRenderer = defaultRenderer; 299 } 300 301 306 public TableCellRenderer getDefaultRenderer() { 307 return defaultRenderer; 308 } 309 310 317 public int columnAtPoint(Point point) { 318 int x = point.x; 319 if (!getComponentOrientation().isLeftToRight()) { 320 x = getWidthInRightToLeft() - x; 321 } 322 return getColumnModel().getColumnIndexAtX(x); 323 } 324 325 333 public Rectangle getHeaderRect(int column) { 334 Rectangle r = new Rectangle(); 335 TableColumnModel cm = getColumnModel(); 336 337 r.height = getHeight(); 338 339 if (column < 0) { 340 if( !getComponentOrientation().isLeftToRight() ) { 342 r.x = getWidthInRightToLeft(); 343 } 344 } 345 else if (column >= cm.getColumnCount()) { 346 if( getComponentOrientation().isLeftToRight() ) { 347 r.x = getWidth(); 348 } 349 } 350 else { 351 for(int i = 0; i < column; i++) { 352 r.x += cm.getColumn(i).getWidth(); 353 } 354 if( !getComponentOrientation().isLeftToRight() ) { 355 r.x = getWidthInRightToLeft() - r.x - cm.getColumn(column).getWidth(); 356 } 357 358 r.width = cm.getColumn(column).getWidth(); 359 } 360 return r; 361 } 362 363 364 370 public String getToolTipText(MouseEvent event) { 371 String tip = null; 372 Point p = event.getPoint(); 373 int column; 374 375 if ((column = columnAtPoint(p)) != -1) { 377 TableColumn aColumn = columnModel.getColumn(column); 378 TableCellRenderer renderer = aColumn.getHeaderRenderer(); 379 if (renderer == null) { 380 renderer = defaultRenderer; 381 } 382 Component component = renderer.getTableCellRendererComponent( 383 getTable(), aColumn.getHeaderValue(), false, false, 384 -1, column); 385 386 if (component instanceof JComponent) { 389 MouseEvent newEvent; 391 Rectangle cellRect = getHeaderRect(column); 392 393 p.translate(-cellRect.x, -cellRect.y); 394 newEvent = new MouseEvent(component, event.getID(), 395 event.getWhen(), event.getModifiers(), 396 p.x, p.y, event.getClickCount(), 397 event.isPopupTrigger()); 398 399 tip = ((JComponent)component).getToolTipText(newEvent); 400 } 401 } 402 403 if (tip == null) 405 tip = getToolTipText(); 406 407 return tip; 408 } 409 410 414 419 public TableHeaderUI getUI() { 420 return (TableHeaderUI)ui; 421 } 422 423 429 public void setUI(TableHeaderUI ui){ 430 if (this.ui != ui) { 431 super.setUI(ui); 432 repaint(); 433 } 434 } 435 436 444 public void updateUI(){ 445 setUI((TableHeaderUI)UIManager.getUI(this)); 446 resizeAndRepaint(); 447 invalidate(); } 449 450 451 460 public String getUIClassID() { 461 return uiClassID; 462 } 463 464 465 469 470 482 public void setColumnModel(TableColumnModel columnModel) { 483 if (columnModel == null) { 484 throw new IllegalArgumentException ("Cannot set a null ColumnModel"); 485 } 486 TableColumnModel old = this.columnModel; 487 if (columnModel != old) { 488 if (old != null) { 489 old.removeColumnModelListener(this); 490 } 491 this.columnModel = columnModel; 492 columnModel.addColumnModelListener(this); 493 494 firePropertyChange("columnModel", old, columnModel); 495 resizeAndRepaint(); 496 } 497 } 498 499 506 public TableColumnModel getColumnModel() { 507 return columnModel; 508 } 509 510 514 523 public void columnAdded(TableColumnModelEvent e) { resizeAndRepaint(); } 524 525 526 535 public void columnRemoved(TableColumnModelEvent e) { resizeAndRepaint(); } 536 537 538 547 public void columnMoved(TableColumnModelEvent e) { repaint(); } 548 549 550 559 public void columnMarginChanged(ChangeEvent e) { resizeAndRepaint(); } 560 561 562 576 public void columnSelectionChanged(ListSelectionEvent e) { } 578 582 589 protected TableColumnModel createDefaultColumnModel() { 590 return new DefaultTableColumnModel (); 591 } 592 593 599 protected TableCellRenderer createDefaultRenderer() { 600 DefaultTableCellRenderer label = new UIResourceTableCellRenderer(); 601 label.setHorizontalAlignment(JLabel.CENTER); 602 return label; 603 } 604 605 private static class UIResourceTableCellRenderer extends DefaultTableCellRenderer implements UIResource { 606 public Component getTableCellRendererComponent(JTable table, Object value, 607 boolean isSelected, boolean hasFocus, int row, int column) { 608 if (table != null) { 609 JTableHeader header = table.getTableHeader(); 610 if (header != null) { 611 setForeground(header.getForeground()); 612 setBackground(header.getBackground()); 613 setFont(header.getFont()); 614 } 615 } 616 617 setText((value == null) ? "" : value.toString()); 618 setBorder(UIManager.getBorder("TableHeader.cellBorder")); 619 return this; 620 } 621 } 622 623 627 protected void initializeLocalVars() { 628 setOpaque(true); 629 table = null; 630 reorderingAllowed = true; 631 resizingAllowed = true; 632 draggedColumn = null; 633 draggedDistance = 0; 634 resizingColumn = null; 635 updateTableInRealTime = true; 636 637 ToolTipManager toolTipManager = ToolTipManager.sharedInstance(); 640 toolTipManager.registerComponent(this); 641 setDefaultRenderer(createDefaultRenderer()); 642 } 643 644 648 public void resizeAndRepaint() { 649 revalidate(); 650 repaint(); 651 } 652 653 662 public void setDraggedColumn(TableColumn aColumn) { 663 draggedColumn = aColumn; 664 } 665 666 670 public void setDraggedDistance(int distance) { 671 draggedDistance = distance; 672 } 673 674 683 public void setResizingColumn(TableColumn aColumn) { 684 resizingColumn = aColumn; 685 } 686 687 692 private void writeObject(ObjectOutputStream s) throws IOException { 693 s.defaultWriteObject(); 694 if ((ui != null) && (getUIClassID().equals(uiClassID))) { 695 ui.installUI(this); 696 } 697 } 698 699 private int getWidthInRightToLeft() { 700 if ((table != null) && 701 (table.getAutoResizeMode() != JTable.AUTO_RESIZE_OFF)) { 702 return table.getWidth(); 703 } 704 return super.getWidth(); 705 } 706 707 719 protected String paramString() { 720 String reorderingAllowedString = (reorderingAllowed ? 721 "true" : "false"); 722 String resizingAllowedString = (resizingAllowed ? 723 "true" : "false"); 724 String updateTableInRealTimeString = (updateTableInRealTime ? 725 "true" : "false"); 726 727 return super.paramString() + 728 ",draggedDistance=" + draggedDistance + 729 ",reorderingAllowed=" + reorderingAllowedString + 730 ",resizingAllowed=" + resizingAllowedString + 731 ",updateTableInRealTime=" + updateTableInRealTimeString; 732 } 733 734 738 747 public AccessibleContext getAccessibleContext() { 748 if (accessibleContext == null) { 749 accessibleContext = new AccessibleJTableHeader(); 750 } 751 return accessibleContext; 752 } 753 754 773 protected class AccessibleJTableHeader extends AccessibleJComponent { 774 775 782 public AccessibleRole getAccessibleRole() { 783 return AccessibleRole.PANEL; 784 } 785 786 795 public Accessible getAccessibleAt(Point p) { 796 int column; 797 798 if ((column = JTableHeader.this.columnAtPoint(p)) != -1) { 800 TableColumn aColumn = JTableHeader.this.columnModel.getColumn(column); 801 TableCellRenderer renderer = aColumn.getHeaderRenderer(); 802 if (renderer == null) { 803 if (defaultRenderer != null) { 804 renderer = defaultRenderer; 805 } else { 806 return null; 807 } 808 } 809 Component component = renderer.getTableCellRendererComponent( 810 JTableHeader.this.getTable(), 811 aColumn.getHeaderValue(), false, false, 812 -1, column); 813 814 return new AccessibleJTableHeaderEntry(column, JTableHeader.this, JTableHeader.this.table); 815 } else { 816 return null; 817 } 818 } 819 820 827 public int getAccessibleChildrenCount() { 828 return JTableHeader.this.columnModel.getColumnCount(); 829 } 830 831 837 public Accessible getAccessibleChild(int i) { 838 if (i < 0 || i >= getAccessibleChildrenCount()) { 839 return null; 840 } else { 841 TableColumn aColumn = JTableHeader.this.columnModel.getColumn(i) 842 ; 843 TableCellRenderer renderer = aColumn.getHeaderRenderer(); 844 if (renderer == null) { 845 if (defaultRenderer != null) { 846 renderer = defaultRenderer; 847 } else { 848 return null; 849 } 850 } 851 Component component = renderer.getTableCellRendererComponent( 852 JTableHeader.this.getTable(), 853 aColumn.getHeaderValue(), false, false, 854 -1, i); 855 856 return new AccessibleJTableHeaderEntry(i, JTableHeader.this, JTableHeader.this.table); 857 } 858 } 859 860 864 protected class AccessibleJTableHeaderEntry extends AccessibleContext 865 implements Accessible, AccessibleComponent { 866 867 private JTableHeader parent; 868 private int column; 869 private JTable table; 870 871 874 public AccessibleJTableHeaderEntry(int c, JTableHeader p, JTable t) { 875 parent = p; 876 column = c; 877 table = t; 878 this.setAccessibleParent(parent); 879 } 880 881 889 public AccessibleContext getAccessibleContext() { 890 return this; 891 } 892 893 private AccessibleContext getCurrentAccessibleContext() { 894 TableColumnModel tcm = table.getColumnModel(); 895 if (tcm != null) { 896 if (column < 0 || column >= tcm.getColumnCount()) { 899 return null; 900 } 901 TableColumn aColumn = tcm.getColumn(column); 902 TableCellRenderer renderer = aColumn.getHeaderRenderer(); 903 if (renderer == null) { 904 if (defaultRenderer != null) { 905 renderer = defaultRenderer; 906 } else { 907 return null; 908 } 909 } 910 Component c = renderer.getTableCellRendererComponent( 911 JTableHeader.this.getTable(), 912 aColumn.getHeaderValue(), false, false, 913 -1, column); 914 if (c instanceof Accessible) { 915 return ((Accessible) c).getAccessibleContext(); 916 } 917 } 918 return null; 919 } 920 921 private Component getCurrentComponent() { 922 TableColumnModel tcm = table.getColumnModel(); 923 if (tcm != null) { 924 if (column < 0 || column >= tcm.getColumnCount()) { 927 return null; 928 } 929 TableColumn aColumn = tcm.getColumn(column); 930 TableCellRenderer renderer = aColumn.getHeaderRenderer(); 931 if (renderer == null) { 932 if (defaultRenderer != null) { 933 renderer = defaultRenderer; 934 } else { 935 return null; 936 } 937 } 938 return renderer.getTableCellRendererComponent( 939 JTableHeader.this.getTable(), 940 aColumn.getHeaderValue(), false, false, 941 -1, column); 942 } else { 943 return null; 944 } 945 } 946 947 949 public String getAccessibleName() { 950 AccessibleContext ac = getCurrentAccessibleContext(); 951 if (ac != null) { 952 String name = ac.getAccessibleName(); 953 if ((name != null) && (name != "")) { 954 return ac.getAccessibleName(); 955 } 956 } 957 if ((accessibleName != null) && (accessibleName != "")) { 958 return accessibleName; 959 } else { 960 return table.getColumnName(column); 961 } 962 } 963 964 public void setAccessibleName(String s) { 965 AccessibleContext ac = getCurrentAccessibleContext(); 966 if (ac != null) { 967 ac.setAccessibleName(s); 968 } else { 969 super.setAccessibleName(s); 970 } 971 } 972 973 public String getAccessibleDescription() { 977 AccessibleContext ac = getCurrentAccessibleContext(); 978 if (ac != null) { 979 return ac.getAccessibleDescription(); 980 } else { 981 return super.getAccessibleDescription(); 982 } 983 } 984 985 public void setAccessibleDescription(String s) { 986 AccessibleContext ac = getCurrentAccessibleContext(); 987 if (ac != null) { 988 ac.setAccessibleDescription(s); 989 } else { 990 super.setAccessibleDescription(s); 991 } 992 } 993 994 public AccessibleRole getAccessibleRole() { 995 AccessibleContext ac = getCurrentAccessibleContext(); 996 if (ac != null) { 997 return ac.getAccessibleRole(); 998 } else { 999 return AccessibleRole.COLUMN_HEADER; 1000 } 1001 } 1002 1003 public AccessibleStateSet getAccessibleStateSet() { 1004 AccessibleContext ac = getCurrentAccessibleContext(); 1005 if (ac != null) { 1006 AccessibleStateSet states = ac.getAccessibleStateSet(); 1007 if (isShowing()) { 1008 states.add(AccessibleState.SHOWING); 1009 } 1010 return states; 1011 } else { 1012 return new AccessibleStateSet(); } 1014 } 1015 1016 public int getAccessibleIndexInParent() { 1017 return column; 1018 } 1019 1020 public int getAccessibleChildrenCount() { 1021 AccessibleContext ac = getCurrentAccessibleContext(); 1022 if (ac != null) { 1023 return ac.getAccessibleChildrenCount(); 1024 } else { 1025 return 0; 1026 } 1027 } 1028 1029 public Accessible getAccessibleChild(int i) { 1030 AccessibleContext ac = getCurrentAccessibleContext(); 1031 if (ac != null) { 1032 Accessible accessibleChild = ac.getAccessibleChild(i); 1033 ac.setAccessibleParent(this); 1034 return accessibleChild; 1035 } else { 1036 return null; 1037 } 1038 } 1039 1040 public Locale getLocale() { 1041 AccessibleContext ac = getCurrentAccessibleContext(); 1042 if (ac != null) { 1043 return ac.getLocale(); 1044 } else { 1045 return null; 1046 } 1047 } 1048 1049 public void addPropertyChangeListener(PropertyChangeListener l) { 1050 AccessibleContext ac = getCurrentAccessibleContext(); 1051 if (ac != null) { 1052 ac.addPropertyChangeListener(l); 1053 } else { 1054 super.addPropertyChangeListener(l); 1055 } 1056 } 1057 1058 public void removePropertyChangeListener(PropertyChangeListener l) { 1059 AccessibleContext ac = getCurrentAccessibleContext(); 1060 if (ac != null) { 1061 ac.removePropertyChangeListener(l); 1062 } else { 1063 super.removePropertyChangeListener(l); 1064 } 1065 } 1066 1067 public AccessibleAction getAccessibleAction() { 1068 return getCurrentAccessibleContext().getAccessibleAction(); 1069 } 1070 1071 1079 public AccessibleComponent getAccessibleComponent() { 1080 return this; } 1082 1083 public AccessibleSelection getAccessibleSelection() { 1084 return getCurrentAccessibleContext().getAccessibleSelection(); 1085 } 1086 1087 public AccessibleText getAccessibleText() { 1088 return getCurrentAccessibleContext().getAccessibleText(); 1089 } 1090 1091 public AccessibleValue getAccessibleValue() { 1092 return getCurrentAccessibleContext().getAccessibleValue(); 1093 } 1094 1095 1096 1098 public Color getBackground() { 1099 AccessibleContext ac = getCurrentAccessibleContext(); 1100 if (ac instanceof AccessibleComponent) { 1101 return ((AccessibleComponent) ac).getBackground(); 1102 } else { 1103 Component c = getCurrentComponent(); 1104 if (c != null) { 1105 return c.getBackground(); 1106 } else { 1107 return null; 1108 } 1109 } 1110 } 1111 1112 public void setBackground(Color c) { 1113 AccessibleContext ac = getCurrentAccessibleContext(); 1114 if (ac instanceof AccessibleComponent) { 1115 ((AccessibleComponent) ac).setBackground(c); 1116 } else { 1117 Component cp = getCurrentComponent(); 1118 if (cp != null) { 1119 cp.setBackground(c); 1120 } 1121 } 1122 } 1123 1124 public Color getForeground() { 1125 AccessibleContext ac = getCurrentAccessibleContext(); 1126 if (ac instanceof AccessibleComponent) { 1127 return ((AccessibleComponent) ac).getForeground(); 1128 } else { 1129 Component c = getCurrentComponent(); 1130 if (c != null) { 1131 return c.getForeground(); 1132 } else { 1133 return null; 1134 } 1135 } 1136 } 1137 1138 public void setForeground(Color c) { 1139 AccessibleContext ac = getCurrentAccessibleContext(); 1140 if (ac instanceof AccessibleComponent) { 1141 ((AccessibleComponent) ac).setForeground(c); 1142 } else { 1143 Component cp = getCurrentComponent(); 1144 if (cp != null) { 1145 cp.setForeground(c); 1146 } 1147 } 1148 } 1149 1150 public Cursor getCursor() { 1151 AccessibleContext ac = getCurrentAccessibleContext(); 1152 if (ac instanceof AccessibleComponent) { 1153 return ((AccessibleComponent) ac).getCursor(); 1154 } else { 1155 Component c = getCurrentComponent(); 1156 if (c != null) { 1157 return c.getCursor(); 1158 } else { 1159 Accessible ap = getAccessibleParent(); 1160 if (ap instanceof AccessibleComponent) { 1161 return ((AccessibleComponent) ap).getCursor(); 1162 } else { 1163 return null; 1164 } 1165 } 1166 } 1167 } 1168 1169 public void setCursor(Cursor c) { 1170 AccessibleContext ac = getCurrentAccessibleContext(); 1171 if (ac instanceof AccessibleComponent) { 1172 ((AccessibleComponent) ac).setCursor(c); 1173 } else { 1174 Component cp = getCurrentComponent(); 1175 if (cp != null) { 1176 cp.setCursor(c); 1177 } 1178 } 1179 } 1180 1181 public Font getFont() { 1182 AccessibleContext ac = getCurrentAccessibleContext(); 1183 if (ac instanceof AccessibleComponent) { 1184 return ((AccessibleComponent) ac).getFont(); 1185 } else { 1186 Component c = getCurrentComponent(); 1187 if (c != null) { 1188 return c.getFont(); 1189 } else { 1190 return null; 1191 } 1192 } 1193 } 1194 1195 public void setFont(Font f) { 1196 AccessibleContext ac = getCurrentAccessibleContext(); 1197 if (ac instanceof AccessibleComponent) { 1198 ((AccessibleComponent) ac).setFont(f); 1199 } else { 1200 Component c = getCurrentComponent(); 1201 if (c != null) { 1202 c.setFont(f); 1203 } 1204 } 1205 } 1206 1207 public FontMetrics getFontMetrics(Font f) { 1208 AccessibleContext ac = getCurrentAccessibleContext(); 1209 if (ac instanceof AccessibleComponent) { 1210 return ((AccessibleComponent) ac).getFontMetrics(f); 1211 } else { 1212 Component c = getCurrentComponent(); 1213 if (c != null) { 1214 return c.getFontMetrics(f); 1215 } else { 1216 return null; 1217 } 1218 } 1219 } 1220 1221 public boolean isEnabled() { 1222 AccessibleContext ac = getCurrentAccessibleContext(); 1223 if (ac instanceof AccessibleComponent) { 1224 return ((AccessibleComponent) ac).isEnabled(); 1225 } else { 1226 Component c = getCurrentComponent(); 1227 if (c != null) { 1228 return c.isEnabled(); 1229 } else { 1230 return false; 1231 } 1232 } 1233 } 1234 1235 public void setEnabled(boolean b) { 1236 AccessibleContext ac = getCurrentAccessibleContext(); 1237 if (ac instanceof AccessibleComponent) { 1238 ((AccessibleComponent) ac).setEnabled(b); 1239 } else { 1240 Component c = getCurrentComponent(); 1241 if (c != null) { 1242 c.setEnabled(b); 1243 } 1244 } 1245 } 1246 1247 public boolean isVisible() { 1248 AccessibleContext ac = getCurrentAccessibleContext(); 1249 if (ac instanceof AccessibleComponent) { 1250 return ((AccessibleComponent) ac).isVisible(); 1251 } else { 1252 Component c = getCurrentComponent(); 1253 if (c != null) { 1254 return c.isVisible(); 1255 } else { 1256 return false; 1257 } 1258 } 1259 } 1260 1261 public void setVisible(boolean b) { 1262 AccessibleContext ac = getCurrentAccessibleContext(); 1263 if (ac instanceof AccessibleComponent) { 1264 ((AccessibleComponent) ac).setVisible(b); 1265 } else { 1266 Component c = getCurrentComponent(); 1267 if (c != null) { 1268 c.setVisible(b); 1269 } 1270 } 1271 } 1272 1273 public boolean isShowing() { 1274 if (isVisible() && JTableHeader.this.isShowing()) { 1275 return true; 1276 } else { 1277 return false; 1278 } 1279 } 1280 1281 public boolean contains(Point p) { 1282 AccessibleContext ac = getCurrentAccessibleContext(); 1283 if (ac instanceof AccessibleComponent) { 1284 Rectangle r = ((AccessibleComponent) ac).getBounds(); 1285 return r.contains(p); 1286 } else { 1287 Component c = getCurrentComponent(); 1288 if (c != null) { 1289 Rectangle r = c.getBounds(); 1290 return r.contains(p); 1291 } else { 1292 return getBounds().contains(p); 1293 } 1294 } 1295 } 1296 1297 public Point getLocationOnScreen() { 1298 if (parent != null) { 1299 Point parentLocation = parent.getLocationOnScreen(); 1300 Point componentLocation = getLocation(); 1301 componentLocation.translate(parentLocation.x, parentLocation.y); 1302 return componentLocation; 1303 } else { 1304 return null; 1305 } 1306 } 1307 1308 public Point getLocation() { 1309 AccessibleContext ac = getCurrentAccessibleContext(); 1310 if (ac instanceof AccessibleComponent) { 1311 Rectangle r = ((AccessibleComponent) ac).getBounds(); 1312 return r.getLocation(); 1313 } else { 1314 Component c = getCurrentComponent(); 1315 if (c != null) { 1316 Rectangle r = c.getBounds(); 1317 return r.getLocation(); 1318 } else { 1319 return getBounds().getLocation(); 1320 } 1321 } 1322 } 1323 1324 public void setLocation(Point p) { 1325 } 1329 1330 public Rectangle getBounds() { 1331 Rectangle r = table.getCellRect(-1, column, false); 1332 r.y = 0; 1333 return r; 1334 1335 } 1349 1350 public void setBounds(Rectangle r) { 1351 AccessibleContext ac = getCurrentAccessibleContext(); 1352 if (ac instanceof AccessibleComponent) { 1353 ((AccessibleComponent) ac).setBounds(r); 1354 } else { 1355 Component c = getCurrentComponent(); 1356 if (c != null) { 1357 c.setBounds(r); 1358 } 1359 } 1360 } 1361 1362 public Dimension getSize() { 1363 return getBounds().getSize(); 1364 } 1378 1379 public void setSize (Dimension d) { 1380 AccessibleContext ac = getCurrentAccessibleContext(); 1381 if (ac instanceof AccessibleComponent) { 1382 ((AccessibleComponent) ac).setSize(d); 1383 } else { 1384 Component c = getCurrentComponent(); 1385 if (c != null) { 1386 c.setSize(d); 1387 } 1388 } 1389 } 1390 1391 public Accessible getAccessibleAt(Point p) { 1392 AccessibleContext ac = getCurrentAccessibleContext(); 1393 if (ac instanceof AccessibleComponent) { 1394 return ((AccessibleComponent) ac).getAccessibleAt(p); 1395 } else { 1396 return null; 1397 } 1398 } 1399 1400 public boolean isFocusTraversable() { 1401 AccessibleContext ac = getCurrentAccessibleContext(); 1402 if (ac instanceof AccessibleComponent) { 1403 return ((AccessibleComponent) ac).isFocusTraversable(); 1404 } else { 1405 Component c = getCurrentComponent(); 1406 if (c != null) { 1407 return c.isFocusTraversable(); 1408 } else { 1409 return false; 1410 } 1411 } 1412 } 1413 1414 public void requestFocus() { 1415 AccessibleContext ac = getCurrentAccessibleContext(); 1416 if (ac instanceof AccessibleComponent) { 1417 ((AccessibleComponent) ac).requestFocus(); 1418 } else { 1419 Component c = getCurrentComponent(); 1420 if (c != null) { 1421 c.requestFocus(); 1422 } 1423 } 1424 } 1425 1426 public void addFocusListener(FocusListener l) { 1427 AccessibleContext ac = getCurrentAccessibleContext(); 1428 if (ac instanceof AccessibleComponent) { 1429 ((AccessibleComponent) ac).addFocusListener(l); 1430 } else { 1431 Component c = getCurrentComponent(); 1432 if (c != null) { 1433 c.addFocusListener(l); 1434 } 1435 } 1436 } 1437 1438 public void removeFocusListener(FocusListener l) { 1439 AccessibleContext ac = getCurrentAccessibleContext(); 1440 if (ac instanceof AccessibleComponent) { 1441 ((AccessibleComponent) ac).removeFocusListener(l); 1442 } else { 1443 Component c = getCurrentComponent(); 1444 if (c != null) { 1445 c.removeFocusListener(l); 1446 } 1447 } 1448 } 1449 1450 } 1452 } 1454} 1456 | Popular Tags |