Author: scabanovich
Date: 2011-12-01 18:49:44 -0500 (Thu, 01 Dec 2011)
New Revision: 36854
Modified:
trunk/jst/plugins/org.jboss.tools.jst.css/resources/cssdialog/color_properties.xml
trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/dialog/StyleComposite.java
trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/dialog/common/CSSConstants.java
trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/dialog/common/Util.java
trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/dialog/tabs/BaseTabControl.java
trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/dialog/widgets/ImageCombo.java
Log:
JBIDE-10228
https://issues.jboss.org/browse/JBIDE-10228
ImageRegistry is used to manage images. Small failures of CSS dialog are fixed.
Modified:
trunk/jst/plugins/org.jboss.tools.jst.css/resources/cssdialog/color_properties.xml
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.css/resources/cssdialog/color_properties.xml 2011-12-01
22:44:46 UTC (rev 36853)
+++
trunk/jst/plugins/org.jboss.tools.jst.css/resources/cssdialog/color_properties.xml 2011-12-01
23:49:44 UTC (rev 36854)
@@ -4,9 +4,9 @@
<comment>Example</comment>
<entry key="#F0F8FF">AliceBlue</entry>
<entry key="#FAEBD7">AntiqueWhite</entry>
- <entry key="#00FFFF">Aqua" </entry>
- <entry key="#7FFFD4">Aquamarine" </entry>
- <entry key="#F0FFFF">Azure" </entry>
+ <entry key="#00FFFF">Aqua</entry>
+ <entry key="#7FFFD4">Aquamarine</entry>
+ <entry key="#F0FFFF">Azure</entry>
<entry key="#F5F5DC">Beige</entry>
<entry key="#FFE4C4">Bisque</entry>
<entry key="#000000">Black</entry>
Modified:
trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/dialog/StyleComposite.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/dialog/StyleComposite.java 2011-12-01
22:44:46 UTC (rev 36853)
+++
trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/dialog/StyleComposite.java 2011-12-01
23:49:44 UTC (rev 36854)
@@ -13,8 +13,11 @@
import java.util.Map;
import org.eclipse.core.databinding.DataBindingContext;
+import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
@@ -22,6 +25,8 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
+import org.jboss.tools.jst.css.CSSPlugin;
+import org.jboss.tools.jst.css.dialog.common.CSSConstants;
import org.jboss.tools.jst.css.dialog.common.StyleAttributes;
import org.jboss.tools.jst.css.dialog.tabs.BaseTabControl;
import org.jboss.tools.jst.css.dialog.tabs.ICSSTabControl;
@@ -145,6 +150,15 @@
tabFolder.setSelection(DEFAULT_START_TAB);
+ addDisposeListener(new DisposeListener() {
+ @Override
+ public void widgetDisposed(DisposeEvent e) {
+ ImageRegistry registry = CSSPlugin.getDefault().getImageRegistry();
+ for (String color : CSSConstants.COLORS_BY_RGB.values()) {
+ registry.remove(color);
+ }
+ }
+ });
}
/**
Modified:
trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/dialog/common/CSSConstants.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/dialog/common/CSSConstants.java 2011-12-01
22:44:46 UTC (rev 36853)
+++
trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/dialog/common/CSSConstants.java 2011-12-01
23:49:44 UTC (rev 36854)
@@ -16,6 +16,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
+import java.util.TreeMap;
import org.jboss.tools.jst.css.CSSPlugin;
import org.jboss.tools.jst.css.dialog.parsers.BaseListener;
@@ -49,7 +50,8 @@
public static final Map<String, ArrayList<String>> CSS_STYLES_MAP = new
HashMap<String, ArrayList<String>>();
- public static Map<String, String> COLORS;
+ public static Map<String, String> COLORS_BY_RGB;
+ public static Map<String, String> COLORS_BY_NAME;
private static final String CSS_VALUES_FILE =
"resources/cssdialog/cssElementsWithCombo.xml"; //$NON-NLS-1$
private static final String CSS_STYLES_FILE =
"resources/cssdialog/cssElements.xml"; //$NON-NLS-1$
@@ -72,7 +74,13 @@
properties.loadFromXML(is);
is.close();
- COLORS = (Map) properties;
+ COLORS_BY_RGB = (Map) properties;
+ COLORS_BY_NAME = new TreeMap<String, String>();
+ for (String rgb: COLORS_BY_RGB.keySet()) {
+ String name = COLORS_BY_RGB.get(rgb);
+ COLORS_BY_NAME.put(name.toLowerCase(), rgb);
+ }
+
} catch (IOException e) {
// TODO Auto-generated catch block
Modified:
trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/dialog/common/Util.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/dialog/common/Util.java 2011-12-01
22:44:46 UTC (rev 36853)
+++
trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/dialog/common/Util.java 2011-12-01
23:49:44 UTC (rev 36854)
@@ -149,35 +149,11 @@
}
return convertColorHEX(color);
} else if (color.toLowerCase().indexOf(RGB) != Constants.DONT_CONTAIN) {
-
- int start = color.indexOf(OPEN_BRACKET);
- int end = color.indexOf(CLOSE_BRACKET);
- String str = color.substring(start + 1, end);
-
- StringTokenizer st = new StringTokenizer(str, Constants.COMMA);
-
- int j = 0;
- while (st.hasMoreTokens()) {
- try {
- int i = Integer.parseInt(st.nextToken().trim());
- if (i < MIN_VALUE_RGB || i > MAX_VALUE_RGB) {
- return null;
- }
- } catch (NumberFormatException e) {
- return null;
- }
- j++;
- }
- if (j == COUNT_COLORS) {
- return convertColorRGB(color);
- }
+ return convertColorRGB(color);
} else {
- Map<String, String> colorMap = CSSConstants.COLORS;
-
- for (String key : colorMap.keySet()) {
- if (colorMap.get(key).equalsIgnoreCase(color)) {
- return convertColorHEX(key);
- }
+ String rgb = CSSConstants.COLORS_BY_NAME.get(color.toLowerCase());
+ if(rgb != null) {
+ return convertColorHEX(rgb);
}
}
@@ -242,15 +218,34 @@
int rgb[] = new int[COUNT_COLORS];
- int start = newStr.indexOf(OPEN_BRACKET);
- int end = newStr.indexOf(CLOSE_BRACKET);
+ int start = -1;
+ int end = -1;
+ if((start = newStr.indexOf('(')) >= 0) {
+ end = newStr.indexOf(')');
+ } else if((start = newStr.indexOf('{')) >= 0) {
+ end = newStr.indexOf('}');
+ }
+ if(start < 0 || end < start) {
+ return null;
+ }
String str = newStr.substring(start + 1, end);
StringTokenizer st = new StringTokenizer(str, Constants.COMMA);
int i = 0;
while (st.hasMoreTokens()) {
- rgb[i++] = Integer.parseInt(st.nextToken().trim());
+ if(i == 3) {
+ return null;
+ }
+ try {
+ rgb[i++] = Integer.parseInt(st.nextToken().trim());
+ } catch (NumberFormatException e) {
+ //It is user input error, should not be reported to log.
+ return null;
+ }
}
+ if(i != 3) {
+ return null;
+ }
return new RGB(rgb[0], rgb[1], rgb[2]);
}
@@ -294,8 +289,8 @@
: Constants.EMPTY)
+ Integer.toHexString(rgb.blue);
colorStr = colorStr.toUpperCase();
- if (CSSConstants.COLORS.get(colorStr) != null) {
- return CSSConstants.COLORS.get(colorStr);
+ if (CSSConstants.COLORS_BY_RGB.containsKey(colorStr)) {
+ return CSSConstants.COLORS_BY_RGB.get(colorStr);
}
return colorStr;
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/dialog/tabs/BaseTabControl.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/dialog/tabs/BaseTabControl.java 2011-12-01
22:44:46 UTC (rev 36853)
+++
trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/dialog/tabs/BaseTabControl.java 2011-12-01
23:49:44 UTC (rev 36854)
@@ -197,9 +197,13 @@
colorCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER,
true, false));
- for (Map.Entry<String, String> me : CSSConstants.COLORS.entrySet()) {
- RGB rgb = Util.getColor(me.getKey());
- colorCombo.add(me.getValue(), rgb);
+ for (Map.Entry<String, String> me : CSSConstants.COLORS_BY_NAME.entrySet()) {
+ RGB rgb = Util.getColor(me.getValue());
+ String name = CSSConstants.COLORS_BY_RGB.get(me.getValue());
+ if(name == null) {
+ name = me.getKey();
+ }
+ colorCombo.add(name, rgb);
}
Button button = createButton(wrapper,
Modified:
trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/dialog/widgets/ImageCombo.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/dialog/widgets/ImageCombo.java 2011-12-01
22:44:46 UTC (rev 36853)
+++
trunk/jst/plugins/org.jboss.tools.jst.css/src/org/jboss/tools/jst/css/dialog/widgets/ImageCombo.java 2011-12-01
23:49:44 UTC (rev 36854)
@@ -322,7 +322,6 @@
}
private Image newImageByColor(String string, RGB rgb) {
- System.out.println("-->" + string);
Color white = new Color(getDisplay(), Constants.RGB_WHITE);
Color black = new Color(getDisplay(), Constants.RGB_BLACK);
Color color = new Color(getDisplay(), rgb);