Example usage for javax.swing JTextField setText

List of usage examples for javax.swing JTextField setText

Introduction

In this page you can find the example usage for javax.swing JTextField setText.

Prototype

@BeanProperty(bound = false, description = "the text of this component")
public void setText(String t) 

Source Link

Document

Sets the text of this TextComponent to the specified text.

Usage

From source file:edu.ku.brc.specify.datamodel.busrules.DeterminationBusRules.java

@Override
public void afterFillForm(final Object dataObj) {
    isBlockingChange = false;//  w  ww.j a v a  2  s .co  m
    determination = null;

    if (formViewObj != null && formViewObj.getDataObj() instanceof Determination) {
        determination = (Determination) formViewObj.getDataObj();

        // if determination exists and is new (no key) then set current true if CO has no other dets
        Component currentComp = formViewObj.getControlByName("isCurrent");
        if (determination != null && currentComp != null) {
            if (isNewObject) {
                // It should never be null, but, currently, it does happen.
                // Also, now with Batch ReIdentify is will always be NULL
                if (determination.getCollectionObject() != null) {
                    if (currentComp instanceof ValCheckBox) {
                        if (formViewObj.isCreatingNewObject()) {
                            // Do this instead of setSelected because
                            // this activates the DataChangeListener
                            isBlockingChange = true;
                            ((ValCheckBox) currentComp).doClick();
                            isBlockingChange = false;

                            // Well, if it is already checked then we just checked it to the 'off' state,
                            // so we need to re-check it so it is in the "checked state"
                            // Note: As stated in the comment above the 'doClick' the easiest way to activate
                            // all the change listeners is by simulating a mouse click.
                            // Also keep in mind that the change listener is listening for ActionEvents for the
                            // checkbox instead of ChangeEvents (ChangeEvents cause to many problems).
                            if (!((ValCheckBox) currentComp).isSelected()) {
                                ((ValCheckBox) currentComp).doClick();
                            }

                            Set<Determination> detSet = determination.getCollectionObject().getDeterminations();
                            for (Determination d : detSet) {
                                if (d != determination) {
                                    d.setIsCurrent(false);
                                }
                            }
                        }

                    } else {
                        log.error("IsCurrent not set to true because form control is of unexpected type: "
                                + currentComp.getClass().getName());
                    }
                }
            } else {
                ((ValCheckBox) currentComp).setValue(determination.getIsCurrent(), null);
            }
        }

        Component activeTax = formViewObj.getControlByName("preferredTaxon");
        if (activeTax != null) {
            JTextField activeTaxTF = (JTextField) activeTax;
            activeTaxTF.setFocusable(false);
            if (determination != null && determination.getPreferredTaxon() != null) {
                activeTaxTF.setText(determination.getPreferredTaxon().getFullName());
            } else {
                activeTaxTF.setText("");
            }
        }

        if (formViewObj.getAltView().getMode() != CreationMode.EDIT) {
            // when we're not in edit mode, we don't need to setup any listeners since the user can't change anything
            //log.debug("form is not in edit mode: no special listeners will be attached");
            return;
        }

        Component nameUsageComp = formViewObj.getControlByName("nameUsage");
        if (nameUsageComp instanceof ValComboBox) {
            // XXX this is probably not necessary anymore...
            if (!checkedBlankUsageItem) {
                boolean fnd = false;

                if (nameUsageComp instanceof ValComboBox) {
                    ValComboBox cbx = (ValComboBox) nameUsageComp;
                    if (cbx.getComboBox().getModel() instanceof PickListDBAdapterIFace) {
                        PickListDBAdapterIFace items = (PickListDBAdapterIFace) cbx.getComboBox().getModel();
                        for (PickListItemIFace item : items.getPickList().getItems()) {
                            if (StringUtils.isBlank(item.getValue())) {
                                fnd = true;
                                break;
                            }
                        }
                        if (!fnd) {
                            boolean readOnly = items.getPickList().getReadOnly();
                            if (readOnly) {
                                items.getPickList().setReadOnly(false);
                            }
                            items.addItem("", null);
                            if (readOnly) {
                                items.getPickList().setReadOnly(true);
                            }
                        }
                    }
                }
                checkedBlankUsageItem = true;
            }
            nameUsageComp.setEnabled(true);
        }

        final Component altNameComp = formViewObj.getControlByName("alternateName");
        if (altNameComp != null && determination != null) {
            altNameComp.setEnabled(determination.getTaxon() == null);
        }

        if (currentComp != null && chkbxCL == null) {
            chkbxCL = new ChangeListener() {
                @Override
                public void stateChanged(ChangeEvent e) {
                    adjustIsCurrentCheckbox();
                }
            };

            isCurrentCheckbox = (ValCheckBox) currentComp;
            isCurrentCheckbox.addChangeListener(chkbxCL);
        }
    }
    isNewObject = false;
}

From source file:net.sf.jabref.gui.openoffice.OpenOfficePanel.java

private void showConnectDialog() {

    dialogOkPressed = false;/*from  w w w . j  a v  a 2 s .com*/
    final JDialog cDiag = new JDialog(frame, Localization.lang("Set connection parameters"), true);
    final JTextField ooPath = new JTextField(30);
    JButton browseOOPath = new JButton(Localization.lang("Browse"));
    ooPath.setText(preferences.getOOPath());
    browseOOPath.addActionListener(BrowseAction.buildForDir(ooPath));

    final JTextField ooExec = new JTextField(30);
    JButton browseOOExec = new JButton(Localization.lang("Browse"));
    ooExec.setText(preferences.getExecutablePath());
    browseOOExec.addActionListener(BrowseAction.buildForFile(ooExec));

    final JTextField ooJars = new JTextField(30);
    JButton browseOOJars = new JButton(Localization.lang("Browse"));
    browseOOJars.addActionListener(BrowseAction.buildForDir(ooJars));
    ooJars.setText(preferences.getJarsPath());

    FormBuilder builder = FormBuilder.create()
            .layout(new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref", "pref"));
    if (OS.WINDOWS || OS.OS_X) {
        builder.add(Localization.lang("Path to OpenOffice/LibreOffice directory")).xy(1, 1);
        builder.add(ooPath).xy(3, 1);
        builder.add(browseOOPath).xy(5, 1);
    } else {
        builder.add(Localization.lang("Path to OpenOffice/LibreOffice executable")).xy(1, 1);
        builder.add(ooExec).xy(3, 1);
        builder.add(browseOOExec).xy(5, 1);

        builder.appendColumns("4dlu, pref");
        builder.add(Localization.lang("Path to OpenOffice/LibreOffice library dir")).xy(1, 3);
        builder.add(ooJars).xy(3, 3);
        builder.add(browseOOJars).xy(5, 3);
    }
    builder.padding("5dlu, 5dlu, 5dlu, 5dlu");
    ButtonBarBuilder bb = new ButtonBarBuilder();
    JButton ok = new JButton(Localization.lang("OK"));
    JButton cancel = new JButton(Localization.lang("Cancel"));
    ActionListener tfListener = e -> {
        preferences.updateConnectionParams(ooPath.getText(), ooExec.getText(), ooJars.getText());
        cDiag.dispose();
    };

    ooPath.addActionListener(tfListener);
    ooExec.addActionListener(tfListener);
    ooJars.addActionListener(tfListener);
    ok.addActionListener(e -> {
        preferences.updateConnectionParams(ooPath.getText(), ooExec.getText(), ooJars.getText());
        dialogOkPressed = true;
        cDiag.dispose();
    });

    cancel.addActionListener(e -> cDiag.dispose());

    bb.addGlue();
    bb.addRelatedGap();
    bb.addButton(ok);
    bb.addButton(cancel);
    bb.addGlue();
    bb.padding("5dlu, 5dlu, 5dlu, 5dlu");
    cDiag.getContentPane().add(builder.getPanel(), BorderLayout.CENTER);
    cDiag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
    cDiag.pack();
    cDiag.setLocationRelativeTo(frame);
    cDiag.setVisible(true);

}

From source file:regresiones.EstadisticaDescriptiva.java

private void pintar(JTabbedPane panel1, Double[][] tabla) {
    JPanel panel = new JPanel(new BorderLayout());
    //tabla/*ww w . ja  v  a 2  s . c  om*/
    jtable = new JTable();//creamos la tabla a mostrar
    jtable.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(255, 0, 0), 2, true));
    jtable.setFont(new java.awt.Font("Arial", 1, 14));
    jtable.setColumnSelectionAllowed(true);
    jtable.setCursor(new java.awt.Cursor(java.awt.Cursor.N_RESIZE_CURSOR));
    jtable.setInheritsPopupMenu(true);
    jtable.setMinimumSize(new java.awt.Dimension(80, 80));
    String[] titulos = { "i", "Li", "Ls", "Xi", "Fi", "Fa", "Fr", "Fra", "XiFi", "|Xi-X|Fi", "(Xi-X)^2 Fi" };//los titulos de la tabla
    DefaultTableModel TableModel = new DefaultTableModel(formato(tabla), titulos);
    jtable.setModel(TableModel);

    JScrollPane jScrollPane1 = new JScrollPane();
    jScrollPane1.setViewportView(jtable);
    jtable.getColumnModel().getSelectionModel()
            .setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);

    panel.add(jScrollPane1, BorderLayout.CENTER);
    //campos
    JPanel medidas = new JPanel(new GridLayout(0, 6));

    JLabel etiquetaMax = new JLabel("Maximo");
    JTextField cajaMax = new JTextField();
    cajaMax.setText(MAXIMO + "");
    cajaMax.setEditable(false);

    JLabel etiquetaMin = new JLabel("Minimo");
    JTextField cajaMin = new JTextField();
    cajaMin.setText(MINIMO + "");
    cajaMin.setEditable(false);

    JLabel etiquetaN = new JLabel("N");
    JTextField cajaN = new JTextField();
    cajaN.setText(N + "");
    cajaN.setEditable(false);

    JLabel etiquetaRango = new JLabel("Rango");
    JTextField cajaRango = new JTextField();
    cajaRango.setText(MAXIMO - MINIMO + "");
    cajaRango.setEditable(false);

    JLabel etiquetaIntervalos = new JLabel("Intervalos");
    JTextField cajaIntervalos = new JTextField();
    cajaIntervalos.setText(INTERVALOS + "");
    cajaIntervalos.setEditable(false);

    JLabel etiquetaAmp = new JLabel("Amplitud");
    JTextField cajaAmp = new JTextField();
    cajaAmp.setText(AMPLITUD + "");
    cajaAmp.setEditable(false);

    JLabel etiquetaRamp = new JLabel("Rango Ampliado");
    JTextField cajaRamp = new JTextField();
    cajaRamp.setText(RANGOAMPLIADO + "");
    cajaRamp.setEditable(false);

    JLabel etiquetaDifRam = new JLabel("Dif Rangos");
    JTextField cajaDifRam = new JTextField();
    cajaDifRam.setText(DIFERENCIARANGOS + "");
    cajaDifRam.setEditable(false);

    JLabel etiquetaLIPI = new JLabel("LIPI");
    JTextField cajaLIPI = new JTextField();
    cajaLIPI.setText(LIPI + "");
    cajaLIPI.setEditable(false);

    JLabel etiquetaLSUI = new JLabel("LSUI");
    JTextField cajaLSUI = new JTextField();
    cajaLSUI.setText(LSUI + "");
    cajaLSUI.setEditable(false);

    JLabel etiquetaDM = new JLabel("Desv media");
    JTextField cajaDM = new JTextField();
    cajaDM.setText(DM + "");
    cajaDM.setEditable(false);

    JLabel etiquetaV = new JLabel("Varianza");
    JTextField cajaV = new JTextField();
    cajaV.setText(VARIANZA + "");
    cajaV.setEditable(false);

    JLabel etiquetaDE = new JLabel("Desv estandar");
    JTextField cajaDE = new JTextField();
    cajaDE.setText(DE + "");
    cajaDE.setEditable(false);

    JLabel etiquetaMe = new JLabel("Media");
    JTextField cajaMe = new JTextField();
    cajaMe.setText(MEDIA + "");
    cajaMe.setEditable(false);

    JLabel etiquetaMEDIANA = new JLabel("Mediana");
    JTextField cajaMEDIANA = new JTextField();
    cajaMEDIANA.setText(MEDIANA + "");
    cajaMEDIANA.setEditable(false);

    JLabel etiquetaModa = new JLabel("Moda");
    JTextField cajaModa = new JTextField();
    cajaModa.setText(MODA + "");
    cajaModa.setEditable(false);

    JButton boton = new JButton("Exportar a PDF");
    boton.addActionListener(this);

    medidas.add(etiquetaMax);
    medidas.add(cajaMax);
    medidas.add(etiquetaMin);
    medidas.add(cajaMin);
    medidas.add(etiquetaN);
    medidas.add(cajaN);

    medidas.add(etiquetaRango);
    medidas.add(cajaRango); //Jhony        
    medidas.add(etiquetaIntervalos);
    medidas.add(cajaIntervalos);
    medidas.add(etiquetaAmp);
    medidas.add(cajaAmp);
    medidas.add(etiquetaRamp);
    medidas.add(cajaRamp);
    medidas.add(etiquetaDifRam);
    medidas.add(cajaDifRam);
    medidas.add(etiquetaLIPI); //lipi
    medidas.add(cajaLIPI);

    medidas.add(etiquetaLSUI);
    medidas.add(cajaLSUI);
    medidas.add(etiquetaDM); //DESVIACION MEDIA
    medidas.add(cajaDM);
    medidas.add(etiquetaV); //VARIANZA
    medidas.add(cajaV);
    medidas.add(etiquetaDE); //DESVIACION ESTANDAR
    medidas.add(cajaDE);
    medidas.add(etiquetaMe); //MEDIA
    medidas.add(cajaMe);
    medidas.add(etiquetaMEDIANA); // mediana
    medidas.add(cajaMEDIANA);
    medidas.add(etiquetaModa); //moda
    medidas.add(cajaModa);
    medidas.add(boton);
    //SECCION DE GRAFICAS

    JFreeChart Grafica;
    DefaultCategoryDataset Datos = new DefaultCategoryDataset();
    //Buscar las pociciones de  LI       LS      Fa
    //                         0,1      0,2     0,5
    //agregar los valores a la grafica
    for (int i = 0; i < INTERVALOS; i++) {

        Datos.addValue(tabla[i][3], "frecuencia", tabla[i][1] + " - " + tabla[i][2]);
    }

    Grafica = ChartFactory.createLineChart("Histograma", "Frecuencia", "Li Ls", Datos, PlotOrientation.VERTICAL,
            true, true, false);

    ChartPanel p = new ChartPanel(Grafica);

    // termina seccion de grafica

    panel.add(medidas, BorderLayout.SOUTH);
    //panel.add(jScrollPane1, BorderLayout.CENTER); 
    panel1.addTab("Resultados", panel);
    panel1.addTab("Grafica", p);
}

From source file:Interface.Stats.java

/**
 *
 * @param f /*from w w  w  . j a va 2  s . c o  m*/
 */
private Stats(JFrame f) {
    // On initialise les boutons
    JButton valider = new JButton("Valider");
    JButton retour = new JButton("Retour");
    JComboBox combo = new JComboBox();

    // On initialise et remplit la combobox
    combo.setPreferredSize(new Dimension(400, 30));
    combo.addItem("Nombre de patient par service");
    combo.addItem("Salaire moyen des employs");
    combo.addItem("Nombre d'intervention par mdecin");

    // On initialise les JLabels
    JLabel texte = new JLabel("Veuillez selectionner la requete  envoyer");

    // On change le bouton de forme
    valider.setPreferredSize(new Dimension(200, 30));
    valider.setOpaque(false);
    retour.setPreferredSize(new Dimension(200, 30));
    retour.setOpaque(false);

    // On initialise les Jpanels
    p1 = new JPanel();
    p1.setPreferredSize(new Dimension(600, 100));
    p1.add(texte);
    p1.setOpaque(false);

    p2 = new JPanel();
    p2.add(combo);
    p2.setOpaque(false);

    p4 = new JPanel();
    p4.add(retour);
    p4.add(valider);
    p4.setOpaque(false);

    // Gestion des boutons
    retour.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Accueil.getFenetre(f);
        }
    });

    valider.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            if (combo.getSelectedItem().equals("Nombre de patient par service")) {

                System.out.println(
                        "Nb de patients en REA : " + Connexion.getInstance().nb_malade_services("\"REA\""));
                System.out.println(
                        "Nb de patients en ORL : " + Connexion.getInstance().nb_malade_services("\"ORL\""));
                System.out.println(
                        "Nb de patients en CHG : " + Connexion.getInstance().nb_malade_services("\"CHG\""));

                //      new Camembert(f, Connexion.getInstance().nb_malade_services("\"REA\""), Connexion.getInstance().nb_malade_services("\"ORL\""), Connexion.getInstance().nb_malade_services("\"CHG\""));
                JPanel panel_camemb = Camembert.cCamembert(f,
                        Connexion.getInstance().nb_malade_services("\"REA\""),
                        Connexion.getInstance().nb_malade_services("\"ORL\""),
                        Connexion.getInstance().nb_malade_services("\"CHG\""));
                ;

                f.setContentPane(new ImagePanel(new ImageIcon("fond66.jpg").getImage())); // Met l'image en background
                f.add(p1);
                f.add(p2);
                f.add(p4);
                f.add(panel_camemb);

                f.setVisible(true);

            } else if (combo.getSelectedItem().equals("Salaire moyen des employs")) {
                JLabel jf_doc, jf_inf, jf_emp;
                JTextField jtf_doc, jtf_inf, jtf_emp;
                JPanel p5, p6, p7;

                // On initialise les JF
                jf_doc = new JLabel("Salaire moyen des docteurs");
                jf_inf = new JLabel("Salaire moyen des infirmiers");
                jf_emp = new JLabel("Salaire moyen de tous les employs");

                // On initialise les JTF
                jtf_doc = new JTextField();
                jtf_doc.setPreferredSize(new Dimension(200, 30));
                jtf_doc.setText(Float.toString(Connexion.getInstance().moyenne_salaired()) + " ");

                jtf_inf = new JTextField();
                jtf_inf.setPreferredSize(new Dimension(200, 30));
                jtf_inf.setText(Float.toString((Connexion.getInstance().moyenne_salairei())) + " ");

                jtf_emp = new JTextField();
                jtf_emp.setPreferredSize(new Dimension(160, 30));
                jtf_emp.setText(Float.toString((Connexion.getInstance().moyenne_salaire())) + " ");

                // On cre les JPanels
                p5 = new JPanel();
                p5.add(jf_doc);
                p5.add(jtf_doc);
                p5.setOpaque(false);

                p6 = new JPanel();
                p6.add(jf_inf);
                p6.add(jtf_inf);
                p6.setOpaque(false);

                p7 = new JPanel();
                p7.add(jf_emp);
                p7.add(jtf_emp);
                p7.setOpaque(false);

                f.setContentPane(new ImagePanel(new ImageIcon("fond66.jpg").getImage())); // Met l'image en background
                f.add(p1);
                f.add(p2);
                f.add(p4);
                f.add(p5);
                f.add(p6);
                f.add(p7);

                f.setVisible(true);
                f.setSize(new Dimension(600, 600));
            } else if (combo.getSelectedItem().equals("Nombre d'intervention par mdecin")) {
                ArrayList liste = null;
                try {
                    // ICI !!!!!!!!!!
                    liste = Connexion.getInstance().reporting(
                            "SELECT e.nom , COUNT(d.no_docteur) FROM hospitalisation h, docteur d , employe e WHERE (h.no_docteur= d.no_docteur) AND e.no_employe = d.no_docteur  GROUP BY e.nom");
                } catch (SQLException ex) {
                    Logger.getLogger(Stats.class.getName()).log(Level.SEVERE, null, ex);
                }
                if (liste != null) {
                    JPanel panel_camemb = Camembert.cCamembert(f, liste);

                    f.setContentPane(new ImagePanel(new ImageIcon("fond66.jpg").getImage())); // Met l'image en background
                    f.add(p1);
                    f.add(p2);
                    f.add(p4);
                    f.add(panel_camemb);

                    f.setVisible(true);
                }

            }
        }
    });
}

