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.tool;
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.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
44  	 *            node figure
45  	 */
46  	public LabelCellEditorLocator(NodeFigure nodeFigure) {
47  		setLabel(nodeFigure);
48  	}
49  
50  	/**
51  	 * {@inheritDoc}
52  	 *
53  	 * @see org.eclipse.gef.tools.CellEditorLocator#relocate(org.eclipse.jface.viewers.CellEditor)
54  	 */
55  	@Override
56  	public void relocate(CellEditor celleditor) {
57  		Text text = (Text)celleditor.getControl();
58  		// show the editor in place of node's label
59  		Rectangle rect = new Rectangle(nodeFigure.getLabelFigure().getBounds());
60  		nodeFigure.translateToAbsolute(rect);
61  		org.eclipse.swt.graphics.Rectangle trim = text.computeTrim(0, 0, 0, 0);
62  		rect.translate(trim.x, trim.y);
63  		rect.width += trim.width;
64  		rect.height += trim.height;
65  		// make the editor at least 100 pixels wide
66  		rect.width = Math.max(rect.width, 100);
67  		text.setBounds(rect.x, rect.y, rect.width, rect.height);
68  	}
69  
70  	/**
71  	 * Returns the nodeFigure figure.
72  	 */
73  	protected NodeFigure getLabel() {
74  		return nodeFigure;
75  	}
76  
77  	/**
78  	 * Sets the node figure.
79  	 *
80  	 * @param nodeFigure
81  	 *            The nodeFigure to set
82  	 */
83  	protected void setLabel(NodeFigure stickyNote) {
84  		this.nodeFigure = stickyNote;
85  	}
86  
87  }