private void zoomAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zoomAllButtonActionPerformed
        int minX = Integer.MAX_VALUE;
        int minY = Integer.MAX_VALUE;
        int maxX = 0;
        int maxY = 0;
        Element minEX = null;
        Element minEY = null;
        Element maxEX = null;
        Element maxEY = null;
        ArrayList<Element> elements = new ArrayList<Element>();
        if (this.graph instanceof PetriNet) {
            PetriNet pn = (PetriNet) this.graph;
            elements = new ArrayList<Element>();
            elements.addAll(pn.getListOfArcs());
            elements.addAll(pn.getListOfPlaces());
            elements.addAll(pn.getListOfResources());
            elements.addAll(pn.getListOfTransitions());
        }
        if (this.graph instanceof PrecedenceGraph) {
            PrecedenceGraph pg = (PrecedenceGraph) this.graph;
            elements = new ArrayList<Element>();
            elements.addAll(pg.getListOfArcs());
            elements.addAll(pg.getListOfNodes());
        }
        for (Element element : elements) {
            if (minX > element.getX()) {
                minX = element.getX();
                minEX = element;
            }
            if (minY > element.getY()) {
                minY = element.getY();
                minEY = element;
            }
            if (maxX < element.getX()) {
                maxX = element.getX();
                maxEX = element;
            }
            if (maxY < element.getY()) {
                maxY = element.getY();
                maxEY = element;
            }
        }
        int graphWidth = maxX - minX;
        int graphHeight = maxY - minY;
        int maxGraphSize = Math.max(graphHeight, graphWidth);
        int minDiagramSize = Math.min(this.diagramScrollPane.getWidth(), this.diagramScrollPane.getHeight());
        double diagramSlant = Math.sqrt((minDiagramSize * minDiagramSize) + (minDiagramSize * minDiagramSize));
        double graphSlant = Math.sqrt((maxGraphSize * maxGraphSize) + (maxGraphSize * maxGraphSize));
        if (graphSlant > diagramSlant) {
            this.diagramPanel.getScaleRatio()[1] = (diagramSlant / graphSlant) - 0.05;
            this.diagramPanel.getScaleRatio()[0] = (diagramSlant / graphSlant) - 0.05;
        } else {
            this.diagramPanel.getScaleRatio()[1] = 1;
            this.diagramPanel.getScaleRatio()[0] = 1;
        }
        this.diagramScrollPane.getViewport().setViewPosition(new java.awt.Point((int)(minX*this.getDiagramPanel().getScaleRatio()[0]),(int)(minY*this.getDiagramPanel().getScaleRatio()[1])));
        repaint();        
    }