Example usage for java.awt.event MouseListener MouseListener

List of usage examples for java.awt.event MouseListener MouseListener

Introduction

In this page you can find the example usage for java.awt.event MouseListener MouseListener.

Prototype

MouseListener

Source Link

Usage

From source file:Form.Principal.java

public void PanelUsuarios() {
    int i = 0;// w w  w.  j a v a  2s.c  om
    int Altura = 0;
    Color gris = new Color(44, 44, 44);
    Color azul = new Color(0, 153, 255);
    Color rojo = new Color(221, 76, 76);
    try {
        //Consultamos todos los clientes
        ResultSet Comandos = Funcion.Select(st, "SELECT * FROM usuarios where Tipo!='Administrador';");
        //Ciclo para crear un panel para cada uno
        while (Comandos.next()) {
            //Creamos un panel con alineacion a la izquierda
            JPanel Panel = new JPanel();
            Panel.setLayout(null);
            jPanel12.add(Panel);
            //Tamao del panel
            Panel.setSize(500, 200);
            // La posicion y del panel ira incrementando para que no se encimen
            Altura = 40 + (i * 220);
            Panel.setLocation(175, Altura);
            Panel.setBackground(Color.white);
            Panel.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
            //Creamos label para mostrar los datos del cliente, el codigo html es para que al llegar al final del panel
            //se pase a la siguiente linea y para el margen izquierdo
            JLabel Foto = new JLabel();
            Foto.setSize(150, 150);
            File FotoPerfil = new File("Imagenes/Fotos Perfil/" + Comandos.getInt("id") + ".png");
            File FotoPerfil2 = new File("Imagenes/Fotos Perfil/" + Comandos.getInt("id") + ".jpg");
            if (FotoPerfil.exists()) {
                ImageIcon Imagen = new ImageIcon("Imagenes/Fotos Perfil/" + Comandos.getInt("id") + ".png");
                Image ImagenEscalada = Imagen.getImage().getScaledInstance(Foto.getWidth(), Foto.getHeight(),
                        Image.SCALE_SMOOTH);
                Icon IconoEscalado = new ImageIcon(ImagenEscalada);
                Foto.setIcon(IconoEscalado);
            } else if (FotoPerfil2.exists()) {
                ImageIcon Imagen = new ImageIcon("Imagenes/Fotos Perfil/" + Comandos.getInt("id") + ".jpg");
                Image ImagenEscalada = Imagen.getImage().getScaledInstance(Foto.getWidth(), Foto.getHeight(),
                        Image.SCALE_SMOOTH);
                Icon IconoEscalado = new ImageIcon(ImagenEscalada);
                Foto.setIcon(IconoEscalado);
            } else {
                ImageIcon Imagen = new ImageIcon(getClass().getResource("/Imagen/Default.png"));
                Image ImagenEscalada = Imagen.getImage().getScaledInstance(Foto.getWidth(), Foto.getHeight(),
                        Image.SCALE_SMOOTH);
                Icon IconoEscalado = new ImageIcon(ImagenEscalada);
                Foto.setIcon(IconoEscalado);
            }
            JLabel Nombre = new JLabel();
            Nombre.setText("Nombre de Usuario: " + Comandos.getString("Nombre"));
            JLabel Contrasena = new JLabel();
            Contrasena.setText(("Contrasea: " + Comandos.getString("contrasena")));
            JButton Editar = new JButton();
            Editar.setText("Editar");
            Editar.setName(Comandos.getString("id"));
            Editar.setBackground(azul);
            JButton Eliminar = new JButton();
            Eliminar.setText("Eliminar");
            Eliminar.setName(Comandos.getString("id"));
            Eliminar.setBackground(rojo);
            MouseListener mlEditar = new MouseListener() {
                @Override
                public void mouseReleased(MouseEvent e) {
                    //System.out.println("Released!");
                }

                @Override
                public void mousePressed(MouseEvent e) {
                    //System.out.println("Pressed!");
                }

                @Override
                public void mouseExited(MouseEvent e) {
                    //System.out.println("Exited!");
                }

                @Override
                public void mouseEntered(MouseEvent e) {
                    //System.out.println("Entered!");
                }

                @Override
                public void mouseClicked(MouseEvent e) {
                    presionadoactual = 24;
                    Color azul = new Color(0, 182, 230);
                    jButton24.setBackground(azul);
                    JButton source = (JButton) e.getSource();
                    System.out.println(source.getName());
                    jPanel17.setVisible(false);
                    jButton30.setLocation(470, 480);
                    jButton31.setLocation(270, 480);
                    jLabel2.setToolTipText(null);
                    jTabbedPane2.setSelectedIndex(5);
                    editando = true;
                    PerfilUsuario(Integer.parseInt(source.getName()));
                    Color gris = new Color(44, 44, 44);
                    jButton4.setBackground(gris);
                }
            };
            MouseListener mlEliminar = new MouseListener() {
                @Override
                public void mouseReleased(MouseEvent e) {
                    //System.out.println("Released!");
                }

                @Override
                public void mousePressed(MouseEvent e) {
                    //System.out.println("Pressed!");
                }

                @Override
                public void mouseExited(MouseEvent e) {
                    //System.out.println("Exited!");
                }

                @Override
                public void mouseEntered(MouseEvent e) {
                    //System.out.println("Entered!");
                }

                @Override
                public void mouseClicked(MouseEvent e) {
                    JButton source = (JButton) e.getSource();
                    System.out.println(source.getName());
                    Funcion.Update(st, "DELETE FROM usuarios WHERE id = " + source.getName() + ";");
                    jPanel12.removeAll();
                    PanelUsuarios();
                    jPanel12.repaint();
                }
            };
            Editar.addMouseListener(mlEditar);
            Eliminar.addMouseListener(mlEliminar);
            //Fuente del texto;
            Nombre.setFont(new Font("Verdana", Font.PLAIN, 15));
            Nombre.setForeground(gris);
            Contrasena.setFont(new Font("Verdana", Font.PLAIN, 15));
            Contrasena.setForeground(gris);
            Editar.setFont(new Font("Verdana", Font.PLAIN, 15));
            Editar.setForeground(Color.white);
            Eliminar.setFont(new Font("Verdana", Font.PLAIN, 15));
            Eliminar.setForeground(Color.white);
            //Aadimos los label al panel correspondiente del cliente
            Panel.add(Foto);
            Panel.add(Nombre);
            Panel.add(Contrasena);
            Panel.add(Editar);
            Panel.add(Eliminar);
            Foto.setLocation(10, 20);
            Nombre.setLocation(170, 30);
            Nombre.setSize(300, 45);
            Contrasena.setLocation(170, 60);
            Contrasena.setSize(300, 45);
            Editar.setLocation(170, 100);
            Editar.setSize(120, 40);
            Eliminar.setLocation(315, 100);
            Eliminar.setSize(120, 40);
            i++;
        }
    } catch (SQLException ex) {
        Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
    }
    //Dependiendo de cuantos clientes se agregaron, se ajusta el tamao del panel principal para que el scroll llegue hasta ahi
    jPanel12.setPreferredSize(new Dimension(jPanel12.getWidth(), Altura + 150));

}

