/*
* JFLAP - Formal Languages and Automata Package
*
*
* Susan H. Rodger
* Computer Science Department
* Duke University
* August 27, 2009
* Copyright (c) 2002-2009
* All rights reserved.
* JFLAP is open source software. Please see the LICENSE for terms.
*
*/
package gui.pumping;
import javax.swing.JPanel;
import pumping.ContextFreePumpingLemma;
import pumping.RegularPumpingLemma;
/**
* This is a subclass of ComputerFirstPane
that deals with
* context-free pumping lemmas.
*
* @author Chris Morgan & Jinghui Lim
* @see pumping.ContextFreePumpingLemma
*
*/
public class CompCFPumpingLemmaInputPane extends ComputerFirstPane {
/**
* Creates a CompCFPumpingInputPane
for a ContextFreePumpingLemma
.
*
* @param l the ContextFreePumpingLemma
we want to run
*/
public CompCFPumpingLemmaInputPane(ContextFreePumpingLemma l)
{
super(l, "L = {" + l.getHTMLTitle() + "} Context-Free Pumping Lemma");
}
/**
* Initializes the animation canvas with the values of u, v,
* x, y, and z.
*
*/
protected void setCanvas()
{
stages[5].setVisible(true);
myCanvas.reset();
myCanvas.addText("w =");
myCanvas.addText(((ContextFreePumpingLemma)myLemma).getU(), "u");
myCanvas.addText(((ContextFreePumpingLemma)myLemma).getV(), "v");
myCanvas.addText(((ContextFreePumpingLemma)myLemma).getX(), "x");
myCanvas.addText(((ContextFreePumpingLemma)myLemma).getY(), "y");
myCanvas.addText(((ContextFreePumpingLemma)myLemma).getZ(), "z");
myCanvas.moveText(new int[]{0, 1, myLemma.getI(), 1, myLemma.getI(), 1});
myStepAnimation.setEnabled(true);
myStartAnimation.setEnabled(false);
repaint();
}
/**
* Creates an HTML string uvixyiz, with the
* real value of i instead of the variable i.
*
* @return a string representing uvixyiz
*/
protected String createXYZ()
{
return "uv" + myLemma.getI() + "xy" +
myLemma.getI() + "z";
}
public void update()
{
ContextFreePumpingLemma pl = (ContextFreePumpingLemma)myLemma;
stageMessages[0].setText("File loaded.");
updateTopPane(false);
/*
* Has w been entered?
*
* If it hasn't, no point doing the rest.
* If it has, then go on and load w.
*/
int[] decomp = pl.getDecomposition();
if(decomp[0] == 0 && decomp[1] == 0 && decomp[2] == 0 && decomp[3] == 0)
return;
myWDisplay.setText(pl.getW());
/*
* Regardless of whether the decomposition has been set, we load
* the stuff in the sliders and table, and send the temporary
* decomposition to the case panel. Even if it hasn't been chosen,
* it won't cause anything to go wrong.
*
*/
int[] decomposition = new int[]{pl.getU().length(), pl.getV().length(),
pl.getX().length(), pl.getY().length()};
setDecomposition(decomposition, pl.getI());
if (myCases != null)
myCases.setDecomposition(decomposition);
decompLabel.setText(myLemma.getDecompositionAsString());
stages[3].setVisible(true);
stages[4].setVisible(true);
if (pl.getI() == -1)
return;
stages[5].setVisible(true);
displayIEnd();
stageMessages[5].setText("Click \"Restart\" to restart the animation.");
stageMessages[5].setVisible(true);
myCanvas.setRestartEnabled(true);
if (myCases != null)
myCases.setAddReplaceButtonsEnabled(true);
}
}