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

📄 classespanel.java

📁 一个用于排队系统仿真的开源软件,有非常形象的图象仿真过程!
💻 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.jaba.panels;

import jmt.gui.common.resources.ImageLoader;
import jmt.gui.exact.panels.ForceUpdatablePanel;
import jmt.gui.exact.table.*;
import jmt.gui.exact.utils.ArrayUtils;
import jmt.gui.help.HoverHelp;
import jmt.gui.jaba.JabaConstants;
import jmt.gui.jaba.JabaModel;
import jmt.gui.jaba.JabaWizard;
import jmt.gui.wizard.WizardPanel;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**

 * @author alyf (Andrea Conti)
 * Date: 11-set-2003
 * Time: 23.48.19

 * Adapted to JABA by Zanzottera

 * Heavily bugfixed by Bertoli Marco (31-jan-2006)

 */

/**
 * 1st panel: classes number, names, types and data
 */
public class ClassesPanel extends WizardPanel implements JabaConstants, ForceUpdatablePanel {
    // Added by Bertoli Marco
    private static final int MINCLASSES = 2;
    private static final int MAXCLASSES = 3;
    // end

    private HoverHelp help;
	private static final String helpText = "<html>In this panel you can define the number of stations in the system and their properties.<br><br>" +
	        " To edit values, single-click on the desired cell" +
	        " and start typing.<br> To select classes click or drag on the row headers.<br> <b>For a list of the available operations right-click" +
	        " on the table</b>.<br>" +
	        " Pressing DELETE removes all selected classes from the system.</html>";

	private JabaWizard ew;
	private boolean isLd;
	private int classes;
	private String[] classNames;
	private int[] classTypes;
	private double[] classData;
	private int nameCounter = 1;

	private List classOps;
	private boolean hasDeletes;
	private boolean deleting = false;

	private JSpinner classSpinner = new JSpinner(new SpinnerNumberModel(2, 2, MAX_CLASSES, 1));

	private ClassTable classTable;

	private ChangeListener spinnerListener = new ChangeListener() {
		public void stateChanged(ChangeEvent ce) {
			if (!deleting) updateSizes();
		}
	};

    private AbstractAction deleteClass = new AbstractAction("Delete selected classes") {
        {
            putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0, false));
            putValue(Action.SHORT_DESCRIPTION, "Deletes selected classes from the system");
        }

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

    private AbstractAction deleteOneClass = new AbstractAction("") {
        {
            putValue(Action.SHORT_DESCRIPTION, "Delete This Class");
            putValue(Action.SMALL_ICON, ImageLoader.loadImage("Close"));
        }

        public void actionPerformed(ActionEvent e) {
        }
    };


    private AbstractAction addClass = new AbstractAction("New Class") {
        {
            putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_C,KeyEvent.ALT_MASK));
            putValue(Action.SHORT_DESCRIPTION, "Adds a new Class to Model");
        }

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


	public ClassesPanel(JabaWizard ew) {
		this.ew = ew;
		help = ew.getHelp();
		classOps = new ArrayList();

		sync();

		initComponents();
		makeNames();

	}

	private void sync() {

		hasDeletes = false;
		classOps.clear();

		/* sync status with data object */
		/* arrays are copied to ensure data object consistency is preserved */
		JabaModel data = ew.getData();
		synchronized (data) {
			classes = data.getClasses();
			isLd = data.isLd();
			classNames = ArrayUtils.copy(data.getClassNames());
			classTypes = ArrayUtils.copy(data.getClassTypes());
			classData = ArrayUtils.copy(data.getClassData());


            //NEW
            //@author Stefano Omini
            if (isLd) {
                //if load dependent is no more supported after class changes
                //remove all load dependent stations
                if (!(data.isClosed() && !data.isMultiClass())) {
                    JOptionPane.showMessageDialog(this, "<html><center>jMVA allows Load Dependent stations only for single class closed model. <br> Load Dependent stations will be replaced with Load Independent stations.</center></html>", "Warning", JOptionPane.WARNING_MESSAGE);
                    data.removeLD();
                    isLd = false;
                }
            }
            //end NEW
		}
		classSpinner.setValue(new Integer(classes));
	}

	/**
	 * make up names for null entries
	 */
	private void makeNames() {
		for (int i = 0; i < classNames.length; i++) {
			if (classNames[i] == null) {
                //classNames[i] = "Class" + (++nameCounter);
                //NEW Zanzottera
                // ++nameCounter+1 per avere subito class3; la soluzione precedente immetteva class2 che 

⌨️ 快捷键说明

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