📄 environment.java2
字号:
/*---------------------------------------------------------------------------
File: Environment.java
Package: JFLAP Version 1.0
Author: Magda & Octavian Procopiuc V1.0 07/15/96
Description of Contents: Contains class Environment.
--------------------------------------------------------------------------*/
/*
* Susan H. Rodger, Magda Procopiuc, Octavian Procopiuc
* Computer Science Department
* Duke University
* June 1996
* Supported by National Science Foundation DUE-9596002 and DUE-9555084.
*
* Copyright (c) 1996
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the author. The name of the author may not be used to
* endorse or promote products derived from this software without
* specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
package javaParse;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.io.*;
import java.net.URL;
import java.util.*;
/**
* This is the main window associated with each machine that the user
* opens. It contains the Desktop in the middle -- where the machine
* is displayed and
* edited --, a status bar at the bottom, an input string bar
* above the Desktop, and a menu bar at the top.
* It also contains the actual machine.
*
* @see flap.Desktop
* @author Magda & Octavian Procopiuc
* @version 1.0, 07/15/96
*/
public class Environment extends WindowItem implements ActionListener, WindowListener, MouseListener, KeyListener, ItemListener{
/**
* The type of the machine.
*/
public int type;
public Panel centerPanel;
/**
* The desktop.
*/
public static Desktop d; //robyn made static for closure window purpose
/**
* Other desktop used by the TO_DFA FSA's to store the DFA to compare with
*/
public FSA dfa;
/**
* The machine.
*/
public Machine a;
private LR1Grammar myGrammar;
/**
* The Environment that generated this Environment
*/
public Environment envSource;
/**
* the Environment that this Environment generated. When this is set the window is frozen
*/
public Environment envTarget;
/**
* The bottom status line.
*/
public Label statusLine;
public final static String CLOSE_STR = "Close";
public final static String DONE_STR = "Check if done";
public final static String TO_DFA_STR = "Convert to DFA";
public final static String SHOW_STR = "Show";
public final static String EXPAND_STATE_STR = "Expand a state";
public final static String SHOW_LABEL_STR = "Show Name Labels";
public final static String MINIMIZE_STR = "Minimize";
public final static String SHOW_UNREACHABLE_STR = "Show unreachable states";
public final static String HLP_STATE_STR = "States";
public final static String HLP_TRANSITION_STR = "Transitions";
public final static String HLP_OVERVIEW_STR = "Overview";
public final static String HLP_UPPERWINDOW_STR = "Step Run Window";
public final static String HLP_TRACEWINDOW_STR = "Trace Window";
public final static String HLP_MENUBAR_STR = "Menu Bar";
public final static String HLP_NFATODFA_STR = "NFA to DFA";
public final static String HLP_MINIMIZE_STR = "Minimize a DFA";
public final static String AUTOMATON_IS_DETER_STR = "The automaton is deterministic.";
public final static String AUTOMATON_IS_NON_DETER_STR = "The automaton is non deterministic.";
public final static String DFA_IS_CORRECT_STR = " The DFA is correct.";
public final static String DONE_MINIMIZE_STR = "Done";
public final static String NO_FILE_NAME = "(no name)";
final static int PRINT = 3;
final static int CLOSE = 4;
final static int SHOWNONDETS = 5;
private Menu filemenu, optionsmenu, runmenu, helpmenu;
public Environment(Vector theStates, LR1Grammar grammar) {
super();
this.type = Machine.FSA;
this.addWindowListener(this);
this.addKeyListener(this);
centerPanel = new Panel();
centerPanel.setLayout(new BorderLayout());
setBackground(DFAParams._e_backcolor);
d = new Desktop(type, this);
centerPanel.add("Center", d);
a = new FSA(d);
statusLine = new Label("", Label.LEFT);
centerPanel.add("South", statusLine);
putMenuBar();
updateStatus("Mail any bugs or comments to: rodger@cs.duke.edu");
setIconImage(DFAParams._img_icon);
setToDfa(theStates);
setInfoPanel(centerPanel);
setReturnCommand(new ReturnCommand(this));
setClearCommand(new ClearCommand(this));
setShowCommand(new ShowCommand(this));
setDoneCommand(new DoneCommand(this));
setHelpCommand(new HelpCommand(this,Params.DFA_HELP));
myGrammar = grammar;
}
public Dimension getPreferredSize() {
return new Dimension(DFAParams._e_width, DFAParams._e_height);
}
/**
* Constructs the menu bar.
*/
private void putMenuBar() {
MenuBar mb = new MenuBar();
Menu m;
MenuItem item;
mb.setFont(DFAParams._m_font);
m = new Menu("File");
filemenu = m;
m.setFont(DFAParams._m_font);
m.add(item = new MenuItem("Print"));
item.addActionListener(this);
m.add(item);
mb.add(m);
m = new Menu("Options");
optionsmenu = m;
m.setFont(DFAParams._m_font);
m.add(item = new MenuItem("Re-label states"));
item.addActionListener(this);
m.add(item = new MenuItem("Show nondeterministic states"));
item.addActionListener(this);
m.add(item = new MenuItem(SHOW_UNREACHABLE_STR));
item.addActionListener(this);
m.addSeparator();
m.add(item = new CheckboxMenuItem("Auto re-label states"));
((CheckboxMenuItem) item).setState(d.autoRelabel);
((CheckboxMenuItem) item).addItemListener(this);
mb.add(m);
setMenuBar(mb);
} // end of method putMenuBar.
public void windowClosing(WindowEvent e) {
Thread actionThread;
actionThread = new DialogThread(this, CLOSE);
actionThread.start();
}
public void windowOpened(WindowEvent e)
{}
public void windowIconified(WindowEvent e)
{}
public void windowDeiconified(WindowEvent e)
{}
public void windowClosed(WindowEvent e)
{}
public void windowActivated(WindowEvent e)
{}
public void windowDeactivated(WindowEvent e)
{}
public void mousePressed(MouseEvent e)
{}
public void mouseReleased(MouseEvent e)
{
updateStatus();
}
public void mouseEntered(MouseEvent e)
{}
public void mouseExited(MouseEvent e)
{}
public void mouseClicked(MouseEvent e)
{}
public void keyPressed(KeyEvent e)
{}
public void keyReleased(KeyEvent e)
{
updateStatus();
}
public void keyTyped(KeyEvent e)
{}
public void itemStateChanged(ItemEvent e){
Thread actionThread;
if (e.getSource() instanceof CheckboxMenuItem){
String arg = ((CheckboxMenuItem)(e.getSource())).getLabel();
if (arg.equals("Auto re-label states")){
d.autoRelabel = ((CheckboxMenuItem) e.getSource()).getState();
d.relabel();
}
}
}
public void actionPerformed(ActionEvent e){
Thread actionThread;
if (e.getSource() instanceof MenuItem) {
String arg = ((MenuItem)(e.getSource())).getLabel();
if (CLOSE_STR.equals(arg)) {
actionThread = new DialogThread(this, CLOSE);
actionThread.start(); }
else if ("Re-label states".equals(arg))
relabel();
else if ("Show nondeterministic states".equals(arg)) {
actionThread = new DialogThread(this, SHOWNONDETS);
actionThread.start(); }
else if (SHOW_UNREACHABLE_STR.equals(arg))
showUnreachables();
else if ("Print".equals(arg))
printPostscript();
else {
DFAOKDialog dg = new DFAOKDialog("This feature is not implemented",this, "Sorry...");
dg.show();
}
}
repaint();
} // end of method action.
/**
* Relabels the states by calling relabel from the Desktop.
*/
public void relabel() {
a.d.relabel();
a.d.repaint();
updateStatus("Relabel completed.");
}
/**
* Pops up a menu and prints the window to a postscript file
*/
public void printPostscript() {
try {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -