/* * This file is part of WebLookAndFeel library. * * WebLookAndFeel library is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * WebLookAndFeel library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with WebLookAndFeel library. If not, see . */ package com.alee.laf.combobox; import com.alee.laf.WebLookAndFeel; import com.alee.managers.settings.DefaultValue; import com.alee.managers.settings.SettingsManager; import com.alee.managers.settings.SettingsMethods; import com.alee.managers.settings.SettingsProcessor; import com.alee.utils.CompareUtils; import com.alee.utils.ReflectUtils; import com.alee.utils.SizeUtils; import com.alee.utils.SwingUtils; import com.alee.utils.laf.ShapeProvider; import com.alee.utils.swing.FontMethods; import com.alee.utils.swing.SizeMethods; import javax.swing.*; import java.awt.*; import java.util.Vector; /** * User: mgarin Date: 28.06.11 Time: 1:11 */ public class WebComboBox extends JComboBox implements ShapeProvider, SettingsMethods, FontMethods, SizeMethods { public WebComboBox () { super (); } public WebComboBox ( final Vector items ) { super ( items ); } public WebComboBox ( final Vector items, final int selected ) { super ( items ); setSelectedIndex ( selected ); } public WebComboBox ( final Vector items, final Object selected ) { super ( items ); setSelectedItem ( selected ); } public WebComboBox ( final Object[] items ) { super ( items ); } public WebComboBox ( final Object[] items, final int selected ) { super ( items ); setSelectedIndex ( selected ); } public WebComboBox ( final Object[] items, final Object selected ) { super ( items ); setSelectedItem ( selected ); } public WebComboBox ( final ComboBoxModel aModel ) { super ( aModel ); } public WebComboBox ( final ComboBoxModel aModel, final int selected ) { super ( aModel ); setSelectedIndex ( selected ); } public WebComboBox ( final ComboBoxModel aModel, final Object selected ) { super ( aModel ); setSelectedItem ( selected ); } /** * Returns selected value index. * This method is overriden by WebComboBox to fix issue with "null" value from the model being ignored if selected. * By default (in JComboBox) this method will not return index of "null" value in the model if it is selected. * * @return index of the selected value */ @Override public int getSelectedIndex () { final Object sObject = dataModel.getSelectedItem (); int i; Object obj; for ( i = 0; i < dataModel.getSize (); i++ ) { obj = dataModel.getElementAt ( i ); if ( CompareUtils.equals ( obj, sObject ) ) { return i; } } return -1; } public void setEditorColumns ( final int columns ) { getWebUI ().setEditorColumns ( columns ); } public boolean isUseFirstValueAsPrototype () { return getWebUI ().isUseFirstValueAsPrototype (); } public void setUseFirstValueAsPrototype ( final boolean use ) { getWebUI ().setUseFirstValueAsPrototype ( use ); } public ImageIcon getExpandIcon () { return getWebUI ().getExpandIcon (); } public void setExpandIcon ( final ImageIcon expandIcon ) { getWebUI ().setExpandIcon ( expandIcon ); } public ImageIcon getCollapseIcon () { return getWebUI ().getCollapseIcon (); } public void setCollapseIcon ( final ImageIcon collapseIcon ) { getWebUI ().setCollapseIcon ( collapseIcon ); } public int getIconSpacing () { return getWebUI ().getIconSpacing (); } public void setIconSpacing ( final int iconSpacing ) { getWebUI ().setIconSpacing ( iconSpacing ); } public boolean isDrawBorder () { return getWebUI ().isDrawBorder (); } public void setDrawBorder ( final boolean drawBorder ) { getWebUI ().setDrawBorder ( drawBorder ); } public boolean isDrawFocus () { return getWebUI ().isDrawFocus (); } public void setDrawFocus ( final boolean drawFocus ) { getWebUI ().setDrawFocus ( drawFocus ); } public int getRound () { return getWebUI ().getRound (); } public void setRound ( final int round ) { getWebUI ().setRound ( round ); } public int getShadeWidth () { return getWebUI ().getShadeWidth (); } public void setShadeWidth ( final int shadeWidth ) { getWebUI ().setShadeWidth ( shadeWidth ); } public boolean isMouseWheelScrollingEnabled () { return getWebUI ().isMouseWheelScrollingEnabled (); } public void setMouseWheelScrollingEnabled ( final boolean enabled ) { getWebUI ().setMouseWheelScrollingEnabled ( enabled ); } @Override public Shape provideShape () { return getWebUI ().provideShape (); } public WebComboBoxCellRenderer getWebRenderer () { return ( WebComboBoxCellRenderer ) getRenderer (); } public WebComboBoxUI getWebUI () { return ( WebComboBoxUI ) getUI (); } @Override public void updateUI () { if ( getUI () == null || !( getUI () instanceof WebComboBoxUI ) ) { try { setUI ( ( WebComboBoxUI ) ReflectUtils.createInstance ( WebLookAndFeel.comboBoxUI ) ); } catch ( final Throwable e ) { e.printStackTrace (); setUI ( new WebComboBoxUI () ); } } else { setUI ( getUI () ); } } /** * Settings methods */ /** * {@inheritDoc} */ @Override public void registerSettings ( final String key ) { SettingsManager.registerComponent ( this, key ); } /** * {@inheritDoc} */ @Override public void registerSettings ( final String key, final Class defaultValueClass ) { SettingsManager.registerComponent ( this, key, defaultValueClass ); } /** * {@inheritDoc} */ @Override public void registerSettings ( final String key, final Object defaultValue ) { SettingsManager.registerComponent ( this, key, defaultValue ); } /** * {@inheritDoc} */ @Override public void registerSettings ( final String group, final String key ) { SettingsManager.registerComponent ( this, group, key ); } /** * {@inheritDoc} */ @Override public void registerSettings ( final String group, final String key, final Class defaultValueClass ) { SettingsManager.registerComponent ( this, group, key, defaultValueClass ); } /** * {@inheritDoc} */ @Override public void registerSettings ( final String group, final String key, final Object defaultValue ) { SettingsManager.registerComponent ( this, group, key, defaultValue ); } /** * {@inheritDoc} */ @Override public void registerSettings ( final String key, final boolean loadInitialSettings, final boolean applySettingsChanges ) { SettingsManager.registerComponent ( this, key, loadInitialSettings, applySettingsChanges ); } /** * {@inheritDoc} */ @Override public void registerSettings ( final String key, final Class defaultValueClass, final boolean loadInitialSettings, final boolean applySettingsChanges ) { SettingsManager.registerComponent ( this, key, defaultValueClass, loadInitialSettings, applySettingsChanges ); } /** * {@inheritDoc} */ @Override public void registerSettings ( final String key, final Object defaultValue, final boolean loadInitialSettings, final boolean applySettingsChanges ) { SettingsManager.registerComponent ( this, key, defaultValue, loadInitialSettings, applySettingsChanges ); } /** * {@inheritDoc} */ @Override public void registerSettings ( final String group, final String key, final Class defaultValueClass, final boolean loadInitialSettings, final boolean applySettingsChanges ) { SettingsManager.registerComponent ( this, group, key, defaultValueClass, loadInitialSettings, applySettingsChanges ); } /** * {@inheritDoc} */ @Override public void registerSettings ( final String group, final String key, final Object defaultValue, final boolean loadInitialSettings, final boolean applySettingsChanges ) { SettingsManager.registerComponent ( this, group, key, defaultValue, loadInitialSettings, applySettingsChanges ); } /** * {@inheritDoc} */ @Override public void registerSettings ( final SettingsProcessor settingsProcessor ) { SettingsManager.registerComponent ( this, settingsProcessor ); } /** * {@inheritDoc} */ @Override public void unregisterSettings () { SettingsManager.unregisterComponent ( this ); } /** * {@inheritDoc} */ @Override public void loadSettings () { SettingsManager.loadComponentSettings ( this ); } /** * {@inheritDoc} */ @Override public void saveSettings () { SettingsManager.saveComponentSettings ( this ); } /** * Font methods */ /** * {@inheritDoc} */ @Override public WebComboBox setPlainFont () { return SwingUtils.setPlainFont ( this ); } /** * {@inheritDoc} */ @Override public WebComboBox setPlainFont ( final boolean apply ) { return SwingUtils.setPlainFont ( this, apply ); } /** * {@inheritDoc} */ @Override public boolean isPlainFont () { return SwingUtils.isPlainFont ( this ); } /** * {@inheritDoc} */ @Override public WebComboBox setBoldFont () { return SwingUtils.setBoldFont ( this ); } /** * {@inheritDoc} */ @Override public WebComboBox setBoldFont ( final boolean apply ) { return SwingUtils.setBoldFont ( this, apply ); } /** * {@inheritDoc} */ @Override public boolean isBoldFont () { return SwingUtils.isBoldFont ( this ); } /** * {@inheritDoc} */ @Override public WebComboBox setItalicFont () { return SwingUtils.setItalicFont ( this ); } /** * {@inheritDoc} */ @Override public WebComboBox setItalicFont ( final boolean apply ) { return SwingUtils.setItalicFont ( this, apply ); } /** * {@inheritDoc} */ @Override public boolean isItalicFont () { return SwingUtils.isItalicFont ( this ); } /** * {@inheritDoc} */ @Override public WebComboBox setFontStyle ( final boolean bold, final boolean italic ) { return SwingUtils.setFontStyle ( this, bold, italic ); } /** * {@inheritDoc} */ @Override public WebComboBox setFontStyle ( final int style ) { return SwingUtils.setFontStyle ( this, style ); } /** * {@inheritDoc} */ @Override public WebComboBox setFontSize ( final int fontSize ) { return SwingUtils.setFontSize ( this, fontSize ); } /** * {@inheritDoc} */ @Override public WebComboBox changeFontSize ( final int change ) { return SwingUtils.changeFontSize ( this, change ); } /** * {@inheritDoc} */ @Override public int getFontSize () { return SwingUtils.getFontSize ( this ); } /** * {@inheritDoc} */ @Override public WebComboBox setFontSizeAndStyle ( final int fontSize, final boolean bold, final boolean italic ) { return SwingUtils.setFontSizeAndStyle ( this, fontSize, bold, italic ); } /** * {@inheritDoc} */ @Override public WebComboBox setFontSizeAndStyle ( final int fontSize, final int style ) { return SwingUtils.setFontSizeAndStyle ( this, fontSize, style ); } /** * {@inheritDoc} */ @Override public WebComboBox setFontName ( final String fontName ) { return SwingUtils.setFontName ( this, fontName ); } /** * {@inheritDoc} */ @Override public String getFontName () { return SwingUtils.getFontName ( this ); } /** * Size methods. */ /** * {@inheritDoc} */ @Override public int getPreferredWidth () { return SizeUtils.getPreferredWidth ( this ); } /** * {@inheritDoc} */ @Override public WebComboBox setPreferredWidth ( final int preferredWidth ) { return SizeUtils.setPreferredWidth ( this, preferredWidth ); } /** * {@inheritDoc} */ @Override public int getPreferredHeight () { return SizeUtils.getPreferredHeight ( this ); } /** * {@inheritDoc} */ @Override public WebComboBox setPreferredHeight ( final int preferredHeight ) { return SizeUtils.setPreferredHeight ( this, preferredHeight ); } /** * {@inheritDoc} */ @Override public int getMinimumWidth () { return SizeUtils.getMinimumWidth ( this ); } /** * {@inheritDoc} */ @Override public WebComboBox setMinimumWidth ( final int minimumWidth ) { return SizeUtils.setMinimumWidth ( this, minimumWidth ); } /** * {@inheritDoc} */ @Override public int getMinimumHeight () { return SizeUtils.getMinimumHeight ( this ); } /** * {@inheritDoc} */ @Override public WebComboBox setMinimumHeight ( final int minimumHeight ) { return SizeUtils.setMinimumHeight ( this, minimumHeight ); } /** * {@inheritDoc} */ @Override public Dimension getPreferredSize () { return SizeUtils.getPreferredSize ( this, super.getPreferredSize () ); } }