From source file:Form.Principal.java

public void PanelFacturas() {
    int i = 0;/*  www. j ava  2 s.co  m*/
    int Altura = 0;
    Color gris = new Color(44, 44, 44);
    Color azul = new Color(0, 153, 255);
    Color rojo = new Color(221, 76, 76);
    try {
        //Consultamos todos los clientes
        ResultSet Comandos = Funcion.Select(st,
                "SELECT factura_emitida.*, cliente.*  FROM cliente,factura_emitida  WHERE factura_emitida.idCliente = cliente.idCliente;");
        //Ciclo para crear un panel para cada uno
        while (Comandos.next()) {
            Variables.Comentario = Comandos.getString("Observaciones");
            //Creamos un panel con alineacion a la izquierda
            JPanel Panel = new JPanel();
            Panel.setLayout(null);
            jPanel11.add(Panel);
            //Tamao del panel
            Panel.setSize(680, 200);
            // La posicion y del panel ira incrementando para que no se encimen
            Altura = 30 + (i * 250);
            Panel.setLocation(50, Altura);
            Panel.setBackground(Color.white);
            Panel.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
            //Creamos label para mostrar los datos del cliente, el codigo html es para que al llegar al final del panel
            //se pase a la siguiente linea y para el margen izquierdo

            JLabel FolioFactura = new JLabel();
            FolioFactura.setText("Folio de factura: " + Comandos.getString("idFacturaEmitida"));
            JLabel RFC = new JLabel();
            RFC.setText("RFC: " + Comandos.getString("RFC"));
            JLabel Nombre = new JLabel();
            Nombre.setText("Nombre: " + Comandos.getString("NombreCliente"));
            JLabel Direccion = new JLabel();
            Direccion.setText("Direccion: " + Comandos.getString("Direccion"));
            JLabel Correo = new JLabel();
            Correo.setText("Correo: " + Comandos.getString("correo"));
            JLabel Fecha = new JLabel();
            Fecha.setText("Fecha y Hora de emisin: " + Comandos.getString("FechaEmision"));

            JButton Abre = new JButton();
            Abre.setText("Abrir");
            Abre.setName(Comandos.getString("idFacturaEmitida"));
            Abre.setBackground(azul);
            JButton Cancelar = new JButton();
            Cancelar.setText("Cancelar");
            Cancelar.setName(Comandos.getString("idFacturaEmitida"));
            Cancelar.setBackground(rojo);
            MouseListener mlAbre = new MouseListener() {
                @Override
                public void mouseReleased(MouseEvent e) {
                    //System.out.println("Released!");
                }

                @Override
                public void mousePressed(MouseEvent e) {
                    //System.out.println("Pressed!");
                }

                @Override
                public void mouseExited(MouseEvent e) {
                    //System.out.println("Exited!");
                }

                @Override
                public void mouseEntered(MouseEvent e) {
                    //System.out.println("Entered!");
                }

                @Override
                public void mouseClicked(MouseEvent e) {
                    try {
                        JButton source = (JButton) e.getSource();
                        idFacClien = Integer.parseInt(source.getName());
                        ResultSet Comandos = Funcion.Select(st,
                                "SELECT *FROM factura_emitida  WHERE idfacturaEmitida=" + idFacClien + ";");
                        while (Comandos.next()) {
                            Variables.FechaFactura = Comandos.getString("FechaEmision");
                            Variables.FechaSistema = Comandos.getString("fechasistema");
                            Variables.idFactura = Comandos.getInt("idFacturaEmitida");
                        }
                        Consulta();
                        Variables.guardar = false;
                        NuevoPdf pdf = new NuevoPdf("Factura.pdf");
                        pdf.main();
                        File myfile = new File("Factura.pdf");
                        Desktop.getDesktop().open(myfile);
                        Comandos = Funcion.Select(st, "SELECT * FROM factura_emitida;");
                        try {
                            if (Comandos.next()) {
                                Comandos.last();
                                Variables.idFactura = Comandos.getInt("idFacturaEmitida") + 1;
                            } else {
                                Variables.idFactura = 1;
                            }
                        } catch (SQLException ex) {
                            Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    } catch (Exception ex) {
                        Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            };
            MouseListener mlCancelar = new MouseListener() {
                @Override
                public void mouseReleased(MouseEvent e) {
                    //System.out.println("Released!");
                }

                @Override
                public void mousePressed(MouseEvent e) {
                    //System.out.println("Pressed!");
                }

                @Override
                public void mouseExited(MouseEvent e) {
                    //System.out.println("Exited!");
                }

                @Override
                public void mouseEntered(MouseEvent e) {
                    //System.out.println("Entered!");
                }

                @Override
                public void mouseClicked(MouseEvent e) {
                    JButton source = (JButton) e.getSource();
                    Variables.Cancelar = Integer.parseInt(source.getName());
                    String Comando = "UPDATE factura_emitida SET Observaciones='Factura Cancelada' WHERE idFacturaEmitida="
                            + Variables.Cancelar + ";";
                    Funcion.Update(st, Comando);
                    jPanel11.removeAll();
                    PanelFacturas();
                    jPanel11.repaint();
                }
            };
            Abre.addMouseListener(mlAbre);
            Cancelar.addMouseListener(mlCancelar);
            //Fuente del texto;
            FolioFactura.setFont(new Font("Verdana", Font.PLAIN, 13));
            FolioFactura.setForeground(gris);
            RFC.setFont(new Font("Verdana", Font.PLAIN, 13));
            RFC.setForeground(gris);
            Nombre.setFont(new Font("Verdana", Font.PLAIN, 13));
            Nombre.setForeground(gris);
            Direccion.setFont(new Font("Verdana", Font.PLAIN, 13));
            Direccion.setForeground(gris);
            Correo.setFont(new Font("Verdana", Font.PLAIN, 13));
            Correo.setForeground(gris);
            Fecha.setFont(new Font("Verdana", Font.PLAIN, 13));
            Fecha.setForeground(gris);
            /// Botones
            Abre.setFont(new Font("Verdana", Font.PLAIN, 15));
            Abre.setForeground(Color.white);
            Cancelar.setFont(new Font("Verdana", Font.PLAIN, 15));
            Cancelar.setForeground(Color.white);
            //Aadimos los label al panel correspondiente del cliente
            Panel.add(FolioFactura);
            Panel.add(RFC);
            Panel.add(Nombre);
            Panel.add(Direccion);
            Panel.add(Correo);
            Panel.add(Fecha);
            Panel.add(Abre);

            FolioFactura.setLocation(15, 5);
            FolioFactura.setSize(400, 45);

            RFC.setLocation(15, 25);
            RFC.setSize(400, 45);

            Nombre.setLocation(15, 45);
            Nombre.setSize(500, 45);

            Direccion.setLocation(15, 65);
            Direccion.setSize(650, 45);

            Correo.setLocation(15, 85);
            Correo.setSize(500, 45);

            Fecha.setLocation(15, 105);
            Fecha.setSize(500, 45);
            /// Botones Tamao y localizacion
            if (Variables.Tipo.equalsIgnoreCase("Administrador")) { // Verificamos que sea un Administrador
                Panel.add(Cancelar);
                Abre.setLocation(185, 160);
                Abre.setSize(120, 30);
                Cancelar.setLocation(350, 160);
                Cancelar.setSize(120, 30);

                if (Variables.Comentario.equalsIgnoreCase("Factura Cancelada")) {
                    Cancelar.setVisible(false);
                    Abre.setLocation(290, 160);
                    Abre.setSize(120, 30);
                }

            } else {
                Abre.setLocation(290, 160);
                Abre.setSize(120, 30);
            }

            i++;
        }
    } catch (SQLException ex) {
        Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
    }
    //Dependiendo de cuantos clientes se agregaron, se ajusta el tamao del panel principal para que el scroll llegue hasta ahi
    jPanel11.setPreferredSize(new Dimension(jPanel11.getWidth(), Altura + 300));

}

From source file:src.gui.ItSIMPLE.java

/**
 * @return the planTreeFramePanel//from  w ww. ja  v a 2 s . c  o m
 */
private ItFramePanel getPlanTreeFramePanel() {
    if (planTreeFramePanel == null) {
        planTreeFramePanel = new ItFramePanel(":: Problem Selection", ItFramePanel.NO_MINIMIZE_MAXIMIZE);

        ItTreeNode root = new ItTreeNode("Projects");
        root.setIcon(new ImageIcon("resources/images/projects.png"));
        problemsPlanTreeModel = new DefaultTreeModel(root);
        problemsPlanTree = new JTree(problemsPlanTreeModel);
        problemsPlanTree.setShowsRootHandles(true);
        problemsPlanTree.setCellRenderer(new ItTreeCellRenderer());

        problemsPlanTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
        problemsPlanTree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
            public void valueChanged(javax.swing.event.TreeSelectionEvent e) {
                ItTreeNode selectedNode = (ItTreeNode) problemsPlanTree.getLastSelectedPathComponent();
                if (selectedNode != null && selectedNode.getLevel() == 3) {

                    planAnalysisFramePanel
                            .setTitle(":: Plan Analysis - Problem: " + selectedNode.getUserObject());

                    solveProblemButton.setEnabled(true);
                    setPlannerButton.setEnabled(true);
                    addPlanActionButton.setEnabled(true);
                    importPlanButton.setEnabled(true);
                    planListModel.clear();
                    xmlPlan = null;

                    //clean up reference of plans from database
                    cleanupPlanDatabaseReference();

                    String pddlVersion = pddlButtonsGroup.getSelection().getActionCommand();
                    Element problem = selectedNode.getData();
                    Element domainProject = problem.getDocument().getRootElement();
                    Element xpddlDomain = ToXPDDL.XMLToXPDDLDomain(domainProject, pddlVersion, null);
                    XMLUtilities.printXML(xpddlDomain);

                    //fill the combo box with the existing available planners
                    plannersComboBox.removeAllItems();
                    plannersList.clear();
                    plannerSuggestion.initialPlannerSelection(xpddlDomain, itPlanners);

                    //List<?> planners = itPlanners.getChild("planners").getChildren("planner");

                    plannersComboBox.addItem("-- Supported Planners --");
                    plannersList.add(null);

                    // Supported Planners
                    fillPlannersComboBox(plannerSuggestion.getSuggestedPlanners());
                    plannersComboBox.addItem("All Supported Planners");
                    plannersList.add("allSupportedPlanners");

                    plannersComboBox.addItem(null);
                    plannersList.add(null);

                    plannersComboBox.addItem("-- Discarded Planners --");
                    plannersList.add(null);

                    // Discarded Planners
                    fillPlannersComboBox(plannerSuggestion.getDiscardedPlanners());

                    plannersComboBox.addItem(null);
                    plannersList.add(null);

                    plannersComboBox.addItem("All Planners");
                    plannersList.add("allPlanners");

                    //This item specify/represent the planners that are seceyed/enable for run all
                    plannersComboBox.addItem("My Favorite Planners");
                    plannersList.add("myFavoritePlanners");
                    //plannersComboBox.addItem("All Selected Planners");
                    //plannersList.add("allSelectedPlanners");

                    CheckBoxNode variablesPlanTreeRoot = (CheckBoxNode) variablesPlanTreeModel.getRoot();

                    // delete old tree nodes
                    if (variablesPlanTreeRoot.getChildCount() > 0) {
                        variablesPlanTreeRoot = new CheckBoxNode("Objects");
                        variablesPlanTreeRoot.setIcon(new ImageIcon("resources/images/projects.png"));
                        variablesPlanTreeModel.setRoot(variablesPlanTreeRoot);
                        variablesPlanTreeModel.reload();
                    }

                    //planningProblems         domain
                    List<?> objects = problem.getParentElement().getParentElement().getChild("elements")
                            .getChild("objects").getChildren("object");
                    for (Iterator<?> iter = objects.iterator(); iter.hasNext();) {
                        Element object = (Element) iter.next();

                        CheckBoxNode objectNode = new CheckBoxNode(object.getChildText("name"), object, null,
                                null);
                        objectNode.setIcon(new ImageIcon("resources/images/object.png"));

                        //CheckBoxNode statesNode = new CheckBoxNode("States");
                        //statesNode.setIcon(new ImageIcon("resources/images/state.png"));
                        //variablesPlanTreeModel.insertNodeInto(statesNode, objectNode, objectNode.getChildCount());

                        // add a node for each object attribute
                        // get the object class
                        Element objectClass = null;
                        try {
                            XPath path = new JDOMXPath("project/elements/classes/class[@id='"
                                    + object.getChildText("class") + "']");
                            objectClass = (Element) path.selectSingleNode(object.getDocument());

                        } catch (JaxenException e1) {
                            e1.printStackTrace();
                        }
                        // get the parent classes
                        List<?> parents = XMLUtilities.getClassAscendents(objectClass);

                        // prepares a list of attributes node
                        List<CheckBoxNode> attributes = new ArrayList<CheckBoxNode>();
                        for (Iterator<?> iterator = objectClass.getChild("attributes").getChildren("attribute")
                                .iterator(); iterator.hasNext();) {
                            Element attribute = (Element) iterator.next();

                            if (attribute.getChild("parameters").getChildren().size() == 0) {// not parameterized attributes
                                CheckBoxNode attributeNode = new CheckBoxNode(attribute.getChildText("name"),
                                        attribute, null, null);
                                attributeNode.setIcon(new ImageIcon("resources/images/attribute.png"));
                                attributes.add(attributeNode);
                                //variablesPlanTreeModel.insertNodeInto(attributeNode, attributesNode, attributesNode.getChildCount());
                            }
                        }

                        for (Iterator<?> iterator = parents.iterator(); iterator.hasNext();) {
                            Element parentClass = (Element) iterator.next();
                            for (Iterator<?> iter2 = parentClass.getChild("attributes").getChildren("attribute")
                                    .iterator(); iter2.hasNext();) {
                                Element attribute = (Element) iter2.next();

                                if (attribute.getChild("parameters").getChildren().size() == 0) {// not parameterized attributes
                                    CheckBoxNode attributeNode = new CheckBoxNode(
                                            attribute.getChildText("name"), attribute, null, null);
                                    attributeNode.setIcon(new ImageIcon("resources/images/attribute.png"));
                                    attributes.add(attributeNode);
                                    //variablesPlanTreeModel.insertNodeInto(attributeNode, attributesNode, attributesNode.getChildCount());
                                }

                            }

                        }

                        // only add attributes node if the object has attributes
                        if (attributes.size() > 0) {
                            CheckBoxNode attributesNode = new CheckBoxNode("Attributes");
                            attributesNode.setIcon(new ImageIcon("resources/images/attribute.png"));
                            variablesPlanTreeModel.insertNodeInto(attributesNode, objectNode,
                                    objectNode.getChildCount());

                            for (Iterator<CheckBoxNode> iterator = attributes.iterator(); iterator.hasNext();) {
                                CheckBoxNode attributeNode = iterator.next();
                                variablesPlanTreeModel.insertNodeInto(attributeNode, attributesNode,
                                        attributesNode.getChildCount());
                            }
                        }

                        // if the object node is not a leaf, add it to the tree
                        if (!objectNode.isLeaf()) {
                            variablesPlanTreeModel.insertNodeInto(objectNode, variablesPlanTreeRoot,
                                    variablesPlanTreeRoot.getChildCount());
                        }

                    }
                    variablesPlanTree.expandRow(0);

                } else {
                    //clear the depending areas
                    planAnalysisFramePanel.setTitle(":: Plan Analysis");
                    //setPlannerButton.setEnabled(false);
                    setPlannerButton.setEnabled(true);
                    addPlanActionButton.setEnabled(false);
                    importPlanButton.setEnabled(false);
                    planListModel.clear();
                    xmlPlan = null;

                    //clean up reference of plans from database
                    cleanupPlanDatabaseReference();

                    //fill the combo box with all planners
                    plannersComboBox.removeAllItems();
                    plannersList.clear();

                    List<?> planners = itPlanners.getChild("planners").getChildren("planner");
                    fillPlannersComboBox(planners);

                    plannersComboBox.addItem("All Planners");
                    plannersList.add("allPlanners");

                    //This item specify/represent the planners that are seceyed/enable for run all
                    plannersComboBox.addItem("My Favorite Planners");
                    plannersList.add("myFavoritePlanners");
                    //plannersComboBox.addItem("All Selected Planners");
                    //plannersList.add("allSelectedPlanners");

                    //clear the variables tree, whether necessary
                    CheckBoxNode variablesPlanTreeRoot = (CheckBoxNode) variablesPlanTreeModel.getRoot();
                    if (variablesPlanTreeRoot.getChildCount() > 0) {
                        CheckBoxNode root = new CheckBoxNode("Objects");
                        root.setIcon(new ImageIcon("resources/images/projects.png"));
                        variablesPlanTreeModel.setRoot(root);
                        variablesPlanTreeModel.reload();
                    }
                }
            }
        });
        CheckBoxNode variablesTreeRoot = new CheckBoxNode("Objects");
        variablesTreeRoot.setIcon(new ImageIcon("resources/images/projects.png"));
        variablesPlanTreeModel = new DefaultTreeModel(variablesTreeRoot);
        variablesPlanTree = new JTree(variablesPlanTreeModel);
        variablesPlanTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
        variablesPlanTree.setShowsRootHandles(true);
        variablesPlanTree.setCellRenderer(new CheckBoxNodeRenderer());
        variablesPlanTree.setCellEditor(new CheckBoxNodeEditor(variablesPlanTree));
        variablesPlanTree.setEditable(true);

        ItTreeNode selectionTreeRoot = new ItTreeNode("Selections");
        selectionTreeRoot.setIcon(new ImageIcon("resources/images/projects.png"));
        selectedVariablesPlanTreeModel = new DefaultTreeModel(selectionTreeRoot);
        selectedVariablesPlanTree = new JTree(selectedVariablesPlanTreeModel);
        selectedVariablesPlanTree.getSelectionModel()
                .setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
        // get the selected nodes in variables plan tree and add it to selectedVariablesPlanTree
        variablesPlanTree.addMouseListener(new MouseListener() {

            public void mouseClicked(MouseEvent e) {
                TreePath path = variablesPlanTree.getPathForLocation(e.getX(), e.getY());

                if (path != null) {
                    ItTreeNode root = new ItTreeNode("Selections");
                    root.setIcon(new ImageIcon("resources/images/projects.png"));

                    // get checked nodes
                    Object[] checked = CheckBoxNode
                            .getCheckedNodes((CheckBoxNode) variablesPlanTree.getModel().getRoot());

                    for (int i = 0; i < checked.length; i++) {
                        CheckBoxNode node = (CheckBoxNode) checked[i];

                        if (node.getUserObject().toString().equals("States") || node.getLevel() == 3) {
                            CheckBoxNode objectNode = (node.getLevel() == 3)
                                    ? (CheckBoxNode) node.getParent().getParent()
                                    : (CheckBoxNode) node.getParent();
                            String nodeName = (node.getLevel() == 3)
                                    ? objectNode.getData().getChildText("name") + "."
                                            + node.getData().getChildText("name")
                                    : "States of " + objectNode.getData().getChildText("name");
                            ImageIcon icon = new ImageIcon(
                                    (node.getLevel() == 3) ? "resources/images/attribute.png"
                                            : "resources/images/state.png");

                            ItTreeNode newNode = new ItTreeNode(nodeName, node.getData(), null, null);
                            newNode.setIcon(icon);
                            root.add(newNode);
                        }
                    }

                    selectedVariablesPlanTreeModel.setRoot(root);
                    selectedVariablesPlanTreeModel.reload();
                    selectedVariablesPlanTree.expandRow(0);
                }
            }

            public void mouseEntered(MouseEvent arg0) {
            }

            public void mouseExited(MouseEvent arg0) {
            }

            public void mousePressed(MouseEvent arg0) {
            }

            public void mouseReleased(MouseEvent arg0) {
            }
        });
        selectedVariablesPlanTree.setShowsRootHandles(true);
        selectedVariablesPlanTree.setCellRenderer(new ItTreeCellRenderer());

        // create a main pane
        JPanel mainTreePanel = new JPanel(new BorderLayout());

        //The below approach of put variable selection and problems all together
        // has confused user, so we decided to put variable selection inside the Variable tracking panel
        // tabbed panes with jtrees
        //planTreeTabbedPane = new JTabbedPane();
        //planTreeTabbedPane.addTab("Problems", new JScrollPane(problemsPlanTree));
        //planTreeTabbedPane.addTab("Variables", new JScrollPane(variablesPlanTree));
        //planTreeTabbedPane.addTab("Selected", new JScrollPane(selectedVariablesPlanTree));
        //mainTreePanel.add(planTreeTabbedPane, BorderLayout.CENTER);

        //
        mainTreePanel.add(new JScrollPane(problemsPlanTree), BorderLayout.CENTER);

        // tool panel
        JPanel toolsPanel = new JPanel(new BorderLayout());

        JPanel topPanel = new JPanel();
        JPanel bottonPanel = new JPanel();

        // combobox with planners
        plannersComboBox = new JComboBox();

        // add to the panel
        //toolsPanel.add(plannersComboBox);
        topPanel.add(plannersComboBox, BorderLayout.CENTER);

        // solve problem button
        solveProblemButton = new JButton("Solve", new ImageIcon("resources/images/engine.png"));
        //solveProblemButton.setEnabled(false);
        solveProblemButton.setActionCommand("solve");
        solveProblemButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (solveProblemButton.getActionCommand().equals("solve")) {
                    ItTreeNode selectedNode = (ItTreeNode) problemsPlanTree.getLastSelectedPathComponent();
                    if (selectedNode != null) {
                        stopRunningPlanners = false;
                        forceFinish = false;
                        //Verify selectedNode and solve problems
                        skipPlannerProblemButton.setEnabled(true);
                        solve(selectedNode);

                    }
                } else {
                    if (currentThread.isAlive()) {
                        stopRunningPlanners = true;
                        forceFinish = true;

                        exe.destroyProcess();

                        try {
                            // waits for the thread to return
                            currentThread.join(2000);// 2 seconds time-out
                        } catch (InterruptedException e1) {
                            e1.printStackTrace();
                        }

                        if (currentThread.isAlive()) {
                            currentThread.interrupt();
                        }

                        if (plannerThread != null) {
                            if (plannerThread.isAlive()) {
                                plannerThread.interrupt();
                            }
                        }

                        planSimStatusBar.setText("Status: Planning process stopped.");
                        outputEditorPane.append(">> Planning process stopped.");

                        // changes the button action command
                        solveProblemButton.setActionCommand("solve");
                        solveProblemButton.setText("Solve");
                        solveProblemButton.setIcon(new ImageIcon("resources/images/engine.png"));

                        //changes the Skip Button
                        skipPlannerProblemButton.setEnabled(false);

                    }
                    hideSimProgressBar();
                    simTimeSpent.setText("");

                }
            }

        });

        // skip planner/problem button
        skipPlannerProblemButton = new JButton("Skip", new ImageIcon("resources/images/skip.png"));
        skipPlannerProblemButton.setVisible(false);
        skipPlannerProblemButton.setActionCommand("skip");
        skipPlannerProblemButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                forceFinish = true;
            }
        });

        // add to the panel
        //toolsPanel.add(solveProblemButton);

        /*
        //runAllPlannersButton = new JButton("Run All planners", new ImageIcon("resources/images/edit.png"));
        runAllPlannersButton = new JButton("Run all planners");
        runAllPlannersButton.setToolTipText("Run all available planners");
        runAllPlannersButton.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                ItTreeNode selectedNode = (ItTreeNode)problemsPlanTree.getLastSelectedPathComponent();
                if(selectedNode != null){
                    Element problem = selectedNode.getData();
                    if(problem != null){
                        solveProblemWithAllPlanners(problem.getDocument().getRootElement(), problem);
                    }
                
                }
            }
        });*/

        // set planner button
        //setPlannerButton = new JButton("Settings");
        setPlannerButton = new JButton(new ImageIcon("resources/images/edit.png"));
        setPlannerButton.setEnabled(false);
        setPlannerButton.setToolTipText("Set planner parameters");
        setPlannerButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {

                //get selected planner
                /*List<?> planners =
                   itPlanners.getChild("planners").getChildren("planner");
                Element chosenPlanner =
                   (Element)planners.get(plannersComboBox.getSelectedIndex());*/

                //PlannersSettingsDialog dialog =   new PlannersSettingsDialog(
                //      ItSIMPLE.this, plannersComboBox.getSelectedIndex());
                PlannersSettingsDialog dialog = new PlannersSettingsDialog(ItSIMPLE.this);

                dialog.setVisible(true);
            }

        });

        //toolsPanel.add(setPlannerButton);

        topPanel.add(setPlannerButton, BorderLayout.EAST);
        bottonPanel.add(solveProblemButton);
        bottonPanel.add(skipPlannerProblemButton);
        //bottonPanel.add(runAllPlannersButton);
        toolsPanel.add(topPanel, BorderLayout.NORTH);
        toolsPanel.add(bottonPanel, BorderLayout.SOUTH);

        // add the tools panel to the main panel
        mainTreePanel.add(toolsPanel, BorderLayout.SOUTH);

        planTreeFramePanel.setContent(mainTreePanel, false);
    }

    return planTreeFramePanel;
}

