Package ket.math.purpose.function

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

/*
* 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.ColourScheme;
import ket.display.ColourSchemeDecorator;
import ket.display.box.Box;
import ket.display.box.BoxList;
import ket.display.box.BoxWord;
import ket.math.*;

public class FunctionSum extends FunctionForm {

  @Override
  public String toHTML(Vector<Argument> args) {
    switch (args.size()) {
      case 1:
        return Symbol.Sigma.toHTML() + "&nbsp;" +
          args.firstElement().toHTML();
      case 2:
        return Symbol.Sigma.toHTML() + "<SUB>" +
          args.firstElement().toHTML() +
          "</SUB>&nbsp;" +
          args.lastElement().toHTML();

      case 3:
        return Symbol.Sigma.toHTML() + "<SUB>" +
          args.get(0).toHTML() +
          "</SUB><SUP>"+
          args.get(1).toHTML() +
          "</SUP>&nbsp;" +
          args.get(2).toHTML();
      default:
        return super.toHTML(args);
    }
  }

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

  @Override
  public Box toBox(Argument argument, Vector<Box> boxArgs, long settings, ColourScheme colourScheme) {
    switch (boxArgs.size()) {
      case 0:
      case 1:
        {
          Box sum1 = new BoxWord(argument, Symbol.Sigma.toUnicode(),
              Box.X_CENTRE_ALIGN|Box.Y_CENTRE_ALIGN|Box.LARGE_FONT|Box.PLAIN_FONT);
          Box arg1 = boxArgs.firstElement();
          arg1.setProperty(Box.LEFT_ALIGN|Box.Y_CENTRE_ALIGN);

          BoxList list1 = new BoxList(argument, Box.X_CENTRE_ALIGN|Box.Y_CENTRE_ALIGN);

          list1.nextHorizontalPath(new Box[]{sum1, arg1});
          list1.nextVerticalPath(new Box[]{sum1});
          list1.nextVerticalPath(new Box[]{arg1});
          return list1;
        }
      case 2:
        {
          Box sum2 = new BoxWord(argument,
              Symbol.Sigma.toUnicode(),
              Box.X_CENTRE_ALIGN|Box.Y_CENTRE_ALIGN|Box.LARGE_FONT|Box.PLAIN_FONT);
          Box arg2 = boxArgs.get(1);
          Box from2 = boxArgs.get(0);

          BoxList list2 = new BoxList(argument, Box.X_CENTRE_ALIGN|Box.Y_CENTRE_ALIGN);

          list2.nextHorizontalPath(new Box[]{sum2, arg2});
          list2.nextHorizontalPath(new Box[]{from2});
          list2.nextVerticalPath(new Box[]{sum2, from2});
          list2.nextVerticalPath(new Box[]{arg2});

          arg2.setProperty(Box.LEFT_ALIGN|Box.Y_CENTRE_ALIGN);
          from2.setProperty(Box.X_CENTRE_ALIGN|Box.TOP_ALIGN|Box.SMALL_FONT);
          return list2;
        }
      default:
        {
          Box sumDefault = new BoxWord(argument,
              Symbol.Sigma.toUnicode(),
              Box.X_CENTRE_ALIGN|Box.Y_CENTRE_ALIGN|Box.LARGE_FONT|Box.PLAIN_FONT);
          Box arg = boxArgs.get(2);
          arg.setProperty(Box.LEFT_ALIGN|Box.Y_CENTRE_ALIGN);
          Box from = boxArgs.get(0);
          Box to = boxArgs.get(1);

          BoxList list = new BoxList(argument, Box.X_CENTRE_ALIGN|Box.Y_CENTRE_ALIGN);

          list.nextHorizontalPath(new Box[]{to});
          list.nextHorizontalPath(new Box[]{sumDefault, arg});
          list.nextHorizontalPath(new Box[]{from});
          list.nextVerticalPath(new Box[]{to, sumDefault, from});
          list.nextVerticalPath(new Box[]{arg});

          from.setProperty(Box.X_CENTRE_ALIGN|Box.TOP_ALIGN|Box.SMALL_FONT);
          to.setProperty(Box.X_CENTRE_ALIGN|Box.BOTTOM_ALIGN|Box.SMALL_FONT);
          return list;
        }
    }
  }
}
TOP

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

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.