View Javadoc

1   /*
2    * This file is a part of CAST project.
3    * (c) Copyright 2007, AGH University of Science & Technology
4    * https://caribou.iisg.agh.edu.pl/trac/cast
5    *
6    * Licensed under the Eclipse Public License, Version 1.0 (the "License").
7    * You may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    * http://www.eclipse.org/legal/epl-v10.html
10   */
11  /*
12   * File: LabelCellEditorLocator.java
13   * Created: 2007-00-00
14   * Author: njord, awos
15   * $Id: LabelCellEditorLocator.java 3054 2009-07-27 10:23:07Z kpietak $
16   */
17  
18  package pl.edu.agh.cast.editpart;
19  
20  import org.eclipse.draw2d.geometry.Rectangle;
21  import org.eclipse.gef.tools.CellEditorLocator;
22  import org.eclipse.jface.viewers.CellEditor;
23  import org.eclipse.swt.widgets.Text;
24  
25  import pl.edu.agh.cast.backward.figure.NodeFigure;
26  
27  /**
28   * Constraint for placing label {@link CellEditor}s.
29   *
30   * @author AGH CAST Team
31   */
32  public class LabelCellEditorLocator implements CellEditorLocator {
33  
34  	private NodeFigure nodeFigure;
35  
36  	public NodeFigure getNodeFigure() {
37  		return nodeFigure;
38  	}
39  
40  	/**
41  	 * Constructor.
42  	 *
43  	 * @param nodeFigure node figure
44  	 */
45  	public LabelCellEditorLocator(NodeFigure nodeFigure) {
46  		setLabel(nodeFigure);
47  	}
48  
49  	/**
50  	 * {@inheritDoc}
51  	 * @see org.eclipse.gef.tools.CellEditorLocator#relocate(org.eclipse.jface.viewers.CellEditor)
52  	 */
53  	public void relocate(CellEditor celleditor) {
54  		Text text = (Text)celleditor.getControl();
55  		// show the editor in place of node's label
56  		Rectangle rect = new Rectangle(nodeFigure.getLabelFigure().getClientArea());
57  		nodeFigure.translateToAbsolute(rect);
58  		org.eclipse.swt.graphics.Rectangle trim = text.computeTrim(0, 0, 0, 0);
59  		rect.translate(trim.x, trim.y);
60  		rect.width += trim.width;
61  		rect.height += trim.height;
62  		// make the editor at least 100 pixels wide
63  		rect.width = Math.max(rect.width, 100);
64  		text.setBounds(rect.x, rect.y, rect.width, rect.height);
65  	}
66  
67  	/**
68  	 * Returns the nodeFigure figure.
69  	 */
70  	protected NodeFigure getLabel() {
71  		return nodeFigure;
72  	}
73  
74  	/**
75  	 * Sets the node figure.
76  	 *
77  	 * @param nodeFigure
78  	 *            The nodeFigure to set
79  	 */
80  	protected void setLabel(NodeFigure stickyNote) {
81  		this.nodeFigure = stickyNote;
82  	}
83  
84  }