1 package fr.ove.openmath.jome.ctrlview.bidim;
2
3 import java.awt.*;
4 import java.awt.image.ImageObserver;
5 import fr.ove.openmath.jome.ctrlview.bidim.*;
6 import fr.ove.openmath.jome.ctrlview.bidim.images.ImageLoader;
7
8
9 /***
10 * The curly bracket.
11 *
12 * @author © 1999 DIRAT Laurent
13 * @version 2.0 19/07/1999
14 */
15 public class CurlySymbol extends DisplayableImpl {
16 /***
17 * The initial images which are parts of the representation of the curly bracket.<BR>
18 * The curly bracket is made of 4 parts : top, middle, bottom and bar.<BR>
19 * The top, middle and bottom are unique during the rendering, and according to the height of the
20 * bracketted display, mutiple instance of the bar are displayed to give the right size
21 * to the curly bracket.
22 */
23 private Image topInit;
24 private Image middleInit;
25 private Image bottomInit;
26 private Image barInit;
27
28 /***
29 * The scale images of the initials ones.
30 */
31 private Image top;
32 private Image middle;
33 private Image bottom;
34 private Image bar;
35
36 /***
37 * The height of the top and the bottom of the symbol.
38 */
39 private int heightExtremities;
40
41 /***
42 * Object to be notified as more of the image is converted.
43 */
44 ImageObserver observer;
45
46 /***
47 * The constructor.
48 * @param isLeftBracket <CODE>true<CODE> if the instance represents a left bracket. <CODE>false</CODE>
49 * otherwise.
50 * @param heightExtremities the height of the extremities of the bracket.
51 * @param observer the object to be notified as more of the image is converted.
52 */
53 public CurlySymbol(boolean isLeftBracket, int heightExtremities, ImageObserver observer) {
54 if (isLeftBracket) {
55 topInit = ImageLoader.getImage("LeftTopCurl");
56 middleInit = ImageLoader.getImage("LeftMiddleCurl");
57 bottomInit = ImageLoader.getImage("LeftBottomCurl");
58 barInit = ImageLoader.getImage("LeftBarCurl");
59 }
60 else {
61 topInit = ImageLoader.getImage("RightTopCurl");
62 middleInit = ImageLoader.getImage("RightMiddleCurl");
63 bottomInit = ImageLoader.getImage("RightBottomCurl");
64 barInit = ImageLoader.getImage("RightBarCurl");
65 }
66
67 this.heightExtremities = heightExtremities;
68 this.observer = observer;
69 }
70
71 /***
72 * The paint method of the object to display.
73 * @param g the drawing area of the symbol.
74 */
75 public void paint(Graphics g) {
76 int height = getHeight();
77
78
79 g.drawImage(top, 3, 0, observer);
80
81
82
83 for (int i = heightExtremities; i < height - heightExtremities; i += heightExtremities)
84 g.drawImage(bar, 3, i, observer);
85
86
87 g.drawImage(bottom, 3, height - heightExtremities, observer);
88
89
90
91
92
93 g.drawImage(middle, 3, getAscent() - middle.getHeight(observer), observer);
94 }
95
96 /***
97 * Returns the preferred size of the display.
98 */
99 public Dimension getPreferredSize() {
100 MediaTracker tracker = new MediaTracker((Component) observer);
101
102
103
104
105 top = topInit.getScaledInstance(-1, heightExtremities, Image.SCALE_SMOOTH);
106 tracker.addImage(top, 0);
107 middle = middleInit.getScaledInstance(-1, heightExtremities*2, Image.SCALE_SMOOTH);
108 tracker.addImage(middle, 0);
109 bottom = bottomInit.getScaledInstance(-1, heightExtremities, Image.SCALE_SMOOTH);
110 tracker.addImage(bottom, 0);
111 bar = barInit.getScaledInstance(-1, heightExtremities, Image.SCALE_SMOOTH);
112 tracker.addImage(bar, 0);
113
114
115 try { tracker.waitForAll(); }
116 catch (InterruptedException e) {
117 System.out.println(e.toString());
118 }
119
120 tracker.removeImage(top);
121 tracker.removeImage(middle);
122 tracker.removeImage(bottom);
123 tracker.removeImage(bar);
124
125 return new Dimension(top.getWidth(observer) + 6, getHeight());
126 }
127
128 /***
129 * Sets the graphic context in which the object is.
130 * @param graphicContext the object graphic context.
131 * Actually, this methods gives information to the object, notably when its preferred
132 * size is required. If the context has changed, the displayable object must be informed.
133 * However, in the most part of the time, the whole graphic context won't be necessary to
134 * be stored, but only specific and usefull data.
135 */
136 public void setGraphicContext(GraphicContext graphicContext) {
137 super.setGraphicContext(graphicContext);
138
139
140 FontMetrics fm = Toolkit.getDefaultToolkit().getFontMetrics(graphicContext.getFont());
141 heightExtremities = fm.getHeight() / 4;
142 }
143 }