📄 skinlookandfeel.java
字号:
+ ".skinlf" + File.separator + "themepack.zip"); if (!themepackFile.isFile()) { // then ~/skinlf/themepack.zip themepackFile = new File( System.getProperty("user.home") + File.separator + "skinlf" + File.separator + "themepack.zip"); } if (themepackFile.isFile()) { s = loadThemePack(themepackFile.toURL()); } else { // finally in the classpath URL u = SkinLookAndFeel.class.getResource("/themepack.zip"); if (u != null) { s = loadThemePack(u); } else { throw new Error("themepack.zip not found in classpath"); } } } setSkin(s); } catch (Throwable th) { throw new Error( "Skin was null and an error occurs while trying to load the user theme pack. Source exception message is " + th.getMessage()); } } return s; } /** * @deprecated no longer needed */ public static void enable() throws javax.swing.UnsupportedLookAndFeelException { SkinLookAndFeel lnf = new SkinLookAndFeel(); UIManager.setLookAndFeel(lnf); UIManager.getLookAndFeelDefaults().put("ClassLoader", lnf.getClass().getClassLoader()); } /** * Load a skin from the given filename. <BR>SkinLF will use the filename to * guess which theme to instanciate * * @param filename the given filename * @return Description of the Returned Value * @exception Exception Description of Exception */ public static Skin loadSkin(String filename) throws Exception { return loadSkin(SkinUtils.toURL(new java.io.File(filename))); } /** * Load a skin from the given url. <BR>SkinLF will use the url filename to * guess which theme to instanciate * * @param url Description of Parameter * @return Description of the Returned Value * @exception Exception Description of Exception */ public static Skin loadSkin(java.net.URL url) throws Exception { String filename = url.getFile(); if (filename.endsWith("gtkrc")) { return new GtkSkin(url, getInputStream(url)); } else if (filename.endsWith(".themerc")) { return new KdeSkin(url, getInputStream(url)); } else { throw new Exception( "Unable to load this skin " + url + " (by using filename matching), " + " try an explicit constructor"); } } /** * Load the default theme pack. <br>Skin Look And Feel will look for the * resource file named <code>skinlf-themepack.xml</code> in the user * classpath (using <code>SkinLookAndFeel.class.getResource("/skinlf-themepack.xml")</code>). * * @return Description of the Returned Value * @exception Exception Description of Exception */ public static Skin loadDefaultThemePack() throws Exception { return loadThemePackDefinition( SkinLookAndFeel.class.getResource("/skinlf-themepack.xml")); } /** * Load a Theme Pack from the given zip file. <br>See * <a href="http://www.L2FProd.com/">L2FProd.com website</a> for the * complete description of a theme pack. * * @param filename the theme pack filename * @return Description of the Returned Value * @exception Exception Description of Exception */ public static Skin loadThemePack(String filename) throws Exception { if (filename.startsWith("http://") || filename.startsWith("https://") || filename.startsWith("ftp://") || filename.startsWith("file:/") || filename.startsWith("jar:/")) { return loadThemePack(new URL(filename)); } else { return loadThemePack(SkinUtils.toURL(new File(filename))); } } /** * Load a Theme Pack from the given zip url. <br>See * <a href="http://www.L2FProd.com/">L2FProd.com website</a> for the * complete description of a theme pack. * * @param url the theme pack url * @return Description of the Returned Value * @exception Exception Description of Exception * @see com.l2fprod.util.ZipResourceLoader */ public static Skin loadThemePack(URL url) throws Exception { return loadThemePack(url.openStream()); } /** * Load a Theme Pack from the given stream pointing to a themepack. <br>See * <a href="http://www.L2FProd.com/">L2FProd.com website</a> for the * complete description of a theme pack. * * @param streamToPack stream to the themepack * @see com.l2fprod.util.ZipResourceLoader */ public static Skin loadThemePack(InputStream streamToPack) throws Exception { ZipResourceLoader loader = new ZipResourceLoader(streamToPack); c_ResourceLoader = loader; Skin skin = loadThemePackDefinition( new URL("http://dummyhostforziploader/skinlf-themepack.xml")); c_ResourceLoader = null; return skin; } /** * Load a Theme Pack from the given theme pack definition. <br>URLs in the * definition must be relative * * @param url the theme pack definition url * @return Description of the Returned Value * @exception Exception Description of Exception */ public static Skin loadThemePackDefinition(java.net.URL url) throws Exception { Skin skin = null; XMLElement element = new XMLElement(); element.parseFromReader(new java.io.InputStreamReader(getInputStream(url))); checkRequiredVersion(element.getProperty("REQUIRE")); // reset any custom properties that may be set in the skin UIManager.put("JDesktopPane.backgroundEnabled", Boolean.FALSE); UIManager.put("PopupMenu.animation", Boolean.FALSE); UIManager.put("ScrollBar.alternateLayout", Boolean.FALSE); UIManager.put("JSplitPane.alternateUI", Boolean.FALSE); Enumeration enumeration = element.enumerateChildren(); while (enumeration.hasMoreElements()) { element = (XMLElement)enumeration.nextElement(); String tagName = element.getTagName().toLowerCase(); if ("skin".equals(tagName)) { skin = buildSkin(url, element); } else if ("property".equals(tagName)) { String type = element.getProperty("TYPE"); // Take the boolean class if the typeclass is not specified for // backward compatibility. if (type == null || "".equals(type) || "boolean".equalsIgnoreCase(type) || "java.lang.Boolean".equalsIgnoreCase(type)) { UIManager.put( element.getProperty("NAME"), Boolean.valueOf(element.getProperty("VALUE"))); } else if ( "int".equalsIgnoreCase(type) || "java.lang.Integer".equalsIgnoreCase(type)) { UIManager.put( element.getProperty("NAME"), Integer.valueOf(element.getProperty("VALUE"))); } else if ( "String".equalsIgnoreCase(type) || "java.lang.String".equalsIgnoreCase(type)) { UIManager.put( element.getProperty("NAME"), element.getProperty("VALUE")); } else if ( "Color".equalsIgnoreCase(type) || "java.awt.Color".equalsIgnoreCase(type)) { Color color = Color.decode(element.getProperty("VALUE")); UIManager.put( element.getProperty("NAME"), new ColorUIResource(color)); } else if ( "Insets".equalsIgnoreCase(type) || "java.awt.Insets".equalsIgnoreCase(type)) { Insets insets = parseInsets(element.getProperty("VALUE")); UIManager.put( element.getProperty("NAME"), new InsetsUIResource( insets.top, insets.left, insets.bottom, insets.right)); } else if ( "Dimension".equalsIgnoreCase(type) || "java.awt.Dimension".equalsIgnoreCase(type)) { Dimension dim = parseDimension(element.getProperty("VALUE")); UIManager.put( element.getProperty("NAME"), new DimensionUIResource(dim.width, dim.height)); } else if ( "LineBorder".equalsIgnoreCase(type) || "javax.swing.border.LineBorder".equalsIgnoreCase(type)) { boolean rounded = false; Color color = Color.black; int thickness = 1; int padding = 0; String temp; temp = element.getProperty("ROUNDED"); if (temp != null) { rounded = (Boolean.getBoolean(temp)); } temp = element.getProperty("THICKNESS"); if (temp != null) { thickness = Integer.parseInt(temp); } temp = element.getProperty("PADDING"); if (temp != null) { padding = Integer.parseInt(temp); } temp = element.getProperty("COLOR"); if (temp != null) { color = Color.decode(temp); } Border border = new com.l2fprod.gui.border.LineBorder(color, thickness, rounded); if (padding > 0) { border = new CompoundBorder( border, BorderFactory.createEmptyBorder( padding, padding, padding, padding)); } UIManager.put( element.getProperty("NAME"), new BorderUIResource(border)); } else if ( "EmptyBorder".equalsIgnoreCase(type) || "javax.swing.border.EmptyBorder".equalsIgnoreCase(type)) { Insets insets = parseInsets(element.getProperty("VALUE")); Border border = new javax.swing.border.EmptyBorder(insets); UIManager.put( element.getProperty("NAME"), new BorderUIResource(border)); } } else if ("font".equalsIgnoreCase(tagName)) { String[] fontStyle = StringUtils.splitString(element.getProperty("VALUE"), ","); Font f = SkinUtils.getFont( fontStyle[0], Integer.parseInt(fontStyle[1]), Integer.parseInt(fontStyle[2])); if (f != null) { if ("Global".equalsIgnoreCase(element.getProperty("NAME"))) { SkinUtils.setFont(new FontUIResource(f)); } else { UIManager.put(element.getProperty("NAME"), new FontUIResource(f)); } } } else if ("icon".equalsIgnoreCase(tagName)) { final URL iconURL = new URL(url, element.getProperty("VALUE")); ImageIcon icon = new ImageIcon(SkinUtils.loadImage(iconURL)); UIManager.put(element.getProperty("NAME"), new IconUIResource(icon)); // put the default internal icon at work for JOptionPane too if ("InternalFrame.icon".equals(element.getProperty("NAME"))) { JOptionPane.getRootFrame().setIconImage(icon.getImage()); } } } return skin; } /** * Description of the Method * * @param required Description of Parameter * @exception IncorrectVersionException */ public static void checkRequiredVersion(String required) throws IncorrectVersionException { if ((required == null) || ("".equals(required))) { return; } IncorrectVersionException.checkRequiredVersion(version(), required); } /** * Gets the InputStream attribute of the SkinLookAndFeel class * * @param url Description of Parameter * @return The InputStream value * @exception Exception Description of Exception */ static InputStream getInputStream(URL url) throws Exception { if (c_ResourceLoader != null) { return c_ResourceLoader.getZipResource(url).getInputStream(); } else { return url.openStream(); } } /** * Gets the URLContent attribute of the SkinLookAndFeel class * * @param url Description of Parameter * @return The URLContent value * @exception Exception Description of Exception */ static byte[] getURLContent(URL url) throws Exception { if (c_ResourceLoader == null) { BufferedInputStream input = new BufferedInputStream(url.openStream()); ByteArrayOutputStream output = new ByteArrayOutputStream(); int read; while ((read = input.read()) != -1) { output.write(read); } return output.toByteArray(); } else { return c_ResourceLoader.getZipResource(url).getURLContent(); } } /** * Description of the Method * * @param str Description of Parameter * @return Description of the Returned Value */ private static Dimension parseDimension(String str) { int[] dim = new int[2]; Arrays.fill(dim, 0); String[] dimStrings = StringUtils.splitString(str, "{,}"); for (int i = 0; i < dim.length; i++) { dim[i] = Integer.parseInt(dimStrings[i]); } return new Dimension(dim[0], dim[1]); } /** * Description of the Method * * @param str Description of Parameter * @return Description of the Returned Value */ private static Insets parseInsets(String str) { int[] insets = new int[4]; Arrays.fill(insets, 0); String[] insetsString = StringUtils.splitString(str, "{,}"); for (int i = 0; i < insets.length; i++) { insets[i] = Integer.parseInt(insetsString[i]); } return new Insets(insets[0], insets[1], insets[2], insets[3]); } /** * Description of the Method * * @param context Description of Parameter * @param element Description of Parameter * @return Description of the Returned Value * @exception Exception Description of Exception */ private static Skin buildSkin(URL context, XMLElement element) throws Exception { Skin result = null; if (element.countChildren() == 0) { result = loadSkin(new URL(context, element.getProperty("URL"))); } else if (element.countChildren() == 2) { // it's a compound skin result = new CompoundSkin( buildSkin(context, (XMLElement)element.getChildren().elementAt(0)), buildSkin(context, (XMLElement)element.getChildren().elementAt(1))); } return result; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -