Package ket.math.purpose.function

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

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

public class FunctionKet extends FunctionForm {

  @Override
  public String toLatex(Vector<Argument> args) {
    switch (args.size()) {
      case 1:
        return "\\left| " + args.get(0).toLatex() + " \\right>";
      case 2:
        return "\\left< " + args.get(0).toLatex() + " | " +  args.get(1).toLatex() + " \\right>";
      case 3:
        return "\\left< " + args.get(0).toLatex() + " | " + args.get(1).toLatex() + " | " + args.get(2).toLatex() + " \\right>";
      default:
        return super.toLatex(args);
    }
  }

  @Override
  public String toHTML(Vector<Argument> args) {
    String less = Symbol.LESS_THAN.toHTML();
    String pipe = Symbol.PIPE.toHTML();
    String greater = Symbol.GREATER_THAN.toHTML();
    switch (args.size()) {
      case 1:
        return pipe + args.get(0).toHTML() + greater;
      case 2:
        return less + args.get(0).toHTML() + pipe + args.get(1).toHTML() + greater;
      case 3:
        return less + args.get(0).toHTML() + pipe + args.get(1).toHTML() + pipe + args.get(2).toHTML() + greater;
      default:
        return super.toHTML(args);
    }
  }

  @Override
  public Box toBox(Argument argument, Vector<Box> boxArgs, long settings, ColourScheme colourScheme) {
    BoxGraphic lt = new BoxGraphic(argument, settings, BoxGraphic.BRA);
    BoxGraphic leftPipe = new BoxGraphic(argument, settings, BoxGraphic.VERTICAL_LINE);
    BoxGraphic rightPipe = new BoxGraphic(argument, settings, BoxGraphic.VERTICAL_LINE);
    BoxGraphic gt = new BoxGraphic(argument, settings, BoxGraphic.KET);
    Vector<Box> list = new Vector<Box>();
    switch (boxArgs.size()) {
      case 1:
        list.add(rightPipe);
        list.add(boxArgs.firstElement());
        list.add(gt);
        return BoxTools.centredHorizontalBoxList(argument, settings, list);
      case 2:
        list.add(lt);
        list.add(boxArgs.get(0));
        list.add(rightPipe);
        list.add(boxArgs.get(1));
        list.add(gt);
        return BoxTools.centredHorizontalBoxList(argument, settings, list);
      case 3:
        list.add(lt);
        list.add(boxArgs.get(0));
        list.add(leftPipe);
        list.add(boxArgs.get(1));
        list.add(rightPipe);
        list.add(boxArgs.get(2));
        list.add(gt);
        return BoxTools.centredHorizontalBoxList(argument, settings, list);
      default:
        return super.toBox(argument, boxArgs, settings, colourScheme);
    }
  }
}
TOP

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

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.