001: /*
002: * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
003: *
004: * http://izpack.org/
005: * http://izpack.codehaus.org/
006: *
007: * Copyright 2002 Jan Blok
008: *
009: * Licensed under the Apache License, Version 2.0 (the "License");
010: * you may not use this file except in compliance with the License.
011: * You may obtain a copy of the License at
012: *
013: * http://www.apache.org/licenses/LICENSE-2.0
014: *
015: * Unless required by applicable law or agreed to in writing, software
016: * distributed under the License is distributed on an "AS IS" BASIS,
017: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018: * See the License for the specific language governing permissions and
019: * limitations under the License.
020: */
021:
022: package com.izforge.izpack.gui;
023:
024: import java.awt.Color;
025:
026: import javax.swing.Action;
027: import javax.swing.Icon;
028: import javax.swing.JButton;
029:
030: /**
031: * This class makes it possible to use default buttons on macosx platform
032: */
033: public class ButtonFactory {
034:
035: private static boolean useHighlightButtons = false;
036:
037: private static boolean useButtonIcons = false;
038:
039: /**
040: * Enable icons for buttons This setting has no effect on OSX
041: */
042: public static void useButtonIcons() {
043: useButtonIcons(true);
044: }
045:
046: /**
047: * Enable or disable icons for buttons This setting has no effect on OSX
048: *
049: * @param useit flag which determines the behavior
050: */
051: public static void useButtonIcons(boolean useit) {
052: if (System.getProperty("mrj.version") == null) {
053: useButtonIcons = useit;
054: }
055: }
056:
057: /**
058: * Enable highlight buttons This setting has no effect on OSX
059: */
060: public static void useHighlightButtons() {
061: useHighlightButtons(true);
062: }
063:
064: /**
065: * Enable or disable highlight buttons This setting has no effect on OSX
066: *
067: * @param useit flag which determines the behavior
068: */
069: public static void useHighlightButtons(boolean useit) {
070: if (System.getProperty("mrj.version") == null) {
071: useHighlightButtons = useit;
072: }
073: useButtonIcons(useit);
074: }
075:
076: public static JButton createButton(Icon icon, Color color) {
077: if (useHighlightButtons) {
078: if (useButtonIcons)
079: return new HighlightJButton(icon, color);
080: else
081: return new HighlightJButton("", color);
082:
083: } else {
084: if (useButtonIcons) {
085: return new JButton(icon);
086: } else {
087: return new JButton();
088: }
089: }
090: }
091:
092: public static JButton createButton(String text, Color color) {
093: if (useHighlightButtons) {
094: return new HighlightJButton(text, color);
095: } else {
096: return new JButton(text);
097: }
098: }
099:
100: public static JButton createButton(String text, Icon icon,
101: Color color) {
102: if (useHighlightButtons) {
103: if (useButtonIcons)
104: return new HighlightJButton(text, icon, color);
105: else
106: return new HighlightJButton(text, color);
107: } else {
108: if (useButtonIcons) {
109: return new JButton(text, icon);
110: } else {
111: return new JButton(text);
112: }
113: }
114: }
115:
116: public static JButton createButton(Action a, Color color) {
117: if (useHighlightButtons) {
118: return new HighlightJButton(a, color);
119: } else {
120: return new JButton(a);
121: }
122: }
123:
124: }
|