「int ←→ RGB int 変換(GMF)」の編集履歴(バックアップ)一覧はこちら
追加された行は緑色になります。
削除された行は赤色になります。
GMFのこの辺りで変換を行っている
org.eclipse.gmf.runtime.draw2d.ui.graphics.ColorRegistry
----
public Color getColor(Integer id) {
Object value = colorRegistry.get(id);
if (value != null) {
return (Color) value;
}
Color newColor = FigureUtilities.integerToColor(id);
colorRegistry.put(id, newColor);
return newColor;
}
/**
* Returns the Color based on the RGB. If the color does not exist in the
* cache, creates a new one and caches.
*
* @param RGB
* @return Color
*/
public Color getColor(RGB rgb) {
Integer colorID = FigureUtilities.RGBToInteger(rgb);
return getColor(colorID);
}
----
org.eclipse.gmf.runtime.draw2d.ui.figures.FigureUtilities
----
public static Color integerToColor(Integer i) {
if (i == null)
return null;
int color = i.intValue();
return new Color(
null,
(color & 0x000000FF),
(color & 0x0000FF00) >> 8,
(color & 0x00FF0000) >> 16);
}
/**
* Method RGBToInteger
* converts from an RGB to an Integer representation
* @param rgb
* @return Integer
*/
public static Integer RGBToInteger(RGB rgb) {
return new Integer((rgb.blue << 16) | (rgb.green << 8) | rgb.red);
}
/**
* Method integerToRGB
* converts from an Integer to an RGB representation
* @param color
* @return RGB
*/
public static RGB integerToRGB(Integer color) {
int n = color.intValue();
return new RGB(
(n & 0x000000FF),
(n & 0x0000FF00) >> 8,
(n & 0x00FF0000) >> 16);
}
----