1 package fr.ove.openmath.jome.ctrlview.bidim;
2
3 import java.awt.*;
4 import fr.ove.openmath.jome.ctrlview.bidim.Display;
5 import fr.ove.openmath.jome.ctrlview.bidim.Displayable;
6 import fr.ove.openmath.jome.ctrlview.bidim.SymbolLayout;
7
8 /***
9 * The display of a symbol.
10 *
11 * @author © 1999 DIRAT Laurent
12 * @version 2.0 09/07/1999
13 */
14 public class SymbolDisplay extends BidimDisplay {
15 /***
16 * the symbol to display.
17 */
18 private Displayable symbol;
19
20 /***
21 * The constructor.
22 * @param graphicContext the graphic context of the display.
23 * @param symbol The displayable symbol of the display.
24 */
25 public SymbolDisplay(GraphicContext graphicContext, Displayable symbol) {
26 this(graphicContext);
27 this.symbol = symbol;
28 symbol.setGraphicContext(graphicContext);
29 }
30
31 /***
32 * The constructor.<BR>
33 * Instanciate a new display, with no displayable symbol associated. The symbol has to be set
34 * by hand.
35 * @param graphicContext the graphic context of the display.
36 */
37 public SymbolDisplay(GraphicContext graphicContext) {
38 super(graphicContext);
39 SymbolLayout layout = new SymbolLayout();
40 layout.initDisplay(this);
41 setLayout(layout);
42 }
43
44 /***
45 * Sets a new symbol to the display.
46 * @param symbol the symbol to set.
47 */
48 public void setSymbol(Displayable symbol) {
49 this.symbol = symbol;
50 symbol.setGraphicContext(getGraphicContext());
51 }
52
53 /***
54 * Returns the symbol which is in the dispay.
55 */
56 public Displayable getSymbol() {
57 return symbol;
58 }
59
60 /***
61 * Paints the display.
62 * @param g where we paint the display.
63 */
64 public void paint(Graphics g) {
65 super.paint(g);
66 Color old = g.getColor();
67 Rectangle bounds = getBounds();
68
69 if (isSelected()) {
70 g.setColor(getSelectionColor());
71 g.fillRect(0, 0, bounds.width - 1, bounds.height - 1);
72 }
73
74 g.setColor(getForegroundColor());
75
76 if (weDrawBounds())
77 g.drawRect(0, 0, bounds.width - 1, bounds.height - 1);
78
79 symbol.paint(g);
80
81 g.setColor(old);
82 }
83
84 /***
85 * Scales the display.
86 */
87 public void scaleDisplay() {
88 setTheFont(getGraphicContext().scaleFont(getLevel()));
89
90 setComputeAttributes(true);
91
92
93
94
95 invalidate();
96
97
98
99
100
101
102 if (symbol != null)
103 symbol.setGraphicContext(getGraphicContext());
104 }
105
106 /***
107 * Sets all the attributes.
108 * @param ascent the new ascent value.
109 * @param descent the new descent value.
110 * @param shiftX the new horizontal shift value.
111 * @param shiftY the new vertical shift value.
112 */
113 public void setAttributes(int ascent, int descent, int shiftX, int shiftY) {
114 super.setAttributes(ascent, descent, shiftX, shiftY);
115 symbol.setAscent(ascent);
116 symbol.setDescent(descent);
117 symbol.setShiftX(shiftX);
118 symbol.setShiftY(shiftY);
119 }
120
121 /***
122 * Sets the graphic context of the instance.
123 * @param graphicContext the graphic context.
124 */
125 public void setGraphicContext(GraphicContext graphicContext) {
126 super.setGraphicContext(graphicContext);
127 symbol.setGraphicContext(graphicContext);
128 }
129 }
130