File: AtkTable.java

package info (click to toggle)
java-atk-wrapper 0.42.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,668 kB
  • sloc: ansic: 5,531; sh: 5,080; java: 2,195; makefile: 100
file content (320 lines) | stat: -rw-r--r-- 9,478 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
/*
 * Java ATK Wrapper for GNOME
 * Copyright (C) 2009 Sun Microsystems Inc.
 * Copyright (C) 2015 Magdalen Berns <m.berns@thismagpie.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

package org.GNOME.Accessibility;

import javax.accessibility.*;
import java.lang.ref.WeakReference;

public class AtkTable {

	WeakReference<AccessibleContext> _ac;
	WeakReference<AccessibleTable> _acc_table;

	public AtkTable (AccessibleContext ac) {
		this._ac = new WeakReference<AccessibleContext>(ac);
		this._acc_table = new WeakReference<AccessibleTable>(ac.getAccessibleTable());
	}

	public static AtkTable createAtkTable(AccessibleContext ac){
		return AtkUtil.invokeInSwing ( () -> { return new AtkTable(ac); }, null);
	}

	public AccessibleContext ref_at (int row, int column) {
		AccessibleTable acc_table = _acc_table.get();
		if (acc_table == null)
			return null;

		return AtkUtil.invokeInSwing ( () -> {
			Accessible accessible = acc_table.getAccessibleAt(row, column);
			if (accessible != null)
				return accessible.getAccessibleContext();
			return null;
		}, null);
	}

	public int get_index_at (int row, int column) {
		AccessibleTable acc_table = _acc_table.get();
		if (acc_table == null)
			return -1;

		return AtkUtil.invokeInSwing ( () -> {
			if (acc_table instanceof AccessibleExtendedTable)
				return ( (AccessibleExtendedTable) acc_table).getAccessibleIndex(row, column);
			Accessible child = acc_table.getAccessibleAt(row, column);
			if (child == null)
				return -1;
			AccessibleContext child_ac = child.getAccessibleContext();
			if (child_ac == null)
				return -1;
			return child_ac.getAccessibleIndexInParent();
		}, -1);
	}

	public int get_column_at_index (int index) {
		AccessibleTable acc_table = _acc_table.get();
		if (acc_table == null)
			return -1;

		return AtkUtil.invokeInSwing ( () -> {
			int column = -1;
			if (acc_table instanceof AccessibleExtendedTable)
				column = ( (AccessibleExtendedTable) acc_table).getAccessibleColumn(index);
			return column;
		}, -1);
	}

	public int get_row_at_index (int index) {
		AccessibleTable acc_table = _acc_table.get();
		if (acc_table == null)
			return -1;

		return AtkUtil.invokeInSwing ( () -> {
			int row = -1;
			if (acc_table instanceof AccessibleExtendedTable)
				row = ( (AccessibleExtendedTable) acc_table).getAccessibleRow(index);
			return row;
		}, -1);
	}

	public int get_n_columns () {
		AccessibleTable acc_table = _acc_table.get();
		if (acc_table == null)
			return 0;

		return AtkUtil.invokeInSwing ( () -> { return acc_table.getAccessibleColumnCount(); }, 0);
	}

	public int get_n_rows () {
		AccessibleTable acc_table = _acc_table.get();
		if (acc_table == null)
			return 0;

		return AtkUtil.invokeInSwing ( () -> { return acc_table.getAccessibleRowCount(); }, 0);
	}

	public int get_column_extent_at (int row, int column) {
		AccessibleTable acc_table = _acc_table.get();
		if (acc_table == null)
			return 0;

		return AtkUtil.invokeInSwing ( () -> { return acc_table.getAccessibleColumnExtentAt(row, column); }, 0);
	}

	public int get_row_extent_at (int row, int column) {
		AccessibleTable acc_table = _acc_table.get();
		if (acc_table == null)
			return 0;

		return AtkUtil.invokeInSwing ( () -> { return acc_table.getAccessibleRowExtentAt(row, column); }, 0);
	}

	public AccessibleContext get_caption () {
		AccessibleTable acc_table = _acc_table.get();
		if (acc_table == null)
			return null;

		return AtkUtil.invokeInSwing ( () -> {
			Accessible accessible = acc_table.getAccessibleCaption();
			if (accessible != null)
				return accessible.getAccessibleContext();
			return null;
		}, null);
	}

	/**
	 *
	 * @param a an Accessible object
	 */
	public void setCaption(Accessible a) {
		AccessibleTable acc_table = _acc_table.get();
		if (acc_table == null)
			return;

		AtkUtil.invokeInSwing( () -> { acc_table.setAccessibleCaption(a); });
	}

	public String get_column_description (int column) {
		AccessibleTable acc_table = _acc_table.get();
		if (acc_table == null)
			return "";

		return AtkUtil.invokeInSwing ( () -> {
			Accessible accessible = acc_table.getAccessibleColumnDescription(column);
			if (accessible != null) {
				AccessibleContext ac = accessible.getAccessibleContext();
				if (ac != null)
					return ac.getAccessibleDescription();
			}
			return "";
		}, "");
	}

	/**
 	*
 	* @param column an int representing a column in table
 	* @param description a String object representing the description text to set for the
 	*                    specified column of the table
 	*/
	public void setColumnDescription(int column, String description) {
		AccessibleTable acc_table = _acc_table.get();
		if (acc_table == null)
			return;

		AtkUtil.invokeInSwing( () -> {
			Accessible accessible = acc_table.getAccessibleColumnDescription(column);
			if (accessible != null && description.equals(accessible.toString()))
				acc_table.setAccessibleColumnDescription(column, accessible);
		});
	}

	public String get_row_description (int row) {
		AccessibleTable acc_table = _acc_table.get();
		if (acc_table == null)
			return "";

		return AtkUtil.invokeInSwing ( () -> {
			Accessible accessible = acc_table.getAccessibleRowDescription(row);
			if (accessible != null) {
				AccessibleContext ac = accessible.getAccessibleContext();
				if (ac != null)
					return ac.getAccessibleDescription();
			}
			return "";
		}, "");
	}

	/**
 	*
	* @param row an int representing a row in table
	* @param description a String object representing the description text to set for the
	*                    specified row of the table
	*/
	public void setRowDescription(int row, String description) {
		AccessibleTable acc_table = _acc_table.get();
		if (acc_table == null)
			return;

		AtkUtil.invokeInSwing( () -> {
			Accessible accessible = acc_table.getAccessibleRowDescription(row);
			if (accessible != null && description.equals(accessible.toString()))
				acc_table.setAccessibleRowDescription(row, accessible);
		});
	}

	public AccessibleContext get_column_header (int column) {
		AccessibleTable acc_table = _acc_table.get();
		if (acc_table == null)
			return null;

		return AtkUtil.invokeInSwing ( () -> {
			AccessibleTable accessibleTable = acc_table.getAccessibleColumnHeader();
			if (accessibleTable != null) {
				Accessible accessible = accessibleTable.getAccessibleAt(0, column);
				if (accessible != null)
					return accessible.getAccessibleContext();
			}
			return null;
		}, null);
	}

	public AccessibleContext get_row_header (int row) {
		AccessibleTable acc_table = _acc_table.get();
		if (acc_table == null)
			return null;

		return AtkUtil.invokeInSwing ( () -> {
			AccessibleTable accessibleTable = acc_table.getAccessibleRowHeader();
			if (accessibleTable != null) {
				Accessible accessible = accessibleTable.getAccessibleAt(row, 0);
				if (accessible != null)
					return accessible.getAccessibleContext();
			}
			return null;
		}, null);
	}

	public AccessibleContext get_summary () {
		AccessibleTable acc_table = _acc_table.get();
		if (acc_table == null)
			return null;

		return AtkUtil.invokeInSwing ( () -> {
			Accessible accessible = acc_table.getAccessibleSummary();
			if (accessible != null)
				return accessible.getAccessibleContext();
			return null;
		}, null);
	}

	/**
	 *
	 * @param a the Accessible object to set summary for
	 */
	public void setSummary(Accessible a) {
		AccessibleTable acc_table = _acc_table.get();
		if (acc_table == null)
			return;

		AtkUtil.invokeInSwing( () -> { acc_table.setAccessibleSummary(a); });
	}

	public int[] get_selected_columns () {
		int[] d = new int[0];
		AccessibleTable acc_table = _acc_table.get();
		if (acc_table == null)
			return d;

		return AtkUtil.invokeInSwing ( () -> { return acc_table.getSelectedAccessibleColumns(); }, d);
	}

	public int[] get_selected_rows () {
		int[] d = new int[0];
		AccessibleTable acc_table = _acc_table.get();
		if (acc_table == null)
			return d;

		return AtkUtil.invokeInSwing ( () -> { return acc_table.getSelectedAccessibleRows(); }, d);
	}

	public boolean is_column_selected (int column) {
		AccessibleTable acc_table = _acc_table.get();
		if (acc_table == null)
			return false;

		return AtkUtil.invokeInSwing ( () -> { return acc_table.isAccessibleColumnSelected(column); }, false);
	}

	public boolean is_row_selected (int row) {
		AccessibleTable acc_table = _acc_table.get();
		if (acc_table == null)
			return false;

		return AtkUtil.invokeInSwing ( () -> { return acc_table.isAccessibleRowSelected(row); }, false);
	}

	public boolean is_selected (int row, int column) {
		AccessibleTable acc_table = _acc_table.get();
		if (acc_table == null)
			return false;

		return AtkUtil.invokeInSwing ( () -> { return acc_table.isAccessibleSelected(row, column); } ,false);
	}
}