Example usage for javax.swing JDialog pack

List of usage examples for javax.swing JDialog pack

Introduction

In this page you can find the example usage for javax.swing JDialog pack.

Prototype

@SuppressWarnings("deprecation")
public void pack() 

Source Link

Document

Causes this Window to be sized to fit the preferred size and layouts of its subcomponents.

Usage

From source file:org.executequery.components.FileChooserDialog.java

protected JDialog createDialog(Component parent) throws HeadlessException {

    Frame frame = parent instanceof Frame ? (Frame) parent
            : (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parent);

    String title = getUI().getDialogTitle(this);

    JDialog dialog = new JDialog(frame, title, true);

    Container contentPane = dialog.getContentPane();
    contentPane.setLayout(new BorderLayout());
    contentPane.add(this, BorderLayout.CENTER);

    setPreferredSize(new Dimension(700, getPreferredSize().height));

    // add any custom panel
    if (customPanel != null) {
        contentPane.add(customPanel, BorderLayout.SOUTH);
    }//from w  w  w. jav a2  s .  c o  m

    if (JDialog.isDefaultLookAndFeelDecorated()) {
        boolean supportsWindowDecorations = UIManager.getLookAndFeel().getSupportsWindowDecorations();

        if (supportsWindowDecorations) {
            dialog.getRootPane().setWindowDecorationStyle(JRootPane.FILE_CHOOSER_DIALOG);
        }

    }

    setFileView(new DefaultFileView());
    dialog.pack();

    dialog.setLocation(GUIUtilities.getLocationForDialog(dialog.getSize()));
    return dialog;
}

From source file:org.executequery.gui.browser.SSHTunnelConnectionPanel.java

public boolean canConnect() {

    if (useSshCheckbox.isSelected()) {

        if (!hasValue(userNameField)) {

            GUIUtilities/*from   w  w w.  j a  va 2 s. co m*/
                    .displayErrorMessage("You have selected SSH Tunnel but have not provided an SSH user name");
            return false;
        }

        if (!hasValue(portField)) {

            GUIUtilities.displayErrorMessage("You have selected SSH Tunnel but have not provided an SSH port");
            return false;
        }

        if (!hasValue(passwordField)) {

            final JPasswordField field = WidgetFactory.createPasswordField();

            JOptionPane optionPane = new JOptionPane(field, JOptionPane.QUESTION_MESSAGE,
                    JOptionPane.OK_CANCEL_OPTION);
            JDialog dialog = optionPane.createDialog("Enter SSH password");

            dialog.addWindowFocusListener(new WindowAdapter() {
                @Override
                public void windowGainedFocus(WindowEvent e) {
                    field.requestFocusInWindow();
                }
            });

            dialog.pack();
            dialog.setLocation(GUIUtilities.getLocationForDialog(dialog.getSize()));
            dialog.setVisible(true);
            dialog.dispose();

            int result = Integer.parseInt(optionPane.getValue().toString());
            if (result == JOptionPane.OK_OPTION) {

                String password = MiscUtils.charsToString(field.getPassword());
                if (StringUtils.isNotBlank(password)) {

                    passwordField.setText(password);
                    return true;

                } else {

                    GUIUtilities.displayErrorMessage(
                            "You have selected SSH Tunnel but have not provided an SSH password");

                    // send back here and force them to select cancel if they want to bail

                    return canConnect();
                }

            }
            return false;
        }

    }

    return true;
}

From source file:org.exist.launcher.Launcher.java

private boolean initSystemTray() {
    final Dimension iconDim = tray.getTrayIconSize();
    BufferedImage image = null;/*www .  j av a2 s  . co  m*/
    try {
        image = ImageIO.read(getClass().getResource("icon32.png"));
    } catch (final IOException e) {
        showMessageAndExit("Launcher failed", "Failed to read system tray icon.", false);
    }
    trayIcon = new TrayIcon(image.getScaledInstance(iconDim.width, iconDim.height, Image.SCALE_SMOOTH),
            "eXist-db Launcher");

    final JDialog hiddenFrame = new JDialog();
    hiddenFrame.setUndecorated(true);
    hiddenFrame.setIconImage(image);

    final PopupMenu popup = createMenu();
    trayIcon.setPopupMenu(popup);
    trayIcon.addActionListener(actionEvent -> {
        trayIcon.displayMessage(null, "Right click for menu", TrayIcon.MessageType.INFO);
        setServiceState();
    });

    // add listener for left click on system tray icon. doesn't work well on linux though.
    if (!SystemUtils.IS_OS_LINUX) {
        trayIcon.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent mouseEvent) {
                if (mouseEvent.getButton() == MouseEvent.BUTTON1) {
                    setServiceState();
                    hiddenFrame.add(popup);
                    popup.show(hiddenFrame, mouseEvent.getXOnScreen(), mouseEvent.getYOnScreen());
                }
            }
        });
    }

    try {
        hiddenFrame.setResizable(false);
        hiddenFrame.pack();
        hiddenFrame.setVisible(true);
        tray.add(trayIcon);
    } catch (final AWTException e) {
        return false;
    }

    return true;
}

From source file:org.geopublishing.atlasViewer.GpCoreUtil.java

public static JDialog getWaitDialog(final Component owner, final String msg) {
    final JDialog waitFrame = new JDialog(SwingUtil.getParentWindow(owner));

    waitFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);

    final JPanel cp = new JPanel(new MigLayout());
    final JLabel label = new JLabel(msg, Icons.ICON_TASKRUNNING_BIG, SwingConstants.LEADING);
    cp.add(label);/*from  w w  w.ja  v a2  s  .  c  om*/
    waitFrame.setContentPane(cp);

    waitFrame.setAlwaysOnTop(true);
    waitFrame.pack();
    SwingUtil.centerFrameOnScreen(waitFrame);
    waitFrame.setVisible(true);

    return waitFrame;
}

From source file:org.gofleet.module.routing.RoutingMap.java

private void newPlan(LatLon from) {
    JDialog d = new JDialog(basicWindow.getFrame(), "Generating New Plan");
    try {// w ww  .  j  ava2  s. c  o m
        JFileChooser fc = new JFileChooser();
        fc.addChoosableFileFilter(new RoutingFilter());
        fc.setAcceptAllFileFilterUsed(true);
        int returnVal = fc.showOpenDialog(basicWindow.getFrame());
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            log.debug("Opening: " + file.getName());

            JProgressBar progressBar = new JProgressBar(0, getNumberLines(file) * 2);
            progressBar.setValue(0);
            progressBar.setPreferredSize(new Dimension(150, 50));
            progressBar.setStringPainted(true);

            d.add(progressBar);
            d.pack();
            d.setVisible(true);

            TSPPlan[] param = processFile(file, progressBar);

            Map<String, String> values = getValues(from);

            double[] origin = new double[2];
            origin[0] = new Double(values.get("origin_x"));
            origin[1] = new Double(values.get("origin_y"));

            TSPPlan[] res = calculateRouteOnWS(new Integer(values.get("maxDistance")),
                    new Integer(values.get("maxTime")), origin, new Integer(values.get("startTime")), param,
                    new Integer(values.get("timeSpentOnStop")));

            progressBar.setValue(progressBar.getMaximum() - res.length);

            processTSPPlan(res, progressBar);

        } else {
            log.trace("Open command cancelled by user.");
        }
    } catch (Throwable t) {
        log.error("Error computing new plan", t);
        JOptionPane.showMessageDialog(basicWindow.getFrame(),
                "<html><p>" + i18n.getString("Main.Error") + ":</p><p>" + t.toString() + "</p><html>",
                i18n.getString("Main.Error"), JOptionPane.ERROR_MESSAGE);
    } finally {
        d.setVisible(false);
        d.dispose();
    }

}

From source file:org.gofleet.module.routing.RoutingMap.java

