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

📄 mediator.java

📁 一个用于排队系统仿真的开源软件,有非常形象的图象仿真过程!
💻 JAVA
📖 第 1 页 / 共 5 页
字号:

    public AbstractJmtAction getSaveModel() {
        return saveModel;
    }

    public AbstractJmtAction getSetConnect() {
        return setConnect;
    }

    public AbstractJmtAction getCopyAction() {
        return actionCopy;
    }

    public AbstractJmtAction getCutAction() {
        return actionCut;
    }

    public AbstractJmtAction getSetOptions() {
        return setOptions;
    }

    public AbstractJmtAction getPasteAction() {
        return actionPaste;
    }

    public AbstractJmtAction getSetSelect() {
        return setSelect;
    }

    public AbstractJmtAction getSimulate() {
        return simulate;
    }

    public AbstractJmtAction getSolveAnalitic() {
        return solveAnalitic;
    }

    public AbstractJmtAction getSolveApp() {
        return solveApp;
    }

    public void newModel() {
        resetMouseState();
        if (checkForSave("<html>Save changes before creating a new model?</html>")) return;
        graph = new JmtJGraph(this);
        graph.setModel(new DefaultGraphModel());
        // Sets the cloneable flag to 'false'
        graph.setCloneable(false);
        graph.setGridSize(20);
        graph.setGridVisible(true);
        if (advanced) graph.setBackground(new Color(120, 120, 120));

        graph.addMouseListener(mouseListner);
        graph.addMouseMotionListener(mouseListner);

        //Conti Andrea
        undoProxy.discardAllEdits();
        graph.getModel().addUndoableEditListener(undoProxy);
        //end

        // Bertoli Marco
        // Instantiates a new JMODELModel data structure to store the entire model
        model = new JMODELModel();
        // end

        mainWindow.setGraph(graph);
        closeModel.setEnabled(true);
        saveModel.setEnabled(true);
        saveModelAs.setEnabled(true);
        editMeasures.setEnabled(true);
        // Bertoli Marco
        // Show only insert options on ComponentBar
        mainWindow.getComponentBar().unsetAll();
        mainWindow.getComponentBar().Enable(true);
        mainWindow.getComponentBar().enableSelect(false);
        mainWindow.getComponentBar().enableLink(false);

        // Disables show results button and measure definition, until simulation
        mainWindow.getResultsButton().setSelected(false);
        showResults.setEnabled(false);
        if (resultsWindow != null)
            resultsWindow.dispose();
        resultsWindow = null;

        // Disables cut/copy/delete (leave paste enabled as clipboard is not flushed)
        enableCopyAction(false);
        enableCutAction(false);
        enableDeleteAction(false);
        //end

        // Disables creation of blocking region
        enableAddBlockingRegion(false);

        // Enable the action to perform editing user classes
        editUserClasses.setEnabled(true);
        switchToExactSolver.setEnabled(true);
        // Enables the botton to start simualtion
        simulate.setEnabled(true);
        editSimParams.setEnabled(true);
        editPAParams.setEnabled(true);
        takeScreenShot.setEnabled(true);
        openedArchive = null;
        // Free same resources by forcing a garbage collection
        System.gc();
    }

    /**
     * Opens a model from a data file.
     * <br> Author: Bertoli Marco
     */
    public void openModel() {
        if (checkForSave("<html>Save changes before opening a saved model?</html>")) return;
        JMODELModel tmpmodel = new JMODELModel();
        int state = modelLoader.loadModel(tmpmodel, mainWindow);
        if (state == ModelLoader.SUCCESS || state == ModelLoader.WARNING) {
            resetMouseState();
            // Avoid checkForSave again...
            if (model != null)
                model.resetSaveState();
            newModel();
            // At this point loading was successful, so substitutes old model with loaded one
            model = tmpmodel;
            this.populateGraph();
            mainWindow.getComponentBar().setSelect();
            openedArchive = modelLoader.getSelectedFile();
            // Removes selection
            graph.clearSelection();
            // If model contains results, enable Results Window
            if (model.containsSimulationResults()) {
                if (model.isParametricAnalysisEnabled()) {
                    this.setResultsWindow(new PAResultsWindow(model.getParametricAnalysisModel(),(PAResultsModel)model.getSimulationResults()));
                    showResults.setEnabled(true);
                }
                else{
                    this.setResultsWindow(new ResultsWindow(model.getSimulationResults()));
                    showResults.setEnabled(true);
                }
            }
            model.resetSaveState();
            System.gc();
        }
        else if (state == ModelLoader.FAILURE)
            showErrorMessage(modelLoader.getFailureMotivation());
        // Shows warnings if any
        if (state == ModelLoader.WARNING) {
            new WarningWindow(modelLoader.getLastWarnings(), mainWindow).show();
        }

    }

    public void closeModel() {
        resetMouseState();
        // Checks if there's an old graph to save
        if (checkForSave("<html>Save changes before closing?</html>")) return;

        //clear undo history
        graph.getModel().removeUndoableEditListener(undoProxy);
        undoProxy.discardAllEdits();
        //end
        //graph.setModel(null); //wreaks quite a bit of havoc
        mainWindow.removeGraph();
        graph = null;
        closeModel.setEnabled(false);
        saveModel.setEnabled(false);
        editMeasures.setEnabled(false);
        saveModelAs.setEnabled(false);
        mainWindow.getComponentBar().unsetAll();
        mainWindow.getComponentBar().Enable(false);
        setConnect.setEnabled(false);
        actionCopy.setEnabled(false);
        actionCut.setEnabled(false);
        actionPaste.setEnabled(false);
        actionDelete.setEnabled(false);
        setSelect.setEnabled(false);
        simulate.setEnabled(false);
        solveAnalitic.setEnabled(false);
        solveApp.setEnabled(false);
        editUserClasses.setEnabled(false);
        editMeasures.setEnabled(false);
        switchToExactSolver.setEnabled(false);
        // Disables the botton to start simualtion
        simulate.setEnabled(false);
        editSimParams.setEnabled(false);
        editPAParams.setEnabled(false);
        takeScreenShot.setEnabled(false);
        // Disables show results button and measure definition
        mainWindow.getResultsButton().setSelected(false);
        showResults.setEnabled(false);
        if (resultsWindow != null)
            resultsWindow.dispose();
        resultsWindow = null;
        openedArchive = null;
        // Free same resources by forcing a garbage collection
        System.gc();
    }

    /** Inserts a new cell (vertex) in the desired point into the graph.
     *
     * @param newCell the new cell
     * @param pt point in absolute coordinates in the
     */
    public void InsertCell(Point2D pt, JmtCell newCell) {
        pt = graph.snap(pt);
        Object[] arg = new Object[]{newCell};
        graph.getModel().insert(arg, newCell.setAttributes(pt, graph), null, null, null);
        // Puts new cell on back to go under blocking regions
        graph.getModel().toBack(new Object[]{newCell});
        newCell.resetParent();
        mainWindow.getComponentBar().enableLink(true);
    }

    /** Set the state of mouse listner to select & passes the event to the
     * listner as if press event is generated.
     *
     * @param e
     */
    public void selectAt(MouseEvent e) {
        mainWindow.getComponentBar().setSelect();
        mouseListner.mousePressed(e);
    }

    /**
     * Determines whether this component is enabled. An enabled component
     * can respond to user input and generate events. Components are
     * enabled initially by default. A component may be enabled or disabled by
     * calling its <code>setEnabled</code> method.
     * @return <code>true</code> if the component is enabled,
     * 		<code>false</code> otherwise
     * @since JDK1.0
     */
    public boolean isGraphEnabled() {
        return graph.isEnabled();
    }

    public void graphRequestFocus() {
        graph.requestFocus();
    }

    public int getTolerance() {
        return graph.getTolerance();
    }

    public Rectangle2D fromScreen(Rectangle2D r) {
        return graph.fromScreen(r);
    }

    public Point2D fromScreen(Point2D p) {
        return graph.fromScreen(p);
    }

    /**
     * Returns this graph's graphics context, which lets you draw
     * on a component. Use this method get a <code>Graphics</code> object and
     * then invoke operations on that object to draw on the component.
     * @return this components graphics context
     */
    public Graphics2D getGraphGraphics() {
        //DEK (Federico Granata) 17-11-2003
        return (Graphics2D) graph.getGraphics();
        //end 17-11-2003
//		return mainWindow.getGraphics();
    }


    public CellView getNextViewAt(CellView current, double x, double y) {
        return graph.getNextViewAt(current, x, y);
    }

    /**
     * Returning true signifies the marquee handler has precedence over
     * other handlers, and is receiving subsequent mouse events.
     */
    public boolean isForceMarqueeEvent(MouseEvent e) {
        return ((JmtGraphUI) graph.getUI()).isForceMarqueeEvent(e);
    }

    /**
     * Returns the number of clicks for editing of the graph to start.
     */
    public int getEditClickCount() {
        return graph.getEditClickCount();
    }

    /**
     * Returning true signifies a mouse event on the cell should toggle
     * the selection of only the cell under mouse.
     */
    public boolean isToggleSelectionEvent(MouseEvent e) {
        return ((JmtGraphUI) graph.getUI()).isToggleSelectionEvent(e);
    }

    /**
     * Returns true if the cell is currently selected.
     * @param cell an object identifying a cell
     * @return true if the cell is selected
     */
    public boolean isCellSelected(Object cell) {
        return graph.isCellSelected(cell);
    }

    /**
     * Messaged to update the selection based on a MouseEvent over a
     * particular cell. If the event is a toggle selection event, the
     * cell is either selected, or deselected. Otherwise the cell is
     * selected.
     */
    public void selectCellForEvent(Object cell, MouseEvent e) {
        ((JmtGraphUI) graph.getUI()).selectCellForEvent(cell, e);
    }

    /**
     * Scroll the graph for an event at <code>p</code>.
     */
    public void autoscroll(Point p) {
        JmtGraphUI.autoscroll(graph, p);
    }

    /**
     * Gets the cursor set in the graph. If the graph does
     * not have a cursor set, the cursor of its parent is returned.
     * If no cursor is set in the entire hierarchy,
     * <code>Cursor.DEFAULT_CURSOR</code> is returned.
     */
    public Cursor getGraphCursor() {
        return graph.getCursor();
    }

    /**
     * Sets graph cursor
     * @param cursor to be setted
     */
    public void setGraphCursor(Cursor cursor) {
        graph.setCursor(cursor);
    }

    /**
     * Returns true if the graph is being edited.  The item that is being
     * edited can be returned by getEditingCell().
     */
    public boolean isGraphEditing() {
        return graph.getUI().isEditing(graph);
    }

    /**
     * Returns the given point applied to the grid.
     * @param p a point in screen coordinates.
     * @return the same point applied to the grid.
     */
    public Point2D snap(Point2D p) {
        return graph.snap(p);
    }

    /**
     * Upscale the given point in place, ie.
     * using the given instance.
     * @param p the point to be upscaled
     * @return the upscaled point instance
     */
    public Point2D toScreen(Point2D p) {
        return graph.toScreen(p);

⌨️ 快捷键说明

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