001/*
002 * IzPack - Copyright 2001-2005 Julien Ponge, All Rights Reserved.
003 * 
004 * http://www.izforge.com/izpack/
005 * http://developer.berlios.de/projects/izpack/
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
022package com.izforge.izpack.gui;
023
024import java.awt.Color;
025
026import javax.swing.Action;
027import javax.swing.Icon;
028import javax.swing.JButton;
029
030/**
031 * This class makes it possible to use default buttons on macosx platform
032 */
033public class ButtonFactory
034{
035
036    private static boolean useHighlightButtons = false;
037
038    private static boolean useButtonIcons = false;
039
040    /**
041     * Enable icons for buttons This setting has no effect on OSX
042     */
043    public static void useButtonIcons()
044    {
045        useButtonIcons(true);
046    }
047
048    /**
049     * Enable or disable icons for buttons This setting has no effect on OSX
050     * 
051     * @param useit flag which determines the behavior
052     */
053    public static void useButtonIcons(boolean useit)
054    {
055        if (System.getProperty("mrj.version") == null)
056        {
057            useButtonIcons = useit;
058        }
059    }
060
061    /**
062     * Enable highlight buttons This setting has no effect on OSX
063     */
064    public static void useHighlightButtons()
065    {
066        useHighlightButtons(true);
067    }
068
069    /**
070     * Enable or disable highlight buttons This setting has no effect on OSX
071     * 
072     * @param useit flag which determines the behavior
073     */
074    public static void useHighlightButtons(boolean useit)
075    {
076        if (System.getProperty("mrj.version") == null)
077        {
078            useHighlightButtons = useit;
079        }
080        useButtonIcons(useit);
081    }
082
083    public static JButton createButton(Icon icon, Color color)
084    {
085        if (useHighlightButtons)
086        {
087            if (useButtonIcons)
088                return new HighlightJButton(icon, color);
089            else
090                return new HighlightJButton("", color);
091
092        }
093        else
094        {
095            if (useButtonIcons)
096            {
097                return new JButton(icon);
098            }
099            else
100            {
101                return new JButton();
102            }
103        }
104    }
105
106    public static JButton createButton(String text, Color color)
107    {
108        if (useHighlightButtons)
109        {
110            return new HighlightJButton(text, color);
111        }
112        else
113        {
114            return new JButton(text);
115        }
116    }
117
118    public static JButton createButton(String text, Icon icon, Color color)
119    {
120        if (useHighlightButtons)
121        {
122            if (useButtonIcons)
123                return new HighlightJButton(text, icon, color);
124            else
125                return new HighlightJButton(text, color);
126        }
127        else
128        {
129            if (useButtonIcons)
130            {
131                return new JButton(text, icon);
132            }
133            else
134            {
135                return new JButton(text);
136            }
137        }
138    }
139
140    public static JButton createButton(Action a, Color color)
141    {
142        if (useHighlightButtons)
143        {
144            return new HighlightJButton(a, color);
145        }
146        else
147        {
148            return new JButton(a);
149        }
150    }
151
152}