private Map<String, String> getValues(LatLon from) {
    final Map<String, String> mapa = new HashMap<String, String>();
    final JDialog frame = new JDialog(basicWindow.getFrame(), "Configuration");
    JPanel panel = new JPanel(new GridLayout(0, 2));
    int width = 10;

    final JTextField maxDistance = new JTextField(width);
    maxDistance.setText("10");
    final JTextField maxTime = new JTextField(width);
    maxTime.setText("8");
    final JTextField origin_x = new JTextField(width / 2);
    origin_x.setText((new Double(from.getX())).toString());
    final JTextField origin_y = new JTextField(width / 2);
    origin_y.setText((new Double(from.getY())).toString());
    final JTextField startTime = new JTextField(width);
    startTime.setText("7");
    final JTextField timeSpentOnStop = new JTextField(width);
    timeSpentOnStop.setText("1");
    JLabel lmaxDistance = new JLabel("Maximum Distance (km)");
    lmaxDistance.setLabelFor(maxDistance);
    JLabel lmaxTime = new JLabel("Maximum Time (hours)");
    lmaxTime.setLabelFor(maxTime);/*from   w w  w  .ja  v a 2  s.c  o m*/
    JLabel lorigin = new JLabel("Point of Origin");
    lorigin.setLabelFor(origin_x);
    JLabel lstartTime = new JLabel("Start Time of Plan (0-24)");
    lstartTime.setLabelFor(startTime);
    JLabel ltimeSpentOnStop = new JLabel("Time Spent on Stop (hours)");
    ltimeSpentOnStop.setLabelFor(timeSpentOnStop);

    JButton close = new JButton("OK");
    close.addActionListener(new AbstractAction() {

        private static final long serialVersionUID = -8912729211256933464L;

        @Override
        public void actionPerformed(ActionEvent arg0) {
            try {
                mapa.put("maxDistance", maxDistance.getText());
                mapa.put("maxTime", maxTime.getText());
                mapa.put("origin_x", origin_x.getText());
                mapa.put("origin_y", origin_y.getText());
                mapa.put("startTime", startTime.getText());
                mapa.put("timeSpentOnStop", timeSpentOnStop.getText());
                frame.dispose();
            } catch (Throwable t) {
                log.error("Error configuring New Route Plan" + t);
                JOptionPane.showMessageDialog(RoutingMap.this, "Some values are wrong. Check them again.");
            }
        }
    });

    panel.add(lmaxDistance);
    panel.add(maxDistance);
    panel.add(lmaxTime);
    panel.add(maxTime);
    panel.add(lorigin);
    JPanel panel_origin = new JPanel();
    panel_origin.add(origin_x);
    panel_origin.add(origin_y);
    panel.add(panel_origin);
    panel.add(lstartTime);
    panel.add(startTime);
    panel.add(ltimeSpentOnStop);
    panel.add(timeSpentOnStop);
    panel.add(close);
    frame.add(panel, BorderLayout.CENTER);
    frame.pack();
    frame.setModalityType(ModalityType.APPLICATION_MODAL);
    frame.setVisible(true);

    return mapa;
}

From source file:org.interreg.docexplore.authoring.AuthoringMenu.java

