View Javadoc
1 /* ------------------------------------------------------------------- 2 * Java source file for the class InsetsEditor 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: InsetsEditor.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 29 import net.jbeans.util.text.*; 30 31 /*==================================================================== 32 Implementation of class InsetsEditor 33 ====================================================================*/ 34 /*** 35 * An editor for editing Insets. 36 * 37 * @version $Revision: 1.1.1.1 $ 38 * @author Masahiro Takatsuka (masa@jbeans.net) 39 * @see EditorSupport 40 */ 41 42 public final class InsetsEditor extends EditorSupport { 43 private JTextField topTF; 44 private JTextField leftTF; 45 private JTextField bottomTF; 46 private JTextField rightTF; 47 48 public InsetsEditor() { 49 this.topTF = new JTextField(); 50 this.topTF.setDocument(new NumberDocument()); 51 this.leftTF = new JTextField(); 52 this.leftTF.setDocument(new NumberDocument()); 53 this.bottomTF = new JTextField(); 54 this.bottomTF.setDocument(new NumberDocument()); 55 this.rightTF = new JTextField(); 56 this.rightTF.setDocument(new NumberDocument()); 57 58 JPanel panel = new JPanel(); 59 panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); 60 panel.add(new JLabel("Top: ")); 61 panel.add(this.topTF); 62 panel.add(new JLabel("Left: ")); 63 panel.add(this.leftTF); 64 panel.add(new JLabel("Bottom: ")); 65 panel.add(this.bottomTF); 66 panel.add(new JLabel("Right: ")); 67 panel.add(this.rightTF); 68 setPanel(panel); 69 } 70 71 public final void setValue(Object value) { 72 super.setValue(value); 73 74 Insets insets = (Insets)value; 75 76 this.topTF.setText(Integer.toString(insets.top)); 77 this.leftTF.setText(Integer.toString(insets.left)); 78 this.bottomTF.setText(Integer.toString(insets.bottom)); 79 this.rightTF.setText(Integer.toString(insets.right)); 80 } 81 82 public final Object getValue() { 83 int top = Integer.parseInt(this.topTF.getText()); 84 int left = Integer.parseInt(this.leftTF.getText()); 85 int bottom = Integer.parseInt(this.bottomTF.getText()); 86 int right = Integer.parseInt(this.rightTF.getText()); 87 88 return new Insets(top, left, bottom, right); 89 } 90 91 public final String getJavaInitializationString() { 92 Insets insets = (Insets) getValue(); 93 return "new java.awt.Insets(" + insets.top + ", " + insets.left + ", " + insets.bottom + ", " + insets.right + ")"; 94 } 95 }

This page was automatically generated by Maven