Revision 3be6ef3e
Added by Niels Hoffmann over 13 years ago
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/LineWrapSupport.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2007 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
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. |
|
8 |
*/ |
|
9 |
|
|
10 |
package eu.etaxonomy.taxeditor.editor.name; |
|
11 |
|
|
12 |
import org.apache.log4j.Logger; |
|
13 |
import org.eclipse.jface.text.TextViewer; |
|
14 |
import org.eclipse.swt.custom.StyledText; |
|
15 |
import org.eclipse.swt.events.ModifyEvent; |
|
16 |
import org.eclipse.swt.events.ModifyListener; |
|
17 |
import org.eclipse.ui.forms.IManagedForm; |
|
18 |
import org.eclipse.ui.forms.widgets.ScrolledForm; |
|
19 |
|
|
20 |
/** |
|
21 |
* Checks whether the ScrolledForm a TextViewer is on needs to be |
|
22 |
* redrawn because of a new line break or the removal of an existing |
|
23 |
* one ... |
|
24 |
* <p> |
|
25 |
* ... in theory, anyway. Until I figure out how to detect a word wrap, |
|
26 |
* the ScrolledForm is redrawn with every modify event. |
|
27 |
* |
|
28 |
* @author p.ciardelli |
|
29 |
* @created 19.05.2008 |
|
30 |
* @version 1.0 |
|
31 |
*/ |
|
32 |
public class LineWrapSupport { |
|
33 |
private static final Logger logger = Logger |
|
34 |
.getLogger(LineWrapSupport.class); |
|
35 |
|
|
36 |
ModifyListener listener = new LineWrapListener(); |
|
37 |
int lineCount; |
|
38 |
|
|
39 |
private StyledText textWidget; |
|
40 |
private ScrolledForm scrolledForm; |
|
41 |
|
|
42 |
// private TextViewer viewer; |
|
43 |
|
|
44 |
/** |
|
45 |
* @return the viewer |
|
46 |
*/ |
|
47 |
// public TextViewer getViewer() { |
|
48 |
// return viewer; |
|
49 |
// } |
|
50 |
|
|
51 |
public LineWrapSupport(TextViewer viewer, IManagedForm form) { |
|
52 |
|
|
53 |
if (viewer == null) { |
|
54 |
throw new IllegalArgumentException( |
|
55 |
"The provided TextViewer object is null."); |
|
56 |
} |
|
57 |
|
|
58 |
// this.viewer = viewer; |
|
59 |
|
|
60 |
textWidget = viewer.getTextWidget(); |
|
61 |
textWidget.addModifyListener(listener); |
|
62 |
|
|
63 |
this.lineCount = textWidget.getLinePixel(textWidget.getLineCount()); |
|
64 |
this.scrolledForm = form.getForm(); |
|
65 |
|
|
66 |
logger.trace(this.getClass().getSimpleName() + " created"); |
|
67 |
} |
|
68 |
|
|
69 |
/** |
|
70 |
* Redraws the scrolledForm if a line wrap is detected. |
|
71 |
*/ |
|
72 |
private void checkLineCount() { |
|
73 |
|
|
74 |
boolean lineWrapDetected = true; |
|
75 |
if (lineWrapDetected ) { |
|
76 |
scrolledForm.getBody().layout(); |
|
77 |
} |
|
78 |
} |
|
79 |
|
|
80 |
/** |
|
81 |
* Calls <code>checkLineCount()</code> on a modify event. |
|
82 |
* |
|
83 |
* @author p.ciardelli |
|
84 |
* @created 21.05.2008 |
|
85 |
* @version 1.0 |
|
86 |
*/ |
|
87 |
class LineWrapListener implements ModifyListener { |
|
88 |
|
|
89 |
public void modifyText(ModifyEvent e) { |
|
90 |
checkLineCount(); |
|
91 |
} |
|
92 |
} |
|
93 |
} |
|
1 |
/** |
|
2 |
* Copyright (C) 2007 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
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. |
|
8 |
*/ |
|
9 |
|
|
10 |
package eu.etaxonomy.taxeditor.editor.name; |
|
11 |
|
|
12 |
import org.apache.log4j.Logger; |
|
13 |
import org.eclipse.jface.text.TextViewer; |
|
14 |
import org.eclipse.swt.custom.StyledText; |
|
15 |
import org.eclipse.swt.events.ModifyEvent; |
|
16 |
import org.eclipse.swt.events.ModifyListener; |
|
17 |
import org.eclipse.ui.forms.IManagedForm; |
|
18 |
import org.eclipse.ui.forms.widgets.ScrolledForm; |
|
19 |
|
|
20 |
/** |
|
21 |
* Checks whether the ScrolledForm a TextViewer is on needs to be |
|
22 |
* redrawn because of a new line break or the removal of an existing |
|
23 |
* one ... |
|
24 |
* <p> |
|
25 |
* ... in theory, anyway. Until I figure out how to detect a word wrap, |
|
26 |
* the ScrolledForm is redrawn with every modify event. |
|
27 |
* |
|
28 |
* @author p.ciardelli |
|
29 |
* @created 19.05.2008 |
|
30 |
* @version 1.0 |
|
31 |
*/ |
|
32 |
public class LineWrapSupport { |
|
33 |
private static final Logger logger = Logger |
|
34 |
.getLogger(LineWrapSupport.class); |
|
35 |
|
|
36 |
ModifyListener listener = new LineWrapListener(); |
|
37 |
int lineCount; |
|
38 |
|
|
39 |
private StyledText textWidget; |
|
40 |
private ScrolledForm scrolledForm; |
|
41 |
|
|
42 |
// private TextViewer viewer; |
|
43 |
|
|
44 |
/** |
|
45 |
* <p>Constructor for LineWrapSupport.</p> |
|
46 |
* |
|
47 |
* @param viewer a {@link org.eclipse.jface.text.TextViewer} object. |
|
48 |
* @param form a {@link org.eclipse.ui.forms.IManagedForm} object. |
|
49 |
*/ |
|
50 |
// public TextViewer getViewer() { |
|
51 |
// return viewer; |
|
52 |
// } |
|
53 |
public LineWrapSupport(TextViewer viewer, IManagedForm form) { |
|
54 |
|
|
55 |
if (viewer == null) { |
|
56 |
throw new IllegalArgumentException( |
|
57 |
"The provided TextViewer object is null."); |
|
58 |
} |
|
59 |
|
|
60 |
// this.viewer = viewer; |
|
61 |
|
|
62 |
textWidget = viewer.getTextWidget(); |
|
63 |
textWidget.addModifyListener(listener); |
|
64 |
|
|
65 |
this.lineCount = textWidget.getLinePixel(textWidget.getLineCount()); |
|
66 |
this.scrolledForm = form.getForm(); |
|
67 |
|
|
68 |
logger.trace(this.getClass().getSimpleName() + " created"); |
|
69 |
} |
|
70 |
|
|
71 |
/** |
|
72 |
* Redraws the scrolledForm if a line wrap is detected. |
|
73 |
*/ |
|
74 |
private void checkLineCount() { |
|
75 |
|
|
76 |
boolean lineWrapDetected = true; |
|
77 |
if (lineWrapDetected ) { |
|
78 |
scrolledForm.getBody().layout(); |
|
79 |
} |
|
80 |
} |
|
81 |
|
|
82 |
/** |
|
83 |
* Calls <code>checkLineCount()</code> on a modify event. |
|
84 |
* |
|
85 |
* @author p.ciardelli |
|
86 |
* @created 21.05.2008 |
|
87 |
* @version 1.0 |
|
88 |
*/ |
|
89 |
class LineWrapListener implements ModifyListener { |
|
90 |
|
|
91 |
public void modifyText(ModifyEvent e) { |
|
92 |
checkLineCount(); |
|
93 |
} |
|
94 |
} |
|
95 |
} |
Also available in: Unified diff
performed javacscript:fix and worked on documentation