Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/utils/NamedColorsUtil.java')
-rw-r--r--plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/utils/NamedColorsUtil.java84
1 files changed, 84 insertions, 0 deletions
diff --git a/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/utils/NamedColorsUtil.java b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/utils/NamedColorsUtil.java
new file mode 100644
index 00000000000..82e625936c5
--- /dev/null
+++ b/plugins/xwt/org.eclipse.papyrus.xwt/src/org/eclipse/papyrus/xwt/utils/NamedColorsUtil.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Soyatec (http://www.soyatec.com) and others. *
+ * All rights reserved. This program and the accompanying materials *
+ * are made available under the terms of the Eclipse Public License v1.0 *
+ * which accompanies this distribution, and is available at *
+ * http://www.eclipse.org/legal/epl-v10.html *
+ * Contributors: *
+ * Soyatec - initial API and implementation *
+ *******************************************************************************/
+package org.eclipse.papyrus.xwt.utils;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.ResourceBundle;
+
+import org.eclipse.papyrus.xwt.internal.utils.ObjectUtil;
+import org.eclipse.swt.graphics.Color;
+
+/**
+ * @author jliu (jin.liu@soyatec.com)
+ */
+public class NamedColorsUtil {
+
+ private static ResourceBundle COLORS = ResourceBundle.getBundle("org.eclipse.papyrus.xwt.utils.colors");
+
+ private static String[] colorNames;
+ static {
+ List<String> colors = new ArrayList<String>();
+ Enumeration<String> keys = COLORS.getKeys();
+ while(keys.hasMoreElements()) {
+ String color = keys.nextElement();
+ colors.add(color);
+ }
+ if(!colors.isEmpty()) {
+ colorNames = colors.toArray(new String[0]);
+ Arrays.sort(colorNames);
+ }
+ }
+
+ public static String[] getColorNames() {
+ return colorNames;
+ }
+
+ public static String getColorValue(String name) {
+ if(!hasColor(name)) {
+ return null;
+ }
+ String value = COLORS.getString(name);
+ if(value != null) {
+ value = value.trim();
+ }
+ return value;
+ }
+
+ public static boolean hasColor(String name) {
+ if(name == null) {
+ return false;
+ }
+ String[] colorNames = getColorNames();
+ if(colorNames == null) {
+ return false;
+ }
+ return Arrays.asList(colorNames).contains(name);
+ }
+
+ public static Color getColor(String name) {
+ if(!hasColor(name)) {
+ return null;
+ }
+ String colorValue = getColorValue(name);
+ if(colorValue != null) {
+ return (Color)ObjectUtil.resolveValue(colorValue, Color.class, null);
+ }
+ return null;
+ }
+
+ /**
+ * Utility class.
+ */
+ private NamedColorsUtil() {
+ }
+}

Back to the top