⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jabawizard.java

📁 一个用于排队系统仿真的开源软件,有非常形象的图象仿真过程!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**    
  * 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.jaba;

import jmt.common.exception.InputDataException;
import jmt.common.exception.SolverException;
import jmt.gui.common.panels.AboutDialogFactory;
import jmt.gui.common.panels.WarningWindow;
import jmt.gui.common.resources.ImageLoader;
import jmt.gui.common.xml.ModelLoader;
import jmt.gui.common.Manager;
import jmt.gui.exact.panels.ForceUpdatablePanel;
import jmt.gui.help.HoverHelp;
import jmt.gui.jaba.link.SolverDispatcher;
import jmt.gui.jaba.panels.*;
import jmt.gui.wizard.Wizard;
import jmt.gui.wizard.WizardPanel;

import javax.help.HelpSet;
import javax.help.JHelp;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.net.URL;
import java.util.Locale;

/**
 * This is the object you use to define your system structure and parameters
 * @author alyf (Andrea Conti)
 * @version Date: 11-set-2003 Time: 14.47.11
 *
 * Adapted by Andrea Zanzottera
 * Heavily bugfixed by Bertoli Marco
 */
public class JabaWizard extends Wizard {

    private final static boolean DEBUG = false;

    private JabaModel data;
    private JLabel helpLabel;
    private HoverHelp help;

    private ModelLoader modelLoader = new ModelLoader(ModelLoader.JABA);

    private SolverDispatcher jsolver;

    //keep a reference to these three components to enable switching
    private WizardPanel serviceTimesPanel, serviceDemandsPanel, visitsPanel;


