Example usage for javax.swing JOptionPane getRootFrame

List of usage examples for javax.swing JOptionPane getRootFrame

Introduction

In this page you can find the example usage for javax.swing JOptionPane getRootFrame.

Prototype

public static Frame getRootFrame() throws HeadlessException 

Source Link

Document

Returns the Frame to use for the class methods in which a frame is not provided.

Usage

From source file:Main.java

public static Window getParentWindow(Component c) {
    if (c == null) {
        return JOptionPane.getRootFrame();
    } else if (c instanceof Window) {
        return (Window) c;
    }/*from   w w w  .  j  av a 2s . c  o  m*/
    return getParentWindow(c.getParent());
}

From source file:Utils.java

public static Window findWindow(Component c) {
    if (c == null) {
        return JOptionPane.getRootFrame();
    } else if (c instanceof Window) {
        return (Window) c;
    } else {//from www. j  a  v a 2 s .  c om
        return findWindow(c.getParent());
    }
}

From source file:fr.duminy.components.swing.form.JFormPane.java

/**
 * Display this form in a dialog.//from w  ww.  j  a v a2s.  c  o  m
 *
 * @param parentComponent The parent component of the dialog.
 * @return The final value entered by the user in the dialog, or null if it was cancelled.
 */
public B showDialog(Component parentComponent) {
    Window parentWindow;
    if (parentComponent == null) {
        parentWindow = JOptionPane.getRootFrame();
    } else if (parentComponent instanceof Window) {
        parentWindow = (Window) parentComponent;
    } else {
        parentWindow = SwingUtilities.getWindowAncestor(parentComponent);
    }
    final JDialog dialog = new JDialog(parentWindow, title, Dialog.ModalityType.APPLICATION_MODAL);
    dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    dialog.setContentPane(this);
    dialog.setResizable(false);
    setBorder(null);
    final MutableObject<Boolean> validated = new MutableObject<>(false);
    FormListener<B> listener = new FormListener<B>() {
        @Override
        public void formValidated(Form<B> form) {
            validated.setValue(true);
            dialog.dispose();
        }

        @Override
        public void formCancelled(Form<B> form) {
            dialog.dispose();
        }
    };

    try {
        addFormListener(listener);
        dialog.pack();
        dialog.setVisible(true);
        return validated.getValue() ? getValue() : null;
    } finally {
        removeFormListener(listener);
    }
}

From source file:forge.gui.ImportDialog.java

@SuppressWarnings("serial")
public ImportDialog(final String forcedSrcDir, final Runnable onDialogClose) {
    this.forcedSrcDir = forcedSrcDir;

    _topPanel = new FPanel(new MigLayout("insets dialog, gap 0, center, wrap, fill"));
    _topPanel.setOpaque(false);/*from www.  j  a  v  a  2 s .c  o  m*/
    _topPanel.setBackgroundTexture(FSkin.getIcon(FSkinProp.BG_TEXTURE));

    isMigration = !StringUtils.isEmpty(forcedSrcDir);

    // header
    _topPanel.add(new FLabel.Builder().text((isMigration ? "Migrate" : "Import") + " profile data").fontSize(15)
            .build(), "center");

    // add some help text if this is for the initial data migration
    if (isMigration) {
        final FPanel blurbPanel = new FPanel(new MigLayout("insets panel, gap 10, fill"));
        blurbPanel.setOpaque(false);
        final JPanel blurbPanelInterior = new JPanel(
                new MigLayout("insets dialog, gap 10, center, wrap, fill"));
        blurbPanelInterior.setOpaque(false);
        blurbPanelInterior.add(new FLabel.Builder().text("<html><b>What's this?</b></html>").build(),
                "growx, w 50:50:");
        blurbPanelInterior.add(new FLabel.Builder()
                .text("<html>Over the last several years, people have had to jump through a lot of hoops to"
                        + " update to the most recent version.  We hope to reduce this workload to a point where a new"
                        + " user will find that it is fairly painless to update.  In order to make this happen, Forge"
                        + " has changed where it stores your data so that it is outside of the program installation directory."
                        + "  This way, when you upgrade, you will no longer need to import your data every time to get things"
                        + " working.  There are other benefits to having user data separate from program data, too, and it"
                        + " lays the groundwork for some cool new features.</html>")
                .build(), "growx, w 50:50:");
        blurbPanelInterior.add(
                new FLabel.Builder().text("<html><b>So where's my data going?</b></html>").build(),
                "growx, w 50:50:");
        blurbPanelInterior.add(new FLabel.Builder().text(
                "<html>Forge will now store your data in the same place as other applications on your system."
                        + "  Specifically, your personal data, like decks, quest progress, and program preferences will be"
                        + " stored in <b>" + ForgeConstants.USER_DIR
                        + "</b> and all downloaded content, such as card pictures,"
                        + " skins, and quest world prices will be under <b>" + ForgeConstants.CACHE_DIR
                        + "</b>.  If, for whatever"
                        + " reason, you need to set different paths, cancel out of this dialog, exit Forge, and find the <b>"
                        + ForgeConstants.PROFILE_TEMPLATE_FILE
                        + "</b> file in the program installation directory.  Copy or rename" + " it to <b>"
                        + ForgeConstants.PROFILE_FILE
                        + "</b> and edit the paths inside it.  Then restart Forge and use"
                        + " this dialog to move your data to the paths that you set.  Keep in mind that if you install a future"
                        + " version of Forge into a different directory, you'll need to copy this file over so Forge will know"
                        + " where to find your data.</html>")
                .build(), "growx, w 50:50:");
        blurbPanelInterior.add(new FLabel.Builder().text(
                "<html><b>Remember, your data won't be available until you complete this step!</b></html>")
                .build(), "growx, w 50:50:");

        final FScrollPane blurbScroller = new FScrollPane(blurbPanelInterior, true,
                ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        blurbPanel.add(blurbScroller, "hmin 150, growy, growx, center, gap 0 0 5 5");
        _topPanel.add(blurbPanel, "gap 10 10 20 0, growy, growx, w 50:50:");
    }

    // import source widgets
    final JPanel importSourcePanel = new JPanel(new MigLayout("insets 0, gap 10"));
    importSourcePanel.setOpaque(false);
    importSourcePanel.add(new FLabel.Builder().text("Import from:").build());
    _txfSrc = new FTextField.Builder().readonly().build();
    importSourcePanel.add(_txfSrc, "pushx, growx");
    _btnChooseDir = new FLabel.ButtonBuilder().text("Choose directory...").enabled(!isMigration).build();
    final JFileChooser _fileChooser = new JFileChooser();
    _fileChooser.setMultiSelectionEnabled(false);
    _fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    _btnChooseDir.setCommand(new UiCommand() {
        @Override
        public void run() {
            // bring up a file open dialog and, if the OK button is selected, apply the filename
            // to the import source text field
            if (JFileChooser.APPROVE_OPTION == _fileChooser.showOpenDialog(JOptionPane.getRootFrame())) {
                final File f = _fileChooser.getSelectedFile();
                if (!f.canRead()) {
                    FOptionPane.showErrorDialog("Cannot access selected directory (Permission denied).");
                } else {
                    _txfSrc.setText(f.getAbsolutePath());
                }
            }
        }
    });
    importSourcePanel.add(_btnChooseDir, "h pref+8!, w pref+12!");

    // add change handler to the import source text field that starts up a
    // new analyzer.  it also interacts with the current active analyzer,
    // if any, to make sure it cancels out before the new one is initiated
    _txfSrc.getDocument().addDocumentListener(new DocumentListener() {
        boolean _analyzerActive; // access synchronized on _onAnalyzerDone
        String prevText;

        private final Runnable _onAnalyzerDone = new Runnable() {
            @Override
            public synchronized void run() {
                _analyzerActive = false;
                notify();
            }
        };

        @Override
        public void removeUpdate(final DocumentEvent e) {
        }

        @Override
        public void changedUpdate(final DocumentEvent e) {
        }

        @Override
        public void insertUpdate(final DocumentEvent e) {
            // text field is read-only, so the only time this will get updated
            // is when _btnChooseDir does it
            final String text = _txfSrc.getText();
            if (text.equals(prevText)) {
                // only restart the analyzer if the directory has changed
                return;
            }
            prevText = text;

            // cancel any active analyzer
            _cancel = true;

            if (!text.isEmpty()) {
                // ensure we don't get two instances of this function running at the same time
                _btnChooseDir.setEnabled(false);

                // re-disable the start button.  it will be enabled if the previous analyzer has
                // already successfully finished
                _btnStart.setEnabled(false);

                // we have to wait in a background thread since we can't block in the GUI thread
                final SwingWorker<Void, Void> analyzerStarter = new SwingWorker<Void, Void>() {
                    @Override
                    protected Void doInBackground() throws Exception {
                        // wait for active analyzer (if any) to quit
                        synchronized (_onAnalyzerDone) {
                            while (_analyzerActive) {
                                _onAnalyzerDone.wait();
                            }
                        }
                        return null;
                    }

                    // executes in gui event loop thread
                    @Override
                    protected void done() {
                        _cancel = false;
                        synchronized (_onAnalyzerDone) {
                            // this will populate the panel with data selection widgets
                            final _AnalyzerUpdater analyzer = new _AnalyzerUpdater(text, _onAnalyzerDone,
                                    isMigration);
                            analyzer.run();
                            _analyzerActive = true;
                        }
                        if (!isMigration) {
                            // only enable the directory choosing button if this is not a migration dialog
                            // since in that case we're permanently locked to the starting directory
                            _btnChooseDir.setEnabled(true);
                        }
                    }
                };
                analyzerStarter.execute();
            }
        }
    });
    _topPanel.add(importSourcePanel, "gaptop 20, pushx, growx");

    // prepare import selection panel (will be cleared and filled in later by an analyzer)
    _selectionPanel = new JPanel();
    _selectionPanel.setOpaque(false);
    _topPanel.add(_selectionPanel, "growx, growy, gaptop 10");

    // action button widgets
    final Runnable cleanup = new Runnable() {
        @Override
        public void run() {
            SOverlayUtils.hideOverlay();
        }
    };
    _btnStart = new FButton("Start import");
    _btnStart.setEnabled(false);
    _btnCancel = new FButton("Cancel");
    _btnCancel.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            _cancel = true;
            cleanup.run();
            if (null != onDialogClose) {
                onDialogClose.run();
            }
        }
    });

    final JPanel southPanel = new JPanel(new MigLayout("ax center"));
    southPanel.setOpaque(false);
    southPanel.add(_btnStart, "center, w pref+144!, h pref+12!");
    southPanel.add(_btnCancel, "center, w pref+144!, h pref+12!, gap 72");
    _topPanel.add(southPanel, "growx");
}

