📄 xlookandfeel.java
字号:
/****************************************************************
* XBrowser - eXtended web Browser *
* *
* Copyright (c) 2000-2001 Armond Avanes *
* Refer to ReadMe & License files for more information *
* *
* *
* By: Armond Avanes *
* Armond555@yahoo.com & Armond333@yahoo.com *
* http://xbrowser.sourceforge.net/ *
*****************************************************************/
package xbrowser.util;
import xbrowser.*;
import java.util.*;
import java.beans.*;
import javax.swing.*;
import javax.swing.plaf.metal.*;
public class XLookAndFeel extends XProxyObject
{
public XLookAndFeel(String name, String package_name)
{
this(name, package_name, null);
}
public XLookAndFeel(String name, String package_name, String resource)
{
super(name, package_name, resource);
propChangeSupport = new PropertyChangeSupport(this);
}
public void addPropertyChangeListener(PropertyChangeListener listener)
{
propChangeSupport.addPropertyChangeListener(listener);
}
public void removePropertyChangeListener(PropertyChangeListener listener)
{
propChangeSupport.removePropertyChangeListener(listener);
}
public boolean hasTheme()
{
return( !themes.isEmpty() );
}
public Iterator getThemes()
{
return themes.iterator();
}
public void addTheme(XTheme theme)
{
themes.add(theme);
Collections.sort(themes);
if( themes.size()==1 )
activeTheme = theme;
}
public XTheme getActiveTheme()
{
return activeTheme;
}
public void setActiveTheme(XTheme theme)
{
if( themes.contains(theme) )
{
XTheme old_theme = activeTheme;
activeTheme = theme;
propChangeSupport.firePropertyChange("ActiveTheme", old_theme, activeTheme);
}
else
throw new IllegalArgumentException("setActiveTheme: Theme not found!");
}
public void activate() throws Exception
{
if( activeTheme!=null )
activeTheme.activate();
if( this.equals(XProjectConstants.NATIVE_LNF) )
activateImpl(UIManager.getSystemLookAndFeelClassName(), getResource());
else if( this.equals(XProjectConstants.CROSSPLATFORM_LNF) )
activateImpl(UIManager.getCrossPlatformLookAndFeelClassName(), getResource());
else
activateImpl(getPackageName(), getResource());
}
private void activateImpl(String lnf_class_name, String lnf_resource) throws Exception
{
LookAndFeel lnf = (LookAndFeel)XRepository.getResourceManager().loadObject(lnf_class_name, lnf_resource);
ClassLoader cl = lnf.getClass().getClassLoader();
Hashtable tb = UIManager.getDefaults();
/* Registering the custom class-loader.
A work-around for dynamically loading a look&feel from a resource which is not in classpath!
The UIDefaults object use the component's CL by default and easily ignores your custom CL
unless you register the custom CL */
tb.put("ClassLoader", cl);
/* Preload the UI objects!
A work-around for UIDefaults class loader problem.
"ClassLoader" property is not always used in all Java version!!!
// But it's causing some problems! and I'm commenting this section out!
*/
/*
Enumeration enum = tb.keys();
while( enum.hasMoreElements() )
{
Object key = enum.nextElement();
if( (key instanceof String) && ((String)key).endsWith("UI") )
{
Object value = tb.get(key);
if( value instanceof String )
{
try
{
Class uic = cl.loadClass((String)value);
tb.put(uic.getName(), uic);
}
catch( Exception e )
{
}
}
}
}*/
UIManager.setLookAndFeel(lnf);
}
// Attributes:
private XTheme activeTheme;
private LinkedList themes = new LinkedList();
private PropertyChangeSupport propChangeSupport = null;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -