1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package org.openoffice.accessibility.awb.view; 25 26 import java.lang.Integer; 27 import java.lang.StringBuffer; 28 29 import javax.swing.JLabel; 30 31 import com.sun.star.accessibility.AccessibleEventId; 32 import com.sun.star.accessibility.AccessibleEventObject; 33 import com.sun.star.accessibility.XAccessible; 34 import com.sun.star.accessibility.XAccessibleContext; 35 import com.sun.star.accessibility.XAccessibleTable; 36 import com.sun.star.uno.UnoRuntime; 37 38 39 40 /** The <type>ContextView</type> class displays information accessible over 41 the <type>XAccessibleContext</type> interface. This includes name, 42 description, and role. 43 */ 44 public class TableView 45 extends ObjectView 46 { Create( ObjectViewContainer aContainer, XAccessibleContext xContext)47 static public ObjectView Create ( 48 ObjectViewContainer aContainer, 49 XAccessibleContext xContext) 50 { 51 if (UnoRuntime.queryInterface( 52 XAccessibleTable.class, xContext) != null) 53 return new TableView (aContainer); 54 else 55 return null; 56 } 57 TableView(ObjectViewContainer aContainer)58 public TableView (ObjectViewContainer aContainer) 59 { 60 super (aContainer); 61 62 ViewGridLayout aLayout = new ViewGridLayout (this); 63 64 maRowCountLabel = aLayout.AddLabeledEntry ("Row Count: "); 65 maColumnCountLabel = aLayout.AddLabeledEntry ("Column Count: "); 66 maCellCountLabel = aLayout.AddLabeledEntry ("Cell Count: "); 67 maSelectedRowsLabel = aLayout.AddLabeledEntry ("Selected Rows: "); 68 maSelectedColumnsLabel = aLayout.AddLabeledEntry ("Selected Columns: "); 69 } 70 71 SetObject(XAccessibleContext xContext)72 public void SetObject (XAccessibleContext xContext) 73 { 74 mxTable = (XAccessibleTable)UnoRuntime.queryInterface( 75 XAccessibleTable.class, xContext); 76 super.SetObject (xContext); 77 } 78 79 Update()80 public void Update () 81 { 82 if (mxTable == null) 83 { 84 maRowCountLabel.setText ("<null object>"); 85 maColumnCountLabel.setText ("<null object>"); 86 maCellCountLabel.setText ("<null object>"); 87 maSelectedRowsLabel.setText ("<null object>"); 88 maSelectedColumnsLabel.setText ("<null object>"); 89 } 90 else 91 { 92 int nRowCount = mxTable.getAccessibleRowCount(); 93 int nColumnCount = mxTable.getAccessibleColumnCount(); 94 maRowCountLabel.setText (Integer.toString (nRowCount)); 95 maColumnCountLabel.setText (Integer.toString (nColumnCount)); 96 maCellCountLabel.setText (Integer.toString (nRowCount*nColumnCount)); 97 98 StringBuffer sList = new StringBuffer(); 99 int[] aSelected = mxTable.getSelectedAccessibleRows(); 100 boolean bFirst = true; 101 for (int i=0; i<aSelected.length; i++) 102 { 103 if ( ! bFirst) 104 { 105 sList.append (", "); 106 bFirst = false; 107 } 108 sList.append (Integer.toString(aSelected[i])); 109 } 110 maSelectedRowsLabel.setText (sList.toString()); 111 sList = new StringBuffer(); 112 aSelected = mxTable.getSelectedAccessibleColumns(); 113 bFirst = true; 114 for (int i=0; i<aSelected.length; i++) 115 { 116 if ( ! bFirst) 117 { 118 sList.append (", "); 119 bFirst = false; 120 } 121 sList.append (Integer.toString(aSelected[i])); 122 } 123 maSelectedColumnsLabel.setText (sList.toString()); 124 } 125 } 126 127 128 129 GetTitle()130 public String GetTitle () 131 { 132 return ("Table"); 133 } 134 135 136 137 138 /** Listen for changes regarding displayed values. 139 */ notifyEvent(AccessibleEventObject aEvent)140 public void notifyEvent (AccessibleEventObject aEvent) 141 { 142 switch (aEvent.EventId) 143 { 144 case AccessibleEventId.TABLE_MODEL_CHANGED : 145 case AccessibleEventId.SELECTION_CHANGED: 146 Update (); 147 } 148 } 149 150 private XAccessibleTable mxTable; 151 private JLabel 152 maRowCountLabel, 153 maColumnCountLabel, 154 maCellCountLabel, 155 maSelectedRowsLabel, 156 maSelectedColumnsLabel; 157 } 158