1 43 44 45 package swingwtx.swing; 46 47 import swingwtx.swing.text.*; 48 49 import org.eclipse.swt.widgets.*; 50 import org.eclipse.swt.*; 51 52 public class JPasswordField extends swingwtx.swing.JTextField { 53 54 55 protected Text ppeer = null; 56 57 protected String pText = ""; 58 61 protected char pEchoChar = '*'; 62 63 64 private String retVal = ""; 65 66 private char[] retChars = null; 67 68 69 public JPasswordField() { 70 this(null, "", -1); 71 } 72 75 public JPasswordField(String text) { 76 this(null, text, 0); 77 } 78 81 public JPasswordField(int columns) { 82 this(null, "", columns); 83 } 84 88 public JPasswordField(String text, int columns) { 89 this(null, text, columns); 90 } 91 96 public JPasswordField(Document document, String text, int columns) { 97 super(); 98 if (document != null) setDocument(document); 99 if (text != null) { setText(text); view.updateModelFromComponent(getText()); } 100 } 101 102 103 public char getEchoChar() { if (!SwingWTUtils.isSWTControlAvailable(ppeer)) return pEchoChar; else return ppeer.getEchoChar(); } 104 105 public void setEchoChar(char c) { if (!SwingWTUtils.isSWTControlAvailable(ppeer)) pEchoChar = c; else ppeer.setEchoChar(c); } 106 107 public boolean isEchoCharSet() { return true; } 108 109 public String getText() { 110 retVal = ""; 111 SwingUtilities.invokeSync(new Runnable () { 112 public void run() { 113 if (SwingWTUtils.isSWTControlAvailable(ppeer)) 114 retVal = ppeer.getText(); 115 else retVal = pText; 116 } 117 }); 118 return retVal; 119 } 120 121 122 public char[] getPassword() { 123 retChars = null; 124 SwingUtilities.invokeSync(new Runnable () { 125 public void run() { 126 if (SwingWTUtils.isSWTControlAvailable(ppeer)) 127 retChars = ppeer.getText().toCharArray(); 128 else retChars = pText.toCharArray(); 129 } 130 }); 131 return retChars; 132 } 133 134 135 public void setText(final String text) { 136 pText = text; 137 SwingUtilities.invokeSync(new Runnable () { 138 public void run() { 139 if (SwingWTUtils.isSWTControlAvailable(ppeer)) 140 ppeer.setText(text);} 141 }); 142 } 143 144 147 protected swingwt.awt.Dimension calculatePreferredSize() { 148 swingwt.awt.Dimension size = new swingwt.awt.Dimension( 149 SwingWTUtils.getRenderStringWidth(pText), 150 SwingWTUtils.getRenderStringHeight(pText) + 4); 151 setSize(size); 152 return size; 153 } 154 155 160 public void setSwingWTParent(swingwt.awt.Container parent) throws Exception { 161 descendantHasPeer = true; 162 ppeer = new Text(parent.getComposite(), SWT.BORDER | SWT.SINGLE); 163 ppeer.setEchoChar(pEchoChar); 164 ppeer.setText(pText); 165 peer = ppeer; 166 this.parent = parent; 167 } 168 169 } 170 | Popular Tags |