User: ko5tik Date: 02/04/14 07:27:40 Added: src/java/xtags/editor BooleanPropertyEditor.java IntegerPropertyEditor.java OptionPropertyEditor.java Log: delegated TagParameter changes to property editors. Revision Changes Path 1.1 xdocletgui/src/java/xtags/editor/BooleanPropertyEditor.java Index: BooleanPropertyEditor.java =================================================================== /* * Copyright (c) 2001, Aslak Hellesøy, BEKK Consulting * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * - Neither the name of BEKK Consulting nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. */ /* * Change log * */ package xtags.editor; import java.beans.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; /** * edit boolean property value * * @author kostik * @created April 13, 2002 * @todo-javadoc Write javadocs */ public class BooleanPropertyEditor extends PropertyEditorSupport { /** * combo box for choosing boolean value */ JComboBox _comboBox; /** * @todo-javadoc Describe the field */ Boolean[] _values = {Boolean.TRUE, Boolean.FALSE}; /** * @todo-javadoc Describe the field */ String[] _strings = {"true", "false"}; /** * default constructor * * @todo-javadoc Write javadocs for constructor */ public BooleanPropertyEditor() { super(); _comboBox = new JComboBox(_values); _comboBox.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { firePropertyChange(); } }); } /** * Sets the AsText attribute of the BooleanPropertyEditor object * * @param text The new AsText value */ public void setAsText(String text) { if (Boolean.valueOf(text).booleanValue()) { _comboBox.setSelectedIndex(0); } else { _comboBox.setSelectedIndex(1); } } /** * Gets the CustomEditor attribute of the BooleanPropertyEditor object * * @return The CustomEditor value */ public Component getCustomEditor() { return _comboBox; } /** * Gets the Tags attribute of the BooleanPropertyEditor object * * @return The Tags value */ public String[] getTags() { return _strings; } /** * Gets the AsText attribute of the BooleanPropertyEditor object * * @return The AsText value */ public String getAsText() { return getValue().toString(); } /** * Gets the JavaInitializationString attribute of the BooleanPropertyEditor * object * * @return The JavaInitializationString value */ public String getJavaInitializationString() { return getAsText(); } /** * Gets the Value attribute of the BooleanPropertyEditor object * * @return The Value value */ public Object getValue() { return _comboBox.getSelectedItem(); } /** * Gets the Paintable attribute of the BooleanPropertyEditor object * * @return The Paintable value */ public boolean isPaintable() { return false; } /** * Describe what the method does * * @return Describe the return value * @todo-javadoc Write javadocs for method * @todo-javadoc Write javadocs for return value */ public boolean supportsCustomEditor() { return true; } } 1.1 xdocletgui/src/java/xtags/editor/IntegerPropertyEditor.java Index: IntegerPropertyEditor.java =================================================================== /* * Copyright (c) 2001, Aslak Hellesøy, BEKK Consulting * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * - Neither the name of BEKK Consulting nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. */ /* * Change log * */ package xtags.editor; import java.beans.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.text.*; import javax.swing.event.*; import java.text.*; /** * property editor for integer values * * @author kostik * @created April 13, 2002 */ public class IntegerPropertyEditor extends PropertyEditorSupport { /** * text field as editor */ JTextArea _text; /** * number formatter */ private NumberFormat _numberFormat; /** * property editor for integers */ public IntegerPropertyEditor() { super(); _numberFormat = NumberFormat.getNumberInstance(); _numberFormat.setParseIntegerOnly(true); _text = new JTextArea() { protected Document createDefaultModel() { return new IntegerDocument(); } class IntegerDocument extends PlainDocument { /** * toolkit reference. mostly for acoustic bombing */ private Toolkit _toolkit = Toolkit.getDefaultToolkit(); /** * validate input before insertion. zap all non-digits * * @param offs offset inside document * @param str Describe string to be inserted * @param a attributes for insertion * @exception BadLocationException never thrown here, but could in * superclass */ public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { // check that input result is valid integer String result = getText(0, offs) + str + getText(offs, getLength() - offs); try { _numberFormat.parse(result); super.insertString(offs, str, a); } catch (ParseException e) { // allow entering of leading minus... if (offs == 0 && str.charAt(0) == '-') { super.insertString(offs, str, a); } else { _toolkit.beep(); } } } } }; _text.getDocument().addDocumentListener( new DocumentListener() { public void changedUpdate(DocumentEvent e) { firePropertyChange(); } public void insertUpdate(DocumentEvent e) { firePropertyChange(); } public void removeUpdate(DocumentEvent e) { firePropertyChange(); } }); } /** * set value as text * * @param text The new AsText value */ public void setAsText(String text) { Integer ii = Integer.decode(text); _text.setText(ii.toString()); } /** * Gets the CustomEditor attribute of the BooleanPropertyEditor object * * @return The CustomEditor value */ public Component getCustomEditor() { return _text; } /** * get integer value as text * * @return The AsText value */ public String getAsText() { return _text.getText(); } /** * string suitable to usage in java source code * * @return The JavaInitializationString value */ public String getJavaInitializationString() { return getAsText(); } /** * Gets the Value attribute of the BooleanPropertyEditor object * * @return The Value value */ public Object getValue() { try { return Integer.decode(getAsText()); } catch (NumberFormatException ex) { return null; } } /** * Gets the Paintable attribute of the BooleanPropertyEditor object * * @return The Paintable value */ public boolean isPaintable() { return false; } /** * Describe what the method does * * @return Describe the return value * @todo-javadoc Write javadocs for method * @todo-javadoc Write javadocs for return value */ public boolean supportsCustomEditor() { return true; } } 1.1 xdocletgui/src/java/xtags/editor/OptionPropertyEditor.java Index: OptionPropertyEditor.java =================================================================== /* * Copyright (c) 2001, Aslak Hellesøy, BEKK Consulting * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * - Neither the name of BEKK Consulting nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. */ /* * Change log * */ package xtags.editor; import xtags.*; import java.beans.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; /** * Describe what this class does * * @author kostik * @created April 14, 2002 * @todo-javadoc Write javadocs */ public class OptionPropertyEditor extends PropertyEditorSupport { /** * combo box for choosing boolean value */ JComboBox _comboBox; /** * allowed values */ String[] _values; /** * as this class is not intendet to be used with property manager, we do not * support default constructor * * @param options Describe what the parameter does * @param value Describe what the parameter does * @todo-javadoc Write javadocs for method parameter * @todo-javadoc Write javadocs for method parameter */ public OptionPropertyEditor(String[] options, String value) { super(); _comboBox = new JComboBox(); _comboBox.setEditable(false); _values = options; for (int i = 0; i < _values.length; i++) { _comboBox.addItem(_values[i]); if (_values[i].equals(value)) { _comboBox.setSelectedIndex(i); } } _comboBox.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { firePropertyChange(); } }); } /** * sets value from text. if not in our list, select first item * * @param text text to be set */ public void setAsText(String text) { _comboBox.setSelectedItem(text); } /** * return custom editor component * * @return custom editor component */ public Component getCustomEditor() { return _comboBox; } /** * Gets the Tags attribute of the BooleanPropertyEditor object * * @return The Tags value */ public String[] getTags() { return _values; } /** * return selected string * * @return selected string */ public String getAsText() { return getValue().toString(); } /** * string value for java source code * * @return java initializaction string */ public String getJavaInitializationString() { return "\"" + getValue().toString() + "\""; } /** * selected value * * @return The Value value */ public Object getValue() { return _comboBox.getSelectedItem(); } /** * Gets the Paintable attribute of the BooleanPropertyEditor object * * @return The Paintable value */ public boolean isPaintable() { return false; } /** * Describe what the method does * * @return Describe the return value * @todo-javadoc Write javadocs for method * @todo-javadoc Write javadocs for return value */ public boolean supportsCustomEditor() { return true; } }
_______________________________________________ Xdoclet-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/xdoclet-devel