1 53 54 55 package swingwtx.swing; 56 57 import swingwtx.swing.text.*; 58 59 import org.eclipse.swt.widgets.*; 60 import org.eclipse.swt.*; 61 62 public class JTextField extends swingwtx.swing.text.JTextComponent implements SwingConstants { 63 64 protected int pCols = 0; 65 66 67 private String retVal = ""; 68 69 public JTextField() { this(null, "", 0); } 70 public JTextField(int columns) { this(null, "", columns); } 71 public JTextField(String text) { this(null, text, 0); } 72 public JTextField(String text, int columns) { this(null, text, columns); } 73 public JTextField(Document doc, String text, int columns) { 74 super(); 75 if (doc != null) setDocument(doc); 76 pText = text; 77 pCols = columns; 78 if (pCols != 0) calculateFromCols(); 79 if (pText != null) 80 if (!pText.equals("")) 81 view.updateModelFromComponent(pText); 82 } 83 84 88 protected void calculateFromCols() { 89 setPreferredSize( new swingwt.awt.Dimension((SwingWTUtils.getRenderStringWidth("W") * pCols), 25)); 90 } 91 92 public int getColumns() { return pCols; } 93 public void setColumns(int columns) { pCols = columns; if (SwingWTUtils.isSWTControlAvailable(ppeer)) ppeer.setTextLimit(pCols); } 94 public void setEditable(boolean b) { pEditable = b; if (SwingWTUtils.isSWTControlAvailable(ppeer)) ppeer.setEditable(b); } 95 public boolean isEditable() { return pEditable; } 96 97 100 protected swingwt.awt.Dimension calculatePreferredSize() { 101 swingwt.awt.Dimension size = new swingwt.awt.Dimension( 102 SwingWTUtils.getRenderStringWidth(pText), 103 SwingWTUtils.getRenderStringHeight(pText) + 4); 104 setSize(size); 105 return size; 106 } 107 108 113 public void setSwingWTParent(swingwt.awt.Container parent) throws Exception { 114 descendantHasPeer = true; 115 ppeer = new Text(parent.getComposite(), SWT.BORDER | SWT.SINGLE); 116 if (pText == null) 117 ppeer.setText(""); 118 else 119 ppeer.setText(pText); 120 ppeer.setEditable(pEditable); 121 if (pCols > 0) ppeer.setTextLimit(pCols); 122 peer = ppeer; 123 this.parent = parent; 124 } 125 126 } 127 | Popular Tags |