/*
* 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.AddMode;
import ketUI.modes.DocumentState;
import ketUI.modes.NormalMode;
import ketUI.responder.MouseResponder;
/**
* Handle toolbar-button mouse clicks.
*/
class ExpandMenuFrame extends ButtonMenu {
public ExpandMenuFrame(Document document, JButton source) {
super(document);
setupUserInterface(source, 3, 1, 200, 100, "Expand the current selection.");
setHold(true);
}
private void addRow(String leftText, String leftMessage, String rightText, String rightMessage) {
add(row(makeButton(leftText, leftMessage), makeButton(rightText, rightMessage)));
}
@Override
public void buttonSetup() {
addRow("parent (prepending arguments)", "Prepend a parent function and, if it contains arguments, prepend them, 'ap'.",
"parent (appending arguments)", "Append a parent function and, if it contains arguments, append them, 'ap'.");
addRow("left sibling", "Prepend a an argument to the left of the current selection, 'al'.",
"right sibling", "Append an argument to the right of the current selection, 'al'");
addRow("left child", "Prepend a new argument to the left of the current selection, 'ai'.",
"right child", "Append a new argument to the right of the current selection, 'ao'.");
}
@Override
public void replaceByText(String text) {
Chord chord = getChord();
switch (text) {
case "parent (prepending arguments)":
getAddMode().prependPurpose(chord);
break;
case "parent (appending arguments)":
getAddMode().appendPurpose(chord);
break;
case "left child":
getAddMode().prependNewChild(chord);
break;
case "right child":
getAddMode().appendNewChild(chord);
break;
case "left sibling":
getAddMode().prependNewSibling(chord);
break;
case "right sibling":
getAddMode().appendNewSibling(chord);
break;
default:
return;
}
getMathCollection().updateUndoStack();
document.getKetPanel().updateAndRepaint();
}
}