View Javadoc

1   /*
2    *  File: MultiLineLabel.java 
3    *  Copyright (c) 2004-2007  Peter Kliem (Peter.Kliem@jaret.de)
4    *  A commercial license is available, see http://www.jaret.de.
5    *
6    * All rights reserved. This program and the accompanying materials
7    * are made available under the terms of the Common Public License v1.0
8    * which accompanies this distribution, and is available at
9    * http://www.eclipse.org/legal/cpl-v10.html
10   */
11  package de.jaret.util.ui;
12  
13  import org.eclipse.swt.events.PaintEvent;
14  import org.eclipse.swt.events.PaintListener;
15  import org.eclipse.swt.graphics.GC;
16  import org.eclipse.swt.widgets.Canvas;
17  import org.eclipse.swt.widgets.Composite;
18  
19  import de.jaret.util.swt.TextRenderer;
20  
21  /**
22   * Mostly for testing.
23   * 
24   * @author Peter Kliem
25   * @version $Id: MultiLineLabel.java 242 2007-02-11 21:05:07Z olk $
26   */
27  public class MultiLineLabel extends Canvas {
28      String _text;
29  
30      public MultiLineLabel(Composite parent, int style) {
31          super(parent, style);
32          addPaintListener(new PaintListener() {
33              public void paintControl(PaintEvent event) {
34                  onPaint(event);
35              }
36  
37          });
38      }
39  
40      private void onPaint(PaintEvent event) {
41          GC gc = event.gc;
42          TextRenderer.renderText(gc, getClientArea(), true, false, _text);
43      }
44  
45      /**
46       * @return Returns the text.
47       */
48      public String getText() {
49          return _text;
50      }
51  
52      /**
53       * @param text The text to set.
54       */
55      public void setText(String text) {
56          _text = text;
57      }
58  }