Package ket.math.purpose.function

Source Code of ket.math.purpose.function.FunctionLimit

/*
* 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.*;
import ket.display.box.BoxTools;

public class FunctionLimit extends FunctionForm {

  @Override
  public String toLatex(Vector<Argument> args) {
    if (args.size()<=2) {
      return "\\lim_{" + args.get(0).toLatex() + "} " + args.get(1).toLatex();
    } else {
      return super.toLatex(args);
    }
  }

  @Override
  public Box toBox(Argument argument, long settings, ColourScheme colourScheme, Vector<Argument> args) {
    if (args.size()>2) {
      Vector<Box> boxArgs = BoxTools.padArgs(args, 2, colourScheme);
      return super.toBox(argument, boxArgs, settings, colourScheme);
    }
    Box lim = null;
    Box arg = null;
    switch (args.size()) {
      case 0:
        lim = new BoxWord(Argument.PAD_ARG, "?", settings);
        arg = new BoxWord(Argument.PAD_ARG, "?", settings);
        break;
      case 1:
        lim = new BoxWord(Argument.PAD_ARG, "?", settings);
        arg = args.firstElement().toBox(settings, colourScheme);
        break;
      case 2:
        lim = args.firstElement().toBox(settings, colourScheme);
        arg = args.lastElement().toBox(settings, colourScheme);
    }
    Vector<Box> boxArgs = new Vector<Box>(Arrays.asList(lim, arg));
    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);
    }
    Box lim = new BoxWord(
        argument,
        "lim",
        Box.X_CENTRE_ALIGN|Box.Y_CENTRE_ALIGN|Box.PLAIN_FONT);
    BoxWord gap = new BoxWord(
        argument,
        " ",
        Box.X_CENTRE_ALIGN|Box.Y_CENTRE_ALIGN);
    Box arg = boxArgs.get(1);
    arg.setProperty(Box.LEFT_ALIGN|Box.Y_CENTRE_ALIGN);
    Box from = boxArgs.get(0);
    from.setProperty(Box.X_CENTRE_ALIGN|Box.TOP_ALIGN|Box.SMALL_FONT);
    BoxList list = new BoxList(argument, Box.X_CENTRE_ALIGN|Box.Y_CENTRE_ALIGN);

    list.nextHorizontalPath(new Box[]{lim, gap, arg});
    list.nextHorizontalPath(new Box[]{from});
    list.nextVerticalPath(new Box[]{lim, from});
    list.nextVerticalPath(new Box[]{gap});
    list.nextVerticalPath(new Box[]{arg});
    return list;
  }

}
TOP

Related Classes of ket.math.purpose.function.FunctionLimit

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.