001: /*
002: * Copyright (C) 2005 Jeff Tassin
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package com.jeta.swingbuilder.gui.properties.editors;
020:
021: import java.awt.Component;
022: import java.awt.Dimension;
023:
024: import javax.swing.JLabel;
025: import javax.swing.JPanel;
026: import javax.swing.JTextField;
027:
028: import com.jeta.open.gui.framework.JETADialog;
029: import com.jeta.open.gui.utils.JETAToolbox;
030: import com.jeta.open.i18n.I18N;
031: import com.jeta.swingbuilder.gui.dimension.DimensionView;
032: import com.jeta.swingbuilder.gui.properties.JETAPropertyEditor;
033: import com.jgoodies.forms.layout.CellConstraints;
034: import com.jgoodies.forms.layout.FormLayout;
035:
036: /**
037: * Editor for handling Dimension types.
038: *
039: * @author Jeff Tassin
040: */
041: public class DimensionEditor extends JETAPropertyEditor {
042: private JPanel m_panel;
043: private JTextField m_width = new JTextField(4);
044: private JTextField m_height = new JTextField(4);
045: private boolean m_is_editable = false;
046:
047: public DimensionEditor() {
048: m_panel = new JPanel();
049: FormLayout layout = new FormLayout(
050: "pref,5px,pref,10px,pref,5px,pref,pref:grow", "pref");
051: m_panel.setLayout(layout);
052: CellConstraints cc = new CellConstraints();
053:
054: m_panel.add(new JLabel(I18N.getLocalizedMessage("width")), cc
055: .xy(1, 1));
056: m_panel.add(m_width, cc.xy(3, 1));
057: m_panel.add(new JLabel(I18N.getLocalizedMessage("height")), cc
058: .xy(5, 1));
059: m_panel.add(m_height, cc.xy(7, 1));
060: m_panel.setBorder(javax.swing.BorderFactory.createEmptyBorder(
061: 2, 2, 2, 2));
062: m_width.setEnabled(false);
063: m_height.setEnabled(false);
064: }
065:
066: public Component getCustomEditor() {
067: return m_panel;
068: }
069:
070: public String getJavaInitializationString() {
071: return "";
072: }
073:
074: /**
075: * Invokes a dialog used to update the property
076: */
077: public void invokePropertyDialog() {
078: DimensionView view = new DimensionView((Dimension) getValue());
079: JETADialog dlg = (JETADialog) JETAToolbox.createDialog(
080: JETADialog.class, null, true);
081: dlg.setPrimaryPanel(view);
082: dlg.setSize(dlg.getPreferredSize());
083: dlg.setTitle(I18N.getLocalizedMessage("Set Preferred Size"));
084: dlg.showCenter();
085: if (dlg.isOk()) {
086: setValue(view.getDimension());
087: }
088: }
089:
090: /**
091: * @return true if this editor supports custom editing inline in the
092: * property table. Property types such as the Java primitives and
093: * Strings support inline editing.
094: */
095: public boolean supportsInlineEditing() {
096: return true;
097: }
098:
099: public boolean supportsCustomEditor() {
100: return false;
101: }
102:
103: public void setValue(Object value) {
104: if (value instanceof Dimension) {
105: super .setValue(value);
106: m_is_editable = false;
107: Dimension d = (Dimension) value;
108: m_width.setText(String.valueOf(d.width));
109: m_height.setText(String.valueOf(d.height));
110: }
111: /*
112: * else if ( value instanceof JETADimensionProperty ) { m_is_editable =
113: * true; JETADimensionProperty dp = (JETADimensionProperty)value;
114: * Dimension d = dp.getDimension(); super.setValue(d); m_width.setText(
115: * String.valueOf( d.width) ); m_height.setText(
116: * String.valueOf(d.height) ); }
117: */
118: }
119:
120: public Object getValue() {
121: return new Dimension(Integer.parseInt(m_width.getText()),
122: Integer.parseInt(m_height.getText()));
123: }
124:
125: }
|