Project

General

Profile

Download (2.73 KB) Statistics
| Branch: | Tag: | Revision:
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.singlesource.editor.name.container;
11

    
12
import javax.naming.OperationNotSupportedException;
13

    
14
import org.apache.log4j.Logger;
15
import org.eclipse.swt.custom.StyledText;
16
import org.eclipse.swt.events.ModifyEvent;
17
import org.eclipse.swt.events.ModifyListener;
18
import org.eclipse.ui.forms.IManagedForm;
19
import org.eclipse.ui.forms.widgets.ScrolledForm;
20

    
21
import eu.etaxonomy.taxeditor.singlesource.editor.name.container.ILineWrapSupport;
22
import eu.etaxonomy.taxeditor.singlesource.editor.name.container.NameViewerFacade;
23

    
24
/**
25
 * Checks whether the ScrolledForm a TextViewer is on needs to be
26
 *  redrawn because of a new line break or the removal of an existing
27
 *  one ...
28
 *  <p>
29
 *  ... in theory, anyway. Until I figure out how to detect a word wrap,
30
 *   the ScrolledForm is redrawn with every modify event.
31
 *
32
 * @author p.ciardelli
33
 * @created 19.05.2008
34
 * @version 1.0
35
 */
36
public class LineWrapSupportFacadeImpl implements ILineWrapSupport {
37
	private static final Logger logger = Logger
38
			.getLogger(LineWrapSupportFacadeImpl.class);
39
	
40
	ModifyListener listener = new LineWrapListener();
41
	int lineCount;
42

    
43
	private StyledText textWidget;
44
	private ScrolledForm scrolledForm;
45

    
46
//	private TextViewer viewer;
47
	
48
	/**
49
	 * <p>Constructor for LineWrapSupport.</p>
50
	 *
51
	 * @param viewer a {@link org.eclipse.jface.text.TextViewer} object.
52
	 * @param form a {@link org.eclipse.ui.forms.IManagedForm} object.
53
	 */
54
//	public TextViewer getViewer() {
55
//		return viewer;
56
//	}
57
	public LineWrapSupportFacadeImpl(NameViewerFacade viewer, IManagedForm form) {
58
		
59
		if (viewer == null) {
60
			throw new IllegalArgumentException(
61
					"The provided TextViewer object is null.");
62
		}
63
		
64
//		this.viewer = viewer;
65
		
66
		try {
67
			textWidget = (StyledText)viewer.getStyledText();
68
		} catch (OperationNotSupportedException e) {
69
		}
70
		textWidget.addModifyListener(listener);
71
				
72
		this.lineCount = textWidget.getLinePixel(textWidget.getLineCount());
73
		this.scrolledForm = form.getForm();
74
		
75
		logger.trace(this.getClass().getSimpleName() + " created");
76
	}
77
	
78
	/**
79
	 * Redraws the scrolledForm if a line wrap is detected. 
80
	 */
81
	private void checkLineCount() {
82

    
83
		boolean lineWrapDetected = true;
84
		if (lineWrapDetected ) {
85
			scrolledForm.getBody().layout();
86
		}
87
	}
88
	
89
	/**
90
	 * Calls <code>checkLineCount()</code> on a modify event.
91
	 * 
92
	 * @author p.ciardelli
93
	 * @created 21.05.2008
94
	 * @version 1.0
95
	 */
96
	class LineWrapListener implements ModifyListener {
97

    
98
		public void modifyText(ModifyEvent e) {
99
			checkLineCount();
100
		}
101
	}
102
}
(4-4/6)