1 /* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 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 7 * 8 * http://www.eclipse.org/org/documents/epl-v10.php 9 * 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. 15 */ 16 17 package com.android.ide.eclipse.adt.internal.resources.configurations; 18 19 import com.android.ide.eclipse.adt.internal.editors.IconFactory; 20 import com.android.sdklib.IAndroidTarget; 21 22 import org.eclipse.swt.graphics.Image; 23 24 25 26 /** 27 * Resource Qualifier for Navigation Method. 28 */ 29 public final class NavigationMethodQualifier extends ResourceQualifier { 30 31 public static final String NAME = "Navigation Method"; 32 33 private NavigationMethod mValue; 34 35 /** 36 * Navigation Method enum. 37 */ 38 public static enum NavigationMethod { 39 DPAD("dpad", "D-pad"), //$NON-NLS-1$ 40 TRACKBALL("trackball", "Trackball"), //$NON-NLS-1$ 41 WHEEL("wheel", "Wheel"), //$NON-NLS-1$ 42 NONAV("nonav", "No Navigation"); //$NON-NLS-1$ 43 44 private String mValue; 45 private String mDisplay; 46 NavigationMethod(String value, String display)47 private NavigationMethod(String value, String display) { 48 mValue = value; 49 mDisplay = display; 50 } 51 52 /** 53 * Returns the enum for matching the provided qualifier value. 54 * @param value The qualifier value. 55 * @return the enum for the qualifier value or null if no matching was found. 56 */ getEnum(String value)57 public static NavigationMethod getEnum(String value) { 58 for (NavigationMethod orient : values()) { 59 if (orient.mValue.equals(value)) { 60 return orient; 61 } 62 } 63 64 return null; 65 } 66 getValue()67 public String getValue() { 68 return mValue; 69 } 70 getDisplayValue()71 public String getDisplayValue() { 72 return mDisplay; 73 } 74 getIndex(NavigationMethod value)75 public static int getIndex(NavigationMethod value) { 76 int i = 0; 77 for (NavigationMethod nav : values()) { 78 if (nav == value) { 79 return i; 80 } 81 82 i++; 83 } 84 85 return -1; 86 } 87 getByIndex(int index)88 public static NavigationMethod getByIndex(int index) { 89 int i = 0; 90 for (NavigationMethod value : values()) { 91 if (i == index) { 92 return value; 93 } 94 i++; 95 } 96 return null; 97 } 98 } 99 NavigationMethodQualifier()100 public NavigationMethodQualifier() { 101 // pass 102 } 103 NavigationMethodQualifier(NavigationMethod value)104 public NavigationMethodQualifier(NavigationMethod value) { 105 mValue = value; 106 } 107 getValue()108 public NavigationMethod getValue() { 109 return mValue; 110 } 111 112 @Override getName()113 public String getName() { 114 return NAME; 115 } 116 117 @Override getShortName()118 public String getShortName() { 119 return "Navigation"; 120 } 121 122 123 @Override getIcon()124 public Image getIcon() { 125 return IconFactory.getInstance().getIcon("navpad"); //$NON-NLS-1$ 126 } 127 128 @Override isValid()129 public boolean isValid() { 130 return mValue != null; 131 } 132 133 @Override checkAndSet(String value, FolderConfiguration config)134 public boolean checkAndSet(String value, FolderConfiguration config) { 135 NavigationMethod method = NavigationMethod.getEnum(value); 136 if (method != null) { 137 NavigationMethodQualifier qualifier = new NavigationMethodQualifier(method); 138 config.setNavigationMethodQualifier(qualifier); 139 return true; 140 } 141 142 return false; 143 } 144 145 @Override equals(Object qualifier)146 public boolean equals(Object qualifier) { 147 if (qualifier instanceof NavigationMethodQualifier) { 148 return mValue == ((NavigationMethodQualifier)qualifier).mValue; 149 } 150 151 return false; 152 } 153 154 @Override hashCode()155 public int hashCode() { 156 if (mValue != null) { 157 return mValue.hashCode(); 158 } 159 160 return 0; 161 } 162 163 /** 164 * Returns the string used to represent this qualifier in the folder name. 165 */ 166 @Override getFolderSegment(IAndroidTarget target)167 public String getFolderSegment(IAndroidTarget target) { 168 if (mValue != null) { 169 return mValue.getValue(); 170 } 171 172 return ""; //$NON-NLS-1$ 173 } 174 175 @Override getStringValue()176 public String getStringValue() { 177 if (mValue != null) { 178 return mValue.getDisplayValue(); 179 } 180 181 return ""; //$NON-NLS-1$ 182 } 183 } 184