    private AbstractAction FILE_SAVE = new AbstractAction("Save...") {
        {
            putValue(Action.SHORT_DESCRIPTION, "Save Model");
            putValue(Action.SMALL_ICON, ImageLoader.loadImage("Save"));
            putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
            putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_S));
        }

        public void actionPerformed(ActionEvent e) {
            save();
        }
    };

    private AbstractAction FILE_OPEN = new AbstractAction("Open...") {
        {
            putValue(Action.SHORT_DESCRIPTION, "Open Saved Model");
            putValue(Action.SMALL_ICON, ImageLoader.loadImage("Open"));
            putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
            putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_O));
        }

        public void actionPerformed(ActionEvent e) {
            open();
        }
    };

    private AbstractAction FILE_NEW = new AbstractAction("New...") {
        {
            putValue(Action.SHORT_DESCRIPTION, "Create New Model");
            putValue(Action.SMALL_ICON, ImageLoader.loadImage("New"));
            putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
            putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_N));
        }

        public void actionPerformed(ActionEvent e) {
            newModel();
        }
    };

    private AbstractAction FILE_EXIT = new AbstractAction("Exit") {
        {
            putValue(Action.SHORT_DESCRIPTION, "Exits Application");
            putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
            putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_Q));
        }

        public void actionPerformed(ActionEvent e) {
            cancel();
        }
    };

    private AbstractAction SWITCH_TO_SIMULATOR = new AbstractAction("Switch to Simulator") {
        {
            putValue(Action.SHORT_DESCRIPTION, "Switch to Simulator");
            putValue(Action.SMALL_ICON, ImageLoader.loadImage("Simulator"));
            putValue(Action.ACCELERATOR_KEY,
                    KeyStroke.getKeyStroke(KeyEvent.VK_G,
                            ActionEvent.CTRL_MASK));
            putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_G));
        }

        public void actionPerformed(ActionEvent e) {
            switchToSimulator();
        }
    };

    private AbstractAction ACTION_RANDOMIZE_MODEL = new AbstractAction("Randomize") {
        {
            putValue(Action.SHORT_DESCRIPTION, "Randomize model service demands");
            putValue(Action.SMALL_ICON, ImageLoader.loadImage("dice"));
            putValue(Action.ACCELERATOR_KEY,
                    KeyStroke.getKeyStroke(KeyEvent.VK_R,
                            ActionEvent.CTRL_MASK));
            putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_R));
        }

        public void actionPerformed(ActionEvent e) {
            randomizeModel();
        }
    };



    //NEW
    //@author Stefano Omini
    private AbstractAction HELP = new AbstractAction("jABA help") {
        {
            putValue(Action.SHORT_DESCRIPTION, "Show jABA help");
            putValue(Action.SMALL_ICON, ImageLoader.loadImage("Help"));
            putValue(Action.ACCELERATOR_KEY,
                    KeyStroke.getKeyStroke(KeyEvent.VK_H,
                            ActionEvent.CTRL_MASK));
            putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_H));
        }

        public void actionPerformed(ActionEvent e) {
            showHelp(e);


        }
    };
    //end NEW



    //NEW
    //@author Stefano Omini
    private AbstractAction ABOUT = new AbstractAction("About jABA...") {
        {
            putValue(Action.SHORT_DESCRIPTION, "About jABA");
            /*
            putValue(Action.SMALL_ICON, ImageLoader.loadImage("helpIcon"));
            putValue(Action.ACCELERATOR_KEY,
            KeyStroke.getKeyStroke(KeyEvent.VK_H,
            ActionEvent.ALT_MASK));
            putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_H));
            */
        }

        public void actionPerformed(ActionEvent e) {
            showAbout();
        }
    };
    //end NEW


    //NEW
    //@author Stefano Omini
    private AbstractAction ACTION_SOLVE = new AbstractAction("Solve") {
        {
            putValue(Action.SHORT_DESCRIPTION, "Solve model");
            putValue(Action.SMALL_ICON, ImageLoader.loadImage("Sim"));

            putValue(Action.ACCELERATOR_KEY,
                    KeyStroke.getKeyStroke(KeyEvent.VK_L,
                            ActionEvent.CTRL_MASK));
            putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_L));

        }

        public void actionPerformed(ActionEvent e) {

            if(checkFinish())
                finish();

        }
    };
    //end NEW


    public JabaWizard() {
        this(new JabaModel());
    }

    public JabaWizard(JabaModel data) {
        super("JABA");
        //setResizable(false);
        setSize(640, 500);
        centerOnScreen(this);
        setIconImage(ImageLoader.loadImageAwt("JABAIcon"));
        this.data = data;
        data.resetChanged();
        JPanel first = new JPanel(new GridLayout(2,1));
        first.add(makeMenubar());
        first.add(makeToolbar());
        getContentPane().add(first, BorderLayout.NORTH);

        addPanel(new ClassesPanel(this));
        addPanel(new StationsPanel(this));
        serviceTimesPanel = new ServiceTimesPanel(this);
        visitsPanel = new VisitsPanel(this);
        serviceDemandsPanel = new ServiceDemandsPanel(this);
        addPanel(serviceDemandsPanel);
        addPanel(new DescriptionPanel(this));


        //NEW Andrea Zanzottera 25/11/2005
        // Pannello con i risultati grafici
        DrawSolPanel drawPanel = new DrawSolPanel();
        drawPanel.setData(this.data);
        addPanel(drawPanel);
        //Pannello con i risultati in numeri
        addPanel(new SectorsTextualPanel(this));
        //END Andrea Zanzottera 25/11/2005

        show();
    }

    /**
     * @return the toolbar for the jaba wizard. Shamelessly uses icon from the main jmt frame
     */
    protected JToolBar makeToolbar() {

        JToolBar tb = new JToolBar();
        tb.setRollover(true);
        tb.setOrientation(SwingConstants.HORIZONTAL);
        tb.setFloatable(false);

        //null values add a gap between toolbar icons

         //Versione with Randomizer
         Action[] actions = {FILE_NEW,FILE_OPEN, FILE_SAVE,null, ACTION_FINISH,
         ACTION_RANDOMIZE_MODEL,null, HELP};
         String[] icons = {"New","Open", "Save", "Sim", "dice", "Help"};
         String[] htext = {"Creates a new model","Opens a saved model", "Saves the current model",
         "Solves the current model", "Randomize model data", "Show help"};

        /* Versione senza Randomizer
        Action[] actions = {FILE_NEW,FILE_OPEN, FILE_SAVE,null, ACTION_FINISH,
                            null, HELP};
        String[] icons = {"New","Open", "Save", "Sim", "Help"};
        String[] htext = {"Creates a new model","Opens a saved model", "Saves the current model",
                          "Solves the current model",  "Show help"};
        */
        JButton button;
        tb.setBorderPainted(true);
        //i index scans actions' array which includes null values, while j scans other arrays.
        //so j must be decremented when a null value is found in action array.
        for (int i = 0, j=0; i < actions.length; i++,j++) {
            if(actions[i]==null){
                j--;
                tb.addSeparator(new Dimension(20,2));
            }else{
                button = new JButton(actions[i]);
                button.setText("");
                button.setIcon(ImageLoader.loadImage(icons[j]));
                button.setRolloverIcon(ImageLoader.loadImage(icons[j] + "RO"));
                button.setPressedIcon(ImageLoader.loadImage(icons[j] + "P"));
                button.setFocusPainted(false);
                button.setContentAreaFilled(false);
                button.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
                tb.add(button);
                help.addHelp(button, htext[j]);
            }
        }
        return tb;
    }


    //BEGIN Federico Dall'Orso 8/3/2005
    //NEW
    private JMenuBar makeMenubar(){

        JMenuBar jmb = new JMenuBar();


        //NEW NEW
        //@author Andrea Zanzottera
        //deleted randomizer
        JMenuItem[][] menuItems = {{new JMenuItem(FILE_NEW), new JMenuItem(FILE_OPEN), new JMenuItem(FILE_SAVE),null, new JMenuItem(FILE_EXIT)},
                                   {new JMenuItem(ACTION_SOLVE),
                                    null, new JMenuItem(ACTION_NEXT), new JMenuItem(ACTION_PREV)},
                                   {new JMenuItem(HELP), null, new JMenuItem(ABOUT)} };
        String[] menuTitles = {"File", "Action", "Help"};
        char[] chars = {'F','A','e'};
        for(int i=0; i<menuItems.length; i++){
            JMenu menu = new JMenu(menuTitles[i]);
            menu.setMnemonic(chars[i]);
            for(int j=0; j<menuItems[i].length; j++){
                if(menuItems[i][j]==null)menu.addSeparator();
                else menu.add(menuItems[i][j]);
            }
            jmb.add(menu);
        }
        return jmb;

    }
    //END Federico Dall'Orso 8/3/2005


    /**
     * @return the button panel
     */
    protected JComponent makeButtons() {
        help = new HoverHelp();
        helpLabel = help.getHelpLabel();

        helpLabel.setBorder(BorderFactory.createEtchedBorder());
        //helpLabel.setHorizontalAlignment(SwingConstants.CENTER);

        ACTION_FINISH.putValue(Action.NAME, "Solve");
        ACTION_CANCEL.putValue(Action.NAME, "Exit");

        JPanel buttons = new JPanel();

        JButton button_finish = new JButton(ACTION_FINISH);
        help.addHelp(button_finish, "Validates the system and starts the solver");
        JButton button_cancel = new JButton(ACTION_CANCEL);
        help.addHelp(button_cancel, "Exits the wizard discarding all changes");
        JButton button_next = new JButton(ACTION_NEXT);
        help.addHelp(button_next, "Moves on to the next step");
        JButton button_previous = new JButton(ACTION_PREV);
        help.addHelp(button_previous, "Goes back to the previous step");
        JButton button_help = new JButton(ACTION_HELP);
        help.addHelp(button_help, "Displays help for the current panel");
        buttons.add(button_previous);
        buttons.add(button_next);
        buttons.add(button_finish);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -