/*
* Copyright (C) 2011 Alasdair C. Hamilton
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package ket.math.purpose.symbolicFunctions;
import java.awt.*;
import java.util.*;
import ket.display.*;
import ket.display.box.Box;
import ket.display.box.BoxGap;
import ket.display.box.BoxGraphic;
import ket.display.box.BoxTools;
import ket.math.*;
import ket.math.purpose.SymbolicState;
/**
* A specific mathematical operation that acts on arguments in a case-specific
* way.
*/
public class SymbolicFunctionFraction extends SymbolicFunctionForm {
@Override
public String toLatex(Vector<Argument> args) {
if (args.size()==2) {
return "\\frac{"+args.get(0).toLatex()+"}{"+args.get(1).toLatex()+"}";
} else {
return super.toLatex(args);
}
}
@Override
public String toHTML(Vector<Argument> args) {
// Not yet implemented.
if (args.size()!=2) {
return super.toHTML(args);
}
return HTMLTools.toFraction(args.firstElement().toHTML(), args.lastElement().toHTML());
/*-
return
"<SPAN class=\"fraction\">\n" +
"<SPAN class=\"numerator\">" + numerator + "</SPAN>\n" +
"<HR class=\"split\"/>\n" +
"<SPAN class=\"denomonator\">" + denomonator + "</SPAN>\n" +
"</SPAN>\n";
*/
}
@Override
public Box toBox(Argument argument, long settings, ColourScheme colourScheme, Vector<Argument> args) {
long[] childFlags = new long[args.size()];
for (int i=0; i<args.size(); i++) {
Argument a = args.get(i);
if (a.getFunction()!=Function.FRACTION) {
childFlags[i] = Box.SUPPRESS_BRACKETS;
}
}
int minArgs = getArgLowerLimit(args.size());
Vector<Box> boxArgs = BoxTools.padArgs(args, minArgs, colourScheme, childFlags);
return this.toBox(argument, boxArgs, settings, colourScheme);
}
@Override
public Box toBox(Argument argument, Vector<Box> boxArgs, long settings, ColourScheme colourScheme) {
if (boxArgs.size()>2) {
return super.toBox(argument, boxArgs, settings, colourScheme);
}
BoxGraphic bar = new BoxGraphic(argument, 0L, BoxGraphic.HORIZONTAL_LINE);
Box above = new BoxGap(argument, 0L, bar, 0.0, 1.0, 0.0, 0.0);
Box below = new BoxGap(argument, 0L, bar, 0.0, 1.0, 0.0, 0.0);
boxArgs.add(1, above);
boxArgs.add(2, bar);
boxArgs.add(3, below);
Box box = BoxTools.centredVerticalBoxList(argument, settings, boxArgs);
bar.setProperty(Box.HORIZONTAL_STRETCH);
return box;
}
}