Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
// Metawidget (licensed under LGPL)
//
// This library 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 2.1 of the License, or (at your option) any later version.
//
// This 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package org.metawidget.swing.widgetbuilder;
import static org.metawidget.inspector.InspectionResultConstants.*;
import java.awt.Component;
import java.text.DecimalFormat;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import javax.swing.JSlider;
import javax.swing.JSpinner;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SpinnerNumberModel;
import javax.swing.plaf.basic.BasicComboBoxEditor;
import javax.swing.plaf.basic.BasicComboBoxRenderer;
import javax.swing.text.JTextComponent;
import org.metawidget.swing.Stub;
import org.metawidget.swing.SwingMetawidget;
import org.metawidget.swing.SwingValuePropertyProvider;
import org.metawidget.swing.widgetprocessor.binding.BindingConverter;
import org.metawidget.util.ClassUtils;
import org.metawidget.util.CollectionUtils;
import org.metawidget.util.WidgetBuilderUtils;
import org.metawidget.widgetbuilder.iface.WidgetBuilder;
/**
* WidgetBuilder for Swing environments.
*
* Creates native Swing JComponents, such as JTextField and
* JComboBox, to suit the inspected fields.
*
* @author Richard Kennard
*/
public class SwingWidgetBuilder
implements WidgetBuilder, SwingValuePropertyProvider {
//
// Public methods
//
public String getValueProperty( Component component ) {
if ( component instanceof JComboBox ) {
return "selectedItem";
}
if ( component instanceof JTextComponent ) {
return "text";
}
if ( component instanceof JSpinner ) {
return "value";
}
if ( component instanceof JSlider ) {
return "value";
}
if ( component instanceof JCheckBox ) {
return "selected";
}
return null;
}
public JComponent buildWidget( String elementName, Map attributes, SwingMetawidget metawidget ) {
// Hidden
if ( TRUE.equals( attributes.get( HIDDEN ) ) ) {
return new Stub();
}
// Action
if ( ACTION.equals( elementName ) ) {
return new JButton( metawidget.getLabelString( attributes ) );
}
Class> clazz = WidgetBuilderUtils.getActualClassOrType( attributes, String.class );
// Support mandatory Booleans (can be rendered as a checkbox, even though they have a
// Lookup)
if ( Boolean.class.equals( clazz ) && TRUE.equals( attributes.get( REQUIRED ) ) ) {
return new JCheckBox();
}
// Lookups
String lookup = attributes.get( LOOKUP );
if ( lookup != null && !"".equals( lookup ) ) {
JComboBox comboBox = new JComboBox();
// Add an empty choice (if nullable, and not required)
if ( WidgetBuilderUtils.needsEmptyLookupItem( attributes ) ) {
comboBox.addItem( null );
}
List values = CollectionUtils.fromString( lookup );
List