/*
* 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.BoxList;
import ket.display.box.BoxWord;
import ket.math.*;
public class FunctionLog extends FunctionForm {
@Override
public String toLatex(Vector<Argument> args) {
switch (args.size()) {
case 1:
return "\\log" + args.get(0).toLatex();
case 2:
return "\\log_{"+args.get(0).toLatex()+"}" + args.get(1).toLatex();
default:
return super.toLatex(args);
}
}
@Override
public Box toBox(Argument argument, Vector<Box> boxArgs, long settings, ColourScheme colourScheme) {
if (boxArgs.size()==2) {
for (Box b : boxArgs) {
if (b.getArgument()==null) {
b.setArgument(argument);
}
}
Box log = new BoxWord(argument, "log", Box.X_CENTRE_ALIGN|Box.Y_CENTRE_ALIGN|Box.PLAIN_FONT);
Box base = boxArgs.get(0);
base.setProperty(Box.X_CENTRE_ALIGN|Box.BOTTOM_ALIGN|Box.SMALL_FONT);
// TODO: Add a bracketWhenAppropriate() method.
Box arg = boxArgs.get(1);
arg.setProperty(Box.LEFT_ALIGN|Box.Y_CENTRE_ALIGN);
BoxList list = new BoxList(argument, Box.X_CENTRE_ALIGN|Box.Y_CENTRE_ALIGN);
list.nextHorizontalPath(new Box[]{log, base, arg});
list.nextVerticalPath(new Box[]{log});
list.nextVerticalPath(new Box[]{base});
list.nextVerticalPath(new Box[]{arg});
return list;
} else {
return super.toBox(argument, boxArgs, settings, colourScheme);
}
}
}