From source file:com.litt.core.security.license.gui.CustomerPanel.java

public CustomerPanel() {
    GridBagLayout gridBagLayout = new GridBagLayout();
    gridBagLayout.columnWidths = new int[] { 0, 0, 0, 0 };
    gridBagLayout.rowHeights = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    gridBagLayout.columnWeights = new double[] { 0.0, 1.0, 0.0, Double.MIN_VALUE };
    gridBagLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 };
    setLayout(gridBagLayout);/*from w  w w  .j  a v  a2  s.  c  o m*/

    JLabel lblProduct = new JLabel("\u4EA7\u54C1\uFF1A");
    GridBagConstraints gbc_lblProduct = new GridBagConstraints();
    gbc_lblProduct.insets = new Insets(0, 0, 5, 5);
    gbc_lblProduct.anchor = GridBagConstraints.EAST;
    gbc_lblProduct.gridx = 0;
    gbc_lblProduct.gridy = 0;
    add(lblProduct, gbc_lblProduct);

    comboBoxProduct = new JComboBox();
    GridBagConstraints gbc_comboBoxProduct = new GridBagConstraints();
    gbc_comboBoxProduct.insets = new Insets(0, 0, 5, 5);
    gbc_comboBoxProduct.fill = GridBagConstraints.HORIZONTAL;
    gbc_comboBoxProduct.gridx = 1;
    gbc_comboBoxProduct.gridy = 0;
    add(comboBoxProduct, gbc_comboBoxProduct);

    JButton btnRefresh = new JButton("");
    btnRefresh.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            initProduct();
        }
    });
    btnRefresh.setIcon(new ImageIcon(CustomerPanel.class.getResource("/images/icon_refresh.png")));
    GridBagConstraints gbc_btnRefresh = new GridBagConstraints();
    gbc_btnRefresh.insets = new Insets(0, 0, 5, 0);
    gbc_btnRefresh.gridx = 2;
    gbc_btnRefresh.gridy = 0;
    add(btnRefresh, gbc_btnRefresh);

    JLabel lblProductVersion = new JLabel("\u4EA7\u54C1\u7248\u672C\uFF1A");
    GridBagConstraints gbc_lblProductVersion = new GridBagConstraints();
    gbc_lblProductVersion.anchor = GridBagConstraints.EAST;
    gbc_lblProductVersion.insets = new Insets(0, 0, 5, 5);
    gbc_lblProductVersion.gridx = 0;
    gbc_lblProductVersion.gridy = 1;
    add(lblProductVersion, gbc_lblProductVersion);

    textFieldProductVersion = new VersionTextField();
    textFieldProductVersion.setColumns(10);
    GridBagConstraints gbc_textFieldProductVersion = new GridBagConstraints();
    gbc_textFieldProductVersion.anchor = GridBagConstraints.WEST;
    gbc_textFieldProductVersion.insets = new Insets(0, 0, 5, 5);
    gbc_textFieldProductVersion.gridx = 1;
    gbc_textFieldProductVersion.gridy = 1;
    add(textFieldProductVersion, gbc_textFieldProductVersion);

    JLabel lblCompanyName = new JLabel("\u516C\u53F8\u540D\u79F0\uFF1A");
    GridBagConstraints gbc_lblCompanyName = new GridBagConstraints();
    gbc_lblCompanyName.anchor = GridBagConstraints.EAST;
    gbc_lblCompanyName.insets = new Insets(0, 0, 5, 5);
    gbc_lblCompanyName.gridx = 0;
    gbc_lblCompanyName.gridy = 2;
    add(lblCompanyName, gbc_lblCompanyName);

    textFieldCompanyName = new JTextField();
    GridBagConstraints gbc_textFieldCompanyName = new GridBagConstraints();
    gbc_textFieldCompanyName.insets = new Insets(0, 0, 5, 5);
    gbc_textFieldCompanyName.fill = GridBagConstraints.HORIZONTAL;
    gbc_textFieldCompanyName.gridx = 1;
    gbc_textFieldCompanyName.gridy = 2;
    add(textFieldCompanyName, gbc_textFieldCompanyName);
    textFieldCompanyName.setColumns(10);

    JLabel lblCustomerCode = new JLabel("\u5BA2\u6237\u7F16\u53F7\uFF1A");
    GridBagConstraints gbc_lblCustomerCode = new GridBagConstraints();
    gbc_lblCustomerCode.anchor = GridBagConstraints.EAST;
    gbc_lblCustomerCode.insets = new Insets(0, 0, 5, 5);
    gbc_lblCustomerCode.gridx = 0;
    gbc_lblCustomerCode.gridy = 3;
    add(lblCustomerCode, gbc_lblCustomerCode);

    textFieldCustomerCode = new JTextField();
    GridBagConstraints gbc_textFieldCustomerCode = new GridBagConstraints();
    gbc_textFieldCustomerCode.insets = new Insets(0, 0, 5, 5);
    gbc_textFieldCustomerCode.fill = GridBagConstraints.HORIZONTAL;
    gbc_textFieldCustomerCode.gridx = 1;
    gbc_textFieldCustomerCode.gridy = 3;
    add(textFieldCustomerCode, gbc_textFieldCustomerCode);
    textFieldCustomerCode.setColumns(10);

    JLabel lblCustomerName = new JLabel("\u5BA2\u6237\u540D\u79F0\uFF1A");
    GridBagConstraints gbc_lblCustomerName = new GridBagConstraints();
    gbc_lblCustomerName.anchor = GridBagConstraints.EAST;
    gbc_lblCustomerName.insets = new Insets(0, 0, 5, 5);
    gbc_lblCustomerName.gridx = 0;
    gbc_lblCustomerName.gridy = 4;
    add(lblCustomerName, gbc_lblCustomerName);

    textFieldCustomerName = new JTextField();
    GridBagConstraints gbc_textFieldCustomerName = new GridBagConstraints();
    gbc_textFieldCustomerName.insets = new Insets(0, 0, 5, 5);
    gbc_textFieldCustomerName.fill = GridBagConstraints.HORIZONTAL;
    gbc_textFieldCustomerName.gridx = 1;
    gbc_textFieldCustomerName.gridy = 4;
    add(textFieldCustomerName, gbc_textFieldCustomerName);
    textFieldCustomerName.setColumns(10);

    JLabel lblLicenseType = new JLabel("\u8BC1\u4E66\u7C7B\u578B\uFF1A");
    GridBagConstraints gbc_lblLicenseType = new GridBagConstraints();
    gbc_lblLicenseType.anchor = GridBagConstraints.EAST;
    gbc_lblLicenseType.insets = new Insets(0, 0, 5, 5);
    gbc_lblLicenseType.gridx = 0;
    gbc_lblLicenseType.gridy = 5;
    add(lblLicenseType, gbc_lblLicenseType);

    comboBoxLicenseType = new JComboBox();
    GridBagConstraints gbc_comboBoxLicenseType = new GridBagConstraints();
    gbc_comboBoxLicenseType.insets = new Insets(0, 0, 5, 5);
    gbc_comboBoxLicenseType.fill = GridBagConstraints.HORIZONTAL;
    gbc_comboBoxLicenseType.gridx = 1;
    gbc_comboBoxLicenseType.gridy = 5;
    add(comboBoxLicenseType, gbc_comboBoxLicenseType);

    JLabel lblExpiredDate = new JLabel("\u8FC7\u671F\u65F6\u95F4\uFF1A");
    GridBagConstraints gbc_lblExpiredDate = new GridBagConstraints();
    gbc_lblExpiredDate.insets = new Insets(0, 0, 5, 5);
    gbc_lblExpiredDate.gridx = 0;
    gbc_lblExpiredDate.gridy = 6;
    add(lblExpiredDate, gbc_lblExpiredDate);

    datePickerExpiredDate = new DatePicker(new Date(), "yyyy-MM-dd", null, null);
    GridBagConstraints gbc_datePicker = new GridBagConstraints();
    gbc_datePicker.anchor = GridBagConstraints.WEST;
    gbc_datePicker.insets = new Insets(0, 0, 5, 5);
    gbc_datePicker.gridx = 1;
    gbc_datePicker.gridy = 6;
    add(datePickerExpiredDate, gbc_datePicker);

    JButton btnSave = new JButton("\u4FDD\u5B58");
    btnSave.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                //????????
                if (comboBoxProduct.getSelectedIndex() <= 0) {
                    JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "??");
                    return;
                }
                String[] array = StringUtils.split(comboBoxProduct.getSelectedItem().toString(), '-');
                String productCode = array[0];
                String productName = array[1];
                String customerCode = textFieldCustomerCode.getText();

                //??
                File configFile = ResourceUtils.getFile(Gui.HOME_PATH + File.separator + "config.xml");
                Document document = XmlUtils.readXml(configFile);
                Element customerNode = (Element) document.selectSingleNode(
                        "//product[@code='" + productCode + "']/customer[@code='" + customerCode + "']");
                if (customerNode != null) {
                    JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),
                            "???");
                    return;
                }

                String licenseId = new RandomGUID().toString();
                String licenseType = Utility.splitStringAll(comboBoxLicenseType.getSelectedItem().toString(),
                        " - ")[0];
                String companyName = textFieldCompanyName.getText();
                String customerName = textFieldCustomerName.getText();
                String version = textFieldProductVersion.getText();
                Date expiredDate = Utility.parseDate(datePickerExpiredDate.getText());

                License license = new License();
                license.setLicenseId(licenseId);
                license.setLicenseType(licenseType);
                license.setProductName(productName);
                license.setCompanyName(companyName);
                license.setCustomerName(customerName);
                license.setVersion(Version.parseVersion(version));
                license.setCreateDate(new Date());
                license.setExpiredDate(expiredDate);

                LicenseService service = new LicenseService();
                String productPath = Gui.HOME_PATH + File.separator + productCode;
                File licenseDir = new File(productPath, customerCode);
                if (!licenseDir.exists()) {
                    licenseDir.mkdir();
                    //?
                    FileUtils.copyFileToDirectory(new File(productPath, "license.key"), licenseDir);
                }
                File priKeyFile = new File(Gui.HOME_PATH + File.separator + productCode, "private.key");
                File licenseFile = new File(licenseDir, "license.xml");

                service.save(Gui.HOME_PATH, productCode, customerCode, license, priKeyFile, licenseFile);

                //??zip?
                File customerPath = licenseFile.getParentFile();
                //???license?????
                File licensePath = new File(customerPath.getParent(), "license");
                if (!licensePath.exists() && !licensePath.isDirectory()) {
                    licensePath.mkdir();
                } else {
                    FileUtils.cleanDirectory(licensePath);
                }

                //?
                FileUtils.copyDirectory(customerPath, licensePath);

                String currentTime = FormatDateTime.formatDateTimeNum(new Date());
                ZipUtils.zip(licensePath,
                        new File(licensePath.getParentFile(), customerCode + "-" + currentTime + ".zip"));
                //license
                FileUtils.deleteDirectory(licensePath);

                JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "??");
            } catch (Exception e1) {
                e1.printStackTrace();
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), e1.getMessage());
            }

        }
    });
    GridBagConstraints gbc_btnSave = new GridBagConstraints();
    gbc_btnSave.insets = new Insets(0, 0, 5, 5);
    gbc_btnSave.gridx = 1;
    gbc_btnSave.gridy = 7;
    add(btnSave, gbc_btnSave);

    //??
    initData();
}

From source file:com.biosis.biosislite.vistas.AsignarPermiso.java

private void imprimirBoletaViaje(AsignacionPermiso asignacion) {
    File reporte = new File("reportes/permiso_comision-servicios.jasper");

    List<AsignacionPermiso> listadoReporteAsignacion = new ArrayList();
    listadoReporteAsignacion.add(asignacion);

    Map<String, Object> parametros = new HashMap<>();
    parametros.put("reporte_ususario", UsuarioActivo.getUsuario().getLogin());

    Departamento area = asignacion.getEmpleado().getAreaEmpleadoList().get(0).getDepartamento();
    if (area != null) {
        parametros.put("area", area.getNombre());
    }/*from   w w w  .  jav a 2  s  .c  o  m*/

    //        AsignarVacacion vac = new AsignarVacacion();
    long dias = this.fechasAlong(asignacion.getPermiso().getFechaInicio(),
            asignacion.getPermiso().getFechaFin());
    parametros.put("dias", dias);

    //Parametros del viaje
    Viaje viaje = vsc.buscarPorPermiso(asignacion.getPermiso());

    if (viaje != null) {
        parametros.put("alimentacion", viaje.getAlimentacion());
        parametros.put("alojamiento", viaje.getAlojamiento());
        parametros.put("movilidad", viaje.getMovilidad());
        parametros.put("combustible", viaje.getCombustible());
        parametros.put("dias_alimentacion", viaje.getDiasAlimentacion());
        parametros.put("dias_alojamiento", viaje.getDiasAlojamiento());
        parametros.put("dias_movilidad", viaje.getDiasMovLocal());
        //            if (asignacion.getEmpleado().getAreaEmpleadoList().get(0).getDepartamento().getDepartamento().getNombre() != null) {
        //                parametros.put("gerencia", asignacion.getEmpleado().getAreaEmpleadoList().get(0).getDepartamento().getDepartamento().getNombre());
        //            } else {
        parametros.put("gerencia",
                asignacion.getEmpleado().getAreaEmpleadoList().get(0).getGerencia().getNombre());
        //            }
        parametros.put("centro_costo", viaje.getCentroCosto());
        parametros.put("ubigeo", viaje.getDestino());
        parametros.put("cargo", asignacion.getEmpleado().getPuestoList().get(0).getPuesto().getNombre());

        double total = (viaje.getAlimentacion() * viaje.getDiasAlimentacion())
                + (viaje.getAlojamiento() * viaje.getDiasAlojamiento())
                + (viaje.getMovilidad() * viaje.getDiasMovLocal()) + viaje.getCombustible();

        parametros.put("total", total);
    }

    //Fin de parametros del viaje
    Component contentPane = reporteador.obtenerReporte(listadoReporteAsignacion, reporte, parametros);
    Frame principal = JOptionPane.getRootFrame();
    JDialog visor = new JDialog(principal, "Reporte", true);
    visor.setSize(contentPane.getSize());
    //        visor.setSize(ventana.getSize().width, ventana.getSize().height);
    visor.getContentPane().add(contentPane);
    visor.setLocationRelativeTo(this);

    //            visor.setUndecorated(true);
    visor.setBounds(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds());
    visor.setVisible(true);
    visor.setAlwaysOnTop(true);
    //        reporteador.getReporte(reporte, parametros, listado) //        reporteador.setConn(controlador.getDao().getConexion());
    //        reporteador.generarReporte(reporte, parametros, JOptionPane.getFrameForComponent(this));
}

