Escolar Documentos
Profissional Documentos
Cultura Documentos
automatas.Automata importacin;
automatas.Arco importacin;
automatas.Estado importacin;
automatas.ListaEstados de importacin;
graphviz.GraphViz importacin;
javax.swing.ImageIcon importacin;
javax.swing.JLabel importacin;
javax.swing.JOptionPane importacin;
/ **
* Clase Encargada de Obtener la imagen del grafo y ponerla en Pantalla
*
*author Marco Alvarez
*author Sebastian Lena
* /
public class DibujarAutomata extiende javax.swing.JFrame {
autmatas Autmatas privado;
/ ** Crea forma nueva DibujarAutomata
* @ Param un Autmatas un Graficar
* /
pblica DibujarAutomata (Autmatas a) {
this.automata = a;
initComponents ();
this.dibujarAutomata ();
Aceptar.requestFocus ();
}
/ ** Este mtodo se llama desde dentro del constructor para
* Inicializar el formulario.
* ADVERTENCIA: NO modifique el cdigo. El contenido de este mtodo
es
* Siempre regenerado por el editor de formularios.
* /
SuppressWarnings ("Sin control")
// <DefaultState editor veces = "colapsado" desc = "cdigo generado">
// GEN-BEGIN: initComponents
initComponents private void () {
jLabelExpReg = new javax.swing.JLabel ();
jTextFieldExpReg = new javax.swing.JTextField ();
Aceptar = new javax.swing.JButton ();
jPanel1 = new javax.swing.JPanel ();
jScrollPane1 = new javax.swing.JScrollPane ();
imagen = new javax.swing.JLabel ();
setTitle ("Grfico Autmatas");
setResizable (false);
jLabelExpReg.setText ("Expresin regular:");
jTextFieldExpReg.setEditable (false);
Aceptar.setText ("Aceptar");
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup (layout.createSequentialGroup ()
.addComponent (jLabelExpReg)
.addPreferredGap
(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent (jTextFieldExpReg,
javax.swing.GroupLayout.PREFERRED_SIZE, 246,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap (javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
);
layout.setVerticalGroup (
layout.createParallelGroup
(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup (layout.createSequentialGroup ()
.addContainerGap ()
.addGroup (layout.createParallelGroup
(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent (jLabelExpReg)
.addComponent (jTextFieldExpReg,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap
(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent (jPanel1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap
(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent (Aceptar)
.addContainerGap (javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
);
pack ();
} // </ Editor veces> // GEN-END: initComponents
void AceptarActionPerformed (evt java.awt.event.ActionEvent) private
{// GEN-PRIMERA: event_AceptarActionPerformed
this.setVisible (false);
} // GEN-LAST: event_AceptarActionPerformed
/ **
* Setea la Expresion Regular Dentro del JTextField
* @ Param texto Expresion Regular
* /
public void setExpresion (String text) {
this.jTextFieldExpReg.setText (texto);
}
/ *
* Metodo Que COLOCA la imagen en el JLabel imagen
* /
void dibujarAutomata privado () {
this.imagen.setIcon (null);
ImageIcon i = null;
i = this.obtenerImagen ();
if (i! = null) {
this.imagen.setIcon (i);
} Else {
JOptionPane.showMessageDialog (this,
"Ha ocurrido inesperado error un!",
"Error", JOptionPane.ERROR_MESSAGE);
volver;
}
this.imagen.setHorizontalAlignment (JLabel.CENTER);
this.imagen.repaint ();
}
/ *
* Metodo Que obtiene la imagen del GraphViz
* /
ImageIcon privado obtenerImagen () {
GraphViz graphviz = new GraphViz ();
Icono ImageIcon;
byte [] imagenBytes;
imagenBytes = graphviz.dibujar (this.generarDot ());
icon = new ImageIcon (imagenBytes);
icono de volver;
}
/ **
* Genera la sintaxis Para La Construccion del autmata MEDIANTE EL
Graphviz
* @ Return Sintaxis Dot
* /
public String generarDot () {
Cadena de cabecera = "dgrafo finite_state_machine {\ n \
trankdir = LR; \ n \ toverlap = escala; \ n";
Nodos String = "\ TNODE [shape = circle]; \ n";
Cadena arcos = "";
Estilos String = "";
ListaEstados ESTADOS = this.automata.getEstados ();
para (e Estado: Estados) {
if (e.isEstadofinal ())
Estilos = "[shape = doublecircle]";
else if (e.isEstadoinicial ())
Estilos = "[label = inicio]";
dems
Estilos = "[shape = circle]";
nodos + = "\ t" + e.getId () + "" + Estilos + "\ n";
para (Arco de ENLACE: e.getEnlaces ()) {
Estado orig = enlace.getOrigen ();
Estado dest = enlace.getDestino ();
Etiqueta String = enlace.getEtiqueta ();