⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 swtcolorfactory.java

📁 Java开发图文混排的编辑器
💻 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 + -