[Ejtools-cvs] CVS: libraries/adwt/src/main/net/sourceforge/ejtools/awt/editors DateTimeEditor.java,N
Brought to you by:
letiemble
Update of /cvsroot/ejtools/libraries/adwt/src/main/net/sourceforge/ejtools/awt/editors In directory usw-pr-cvs1:/tmp/cvs-serv9720 Added Files: DateTimeEditor.java NumberEditor.java ObjectNameEditor.java PropertiesEditor.java URLEditor.java Log Message: Initial Import --- NEW FILE: DateTimeEditor.java --- /* * EJT, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package net.sourceforge.ejtools.awt.editors; import java.beans.PropertyEditorSupport; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; /** * Description of the Class * * @author letiembl * @created 2 janvier 2002 */ public class DateTimeEditor extends PropertyEditorSupport { /** Description of the Field */ protected DateFormat fmts[]; /** Description of the Field */ private Date date; /** Constructor for the DateEditor object */ public DateTimeEditor() { fmts = new DateFormat[5]; fmts[0] = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); fmts[1] = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); fmts[2] = new SimpleDateFormat("yyyy-MM-dd HH:mm"); fmts[3] = new SimpleDateFormat("yyMMdd HH:mm:ss"); fmts[4] = new SimpleDateFormat("yyMMdd HH:mm"); } /** * Sets the asText attribute of the DateEditor object * * @param s The new asText value */ public void setAsText(String s) { if (s.equals("")) { date = null; return; } String s1 = null; for (int i = 0; i < fmts.length; i++) { try { date = fmts[i].parse(s); firePropertyChange(); return; } catch (ParseException parseexception) { s1 = parseexception.getMessage(); } } throw new IllegalArgumentException(s1); } /** * Sets the value attribute of the DateEditor object * * @param obj The new value value */ public void setValue(Object obj) { date = (Date) obj; } /** * Gets the asText attribute of the DateEditor object * * @return The asText value */ public String getAsText() { if (date != null) { return fmts[0].format(date); } else { return ""; } } /** * Gets the javaInitializationString attribute of the DateEditor object * * @return The javaInitializationString value */ public String getJavaInitializationString() { return "null"; } /** * Gets the value attribute of the DateEditor object * * @return The value value */ public Object getValue() { return date; } } --- NEW FILE: NumberEditor.java --- /* * EJT, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package net.sourceforge.ejtools.awt.editors; import java.beans.PropertyEditorSupport; import java.math.BigDecimal; import java.math.BigInteger; /** * Description of the Class * * @author laurent * @created 6 avril 2002 */ public class NumberEditor extends PropertyEditorSupport { /** Description of the Field */ protected Class clazz = Integer.class; /** Description of the Field */ protected Object value; /** Constructor */ public NumberEditor() { value = new Integer(0); } /** * Setter for the asText attribute * * @param s The new value */ public void setAsText(String s) { if (clazz.equals(Integer.class)) { value = new Integer(s); } else { if (clazz.equals(Float.class)) { value = new Float(s); } else { if (clazz.equals(Double.class)) { value = new Double(s); } else { if (clazz.equals(Byte.class)) { value = new Byte(s); } else { if (clazz.equals(Short.class)) { value = new Short(s); } else { if (clazz.equals(Long.class)) { value = new Long(s); } else { } } } } } } firePropertyChange(); } /** * Setter for the value attribute * * @param obj The new value */ public void setValue(Object obj) { value = obj; clazz = obj.getClass(); firePropertyChange(); } /** * Getter for the asText attribute * * @return The value */ public String getAsText() { return value.toString(); } /** * Getter for the value attribute * * @return The value */ public Object getValue() { return value; } } --- NEW FILE: ObjectNameEditor.java --- /* * EJT, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package net.sourceforge.ejtools.awt.editors; import java.awt.Component; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.beans.PropertyEditorSupport; import javax.management.ObjectName; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.SwingUtilities; import net.sourceforge.ejtools.jmx.ObjectNameFinder; /** * Description of the Class * * @author laurent * @created 6 avril 2002 */ public class ObjectNameEditor extends PropertyEditorSupport { /** Description of the Field */ protected JButton button; /** Description of the Field */ protected JPanel panel; /** Description of the Field */ protected JTextField text; /** Description of the Field */ protected Object value; /** Description of the Field */ protected static ImageIcon icon = new ImageIcon(ObjectNameEditor.class.getResource("/toolbarButtonGraphics/general/Bookmarks16.gif")); /** Constructor */ public ObjectNameEditor() { panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); text = new JTextField(20); if (icon != null) { button = new JButton(icon); } else { button = new JButton("View"); } panel.add(button); panel.add(text); panel.add(Box.createHorizontalGlue()); button.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent evt) { ObjectNameFinder finder = (ObjectNameFinder) SwingUtilities.getAncestorOfClass(ObjectNameFinder.class, panel); if ((finder != null) && (value != null)) { finder.searchObjectName(value.toString()); } } } ); } /** * Getter for the asText attribute * * @return The value */ public String getAsText() { return value.toString(); } /** * Gets the customEditor attribute of the ObjectNameEditor object * * @return The customEditor value */ public Component getCustomEditor() { return panel; } /** * Getter for the value attribute * * @return The value */ public Object getValue() { return value; } /** * Setter for the asText attribute * * @param s The new value */ public void setAsText(String s) { try { value = new ObjectName(s); } catch (Exception e) { } text.setText(value.toString()); firePropertyChange(); } /** * Setter for the value attribute * * @param obj The new value */ public void setValue(Object obj) { value = obj; text.setText(value.toString()); firePropertyChange(); } /** * Description of the Method * * @return Description of the Return Value */ public boolean supportsCustomEditor() { return true; } } --- NEW FILE: PropertiesEditor.java --- /* * EJT, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package net.sourceforge.ejtools.awt.editors; import java.beans.PropertyEditorSupport; import java.awt.Component; import java.util.Properties; import javax.swing.JTable; import javax.swing.table.AbstractTableModel; /** *Description of the Class * * @author letiembl * @created 19 octobre 2001 */ public class PropertiesEditor extends PropertyEditorSupport { protected Object value; public PropertiesEditor() { value = new Properties(); } public void setAsText(String s) { firePropertyChange(); } public void setValue(Object obj) { firePropertyChange(); } public String getAsText() { return value.toString(); } public Component getCustomEditor() { return new PropertiesView(); } /** *Gets the value attribute of the FileEditor object * * @return The value value */ public Object getValue() { return value; } /** *Description of the Method * * @return Description of the Returned Value */ public boolean supportsCustomEditor() { return true; } /** *Description of the Class * * @author letiembl * @created 19 octobre 2001 */ class PropertiesView extends JTable { } } --- NEW FILE: URLEditor.java --- /* * EJT, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package net.sourceforge.ejtools.awt.editors; import java.beans.PropertyEditorSupport; import java.net.URL; /** * Description of the Class * * @author laurent * @created 6 avril 2002 */ public class URLEditor extends PropertyEditorSupport { /** Description of the Field */ protected Object value; /** Constructor */ public URLEditor() { } /** * Getter for the asText attribute * * @return The value */ public String getAsText() { return value.toString(); } /** * Getter for the value attribute * * @return The value */ public Object getValue() { return value; } /** * Setter for the asText attribute * * @param s The new value */ public void setAsText(String s) { try { value = new URL(s); } catch (Exception e) { } firePropertyChange(); } /** * Setter for the value attribute * * @param obj The new value */ public void setValue(Object obj) { value = obj; firePropertyChange(); } } |