1 10 11 12 package org.enhydra.jawe.xml.panels; 13 14 import org.enhydra.jawe.xml.*; 15 16 import java.util.*; 17 import javax.swing.*; 18 import java.awt.*; 19 import java.awt.event.*; 20 21 24 public class XMLTextPanel extends XMLPanel { 25 26 private static Dimension textFieldDimension=new Dimension(200,20); 27 28 public static int DTDTextPanel_SMALL=0; 29 public static int DTDTextPanel_MEDIUM=1; 30 public static int DTDTextPanel_LARGE=2; 31 32 public XMLTextPanel (XMLElement myOwner) { 33 this(myOwner,XMLPanel.BOX_LAYOUT,false,false); 34 } 35 36 public XMLTextPanel (XMLElement myOwner,int layout, 37 boolean isVertical,boolean isPasswordField) { 38 39 super(myOwner,3,"",layout,isVertical,false); 40 41 JLabel jl=new JLabel(myOwner.toLabel()+": "); 42 jl.setAlignmentX(Component.LEFT_ALIGNMENT); 43 jl.setAlignmentY(Component.BOTTOM_ALIGNMENT); 44 jl.setHorizontalAlignment(SwingConstants.RIGHT); 45 46 final JTextField jtf; 47 if (!isPasswordField) { 48 jtf=new JTextField(); 49 } else { 50 jtf=new JPasswordField(); 51 } 52 jtf.setText(myOwner.toValue().toString()); 53 jtf.setAlignmentX(Component.LEFT_ALIGNMENT); 54 jtf.setAlignmentY(Component.BOTTOM_ALIGNMENT); 55 jtf.setMinimumSize(new Dimension(textFieldDimension)); 56 jtf.setMaximumSize(new Dimension(textFieldDimension)); 57 jtf.setPreferredSize(new Dimension(textFieldDimension)); 58 59 jtf.setEnabled(!myOwner.isReadOnly()); 60 61 Dimension minSize = new Dimension(5, 10); 62 Dimension prefSize = new Dimension(100, 10); 63 Dimension maxSize = new Dimension(Short.MAX_VALUE,10); 64 65 70 71 add(Box.createHorizontalGlue()); 72 add(jl); 73 add(jtf); 74 75 } 76 77 public boolean checkRequired () { 78 if (isEmpty() && getOwner().isRequired() && !getOwner().isReadOnly()) { 79 80 XMLPanel.defaultErrorMessage(this.getDialog(),((JLabel)getComponent(1)).getText()); 81 ((JTextField)getComponent(2)).requestFocus(); 82 return false; 83 } 84 return true; 85 } 86 87 public boolean isEmpty () { 88 return getText().trim().equals(""); 89 } 90 91 public void setElements () { 92 getOwner().setValue(getText()); 93 } 94 95 public String getText () { 96 return ((JTextField)getComponent(2)).getText(); 97 } 98 99 } 100 | Popular Tags |