2 * Copyright (C) 2007 The Android Open Source Project
4 * Licensed under the Eclipse Public License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.eclipse.org/org/documents/epl-v10.php
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.ide.eclipse.adt.internal.resources.configurations;
19 import com.android.ide.eclipse.adt.internal.editors.IconFactory;
20 import com.android.sdklib.IAndroidTarget;
22 import org.eclipse.swt.graphics.Image;
24 import java.util.regex.Matcher;
25 import java.util.regex.Pattern;
28 * Resource Qualifier for Region.
30 public final class RegionQualifier extends ResourceQualifier {
31 private final static Pattern sRegionPattern = Pattern.compile("^r([A-Z]{2})$"); //$NON-NLS-1$
33 public static final String NAME = "Region";
35 private String mValue;
38 * Creates and returns a qualifier from the given folder segment. If the segment is incorrect,
39 * <code>null</code> is returned.
40 * @param segment the folder segment from which to create a qualifier.
41 * @return a new {@link RegionQualifier} object or <code>null</code>
43 public static RegionQualifier getQualifier(String segment) {
44 Matcher m = sRegionPattern.matcher(segment);
46 RegionQualifier qualifier = new RegionQualifier();
47 qualifier.mValue = m.group(1);
55 * Returns the folder name segment for the given value. This is equivalent to calling
56 * {@link #toString()} on a {@link RegionQualifier} object.
57 * @param value the value of the qualifier, as returned by {@link #getValue()}.
59 public static String getFolderSegment(String value) {
61 String segment = "r" + value.toUpperCase(); //$NON-NLS-1$
62 if (sRegionPattern.matcher(segment).matches()) {
67 return ""; //$NON-NLS-1$
70 public RegionQualifier() {
74 public RegionQualifier(String value) {
78 public String getValue() {
83 return ""; //$NON-NLS-1$
87 public String getName() {
92 public String getShortName() {
97 public Image getIcon() {
98 return IconFactory.getInstance().getIcon("region"); //$NON-NLS-1$
102 public boolean isValid() {
103 return mValue != null;
107 public boolean checkAndSet(String value, FolderConfiguration config) {
108 RegionQualifier qualifier = getQualifier(value);
109 if (qualifier != null) {
110 config.setRegionQualifier(qualifier);
118 public boolean equals(Object qualifier) {
119 if (qualifier instanceof RegionQualifier) {
120 if (mValue == null) {
121 return ((RegionQualifier)qualifier).mValue == null;
123 return mValue.equals(((RegionQualifier)qualifier).mValue);
130 public int hashCode() {
131 if (mValue != null) {
132 return mValue.hashCode();
139 * Returns the string used to represent this qualifier in the folder name.
142 public String getFolderSegment(IAndroidTarget target) {
143 return getFolderSegment(mValue);
147 public String getStringValue() {
148 if (mValue != null) {
152 return ""; //$NON-NLS-1$