package com.swtdesigner;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
/**
* Utility class for managing OS resources associated with SWT controls such as colors, fonts, images, etc.
* <p>
* !!! IMPORTANT !!! Application code must explicitly invoke the <code>dispose()</code> method to release the
* operating system resources managed by cached objects when those objects and OS resources are no longer
* needed (e.g. on application shutdown)
* <p>
* This class may be freely distributed as part of any application or plugin.
* <p>
* Copyright (c) 2003 - 2007, Instantiations, Inc. <br>
* All Rights Reserved
*
* @author scheglov_ke
* @author Dan Rubel
*/
public class SWTResourceManager {
////////////////////////////////////////////////////////////////////////////
//
// Color
//
////////////////////////////////////////////////////////////////////////////
private static Map<RGB, Color> m_colorMap = new HashMap<RGB, Color>();
/**
* Returns the system {@link Color} matching the specific ID.
*
* @param systemColorID
* the ID value for the color
* @return the system {@link Color} matching the specific ID
*/
public static Color getColor(int systemColorID) {
Display display = Display.getCurrent();
return display.getSystemColor(systemColorID);
}
/**
* Returns a {@link Color} given its red, green and blue component values.
*
* @param r
* the red component of the color
* @param g
* the green component of the color
* @param b
* the blue component of the color
* @return the {@link Color} matching the given red, green and blue component values
*/
public static Color getColor(int r, int g, int b) {
return getColor(new RGB(r, g, b));
}
/**
* Returns a {@link Color} given its RGB value.
*
* @param rgb
* the {@link RGB} value of the color
* @return the {@link Color} matching the RGB value
*/
public static Color getColor(RGB rgb) {
Color color = m_colorMap.get(rgb);
if (color == null) {
Display display = Display.getCurrent();
color = new Color(display, rgb);
m_colorMap.put(rgb, color);
}
return color;
}
/**
* Dispose of all the cached {@link Color}'s.
*/
public static void disposeColors() {
for (Color color : m_colorMap.values()) {
color.dispose();
}
m_colorMap.clear();
}
////////////////////////////////////////////////////////////////////////////
//
// Image
//
////////////////////////////////////////////////////////////////////////////
/**
* Maps image paths to images.
*/
private static Map<String, Image> m_imageMap = new HashMap<String, Image>();
/**
* Returns an {@link Image} encoded by the specified {@link InputStream}.
*
* @param stream
* the {@link InputStream} encoding the image data
* @return the {@link Image} encoded by the specified input stream
*/
protected static Image getImage(InputStream stream) throws IOException {
try {
Display display = Display.getCurrent();
ImageData data = new ImageData(stream);
if (data.transparentPixel > 0) {
return new Image(display, data, data.getTransparencyMask());
}
return new Image(display, data);
} finally {
stream.close();
}
}
/**
* Returns an {@link Image} stored in the file at the specified path.
*
* @param path
* the path to the image file
* @return the {@link Image} stored in the file at the specified path
*/
public static Image getImage(String path) {
Image image = m_imageMap.get(path);
if (image == null) {
try {
image = getImage(new FileInputStream(path));
m_imageMap.put(path, image);
} catch (Exception e) {
image = getMissingImage();
m_imageMap.put(path, image);
}
}
return image;
}
/**
* Returns an {@link Image} stored in the file at the specified path relative to the specified class.
*
* @param clazz
* the {@link Class} relative to which to find the image
* @param path
* the path to the image file, if starts with <code>'/'</code>
* @return the {@link Image} stored in the file at the specified path
*/
public static Image getImage(Class<?> clazz, String path) {
String key = clazz.getName() + '|' + path;
Image image = m_imageMap.get(key);
if (image == null) {
try {
image = getImage(clazz.getResourceAsStream(path));
m_imageMap.put(key, image);
} catch (Exception e) {
image = getMissingImage();
m_imageMap.put(key, image);
}
}
return image;
}
private static final int MISSING_IMAGE_SIZE = 10;
/**
* @return the small {@link Image} that can be used as placeholder for missing image.
*/
private static Image getMissingImage() {
Image image = new Image(Display.getCurrent(), MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE);
//
GC gc = new GC(image);
gc.setBackground(getColor(SWT.COLOR_RED));
gc.fillRectangle(0, 0, MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE);
gc.dispose();
//
return image;
}
/**
* Style constant for placing decorator image in top left corner of base image.
*/
public static final int TOP_LEFT = 1;
/**
* Style constant for placing decorator image in top right corner of base image.
*/
public static final int TOP_RIGHT = 2;
/**
* Style constant for placing decorator image in bottom left corner of base image.
*/
public static final int BOTTOM_LEFT = 3;
/**
* Style constant for placing decorator image in bottom right corner of base image.
*/
public static final int BOTTOM_RIGHT = 4;
/**
* Internal value.
*/
protected static final int LAST_CORNER_KEY = 5;
/**
* Maps images to decorated images.
*/
@SuppressWarnings("unchecked")
private static Map<Image, Map<Image, Image>>[] m_decoratedImageMap = new Map[LAST_CORNER_KEY];
/**
* Returns an {@link Image} composed of a base image decorated by another image.
*
* @param baseImage
* the base {@link Image} that should be decorated
* @param decorator
* the {@link Image} to decorate the base image
* @return {@link Image} The resulting decorated image
*/
public static Image decorateImage(Image baseImage, Image decorator) {
return decorateImage(baseImage, decorator, BOTTOM_RIGHT);
}
/**
* Returns an {@link Image} composed of a base image decorated by another image.
*
* @param baseImage
* the base {@link Image} that should be decorated
* @param decorator
* the {@link Image} to decorate the base image
* @param corner
* the corner to place decorator image
* @return the resulting decorated {@link Image}
*/
public static Image decorateImage(final Image baseImage, final Image decorator, final int corner) {
if (corner <= 0 || corner >= LAST_CORNER_KEY) {
throw new IllegalArgumentException("Wrong decorate corner");
}
Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[corner];
if (cornerDecoratedImageMap == null) {
cornerDecoratedImageMap = new HashMap<Image, Map<Image, Image>>();
m_decoratedImageMap[corner] = cornerDecoratedImageMap;
}
Map<Image, Image> decoratedMap = cornerDecoratedImageMap.get(baseImage);
if (decoratedMap == null) {
decoratedMap = new HashMap<Image, Image>();
cornerDecoratedImageMap.put(baseImage, decoratedMap);
}
//
Image result = decoratedMap.get(decorator);
if (result == null) {
Rectangle bib = baseImage.getBounds();
Rectangle dib = decorator.getBounds();
//
result = new Image(Displa
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
eclipse rcp 客户端MySQL连接 (185个子文件)
splash.bmp 132KB
SWTResourceManager.class 11KB
ConnControl.class 8KB
QueryResultView.class 7KB
SQLEditor.class 6KB
NewConnectDialog.class 5KB
TBActionGroup$OpenTable.class 4KB
VBActionGroup$OpenTable.class 4KB
ConnectModel.class 4KB
Main.class 4KB
TBDatas.class 4KB
SQLActionGroup$RunSql.class 4KB
ConnectManagerView.class 4KB
ConnectModelManager.class 4KB
ConnectManagerLabelProvider.class 3KB
JavaCmd.class 3KB
ConnUtil.class 3KB
ApplicationActionBarAdvisor.class 3KB
AddDBDialog.class 3KB
ConnectManagerContextProvider.class 3KB
DBModel.class 3KB
SQLActionGroup.class 3KB
QueryResultActionGroup.class 3KB
ConnActionGroup.class 2KB
QueryResultView$1.class 2KB
NewConnectDialog$2.class 2KB
VBActionGroup$DelTable.class 2KB
ConnActionGroup$CloseConn.class 2KB
TBActionGroup$DelTable.class 2KB
VBActionGroup.class 2KB
TBActionGroup.class 2KB
DBActionGroup.class 2KB
DBActionGroup$DelDB.class 2KB
OpenSQLQueryEditor$1.class 2KB
ConnectManagerView$2.class 2KB
AddDBDialog$1.class 2KB
ApplicationWorkbenchWindowAdvisor.class 2KB
ViewModelManager.class 2KB
TBModelManager.class 2KB
PreModelManager.class 2KB
FunModelManager.class 2KB
QueryResultActionGroup$DownPage.class 2KB
QueryResultActionGroup$UpPage.class 2KB
AdvancedInforBean.class 2KB
ConnActionGroup$DelConn.class 2KB
OpenConn.class 2KB
GeneralInforBean.class 2KB
NewConnectAction.class 2KB
ConnPreferences.class 2KB
AbstractDBModelManager.class 2KB
Application.class 2KB
AbstractActionGroup.class 2KB
SQLInput.class 2KB
ApplicationWorkbenchAdvisor.class 2KB
QueryResultView$2.class 2KB
AbstractTableModel.class 2KB
NewConnectDialog$1.class 2KB
ConnectManagerView$1.class 1KB
QueryResultView$4.class 1KB
OpenConnectView.class 1KB
SQLEditor$1.class 1KB
AddDB.class 1KB
NewConnectAction$1.class 1KB
QueryResultView$3.class 1KB
OpenSQLQueryEditor.class 1KB
SQLEditor$2.class 1KB
DBActivator.class 1KB
AbstractActionGroup$Refresh.class 1KB
TBMActionGroup.class 1KB
DBActionGroup$PropertyDB.class 1KB
ConnActionGroup$PropertyConn.class 1KB
ConnectBean.class 1003B
PreferenceInitializer.class 972B
Application$1.class 970B
DBBean.class 924B
AddDBDialog$2.class 878B
NewConnectDialog$3.class 868B
TBMActionGroup$CreateTable.class 854B
Main$1.class 847B
Perspective.class 768B
DBSystemConstant.class 743B
MYSQLException.class 588B
TableModel.class 469B
ViewModel.class 468B
PreModel.class 464B
FunModel.class 464B
IList.class 457B
PreferenceConstants.class 412B
IBase.class 333B
.classpath 470B
shared.css 671B
root.css 312B
Thumbs.db 17KB
link_obj.gif 2KB
newConn.gif 1KB
alt_window_32.gif 1KB
titlebanner.gif 1KB
sample.gif 983B
alt_window_16.gif 637B
views.gif 615B
共 185 条
- 1
- 2
资源评论
- leeniu2018-07-16还不错,可以参考
能量守恒洛
- 粉丝: 154
- 资源: 47
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功