1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 package fr.ove.openmath.jome.model;
30
31 import java.util.*;
32 import fr.ove.openmath.jome.model.FormulaTreeStructure;
33 import fr.ove.openmath.jome.model.events.ModelEvent;
34 import fr.ove.openmath.jome.model.evaluation.*;
35
36 /***
37 * The operator bracket.
38 *
39 * @author © 1999 DIRAT Laurent
40 * @version 2.0 25/06/1999
41 */
42 public class Bracket extends UnaryOperator {
43 private boolean isVisible = true;
44
45 /***
46 * The Constructor.
47 */
48 public Bracket() {
49 setResourceIdentifier("OPEN_PAREN"
50 setValue("(");
51 setAsOperatorPriority(resourcesManager.getAsOperatorPriority("bracketPriorities"));
52 setAsOperandPriority(resourcesManager.getAsOperandPriority("bracketPriorities"));
53 }
54
55 /***
56 * Returns the father of the node which, from the current instance, have the specified
57 * priority.
58 *
59 * @param priority the specified priority.
60 * @return the desired father.
61 */
62 public FormulaTreeStructure goTo(int priority) {
63 FormulaTreeStructure current = this;
64
65
66
67
68
69
70
71
72 if (current.getAsOperatorPriority() == priority)
73 return (FormulaTreeStructure) current.getFather();
74 else
75 current = (FormulaTreeStructure) current.getFather();
76
77 while ((current.getAsOperatorPriority() != priority) &&
78 (((FormulaTreeStructure)current.getFather()).getAsOperatorPriority() != 0))
79 current = (FormulaTreeStructure) current.getFather();
80
81 return current;
82 }
83
84 /***
85 * Inserts the operator instance in the formula tree, from the current insertion position.
86 * (checks the priorities and goes up in the tree if necessary).
87 *
88 * @param ope the current insertion position.
89 * @return the new insertion position.
90 */
91 public FormulaTreeStructure insert(FormulaTreeStructure current) {
92
93 current = findLocation(current);
94
95 if (current.getFather() == null) {
96
97
98 current.addChild(this);
99
100 }
101 else {
102 if ((current.getAsOperatorPriority() == resourcesManager.getAsOperatorPriority("constantPriorities")) &&
103 current.isTemplate()) {
104
105
106
107 int rank = current.getRank();
108 FormulaTreeStructure father = (FormulaTreeStructure) current.getFather();
109 father.addChild(this, rank);
110 father.removeChild(current);
111
112
113
114 if (father.getAsOperatorPriority() == resourcesManager.getAsOperatorPriority("dividePriorities"))
115 isVisible = false;
116 }
117 else {
118
119
120
121 current = (new HorizentalGroup()).insert(current);
122
123 current = insert(current);
124
125
126
127 return current;
128 }
129 }
130
131
132 VariableOrNumber template = new VariableOrNumber();
133 addChild(template);
134
135
136 return template;
137
138 }
139
140 /***
141 * The Creation of the corresponding linear expression of the formula.
142 */
143 public String createLinear(String linear) {
144 linear += "(" + ((FormulaTreeStructure) getChild(0)).createLinear("") + ")";
145
146 return linear;
147 }
148
149 /***
150 * Evaluates the instance.
151 */
152 public String evaluate() {
153 return "(" + ((FormulaTreeStructure) getChild(0)).evaluate() + ")";
154 }
155
156 /***
157 * Returns <CODE>true</CODE> if the brackets have to be displayed.
158 * <CODE>false</CODE> otherwise.
159 */
160 public boolean isVisible() {
161 return isVisible;
162 }
163
164 /***
165 * Sets if the brackets have to be displayed or not.
166 * @param isVisible <CODE>true</CODE> if we want it. <CODE>false</CODE> otherwise.
167 */
168 public void setIsVisible(boolean isVisible) {
169 this.isVisible = isVisible;
170 }
171
172 /***
173 * Returns the name of the icon associated to the instance.<BR>
174 * The icon name is the name of the ressource identifier where "_Ico" added to the end.
175 * @returns The name of the icon, or <CODE>null</CODE> if there is no name
176 * associated.
177 */
178 public String getIconName() {
179
180
181 return ((FormulaTreeStructure) getChild(0)).getIconName();
182 }
183 }