001 /*
002 * $Id: DatePickerAddon.java 3100 2008-10-14 22:33:10Z rah003 $
003 *
004 * Copyright 2005 Sun Microsystems, Inc., 4150 Network Circle,
005 * Santa Clara, California 95054, U.S.A. All rights reserved.
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * You should have received a copy of the GNU Lesser General Public
018 * License along with this library; if not, write to the Free Software
019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
020 */
021 package org.jdesktop.swingx.plaf;
022
023 import javax.swing.BorderFactory;
024 import javax.swing.LookAndFeel;
025 import javax.swing.UIManager;
026 import javax.swing.border.LineBorder;
027 import javax.swing.plaf.BorderUIResource;
028
029 import org.jdesktop.swingx.JXDatePicker;
030 import org.jdesktop.swingx.plaf.basic.BasicDatePickerUI;
031 import org.jdesktop.swingx.util.OS;
032
033 /**
034 * @author Joshua Outwater
035 */
036 public class DatePickerAddon extends AbstractComponentAddon {
037 public DatePickerAddon() {
038 super("JXDatePicker");
039 }
040
041 /**
042 * {@inheritDoc}
043 */
044 @Override
045 protected void addBasicDefaults(LookAndFeelAddons addon, DefaultsList defaults) {
046 super.addBasicDefaults(addon, defaults);
047
048 defaults.add(JXDatePicker.uiClassID, BasicDatePickerUI.class.getName());
049 defaults.add("JXDatePicker.border",
050 new BorderUIResource(BorderFactory.createCompoundBorder(
051 LineBorder.createGrayLineBorder(),
052 BorderFactory.createEmptyBorder(3, 3, 3, 3))));
053
054 UIManagerExt.addResourceBundle(
055 "org.jdesktop.swingx.plaf.basic.resources.DatePicker");
056 }
057
058 /**
059 * {@inheritDoc}
060 */
061 @Override
062 protected void addWindowsDefaults(LookAndFeelAddons addon, DefaultsList defaults) {
063 super.addWindowsDefaults(addon, defaults);
064 if (OS.isWindowsXP() && OS.isUsingWindowsVisualStyles()) {
065 defaults.add("JXDatePicker.arrowIcon",
066 LookAndFeel.makeIcon(DatePickerAddon.class, "windows/resources/combo-xp.png"));
067 } else {
068 defaults.add("JXDatePicker.arrowIcon",
069 LookAndFeel.makeIcon(DatePickerAddon.class, "windows/resources/combo-w2k.png"));
070 }
071 }
072
073 /**
074 * {@inheritDoc}
075 */
076 @Override
077 protected void addLinuxDefaults(LookAndFeelAddons addon, DefaultsList defaults) {
078 super.addLinuxDefaults(addon, defaults);
079
080 defaults.add("JXDatePicker.arrowIcon",
081 LookAndFeel.makeIcon(DatePickerAddon.class, "linux/resources/combo-gtk.png"));
082
083 if (isGTK()) {
084 // Issue #667-swingx: ugly border in GTK
085 // remove the border which was installed in addBasicDefaults
086 defaults.add("JXDatePicker.border", null);
087 }
088 }
089
090 /**
091 *
092 * @return true if the LF is GTK.
093 */
094 private boolean isGTK() {
095 return "GTK".equals(UIManager.getLookAndFeel().getID());
096 }
097
098 /**
099 * {@inheritDoc}
100 */
101 @Override
102 protected void addMacDefaults(LookAndFeelAddons addon, DefaultsList defaults) {
103 super.addMacDefaults(addon, defaults);
104
105 defaults.add("JXDatePicker.arrowIcon",
106 LookAndFeel.makeIcon(DatePickerAddon.class, "macosx/resources/combo-osx.png"));
107
108 defaults.add("JXDatePicker.border", "none");
109
110 }
111
112 /** {@inheritDoc} */
113 @Override
114 protected void addNimbusDefaults (LookAndFeelAddons addon,
115 DefaultsList defaults) {
116 super.addNimbusDefaults (addon, defaults);
117
118 // Issue #913-swingx: ugly in Nimbus
119 // TODO: don't use an image here, Nimbus uses Painters for everything
120 // => e.g. reuse the
121 // com.sun.java.swing.plaf.nimbus.ComboBoxComboBoxArrowButtonPainter
122 // (at the moment the OS-X icon looks most similar, it's much better
123 // than no icon...)
124 defaults.add ("JXDatePicker.arrowIcon",
125 LookAndFeel.makeIcon (DatePickerAddon.class,
126 "macosx/resources/combo-osx.png"));
127
128 // Issue #913-swingx: ugly in Nimbus
129 // remove the border which was installed in addBasicDefaults
130 // this is done by Nimbus
131 defaults.add ("JXDatePicker.border", null);
132 }
133
134 }
135