public AuthoringMenu(final AuthoringToolFrame authoringTool) {
    this.tool = authoringTool;

    this.recent = new LinkedList<String>();
    readRecent();//from w  w w  .ja va 2 s.co m
    this.file = new JMenu(XMLResourceBundle.getBundledString("generalMenuFile"));
    add(file);

    newItem = new JMenuItem(new AbstractAction(XMLResourceBundle.getBundledString("generalMenuNew")) {
        public void actionPerformed(ActionEvent arg0) {
            newFile();
        }
    });
    loadItem = new JMenuItem(new AbstractAction(XMLResourceBundle.getBundledString("generalMenuLoad")) {
        public void actionPerformed(ActionEvent arg0) {
            load();
        }
    });
    saveItem = new JMenuItem(new AbstractAction(XMLResourceBundle.getBundledString("generalMenuSave")) {
        public void actionPerformed(ActionEvent arg0) {
            save();
        }
    });
    saveAsItem = new JMenuItem(new AbstractAction(XMLResourceBundle.getBundledString("generalMenuSaveAs")) {
        public void actionPerformed(ActionEvent arg0) {
            saveAs();
        }
    });
    exportItem = new JMenuItem(
            new AbstractAction(XMLResourceBundle.getBundledString("generalMenuExport") + "...") {
                public void actionPerformed(ActionEvent arg0) {
                    GuiUtils.blockUntilComplete(new ProgressRunnable() {
                        public void run() {
                            try {
                                authoringTool.readerExporter.doExport(authoringTool.editor.link);
                            } catch (Exception ex) {
                                ErrorHandler.defaultHandler.submit(ex);
                            }
                        }

                        public float getProgress() {
                            return (float) authoringTool.readerExporter.progress[0];
                        }
                    }, authoringTool.editor);
                }
            });
    webExportItem = new JMenuItem(
            new AbstractAction(XMLResourceBundle.getBundledString("generalMenuWebExport") + "...") {
                public void actionPerformed(ActionEvent arg0) {
                    GuiUtils.blockUntilComplete(new ProgressRunnable() {
                        public void run() {
                            try {
                                authoringTool.webExporter.doExport(authoringTool.editor.link);
                            } catch (Exception ex) {
                                ErrorHandler.defaultHandler.submit(ex);
                            }
                        }

                        public float getProgress() {
                            return (authoringTool.webExporter.copyComplete ? .5f : 0f)
                                    + (float) (.5 * authoringTool.webExporter.progress[0]);
                        }
                    }, authoringTool.editor);
                }
            });
    //      webExportItem = new JMenuItem(new AbstractAction("Web export") {public void actionPerformed(ActionEvent arg0)
    //      {
    //         GuiUtils.blockUntilComplete(new Runnable() {public void run()
    //         {
    //            try 
    //            {
    //               new WebStaticExporter().doExport(authoringTool.editor.link.getBook(authoringTool.editor.link.getLink().getAllBookIds().get(0)));
    //            }
    //            catch (Exception ex) {ErrorHandler.defaultHandler.submit(ex);}
    //         }}, authoringTool.editor);
    //      }});
    //      webExportItem.setEnabled(false);
    quitItem = new JMenuItem(new AbstractAction(XMLResourceBundle.getBundledString("generalMenuQuit")) {
        public void actionPerformed(ActionEvent arg0) {
            authoringTool.quit();
        }
    });
    buildFileMenu();

    JMenu edit = new JMenu(XMLResourceBundle.getBundledString("generalMenuEdit"));
    this.undoItem = new JMenuItem();
    undoItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                authoringTool.historyManager.undo();
            } catch (Exception ex) {
                ErrorHandler.defaultHandler.submit(ex);
            }
        }
    });
    edit.add(undoItem);
    this.redoItem = new JMenuItem();
    redoItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                authoringTool.historyManager.redo();
            } catch (Exception ex) {
                ErrorHandler.defaultHandler.submit(ex);
            }
        }
    });
    edit.add(redoItem);
    JMenuItem viewHistory = new JMenuItem(XMLResourceBundle.getBundledString("generalMenuEditViewHistory"));
    viewHistory.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            authoringTool.historyDialog.setVisible(true);
        }
    });
    edit.add(viewHistory);

    edit.addSeparator();

    edit.add(new JMenuItem(new AbstractAction(XMLResourceBundle.getBundledString("fixChars")) {
        public void actionPerformed(ActionEvent arg0) {
            Object res = JOptionPane.showInputDialog(tool, XMLResourceBundle.getBundledString("fixCharsMsg"),
                    XMLResourceBundle.getBundledString("fixChars"), JOptionPane.QUESTION_MESSAGE, null,
                    new Object[] { XMLResourceBundle.getBundledString("fixCharsWin"),
                            XMLResourceBundle.getBundledString("fixCharsMac") },
                    XMLResourceBundle.getBundledString("fixCharsWin"));
            if (res == null)
                return;
            try {
                convertPresentation(tool.defaultFile,
                        res.equals(XMLResourceBundle.getBundledString("fixCharsWin")) ? "ISO-8859-1"
                                : "x-MacRoman");
            } catch (Exception e) {
                ErrorHandler.defaultHandler.submit(e);
            }
            try {
                tool.editor.reset();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }));

    //TODO: remove!
    //      edit.add(new JMenuItem(new AbstractAction("hack!")
    //      {
    //         public void actionPerformed(ActionEvent e) {try
    //         {
    //            BookEditorView be = null;
    //            for (ExplorerView view : tool.editor.views)
    //               if (view instanceof BookEditorView)
    //                  be = (BookEditorView)view;
    //            Book book = be.curBook;
    //            int lastPage = book.getLastPageNumber();
    //            for (int pageNum = 1;pageNum <= lastPage;pageNum++)
    //            {
    //               Page page = book.getPage(pageNum);
    //               Set<Region> regions = page.getRegions();
    //               if (regions.size() > 2)
    //               {
    //                  Region highest = null;
    //                  int max = -1;
    //                  for (Region region : regions)
    //                     for (Point point : region.getOutline())
    //                        if (max < 0 || point.y < max)
    //                           {max = point.y; highest = region;}
    //                  Region middle = null;
    //                  max = -1;
    //                  for (Region region : regions)
    //                     if (region != highest)
    //                        for (Point point : region.getOutline())
    //                           if (max < 0 || point.y < max)
    //                              {max = point.y; middle = region;}
    //                  if (regions.size() > 3)
    //                  {
    //                     max = -1;
    //                     Region newMiddle = null;
    //                     for (Region region : regions)
    //                        if (region != highest && region != middle)
    //                           for (Point point : region.getOutline())
    //                              if (max < 0 || point.y < max)
    //                                 {max = point.y; newMiddle = region;}
    //                     middle = newMiddle;
    //                  }
    //                  MetaDataKey display = book.getLink().getKey("display", "");
    //                  for (Map.Entry<MetaDataKey, List<MetaData>> entry : highest.getMetaData().entrySet())
    //                     for (MetaData md : entry.getValue())
    //                        if (md.getType().equals(MetaData.textType))
    //                        {
    //                           String val = "<b>"+md.getString()+"</b>\n";
    //                           for (Map.Entry<MetaDataKey, List<MetaData>> entry2 : middle.getMetaData().entrySet())
    //                              for (MetaData md2 : entry2.getValue())
    //                                 if (md2.getType().equals(MetaData.textType) && TextElement.getStyle(md, tool.styleManager) == TextElement.getStyle(md2, tool.styleManager))
    //                                    val = val+"\n"+md2.getString();
    //                           md.setString(val);
    //                        }
    //                  boolean hasImage = false;
    //                  for (Map.Entry<MetaDataKey, List<MetaData>> entry2 : middle.getMetaData().entrySet())
    //                     for (MetaData md2 : entry2.getValue())
    //                        if (md2.getType().equals(MetaData.imageType))
    //                        {
    //                           MetaData imageMd = new MetaData(book.getLink(), display, md2.getType(), md2.getValue());
    //                           if (!hasImage)
    //                              BookImporter.insert(imageMd, highest, 0);
    //                           else BookImporter.insert(imageMd, highest, BookImporter.getHighestRank(highest)+1);
    //                           hasImage = true;
    //                        }
    //                  page.removeRegion(middle);
    //               }
    //            }
    //         }
    //         catch (Exception ex) {ex.printStackTrace();}System.out.println("done");}
    //      }));
    //      edit.add(new JMenuItem(new AbstractAction("hack!")
    //      {
    //         public void actionPerformed(ActionEvent e) {try
    //         {
    //            BookEditorView be = null;
    //            for (ExplorerView view : tool.editor.views)
    //               if (view instanceof BookEditorView)
    //                  be = (BookEditorView)view;
    //            Book book = be.curBook;
    //            int lastPage = book.getLastPageNumber();
    //            MetaDataKey display = book.getLink().getKey("display", "");
    //            for (int pageNum = 1;pageNum <= lastPage;pageNum++)
    //            {
    //               Page page = book.getPage(pageNum);
    //               Set<Region> regions = page.getRegions();
    //               for (Region region : regions)
    //               {
    //                  List<MetaData> mds = region.getMetaDataListForKey(display);
    //                     for (MetaData md : mds)
    //                        if (md.getType().equals(MetaData.textType))
    //                        {
    //                           String val = md.getString().trim();
    //                           if (!val.startsWith("<i>") || !val.endsWith("</i>"))
    //                              continue;
    //                           TextElement.getStyleMD(md).setString("4");
    //                           md.setString(val.substring(3, val.length()-4));
    //                           System.out.println(md.getString());
    //                        }
    //               }
    //            }
    //         }
    //         catch (Exception ex) {ex.printStackTrace();}System.out.println("done");}
    //      }));
    //      edit.add(new JMenuItem(new AbstractAction("hack!")
    //      {
    //         public void actionPerformed(ActionEvent e) {try
    //         {
    //            BookEditorView be = null;
    //            for (ExplorerView view : tool.editor.views)
    //               if (view instanceof BookEditorView)
    //                  be = (BookEditorView)view;
    //            Book book = be.curBook;
    //            int lastPage = book.getLastPageNumber();
    //            MetaDataKey display = book.getLink().getKey("display", "");
    //            for (int pageNum = 1;pageNum <= lastPage;pageNum++)
    //            {
    //               Page page = book.getPage(pageNum);
    //               Set<Region> regions = page.getRegions();
    //               for (Region region : regions)
    //               {
    //                  int max = BookImporter.getHighestRank(region);
    //                  for (int i=0;i<max;i++)
    //                  {
    //                     MetaData md1 = BookImporter.getAtRank(region, i);
    //                     if (md1 == null || !md1.getType().equals(MetaData.textType))
    //                        continue;
    //                     MetaData style1 = TextElement.getStyleMD(md1);
    //                     if (!style1.getString().equals("0"))
    //                        continue;
    //                     MetaData md2 = BookImporter.getAtRank(region, i+1);
    //                     if (md2 == null || !md2.getType().equals(MetaData.textType))
    //                        continue;
    //                     MetaData style2 = TextElement.getStyleMD(md2);
    //                     if (!style2.getString().equals("1"))
    //                        continue;
    //                     BookImporter.setRank(md1, i+1);
    //                     BookImporter.setRank(md2, i);
    //                     i++;
    //                  }
    //               }
    //            }
    //         }
    //         catch (Exception ex) {ex.printStackTrace();}System.out.println("done");}
    //      }));
    //      edit.add(new JMenuItem(new AbstractAction("hack!")
    //      {
    //         public void actionPerformed(ActionEvent e) {try
    //         {
    //            BookEditorView be = null;
    //            for (ExplorerView view : tool.editor.views)
    //               if (view instanceof BookEditorView)
    //                  be = (BookEditorView)view;
    //            Book book = be.curBook;
    //            MetaDataKey mini = book.getLink().getOrCreateKey("mini", "");
    //            MetaDataKey dim = book.getLink().getOrCreateKey("dimension", "");
    //            int lastPage = book.getLastPageNumber();
    //            for (int pageNum = 1;pageNum <= lastPage;pageNum++)
    //            {
    //               Page page = book.getPage(pageNum);
    //               List<MetaData> mds = page.getMetaDataListForKey(mini);
    //               if (mds != null)
    //                  for (MetaData md : mds)
    //                     page.removeMetaData(md);
    //               mds = page.getMetaDataListForKey(dim);
    //               if (mds != null)
    //                  for (MetaData md : mds)
    //                     page.removeMetaData(md);
    //               DocExploreDataLink.getImageDimension(page, true);
    //               DocExploreDataLink.getImageMini(page, false);
    //            }
    //         }
    //         catch (Exception ex) {ex.printStackTrace();}System.out.println("done");}
    //      }));

    add(edit);

    JMenu view = new JMenu(XMLResourceBundle.getBundledString("generalMenuView"));
    add(view);

    JMenuItem styles = new JMenuItem(XMLResourceBundle.getBundledString("styleEdit") + "...",
            ImageUtils.getIcon("pencil-24x24.png"));
    styles.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            authoringTool.styleManager.styleDialog.setVisible(true);
        }
    });
    view.add(styles);

    helpToggle = new JCheckBoxMenuItem(
            new AbstractAction(XMLResourceBundle.getBundledString("viewHelpToggle")) {
                public void actionPerformed(ActionEvent arg0) {
                    authoringTool.displayHelp = helpToggle.isSelected();
                    authoringTool.repaint();
                }
            });
    helpToggle.setSelected(tool.startup.showHelp);
    view.add(helpToggle);

    JMenu helpMenu = new JMenu(XMLResourceBundle.getString("management-lrb", "generalMenuHelp"));
    if (Desktop.isDesktopSupported()) {
        final Desktop desktop = Desktop.getDesktop();
        if (desktop.isSupported(Desktop.Action.OPEN)) {
            helpMenu.add(new AbstractAction(
                    XMLResourceBundle.getString("management-lrb", "generalMenuHelpContents")) {
                public void actionPerformed(ActionEvent e) {
                    try {
                        File doc = new File(DocExploreTool.getExecutableDir(), "MMT documentation.htm");
                        desktop.open(doc);
                    } catch (Exception ex) {
                        ErrorHandler.defaultHandler.submit(ex, true);
                    }
                }
            });
            helpMenu.add(new AbstractAction(
                    XMLResourceBundle.getString("management-lrb", "generalMenuHelpWebsite")) {
                public void actionPerformed(ActionEvent e) {
                    try {
                        File link = new File(DocExploreTool.getExecutableDir(), "website.url");
                        desktop.open(link);
                    } catch (Exception ex) {
                        ErrorHandler.defaultHandler.submit(ex, true);
                    }
                }
            });
        }
    }
    helpMenu.add(new AbstractAction(XMLResourceBundle.getString("management-lrb", "generalMenuHelpAbout")) {
        public void actionPerformed(ActionEvent e) {
            final JDialog splash = new JDialog(tool, true);
            splash.setLayout(new BorderLayout());
            SplashScreen screen = new SplashScreen("logoAT.png");
            splash.add(screen, BorderLayout.NORTH);
            screen.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseReleased(MouseEvent e) {
                    splash.setVisible(false);
                }
            });
            splash.setUndecorated(true);
            screen.setText(
                    "<html>DocExplore 2009-2014" + "<br/>Released under the CeCILL v2.1 license" + "</html>");
            splash.pack();
            splash.setAlwaysOnTop(true);
            GuiUtils.centerOnScreen(splash);
            splash.setVisible(true);
        }
    });
    add(helpMenu);

    historyChanged(authoringTool.historyManager);
    authoringTool.historyManager.addHistoryListener(this);
}

From source file:org.interreg.docexplore.DocExploreTool.java

@SuppressWarnings("serial")
protected static File askForHome(String text) {
    final File[] file = { null };
    final JDialog dialog = new JDialog((Frame) null, XMLResourceBundle.getBundledString("homeLabel"), true);
    JPanel content = new JPanel(new LooseGridLayout(0, 1, 10, 10, true, false, SwingConstants.CENTER,
            SwingConstants.TOP, true, false));
    content.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10));
    JLabel message = new JLabel(text, ImageUtils.getIcon("free-64x64.png"), SwingConstants.LEFT);
    message.setIconTextGap(20);/*  w  ww  .j av a  2  s.  com*/
    //message.setFont(Font.decode(Font.SANS_SERIF));
    content.add(message);

    final JPanel pathPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 10));
    pathPanel.add(new JLabel("<html><b>" + XMLResourceBundle.getBundledString("homeLabel") + ":</b></html>"));
    final JTextField pathField = new JTextField(System.getProperty("user.home") + File.separator + "DocExplore",
            40);
    pathPanel.add(pathField);
    pathPanel.add(new JButton(new AbstractAction(XMLResourceBundle.getBundledString("browseLabel")) {
        JNativeFileDialog nfd = null;

        public void actionPerformed(ActionEvent arg0) {
            if (nfd == null) {
                nfd = new JNativeFileDialog();
                nfd.acceptFiles = false;
                nfd.acceptFolders = true;
                nfd.multipleSelection = false;
                nfd.title = XMLResourceBundle.getBundledString("homeLabel");
            }
            nfd.setCurrentFile(new File(pathField.getText()));
            if (nfd.showOpenDialog())
                pathField.setText(nfd.getSelectedFile().getAbsolutePath());
        }
    }));
    content.add(pathPanel);

    JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 10));
    buttonPanel.add(new JButton(new AbstractAction(XMLResourceBundle.getBundledString("cfgOkLabel")) {
        public void actionPerformed(ActionEvent e) {
            File res = new File(pathField.getText());
            if (res.exists() && !res.isDirectory() || !res.exists() && !res.mkdirs())
                JOptionPane.showMessageDialog(dialog, XMLResourceBundle.getBundledString("homeErrorMessage"),
                        XMLResourceBundle.getBundledString("errorLabel"), JOptionPane.ERROR_MESSAGE);
            else {
                file[0] = res;
                dialog.setVisible(false);
            }
        }
    }));
    buttonPanel.add(new JButton(new AbstractAction(XMLResourceBundle.getBundledString("cfgCancelLabel")) {
        public void actionPerformed(ActionEvent e) {
            dialog.setVisible(false);
        }
    }));
    content.add(buttonPanel);

    dialog.getContentPane().add(content);
    dialog.pack();
    dialog.setResizable(false);
    GuiUtils.centerOnScreen(dialog);
    dialog.setVisible(true);
    return file[0];
}

From source file:org.myrobotlab.service.MarySpeech.java

private void showProgressPanel(List<ComponentDescription> comps, boolean install) {
    final ProgressPanel pp = new ProgressPanel(comps, install);
    final JOptionPane optionPane = new JOptionPane(pp, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION,
            null, new String[] { "Abort" }, "Abort");
    // optionPane.setPreferredSize(new Dimension(640,480));
    final JDialog dialog = new JDialog((Frame) null, "Progress", false);
    dialog.setContentPane(optionPane);//from  w w  w  . j  av a 2 s  . c  o m
    optionPane.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent e) {
            String prop = e.getPropertyName();

            if (dialog.isVisible() && (e.getSource() == optionPane)
                    && (prop.equals(JOptionPane.VALUE_PROPERTY))) {
                pp.requestExit();
                dialog.setVisible(false);
            }
        }
    });
    dialog.pack();
    dialog.setVisible(true);
    new Thread(pp).start();
}

From source file:org.nuclos.client.main.MainController.java

public static void cmdOpenSettings() {
    NuclosSettingsContainer panel = new NuclosSettingsContainer(frm);

    JOptionPane p = new JOptionPane(panel, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null);
    JDialog dlg = p.createDialog(Main.getInstance().getMainFrame(),
            SpringLocaleDelegate.getInstance().getMessage("R00022927", "Einstellungen"));
    dlg.pack();
    dlg.setResizable(true);/* w  w w  .j  a  va2 s. c  om*/
    dlg.setVisible(true);
    Object o = p.getValue();
    int res = ((o instanceof Integer) ? ((Integer) o).intValue() : JOptionPane.CANCEL_OPTION);

    if (res == JOptionPane.OK_OPTION) {
        try {
            panel.save();
        } catch (PreferencesException e) {
            Errors.getInstance().showExceptionDialog(frm, e);
        }
    }
}