From source file:ConfigFiles.java

public JPanel addField(JTextField textfield, String text, int nr) {
    textfield.setMaximumSize(new Dimension(340, 25));
    textfield.setPreferredSize(new Dimension(340, 25));
    if (RunnerRepository.getLogs().size() > 0)
        textfield.setText(RunnerRepository.getLogs().get(nr));
    JLabel l1 = new JLabel(text);
    l1.setMaximumSize(new Dimension(80, 20));
    l1.setPreferredSize(new Dimension(80, 20));
    JPanel p721 = new JPanel();
    p721.setBackground(Color.WHITE);
    p721.add(l1);//from w  w  w .ja  va 2 s.  co m
    p721.add(textfield);
    p721.setMaximumSize(new Dimension(800, 28));
    p721.setPreferredSize(new Dimension(800, 28));
    return p721;
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopSuggestionField.java

protected void updateTextRepresentation() {
    disableActionListener = true;/*from   w w w. j  av a2 s. c om*/
    try {
        Object value = comboBox.getSelectedItem();
        comboBox.getEditor().setItem(value);

        JTextField searchEditor = getComboBoxEditorField();
        if (value instanceof ValueWrapper) {
            searchEditor.setText(value.toString());
        }
    } finally {
        disableActionListener = false;
    }
}

From source file:net.sf.jabref.openoffice.OpenOfficePanel.java

private void showConnectDialog() {

    dialogOkPressed = false;//  ww w  .  ja  v  a 2  s . c  o  m
    final JDialog cDiag = new JDialog(frame, Localization.lang("Set connection parameters"), true);
    final JTextField ooPath = new JTextField(30);
    JButton browseOOPath = new JButton(Localization.lang("Browse"));
    ooPath.setText(Globals.prefs.get(JabRefPreferences.OO_PATH));
    browseOOPath.addActionListener(BrowseAction.buildForDir(ooPath));

    final JTextField ooExec = new JTextField(30);
    JButton browseOOExec = new JButton(Localization.lang("Browse"));
    ooExec.setText(Globals.prefs.get(JabRefPreferences.OO_EXECUTABLE_PATH));
    browseOOExec.addActionListener(BrowseAction.buildForFile(ooExec));

    final JTextField ooJars = new JTextField(30);
    JButton browseOOJars = new JButton(Localization.lang("Browse"));
    browseOOJars.addActionListener(BrowseAction.buildForDir(ooJars));
    ooJars.setText(Globals.prefs.get(JabRefPreferences.OO_JARS_PATH));

    DefaultFormBuilder builder = new DefaultFormBuilder(
            new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref", ""));
    if (OS.WINDOWS || OS.OS_X) {
        builder.append(Localization.lang("Path to OpenOffice directory"));
        builder.append(ooPath);
        builder.append(browseOOPath);
        builder.nextLine();
    } else {
        builder.append(Localization.lang("Path to OpenOffice executable"));
        builder.append(ooExec);
        builder.append(browseOOExec);
        builder.nextLine();

        builder.append(Localization.lang("Path to OpenOffice library dir"));
        builder.append(ooJars);
        builder.append(browseOOJars);
        builder.nextLine();
    }

    ButtonBarBuilder bb = new ButtonBarBuilder();
    JButton ok = new JButton(Localization.lang("OK"));
    JButton cancel = new JButton(Localization.lang("Cancel"));
    ActionListener tfListener = (e -> {

        updateConnectionParams(ooPath.getText(), ooExec.getText(), ooJars.getText());
        cDiag.dispose();

    });

    ooPath.addActionListener(tfListener);
    ooExec.addActionListener(tfListener);
    ooJars.addActionListener(tfListener);
    ok.addActionListener(e -> {
        updateConnectionParams(ooPath.getText(), ooExec.getText(), ooJars.getText());
        dialogOkPressed = true;
        cDiag.dispose();
    });

    cancel.addActionListener(e -> cDiag.dispose());

    bb.addGlue();
    bb.addRelatedGap();
    bb.addButton(ok);
    bb.addButton(cancel);
    bb.addGlue();
    builder.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    cDiag.getContentPane().add(builder.getPanel(), BorderLayout.CENTER);
    cDiag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
    cDiag.pack();
    cDiag.setLocationRelativeTo(frame);
    cDiag.setVisible(true);

}

From source file:com.streamhub.StreamHubLicenseGenerator.java

private JPanel createActionsRow() {
    JPanel actionsRow = new JPanel(new FlowLayout());
    File baseFolder = new File(DEFAULT_CUSTOMERS_DIRECTORY);
    JButton generate = new JButton("Generate");
    generate.addActionListener(new ActionListener() {
        @Override/*from   w w  w .j  ava 2s .co m*/
        public void actionPerformed(ActionEvent e) {
            for (JPanel row : macAddressPanels) {
                try {
                    String macAddress = ((JTextField) row.getComponent(1)).getText();
                    if (macAddress.length() > 0) {
                        String startDate = ((JTextField) row.getComponent(3)).getText();
                        String expiryDate = ((JTextField) row.getComponent(5)).getText();
                        String edition = ((JComboBox) row.getComponent(6)).getSelectedItem().toString();
                        macAddress = macAddress.replaceAll("-", ":").trim();
                        String name = ((JTextField) row.getComponent(8)).getText().trim();
                        String numUsers = ((JTextField) row.getComponent(10)).getText();
                        String licenseString = startDate + "-" + expiryDate + "-" + numUsers + "-" + macAddress
                                + "-" + edition + ":" + name;
                        String hashInput = licenseString + USELESS_KEY;
                        MessageDigest m = MessageDigest.getInstance("SHA-512");
                        m.update(hashInput.getBytes(), 0, hashInput.length());
                        String hash = "==" + new BigInteger(1, m.digest()).toString(16) + "==";
                        StringBuilder licenseText = new StringBuilder();
                        licenseText.append("--").append(licenseString).append("--");
                        licenseText.append(CRLF);
                        licenseText.append(hash);
                        licenseText.append(CRLF);
                        System.out.println(name + ":");
                        System.out.println();
                        System.out.println(licenseText);

                        File licenseDir = new File(folderChooser.getSelectedFile(), name);
                        if (!licenseDir.isDirectory() && !licenseDir.exists()) {
                            licenseDir.mkdir();
                        }
                        File licenseFile = new File(licenseDir, "license.txt");
                        System.out.println("writing to " + licenseFile.getAbsolutePath());
                        FileUtils.writeStringToFile(licenseFile, licenseText.toString());
                    }
                } catch (Exception exception) {
                    System.out.println("Could not generate license");
                    exception.printStackTrace();
                }
            }
        }
    });
    final JButton chooseFolder = new JButton("Choose Folder");
    final JTextField folderDisplay = new JTextField(baseFolder.getAbsolutePath());
    folderChooser = new JFileChooser(baseFolder);
    folderChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    folderChooser.setSelectedFile(baseFolder);
    chooseFolder.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (e.getSource() == chooseFolder) {
                int returnVal = folderChooser.showOpenDialog(StreamHubLicenseGenerator.this);

                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    File folder = folderChooser.getSelectedFile();
                    folderDisplay.setText(folder.getAbsolutePath());
                }
            }
        }
    });

    actionsRow.add(folderDisplay);
    actionsRow.add(chooseFolder);
    actionsRow.add(generate);
    return actionsRow;
}