From source file:src.gui.ItSIMPLE.java

/**
 * @return the planListFramePanel//from  w w w . j a v  a  2s  . co  m
 */
private ItFramePanel getPlanListFramePanel() {
    if (planListFramePanel == null) {
        planListFramePanel = new ItFramePanel(":: Plan", ItFramePanel.MINIMIZE_MAXIMIZE);
        planListFramePanel.setParentSplitPane(planDetailsSplitPane);

        planListModel = new DefaultListModel();
        planList = new JList(planListModel);
        planList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                // this is done to enable or disable the remove plan action button
                if (planList.getSelectedIndex() < 0) {
                    removePlanActionButton.setEnabled(false);
                    editPlanActionButton.setEnabled(false);
                } else {
                    removePlanActionButton.setEnabled(true);
                    editPlanActionButton.setEnabled(true);
                }
            }
        });

        planList.addMouseListener(new MouseListener() {
            public void mouseClicked(MouseEvent e) {
                if (planList.getSelectedIndex() > 0 && e.getClickCount() == 2) {
                    editPlanAction.actionPerformed(null);
                }
            }

            public void mouseEntered(MouseEvent arg0) {
            }

            public void mouseExited(MouseEvent arg0) {
            }

            public void mousePressed(MouseEvent arg0) {
            }

            public void mouseReleased(MouseEvent arg0) {
            }

        });

        // initialize the buttons
        addPlanActionButton = new JButton(addPlanAction);
        addPlanActionButton.setToolTipText("Add an action to the plan");

        removePlanActionButton = new JButton(removePlanAction);
        removePlanActionButton.setToolTipText("Remove selected action");

        editPlanActionButton = new JButton(editPlanAction);
        editPlanActionButton.setToolTipText("Edit selected action");

        importPlanButton = new JButton(importPlanAction);
        importPlanButton.setToolTipText("Import plan from xml file");

        exportPlanButton = new JButton(exportPlanAction);
        exportPlanButton.setToolTipText("Export current plan");

        checkPlanValidityButton = new JButton(checkPlanValidity);
        checkPlanValidityButton.setToolTipText(
                "<html>Validate plan with validator VAL <br>(based on the generated PDDL model).</html>");

        //quickEvaluateButton = new JButton(quickEvaluation);
        //quickEvaluateButton.setToolTipText("Quick evaluation of the selected plan");

        //fullEvaluationButton = new JButton(generateEvaluatioReport);
        //fullEvaluationButton.setToolTipText("<html>Full evaluation of the selected plan. <br> Generate a plan evaluation in the planReport. <br> This is restricted to non-time-based domain only.</html>");
        //fullEvaluationButton.setText("");

        addPlanActionButton.setEnabled(false);
        removePlanActionButton.setEnabled(false);
        editPlanActionButton.setEnabled(false);
        checkPlanValidityButton.setEnabled(false);
        //quickEvaluateButton.setEnabled(false);
        //fullEvaluationButton.setEnabled(false);
        importPlanButton.setEnabled(false);
        exportPlanButton.setEnabled(false);

        JToolBar planListToolBar = new JToolBar();
        planListToolBar.add(addPlanActionButton);
        planListToolBar.add(removePlanActionButton);
        planListToolBar.add(editPlanActionButton);
        planListToolBar.addSeparator();
        planListToolBar.add(checkPlanValidityButton);
        //planListToolBar.add(quickEvaluateButton);
        //planListToolBar.add(fullEvaluationButton);
        planListToolBar.addSeparator();
        planListToolBar.add(importPlanButton);
        planListToolBar.add(exportPlanButton);

        JScrollPane listScrollPane = new JScrollPane(planList);

        JPanel listPanel = new JPanel(new BorderLayout());
        listPanel.add(listScrollPane, BorderLayout.CENTER);
        listPanel.add(planListToolBar, BorderLayout.SOUTH);

        planListFramePanel.setContent(listPanel, false);

    }

    return planListFramePanel;
}