📄 environment.java2
字号:
PrintJob pj = this.getToolkit().getPrintJob(this, "Print Screen", null);
Graphics pg = pj.getGraphics();
this.printComponents(pg);
pg.dispose();
pj.end();
updateStatus("Print completed.");
} catch (Exception e) {
updateStatus("");
if(e.getMessage() !=null) { //cancel button
DFAOKDialog dg = new DFAOKDialog("Could not print current machine.\n"+ e.getMessage(),
this, "DFA Print Error");
dg.show();
}
}
}
/**
* Opens a dialog and focuses the nondeterministic states.
* These are found by calling showNondets from Machine.
* @see Machine
*/
public void showNondets() {
String error = a.checkMachine();
if (error == null)
if (a.showNondets()) {
a.d.repaint();
DFAOKDialog dg = new DFAOKDialog("The nondeterministic states\nare highlighted.",
this, "DFA Message");
Thread dt = Thread.currentThread();
dg.setDialogThread(dt);
dg.show();
if (dg.getPushedButton().equals(ThreadDialog.NOT_YET))
dt.suspend();
a.d.unfocusAll();
a.d.repaint();
} else {
DFAOKDialog dg = new DFAOKDialog(AUTOMATON_IS_DETER_STR, this,"DFA Message");
dg.show();
}
else {
DFAOKDialog dg = new DFAOKDialog(error, this, "DFA Error");
dg.show();
}
}
/**
* Checks if the machine is deterministic or has any errors and returns an appropriate String.
*/
public String checkDeterministic() {
String error = a.checkMachine();
if (error != null )
return error;
if (a.showNondets() == false)
return AUTOMATON_IS_DETER_STR;
a.d.unfocusAll();
a.d.repaint();
return AUTOMATON_IS_NON_DETER_STR;
}
/**
* sets the FSA to be a DFA builder
*/
public void setToDfa(Vector theStates) {
Desktop temp = new Desktop(Machine.FSA, this);
dfa = new FSA(temp);
dfa.buildDfa(theStates);
d.setRowSize(dfa.d.theStates);
dfa.d.setRowSize(dfa.d.theStates);
d.setChecker(dfa.d.theStates);
dfa.d.setChecker(dfa.d.theStates);
updateStatus("Mail any bugs or comments to: rodger@cs.duke.edu");
}
/**
* Sets the source Environment that generated this Environment
*/
public void setEnvSource(Environment source) {
envSource = source;
}
/**
* Sets the Environment that is generated by this environment
*/
public void setEnvTarget(Environment target) {
envTarget = target;
setEnabled(target == null);
}
public Environment getEnvSource() {
return envSource;
}
/**
* Show the answer to the DFA convertion problem
*/
public void showAnswers() {
if (dfa == null)
return;
Machine temp = a;
a = new FSA(dfa);
d = a.d;
centerPanel.remove(temp.d);
centerPanel.add("Center", d);
temp.d.setVisible(false);
d.setVisible(true);
super.validate();
((FSA) a).placeAllStates(temp);
d.repaint();
}
public void setShowing(boolean boo) {
super.setShowing(boo);
if(boo == false)
d.setVisible(false);
}
/**
* Handles the checking to see if DFA and NFA are identical
*/
public void done() {
String erro;
if (dfa == null)
return;
d.unmarkAllStates();
dfa.d.unmarkAllStates();
d.unselectTransitions();
erro = checkDeterministic();
if(erro != AUTOMATON_IS_DETER_STR) {
a.showNondets();
if( erro.equals(AUTOMATON_IS_NON_DETER_STR))
erro = "The highlighted state(s) are nondeterministic";
DFAOKDialog dg = new DFAOKDialog(erro, this, "Automaton check.");
dg.show();
} else if(checkMultiLetterLabels()) {
erro = "Your automaton should have no multiple \n letter transition labels.";
DFAOKDialog dg = new DFAOKDialog(erro, this, "Automaton check.");
dg.show();
} else {
erro = ((FSA) a).checkDfaDone(dfa);
d.repaint();
if(erro.equals(DFA_IS_CORRECT_STR)) {
d.relabel();
d.repaint();
myGrammar.addOtherWindows();
informWatcher("Next");
return;
}
DFAOKDialog dg = new DFAOKDialog(erro, this, "Automaton check.");
dg.show();
}
d.unfocusAll();
d.repaint();
d.selectedState = null;
}
/**
* Solves only the selected State in the NFA to DFA window
*/
public void expandState(State s) {
String answer = ((FSA) a).expandState(dfa, s);
if(!answer.equals(DFA_IS_CORRECT_STR)) {
DFAOKDialog dg = new DFAOKDialog(answer, this, "Expand State.");
dg.show();
}
d.repaint();
}
/**
* Check if any of the transitions have more than one letter.
*/
public boolean checkMultiLetterLabels() {
LabelSeparator breaker = new LabelSeparator((FSA) a);
return breaker.checkMultiLetterLabels();
}
/**
* Breaks up all multiple letter labels on the desktop into several states.
*/
public void breakupMultipleLabels() {
LabelSeparator breaker = new LabelSeparator((FSA) a);
breaker.breakupMultipleLabels();
}
/**
* Shows the states which are unreachable from
* the initial state.
*/
public void showUnreachables() {
DFAOKDialog dg = new DFAOKDialog(a.showUnreachables(), this,"Unreachable States.");
d.repaint();
dg.show();
d.unfocusAll();
d.repaint();
}
public void showClosures(State s) {
((FSA)a).showClosures(s, dfa);
}
/**
* Removes the current desktop and opens a brand new one.
*/
public void clear() {
centerPanel.remove(d);
d.setVisible(false);
d = new Desktop(type, this);
a = new FSA(d);
centerPanel.add("Center", d);
doLayout();
updateStatus();
d.setRowSize(dfa.d.theStates);
d.setChecker(dfa.d.theStates);
d.setVisible(true);
super.validate();
}
public void setEnabled(boolean b) {
super.setEnabled(b);
runmenu.setEnabled(b);
filemenu.setEnabled(b);
optionsmenu.setEnabled(b);
}
public void close() {
this.setVisible(false);
}
/**
* Updates the title and the status line.
*/
public void updateStatus() {
String typeInTitle = "DFA Window";
this.setTitle(typeInTitle);
String strModified = (a.d.modified) ? "(modified)":"";
statusLine.setText("");
}
/**
* Updates the title and the status line.
* @param message the new status line.
*/
public int updateStatus(String message) {
updateStatus();
setMessage(message);
setMessageSize(70);
return 0;
}
/**
* Should be removed when the bug regarding non-modal
* dialogs is fixed.
*/
public void threadAction(int id) {
switch (id) {
case CLOSE:
close();
break;
case SHOWNONDETS:
showNondets();
break;
}
} // end of method threadAction
} // end of class Environment.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -