File: AtkTableCell.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 (111 lines) | stat: -rw-r--r-- 3,932 bytes parent folder | download | duplicates (3)
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
/*
 * Java ATK Wrapper for GNOME
 * 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 AtkTableCell {

    WeakReference<AccessibleContext> _ac;
    WeakReference<AccessibleTable> _acc_pt;
    public int row, rowSpan, column, columnSpan;

    public AtkTableCell (AccessibleContext ac) {
        this._ac = new WeakReference<AccessibleContext>(ac);
        Accessible parent = ac.getAccessibleParent();
        _acc_pt = null;
        row = -1;
        rowSpan = -1;
        column = -1;
        columnSpan = -1;
        if (parent == null){
            return;
        }
        AccessibleContext pc = parent.getAccessibleContext();
        if(pc == null){
            return;
        }
        AccessibleTable pt = pc.getAccessibleTable();
        if(pt == null){
            return;
        }
        _acc_pt = new WeakReference<AccessibleTable>(pt);
        int index = ac.getAccessibleIndexInParent();
        if (!(pt instanceof AccessibleExtendedTable)){
            return;
        }
        AccessibleExtendedTable aet = (AccessibleExtendedTable) pt;
        row = aet.getAccessibleRow(index);
        column = aet.getAccessibleColumn(index);
        rowSpan = pt.getAccessibleRowExtentAt(row,column);
        columnSpan = pt.getAccessibleColumnExtentAt(row,column);
    }

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

    /**
    * getTable
    * @return: Reference to the accessible of the containing table as an
    *          AccessibleTable instance.
    */
    public AccessibleTable getTable() {
        if (_acc_pt == null)
            return null;
        return _acc_pt.get();
    }

    public AccessibleContext[] getAccessibleColumnHeader(){
        if (_acc_pt == null)
            return null;
        return AtkUtil.invokeInSwing( () -> {
            AccessibleTable iteration = _acc_pt.get().getAccessibleColumnHeader();
            if (iteration != null){
                int length = iteration.getAccessibleColumnCount();
                AccessibleContext[] result = new AccessibleContext[length];
                for (int i = 0; i < length; i++){
                    result[i] = iteration.getAccessibleAt(0,i).getAccessibleContext();
                }
                return result;
            }
            return null;
        }, null);
    }

    public AccessibleContext[] getAccessibleRowHeader(){
        if (_acc_pt == null)
            return null;
        return AtkUtil.invokeInSwing( () -> {
            AccessibleTable iteration = _acc_pt.get().getAccessibleRowHeader();
            if (iteration != null){
                int length = iteration.getAccessibleRowCount();
                AccessibleContext[] result = new AccessibleContext[length];
                for (int i = 0; i < length; i++){
                    result[i] = iteration.getAccessibleAt(i,0).getAccessibleContext();
                }
                return result;
            }
            return null;
        }, null);
    }

}