1 70 71 72 package swingwtx.swing; 73 74 import org.eclipse.swt.SWT; 75 76 import swingwt.awt.Component; 77 78 public class JLabel extends swingwtx.swing.JComponent implements SwingConstants { 79 80 81 protected org.eclipse.swt.widgets.Label ppeer = null; 82 83 protected String pText = ""; 84 85 protected Icon pImage = null; 86 87 protected int pHTextPosition = LEFT; 88 89 protected int pVTextPosition = TOP; 90 91 protected int pHAlign = LEFT; 92 93 protected int pVAlign = TOP; 94 95 protected Component labelFor = null; 96 97 98 public JLabel() { } 99 102 public JLabel(String text) { pText = text; } 103 107 public JLabel(String text, int align) { pText = text; setHorizontalAlignment(align); } 108 111 public JLabel(Icon icon) { pImage = icon; } 112 113 public JLabel(String text, Icon icon, int align) { pText = text; pImage = icon; setHorizontalAlignment(align); } 114 115 118 public String getText() 119 { 120 return pText; 121 } 122 123 127 public void setText(String text) { 128 pText = text; 129 if (pText == null) pText = ""; 130 SwingUtilities.invokeSync(new Runnable () { 131 public void run() { 132 if (SwingWTUtils.isSWTControlAvailable(ppeer)) 133 ppeer.setText(SwingWTUtils.removeHTML(pText)); 134 if (parent != null) { 135 parent.invalidate(); 137 repaint(); 138 } 139 } 140 }); 141 } 142 143 147 public void setLabelFor(Component c) { labelFor = c; } 148 152 public Component getLabelFor() { return labelFor; } 153 154 155 public void setDisplayedMnemonic(char c) {} 156 157 public void setDisplayedMnemonic(int c) {} 158 159 163 public void setIcon(Icon icon) { 164 pImage = icon; 165 final JLabel pthis = this; 166 SwingUtilities.invokeSync(new Runnable () { 167 public void run() { 168 if (SwingWTUtils.isSWTControlAvailable(ppeer)) { 169 if (pImage == null) 170 ppeer.setImage(null); 171 else 172 ppeer.setImage(SwingWTUtils.getSWTImageFromSwingIcon(pthis, pImage)); 173 if (parent != null) { 175 parent.invalidate(); 176 repaint(); 177 } 178 } 179 } 180 }); 181 } 182 183 186 public Icon getIcon() { return pImage; } 187 188 189 public Icon getDisabledIcon() { return null; } 190 191 public void setDisabledIcon(Icon icon) { } 192 193 198 public void setHorizontalAlignment(final int align) { pHAlign = align; SwingUtilities.invokeAsync(new Runnable () { public void run() { if (SwingWTUtils.isSWTControlAvailable(ppeer)) ppeer.setAlignment(SwingWTUtils.translateSwingAlignmentConstant(align) | SwingWTUtils.translateSwingAlignmentConstant(pVAlign));}}); } 199 204 public void setVerticalAlignment(final int align) { pVAlign = align; SwingUtilities.invokeAsync(new Runnable () { public void run() {if (SwingWTUtils.isSWTControlAvailable(ppeer))ppeer.setAlignment(SwingWTUtils.translateSwingAlignmentConstant(align) | SwingWTUtils.translateSwingAlignmentConstant(pHAlign));}});} 205 209 public int getHorizontalAlignment() { return pHAlign; } 210 214 public int getVerticalAlignment() { return pVAlign; } 215 216 public void setHorizontalTextPosition(int textpos) { setHorizontalAlignment(textpos); } 217 218 public void setVerticalTextPosition(int textpos) { setVerticalAlignment(textpos); } 219 220 public int getHorizontalTextPosition() { return getHorizontalAlignment(); } 221 222 public int getVerticalTextPosition() { return getVerticalAlignment(); } 223 224 227 protected swingwt.awt.Dimension calculatePreferredSize() { 228 swingwt.awt.Dimension size = new swingwt.awt.Dimension( 229 SwingWTUtils.getRenderStringWidth(pText), 230 SwingWTUtils.getRenderStringHeight(pText)); 231 setSize(size); 232 return size; 233 } 234 235 240 public void setSwingWTParent(swingwt.awt.Container parent) throws Exception { 241 descendantHasPeer = true; 242 ppeer = new org.eclipse.swt.widgets.Label(parent.getComposite(), SWT.NONE); 243 if (pText != null) ppeer.setText(SwingWTUtils.removeHTML(pText)); 244 ppeer.setAlignment(SwingWTUtils.translateSwingAlignmentConstant(pHAlign) | 245 SwingWTUtils.translateSwingAlignmentConstant(pVAlign)); 246 if (pImage != null) setIcon(pImage); 247 peer = ppeer; 248 this.parent = parent; 249 } 250 } 251 | Popular Tags |