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: LegendFigure.java
13   * Created: 2009-07-29
14   * Author: cast
15   * $Id: LegendFigure.java 3090 2009-07-30 12:59:21Z kpietak $
16   */
17  
18  package pl.edu.agh.cast.figure;
19  
20  import java.util.List;
21  
22  import org.eclipse.draw2d.ColorConstants;
23  import org.eclipse.draw2d.Figure;
24  import org.eclipse.draw2d.FrameBorder;
25  import org.eclipse.draw2d.ToolbarLayout;
26  import org.eclipse.draw2d.geometry.Rectangle;
27  
28  import pl.edu.agh.cast.model.visual.Legend;
29  import pl.edu.agh.cast.util.Messages;
30  
31  /**
32   * A figure for displaying diagram {@link Legend}.
33   *
34   * @author AGH CAST Team
35   */
36  public abstract class AbstractLegendFigure extends Figure {
37  
38  	/**
39  	 * Legend model
40  	 */
41  	protected Legend legend;
42  
43  	private FrameBorder legendBorder;
44  
45  	/**
46  	 * Returns all figures(image and caption as one figure) that has to be listed in legend.
47  	 *
48  	 * @return list of entries
49  	 */
50  	protected abstract List<Figure> getLegendEntries();
51  
52  	/**
53  	 * Creates new legend figure.
54  	 *
55  	 * @param legend
56  	 *            legend to display
57  	 */
58  	public AbstractLegendFigure(Legend legend) {
59  		super();
60  		this.legend = legend;
61  	}
62  
63  	/**
64  	 * Refreshes the legend figure.
65  	 */
66  	public void refresh() {
67  		if (getLegendEntries().size() == 0) {
68  			setVisible(false);
69  			return;
70  		} else {
71  			setVisible(true);
72  		}
73  
74  		ToolbarLayout layout = new ToolbarLayout();
75  		layout.setStretchMinorAxis(false);
76  		layout.setMinorAlignment(ToolbarLayout.ALIGN_TOPLEFT);
77  		setLayoutManager(layout);
78  
79  		removeAll();
80  		for (Figure legendEntry : getLegendEntries()) {
81  			add(legendEntry);
82  		}
83  		legendBorder = new FrameBorder(Messages.Legend_0);
84  		this.setBackgroundColor(ColorConstants.listBackground);
85  		this.setOpaque(true);
86  		this.setBorder(legendBorder);
87  		this.setBounds(new Rectangle(getLocation(), getPreferredSize()));
88  
89  	}
90  
91  }