/* * DijkstraApplet.java * * Created on 19 de Junho de 2003, 09:53 */ package graph.applet; import graph.*; import graph.spath.*; /** * * @author unknown */ public class DijkstraApplet extends javax.swing.JApplet { GraphTable gt = new GraphTable(sample()); /** Creates new form DijkstraApplet */ public DijkstraApplet() { initComponents(); gTable.setModel(gt); } private Graph sample() { Vertex s = new Vertex("s"), t = new Vertex("t"), x = new Vertex("x"), y = new Vertex("y"), z = new Vertex("z"); Edge[] es = {new Edge(s, t, 10), new Edge(s, y, 5)}, et = {new Edge(t, x, 1), new Edge(t, y, 2)}, ex = {new Edge(x, z, 4)}, ey = {new Edge(y, t, 3), new Edge(y, x, 9), new Edge(y, z, 2)}, ez = {new Edge(z, s, 7), new Edge(z, x, 6)}; s.setEdges(es); t.setEdges(et); x.setEdges(ex); y.setEdges(ey); z.setEdges(ez); Graph g = new Graph(); g.addVertex(s); g.addVertex(t); g.addVertex(x); g.addVertex(y); g.addVertex(z); return g; } public void executeDijkstra(heap.MinimumHeap h) { Graph g = gt.getGraph(); Dijkstra dj = new Dijkstra(g, g.getVertex(0), h); dj.setOutput(rMessage); rTable.setModel(new GraphTable(dj.shortestPath())); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ private void initComponents()//GEN-BEGIN:initComponents { gPanel = new javax.swing.JPanel(); cPanel = new javax.swing.JPanel(); cLabel = new javax.swing.JLabel(); cField = new javax.swing.JTextField(); cButton = new javax.swing.JButton(); cScroll = new javax.swing.JScrollPane(); gTable = new javax.swing.JTable(); rPanel = new javax.swing.JPanel(); dPanel = new javax.swing.JPanel(); dLabel = new javax.swing.JLabel(); bButton = new javax.swing.JButton(); wButton = new javax.swing.JButton(); wbButton = new javax.swing.JButton(); rScrollTable = new javax.swing.JScrollPane(); rTable = new javax.swing.JTable(); rScrollMessage = new javax.swing.JScrollPane(); rMessage = new javax.swing.JTextArea(); getContentPane().setLayout(new java.awt.GridLayout(2, 0)); gPanel.setLayout(new java.awt.BorderLayout()); cLabel.setText("N\u00famero v\u00e9rtices"); cPanel.add(cLabel); cField.setColumns(3); cField.setText("5"); cPanel.add(cField); cButton.setText("Criar grafo vazio"); cButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { emptySourceGraph(evt); } }); cPanel.add(cButton); gPanel.add(cPanel, java.awt.BorderLayout.NORTH); cScroll.setViewportView(gTable); gPanel.add(cScroll, java.awt.BorderLayout.CENTER); getContentPane().add(gPanel); rPanel.setLayout(new java.awt.BorderLayout()); dLabel.setText("Heap p/ Dijkstra"); dPanel.add(dLabel); bButton.setText("Bin\u00e1rio"); bButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { executeBinario(evt); } }); dPanel.add(bButton); wButton.setText("Vetor W"); wButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { executeVectorW(evt); } }); dPanel.add(wButton); wbButton.setText("Misto"); wbButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { executeMix(evt); } }); dPanel.add(wbButton); rPanel.add(dPanel, java.awt.BorderLayout.NORTH); rTable.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { {null, null, null, null}, {null, null, null, null}, {null, null, null, null}, {null, null, null, null} }, new String [] { "Title 1", "Title 2", "Title 3", "Title 4" } )); rScrollTable.setViewportView(rTable); rPanel.add(rScrollTable, java.awt.BorderLayout.CENTER); rMessage.setRows(3); rScrollMessage.setViewportView(rMessage); rPanel.add(rScrollMessage, java.awt.BorderLayout.SOUTH); getContentPane().add(rPanel); }//GEN-END:initComponents private void emptySourceGraph(java.awt.event.ActionEvent evt)//GEN-FIRST:event_emptySourceGraph {//GEN-HEADEREND:event_emptySourceGraph char c = 'a'; int nv = Integer.parseInt(cField.getText()); if (nv > 0) { String vl[] = new String[nv]; for (int i = 0; i < nv; i++) { vl[i] = "" + c; c++; } gt = new GraphTable(vl); gTable.setModel(gt); } }//GEN-LAST:event_emptySourceGraph private void executeMix(java.awt.event.ActionEvent evt)//GEN-FIRST:event_executeMix {//GEN-HEADEREND:event_executeMix executeDijkstra(new heap.WBinaryHeap(gt.getGraph().getMaximumWeight())); }//GEN-LAST:event_executeMix private void executeVectorW(java.awt.event.ActionEvent evt)//GEN-FIRST:event_executeVectorW {//GEN-HEADEREND:event_executeVectorW executeDijkstra(new heap.WHeap(gt.getGraph().getMaximumWeight())); }//GEN-LAST:event_executeVectorW private void executeBinario(java.awt.event.ActionEvent evt)//GEN-FIRST:event_executeBinario {//GEN-HEADEREND:event_executeBinario executeDijkstra(new heap.BinaryHeap()); }//GEN-LAST:event_executeBinario // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JScrollPane cScroll; private javax.swing.JTextField cField; private javax.swing.JButton cButton; private javax.swing.JButton wButton; private javax.swing.JButton wbButton; private javax.swing.JLabel dLabel; private javax.swing.JPanel gPanel; private javax.swing.JTextArea rMessage; private javax.swing.JTable gTable; private javax.swing.JPanel rPanel; private javax.swing.JPanel cPanel; private javax.swing.JPanel dPanel; private javax.swing.JScrollPane rScrollTable; private javax.swing.JButton bButton; private javax.swing.JScrollPane rScrollMessage; private javax.swing.JTable rTable; private javax.swing.JLabel cLabel; // End of variables declaration//GEN-END:variables }