?? swtcolorfactory.java
字號:
/*
* Created on 2004-7-31
* Author: Xuefeng, Copyright (C) 2004, Xuefeng.
*/
package jexi.ui.swt;
import java.util.*;
/**
* The implementation of ColorFactory.
*
* @author Xuefeng
*/
public class SWTColorFactory extends jexi.ui.ColorFactory {
// cache the color:
private Hashtable colors = new Hashtable();
// store the Display object:
private org.eclipse.swt.widgets.Display display = null;
/**
* Create color.
*
* @see jexi.ui.ColorFactory#createColor(int, int, int)
*/
public jexi.ui.Color createColor(int r, int g, int b) {
// first check if it already cached:
Integer key = SWTColor.toKey(r, g, b);
Object o = colors.get(key);
if(o!=null) {
SWTColor color = (SWTColor)o;
color.addRef(); // add a reference!
return color;
}
// if not found, we create a new color:
if(this.display==null) {
this.display = ((jexi.ui.swt.SWTFrame)(jexi.ui.Application.instance().getFrame())).getDisplay();
}
SWTColor newColor = new SWTColor(key, new org.eclipse.swt.graphics.Color(display, r, g, b));
// put it to cache:
colors.put(key, newColor);
return newColor;
}
/**
* Clear all color resources when application terminated.
*
* @see jexi.ui.ColorFactory#clearAllColors()
*/
public void clearAllColors() {
Collection all_colors = new ArrayList( colors.values() );
Iterator it = all_colors.iterator();
while(it.hasNext()) {
jexi.ui.swt.SWTColor color = (jexi.ui.swt.SWTColor)it.next();
while(color.refCount()>0) {
System.out.println("WARNING: Some colors are not released.");
color.dispose();
}
}
// clear hash table:
colors.clear();
}
/**
* Get the size of the cache.
*/
public int size() {
return colors.size();
}
// remove the color:
protected void remove(SWTColor c) {
colors.remove(c.getKey());
}
public void debug() {
System.out.println("\n[ColorFactory: " + colors.size() + " colors]");
Iterator it = colors.values().iterator();
while(it.hasNext()) {
jexi.ui.Color c = (jexi.ui.Color)it.next();
c.debug();
}
System.out.println("-- END ColorFactory --");
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -