View | Details | Raw Unified | Return to bug 178117 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/gef/examples/logicdesigner/figures/StickyNoteFigure.java (+2 lines)
Lines 44-49 Link Here
44
public StickyNoteFigure(int borderSize) {
44
public StickyNoteFigure(int borderSize) {
45
	setBorder(new MarginBorder(borderSize));
45
	setBorder(new MarginBorder(borderSize));
46
	FlowPage flowPage = new FlowPage();
46
	FlowPage flowPage = new FlowPage();
47
	flowPage.setTruncateVertically(true);
48
47
49
48
	textFlow = new TextFlow();
50
	textFlow = new TextFlow();
49
51
(-)src/org/eclipse/gef/examples/logicdesigner/edit/LabelCellEditorLocator.java (-1 / +5 lines)
Lines 15-20 Link Here
15
import org.eclipse.jface.viewers.CellEditor;
15
import org.eclipse.jface.viewers.CellEditor;
16
16
17
import org.eclipse.draw2d.geometry.Rectangle;
17
import org.eclipse.draw2d.geometry.Rectangle;
18
import org.eclipse.draw2d.text.FlowPage;
18
19
19
import org.eclipse.gef.tools.CellEditorLocator;
20
import org.eclipse.gef.tools.CellEditorLocator;
20
21
Lines 32-38 Link Here
32
33
33
public void relocate(CellEditor celleditor) {
34
public void relocate(CellEditor celleditor) {
34
	Text text = (Text)celleditor.getControl();
35
	Text text = (Text)celleditor.getControl();
35
	Rectangle rect = stickyNote.getClientArea();
36
37
	FlowPage flowPage = (FlowPage) stickyNote.getChildren().get(0);
38
    Rectangle rect = new Rectangle(stickyNote.getClientArea().getLocation(), flowPage
39
            .getPreferredSize(flowPage.getClientArea().width, -1));
36
	stickyNote.translateToAbsolute(rect);
40
	stickyNote.translateToAbsolute(rect);
37
	org.eclipse.swt.graphics.Rectangle trim = text.computeTrim(0, 0, 0, 0);
41
	org.eclipse.swt.graphics.Rectangle trim = text.computeTrim(0, 0, 0, 0);
38
	rect.translate(trim.x, trim.y);
42
	rect.translate(trim.x, trim.y);
(-)src/org/eclipse/gef/examples/logicdesigner/edit/LogicXYLayoutEditPolicy.java (-4 lines)
Lines 190-199 Link Here
190
		ResizableEditPolicy policy = new LogicResizableEditPolicy();
190
		ResizableEditPolicy policy = new LogicResizableEditPolicy();
191
		policy.setResizeDirections(0);
191
		policy.setResizeDirections(0);
192
		return policy;
192
		return policy;
193
	} else if (child instanceof LogicLabelEditPart) {
194
		ResizableEditPolicy policy = new LogicResizableEditPolicy();
195
		policy.setResizeDirections(PositionConstants.EAST | PositionConstants.WEST);
196
		return policy;
197
	}
193
	}
198
	
194
	
199
	return new LogicResizableEditPolicy();
195
	return new LogicResizableEditPolicy();
(-)src/org/eclipse/gef/examples/logicdesigner/model/LogicLabel.java (-12 / +1 lines)
Lines 14-21 Link Here
14
14
15
import org.eclipse.swt.graphics.Image;
15
import org.eclipse.swt.graphics.Image;
16
16
17
import org.eclipse.draw2d.geometry.Dimension;
18
19
import org.eclipse.gef.examples.logicdesigner.LogicMessages;
17
import org.eclipse.gef.examples.logicdesigner.LogicMessages;
20
18
21
public class LogicLabel
19
public class LogicLabel
Lines 47-68 Link Here
47
	return Integer.toString(count++);
45
	return Integer.toString(count++);
48
}
46
}
49
47
50
public Dimension getSize(){
51
	return new Dimension(size.width, -1);
52
}
53
54
private void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException {
48
private void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException {
55
	s.defaultReadObject();
49
	s.defaultReadObject();
56
}
50
}
57
51
58
public void setSize(Dimension d) {
59
	d.height = -1;
60
	super.setSize(d);
61
}
62
63
public void setLabelContents(String s){
52
public void setLabelContents(String s){
64
	text = s;
53
	text = s;
65
	firePropertyChange("labelContents", null, text); //$NON-NLS-2$//$NON-NLS-1$
54
	firePropertyChange("labelContents", null, text); //$NON-NLS-1$
66
}
55
}
67
56
68
public String toString() {
57
public String toString() {
(-)src/org/eclipse/draw2d/examples/text/CaretExampleWithVerticalTruncation.java (+134 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/ 
11
12
package org.eclipse.draw2d.examples.text;
13
14
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.events.KeyAdapter;
16
import org.eclipse.swt.graphics.Color;
17
import org.eclipse.swt.graphics.Font;
18
import org.eclipse.swt.layout.GridData;
19
import org.eclipse.swt.layout.GridLayout;
20
import org.eclipse.swt.widgets.Caret;
21
import org.eclipse.swt.widgets.Group;
22
import org.eclipse.swt.widgets.Label;
23
24
import org.eclipse.draw2d.ColorConstants;
25
import org.eclipse.draw2d.IFigure;
26
import org.eclipse.draw2d.LineBorder;
27
import org.eclipse.draw2d.MouseEvent;
28
import org.eclipse.draw2d.MouseMotionListener;
29
import org.eclipse.draw2d.PositionConstants;
30
import org.eclipse.draw2d.examples.AbstractExample;
31
import org.eclipse.draw2d.geometry.Point;
32
import org.eclipse.draw2d.text.CaretInfo;
33
import org.eclipse.draw2d.text.FlowPage;
34
import org.eclipse.draw2d.text.TextFlow;
35
36
public class CaretExampleWithVerticalTruncation extends AbstractExample {
37
38
TextFlow caretOwner;
39
TextFlow content[];
40
Caret caret;
41
private Label offsetLabel;
42
private Label trailLabel;
43
private Label charLabel;
44
45
protected IFigure getContents() {
46
	caret = new Caret(getFigureCanvas(), 0);
47
	final FlowPage page = new FlowPage() {
48
		protected void paintFigure(org.eclipse.draw2d.Graphics graphics) {
49
			graphics.setBackgroundColor(new Color(null, 190, 220, 250));
50
			graphics.fillRectangle(getBounds());
51
		};
52
	};
53
    page.setTruncateVertically(true);
54
55
	
56
//	page.setBorder(new LineBorder(ColorConstants.darkGray, 10));
57
	page.setHorizontalAligment(PositionConstants.CENTER);
58
	
59
	final TextFlow text = new TextFlow();
60
	text.setText("A TextFlow can be queried for an offset for a given Point relative " +
61
			"to it. The returned offset will be between 0 and N, where N is the length " +
62
			"of the figure's text.\n" +
63
			"<Chinese>\u6700\u65B0\u6D88\u606F</Chinese>.\n" +
64
			"<Japanese>\u65e5\u672c\u8a9e\u306e\u30da\u30fc\u30b8\u3092\u691c\u7d22" +
65
			"</Japanese>.\n" +
66
			"<Hebrew>דפי×?Ö± מֱ- ישרֱֹ×?ןץֱֹ" +
67
			"</Hebrew>\n" +
68
			"<Arabic>نصً Ø«Ù? سÙ?َبÙ?س</Arabic>");
69
	
70
	text.setBorder(new TestBorder());
71
	text.setFont(new Font(null, "Tahoma", 20, 0));
72
	page.add(text);
73
	
74
	page.addMouseMotionListener(new MouseMotionListener.Stub() {
75
		public void mouseMoved(MouseEvent me) {
76
			int trail[] = new int[1];
77
			Point where = me.getLocation();
78
			page.translateFromParent(where);
79
			int offset = text.getOffset(where, trail, null);
80
			showCaret(text, offset, trail);
81
		}
82
		public void mouseExited(MouseEvent me) {
83
			
84
		};
85
	});
86
	return page;
87
}
88
89
//protected int getShellStyle() {
90
//	return super.getShellStyle() | SWT.RIGHT_TO_LEFT;
91
//}
92
93
protected void hookShell() {
94
	getFigureCanvas().addKeyListener(new KeyAdapter() {});
95
	Group panel = new Group(shell, 0);
96
	panel.setLayout(new GridLayout());
97
	panel.setText("Hit info");
98
	panel.setLayoutData(new GridData(GridData.FILL_VERTICAL));
99
	offsetLabel = new Label(panel, 0);
100
	offsetLabel.setText("Offset: 999");
101
	trailLabel = new Label(panel, 0);
102
	trailLabel.setText("Trail: 0");
103
	charLabel = new Label(panel, 0);
104
	charLabel.setText("Char: WW");
105
}
106
107
void showCaret(TextFlow text, int offset, int[] trailing) {
108
	if (caretOwner != null)
109
		caretOwner.setSelection(-1, -1);
110
	
111
	offsetLabel.setText("Offset: " + offset);
112
	trailLabel.setText("Trail: " + trailing[0]);
113
	
114
	caretOwner = text;
115
	caret.setVisible(text != null);
116
	CaretInfo info = text.getCaretPlacement(offset, trailing[0] != 0);
117
	caret.setSize(1, info.getHeight());
118
	caret.setLocation(info.getX(), info.getY());
119
	text.setSelection(offset, offset + 1);
120
	if (text.getText().length() == offset)
121
		charLabel.setText("Char: ?");
122
	else
123
		charLabel.setText("Char: " + text.getText().charAt(offset));
124
}
125
126
public static void main(String[] args) {
127
	new CaretExampleWithVerticalTruncation().run();
128
}
129
130
protected void sizeShell() {
131
	shell.setSize(shell.computeSize(400, -1));
132
}
133
134
}
(-)src/org/eclipse/draw2d/examples/text/TextFlowLargeExampleWithVerticalTruncation.java (+112 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.draw2d.examples.text;
12
13
import org.eclipse.draw2d.*;
14
import org.eclipse.draw2d.text.*;
15
16
import org.eclipse.swt.graphics.Font;
17
import org.eclipse.swt.layout.GridData;
18
import org.eclipse.swt.layout.GridLayout;
19
import org.eclipse.swt.events.KeyAdapter;
20
import org.eclipse.swt.events.KeyEvent;
21
import org.eclipse.swt.widgets.Display;
22
import org.eclipse.swt.widgets.Shell;
23
import org.eclipse.swt.SWT;
24
25
/**
26
 * The example is used to build large draw2d.text flow documents to benchmark the layout
27
 * performance as the document changes.  In this case, we allow fake typing of text.
28
 * @author hudsonr
29
 */
30
31
public class TextFlowLargeExampleWithVerticalTruncation {
32
33
static int KEYS_TYPED = 0;
34
static boolean PERFORMANCE = false;
35
static FigureCanvas canvas;
36
static TextFlow target;
37
static FlowPage page;
38
static Font
39
	regularFont = new Font(Display.getDefault(), "Arial", 15, SWT.NORMAL),
40
	boldFont = new Font(Display.getDefault(), "Comic Sans MS", 16, SWT.BOLD);
41
42
public static void main(String[] args) {
43
	Display d = Display.getDefault();
44
	Shell shell = new Shell(d);
45
	shell.setLayout(new GridLayout());
46
47
	canvas = new FigureCanvas(shell);
48
	canvas.setLayoutData(new GridData(GridData.FILL_BOTH));
49
	canvas.setVerticalScrollBarVisibility(canvas.NEVER);
50
	canvas.getViewport().setContentsTracksWidth(true);
51
    canvas.getViewport().setContentsTracksHeight(true);
52
	shell.open();
53
54
	canvas.addKeyListener(new KeyAdapter(){
55
		public void keyPressed(KeyEvent e){
56
			addText(e.character);
57
		}
58
	});
59
60
    page = new FlowPage();
61
    page.setTruncateVertically(true);
62
	populatePage();
63
	canvas.setContents(page);
64
65
	while (!shell.isDisposed())
66
		if (!d.readAndDispatch())
67
			d.sleep();
68
}
69
70
static protected void addText(char c){
71
	if ((c <= 'Z' && c >='A') ||
72
	    (c <= 'z' && c >='a') ||
73
	    (c == ' '))
74
	if (target != null){
75
		target.setText(target.getText()+c);
76
		if (PERFORMANCE && (KEYS_TYPED % 10 == 0)){
77
//			System.out.println(KEYS_TYPED + " keys typed " + FlowPage.VALIDATIONS + " paints and layouts");
78
		}
79
		KEYS_TYPED++;
80
	}
81
}
82
83
static public void populatePage(){
84
85
	target = new TextFlow("Normal text.");
86
	target.setToolTip(new Label("This is a Tooltip"));
87
	page.add(target);
88
	page.setOpaque(true);
89
	page.setBackgroundColor(ColorConstants.white);
90
91
	for (int i=0; i< 20; i++){
92
		BlockFlow bf = new BlockFlow();
93
		page.add(bf);
94
		if (i == 0)
95
			bf.add(target);
96
		
97
		FlowFigure ff = new InlineFlow();
98
		ff.add(new TextFlow("This is the first small sentence. "));
99
		bf.add(ff);
100
		
101
		FlowFigure inline = new InlineFlow();
102
		TextFlowFactory.addSentences(inline,4);
103
		ff.add(inline);
104
		
105
		BlockFlow block = new BlockFlow();
106
		block.setHorizontalAligment(PositionConstants.CENTER);
107
		TextFlowFactory.addFontSizes(block, 5, 25);
108
		page.add(block);
109
	}
110
}
111
112
}
(-)src/org/eclipse/draw2d/examples/text/TextFlowExampleTextWithVerticalTruncation.java (+169 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.draw2d.examples.text;
12
13
import org.eclipse.swt.graphics.Font;
14
15
import org.eclipse.draw2d.ColorConstants;
16
import org.eclipse.draw2d.FigureCanvas;
17
import org.eclipse.draw2d.IFigure;
18
import org.eclipse.draw2d.PositionConstants;
19
import org.eclipse.draw2d.examples.AbstractExample;
20
import org.eclipse.draw2d.text.BlockFlow;
21
import org.eclipse.draw2d.text.FlowPage;
22
import org.eclipse.draw2d.text.InlineFlow;
23
import org.eclipse.draw2d.text.SimpleTextLayout;
24
import org.eclipse.draw2d.text.TextFlow;
25
26
/**
27
 * This example shows the basic ways that the draw2d.text figures can be used.
28
 * 
29
 * @author hudsonr
30
 * @since 2.0
31
 */
32
public class TextFlowExampleTextWithVerticalTruncation extends AbstractExample {
33
34
static protected IFigure createAlignmentParagraph() {
35
	BlockFlow block = new BlockFlow();
36
	block.setHorizontalAligment(PositionConstants.RIGHT);
37
	block.add(new TextFlow("An inline flow figure's aligment is determined "
38
	  + "by the block flow in which it resides. This block is aligned using "));
39
	TextFlow text = new TextFlow("PositionConstants.RIGHT");
40
	text.setFont(COURIER);
41
	block.add(text);
42
	block.add(new TextFlow(", which results in right text aligment"));
43
	return block;
44
}
45
46
static protected IFigure createBaselineParagraph() {
47
	BlockFlow block = new BlockFlow();
48
49
	String message[] = {
50
		"Text fragments ",
51
		"with different ",
52
		"Font sizes will ",
53
		"have their ",
54
		"baseline ",
55
		"vertically ",
56
		"aligned ",
57
		"within ",
58
		"the current ",
59
		"line"
60
	};
61
62
	for (int i=0; i<message.length; i++){
63
		TextFlow tf = new TextFlow(message[i]);
64
		//This is a resource leak.
65
		tf.setFont(new Font(null, "Helvetica", i+8, 0));
66
		block.add(tf);
67
	}
68
69
	return block;	
70
}
71
72
static protected IFigure createBlockParagraph() {
73
	BlockFlow blockFlow = new BlockFlow();
74
	blockFlow.setFont(COURIER);
75
	TextFlow contents = new TextFlow();
76
	contents.setLayoutManager(new SimpleTextLayout(contents));
77
	contents.setText(
78
	  "/**\n" +
79
	  " * The SimpleTextLayout only breaks at newlines\n" +
80
	  " * It can be used to render source code.\r" +
81
	  " */\r\n" +
82
	  "public void foo() {\n" + 
83
	  "    //TABs are not handled currently, only spaces.\n" + 
84
	  "    System.out.println(\"foo\")\n" +
85
	  "}"
86
	);
87
	blockFlow.add(contents);
88
	return blockFlow;
89
}
90
91
static protected IFigure createNestedInlineParagraph() {
92
	BlockFlow blockFlow = new BlockFlow();
93
	TextFlow text;
94
	blockFlow.add(new TextFlow("A paragraph can contain multiple children, including"
95
	  + " nested structure using InlineFlows. "));
96
	
97
	InlineFlow inline = new InlineFlow();
98
	inline.setForegroundColor(ColorConstants.darkBlue);
99
	inline.add(new TextFlow("Children can have "));
100
	text = new TextFlow("Bold ");
101
	text.setFont(BOLD);
102
	inline.add(text);
103
	
104
	inline.add(new TextFlow("or "));
105
106
	text = new TextFlow("Italic ");
107
	text.setFont(ITALICS);
108
	inline.add(text);
109
110
	inline.add(new TextFlow("Font, or override other inherited attributes."));
111
	blockFlow.add(inline);
112
	return blockFlow;
113
}
114
115
static protected IFigure createParagraph() {
116
	BlockFlow blockFlow = new BlockFlow();
117
	TextFlow contents = new TextFlow();
118
	contents.setText("A paragraph is created by using a BlockFlow figure. A "
119
	  + "paragraph usually wraps to the width of the current page. "
120
	  + "To see this, try resizing the example's window. "
121
	  + "The contents of this paragraph were created using a TextFlow figure "
122
	  + "in its default layout, which breaks at whitespace. "
123
	  + "a block of text that doesn't wrap can be created by using the "
124
	  + "SimpleTextLayout on a TextFlow");
125
	
126
	blockFlow.add(contents);
127
	return blockFlow;
128
}
129
130
static protected IFigure createTitle() {
131
	BlockFlow blockFlow = new BlockFlow();
132
	TextFlow contents = new TextFlow("Draw2D TextFlow Example");
133
	contents.setFont(HEADING_1);
134
	blockFlow.add(contents);
135
	return blockFlow;
136
}
137
138
/**
139
 * @see org.eclipse.draw2d.examples.AbstractExample#getContents()
140
 */
141
protected IFigure getContents() {
142
    FlowPage page = new FlowPage();
143
    page.setTruncateVertically(true);
144
	page.setOpaque(true);
145
	page.setBackgroundColor(ColorConstants.white);
146
	page.add(createTitle());
147
	page.add(createParagraph());
148
	page.add(createBlockParagraph());
149
	page.add(createNestedInlineParagraph());
150
	page.add(createBaselineParagraph());
151
	page.add(createAlignmentParagraph());
152
	return page;
153
}
154
155
public static void main(String[] args) {
156
	new TextFlowExampleTextWithVerticalTruncation().run();
157
}
158
159
/**
160
 * @see org.eclipse.draw2d.examples.AbstractExample#setFigureCanvas(FigureCanvas)
161
 */
162
protected void setFigureCanvas(FigureCanvas canvas) {
163
	super.setFigureCanvas(canvas);
164
//	canvas.setVerticalScrollBarVisibility(canvas.ALWAYS);
165
	canvas.getViewport().setContentsTracksWidth(true);
166
    canvas.getViewport().setContentsTracksHeight(true);
167
}
168
169
}
(-)src/org/eclipse/draw2d/examples/text/TextSurroundingFigureExampleWithVerticalTruncation.java (+102 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.draw2d.examples.text;
12
13
import org.eclipse.swt.SWT;
14
import org.eclipse.swt.custom.StackLayout;
15
import org.eclipse.swt.widgets.Display;
16
import org.eclipse.swt.widgets.Shell;
17
18
import org.eclipse.draw2d.ColorConstants;
19
import org.eclipse.draw2d.Ellipse;
20
import org.eclipse.draw2d.FigureCanvas;
21
import org.eclipse.draw2d.LineBorder;
22
import org.eclipse.draw2d.RoundedRectangle;
23
import org.eclipse.draw2d.Shape;
24
import org.eclipse.draw2d.ToolbarLayout;
25
import org.eclipse.draw2d.Triangle;
26
import org.eclipse.draw2d.geometry.Dimension;
27
import org.eclipse.draw2d.text.FlowAdapter;
28
import org.eclipse.draw2d.text.FlowPage;
29
import org.eclipse.draw2d.text.TextFlow;
30
31
public class TextSurroundingFigureExampleWithVerticalTruncation
32
{
33
	
34
public static void main(String[] args) {
35
	Display d = Display.getDefault();
36
	Shell shell = new Shell(d);
37
	StackLayout layout = new StackLayout();
38
	shell.setLayout(layout);
39
40
	FigureCanvas canvas = new FigureCanvas(shell);
41
	layout.topControl = canvas;
42
	canvas.getViewport().setContentsTracksWidth(true);
43
    canvas.getViewport().setContentsTracksHeight(true);
44
45
    FlowPage page = new FlowPage();
46
    page.setTruncateVertically(true);
47
	populatePage(page);
48
	canvas.setContents(page);
49
50
	shell.setSize(300, 300);
51
	shell.open();
52
	while (!shell.isDisposed())
53
		if (!d.readAndDispatch())
54
			d.sleep();
55
}
56
57
private static void populatePage(FlowPage page) {
58
	page.setOrientation(SWT.LEFT_TO_RIGHT);
59
	
60
	TextFlow textFlow1 = new TextFlow();
61
	textFlow1.setText("This is the text on the left side, and \u0634\u0637\u0635.  There has to be a lot of text here to see the first proxy wrap.  So, here we go.");
62
	page.add(textFlow1);
63
64
	FlowAdapter proxy1 = new FlowAdapter();
65
	proxy1.setBorder(new LineBorder(ColorConstants.orange, 3));
66
	proxy1.setLayoutManager(new ToolbarLayout());
67
	RoundedRectangle rect = new RoundedRectangle();
68
	rect.setCornerDimensions(new Dimension(25,25));
69
	rect.setBackgroundColor(ColorConstants.green);
70
	rect.setForegroundColor(ColorConstants.black);
71
	rect.setPreferredSize(100, 40);
72
	proxy1.add(rect);
73
	Shape shape = new Triangle();
74
	shape.setBackgroundColor(ColorConstants.red);
75
	shape.setForegroundColor(ColorConstants.black);
76
	shape.setPreferredSize(80, 80);
77
	proxy1.add(shape);
78
	shape = new Ellipse();
79
	shape.setBackgroundColor(ColorConstants.blue);
80
	shape.setForegroundColor(ColorConstants.black);
81
	shape.setPreferredSize(70, 70);	
82
	proxy1.add(shape);
83
	page.add(proxy1);
84
	
85
	TextFlow textFlow2 = new TextFlow();
86
	textFlow2.setText("This is the right side text.");
87
	page.add(textFlow2);
88
	
89
	FlowAdapter proxy2 = new FlowAdapter();
90
	proxy2.setBorder(proxy1.getBorder());
91
	proxy2.setLayoutManager(new org.eclipse.draw2d.StackLayout());
92
	TextFlow flow = new TextFlow();
93
	flow.setText("Text inside a proxy figure with BiDi: \u0634\u0637\u0635 \u0639\u0633\u0640 \u0632\u0638\u0635.");
94
	FlowPage innerPage = new FlowPage();
95
	innerPage.setTruncateVertically(true);
96
	innerPage.setOrientation(SWT.RIGHT_TO_LEFT);
97
	innerPage.add(flow);
98
	proxy2.add(innerPage);
99
	page.add(proxy2);
100
}
101
102
}
(-)src/org/eclipse/draw2d/examples/text/BidiBlockExampleWithVerticalTruncation.java (+143 lines)
Added Link Here
1
/*****************************************************************************************
2
 * Copyright (c) 2004 IBM Corporation and others. All rights reserved. This program and
3
 * the accompanying materials are made available under the terms of the Common Public
4
 * License v1.0 which accompanies this distribution, and is available at
5
 * http://www.eclipse.org/legal/cpl-v10.html
6
 * 
7
 * Contributors: IBM Corporation - initial API and implementation
8
 ****************************************************************************************/
9
10
package org.eclipse.draw2d.examples.text;
11
12
import org.eclipse.swt.SWT;
13
import org.eclipse.swt.events.ControlEvent;
14
import org.eclipse.swt.events.ControlListener;
15
import org.eclipse.swt.layout.GridData;
16
import org.eclipse.swt.layout.GridLayout;
17
import org.eclipse.swt.widgets.Display;
18
import org.eclipse.swt.widgets.Shell;
19
20
import org.eclipse.draw2d.Figure;
21
import org.eclipse.draw2d.FigureCanvas;
22
import org.eclipse.draw2d.IFigure;
23
import org.eclipse.draw2d.LineBorder;
24
import org.eclipse.draw2d.PositionConstants;
25
import org.eclipse.draw2d.StackLayout;
26
import org.eclipse.draw2d.examples.AbstractExample;
27
import org.eclipse.draw2d.geometry.Dimension;
28
import org.eclipse.draw2d.text.BlockFlow;
29
import org.eclipse.draw2d.text.FlowPage;
30
import org.eclipse.draw2d.text.TextFlow;
31
32
public class BidiBlockExampleWithVerticalTruncation extends AbstractExample {
33
34
public static void main(String[] args) {
35
	new BidiBlockExampleWithVerticalTruncation().run();
36
}
37
38
// The backwards figure canvas for bidi
39
protected FigureCanvas cf;
40
protected String s = "\u0634\u0635\u062c\u062d \u0630\u0628\u063a and some english text.";
41
42
protected IFigure getContents() {
43
	FlowPage page = new FlowPage();
44
	page.setTruncateVertically(true);
45
46
	BlockFlow para = new BlockFlow();
47
	page.add(para);
48
	para.setOrientation(SWT.LEFT_TO_RIGHT);
49
	para.setHorizontalAligment(PositionConstants.LEFT);
50
	para.add(new TextFlow(s));
51
	
52
	para = new BlockFlow();
53
	page.add(para);
54
	para.setOrientation(SWT.LEFT_TO_RIGHT);
55
	para.setHorizontalAligment(PositionConstants.RIGHT);
56
	para.add(new TextFlow(s));
57
	
58
	para = new BlockFlow();
59
	page.add(para);
60
	para.setOrientation(SWT.LEFT_TO_RIGHT);
61
	para.setHorizontalAligment(PositionConstants.ALWAYS_LEFT);
62
	para.add(new TextFlow(s));
63
64
	para = new BlockFlow();
65
	page.add(para);
66
	para.setOrientation(SWT.LEFT_TO_RIGHT);
67
	para.setHorizontalAligment(PositionConstants.ALWAYS_RIGHT);
68
	para.add(new TextFlow(s));
69
70
	para = new BlockFlow();
71
	page.add(para);
72
	para.setOrientation(SWT.LEFT_TO_RIGHT);
73
	para.add(new TextFlow(s));
74
75
	para = new BlockFlow();
76
	page.add(para);
77
	para.setOrientation(SWT.RIGHT_TO_LEFT);
78
	para.setHorizontalAligment(PositionConstants.LEFT);
79
	para.add(new TextFlow(s));
80
81
	para = new BlockFlow();
82
	page.add(para);
83
	para.setOrientation(SWT.RIGHT_TO_LEFT);
84
	para.setHorizontalAligment(PositionConstants.RIGHT);
85
	para.add(new TextFlow(s));
86
87
	para = new BlockFlow();
88
	page.add(para);
89
	para.setOrientation(SWT.RIGHT_TO_LEFT);
90
	para.setHorizontalAligment(PositionConstants.ALWAYS_LEFT);
91
	para.add(new TextFlow(s));
92
93
	para = new BlockFlow();
94
	page.add(para);
95
	para.setOrientation(SWT.RIGHT_TO_LEFT);
96
	para.setHorizontalAligment(PositionConstants.ALWAYS_RIGHT);
97
	para.add(new TextFlow(s));
98
99
	para = new BlockFlow();
100
	page.add(para);
101
	para.setOrientation(SWT.RIGHT_TO_LEFT);
102
	para.add(new TextFlow(s));
103
104
    return page;
105
	
106
//    IFigure containerFigure = new Figure();
107
//    containerFigure.setBorder(new LineBorder());
108
//    containerFigure.setLayoutManager(new StackLayout());
109
//    containerFigure.add(page);
110
//    return containerFigure;
111
}
112
113
protected void run() {
114
	Display d = Display.getDefault();
115
	shell = new Shell(d);
116
	String appName = getClass().getName();
117
	appName = appName.substring(appName.lastIndexOf('.') + 1);
118
	shell.setText(appName);
119
	shell.setLayout(new GridLayout(2, true));
120
121
	fc = new FigureCanvas(shell);
122
	fc.setScrollBarVisibility(FigureCanvas.NEVER);
123
	fc.setContents(getContents());
124
	cf = new FigureCanvas(shell, SWT.RIGHT_TO_LEFT);
125
	cf.setScrollBarVisibility(FigureCanvas.NEVER);
126
	cf.setContents(getContents());
127
	
128
	fc.getViewport().setContentsTracksWidth(true);
129
    fc.getViewport().setContentsTracksHeight(true);
130
	cf.getViewport().setContentsTracksWidth(true);
131
    cf.getViewport().setContentsTracksHeight(true);
132
133
	fc.setLayoutData(new GridData(GridData.FILL_BOTH));
134
	cf.setLayoutData(new GridData(GridData.FILL_BOTH));
135
136
	shell.pack();
137
	shell.open();
138
	while (!shell.isDisposed())
139
		while (!d.readAndDispatch())
140
			d.sleep();
141
}
142
143
}
(-)src/org/eclipse/draw2d/text/TextFlow.java (+8 lines)
Lines 485-490 Link Here
485
	g.getClip(Rectangle.SINGLETON);
485
	g.getClip(Rectangle.SINGLETON);
486
	int yStart = Rectangle.SINGLETON.y;
486
	int yStart = Rectangle.SINGLETON.y;
487
	int yEnd = Rectangle.SINGLETON.bottom();
487
	int yEnd = Rectangle.SINGLETON.bottom();
488
	
489
	Point truncationPoint = getTruncationPoint();
488
		
490
		
489
	for (int i = 0; i < fragments.size(); i++) {
491
	for (int i = 0; i < fragments.size(); i++) {
490
		frag = (TextFragmentBox)fragments.get(i);
492
		frag = (TextFragmentBox)fragments.get(i);
Lines 499-504 Link Here
499
		//Break loop at first non-visible fragment
501
		//Break loop at first non-visible fragment
500
		if (yEnd < frag.getLineRoot().getVisibleTop())
502
		if (yEnd < frag.getLineRoot().getVisibleTop())
501
			break;
503
			break;
504
		
505
        // Break loop if the parent figure is in the middle of this text.
506
        if (truncationPoint != null
507
                && truncationPoint.y < frag.getLineRoot().getVisibleBottom()) {
508
            break;
509
        }
502
510
503
		String draw = getBidiSubstring(frag, i);
511
		String draw = getBidiSubstring(frag, i);
504
		
512
		
(-)src/org/eclipse/draw2d/text/InlineFlow.java (+4 lines)
Lines 19-24 Link Here
19
import org.eclipse.draw2d.Border;
19
import org.eclipse.draw2d.Border;
20
import org.eclipse.draw2d.ColorConstants;
20
import org.eclipse.draw2d.ColorConstants;
21
import org.eclipse.draw2d.Graphics;
21
import org.eclipse.draw2d.Graphics;
22
import org.eclipse.draw2d.geometry.Point;
22
import org.eclipse.draw2d.geometry.Rectangle;
23
import org.eclipse.draw2d.geometry.Rectangle;
23
24
24
/**
25
/**
Lines 174-177 Link Here
174
		throw new RuntimeException("Border must be an instance of FlowBorder"); //$NON-NLS-1$
175
		throw new RuntimeException("Border must be an instance of FlowBorder"); //$NON-NLS-1$
175
}
176
}
176
177
178
protected Point getTruncationPoint() {
179
    return ((FlowFigure) getParent()).getTruncationPoint();
180
}
177
}
181
}
(-)src/org/eclipse/draw2d/text/FlowPage.java (-18 / +115 lines)
Lines 12-18 Link Here
12
12
13
import java.util.List;
13
import java.util.List;
14
14
15
import org.eclipse.draw2d.Graphics;
15
import org.eclipse.draw2d.geometry.Dimension;
16
import org.eclipse.draw2d.geometry.Dimension;
17
import org.eclipse.draw2d.geometry.Point;
18
import org.eclipse.draw2d.geometry.PointList;
16
import org.eclipse.draw2d.geometry.Rectangle;
19
import org.eclipse.draw2d.geometry.Rectangle;
17
20
18
/**
21
/**
Lines 29-39 Link Here
29
	extends BlockFlow
32
	extends BlockFlow
30
{
33
{
31
34
35
/** temporarily stores the preferred size of this figure after a layout has occurred */
32
private Dimension pageSize = new Dimension();
36
private Dimension pageSize = new Dimension();
33
private int recommendedWidth;
37
38
/** the recommended size for this figure to be used during layout */
39
private Dimension recommendedSize = new Dimension();
40
34
private int pageSizeCacheKeys[] = new int[3];
41
private int pageSizeCacheKeys[] = new int[3];
35
private Dimension pageSizeCacheValues[] = new Dimension[3];
42
private Dimension pageSizeCacheValues[] = new Dimension[3];
36
43
44
/** true if the text should be truncated vertically if necessary */
45
private boolean truncateVertically = false;
46
47
/**
48
 * Returns true if the text should be truncated vertically if it is too big
49
 * vertically to fit in the preferred size given.
50
 * 
51
 * @return true if the text should be truncated vertically if necessary
52
 */
53
public boolean shouldTruncateVertically() {
54
    return truncateVertically;
55
}
56
57
/**
58
 * If set to true and the text is too big vertically to fit in the preferred
59
 * size given, a truncation decoration (by default an arrow) will be drawn
60
 * at the bottom of this figure.
61
 * 
62
 * @param truncateVertically
63
 *            true if the text should be truncated vertically if necessary;
64
 *            false otherwise
65
 */
66
public void setTruncateVertically(boolean truncateVertically) {
67
    this.truncateVertically = truncateVertically;
68
}
69
37
/**
70
/**
38
 * @see org.eclipse.draw2d.Figure#addNotify()
71
 * @see org.eclipse.draw2d.Figure#addNotify()
39
 */
72
 */
Lines 53-58 Link Here
53
 * @see org.eclipse.draw2d.Figure#getMinimumSize(int, int)
86
 * @see org.eclipse.draw2d.Figure#getMinimumSize(int, int)
54
 */
87
 */
55
public Dimension getMinimumSize(int w, int h) {
88
public Dimension getMinimumSize(int w, int h) {
89
	if (shouldTruncateVertically()) {
90
		return getTruncatedDecorationSize();
91
	}
56
	return getPreferredSize(w, h);
92
	return getPreferredSize(w, h);
57
}
93
}
58
94
Lines 67-77 Link Here
67
/**
103
/**
68
 * @see org.eclipse.draw2d.Figure#getPreferredSize(int, int)
104
 * @see org.eclipse.draw2d.Figure#getPreferredSize(int, int)
69
 */
105
 */
70
public Dimension getPreferredSize(int width, int h) {
106
public Dimension getPreferredSize(int width, int height) {
71
	for (int i = 0; i < 3; i++) {
107
    for (int i = 0; i < 3; i++) {
72
		if (pageSizeCacheKeys[i] == width && pageSizeCacheValues[i] != null)
108
        if (pageSizeCacheKeys[i] == width && pageSizeCacheValues[i] != null)
73
			return pageSizeCacheValues[i];
109
            return pageSizeCacheValues[i];
74
	}
110
    }
111
    
112
    Dimension sizeHint = new Dimension(width, height);
113
    if (!shouldTruncateVertically()) {
114
        // avoid triggering a layout in the children blockflows if only the
115
        // height has changed in this case
116
        sizeHint.height = -1;
117
    }
75
118
76
	pageSizeCacheKeys[2] = pageSizeCacheKeys[1];
119
	pageSizeCacheKeys[2] = pageSizeCacheKeys[1];
77
	pageSizeCacheKeys[1] = pageSizeCacheKeys[0];
120
	pageSizeCacheKeys[1] = pageSizeCacheKeys[0];
Lines 81-100 Link Here
81
	pageSizeCacheValues[1] = pageSizeCacheValues[0];	
124
	pageSizeCacheValues[1] = pageSizeCacheValues[0];	
82
125
83
	//Flowpage must temporarily layout to determine its preferred size
126
	//Flowpage must temporarily layout to determine its preferred size
84
	int oldWidth = getPageWidth();
127
	Dimension oldSize = getPageSize();
85
	setPageWidth(width);
128
	setPageSize(sizeHint);
129
	
86
	validate();
130
	validate();
87
	pageSizeCacheValues[0] = pageSize.getCopy();
131
	pageSizeCacheValues[0] = pageSize.getCopy();
88
	
132
	
89
	if (width != oldWidth) {
133
	if (sizeHint.equals(oldSize)) {
90
		setPageWidth(oldWidth);
134
		setPageSize(oldSize);
91
		getUpdateManager().addInvalidFigure(this);
135
		getUpdateManager().addInvalidFigure(this);
92
	}
136
	}
93
	return pageSizeCacheValues[0];
137
	return pageSizeCacheValues[0];
94
}
138
}
95
139
96
int getPageWidth() {
140
Dimension getPageSize() {
97
	return recommendedWidth;
141
	return recommendedSize;
98
}
142
}
99
143
100
/**
144
/**
Lines 104-109 Link Here
104
	Rectangle r = getBlockBox().toRectangle();
148
	Rectangle r = getBlockBox().toRectangle();
105
	pageSize.width = r.width;
149
	pageSize.width = r.width;
106
	pageSize.height = r.height;
150
	pageSize.height = r.height;
151
	
152
	if (shouldTruncateVertically() && r.height > getPageSize().height) {
153
        setTruncationPoint(new Point(0, getPageSize().height
154
            - getTruncatedDecorationSize().height));
155
    }
156
	
107
	List v = getChildren();
157
	List v = getChildren();
108
	for (int i = 0; i < v.size(); i++)
158
	for (int i = 0; i < v.size(); i++)
109
		((FlowFigure)v.get(i)).postValidate();
159
		((FlowFigure)v.get(i)).postValidate();
Lines 126-142 Link Here
126
		return;
176
		return;
127
	boolean invalidate = getBounds().width != r.width || getBounds().height != r.height;
177
	boolean invalidate = getBounds().width != r.width || getBounds().height != r.height;
128
	super.setBounds(r);
178
	super.setBounds(r);
129
	int newWidth = r.width;
179
	Dimension newSize = new Dimension(r.width, r.height);
130
	if (invalidate || getPageWidth() != newWidth) {
180
    if (!shouldTruncateVertically()) {
131
		setPageWidth(newWidth);
181
        // avoid triggering a layout if only the height has changed in this case
182
        newSize.height = -1;
183
    }
184
	if (invalidate || !newSize.equals(getPageSize())) {
185
		setPageSize(newSize);
132
		getUpdateManager().addInvalidFigure(this);
186
		getUpdateManager().addInvalidFigure(this);
133
	}
187
	}
134
}
188
}
135
189
136
private void setPageWidth(int width) {
190
private void setPageSize(Dimension size) {
137
	if (recommendedWidth == width)
191
	if (size.equals(recommendedSize))
138
		return;
192
		return;
139
	recommendedWidth = width;
193
	recommendedSize = size;
140
	super.invalidate();
194
	super.invalidate();
141
}
195
}
142
196
Lines 150-153 Link Here
150
	postValidate();
204
	postValidate();
151
}
205
}
152
206
207
protected void layout() {
208
    setTruncationPoint(null);
209
    super.layout();
210
}
211
212
protected Point getTruncationPoint() {
213
    if (shouldTruncateVertically()) {
214
        return super.getTruncationPoint();
215
    } else {
216
        return null;
217
    }
218
}
219
220
public void paintBorder(Graphics graphics) {
221
    super.paintBorder(graphics);
222
    if (getTruncationPoint() != null) {
223
        paintTruncationDecoration(graphics);
224
    }
225
}
226
227
/**
228
 * Paints the truncation decoration.
229
 * 
230
 * @param graphics
231
 */
232
protected void paintTruncationDecoration(Graphics graphics) {
233
    Point bottomPoint = getBounds().getBottom().translate(-1, -1);
234
    PointList points = new PointList(3);
235
    points.addPoint(bottomPoint);
236
    points.addPoint(bottomPoint.getTranslated(-4, -4));
237
    points.addPoint(bottomPoint.getTranslated(4, -4));
238
    graphics.drawPolygon(points);
239
}
240
241
/**
242
 * Gets the size of the truncation decoration that will be drawn and any
243
 * whitespace around it.
244
 * 
245
 * @return the size required for the truncation decoration
246
 */
247
protected Dimension getTruncatedDecorationSize() {
248
    return new Dimension(10, 6);
249
}
153
}
250
}
(-)src/org/eclipse/draw2d/text/PageFlowLayout.java (-1 / +1 lines)
Lines 32-38 Link Here
32
 * @see org.eclipse.draw2d.text.BlockFlowLayout#getContextWidth()
32
 * @see org.eclipse.draw2d.text.BlockFlowLayout#getContextWidth()
33
 */
33
 */
34
int getContextWidth() {
34
int getContextWidth() {
35
	return ((FlowPage)getFlowFigure()).getPageWidth();
35
	return ((FlowPage)getFlowFigure()).getPageSize().width;
36
}
36
}
37
37
38
}
38
}
(-)src/org/eclipse/draw2d/text/BlockFlow.java (+25 lines)
Lines 19-24 Link Here
19
import org.eclipse.draw2d.IFigure;
19
import org.eclipse.draw2d.IFigure;
20
import org.eclipse.draw2d.PositionConstants;
20
import org.eclipse.draw2d.PositionConstants;
21
import org.eclipse.draw2d.geometry.Insets;
21
import org.eclipse.draw2d.geometry.Insets;
22
import org.eclipse.draw2d.geometry.Point;
22
import org.eclipse.draw2d.geometry.Rectangle;
23
import org.eclipse.draw2d.geometry.Rectangle;
23
24
24
/**
25
/**
Lines 44-49 Link Here
44
private int orientation = SWT.NONE;
45
private int orientation = SWT.NONE;
45
private boolean bidiValid;
46
private boolean bidiValid;
46
47
48
/** the point where children figures should be truncated */
49
private Point truncationPoint;
50
47
/**
51
/**
48
 * Constructs a new BlockFlow.
 */
52
 * Constructs a new BlockFlow.
 */
49
public BlockFlow() {
53
public BlockFlow() {
Lines 207-212 Link Here
207
	newBounds.crop(new Insets(getTopMargin(), getLeftMargin(),
211
	newBounds.crop(new Insets(getTopMargin(), getLeftMargin(),
208
			getBottomMargin(), getRightMargin()));
212
			getBottomMargin(), getRightMargin()));
209
	setBounds(newBounds);
213
	setBounds(newBounds);
214
	
215
	Point point = ((FlowFigure)getParent()).getTruncationPoint();
216
	if (point != null) {
217
	    point = point.getCopy();
218
	    translateFromParent(point);
219
	}
220
	setTruncationPoint(point);
210
}
221
}
211
222
212
/**
223
/**
Lines 298-301 Link Here
298
	super.validate();
309
	super.validate();
299
}
310
}
300
311
312
/**
313
 * Sets the point where this figure's children should be truncated.
314
 * 
315
 * @param truncationPoint
316
 */
317
protected void setTruncationPoint(Point truncationPoint) {
318
    this.truncationPoint = truncationPoint;
319
}
320
321
protected Point getTruncationPoint() {
322
    return truncationPoint;
323
}
324
325
301
}
326
}
(-)src/org/eclipse/draw2d/text/BlockFlowLayout.java (+6 lines)
Lines 231-236 Link Here
231
	if (recommended != blockBox.recommendedWidth) {
231
	if (recommended != blockBox.recommendedWidth) {
232
		blockInvalid = true;
232
		blockInvalid = true;
233
		blockBox.setRecommendedWidth(recommended);
233
		blockBox.setRecommendedWidth(recommended);
234
	} 
235
	if (blockBox.height != -1) {
236
        // force the block to revalidate if the height is important
237
	    blockInvalid = true;	    
234
	}
238
	}
235
	
239
	
236
	if (blockInvalid) {
240
	if (blockInvalid) {
Lines 239-242 Link Here
239
	}
243
	}
240
}
244
}
241
245
246
247
242
}
248
}
(-)src/org/eclipse/draw2d/text/FlowAdapter.java (+4 lines)
Lines 14-19 Link Here
14
14
15
import org.eclipse.draw2d.IFigure;
15
import org.eclipse.draw2d.IFigure;
16
import org.eclipse.draw2d.geometry.Dimension;
16
import org.eclipse.draw2d.geometry.Dimension;
17
import org.eclipse.draw2d.geometry.Point;
17
import org.eclipse.draw2d.geometry.Rectangle;
18
import org.eclipse.draw2d.geometry.Rectangle;
18
19
19
/**
20
/**
Lines 154-157 Link Here
154
	}
155
	}
155
}
156
}
156
157
158
protected Point getTruncationPoint() {
159
    return ((FlowFigure) getParent()).getTruncationPoint();
160
}
157
}
161
}
(-)src/org/eclipse/draw2d/text/FlowFigure.java (+15 lines)
Lines 14-19 Link Here
14
14
15
import org.eclipse.draw2d.Figure;
15
import org.eclipse.draw2d.Figure;
16
import org.eclipse.draw2d.IFigure;
16
import org.eclipse.draw2d.IFigure;
17
import org.eclipse.draw2d.geometry.Point;
17
import org.eclipse.draw2d.geometry.Rectangle;
18
import org.eclipse.draw2d.geometry.Rectangle;
18
19
19
/**
20
/**
Lines 182-185 Link Here
182
	repaint();
183
	repaint();
183
}
184
}
184
185
186
/**
187
 * Gets the point where this <code>FlowFigure</code> should be truncated;
188
 * that is, the point where this <code>FlowFigure</code> will no longer be
189
 * visible because it extends beyond the area it has been given. A
190
 * <code>null</code> return value implies that this figure is not being
191
 * truncated.
192
 * 
193
 * @return the point at which this <code>FlowFigure</code> should be
194
 *         truncated or null if it should not be truncated
195
 */
196
protected Point getTruncationPoint() {
197
    return null;
198
}
199
185
}
200
}

Return to bug 178117