2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.editor
.name
.container
;
11 import org
.apache
.log4j
.Logger
;
12 import org
.eclipse
.jface
.text
.TextViewer
;
13 import org
.eclipse
.swt
.custom
.StyledText
;
14 import org
.eclipse
.swt
.events
.ModifyEvent
;
15 import org
.eclipse
.swt
.events
.ModifyListener
;
16 import org
.eclipse
.ui
.forms
.IManagedForm
;
17 import org
.eclipse
.ui
.forms
.widgets
.ScrolledForm
;
20 * Checks whether the ScrolledForm a TextViewer is on needs to be
21 * redrawn because of a new line break or the removal of an existing
24 * ... in theory, anyway. Until I figure out how to detect a word wrap,
25 * the ScrolledForm is redrawn with every modify event.
30 public class LineWrapSupport
{
31 private static final Logger logger
= Logger
32 .getLogger(LineWrapSupport
.class);
34 ModifyListener listener
= new LineWrapListener();
37 private StyledText textWidget
;
38 private ScrolledForm scrolledForm
;
40 // private TextViewer viewer;
43 * <p>Constructor for LineWrapSupport.</p>
45 * @param viewer a {@link org.eclipse.jface.text.TextViewer} object.
46 * @param form a {@link org.eclipse.ui.forms.IManagedForm} object.
48 // public TextViewer getViewer() {
51 public LineWrapSupport(TextViewer viewer
, IManagedForm form
) {
54 throw new IllegalArgumentException(
55 "The provided TextViewer object is null."); //$NON-NLS-1$
58 // this.viewer = viewer;
60 textWidget
= viewer
.getTextWidget();
61 textWidget
.addModifyListener(listener
);
63 this.lineCount
= textWidget
.getLinePixel(textWidget
.getLineCount());
64 this.scrolledForm
= form
.getForm();
66 logger
.trace(this.getClass().getSimpleName() + " created"); //$NON-NLS-1$
70 * Redraws the scrolledForm if a line wrap is detected.
72 private void checkLineCount() {
74 boolean lineWrapDetected
= true;
75 if (lineWrapDetected
) {
76 scrolledForm
.getBody().layout();
81 * Calls <code>checkLineCount()</code> on a modify event.
86 class LineWrapListener
implements ModifyListener
{
88 public void modifyText(ModifyEvent e
) {