/*
* Copyright (C) 2006 Sun Microsystems, Inc. All rights reserved. Use is
* subject to license terms.
*/
package application;
import application.ResourceConverter.ResourceConverterException;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Font;
import java.awt.Image;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URL;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JMenu;
import javax.swing.KeyStroke;
/**
* A read-only encapsulation of one or more ResourceBundles that adds
* automatic string conversion, support for field and Swing component
* property injection, string resource variable substitution, and chaining.
* <p>
* ResourceMaps are typically obtained with the {@code ApplicationContext}
* {@link ApplicationContext#getResourceMap getResourceMap} method
* which lazily creates per Application, package, and class ResourceMaps that
* are linked together with the ResourceMap <tt>parent</tt> property.
* <p>
* An individual ResourceMap provides read-only access to all of the
* resources defined by the ResourceBundles named when the ResourceMap
* was created as well as all of its parent ResourceMaps. Resources
* are retrieved with the <tt>getObject</tt> method which requires both
* the name of the resource and its expected type. The latter is used
* to convert strings if neccessary.
* Converted values are cached. As a convenience, <tt>getObject</tt>
* wrapper methods for common GUI types, like <tt>getFont</tt>,
* and <tt>getColor</tt>, are provided.
* <p>
* The <tt>getObject</tt> method scans raw string resource values
* for <tt>${resourceName}</tt> variable substitutions before
* performing string conversion. Variables named this way can
* refer to String resources defined anywhere in their ResourceMap
* or any parent ResourceMap. The special variable <tt>${null}</tt>
* means that the value of the resource will be null.
* <p>
* ResourceMaps can be used to "inject" resource values into Swing
* component properties and into object fields. The
* <tt>injectComponents</tt> method uses Component names ({@link
* Component#setName}) to match resources names with properties. The
* <tt>injectFields</tt> method sets fields that have been tagged with
* the <tt>@Resource</tt> annotation to the value of resources
* with the same name.
*
* @author Hans Muller (Hans.Muller@Sun.COM)
* @see #injectComponents
* @see #injectFields
* @see ResourceConverter
* @see ResourceBundle
*/
public class ResourceMap {
private static Logger logger = Logger.getLogger(ResourceMap.class.getName());
private final static Object nullResource = new String("null resource");
private final ClassLoader classLoader;
private final ResourceMap parent;
private final String bundleNames[];
private final String resourcesDir;
private Map<String, Object> bundlesMapP = null; // see getBundlesMap()
private Set<String> bundlesMapKeysP = null; // set getBundlesMapKeys()
private boolean bundlesLoaded = false; // ResourceBundles are loaded lazily
/* If path doesn't have a leading "/" then the resourcesDir
* is prepended, otherwise the leading "/" is removed.
*/
private static String resourcePath(String path, ResourceMap resourceMap) {
String rPath = path;
if (path == null) {
rPath = null;
}
else if (path.startsWith("/")) {
rPath = (path.length() > 1) ? path.substring(1) : null;
}
else {
rPath = resourceMap.getResourcesDir() + path;
}
return rPath;
}
private static ImageIcon loadImageIcon(String s, ResourceMap resourceMap)
throws ResourceConverterException
{
String rPath = resourcePath(s, resourceMap);
if (rPath == null) {
String msg = String.format("invalid image/icon path \"%s\"", s);
throw new ResourceConverterException(msg, s);
}
URL url = resourceMap.getClassLoader().getResource(rPath);
if (url != null) {
return new ImageIcon(url);
}
else {
String msg = String.format("couldn't find Icon resource \"%s\"", s);
throw new ResourceConverterException(msg, s);
}
}
/* Register ResourceConverters that are defined in this class
* and documented here.
*/
static {
ResourceConverter[] stringConverters = {
new ColorStringConverter(),
new IconStringConverter(),
new ImageStringConverter(),
new FontStringConverter(),
new KeyStrokeStringConverter(),
};
for (ResourceConverter sc : stringConverters) {
ResourceConverter.register(sc);
}
}
private static class FontStringConverter extends ResourceConverter {
FontStringConverter() {
super(Font.class);
}
/* Just delegates to Font.decode.
* Typical string is: face-STYLE-size, for example "Arial-PLAIN-12"
*/
@Override
public Object parseString(String s, ResourceMap ignore) throws ResourceConverterException {
return Font.decode(s);
}
}
private static class ColorStringConverter extends ResourceConverter {
ColorStringConverter() {
super(Color.class);
}
private void error(String msg, String s, Exception e) throws ResourceConverterException {
throw new ResourceConverterException(msg, s, e);
}
private void error(String msg, String s) throws ResourceConverterException {
error(msg, s, null);
}
/* An improved version of Color.decode() that supports colors
* with an alpha channel and comma separated RGB[A] values.
* Legal format for color resources are:
* "#RRGGBB", "#AARRGGBB", "R, G, B", "R, G, B, A"
* Thanks to Romain Guy for the code.
*/
@Override
public Object parseString(String s, ResourceMap ignore) throws ResourceConverterException {
Color color = null;
if (s.startsWith("#")) {
switch (s.length()) {
// RGB/hex color
case 7:
color = Color.decode(s);
break;
// ARGB/hex color
case 9:
int alpha = Integer.decode(s.substring(0, 3));
int rgb = Integer.decode("#" + s.substring(3));
color = new Color(alpha << 24 | rgb, true);
break;
default:
throw new ResourceConverterException("invalid #RRGGBB or #AARRGGBB color string", s);
}
}
else {
String[] parts = s.split(",");
if (parts.length < 3 || parts.length > 4) {
throw new ResourceConverterException("invalid R, G, B[, A] color string", s);
}
try {
// with alpha component
if (parts.length == 4) {
int r = Integer.parseInt(parts[0].trim());
int g = Integer.parseInt(parts[1].trim());
int b = Integer.parseInt(parts[2].trim());
int a = Integer.parseInt(parts[3].trim());
color = new Color(r, g, b, a);
} else {
int r = Integer.parseInt(parts[0].trim());
int g = Integer.parseInt(parts[1].trim());
int b = Integer.parseInt(parts[2].trim());
color = new Color(r, g, b);
}
}
catch (NumberFormatException e) {
throw new ResourceConverterException("invalid R, G, B[, A] color string", s, e);
}
}
return color;
}
}
private static class IconStringConverter extends ResourceConverter {
IconStringConverter() {
super(Icon.class);
}
@Override
public Object parseString(String s, ResourceMap resourceMap) throws ResourceConverterException {
return loadImageIcon(s, resourceMap);
}
@Override
public
没有合适的资源?快使用搜索试试~ 我知道了~
Java Swing 框架
共128个文件
java:55个
properties:34个
png:33个
4星 · 超过85%的资源 需积分: 9 56 下载量 35 浏览量
2009-06-16
16:54:32
上传
评论 2
收藏 354KB ZIP 举报
温馨提示
Java Swing Application 框架,可以自由构建大型应用程序。
资源推荐
资源详情
资源评论
收起资源包目录
Java Swing 框架 (128个子文件)
COPYING 26KB
swing-worker.jar 11KB
ResourceMap.java 49KB
SessionStorage.java 37KB
ApplicationAction.java 30KB
Task.java 28KB
ResourceMapTest.java 25KB
ResourceManager.java 19KB
Application.java 18KB
ApplicationActionMapTest.java 16KB
ApplicationContext.java 16KB
SingleFrameApplication.java 14KB
LocalStorage.java 13KB
ApplicationTest.java 12KB
SingleFrameExample5.java 11KB
TaskMonitor.java 10KB
ProxyActionTest.java 9KB
ActionExample4.java 9KB
ActionManager.java 9KB
TextActions.java 8KB
LocalStorageExample1.java 8KB
ResourceConverter.java 8KB
ApplicationActionMap.java 7KB
SessionStorageExample1.java 7KB
ActionExample5.java 7KB
TaskTest.java 6KB
StatusBar.java 5KB
SingleFrameExample4.java 5KB
TaskListener.java 5KB
LoadImageTask.java 5KB
AbstractBean.java 4KB
ApplicationActionsTest.java 4KB
SingleFrameExample6.java 4KB
ActionExample1.java 3KB
ActionExample2.java 3KB
TaskService.java 3KB
ActionExample3.java 3KB
LocalStorageTest.java 3KB
ExitExample1.java 3KB
BadSessionStateTest.java 3KB
Action.java 3KB
ApplicationExample2.java 2KB
ApplicationDefaultLNFResourceTest.java 1KB
ApplicationMotifLNFResourceTest.java 1KB
ApplicationExample1.java 1KB
ApplicationSystemLNFResourceTest.java 1KB
WaitForStartupSFA.java 1KB
WaitForStartupApplication.java 1KB
SingleFrameExample3.java 1KB
ApplicationNoLNFResourceTest.java 1KB
TaskEvent.java 869B
SingleFrameExample1.java 819B
ResourceManagerTest.java 791B
SingleFrameExample2.java 579B
ProxyActions.java 532B
Resource.java 473B
Test.java 131B
earth.png 57KB
about-box.png 24KB
exit.png 5KB
busy-icon7.png 4KB
busy-icon8.png 4KB
busy-icon12.png 4KB
busy-icon0.png 4KB
busy-icon13.png 4KB
busy-icon14.png 4KB
busy-icon1.png 4KB
busy-icon2.png 4KB
busy-icon9.png 3KB
busy-icon11.png 3KB
busy-icon6.png 3KB
busy-icon5.png 3KB
busy-icon4.png 3KB
busy-icon3.png 3KB
busy-icon10.png 3KB
delete.png 3KB
cut.png 3KB
idle-icon.png 3KB
open.png 3KB
paste.png 3KB
save.png 3KB
new.png 3KB
copy.png 3KB
wait.png 2KB
refresh.png 2KB
stop.png 2KB
previous.png 1KB
next.png 1KB
pause.png 810B
black1x1.png 142B
project.properties 2KB
Basic.properties 2KB
Controller.properties 2KB
ActionExample5.properties 2KB
Application.properties 2KB
SingleFrameExample5.properties 2KB
SingleFrameExample6.properties 2KB
SingleFrameExample4.properties 1KB
LocalStorageExample1.properties 1KB
StatusBar.properties 739B
共 128 条
- 1
- 2
资源评论
- yyoosn2013-08-27资源一般,都是文档收到但是发生
- kang86902013-02-06资源简介 Java Swing Application 框架,可以自由构建大型应用程序。
- 十点数据2012-11-14不是太好啊a!
- chengjun051255662012-04-04资源一般,都是文档
一缕阳光
- 粉丝: 4
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功