public mxGraphComponent gerar() { graph.getModel().beginUpdate(); if (!gerado) { Object fim = graph.insertVertex( parent, null, "Fim", 10 + (colunaatual * DISTANCIAX) + (LARGURA * colunaatual) + Math.round((LARGURA - 70) / 2), 10 + ((nlinhas) * DISTANCIAY) + (ALTURA * nlinhas++), 70, ALTURA, "terminador"); graph.insertEdge(parent, null, getProximaLigacao(), ultimo, fim, "linhaquadrada"); gerado = true; } graph.setAllowDanglingEdges(false); graph.setAutoSizeCells(true); graph.setConnectableEdges(false); graph.getModel().endUpdate(); final mxGraphComponent graphComponent = new mxGraphComponent(graph); graphComponent.setToolTips(true); graphComponent.getViewport().setOpaque(true); graphComponent.getViewport().setBackground(new Color(250, 250, 250)); graphComponent.setGridVisible(true); getContentPane().add(graphComponent); // Handle only mouse click events graphComponent .getGraphControl() .addMouseListener( new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { Object cell = graphComponent.getCellAt(e.getX(), e.getY()); if (cell != null) { JanelaPrincipal.alertarClique((String) ((mxCell) cell).getValue()); } } }); return graphComponent; }
// currently not being used public void fitToSize() { double newScale = 1; Dimension graphSize = graphComponent.getGraphControl().getSize(); Dimension viewPortSize = graphComponent.getViewport().getSize(); int gw = (int) graphSize.getWidth(); int gh = (int) graphSize.getHeight(); if (gw > 0 && gh > 0) { int w = (int) viewPortSize.getWidth(); int h = (int) viewPortSize.getHeight(); newScale = Math.min((double) w / gw, (double) h / gh); } graphComponent.zoom(newScale); }