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;
21 import org.eclipse.swt.graphics.Image;
23 import java.util.regex.Matcher;
24 import java.util.regex.Pattern;
27 * Resource Qualifier for Region.
29 public final class RegionQualifier extends ResourceQualifier {
30 private final static Pattern sRegionPattern = Pattern.compile("^r([A-Z]{2})$"); //$NON-NLS-1$
32 public static final String FAKE_REGION_VALUE = "__"; //$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 hasFakeValue() {
108 return FAKE_REGION_VALUE.equals(mValue);
112 public boolean checkAndSet(String value, FolderConfiguration config) {
113 RegionQualifier qualifier = getQualifier(value);
114 if (qualifier != null) {
115 config.setRegionQualifier(qualifier);
123 public boolean equals(Object qualifier) {
124 if (qualifier instanceof RegionQualifier) {
125 if (mValue == null) {
126 return ((RegionQualifier)qualifier).mValue == null;
128 return mValue.equals(((RegionQualifier)qualifier).mValue);
135 public int hashCode() {
136 if (mValue != null) {
137 return mValue.hashCode();
144 * Returns the string used to represent this qualifier in the folder name.
147 public String getFolderSegment() {
148 return getFolderSegment(mValue);
152 public String getShortDisplayValue() {
153 if (mValue != null) {
157 return ""; //$NON-NLS-1$
161 public String getLongDisplayValue() {
162 if (mValue != null) {
163 return String.format("Region %s", mValue);
166 return ""; //$NON-NLS-1$