0N/A/*
2362N/A * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/Apackage sun.swing.plaf.synth;
0N/A
0N/Aimport javax.swing.plaf.synth.*;
0N/Aimport java.util.*;
0N/Aimport java.util.regex.*;
0N/A
0N/A/**
0N/A * <b>WARNING:</b> This class is an implementation detail and is only
0N/A * public so that it can be used by two packages. You should NOT consider
0N/A * this public API.
0N/A * <p>
0N/A * StyleAssociation is used to lookup a style for a particular
0N/A * component (or region).
0N/A *
0N/A * @author Scott Violet
0N/A */
0N/Apublic class StyleAssociation {
0N/A /**
0N/A * The style
0N/A */
0N/A private SynthStyle _style;
0N/A
0N/A /**
0N/A * Pattern used for matching.
0N/A */
0N/A private Pattern _pattern;
0N/A /**
0N/A * Matcher used for testing if path matches that of pattern.
0N/A */
0N/A private Matcher _matcher;
0N/A
0N/A /**
0N/A * Identifier for this association.
0N/A */
0N/A private int _id;
0N/A
0N/A
0N/A /**
0N/A * Returns a StyleAssociation that can be used to determine if
0N/A * a particular string matches the returned association.
0N/A */
0N/A public static StyleAssociation createStyleAssociation(
0N/A String text, SynthStyle style)
0N/A throws PatternSyntaxException {
0N/A return createStyleAssociation(text, style, 0);
0N/A }
0N/A
0N/A /**
0N/A * Returns a StyleAssociation that can be used to determine if
0N/A * a particular string matches the returned association.
0N/A */
0N/A public static StyleAssociation createStyleAssociation(
0N/A String text, SynthStyle style, int id)
0N/A throws PatternSyntaxException {
0N/A return new StyleAssociation(text, style, id);
0N/A }
0N/A
0N/A
0N/A private StyleAssociation(String text, SynthStyle style, int id)
0N/A throws PatternSyntaxException {
0N/A _style = style;
0N/A _pattern = Pattern.compile(text);
0N/A _id = id;
0N/A }
0N/A
0N/A /**
0N/A * Returns the developer specified identifier for this association, will
0N/A * be <code>0</code> if an identifier was not specified when this
0N/A * <code>StyleAssociation</code> was created.
0N/A */
0N/A public int getID() {
0N/A return _id;
0N/A }
0N/A
0N/A /**
0N/A * Returns true if this <code>StyleAssociation</code> matches the
0N/A * passed in CharSequence.
0N/A *
0N/A * @return true if this <code>StyleAssociation</code> matches the
0N/A * passed in CharSequence.if this StyleAssociation.
0N/A */
0N/A public synchronized boolean matches(CharSequence path) {
0N/A if (_matcher == null) {
0N/A _matcher = _pattern.matcher(path);
0N/A }
0N/A else {
0N/A _matcher.reset(path);
0N/A }
0N/A return _matcher.matches();
0N/A }
0N/A
0N/A /**
0N/A * Returns the text used in matching the string.
0N/A *
0N/A * @return the text used in matching the string.
0N/A */
0N/A public String getText() {
0N/A return _pattern.pattern();
0N/A }
0N/A
0N/A /**
0N/A * Returns the style this association is mapped to.
0N/A *
0N/A * @return the style this association is mapped to.
0N/A */
0N/A public SynthStyle getStyle() {
0N/A return _style;
0N/A }
0N/A}