Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Labels on Figure not showing up(sampe figure included.)
Labels on Figure not showing up [message #835406] Tue, 03 April 2012 07:01 Go to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 365
Registered: July 2009
Senior Member
i created an figure which shows up as a rounded rectangle with a shadow.
on the rounded rectangle (content) new content should be added.
i added two labels but somehow the labels do not show up.

can someone point me to my mistake?

thanks in advance

import org.eclipse.draw2d.GridData;
import org.eclipse.draw2d.GridLayout;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.Panel;
import org.eclipse.draw2d.RoundedRectangle;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Display;

public class SampleFigure extends Panel {
	protected static final int offset = 5;
	private RoundedRectangle contentPane;
	private RoundedRectangle shadow;
	private Label lblTime;
	private Label lblSubject;
	private String start = "7:00";
	private String end = "8:00";

	public SampleFigure() {
		setOpaque(false);

		XYLayout layout = new XYLayout();
		setLayoutManager(layout);

		shadow = new RoundedRectangle();
		shadow.setAlpha(25);
		shadow.setBackgroundColor(new Color(Display.getDefault(), 0, 0, 0));
		add(shadow);
		contentPane = new RoundedRectangle();
		contentPane.setAntialias(SWT.ON);
		GridLayout gl = new GridLayout(2, false);
		gl.horizontalSpacing = 0;
		gl.verticalSpacing = 0;
		gl.marginHeight = 0;
		gl.marginWidth = 0;
		contentPane.setLayoutManager(gl);
		createContents();
		add(contentPane);
	}

	@Override
	protected boolean useLocalCoordinates() {
		return true;
	}

	protected void createContents() {
		lblTime = new Label("lblTime");
		GridData gridTime = new GridData(SWT.BEGINNING, SWT.FILL, false, false,
				1, 1);
		contentPane.add(lblTime, gridTime);

		lblSubject = new Label("lblSubject:");
		GridData gridSubject = new GridData(SWT.FILL, SWT.FILL, true, false, 1,
				1);
		contentPane.add(lblSubject, gridSubject);
		updateTime();
	}

	@Override
	public void validate() {
		shadow.setBounds(new Rectangle(offset, offset, getClientArea().width
				- offset, getClientArea().height - offset));
		contentPane.setBounds(new Rectangle(0, 0, getClientArea().width
				- offset, getClientArea().height - offset));
	}

	public void setStart(String start) {
		this.start = start;
		updateTime();
	}

	public void setEnd(String end) {
		this.end = end;
		updateTime();
	}

	private void updateTime() {
		if (lblTime == null) {
			System.err.println("time lbl was null");
			return;
		}
		lblTime.setText(start + "-" + end);
	}

	public void setSubject(String subject) {
		lblSubject.setText(subject);
	}
}
Re: Labels on Figure not showing up [message #836159 is a reply to message #835406] Wed, 04 April 2012 06:25 Go to previous messageGo to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 365
Registered: July 2009
Senior Member
i still do not know why it is not working.
but i recreated the figure (cleaner)

here is the working copy iff someone is interested (leave a comment what you think about it)
import org.eclipse.draw2d.GridData;
import org.eclipse.draw2d.GridLayout;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Layer;
import org.eclipse.draw2d.MarginBorder;
import org.eclipse.draw2d.Panel;
import org.eclipse.draw2d.RoundedRectangle;
import org.eclipse.draw2d.StackLayout;
import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.swt.SWT;
import org.eclipse.wb.swt.SWTResourceManager;

public class SampleFigure extends Panel {
	protected static final int offset = 5;

	private RoundedRectangle content;

	public SampleFigure() {
		setOpaque(false);
		setLayoutManager(new StackLayout());
		// =================================
		Layer shadowLayer = new Layer();
		shadowLayer.setOpaque(false);
		MarginBorder marginBorderShadow = new MarginBorder(new Insets(offset,
				offset, 0, 0));
		shadowLayer.setBorder(marginBorderShadow);
		shadowLayer.setLayoutManager(getLayout(1));
		// ---------------------------------
		RoundedRectangle shadow = new RoundedRectangle();
		shadow.setAlpha(25);
		shadow.setBackgroundColor(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		shadowLayer.add(shadow, new GridData(GridData.FILL_BOTH));
		add(shadowLayer);
		// =================================
		Layer gradientLayer = new Layer();
		gradientLayer.setOpaque(false);
		MarginBorder marginBorderGradient = new MarginBorder(new Insets(0, 0,
				offset, offset));
		gradientLayer.setBorder(marginBorderGradient);
		gradientLayer.setLayoutManager(getLayout(1));
		content = new RoundedRectangle();
		content.setAntialias(SWT.ON);
		gradientLayer.add(content, new GridData(GridData.FILL_BOTH));
		add(gradientLayer);
		// =================================
	}

	public static GridLayout getLayout(int columns) {
		GridLayout gl = new GridLayout(columns, false);
		gl.horizontalSpacing = 0;
		gl.verticalSpacing = 0;
		gl.marginHeight = 0;
		gl.marginWidth = 0;
		return gl;
	}

	public IFigure getContentPane() {
		return content;
	}
}
Re: Labels on Figure not showing up [message #888881 is a reply to message #836159] Mon, 18 June 2012 18:44 Go to previous message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Hi Ludwig,

in the first post it doesn't work because you omitted calling super.validate() in the you overridden validate method.
Previous Topic:Graphical Editor Selection of Edit Part
Next Topic:Maximize Graph Width to View Width
Goto Forum:
  


Current Time: Sat Nov 29 05:43:40 GMT 2014

Powered by FUDForum. Page generated in 0.01718 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software