From source file:CSSDFarm.UserInterface.java

private void btnAddFieldStationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddFieldStationActionPerformed
    JTextField id = new JTextField();
    JTextField name = new JTextField();
    //Space is needed to expand dialog
    JLabel verified = new JLabel(" ");
    JButton okButton = new JButton("Ok");
    JButton cancelButton = new JButton("Cancel");
    okButton.setEnabled(false);/*w  ww . j a  v a  2  s  .co  m*/
    okButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            String idText = id.getText();
            String nameText = name.getText();
            addFieldStation(id.getText(), name.getText());
            JOptionPane.getRootFrame().dispose();
            listUserStations.setSelectedValue(server.getFieldStation(idText), false);
        }
    });

    cancelButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            JOptionPane.getRootFrame().dispose();
        }
    });

    id.addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent key) {
            boolean theid = id.getText().equals("");
            boolean thename = name.getText().equals("");
            if (server.verifyFieldStation(id.getText()) && !theid && !thename) {
                verified.setText(" Verified");
                verified.setForeground(new Color(0, 102, 0));
                okButton.setEnabled(true);
            } else {
                verified.setText(" Not Verified");
                verified.setForeground(Color.RED);
                okButton.setEnabled(false);
            }
        }
    });
    name.addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent key) {
            boolean theid = id.getText().equals("");
            boolean thename = name.getText().equals("");
            if (server.verifyFieldStation(id.getText()) && !theid && !thename) {
                verified.setText(" Verified");
                verified.setForeground(new Color(0, 102, 0));
                okButton.setEnabled(true);
            } else {
                verified.setText(" Not Verified");
                verified.setForeground(Color.RED);
                okButton.setEnabled(false);
            }
        }
    });

    Object[] message = { "Field Station ID:", id, "Field Station Name:", name, verified };
    int inputFields = JOptionPane.showOptionDialog(null, message, "Add Field Station",
            JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null,
            new Object[] { okButton, cancelButton }, null);
    if (inputFields == JOptionPane.OK_OPTION) {
        System.out.print("Added Field Station!");
    }
}

From source file:org.kuali.test.ui.utils.UIUtils.java

/**
 *
 * @param c/*ww  w. java 2  s  . c  om*/
 * @return
 */
public static Window findWindow(Component c) {
    if (c == null) {
        return JOptionPane.getRootFrame();
    } else if (c instanceof Window) {
        return (Window) c;
    } else {
        return findWindow(c.getParent());
    }
}

From source file:org.springframework.richclient.dialog.ApplicationDialog.java

/**
 * <p>// w w  w .  j  av a  2  s. c  o  m
 * --jh-- This method is copied from JOptionPane. I'm still trying to figure
 * out why they chose to have a static method with package visibility for
 * this one instead of just making it public.
 * </p>
 *
 * Returns the specified component's toplevel <code>Frame</code> or
 * <code>Dialog</code>.
 *
 * @param parentComponent the <code>Component</code> to check for a
 * <code>Frame</code> or <code>Dialog</code>
 * @return the <code>Frame</code> or <code>Dialog</code> that contains
 * the component, or the default frame if the component is <code>null</code>,
 * or does not have a valid <code>Frame</code> or <code>Dialog</code>
 * parent
 * @exception HeadlessException if
 * <code>GraphicsEnvironment.isHeadless</code> returns <code>true</code>
 * @see java.awt.GraphicsEnvironment#isHeadless
 */
public static Window getWindowForComponent(Component parentComponent) throws HeadlessException {
    if (parentComponent == null)
        return JOptionPane.getRootFrame();
    if (parentComponent instanceof Frame || parentComponent instanceof Dialog)
        return (Window) parentComponent;
    return getWindowForComponent(parentComponent.getParent());
}