From source file:net.pandoragames.far.ui.swing.dialog.SettingsDialog.java

private void init() {
    this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    this.setLayout(new BoxLayout(this.getContentPane(), BoxLayout.Y_AXIS));
    this.setResizable(false);

    JPanel basePanel = new JPanel();
    basePanel.setLayout(new BoxLayout(basePanel, BoxLayout.Y_AXIS));
    basePanel.setBorder(/* w  ww  . j  a  v a  2 s .  c  o  m*/
            BorderFactory.createEmptyBorder(0, SwingConfig.PADDING, SwingConfig.PADDING, SwingConfig.PADDING));
    registerCloseWindowKeyListener(basePanel);

    // sink for error messages
    MessageLabel errorField = new MessageLabel();
    errorField.setMinimumSize(new Dimension(100, swingConfig.getStandardComponentHight()));
    errorField.setBorder(BorderFactory.createEmptyBorder(1, SwingConfig.PADDING, 2, SwingConfig.PADDING));
    TwoComponentsPanel lineError = new TwoComponentsPanel(errorField,
            Box.createRigidArea(new Dimension(1, swingConfig.getStandardComponentHight())));
    lineError.setAlignmentX(Component.LEFT_ALIGNMENT);
    basePanel.add(lineError);

    // character set
    JLabel labelCharset = new JLabel(swingConfig.getLocalizer().localize("label.default-characterset"));
    labelCharset.setAlignmentX(Component.LEFT_ALIGNMENT);
    basePanel.add(labelCharset);

    JComboBox listCharset = new JComboBox(swingConfig.getCharsetList().toArray());
    listCharset.setAlignmentX(Component.LEFT_ALIGNMENT);
    listCharset.setSelectedItem(swingConfig.getDefaultCharset());
    listCharset.setEditable(true);
    listCharset.setMaximumSize(
            new Dimension(SwingConfig.COMPONENT_WIDTH_MAX, swingConfig.getStandardComponentHight()));

    listCharset.addActionListener(new CharacterSetListener(errorField));
    listCharset.setEditor(new CharacterSetEditor(errorField));
    basePanel.add(listCharset);

    basePanel.add(Box.createRigidArea(new Dimension(1, SwingConfig.PADDING)));

    // select the group selector
    JPanel selectorPanel = new JPanel();
    selectorPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
    selectorPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    // linePattern.setAlignmentX( Component.LEFT_ALIGNMENT );
    JLabel labelSelector = new JLabel(swingConfig.getLocalizer().localize("label.group-ref-indicator"));
    selectorPanel.add(labelSelector);
    JComboBox selectorBox = new JComboBox(FARConfig.GROUPREFINDICATORLIST);
    selectorBox.setSelectedItem(Character.toString(groupReference));
    selectorBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            JComboBox cbox = (JComboBox) event.getSource();
            String indicator = (String) cbox.getSelectedItem();
            groupReference = indicator.charAt(0);
        }
    });
    selectorPanel.add(selectorBox);
    basePanel.add(selectorPanel);

    basePanel.add(Box.createRigidArea(new Dimension(1, SwingConfig.PADDING)));

    // checkbox DO BACKUP
    JCheckBox doBackupFlag = new JCheckBox(swingConfig.getLocalizer().localize("label.create-backup"));
    doBackupFlag.setAlignmentX(Component.LEFT_ALIGNMENT);
    doBackupFlag.setHorizontalTextPosition(SwingConstants.LEADING);
    doBackupFlag.setSelected(replaceForm.isDoBackup());
    doBackupFlag.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent event) {
            doBackup = ItemEvent.SELECTED == event.getStateChange();
            backupFlagEvent = event;
        }
    });
    basePanel.add(doBackupFlag);

    JTextField backupDirPathTextField = new JTextField();
    backupDirPathTextField.setPreferredSize(
            new Dimension(SwingConfig.COMPONENT_WIDTH, swingConfig.getStandardComponentHight()));
    backupDirPathTextField.setMaximumSize(
            new Dimension(SwingConfig.COMPONENT_WIDTH_MAX, swingConfig.getStandardComponentHight()));
    backupDirPathTextField.setText(backupDirectory.getPath());
    backupDirPathTextField.setToolTipText(backupDirectory.getPath());
    backupDirPathTextField.setEditable(false);
    JButton openBaseDirFileChooserButton = new JButton(swingConfig.getLocalizer().localize("button.browse"));
    BrowseButtonListener backupDirButtonListener = new BrowseButtonListener(backupDirPathTextField,
            new BackUpDirectoryRepository(swingConfig, findForm, replaceForm, errorField),
            swingConfig.getLocalizer().localize("label.choose-backup-directory"));
    openBaseDirFileChooserButton.addActionListener(backupDirButtonListener);
    TwoComponentsPanel lineBaseDir = new TwoComponentsPanel(backupDirPathTextField,
            openBaseDirFileChooserButton);
    lineBaseDir.setAlignmentX(Component.LEFT_ALIGNMENT);
    basePanel.add(lineBaseDir);

    basePanel.add(Box.createRigidArea(new Dimension(1, SwingConfig.PADDING)));

    JPanel fileInfoPanel = new JPanel();
    fileInfoPanel
            .setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED),
                    swingConfig.getLocalizer().localize("label.default-file-info")));
    fileInfoPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    fileInfoPanel.setLayout(new BoxLayout(fileInfoPanel, BoxLayout.Y_AXIS));
    JLabel fileInfoLabel = new JLabel(swingConfig.getLocalizer().localize("message.displayed-in-info-column"));
    fileInfoLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
    fileInfoPanel.add(fileInfoLabel);
    fileInfoPanel.add(Box.createHorizontalGlue());
    JRadioButton nothingRadio = new JRadioButton(swingConfig.getLocalizer().localize("label.nothing"));
    nothingRadio.setAlignmentX(Component.LEFT_ALIGNMENT);
    nothingRadio.setActionCommand(SwingConfig.DefaultFileInfo.NOTHING.name());
    nothingRadio.setSelected(swingConfig.getDefaultFileInfo() == SwingConfig.DefaultFileInfo.NOTHING);
    fileInfoOptions.add(nothingRadio);
    fileInfoPanel.add(nothingRadio);
    JRadioButton readOnlyRadio = new JRadioButton(
            swingConfig.getLocalizer().localize("label.read-only-warning"));
    readOnlyRadio.setAlignmentX(Component.LEFT_ALIGNMENT);
    readOnlyRadio.setActionCommand(SwingConfig.DefaultFileInfo.READONLY.name());
    readOnlyRadio.setSelected(swingConfig.getDefaultFileInfo() == SwingConfig.DefaultFileInfo.READONLY);
    fileInfoOptions.add(readOnlyRadio);
    fileInfoPanel.add(readOnlyRadio);
    JRadioButton sizeRadio = new JRadioButton(swingConfig.getLocalizer().localize("label.filesize"));
    sizeRadio.setAlignmentX(Component.LEFT_ALIGNMENT);
    sizeRadio.setActionCommand(SwingConfig.DefaultFileInfo.SIZE.name());
    sizeRadio.setSelected(swingConfig.getDefaultFileInfo() == SwingConfig.DefaultFileInfo.SIZE);
    fileInfoOptions.add(sizeRadio);
    fileInfoPanel.add(sizeRadio);
    JCheckBox showPlainBytesFlag = new JCheckBox(
            "  " + swingConfig.getLocalizer().localize("label.show-plain-bytes"));
    showPlainBytesFlag.setAlignmentX(Component.LEFT_ALIGNMENT);
    showPlainBytesFlag.setHorizontalTextPosition(SwingConstants.LEADING);
    showPlainBytesFlag.setSelected(swingConfig.isShowPlainBytes());
    showPlainBytesFlag.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent event) {
            showBytes = ItemEvent.SELECTED == event.getStateChange();
        }
    });
    fileInfoPanel.add(showPlainBytesFlag);
    JRadioButton lastModifiedRadio = new JRadioButton(
            swingConfig.getLocalizer().localize("label.last-modified"));
    lastModifiedRadio.setAlignmentX(Component.LEFT_ALIGNMENT);
    lastModifiedRadio.setActionCommand(SwingConfig.DefaultFileInfo.LAST_MODIFIED.name());
    lastModifiedRadio
            .setSelected(swingConfig.getDefaultFileInfo() == SwingConfig.DefaultFileInfo.LAST_MODIFIED);
    fileInfoOptions.add(lastModifiedRadio);
    fileInfoPanel.add(lastModifiedRadio);
    basePanel.add(fileInfoPanel);

    // buttons
    JPanel buttonPannel = new JPanel();
    buttonPannel.setAlignmentX(Component.LEFT_ALIGNMENT);
    buttonPannel.setLayout(new FlowLayout(FlowLayout.TRAILING));
    // cancel
    JButton cancelButton = new JButton(swingConfig.getLocalizer().localize("button.cancel"));
    cancelButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            SettingsDialog.this.dispose();
        }
    });
    buttonPannel.add(cancelButton);
    // save
    JButton saveButton = new JButton(swingConfig.getLocalizer().localize("button.save"));
    saveButton.addActionListener(new SaveButtonListener());
    buttonPannel.add(saveButton);
    this.getRootPane().setDefaultButton(saveButton);

    this.add(basePanel);
    this.add(buttonPannel);
    placeOnScreen(swingConfig.getScreenCenter());
}

From source file:ca.uhn.hl7v2.testpanel.ui.conn.Hl7ConnectionPanel.java

private static void chooseKeystore(Component theParentController, JTextField theTextbox) {
    String directory = Prefs.getInstance().getInterfaceHohSecurityKeystoreDirectory();
    directory = StringUtils.defaultString(directory, ".");
    JFileChooser chooser = new JFileChooser(directory);
    chooser.setDialogType(JFileChooser.OPEN_DIALOG);
    chooser.setDialogTitle("Select a Java Keystore");
    int result = chooser.showOpenDialog(theParentController);
    if (result == JFileChooser.APPROVE_OPTION) {
        Prefs.getInstance().setInterfaceHohSecurityKeystoreDirectory(chooser.getSelectedFile().getParent());
        theTextbox.setText(chooser.getSelectedFile().getAbsolutePath());
    }//from   ww w. j av a 2 s  .  com
}