The PgsLookAndFeel contains already a bunch of functions and features. I'm now going to introduce some of them.
You may choose the "everyday" version of setting a PLAF:
try {
UIManager.setLookAndFeel("com.pagosoft.plaf.PgsLookAndFeel");
// Is your UI already created? So you will have to update the component-tree
// of your current frame (or actually all of them...)
SwingUtilities.updateComponentTreeUI(yourFrame);
} catch(Exception e) { /* Most of the time you're just going to ignore it */ }
As an alternative both PlafOptions and PgsLookAndFeel provide static methods to do both of it:
PlafOptions.setAsLookAndFeel();
PlafOptions.updateAllUIs();
Why is this better?
updateAllUIs
-method does this
by itself!Please notice: It does not matter on what of the two classes you call the two methods.
PlafOptions calls the right methods on the PgsLookAndFeel (same goes for setCurrentTheme
).
You may ask why I've integrated them into PlafOptions, right? Well, it's because I wanted to have every configuration/option to be inside of it, so you have only to work with one class.
After your first testdrive you might have noticed that all menuitems are aligned somewhat equally.
This is because all menuitems get an empty icon. But what happens if you default icons are bigger/smaller
than what I've specified? Well, you can change mine by calling
PlafOptions.setDefaultMenuItemIconSize(new Dimension(ICON_WIDTH, ICON_HEIGHT));
pretty simple, isn't it?
This is not everything that deals with menus and their view. You can also specify menus to have a gradient instead of
a "normal"-one-colored background on rollover with
PlafOptions.setStyle(PlafOptions.MENUBARMENU, PlafOptions.GRADIENT_STYLE);
. This can actually be done for the
following components:
If you want them to be without gradients you pass PlafOptions.FLAT_STYLE
as the second parameter.
One note about default-settings: Those settings regarding menus are flat, toolbars are gradients. This is the combination I prefer as it creates really nice effects. A good effect can be achieved by turning on gradients for menuitems.
Don't you like that bold fonts Swing's using? You may choose the "Metal-Way" of changing this, but you might want to do it
by the Pgs-way. This means: PlafOptions.useBoldFonts(false);
.
Why is that better? Because you can enable bold-fonts for menus only: PlafOptions.useBoldMenuFonts(true);
, so
only menu-fonts are bold! (Note: This works only with a PgsTheme)
The ThemeFactory is a great tool to create your own Theme.
Creating a colortheme is a task of just one line:
public static final PgsTheme GRAY = createTheme("Gray", new Color(0x7997D1), new Color(0xABABAB), Color.black);
public static final PgsTheme YELLOW = createTheme("Yellow", new Color(0xCCAA53), new Color(0xABABAB), Color.black);
public static final PgsTheme RUBY = createTheme("Ruby", new Color(244, 10, 66), new Color(0xABABAB), Color.black);
public static final PgsTheme GOLD = createTheme("Gold", new Color(0xFFDB29));
This is the code that is used to create the four most basic themes for the PgsLookAndFeel. You can select them
by using PlafOption.setCurrentTheme(ThemeFactory.YELLOW);
- just to name an example.
The fifth theme is much more complicated anyway. It uses all features provided by the PgsTheme, take a look at how it is implemented:
public static final PgsTheme WIN = new PgsTheme(
"Win",
new Color(0x6080AC), // p1
new Color(0xFFCF31), // p2
new Color(0xF9E089), // p3
new Color(0x666554),
new Color(0xDCDBCB),
new Color(0xF1F0E3),
Color.black,
Color.white,
getWinCustomEntries()
);
private static Object[] getWinCustomEntries() {
Color s2 = new Color(0xDCDBCB);
Color s3 = new Color(0xF1F0E3);
Color p2 = new Color(0xF9E089);
Color p3 = new Color(0xFFCF31);
return new Object[] {
"Button.rolloverGradientStart", Color.white,
"Button.rolloverGradientEnd", s2,
"ToggleButton.rolloverGradientStart", Color.white,
"ToggleButton.rolloverGradientEnd", s2,
"ToolBar.gradientStart", s3,
"ToolBar.gradientEnd", s2,
"ToolBarButton.rolloverGradientStart", p3,
"ToolBarButton.rolloverGradientEnd", p2
};
}
Pretty simple too, isn't it?
But this is not all! You can create a theme out of one color (like I did for the "GoldTheme") or out of a map (e.g. a Propertiesfiles) or even a simple string!
Anyway, you may want to take a look at both, the PgsTheme and the ThemeFactory. It is worth it!
ThemeFactory has also a usefull method called getDefaultTheme that returns the WIN or the GRAY theme, regarding on which OS your application is used on. The WIN-theme is very good to be used on Windows platforms as it uses windows-typical colors.
Currently implemented are only two special styles for JTabbedPanes. You can enable them by using
myTabbedPane.putClientProperty("pgs.isSubTab", Boolean.TRUE);
or myTabbedPane.putClientProperty("pgs.isButtonStyle", Boolean.TRUE);
.
It will paint the tabbedpane with a completly
different style, thus it works perfectly well if you need to place a tabbedpane within a tabbedpane (like some editors
(JBuilder - just to name one) need to do). I would advise you to put the panes on the bottom, this creates the best effect.
We've build-in support for Antialiasing for most components.
However, we decided to disable it by default, because the used Java-implementation isn't that good and some users might not like it.
You can use PlafOptions.setAntialiasingEnabled(true);
to enable Antialiasing globally.
I would recommend to do so on unix-platforms only. You might utilize com.pagosoft.OS
to help you
find out what OS you're running on. If it is Windows, don't use Antialiasing.
Another important thing to mention: Make this configurable by the user.
Note: This feature is not included in 0.1, but only the current CVS-Version!
The PgsLookAndFeel will automatically lookup for a pgs.properties in the classpath.
You can update all properties that normally go into the UIManager, and you can use custom properties to setup the PgsLookAndFeel.
These are our special properties:
Key | Values | Description |
---|---|---|
General options | ||
pgs.shadowBorder | true|false | Controls the settings for splitpanes (shall shadowed borders be used?) |
swing.boldMetal | true|false | Shall we use bold fonts? |
pgs.boldMenuFonts | true|false | Shall we use bold fonts on menus? |
pgs.extraMargin | true|false | Shall we use the extra margin for buttons? If disabled buttons will be smaller. |
pgs.useDisabledIcon | true|false | Shall we generate disabled icons for toolbar-buttons? |
pgs.useToolBarIcon | true|false | Shall we generate icons for toolbar-buttons on rollover? |
pgs.aaEnabled | true|false | Shall we enable antialiasing? |
Styles | ||
pgs.style.menuBar | flat|gradient | Controls the style of menubars. |
pgs.style.menuitem | flat|gradient | Controls the style of menuitems. |
pgs.style.menuBarMenu | flat|gradient | Controls the style of menubar-menus. |
pgs.style.toolBar | flat|gradient | Controls the style of toolbars. |
pgs.style.toolBarButton | flat|gradient | Controls the style of toolbar-buttons. |
pgs.style.button | flat|gradient | Controls the style of buttons. |
You can even create a complete theme in this properties-file.
The keys you have to use for that are:
Key | Description |
---|---|
name | The name of the theme |
primary1 | The first primary color of the theme. |
primary2 | The second primary color of the theme. |
primary3 | The third primary color of the theme. |
secondary1 | The first secondary color of the theme |
secondary2 | The second secondary color of the theme |
secondary3 | The third secondary color of the theme |
The colors must hexcodes and must start with "#".
An important thing to note is that currently (as of version 0.2) every properties-file must contain information for a theme. We will fix this problem later.