AccessibleDescriptionChooser.java revision 13978:1993af50385d
176082Sbmah/*
276082Sbmah * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
376082Sbmah * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
476082Sbmah *
576082Sbmah * This code is free software; you can redistribute it and/or modify it
676082Sbmah * under the terms of the GNU General Public License version 2 only, as
776082Sbmah * published by the Free Software Foundation.
876082Sbmah *
976082Sbmah * This code is distributed in the hope that it will be useful, but WITHOUT
1076082Sbmah * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11119431Sbmah * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12119431Sbmah * version 2 for more details (a copy is included in the LICENSE file that
1376082Sbmah * accompanied this code).
1476082Sbmah *
1576082Sbmah * You should have received a copy of the GNU General Public License version
1676082Sbmah * 2 along with this work; if not, write to the Free Software Foundation,
1776082Sbmah * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1886157Solgeni *
1976082Sbmah * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2076082Sbmah * or visit www.oracle.com if you need additional information or have any
2176560Sbmah * questions.
2276560Sbmah */
2376560Sbmahpackage org.netbeans.jemmy.accessibility;
2476560Sbmah
2576560Sbmahimport javax.accessibility.AccessibleContext;
2676560Sbmah
2776560Sbmahimport org.netbeans.jemmy.operators.Operator;
2876082Sbmahimport org.netbeans.jemmy.operators.Operator.StringComparator;
2976082Sbmah
30109143Sroampublic class AccessibleDescriptionChooser extends AccessibilityChooser {
3176598Sbmah
3276598Sbmah    private final String description;
3376598Sbmah    private final StringComparator comparator;
3476598Sbmah
3576082Sbmah    public AccessibleDescriptionChooser(String description, StringComparator comparator) {
3676082Sbmah        this.description = description;
3776082Sbmah        this.comparator = comparator;
3885416Sbmah    }
3976082Sbmah
4076082Sbmah    public AccessibleDescriptionChooser(String description) {
4176082Sbmah        this(description, Operator.getDefaultStringComparator());
4276560Sbmah    }
4376560Sbmah
44119127Sbmah    @Override
45119127Sbmah    public final boolean checkContext(AccessibleContext context) {
46119127Sbmah        return comparator.equals(context.getAccessibleDescription(), description);
4776560Sbmah    }
48119127Sbmah
49134047Ssimon    @Override
50134047Ssimon    public String getDescription() {
51134047Ssimon        return "JComponent with \"" + description + "\" accessible description";
52134047Ssimon    }
53119127Sbmah
54119127Sbmah    @Override
55133458Ssimon    public String toString() {
5676082Sbmah        return "AccessibleDescriptionChooser{" + "description=" + description + ", comparator=" + comparator + '}';
57124988Sbrueffer    }
58124988Sbrueffer}
5997677Snyan