Sindbad~EG File Manager
/**
* @author Michael Beeson
* About 60 lines at the beginning of init() are taken from Alex Ostrovsky's CS 240 code;
* and about 80 lines at the end of the file are taken from Euna Park's CS240 code.
* Everything else is by Beeson.
* First version 12.18.2006
* modified 'in' and freshVar and replace 1.10.07
* 1.10.07 added fixupSubstForReturn and the call to it
* @date 12.24.2006
*/
package org.dynamicgeometry.constructor;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.ListIterator;
import java.util.Set;
import java.util.logging.Logger;
import java.util.Stack;
import java.util.Hashtable;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import org.dynamicgeometry.diagrammer.Diagrammer;
import org.dynamicgeometry.diagrammer.GeometricObject;
import org.dynamicgeometry.diagrammer.Label;
import org.dynamicgeometry.diagrammer.SymbolTable;
import org.dynamicgeometry.diagrammer.Parser;
import org.dynamicgeometry.diagrammer.Command;
import org.dynamicgeometry.scripts.Scripts;
class IllegalScriptException extends Exception{
public IllegalScriptException(){}
public IllegalScriptException(String msg) { super(msg);}
}
class State {
public Stack<Scripts> stack;
public ArrayList<GeometricObject> figure;
public SymbolTable symbolTable;
public Scripts activeScript;
public int activeLine;
public Hashtable<String,String> Subst;
boolean inButtonEnabled;
boolean executeButtonEnabled;
public State(Stack<Scripts> _stack, ArrayList<GeometricObject> _figure, SymbolTable _symbolTable, Scripts _activeScript, int _activeLine, boolean _inButtonEnabled, boolean _executeButtonEnabled, Hashtable<String,String> _Subst)
// we need to make clones of all these objects, not just store references
{ stack = (Stack<Scripts>) _stack.clone();
int n = _figure.size();
figure = new ArrayList<GeometricObject>(n);
int i;
symbolTable = _symbolTable.copy();
for(i=0;i<n;i++)
figure.add(symbolTable.value(_figure.get(i).getLabel().toString()));
activeScript = _activeScript;
activeLine = _activeLine;
inButtonEnabled = _inButtonEnabled;
executeButtonEnabled = _executeButtonEnabled;
Subst = _Subst;
}
}
public class Constructor extends JApplet
{
static final int textAreaWidth = 10;
static final int textAreaHeight = 30;
private Container contentPane;
private JPanel westPane;
private JPanel centerPane;
private JTextArea textArea;
private JButton executeButton;
private JButton inButton;
private JButton backButton;
private Stack<State> stateStack = new Stack<State>();
private JApplet diagrammer = null;
private Stack<Scripts> theStack = new Stack<Scripts>();
Scripts activeScript;
SymbolTable theSymbolTable;
ArrayList<GeometricObject> Selected;
ArrayList<GeometricObject> theFigure;
boolean isVisible = true;
private boolean isDiagrammerEnabled = false;
private String whichConstruction = "";
private Hashtable<String,String> Subst = new Hashtable<String,String>();
public void init()
{
whichConstruction = getParameter("whichConstruction");
// get the content pane to draw stuff
contentPane = getContentPane();
contentPane.setLayout(new BorderLayout()); // set border layout
// init panels
westPane = new JPanel();
centerPane = new JPanel();
// set layout for panels
westPane.setLayout(new GridLayout(10, 1, 3, 3));
centerPane.setLayout(new BorderLayout());
// add panels to the content pane
contentPane.add(westPane, BorderLayout.WEST);
contentPane.add(centerPane, BorderLayout.CENTER);
textArea = new JTextArea(textAreaHeight, textAreaWidth);
JScrollPane scroll = new JScrollPane(textArea,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
executeButton = new JButton("Execute");
executeButton.addActionListener(new
ActionListener()
{
public void actionPerformed(ActionEvent event)
{
try{
execute();
}
catch(Exception ex)
{ System.out.println(ex.toString());
}
}
});
inButton = new JButton("Step In");
inButton.addActionListener(new
ActionListener()
{
public void actionPerformed(ActionEvent event)
{ try{
in();
}
catch(Exception ex)
{ System.out.println(ex.toString());
}
}
});
backButton = new JButton("Step Back");
backButton.addActionListener(new
ActionListener()
{
public void actionPerformed(ActionEvent event)
{
back();
}
});
westPane.add(new JLabel("Choose Action"));
westPane.add(executeButton);
westPane.add(inButton);
westPane.add(backButton);
backButton.setEnabled(false); // can't go back at the beginning
centerPane.add(scroll, BorderLayout.CENTER);
theFigure = getFigure(); // unfortunately it is null at this point, so this is useless.
Selected = getSelected();
try{
activeScript = Scripts.finalScript(whichConstruction); // get a new instance of this script
activeScript.ActiveLine = 0; // we're starting at the first line of this script
String command = activeScript.getScript()[0];
Parser p = new Parser();
command = p.parse(command).getCommandName();
if(Scripts.isPrimitiveCommand(command) || command == "return")
inButton.setEnabled(false);
else
inButton.setEnabled(true);
}
catch( Exception ex){
ex.printStackTrace();
}
displayScript();
}
private void fixupSubstForReturn()
{ String n = activeScript.getName();
String[] pNames;
String[] pTypes;
String ret;
String[] commands;
// look this command up in Euclid to get its script, parameters, etc.
try{
pNames = Scripts.getParameterNames(n);
commands = Scripts.getScript(n);
}
catch(Exception ex)
{ System.out.println("Command " + n + " is not supported.");
return;
}
int i;
for(i=0;i<pNames.length;i++)
{ Subst.remove(pNames[i]);
System.out.println("Removing " + pNames[i]);
}
String[] temp = commands[commands.length-1].split(" +");
String ReturnVariable = temp[1];
//Subst.remove(ReturnVariable);
//System.out.println("Removing " + ReturnVariable);
}
/**
* First ensure that in Diagrammer, all previously selected items are
* deselected, and the correct arguments for the active line are selected,
* and in the correct order. This is done using the Diagrammer.setSelected
* method.
* Then, in case the line being executed (activeLine) is not a "return"
* statement, it increments activeLine and causes the window to be repainted.
* It then takes care to enable or disable the In button, and then returns.
* If the line being executed is a "return" statement, then it has to
* decrement the level of the returned object (and its points if it is a polygon),
* then pop the stack,
* increment the activeline (in the popped script)
* and set activeScript to the popped script.
* If it's the last line of the script but doesn't begin with
* "return" then the same is done.
*/
private void execute()
{
// get the command to be executed.
if(theFigure == null)
{ theFigure = getFigure(); // it hasn't been initialized yet
Selected = getSelected();
theSymbolTable = new SymbolTable(theFigure);
}
else
theFigure = getFigure(); // it may have been changed by dragging since the last command was executed.
State currentState = new State(theStack,theFigure,theSymbolTable,activeScript,activeScript.ActiveLine,inButton.isEnabled(), executeButton.isEnabled(),Subst);
stateStack.push(currentState);
backButton.setEnabled(true);
String[] commands = activeScript.getScript();
String command = commands[activeScript.ActiveLine]; // OK, that's the command to be executed
String[] activeScriptParameters;
int L,i;
Command c;
ArrayList<GeometricObject> newFigure;
Parser p = new Parser();
c = p.parse(command);
if(c == null)
{ System.out.println(p.getErrorMsg());
return;
}
if(c.getCommandName() == "return")
{ // find the object or objects to be returned. There must be just a variable or variables separated by "and" after the "return".
// the first variable is the actual returned object, but the rest of the returned objects get retained in theFigure too.
String[] args = c.getArguments();
GeometricObject ans = theSymbolTable.value(args[0]);
ans.setLevel(ans.getLevel()-1);
ans.setSelected(true);
// State oldState = stateStack.pop();
// Subst = oldState.Subst;
// Next fix up the construction and arg fields of ans
System.out.println("Line 1");
ans.setConstruction(activeScript.getName());
// ans.args should become the list of parameters that were passed to activeScript
ArrayList<GeometricObject> actualArgs = new ArrayList<GeometricObject>(activeScript.getParameterNames().length);
System.out.println("activeScript.getName() returned " + activeScript.getName());
//activeScriptParameters = activeScript.getParameterNames();
activeScriptParameters = activeScript.getParameterNames();
int nParameters = activeScriptParameters.length;
System.out.print("parameters are "); for(i=0;i<nParameters;i++) System.out.print(activeScriptParameters[i]); System.out.println("");
for(i=0;i<nParameters; i++)
{ String argName = activeScriptParameters[i];
GeometricObject actualArg = null;
try{ System.out.println("argName is " + argName);
String NameInFigure = Subst.get(argName);
if(NameInFigure == null) // no entry in Subst for it
NameInFigure = argName; // not necessary to rename it
actualArg = theSymbolTable.value(NameInFigure);
System.out.println("NameInFigure is " + NameInFigure + " whose value is " + actualArg.getLabel().toString());
}
catch(Exception ex)
{ System.out.println("Something went wrong with " + argName);
ex.printStackTrace();
}
actualArgs.add(actualArg);
}
ans.setArgs(actualArgs);
fixupSubstForReturn();
System.out.println("Line 2");
L = ans.getLevel();
for(i=0;i<args.length;i++)
{ GeometricObject x = theSymbolTable.value(args[i]);
int l = x.getLevel();
if(l > L)
{ x.setLevel(L); // keep this object in theFigure after the return
// System.out.println("Level of " + x.getLabel() + " is " + x.getLevel());
/* if(i>0) // make multiple returns anonymous except for the first (main) return value
{ Label ll= x.getLabel();
ll.setLabel("");
x.setLabel(ll);
}*/
}
}
// now remove all objects with larger level than L from theFigure
// and make every object except ans be unselected.
System.out.println("Line 3");
newFigure = new ArrayList<GeometricObject>();
for(GeometricObject x:theFigure)
{ GeometricObject y = theSymbolTable.value(x.getLabel().toString());
if(y != x)
System.out.println("Oops! " + x.getLabel().toString());
if(x.getLevel() <= L)
{ if(x != ans)
x.setSelected(false);
newFigure.add(x);
}
}
System.out.println("Line 4");
theFigure = newFigure;
setFigure();
System.out.println("Line 5");
if(!theStack.empty())
{ activeScript = theStack.pop();
activeScript.ActiveLine++;
}
displayScript();
if(L==0)
{ executeButton.setEnabled(false);
inButton.setEnabled(false);
}
return;
}
// Now it doesn't start with "return"
GeometricObject[] args = new GeometricObject[c.getArguments().length];
for(i=0;i<args.length;i++)
args[i] = theSymbolTable.value(c.getArguments()[i]);
SymbolTable localSymbolTable = theSymbolTable.copy();
GeometricObject[] results = null;
try{
results = localSymbolTable.Execute1(c.getLabel(),c.getCommandName(),args);
// Command.getLabel() returns a string, while GeometricObject.getLabel() returns a Label
}
catch(Exception ex)
{ ex.printStackTrace();
}
GeometricObject result;
Selected.clear();
if(results == null || results[0] == null) System.out.println("Failed to execute " + c.getCommandName());
for(int k = 0; k < results.length; k++)
{ result = results[k];
if(result == null) System.out.println("Failed to execute " + c.getCommandName());
result.setLevel(theStack.size()+1); // thus, objects created by the lines of the toplevel script have level 1
// initial data have level 0.
result.setVisible(true);
result.setIsInput(1);
if(k==0)
{
theSymbolTable.addObject(result.getLabel().toString(), result);
// now for debugging check that the args are what they should be
int nn = result.getArgs().size();
if(nn != args.length) System.out.println("Ooops! wrong length " + nn + "!=" + args.length);
for(int jj = 0; jj < nn; jj++) if(result.getArgs().get(jj) != args[jj]) System.out.println("Ooops! Argument " + args[jj].getLabel() + " is wrong");
theFigure.add(result);
Selected.add(result);
}
else
{ /* multiple objects were returned.
If multiple objects are returned, they must be constructible from the parameters of the Geoscript that returns them
together with the first return value. For example, EquilateralTriangle(A,B) returns D and T, where T = Triangle(A,B,D).
*/
for(GeometricObject o : result.getArgs())
o.setVisible(true);
String key = result.getLabel().toString();
String newLabel;
String[] returnTypes = null;
try{
returnTypes = Scripts.getReturnTypes(c.getCommandName()); // this should not be null if multiple objects were returned
}
catch(Exception ex)
{ ex.printStackTrace();
}
if(returnTypes == null)
System.out.println("Script " + c.getCommandName() + " returns more than one object but doesn't define their return types.");
String returnType = returnTypes[k];
//newLabel = ""; // multiple returns are [not yet] anonymous. Otherwise their labels may clash with
// variables in the scripts in the call stack that aren't yet in theSymbolTable.
if(theSymbolTable.value(key) == null)
newLabel = key;
else
{ newLabel = null;
try{
newLabel = freshVar(returnType, theSymbolTable,null);
}
catch(Exception ex)
{ ex.printStackTrace();
}
}
Label qq = result.getLabel();
qq.setLabel(newLabel);
result.setLabel(qq);
theSymbolTable.addObject(newLabel.toString(), result);
theFigure.add(result);
}
}
// now the after-execution adjustments:
if(activeScript.ActiveLine < commands.length-1)
{ ++activeScript.ActiveLine;
// Next enable or disable "in" button as appropriate, depending on the next line
c = p.parse(commands[activeScript.ActiveLine]);
if(c == null) System.out.println(p.getErrorMsg());
String NextCommand = c.getCommandName();
if(Scripts.isPrimitiveCommand(NextCommand) || NextCommand == "return")
inButton.setEnabled(false);
else
inButton.setEnabled(true);
displayScript();
setFigure();
return;
}
// Now, it was the last line of the script.
// The original plan called for an Up button so in that case you could press Execute, then Up.
// But now, you'll automatically go Up after executing a return, if there is a stack to go Up.
L = theStack.size();
if(L==0) return; // done.
// no objects will be retained since there was no "return" statement in the script
newFigure = new ArrayList<GeometricObject>();
for(GeometricObject x:theFigure)
{ if(x.getLevel() <= L)
newFigure.add(x);
}
theFigure = newFigure;
setFigure();
if(!theStack.empty())
activeScript = theStack.pop();
displayScript();
}
/** return a string containing 2n spaces
*
*/
private String indent(int n)
{ int indentationIncrement = 2;
char[] x = new char[2*indentationIncrement];
for(int i=0;i<x.length;i++)
x[i] = ' ';
return new String(x);
}
/**
* Displays all the scripts on the stack up to their ActiveLine, with
* indentation showing the stack depth, and finally the activeScript is also
* displayed, with an indication at the ActiveLine.
*
*/
private void displayScript()
{ Stack<Scripts> temp = new Stack<Scripts>();
String before = "";
String after = "";
while(!theStack.empty())
temp.push(theStack.pop());
// now temp contains all the scripts we have gone "in", in reverse order from theStack
int level = 0;
String[] x;
int i;
while(!temp.empty())
{ Scripts t = temp.pop();
x = t.getScript();
for(i=0;i<=t.ActiveLine;i++)
before += indent(level) + x[i] + "\n";
for(i= x.length-1; i > t.ActiveLine;i--)
after = indent(level) + x[i] + "\n" + after;
theStack.push(t);
++level;
}
// now theStack is exactly as it was to begin with
x = activeScript.getScript();
for(i=0;i<activeScript.ActiveLine;i++)
before += indent(level) + x[i] + "\n";
for(i= x.length-1; i > activeScript.ActiveLine; i--)
after = indent(level) + x[i] + "\n" + after;
int A = before.length();
before += indent(level) + ">>" + x[activeScript.ActiveLine] + "\n";
int B = before.length();
textArea.setText(before + after);
textArea.select(A,B);
}
/**
* Undo the previous Execute or In command (and any selection and dragging operations done since then)
* by restoring the state on the top of stateStack.
*/
private void back()
{ State oldState = stateStack.pop();
if(stateStack.empty())
backButton.setEnabled(false); // all the way back to the beginning.
theFigure = oldState.figure;
Selected = getSelected();
theSymbolTable = oldState.symbolTable;
activeScript = oldState.activeScript;
activeScript.ActiveLine = oldState.activeLine;
setFigure();
displayScript();
inButton.setEnabled(oldState.inButtonEnabled);
executeButton.setEnabled(oldState.executeButtonEnabled);
Subst = oldState.Subst;
}
/** Apply the values in the substitution table t to substitute
* for variables occurring in the command x, and return the
* result of the substitution.
*/
private String replace(String x, Hashtable<String,String> t)
{ if(x.startsWith("return"))
{ String[] p = x.split(" +");
String ans = "return ";
for(int i = 1;i<p.length;i++)
{ if(p[i].equals("and"))
ans += p[i];
else if(p[i].equals(";"))
ans += p[i];
else
ans += replace(p[i],t);
if(i < p.length-1)
ans += " ";
}
return ans;
}
int j = x.indexOf('(');
if(j==-1)
{ // atomic case, since you can't have '=' unless there's also a '(' somewhere on the right of '='
String ans = t.get(x);
return (ans==null) ? x : ans;
}
Parser p = new Parser();
Command c = p.parse(x);
String[] arguments = c.getArguments();
String[] _arguments = new String[arguments.length];
for(j=0;j<c.getArguments().length;j++)
_arguments[j] = replace(arguments[j],t);
Command d = new Command(replace(c.getLabel(),t),c.getCommandName(), _arguments);
return d.toString();
}
/** return a fresh variable name that is not already in a given symbol table
* and hashtable. Try to use a name suitable for an object of type retType.
*/
private String freshVar(String retType, SymbolTable t, Hashtable<String,String> p)
throws Exception
{ String CircleNames = "CKLRTSJcklrtsj";
String PointNames = "ABDEFGHPQRXYZUVWabdefghpqrxyzuvw";
String SegmentNames = "stuvwabcSTUVWABC";
String RayNames = "rstuvwRSTUVW";
String LineNames = "LKMNSTlkmnst";
String PolygonNames = "stuvSTUV";
int i,j;
ArrayList<String> blocked = new ArrayList<String>();
for(GeometricObject o : theFigure)
blocked.add(o.getLabel().toString());
String pos;
if(retType == "Circle") pos = CircleNames;
else if(retType == "Point") pos = PointNames;
else if(retType == "Segment") pos = SegmentNames;
else if(retType == "Ray") pos = RayNames;
else if(retType == "Line") pos = LineNames;
else if(retType == "Square" || retType == "Quadilateral" || retType == "Polygon" || retType == "Triangle")
pos = PolygonNames;
else throw new Exception("Unrecognized return type in freshVar");
// get a name in pos that is not blocked and not in hashtable p if possible
for(i=0;i<pos.length();i++)
{ for(j=0;j<blocked.size();j++)
{ if(pos.charAt(i) == blocked.get(j).charAt(0))
break;
}
if(j < blocked.size()) continue; // with next i, this one was blocked
// this i is not blocked; check if it's in hashtable p
if(p != null && p.contains(""+pos.charAt(i)))
continue; // already used
return ""+pos.charAt(i);
}
throw new Exception("Too many variable names");
}
/**
* Gets the script corresponding to the command at the active line.
* Renames variables in that script to correspond to the current figure.
* Pushes the active script onto theStack and then sets activeScript
* to be the script defining the construction called at the active line
* of the (up till now) active script, and sets the active line to be 0 because
* we're starting with the first line of that script. No change is made to the current figure.
* The Constructor window, however, will be repainted so that the changes to the
* active script will show.
* @see specs 12
*
*/
private void in()
throws IllegalScriptException
{
String currentLine = activeScript.getScript()[activeScript.ActiveLine];
Parser p = new Parser();
Command c = p.parse(currentLine);
String n = c.getCommandName();
String[] pNames;
String[] pTypes;
String ret;
String[] commands;
// look this command up in Euclid to get its script, parameters, etc.
try{
pNames = Scripts.getParameterNames(n);
pTypes = Scripts.getParameterTypes(n);
ret = Scripts.getReturnType(n);
commands = Scripts.getScript(n);
}
catch(Exception ex)
{ System.out.println("Command " + n + " is not supported.");
return;
}
State currentState = new State(theStack,theFigure,theSymbolTable,activeScript,activeScript.ActiveLine,inButton.isEnabled(), executeButton.isEnabled(),Subst);
stateStack.push(currentState);
backButton.setEnabled(true);
// adjust the variable names in the script we're going into to correspond to the labels in the current diagram.
String[] newParameterNames = new String[pNames.length];
String[] args = c.getArguments(); // the parameter names in the command we're going into
if(pNames.length != args.length)
throw new IllegalScriptException("Command " + n + " called with unexpected number of arguments by command " + activeScript.getName());
int N = pNames.length;
// prepare the table of substitutions
Subst = new Hashtable<String,String>(); // the old Subst has just been pushed on stateStack
// this will associate variable names in the stored script with new names; the new names will be either
// labels in the current diagram, or the name to be assigned to the return value (ReturnVariable below).
for(int i=0; i<N;i++)
{ String s = args[i]; // s should already be in theFigure and theSymbolTable
GeometricObject q = theSymbolTable.value(s);
if(q == null)
throw new IllegalScriptException("Command " + n + "called with undefined arguments");
// associate pNames[i] with s
Subst.put(pNames[i],s);
System.out.println("Putting in " + pNames[i] + " as " + s);
}
// Now for the renaming of variables. First, rename the return value:
String[] temp = commands[commands.length-1].split(" +");
String ReturnVariable = temp[1]; // the variable used for the main return in the original script's return statement
Subst.put(ReturnVariable, c.getLabel().toString()); // the variable in the calling script to which the return value is assigned
System.out.println("return variable " + ReturnVariable + " renamed as " + c.getLabel());
// In addition there will be other variables occurring in the script, introduced on the left of '='
// Some of these variables may already have been used before this script was called, so
// we may have to rename them.
for(String w : commands)
{ Command cc = p.parse(w);
if(cc == null)
throw new IllegalScriptException("Malformed command in script " + n + ": " + w);
String scriptVar = cc.getLabel();
if(scriptVar == null) continue;
GeometricObject o = theSymbolTable.value(scriptVar);
if(o==null && !scriptVar.equals(c.getLabel()) ) continue; // this variable can be left alone, it's not used yet
if(scriptVar.equals(ReturnVariable)) continue; // the return variable is already in Subst
System.out.println(scriptVar + " will be renamed.");
String CommandName = cc.getCommandName();
String ReturnType;
String t;
try{
ReturnType = Scripts.getReturnType(CommandName);
t = freshVar(ReturnType,theSymbolTable,Subst); // get an unused variable;
}
catch( Exception ex)
{ ex.printStackTrace();
return;
}
Subst.put(scriptVar,t);
}
// now replace all variables in the commands array with their values in Subst.
String[] newCommands = new String[commands.length];
for(int i=0;i < commands.length; i++)
newCommands[i] = replace(commands[i],Subst);
// create a new script defining the called construction
Scripts q=null;
try{
q = Scripts.finalScript(n);
}
catch(Exception ex)
{ ex.printStackTrace();
}
q.ActiveLine = 0;
theStack.push(activeScript);
activeScript = q;
activeScript.setScript(newCommands);
// Next disable or enable the In button depending on the now-active line.
c = p.parse(commands[activeScript.ActiveLine]);
if(c == null) System.out.println(p.getErrorMsg());
String NextCommand = c.getCommandName();
if(Scripts.isPrimitiveCommand(NextCommand) || NextCommand == "return")
inButton.setEnabled(false);
else
inButton.setEnabled(true);
displayScript();
}
// functions for communicating with the diagrammer applet by Euna Park 11/12/2006
/**
* Function enables the Diagrammer
*/
private void enableDiagrammer()
{
diagrammer = (JApplet)getAppletContext().getApplet("Diagrammer");
if(diagrammer != null)
{
if(diagrammer instanceof Diagrammer)
{
isDiagrammerEnabled = true;
}
}
}
/**
* Disables creation of objects in Diagrammer. Dragging is still allowed.
* @return true if diagrammer has been disabled, false otherwise
*/
private boolean disableDiagrammer()
{
if (diagrammer != null)
{
((Diagrammer)diagrammer).disableDiagrammer(true);
isDiagrammerEnabled = false;
return true;
}
return false;
}
/**
* Gets theFigure from the Diagrammer
* @return ArrayList of Geometric Objects from the Diagrammer
*/
private ArrayList<GeometricObject> getFigure()
{
ArrayList<GeometricObject> figure = null;
// communicate thru the web page
if(!isDiagrammerEnabled)
enableDiagrammer();
if(isDiagrammerEnabled)
figure = ((Diagrammer)diagrammer).getFigure();
return figure;
}
/**
* set the figure in Diagrammer
*
*/
private void setFigure()
{
// communicate thru the web page
if(!isDiagrammerEnabled)
enableDiagrammer();
if(isDiagrammerEnabled)
((Diagrammer)diagrammer).setFigure(theFigure);
}
/**
* Get all selected object from theFigure
* @return {@link ArrayList} of selected Geometric Objects.
*
*/
private ArrayList<GeometricObject> getSelected()
{
if (theFigure == null) return null;
ArrayList<GeometricObject> figure = new ArrayList<GeometricObject>();
for(int i = 0; i < theFigure.size(); i++)
{
if(theFigure.get(i) != null && theFigure.get(i).isSelected())
figure.add(theFigure.get(i));
}
return figure;
}
}
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists