/*******************************************************************************
* Copyright (c) 2011 Google, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Google, Inc. - initial API and implementation
*******************************************************************************/
package org.eclipse.wb.swt;
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>
* @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
没有合适的资源?快使用搜索试试~ 我知道了~
考试系统 java rcp
共94个文件
class:52个
java:26个
gif:4个
5星 · 超过95%的资源 需积分: 10 25 下载量 188 浏览量
2011-12-19
16:28:48
上传
评论
收藏 671KB ZIP 举报
温馨提示
1.添加试题(试题应至少包含以下属性:所属科目、题型、难度系数、问题、答案等),添加试题保存到数据库中。 2.修改试题功能,对已经在数据库中的试题可以进行修改。 3.查询试题功能,根据用户输入的查询条件对试题进行搜索,显示试题要求有分页(每页显示5条记录)功能(例如:查询所有java基础科目的简答题)。 4.生成试卷功能,应将试题按用户选择的难度系数的所有组合情况列出,待用户最后确定一个系数组合(例如:用户选择3道选择题,平均系数为3,应该显示1-3-5、1-4-4、2-2-5、2-3-4,3-3-3),同时,试卷在确认生成时应校验数据库中是否包含足够的题目。 5.答题功能,使用普通用户权限(不能进行试题的添加、修改、查询和生成试卷功能)登录,选择一套试卷进行答题,题目依据试卷在生成时的方案依次显示,每答一题,点击【回答完毕】进入下一题的答题界面
资源推荐
资源详情
资源评论
收起资源包目录
examsys.zip (94个子文件)
考试系统
icons
alt_about.gif 9KB
alt_launcher.icns 50KB
alt_window_32.gif 1KB
gif-0001.GIF 1KB
alt_window_16.gif 637B
alt_launcher.xpm 11KB
alt_launcher.ico 26KB
META-INF
MANIFEST.MF 388B
build.properties 139B
src
com
shxt
examsys
core
ApplicationWorkbenchAdvisor.java 614B
Perspective.java 576B
ApplicationWorkbenchWindowAdvisor.java 1KB
Application.java 2KB
ApplicationActionBarAdvisor.java 851B
jdbc
LinkJDBC.java 2KB
editors
UpdateEditor.java 9KB
SelectEditor.java 8KB
AddEditor.java 8KB
ProduceEditor.java 10KB
AnswerEditor.java 9KB
views
OrdinaryView.java 3KB
AdminView.java 4KB
shell
Update.java 3KB
actions
OpenViewAction.java 1KB
Difficulty.java 3KB
TimeCount.java 396B
GetDate.java 365B
dialog
FalseAdd.java 937B
AddOk.java 1KB
Finish.java 1KB
TableDialog.java 4KB
LoginDialog.java 3KB
Produce.java 937B
examsys
Activator.java 1KB
org
eclipse
wb
swt
SWTResourceManager.java 14KB
sql.jar 247KB
bin
com
shxt
examsys
core
ApplicationWorkbenchWindowAdvisor.class 2KB
ApplicationActionBarAdvisor.class 1KB
Application.class 2KB
ApplicationWorkbenchAdvisor.class 1006B
Perspective.class 973B
Application$1.class 990B
jdbc
LinkJDBC.class 4KB
editors
UpdateEditor.class 8KB
UpdateEditor$1.class 3KB
AnswerEditor$4.class 1KB
ProduceEditor$1.class 1KB
UpdateEditor$3.class 1KB
AddEditor$1.class 4KB
ProduceEditor$5.class 1KB
AnswerEditor.class 8KB
AddEditor.class 7KB
AnswerEditor$3.class 2KB
AnswerEditor$1.class 2KB
ProduceEditor$3.class 2KB
ProduceEditor.class 8KB
UpdateEditor$2.class 2KB
ProduceEditor$6.class 2KB
AnswerEditor$2.class 2KB
AnswerEditor$5.class 3KB
SelectEditor$3.class 836B
ProduceEditor$4.class 5KB
SelectEditor$2.class 1KB
SelectEditor.class 8KB
UpdateEditor$4.class 1KB
SelectEditor$1.class 1KB
ProduceEditor$2.class 1KB
views
AdminView.class 3KB
OrdinaryView$1.class 2KB
AdminView$1.class 3KB
OrdinaryView.class 3KB
shell
Update.class 3KB
Update$1.class 2KB
actions
GetDate.class 742B
OpenViewAction.class 2KB
Difficulty$1.class 1KB
TimeCount.class 942B
Difficulty.class 3KB
dialog
TableDialog$1.class 2KB
AddOk.class 2KB
Finish.class 2KB
TableDialog.class 5KB
FalseAdd.class 1KB
LoginDialog.class 3KB
LoginDialog$1.class 2KB
Produce.class 1KB
examsys
Activator.class 1KB
org
eclipse
wb
swt
SWTResourceManager.class 11KB
sql.jar 247KB
.classpath 478B
swing2swt.jar 31KB
.settings
org.eclipse.jdt.core.prefs 395B
plugin.xml 2KB
.project 673B
共 94 条
- 1
资源评论
- vic3492139102013-05-10谢谢 很需要源码
- music199003152013-08-28运行不了,竟然用中文命名
- A_chuchu2014-08-27下载很久了,忘记评论了,很不错的资源,感谢分享
loveminghui1314
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功