Source code: jaxe/equations/element/MathUnderOver.java
1 /*
2 Jaxe - Editeur XML en Java
3
4 Copyright (C) 2003 Observatoire de Paris-Meudon
5
6 Ce programme est un logiciel libre ; vous pouvez le redistribuer et/ou le modifier conformément aux dispositions de la Licence Publique Générale GNU, telle que publiée par la Free Software Foundation ; version 2 de la licence, ou encore (à votre choix) toute version ultérieure.
7
8 Ce programme est distribué dans l'espoir qu'il sera utile, mais SANS AUCUNE GARANTIE ; sans même la garantie implicite de COMMERCIALISATION ou D'ADAPTATION A UN OBJET PARTICULIER. Pour plus de détail, voir la Licence Publique Générale GNU .
9
10 Vous devez avoir reçu un exemplaire de la Licence Publique Générale GNU en même temps que ce programme ; si ce n'est pas le cas, écrivez à la Free Software Foundation Inc., 675 Mass Ave, Cambridge, MA 02139, Etats-Unis.
11 */
12
13 package jaxe.equations.element;
14
15 import java.awt.*;
16 import java.util.Vector;
17 import java.util.Enumeration;
18
19 /**
20 * This class arrange an element under, and an other element over
21 * an element
22 *
23 * @author <a href="mailto:stephan@vern.chem.tu-berlin.de">Stephan Michels</a>
24 * @author <a href="mailto:sielaff@vern.chem.tu-berlin.de">Marco Sielaff</a>
25 * @version %I%, %G%
26 */
27 public class MathUnderOver extends MathElement
28 {
29
30 /** The XML element from this class */
31 public final static String ELEMENT = "munderover";
32
33 /**
34 * Add a math element as a child
35 *
36 * @param child Math element
37 */
38 public void addMathElement(MathElement child)
39 {
40 super.addMathElement(child);
41 if (child != null)
42 {
43 if ((getMathElementCount() == 2) || (getMathElementCount() == 3))
44 child.setFontSize(getFontSize() - 2);
45 else
46 child.setFontSize(getFontSize());
47 }
48 }
49
50 /**
51 * Sets the font size for this component
52 *
53 * @param fontsize Font size
54 */
55 public void setFontSize(int fontsize)
56 {
57 super.setFontSize(fontsize);
58 if (getMathElement(1)!=null)
59 getMathElement(1).setFontSize(getFontSize()-2);
60 if (getMathElement(2)!=null)
61 getMathElement(2).setFontSize(getFontSize()-2);
62 }
63
64 /**
65 * Paints this element
66 *
67 * @param g The graphics context to use for painting
68 * @param posX The first left position for painting
69 * @param posY The position of the baseline
70 */
71 public void paint(Graphics g, int posX, int posY)
72 {
73 MathElement e1 = getMathElement(0);
74 MathElement e2 = getMathElement(1);
75 MathElement e3 = getMathElement(2);
76
77 int width = getWidth(true);
78
79 e1.paint(g, posX + (width - e1.getWidth(true)) / 2, posY);
80 e2.paint(g, posX + (width - e2.getWidth(true)) / 2,
81 posY + e1.getDescentHeight(true) + e2.getAscentHeight(true));
82 e3.paint(g, posX + (width - e3.getWidth(true)) / 2,
83 posY - (e1.getAscentHeight(true) + e3.getDescentHeight(true)));
84 }
85
86 /**
87 * Return the current width of this element
88 *
89 * @param dynamicParts Should be true, if the calculation consider the elements,
90 * which has not fixed sizes
91 *
92 * @return Width of this element
93 */
94 public int getWidth(boolean dynamicParts)
95 {
96 return Math.max(getMathElement(0).getWidth(dynamicParts),
97 Math.max(getMathElement(1).getWidth(dynamicParts),
98 getMathElement(2).getWidth(dynamicParts)));
99 }
100
101 /**
102 * Return the current height of this element
103 *
104 * @param dynamicParts Should be true, if the calculation consider the elements,
105 * which has not fixed sizes
106 *
107 * @return Height of this element
108 */
109 public int getHeight(boolean dynamicParts)
110 {
111 return getMathElement(0).getHeight(true)
112 + getMathElement(1).getHeight(true)
113 + getMathElement(2).getHeight(true);
114 }
115
116 /**
117 * Return the current height of the upper part
118 * of this component from the baseline
119 *
120 * @param dynamicParts Should be true, if the calculation consider the elements,
121 * which has not fixed sizes
122 *
123 * @return Height of the upper part
124 */
125 public int getAscentHeight(boolean dynamicParts)
126 {
127 return getMathElement(0).getAscentHeight(true)
128 + getMathElement(1).getHeight(true);
129 }
130
131 /**
132 * Return the current height of the lower part
133 * of this component from the baseline
134 *
135 * @param dynamicParts Should be true, if the calculation consider the elements,
136 * which has not fixed sizes
137 *
138 * @return Height of the lower part
139 */
140 public int getDescentHeight(boolean dynamicParts)
141 {
142 return getMathElement(0).getDescentHeight(true)
143 + getMathElement(2).getHeight(true);
144 }
145 }