Package ketUI

Source Code of ketUI.MouseMenuFrame

/*
* 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 ketUI;

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;


import geom.Position;
import ket.MathCollection;
import ket.Selection;
import ket.display.ImageTools;
import ket.math.Argument;
import ket.math.Branch;
import ket.math.Equation;
import ket.math.Function;
import ket.math.Symbol;
import ket.math.SymbolicFunction;
import ket.math.Token;
import ket.math.purpose.Word;
import ketUI.chord.Chord;
import ketUI.chord.KeyboardEventHandler;
import ketUI.modes.*;
import ketUI.responder.MouseResponder;

/**
* Handle toolbar-button mouse clicks.
*/

public class MouseMenuFrame extends ButtonMenu implements ActionListener {

  JButton mDeleteTrace;
  JButton mCut;
  JButton mUndo;
  JButton mClone;
  JButton mOut;
  JButton mCompositon;
  JButton mState;
  JButton mChild;
  JButton mAfter;

  MouseResponder mouseResponder;

  public MouseMenuFrame(Document document, JComponent source, MouseResponder mouseResponder, Position location) {
    super(document);
    this.mouseResponder = mouseResponder;
    setupUserInterface(source, 3, 1, 200, 100, null);
    setToolTipText("Instead of right-clicking, you can right-drag the mouse in the direction of a button.");
    show(source, (int) location.x-this.getWidth()/2, (int) location.y-this.getHeight()/2); // Duplicates yet contradicts previous code.
  }

  @Override
  public void buttonSetup() {
    mOut = ImageTools.makeNavigationButton("out", "Delete around, 'X'", "Out", this);

    mClone = ImageTools.makeNavigationButton("camera", "Clone the current selection", "Clone", this);
    mUndo = ImageTools.makeNavigationButton("left", "Undo the previous edit, 'u'.", "Undo", this);

    mCut = ImageTools.makeNavigationButton("cut", "Remove the selection and its arguments, 'x'.", "Cut", this);
    mCompositon = ImageTools.makeNavigationButton("S", "Wrap selection in a new function.", "Wrap", this);
    //- JButton mAfter = makeButton("Add After", null);
    mAfter = ImageTools.makeNavigationButton("sibling", "Add after selection.", "Add After", this);

    mDeleteTrace = ImageTools.makeNavigationButton("delete",
        "Remove the selection and if it's parent function has no other arguments, that too, 'D'.",
        "Delete",
        this);
    //- mState = ImageTools.makeNavigationButton("sun", "Change the current selection's state.", "State", this);
    mState = ImageTools.makeNavigationButton("transform", "Change the current selection's state.", "State", this);
    //- JButton mChild = makeButton("Add Child", null);
    mChild = ImageTools.makeNavigationButton("child", "Insert argument into the selected function.", "Child", this);

    add(row(mOut, mClone, mUndo));
    add(row(mCut, mCompositon, mAfter));
    add(row(mDeleteTrace, mState, mChild));
  }

  public void actionPerformed(ActionEvent e) {
    document.getKeyboardEventHandler().setToInitialState();   // What about set-state?
    Object source = e.getSource();
    Chord chord = getChord();
    String text = null;
    if (source==mDeleteTrace) {
      getSelection().deleteTrace();
    } else if (source==mUndo) {
      getMathCollection().undo();
    } else if (source==mOut) {
      getDeleteMode().deleteParent();
    } else if (source==mClone) {
      Argument clone = Argument.cloneArgument(getCurrent());
      getSelection().appendEquation(new Equation(clone));
    } else if (source==mCut) {
      getDeleteMode().remove();
    } else if (source==mCompositon) {
      getAddMode().appendPurpose(chord);
    } else if (source==mState) {
      getNormalMode().substitutePurpose(chord);
    } else if (source==mChild) { // TODO: Each case duplicates MouseResponder.processAction().
      /*>
        if (getCurrent() instanceof VariableToken) {
        getSelection().variableTokenToBranch(mathCollection.getKnownArguments());
        }*/
      getAddMode().appendNewChild(chord);
    } else if (source==mAfter) {
      getAddMode().appendNewSibling(chord);
    }
    getMathCollection().updateUndoStack();
    document.getKetPanel().updateAndRepaint();
    done();
  }


  @Override
  public void replaceByText(String text) {
    //- Chord chord = getChord();
    getMathCollection().updateUndoStack();
    document.getKetPanel().updateAndRepaint();
  }

  private DeleteMode getDeleteMode() {
    return document.getModes().getDeleteMode();
  }
}
TOP

Related Classes of ketUI.MouseMenuFrame

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.