Author: echatellier Date: 2010-04-09 18:15:11 +0200 (Fri, 09 Apr 2010) New Revision: 2845 Log: Move wide combo box into widgets package Added: trunk/lima-swing/src/main/java/org/chorem/lima/widgets/ trunk/lima-swing/src/main/java/org/chorem/lima/widgets/JWideComboBox.java Removed: trunk/lima-swing/src/main/java/org/chorem/lima/combobox/JWideComboBox.java Deleted: trunk/lima-swing/src/main/java/org/chorem/lima/combobox/JWideComboBox.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/combobox/JWideComboBox.java 2010-04-09 16:14:25 UTC (rev 2844) +++ trunk/lima-swing/src/main/java/org/chorem/lima/combobox/JWideComboBox.java 2010-04-09 16:15:11 UTC (rev 2845) @@ -1,114 +0,0 @@ -/** - * *##% Lima Main - * Copyright (C) 2008 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* - */ - -package org.chorem.lima.combobox; - -import javax.swing.*; -import javax.swing.plaf.basic.BasicComboPopup; -import javax.swing.plaf.basic.ComboPopup; -import javax.swing.plaf.metal.MetalComboBoxUI; -import java.awt.*; -import java.util.Vector; - -/** - * Cette combo box surcharge quelques methodes de l'UI par defaut - * pour que le composant popup soit plus grand que la combobox - * elle même. - * - * @author ore - */ -public class JWideComboBox extends JComboBox { - - private boolean layingOut = false; - - /** - * - */ - public JWideComboBox() { - setUI(new ScrollMetalComboUI()); - } - - /** - * @param items - */ - public JWideComboBox(final Object items[]) { - super(items); - } - - /** - * @param items - */ - public JWideComboBox(Vector items) { - super(items); - } - - /** - * @param aModel - */ - public JWideComboBox(ComboBoxModel aModel) { - super(aModel); - } - - /** - * - */ - @Override - public void doLayout() { - try { - layingOut = true; - super.doLayout(); - } finally { - layingOut = false; - } - } - - /** - * @return - */ - @Override - public Dimension getSize() { - Dimension dim = super.getSize(); - if (!layingOut) { - int max = Math.max(dim.width, getPreferredSize().width); - dim.width = max > 600 ? 600 : max; - } - return dim; - } -} - -class ScrollMetalComboUI extends MetalComboBoxUI { - - @Override - protected ComboPopup createPopup() { - return new ScrollBasicComboPopup(comboBox); - } -} - -class ScrollBasicComboPopup extends BasicComboPopup { - - public ScrollBasicComboPopup(JComboBox combo) { - super(combo); - } - - @Override - protected JScrollPane createScroller() { - return new JScrollPane(list, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, - JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - } -} Copied: trunk/lima-swing/src/main/java/org/chorem/lima/widgets/JWideComboBox.java (from rev 2836, trunk/lima-swing/src/main/java/org/chorem/lima/combobox/JWideComboBox.java) =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/widgets/JWideComboBox.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/widgets/JWideComboBox.java 2010-04-09 16:15:11 UTC (rev 2845) @@ -0,0 +1,100 @@ +/* *##% Lima Swing + * Copyright (C) 2008 - 2010 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ + +package org.chorem.lima.widgets; + +import javax.swing.*; +import javax.swing.plaf.basic.BasicComboPopup; +import javax.swing.plaf.basic.ComboPopup; +import javax.swing.plaf.metal.MetalComboBoxUI; +import java.awt.*; +import java.util.Vector; + +// put it at begin, otherwise jaxx complains again !!! +class ScrollMetalComboUI extends MetalComboBoxUI { + + @Override + protected ComboPopup createPopup() { + return new ScrollBasicComboPopup(comboBox); + } +} + +//put it at begin, otherwise jaxx complains again !!! +class ScrollBasicComboPopup extends BasicComboPopup { + + /** serialVersionUID. */ + private static final long serialVersionUID = 2353523521723292218L; + + public ScrollBasicComboPopup(JComboBox combo) { + super(combo); + } + + @Override + protected JScrollPane createScroller() { + return new JScrollPane(list, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, + JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + } +} + +/** + * Cette combo box surcharge quelques methodes de l'UI par defaut + * pour que le composant popup soit plus grand que la combobox + * elle même. + * + * @author ore + */ +public class JWideComboBox extends JComboBox { + + /** serialVersionUID. */ + private static final long serialVersionUID = -6715271536163434385L; + + private boolean layingOut = false; + + public JWideComboBox() { + super(); + setUI(new ScrollMetalComboUI()); + } + + public JWideComboBox(final Object items[]) { + super(items); + } + + public JWideComboBox(ComboBoxModel aModel) { + super(aModel); + } + + @Override + public void doLayout() { + try { + layingOut = true; + super.doLayout(); + } finally { + layingOut = false; + } + } + + @Override + public Dimension getSize() { + Dimension dim = super.getSize(); + if (!layingOut) { + int max = Math.max(dim.width, getPreferredSize().width); + dim.width = max > 600 ? 600 : max; + } + return dim; + } +}