View Javadoc
1 /* ------------------------------------------------------------------- 2 * Java source file for the class DimensionEditor 3 * 4 * Copyright (c), 2002, Masahiro Takatsuka. 5 * All Rights Researved. 6 * 7 * Original Author: Masahiro Takatsuka (masa@jbeans.net) 8 * $Author: takatsukam $ 9 * 10 * $Date: 2003/07/25 04:51:45 $ 11 * 12 * $Id: DimensionEditor.java,v 1.1.1.1 2003/07/25 04:51:45 takatsukam Exp $ 13 * 14 * Reference: Document no: 15 * ___ ___ 16 * 17 * To Do: 18 * ___ 19 * 20 ------------------------------------------------------------------- */ 21 22 /* --------------------------- Package ---------------------------- */ 23 package net.jbeans.bean.property.editor; 24 25 /* ------------------ Import classes (packages) ------------------- *//package-summary/html">color="#329900"> ------------------ Import classes (packages) ------------------- *//package-summary.html">color="#329900">/* ------------------ Import classes (packages) ------------------- *//package-summary.html">color="#329900"> ------------------ Import classes (packages) ------------------- */ 26 import java.awt.*; 27 import javax.swing.*; 28 import net.jbeans.util.text.*; 29 30 /*==================================================================== 31 Implementation of class DimensionEditor 32 ====================================================================*/ 33 /*** 34 * A PropertyEditor for editing a Dimension object. 35 * 36 * @version $Revision: 1.1.1.1 $ 37 * @author Masahiro Takatsuka (masa@jbeans.net) 38 * @see EditorSupport 39 */ 40 41 public final class DimensionEditor extends EditorSupport { 42 private JTextField widthTF; 43 private JTextField heightTF; 44 45 public DimensionEditor() { 46 this.widthTF = new JTextField(); 47 this.widthTF.setDocument(new NumberDocument()); 48 this.heightTF = new JTextField(); 49 this.heightTF.setDocument(new NumberDocument()); 50 51 JLabel wlabel = new JLabel("Width: "); 52 JLabel hlabel = new JLabel("Height: "); 53 54 JPanel panel = new JPanel(); 55 panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); 56 panel.add(wlabel); 57 panel.add(this.widthTF); 58 panel.add(hlabel); 59 panel.add(this.heightTF); 60 setPanel(panel); 61 } 62 63 public final void setValue(Object value) { 64 super.setValue(value); 65 66 Dimension dim = (Dimension)value; 67 68 this.widthTF.setText(Integer.toString(dim.width)); 69 this.heightTF.setText(Integer.toString(dim.height)); 70 } 71 72 public final Object getValue() { 73 int width = Integer.parseInt(this.widthTF.getText()); 74 int height = Integer.parseInt(this.heightTF.getText()); 75 76 return new Dimension(width, height); 77 } 78 79 public final String getJavaInitializationString() { 80 Dimension dim = (Dimension) getValue(); 81 return "new java.awt.Dimension(" + dim.width + ", " + dim.height + ")"; 82 } 83 }

This page was automatically generated by Maven