Copyright (C) 2000, 2001, Geert Vernaeve. All Rights Reserved.
package
gve.calc.formula;
import
awt.*;
import
java.awt.*;
import
awt.
Button
;
import
java.awt.event.*;
public
class
OperatorNot
extends
PrefixUnaryOp
{
public
String getName() {
return
"not"
; }
public
int
getPri() {
return
1300; }
public
OperatorNot
(
Part
ch) {
super
(ch); }
public
Part
evaluate(
Evaluator
ev) {
Part
eval = child.evaluate(ev);
if
(eval
instanceof
Boolean
) {
return
new
Boolean
(!((
Boolean
)eval).getBooleanValue()); }
return
new
OperatorNot
(eval); }
public
static
Part
read(java.io.BufferedReader r)
throws
java.io.IOException, ClassNotFoundException,NoSuchMethodException, java.lang.reflect.InvocationTargetException,IllegalAccessException{
return
new
OperatorNot
(
Part
.read(r)); }
public
boolean
same(Object o) { o =
Brackets
.unbracket(o);
if
(!(o
instanceof
OperatorNot
))
return
false;
OperatorNot
obj = (
OperatorNot
)o;
return
child.same(obj.child); }
public
Component createView(
FormulaView
view) {
return
new
OperatorNotView
(this,view,
new
OperatorNotSymbolView(getName())); }
public
void
saveOperatorLatex(java.io.BufferedWriter w)
throws
java.io.IOException { w.write(
"\\neg"
); } }
class
OperatorNotSymbolView
extends
TextSymbolView
{
public
OperatorNotSymbolView(String str) {
super
(str); }
public
Dimension getSymbolSize() { FontMetrics metrics = getFontMetrics(getFont());
return
new
Dimension(metrics.charWidth(
' '
)+1,metrics.getHeight()); }
public
void
paintSymbol(Graphics g) { FontMetrics metrics = g.getFontMetrics();
int
spatWidth = metrics.charWidth(
' '
);
int
ascent = metrics.getAscent();
int
y = ascent/2; g.drawLine(0,y,spatWidth-1,y); g.drawLine(spatWidth-1,y,spatWidth-1,(ascent*3)/4 + 1); } }