/*
* 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.function;
import java.awt.*;
import java.util.*;
import ket.display.*;
import ket.display.box.Box;
import ket.display.box.BoxFactory;
import ket.display.box.BoxGraphic;
import ket.display.box.BoxList;
import ket.display.box.BoxTools;
import ket.display.box.BoxWord;
import ket.math.*;
public class FunctionIntegral extends FunctionForm {
@Override
public String toHTML(Vector<Argument> args) {
String integral = Symbol.INTEGRAL.toHTML();
switch (args.size()) {
case 1:
return integral +
"d" +
args.firstElement().toHTML();
case 2:
return integral +
args.firstElement().toHTML() +
" " + "d" +
args.lastElement().toHTML();
case 3:
// TODO: This looks ugly as the subscript precedes the
// superscript rather than being directly above it.
return integral +
"<SUB>" + args.get(0).toHTML() + "</SUB>" +
args.get(1).toHTML() +
" d" +
args.get(2).toHTML();
case 4:
// TODO: This looks ugly as the subscript precedes the
// superscript rather than being directly above it.
return integral +
"<SUB>" + args.get(0).toHTML() + "</SUB>" +
"<SUP>" + args.get(1).toHTML() + "</SUP>" +
args.get(2).toHTML() +
" d" +
args.get(3).toHTML();
default:
return super.toHTML(args);
}
}
@Override
public String toLatex(Vector<Argument> args) {
String integral = Symbol.INTEGRAL.toLatex();
switch (args.size()) {
case 1:
return integral + " d " +
args.get(0).toLatex();
case 2:
return integral + " " +
args.get(0).toLatex() +
"\\,d" +
args.get(1).toLatex();
case 3:
return integral + "_{" +
args.get(0).toLatex() +
"} " +
args.get(1).toLatex() +
"\\,d" +
args.get(2).toLatex();
case 4:
return integral + "_{" +
args.get(0).toLatex() +
"}^{" +
args.get(1).toLatex() +
"} " +
args.get(2).toLatex() +
"\\,d" +
args.get(3).toLatex();
default:
return super.toLatex(args);
}
}
@Override
public Box toBox(Argument argument, Vector<Box> boxArgs, long settings, ColourScheme colourScheme) {
switch (boxArgs.size()) {
case 1:
Box box1 = BoxFactory.integral(argument, BoxGraphic.INTEGRAL, null, null, null, boxArgs.get(0));
box1.setProperty(Box.X_CENTRE_ALIGN|Box.Y_CENTRE_ALIGN);
box1.setProperty(settings);
return box1;
case 2:
Box box2 = BoxFactory.integral(argument, BoxGraphic.INTEGRAL, null, null, boxArgs.get(0), boxArgs.get(1));
box2.setProperty(Box.X_CENTRE_ALIGN|Box.Y_CENTRE_ALIGN);
box2.setProperty(settings);
return box2;
case 3:
Box box3 = BoxFactory.integral(argument, BoxGraphic.INTEGRAL, boxArgs.get(0), null, boxArgs.get(1), boxArgs.get(2));
box3.setProperty(Box.X_CENTRE_ALIGN|Box.Y_CENTRE_ALIGN);
box3.setProperty(settings);
return box3;
case 4:
Box box4 = BoxFactory.integral(argument, BoxGraphic.INTEGRAL, boxArgs.get(0), boxArgs.get(1), boxArgs.get(2), boxArgs.get(3));
box4.setProperty(Box.X_CENTRE_ALIGN|Box.Y_CENTRE_ALIGN);
box4.setProperty(settings);
return box4;
default:
return super.toBox(argument, boxArgs, settings, colourScheme);
}
}
}