📄 mainwindow.java
字号:
/**
* Copyright (C) 2006, Laboratorio di Valutazione delle Prestazioni - Politecnico di Milano
* 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 2 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package jmt.gui.jmodel.mainGui;
import jmt.gui.common.layouts.MultiBorderLayout;
import jmt.gui.common.resources.ImageLoader;
import jmt.gui.common.Manager;
import jmt.gui.jmodel.controller.GraphMouseListner;
import jmt.gui.jmodel.controller.Mediator;
import org.jgraph.JGraph;
import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Locale;
/**
* MainWindow contains the main window of the jmodel project, it implements the
* Singleton pattern. no need to create more then 1 main window!
*
* @author Federico Granata
* Date: 3-giu-2003
* Time: 14.09.14
* Modified by Bertoli Marco 7-giu-2005
*/
public class MainWindow extends JmtFrame {
protected static JmtFrame thisFrame;//reference to this object
protected Mediator mediator;// mediator between components of the application
protected ToolBar toolbar;//main toolbar
protected JMenuBar menu;//main menu
protected GraphMouseListner ml;//mouse listener of the JGraph
protected JScrollPane scroll;//panel that contains the JGraph component
protected JPanel mainPane;//panel that contains the "scroll"
protected ComponentBar componentbar;
public static boolean advanced = false;
/** Creates the new Main window of the application.
*
*/
public MainWindow() {
super();
this.setIconImage(ImageLoader.loadImage("JMODELIcon").getImage());
thisFrame = this;
setTitle("JSIMgraph - Advanced queuing network design tool");
mediator = new Mediator(null, (MainWindow) thisFrame);
Mediator.advanced = advanced;
menu = new Menu(mediator);
setJMenuBar(menu);
toolbar = new ToolBar(mediator);
componentbar = new ComponentBar(mediator);
getContentPane().setLayout(new MultiBorderLayout());
getContentPane().add(toolbar, BorderLayout.NORTH);
getContentPane().add(componentbar, BorderLayout.NORTH);
mainPane = new JPanel(new BorderLayout());
getContentPane().add(mainPane, BorderLayout.CENTER);
ml = new GraphMouseListner(mediator);
mediator.setMouseListner(ml);
scroll = new JScrollPane();
// 23/07/03 - Massimo Cattai //////////////////////////////////////////
mainPane.add(scroll, BorderLayout.CENTER);
// Old Code - getContentPane().add(scroll, BorderLayout.CENTER);
// 23/07/03 - end /////////////////////////////////////////////////////
setSize(800, 600);
centerOnScreen();
setVisible(true);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
if (mediator.checkForSave("<html>Save changes before closing?</html>")) return;
// Ends simulation process if active
mediator.stopSimulation();
// Disposes resultsWindow (if present) and mainwindow
if (mediator.getResultsWindow() != null)
mediator.getResultsWindow().dispose();
if (mediator.getPAProgressWindow() != null) {
mediator.getPAProgressWindow().stopAnimation();
mediator.getPAProgressWindow().dispose();
}
MainWindow.this.dispose();
Manager.exit(MainWindow.this);
}
});
}
/** Sets the new Graph inside the scroll panel.
*
* @param newGraph
*/
public void setGraph(JGraph newGraph) {
// 23/07/03 - Massimo Cattai //////////////////////////////////////////
//removeEditor();
mainPane.remove(scroll);
// Old Code - remove(scroll);
// 23/07/03 - end /////////////////////////////////////////////////////
scroll = new JScrollPane(newGraph);
// 23/07/03 - Massimo Cattai //////////////////////////////////////////
mainPane.add(scroll, BorderLayout.CENTER);
// Old Code - getContentPane().add(scroll);
// 23/07/03 - end /////////////////////////////////////////////////////
getContentPane().validate();
}
/** Removes the current graph from the main window.
*
*/
public void removeGraph() {
mainPane.remove(scroll);
getContentPane().repaint();
}
public ComponentBar getComponentBar() {
return componentbar;
}
public JScrollPane getScroll() {
return scroll;
}
public JToggleButton getResultsButton() {
return toolbar.getResultsButton();
}
/** main function it activates the application .
*
* @param args
*/
public static void main(String[] args) {
try {
// UIManager.setLookAndFeel(new com.incors.plaf.kunststoff.KunststoffLookAndFeel());
UIManager.setLookAndFeel(new com.jgoodies.looks.plastic.Plastic3DLookAndFeel());
} catch (UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
if ((args != null && args.length > 0)
&& (args[0] != null)
&& (args[0].equals("trek")))
advanced = true;
Locale.setDefault(Locale.ENGLISH);
Manager.addJMTWindow(new MainWindow());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -