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;
25 * Resource Qualifier for Screen Orientation.
27 public final class ScreenOrientationQualifier extends ResourceQualifier {
29 public static final String NAME = "Screen Orientation";
31 private ScreenOrientation mValue = null;
34 * Screen Orientation enum.
36 public static enum ScreenOrientation {
37 PORTRAIT("port", "Portrait"), //$NON-NLS-1$
38 LANDSCAPE("land", "Landscape"), //$NON-NLS-1$
39 SQUARE("square", "Square"); //$NON-NLS-1$
41 private String mValue;
42 private String mDisplayValue;
44 private ScreenOrientation(String value, String displayValue) {
46 mDisplayValue = displayValue;
50 * Returns the enum for matching the provided qualifier value.
51 * @param value The qualifier value.
52 * @return the enum for the qualifier value or null if no matching was found.
54 static ScreenOrientation getEnum(String value) {
55 for (ScreenOrientation orient : values()) {
56 if (orient.mValue.equals(value)) {
64 public String getValue() {
68 public String getDisplayValue() {
72 public static int getIndex(ScreenOrientation orientation) {
74 for (ScreenOrientation orient : values()) {
75 if (orient == orientation) {
85 public static ScreenOrientation getByIndex(int index) {
87 for (ScreenOrientation orient : values()) {
98 public ScreenOrientationQualifier() {
101 public ScreenOrientationQualifier(ScreenOrientation value) {
105 public ScreenOrientation getValue() {
110 public String getName() {
115 public String getShortName() {
116 return "Orientation";
120 public Image getIcon() {
121 return IconFactory.getInstance().getIcon("orientation"); //$NON-NLS-1$
125 public boolean isValid() {
126 return mValue != null;
130 public boolean checkAndSet(String value, FolderConfiguration config) {
131 ScreenOrientation orientation = ScreenOrientation.getEnum(value);
132 if (orientation != null) {
133 ScreenOrientationQualifier qualifier = new ScreenOrientationQualifier(orientation);
134 config.setScreenOrientationQualifier(qualifier);
142 public boolean equals(Object qualifier) {
143 if (qualifier instanceof ScreenOrientationQualifier) {
144 return mValue == ((ScreenOrientationQualifier)qualifier).mValue;
151 public int hashCode() {
152 if (mValue != null) {
153 return mValue.hashCode();
160 * Returns the string used to represent this qualifier in the folder name.
163 public String getFolderSegment(IAndroidTarget target) {
164 if (mValue != null) {
165 return mValue.getValue();
168 return ""; //$NON-NLS-1$
172 public String getStringValue() {
173 if (mValue != null) {
174 return mValue.getDisplayValue();
177 return ""; //$NON-NLS-1$