Java by API/org.eclipse.jface.viewers/TextViewer — различия между версиями

Материал из Java эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 17:43, 31 мая 2010

TextViewer: getTextWidget()

import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.TextViewer;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.widgets.ruposite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class MainClass extends ApplicationWindow {
  public MainClass() {
    super(null);
  }
  public void run() {
    setBlockOnOpen(true);
    open();
    Display.getCurrent().dispose();
  }
  protected void configureShell(Shell shell) {
    super.configureShell(shell);
    shell.setText("Text Editor 2");
    shell.setSize(600, 400);
  }
  protected Control createContents(Composite parent) {
    TextViewer viewer = new TextViewer(parent, SWT.V_SCROLL);
    final StyledText styledText = viewer.getTextWidget();
    styledText.setWordWrap(true);
    styledText.addKeyListener(new KeyAdapter() {
      public void keyReleased(KeyEvent event) {
        if (event.keyCode == "p" && (event.stateMask & SWT.CTRL) != 0) {
          styledText.print();
        }
      }
    });
    viewer.setDocument(new Document());
    return styledText;
  }
  public static void main(String[] args) {
    new MainClass().run();
  }
}





TextViewer: setDocument(IDocument idoc)

import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.TextViewer;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.ruposite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class MainClass extends ApplicationWindow {
  public MainClass() {
    super(null);
  }
  public void run() {
    setBlockOnOpen(true);
    open();
    Display.getCurrent().dispose();
  }
  protected void configureShell(Shell shell) {
    super.configureShell(shell);
    shell.setText("Text Editor");
    shell.setSize(600, 400);
  }
  protected Control createContents(Composite parent) {
    TextViewer viewer = new TextViewer(parent, SWT.NONE);
    viewer.setDocument(new Document());
    return viewer.getTextWidget();
  }
  public static void main(String[] args) {
    new MainClass().run();
  }
}