jmodelproblemswindow.java

来自「一个用于排队系统仿真的开源软件,有非常形象的图象仿真过程!」· Java 代码 · 共 531 行 · 第 1/2 页

JAVA
531
字号
/**    
  * 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.panels;

import jmt.gui.common.CommonConstants;
import jmt.gui.common.controller.ModelChecker;
import jmt.gui.common.definitions.GuiInterface;
import jmt.gui.common.resources.ImageLoader;

import javax.swing.*;
import javax.swing.border.LineBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.HashMap;
import java.util.Vector;

/**
 * <p>Title:</p>
 * <p>Description:</p>
 *
 * @author Francesco D'Aquino
 *         Date: 13-ott-2005
 *         Time: 14.36.31
 */
public class JModelProblemsWindow extends JDialog {
    GuiInterface gi;

    private boolean canBeRun;
    private boolean operationCanceled;

    boolean isToJMVAConversion;

    JLabel title;
    JList problemsList;
    ModelChecker mc;
    Vector problems;

    GridBagLayout gblayout;
    GridBagConstraints gbconstants;

    JButton continueButton;
    JButton cancelButton;

    JButton typeButton;
    JButton descriptionButton;





    public JModelProblemsWindow(Frame owner,ModelChecker checker, GuiInterface gi) {
        super(owner,true);
        this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        problems = new Vector(0,1);
        mc = checker;
        isToJMVAConversion = mc.isToJMVA();
        this.gi = gi;
        canBeRun = false;
        operationCanceled = true;
        GridBagLayout gblayout = new GridBagLayout();
        GridBagConstraints gbconstants = new GridBagConstraints();
        getContentPane().setLayout(gblayout);


        if (isToJMVAConversion) this.setTitle("Problems while trying to convert to JMVA");
        else this.setTitle("Simulation diagnostic");
        setBounds(20,20,20,20);

        title = new JLabel (CommonConstants.HTML_START + CommonConstants.HTML_FONT_TITLE +
            "Problems found" + CommonConstants.HTML_FONT_TIT_END
            + CommonConstants.HTML_FONT_NORM +"Click on an element to solve the problem" +
             CommonConstants.HTML_FONT_NOR_END + CommonConstants.HTML_END);

        problemsList = new JList();
        initializeList();
        problemsList.setListData(problems);
        problemsList.setCellRenderer(new ProblemElementRenderer());
        problemsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        problemsList.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        problemsList.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                setVisible(false);
                ProblemElement temp = (ProblemElement)problemsList.getSelectedValue();
                int pType = temp.getProblemType();
                int pSubType = temp.getProblemSubType();
                getRelatedPanel(pType,pSubType,temp.getRelatedStationKey(),temp.getRelatedClassKey());
                problems.removeAllElements();
                problemsList.removeAll();
                mc.checkModel();
                initializeList();
                problemsList.setListData(problems);
                if (isToJMVAConversion) {
                    if (mc.isErrorFreeToJMVA()) continueButton.setEnabled(true);
                    //else continueButton.setEnabled(false);
                    if ( ((pType == ModelChecker.ERROR_PROBLEM) && ((pSubType == ModelChecker.OPEN_CLASS_BUT_NO_SOURCE_ERROR))) || ((pType == ModelChecker.ERROR_PROBLEM) && ((pSubType == ModelChecker.NO_STATION_ERROR))) ) {
                        setVisible(false);
                    }
                    else {
                        if (!mc.isEverythingOkToJMVA()) show();
                    }
                }
                else {
                    if (mc.isErrorFreeNormal()) continueButton.setEnabled(true);
                    if ((pType == ModelChecker.ERROR_PROBLEM) && ((pSubType == ModelChecker.NO_CLASSES_ERROR)||(pSubType == ModelChecker.SIMULATION_ERROR)||(pSubType == ModelChecker.REFERENCE_STATION_ERROR)||(pSubType == ModelChecker.SOURCE_WITH_NO_OPEN_CLASSES_ERROR)||(pSubType == ModelChecker.ROUTING_ERROR)||(pSubType == ModelChecker.SINK_BUT_NO_OPEN_CLASSES_ERROR))  ) {
                        if (!mc.isEverythingOkNormal()) show();
                    }
                    else {
                        setVisible(false);
                    }
                }

            }

        });

        JPanel containerPanel = new JPanel();
        containerPanel.setLayout(new BorderLayout());
        JPanel blankPanel = new JPanel();
        blankPanel.setBackground(Color.WHITE);
        containerPanel.add(problemsList,BorderLayout.NORTH);
        containerPanel.add(blankPanel,BorderLayout.CENTER);

        JScrollPane jsp = new JScrollPane(containerPanel,
        JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
        JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

        jsp.setPreferredSize(new Dimension(310,230));
        gbconstants.insets.top = 10;
        this.addComponent(title,gblayout,gbconstants,0,0,2,1);
        gbconstants.insets.top = 20;
        gbconstants.insets.left = -38;
        typeButton = new JButton("Type");
        typeButton.setPreferredSize(new Dimension(100,15));
        this.addComponent(typeButton,gblayout,gbconstants,1,0,1,1);
        descriptionButton = new JButton("Description");
        descriptionButton.setPreferredSize(new Dimension(333,15));
        gbconstants.insets.left = -68;
        this.addComponent(descriptionButton,gblayout,gbconstants,1,1,1,1);
        gbconstants.fill = GridBagConstraints.BOTH;
        gbconstants.insets.top = 0;
        gbconstants.weightx = 1;
        gbconstants.weighty = 1;
        gbconstants.insets.right = 10;
        gbconstants.insets.left = 10;
        this.addComponent(jsp,gblayout,gbconstants,2,0,2,1);
        ButtonEventHandler beh = new ButtonEventHandler();
        continueButton = new JButton("Continue");
        continueButton.setPreferredSize(new Dimension(80,25));
        continueButton.addActionListener(beh);
        cancelButton = new JButton("Cancel");
        cancelButton.setPreferredSize(new Dimension(80,25));
        cancelButton.setSelected(true);
        cancelButton.addActionListener(beh);
        if (isToJMVAConversion) {
            if (!mc.isErrorFreeToJMVA()) continueButton.setEnabled(false);
        }
        else {
            if (!mc.isErrorFreeNormal()) continueButton.setEnabled(false);    
        }
        gbconstants.fill = GridBagConstraints.NONE;
        gbconstants.insets.left = 50;
        this.addComponent(continueButton,gblayout,gbconstants,3,0,1,1);
        gbconstants.insets.right = -45;
        this.addComponent(cancelButton,gblayout,gbconstants,3,1,1,1);
        this.setSize(450,435);
        this.setLocation(300,190);
        this.setModal(true);
        this.setResizable(false);
        this.setFocusableWindowState(false);
    }

    /**
     * create the ProblemElements and insert them into the problems vector
     */
    private void initializeList() {
        if (isToJMVAConversion) {
            if (mc.isThereNoClassesError()) {
                problems.add(new ProblemElement(ModelChecker.ERROR_PROBLEM,ModelChecker.NO_CLASSES_ERROR,"<html><font color=\"white\">----</font><b>Error</b><font color=\"white\">---------</font>No classes defined",null,null));
            }
            if (mc.isThereNoStationError()) {
                problems.add(new ProblemElement(ModelChecker.ERROR_PROBLEM,ModelChecker.NO_STATION_ERROR,"<html><font color=\"white\">----</font><b>Error</b><font color=\"white\">---------</font>No station defined",null,null));
            }
            if (mc.isThereOpenClassButNoSourceError()) {
                problems.add(new ProblemElement(ModelChecker.ERROR_PROBLEM,ModelChecker.OPEN_CLASS_BUT_NO_SOURCE_ERROR,"<html><font color=\"white\">----</font><b>Error</b><font color=\"white\">---------</font>Open class found but no source defined",null,null));
            }
            if (mc.isThereClassesWithoutRefStationError()) {
                Vector temp = mc.getKeysOfClassesWithoutRefStation();
                for (int i=0;i<temp.size();i++) {
                    Object classKey = temp.get(i);
                    String className = mc.getClassModel().getClassName(classKey);
                    problems.add(new ProblemElement(ModelChecker.ERROR_PROBLEM,ModelChecker.REFERENCE_STATION_ERROR,"<html><font color=\"white\">----</font><b>Error</b><font color=\"white\">---------</font>No reference station defined for " + className ,null,classKey));
                }
            }
            /*if (mc.isThereOpenClassReferenceStationError()) {
                Vector openClasses = mc.getKeysOfOpenClassesWithoutRefStation();
                for (int i=0; i<openClasses.size(); i++) {
                    String className = mc.getClassModel().getClassName(openClasses.get(i));
                    problems.add(new ProblemElement(ModelChecker.ERROR_PROBLEM,ModelChecker.OPEN_CLASS_REFERENCE_STATION_ERROR,"<html><font color=\"white\">----</font><b>Error</b><font color=\"white\">---------</font>Open class " + className + " has not a reference station",null,null));
                }
            }*/
            
            /*if (mc.isThereNoExpFoundWarning()) {
                problems.add(new ProblemElement(ModelChecker.WARNING_PROBLEM,ModelChecker.NO_EXP_FOUND_WARNING,"<html><font color=\"white\">--</font><i>Warning</i><font color=\"white\">--------</font>A non-exponential time distribution was found",null,null));
            }
            /*if (mc.isThereDelaysFoundError()) {
                problems.add(new ProblemElement(ModelChecker.ERROR_PROBLEM,ModelChecker.DELAYS_FOUND_ERROR,"      Error             Delays not supported in JModel to JMVA conversion",null,null));
            }*/
            /*if (mc.isThereDifferentServiceTimeWarning()) {
                problems.add(new ProblemElement(ModelChecker.WARNING_PROBLEM,ModelChecker.DIFFERENT_SERVICE_TIME_WARNING,"<html><font color=\"white\">--</font><i>Warning</i><font color=\"white\">--------</font>A station with different mean service time per class was found",null,null));
            }
            if (mc.isThereNonFCFSWarning()) {
                problems.add(new ProblemElement(ModelChecker.WARNING_PROBLEM,ModelChecker.NON_FCFS_WARNING,"<html><font color=\"white\">--</font><i>Warning</i><font color=\"white\">--------</font>A non FCFS queue strategy was found",null,null));
            }*/
            if (mc.isThereBCMPDifferentQueueingStrategyWarning()) {
                Vector temp = mc.getBCMPserversWithDifferentQueueStrategy();
                for (int i=0;i<temp.size();i++) {
                    String thisStation = mc.getStationModel().getStationName(temp.get(i));
                    problems.add(new ProblemElement(ModelChecker.WARNING_PROBLEM,ModelChecker.BCMP_DIFFERENT_QUEUEING_STRATEGIES_WARNING,"<html><font color=\"white\">--</font><i>Warning</i><font color=\"white\">--------</font>Different per class queueing strategy found at " + thisStation,temp.get(i),null));
                }
            }
            if (mc.isThereBCMPDifferentServiceTypeWarning()) {
                Vector temp = mc.getBCMPserversWithDifferentServiceTypes();
                for (int i=0;i<temp.size();i++) {
                    String thisStation = mc.getStationModel().getStationName(temp.get(i));
                    problems.add(new ProblemElement(ModelChecker.WARNING_PROBLEM,ModelChecker.BCMP_FCFS_DIFFERENT_SERVICE_TYPES_WARNING,"<html><font color=\"white\">--</font><i>Warning</i><font color=\"white\">--------</font>Non uniform service strategy inside FCFS station " + thisStation,temp.get(i),null));
                }
            }
            if (mc.isThereBCMPFcfsNonExponentialWarning()) {
                Vector temp = mc.getBCMPserversFCFSWithoutExponential();
                for (int i=0;i<temp.size();i++) {
                    String thisStation = mc.getStationModel().getStationName(temp.get(i));
                    problems.add(new ProblemElement(ModelChecker.WARNING_PROBLEM,ModelChecker.BCMP_FCFS_EXPONENTIAL_WARNING,"<html><font color=\"white\">--</font><i>Warning</i><font color=\"white\">--------</font>Non exponential service time inside FCFS station " + thisStation,temp.get(i),null));
                }
            }
            if (mc.isThereBCMPFcfsDifferentServiceTimesWarning()) {
                Vector temp = mc.getBCMPFcfsServersWithDifferentServiceTimes();
                for (int i=0;i<temp.size();i++) {
                    String thisStation = mc.getStationModel().getStationName(temp.get(i));
                    problems.add(new ProblemElement(ModelChecker.WARNING_PROBLEM,ModelChecker.BCMP_FCFS_DIFFERENT_SERVICE_TIMES_WARNING,"<html><font color=\"white\">--</font><i>Warning</i><font color=\"white\">--------</font>Different service times inside FCFS station " + thisStation,temp.get(i),null));
                }
            }
            if (mc.isThereBCMPDelayWarning()) {
                Vector temp = mc.getBCMPdelaysWithNonRationalServiceDistribution();
                for (int i=0;i<temp.size();i++) {
                    String thisStation = mc.getStationModel().getStationName(temp.get(i));
                    problems.add(new ProblemElement(ModelChecker.WARNING_PROBLEM,ModelChecker.BCMP_FCFS_EXPONENTIAL_WARNING,"<html><font color=\"white\">--</font><i>Warning</i><font color=\"white\">--------</font>" + thisStation + " with non valid service time distribution",temp.get(i),null));
                }

⌨️ 快捷键说明

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