Example usage for javax.swing JOptionPane QUESTION_MESSAGE

List of usage examples for javax.swing JOptionPane QUESTION_MESSAGE

Introduction

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

Prototype

int QUESTION_MESSAGE

To view the source code for javax.swing JOptionPane QUESTION_MESSAGE.

Click Source Link

Document

Used for questions.

Usage

From source file:org.gitools.ui.app.actions.file.OpenFromURLAction.java

@Override
public void actionPerformed(ActionEvent e) {

    String fileURL = JOptionPane.showInputDialog(null, "Specify URL:", "Open URL",
            JOptionPane.QUESTION_MESSAGE);

    if (!isEmpty(fileURL)) {
        JobRunnable loadFile = new CommandLoadFile(fileURL);
        JobThread.execute(Application.get(), loadFile);
        Application.get().showNotification("File loaded.");
    }/*from  w w w.  j  av a 2s. c  o  m*/
}

From source file:org.hu.deezer.DeezerAction.java

@Override
public void actionPerformed(ActionEvent e) {
    try {/*from   w ww  .j a v a 2  s. co m*/
        loadUserIdSettings();
        if (userID.equals("")) {
            userID = JOptionPane.showInputDialog(null, "Please enter your Deezer ID.");
            System.setProperty("deezerID", userID);
        }

        HashMap<String, Long> playlists = getDeezerPlaylists(
                "https://api.deezer.com/user/" + userID + "/playlists");
        String[] options = getArrayFromMap(playlists);

        String selected = (String) JOptionPane.showInputDialog(null, "Select a playlist", "Deezer playlists",
                JOptionPane.QUESTION_MESSAGE, null, options, options[1]);

        if (selected != null) {
            Long playlistId = playlists.get(selected);
            URLDisplayer.getDefault().showURL(new URL("http://www.deezer.com/playlist/" + playlistId));
        }
    } catch (Exception eee) {
        eee.printStackTrace();
        return;//nothing much to do
    }
}

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

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

    this.recent = new LinkedList<String>();
    readRecent();/*w  w w .  j  av a2  s.c  o  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.GeneralConfigPanel.java

String browseClasses(File file) {
    try {//from  ww w  . ja  va 2s.c o  m
        List<Class<?>> metaDataPlugins = new LinkedList<Class<?>>();
        List<Class<?>> analysisPlugins = new LinkedList<Class<?>>();
        List<Class<?>> clientPlugins = new LinkedList<Class<?>>();
        List<Class<?>> serverPlugins = new LinkedList<Class<?>>();
        List<Class<?>> inputPlugins = new LinkedList<Class<?>>();

        List<URL> urls = Startup.extractDependencies(file.getName().substring(0, file.getName().length() - 4),
                file.getName());
        urls.add(file.toURI().toURL());
        URLClassLoader loader = new URLClassLoader(urls.toArray(new URL[] {}),
                this.getClass().getClassLoader());

        JarFile jarFile = new JarFile(file);
        Enumeration<JarEntry> entries = jarFile.entries();
        while (entries.hasMoreElements()) {
            JarEntry entry = entries.nextElement();
            if (!entry.getName().endsWith(".class") || entry.getName().indexOf('$') > 0)
                continue;
            String className = entry.getName().substring(0, entry.getName().length() - 6).replace('/', '.');
            Class<?> clazz = null;
            try {
                clazz = loader.loadClass(className);
                System.out.println("Reading " + className);
            } catch (NoClassDefFoundError e) {
                System.out.println("Couldn't read " + className);
            }
            if (clazz == null)
                continue;

            if (clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers()))
                continue;
            if (MetaDataPlugin.class.isAssignableFrom(clazz))
                metaDataPlugins.add(clazz);
            if (AnalysisPlugin.class.isAssignableFrom(clazz))
                analysisPlugins.add(clazz);
            if (ClientPlugin.class.isAssignableFrom(clazz))
                clientPlugins.add(clazz);
            if (ServerPlugin.class.isAssignableFrom(clazz))
                serverPlugins.add(clazz);
            if (InputPlugin.class.isAssignableFrom(clazz))
                inputPlugins.add(clazz);
        }
        jarFile.close();

        @SuppressWarnings("unchecked")
        Pair<String, String>[] classes = new Pair[metaDataPlugins.size() + analysisPlugins.size()
                + clientPlugins.size() + serverPlugins.size() + inputPlugins.size()];
        if (classes.length == 0)
            throw new Exception("Invalid plugin (no entry points were found).");

        int cnt = 0;
        for (Class<?> clazz : metaDataPlugins)
            classes[cnt++] = new Pair<String, String>(clazz.getName(), "MetaData plugin") {
                public String toString() {
                    return first + " (" + second + ")";
                }
            };
        for (Class<?> clazz : analysisPlugins)
            classes[cnt++] = new Pair<String, String>(clazz.getName(), "Analysis plugin") {
                public String toString() {
                    return first + " (" + second + ")";
                }
            };
        for (Class<?> clazz : clientPlugins)
            classes[cnt++] = new Pair<String, String>(clazz.getName(), "Reader client plugin") {
                public String toString() {
                    return first + " (" + second + ")";
                }
            };
        for (Class<?> clazz : serverPlugins)
            classes[cnt++] = new Pair<String, String>(clazz.getName(), "Reader server plugin") {
                public String toString() {
                    return first + " (" + second + ")";
                }
            };
        for (Class<?> clazz : inputPlugins)
            classes[cnt++] = new Pair<String, String>(clazz.getName(), "Reader input plugin") {
                public String toString() {
                    return first + " (" + second + ")";
                }
            };
        @SuppressWarnings("unchecked")
        Pair<String, String> res = (Pair<String, String>) JOptionPane.showInputDialog(this,
                "Please select an entry point for the plugin:", "Plugin entry point",
                JOptionPane.QUESTION_MESSAGE, null, classes, classes[0]);
        if (res != null)
            return res.first;
    } catch (Throwable e) {
        ErrorHandler.defaultHandler.submit(e);
    }
    return null;
}

From source file:org.isatools.isacreator.spreadsheet.Spreadsheet.java

/**
 * Create the FlatButton panel - a panel which contains graphical representations of the options available
 * to the user when interacting with the software.
 *///from   www .  ja  va2 s  .  com
private void createButtonPanel() {

    spreadsheetFunctionPanel = new JPanel();
    spreadsheetFunctionPanel.setLayout(new BoxLayout(spreadsheetFunctionPanel, BoxLayout.LINE_AXIS));
    spreadsheetFunctionPanel.setBackground(UIHelper.BG_COLOR);

    addRow = new JLabel(addRowButton);
    addRow.setToolTipText("<html><b>add row</b>" + "<p>add a new row to the table</p></html>");
    addRow.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent mouseEvent) {
            addRow.setIcon(addRowButton);
            showMultipleRowsGUI();
        }

        public void mouseEntered(MouseEvent mouseEvent) {
            addRow.setIcon(addRowButtonOver);
        }

        public void mouseExited(MouseEvent mouseEvent) {
            addRow.setIcon(addRowButton);
        }
    });

    deleteRow = new JLabel(deleteRowButton);
    deleteRow.setToolTipText("<html><b>remove row</b>" + "<p>remove selected row from table</p></html>");
    deleteRow.setEnabled(false);
    deleteRow.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent mouseEvent) {
            deleteRow.setIcon(deleteRowButton);
            if (table.getSelectedRow() != -1) {
                if (!(table.getSelectedRowCount() > 1)) {
                    spreadsheetFunctions.deleteRow(table.getSelectedRow());
                } else {
                    spreadsheetFunctions.deleteRow(table.getSelectedRows());
                }

            }
        }

        public void mouseEntered(MouseEvent mouseEvent) {
            deleteRow.setIcon(deleteRowButtonOver);
        }

        public void mouseExited(MouseEvent mouseEvent) {
            deleteRow.setIcon(deleteRowButton);
        }
    });

    deleteColumn = new JLabel(deleteColumnButton);
    deleteColumn
            .setToolTipText("<html><b>remove column</b>" + "<p>remove selected column from table</p></html>");
    deleteColumn.setEnabled(false);
    deleteColumn.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent mouseEvent) {
            deleteColumn.setIcon(deleteColumnButton);
            if (!(table.getSelectedColumns().length > 1)) {
                spreadsheetFunctions.deleteColumn(table.getSelectedColumn());
            } else {
                showColumnErrorMessage();
            }
        }

        public void mouseEntered(MouseEvent mouseEvent) {
            deleteColumn.setIcon(deleteColumnButtonOver);
        }

        public void mouseExited(MouseEvent mouseEvent) {
            deleteColumn.setIcon(deleteColumnButton);
        }
    });

    multipleSort = new JLabel(multipleSortButton);
    multipleSort.setToolTipText(
            "<html><b>multiple sort</b>" + "<p>perform a multiple sort on the table</p></html>");
    multipleSort.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent mouseEvent) {
            multipleSort.setIcon(multipleSortButton);
            showMultipleColumnSortGUI();
        }

        public void mouseEntered(MouseEvent mouseEvent) {
            multipleSort.setIcon(multipleSortButtonOver);
        }

        public void mouseExited(MouseEvent mouseEvent) {
            multipleSort.setIcon(multipleSortButton);
        }
    });

    copyColDown = new JLabel(copyColDownButton);
    copyColDown.setToolTipText("<html><b>copy column downwards</b>"
            + "<p>duplicate selected column and copy it from the current</p>"
            + "<p>position down to the final row in the table</p></html>");
    copyColDown.setEnabled(false);
    copyColDown.addMouseListener(new MouseAdapter() {

        public void mouseExited(MouseEvent mouseEvent) {
            copyColDown.setIcon(copyColDownButton);
        }

        public void mouseEntered(MouseEvent mouseEvent) {
            copyColDown.setIcon(copyColDownButtonOver);
        }

        public void mousePressed(MouseEvent mouseEvent) {
            copyColDown.setIcon(copyColDownButton);

            final int row = table.getSelectedRow();
            final int col = table.getSelectedColumn();

            if (row != -1 && col != -1) {
                JOptionPane copyColDownConfirmationPane = new JOptionPane(
                        "<html><b>Confirm Copy of Column...</b><p>Are you sure you wish to copy "
                                + "this column downwards?</p><p>This Action can not be undone!</p></html>",
                        JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);

                copyColDownConfirmationPane.setIcon(copyColumnDownWarningIcon);
                UIHelper.applyOptionPaneBackground(copyColDownConfirmationPane, UIHelper.BG_COLOR);

                copyColDownConfirmationPane.addPropertyChangeListener(new PropertyChangeListener() {
                    public void propertyChange(PropertyChangeEvent event) {
                        if (event.getPropertyName().equals(JOptionPane.VALUE_PROPERTY)) {
                            int lastOptionAnswer = Integer.valueOf(event.getNewValue().toString());
                            parentFrame.hideSheet();
                            if (lastOptionAnswer == JOptionPane.YES_OPTION) {
                                spreadsheetFunctions.copyColumnDownwards(row, col);
                            }
                        }
                    }
                });
                parentFrame.showJDialogAsSheet(
                        copyColDownConfirmationPane.createDialog(Spreadsheet.this, "Copy Column?"));
            }
        }
    });

    copyRowDown = new JLabel(copyRowDownButton);
    copyRowDown.setToolTipText(
            "<html><b>copy row downwards</b>" + "<p>duplicate selected row and copy it from the current</p>"
                    + "<p>position down to the final row</p></html>");
    copyRowDown.setEnabled(false);
    copyRowDown.addMouseListener(new MouseAdapter() {

        public void mouseExited(MouseEvent mouseEvent) {
            copyRowDown.setIcon(copyRowDownButton);
        }

        public void mouseEntered(MouseEvent mouseEvent) {
            copyRowDown.setIcon(copyRowDownButtonOver);
        }

        public void mousePressed(MouseEvent mouseEvent) {
            copyRowDown.setIcon(copyRowDownButton);

            final int row = table.getSelectedRow();

            JOptionPane copyRowDownConfirmationPane = new JOptionPane(
                    "<html><b>Confirm Copy of Row...</b><p>Are you sure you wish to copy "
                            + "this row downwards?</p><p>This Action can not be undone!</p>",
                    JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);

            copyRowDownConfirmationPane.setIcon(copyRowDownWarningIcon);

            UIHelper.applyOptionPaneBackground(copyRowDownConfirmationPane, UIHelper.BG_COLOR);

            copyRowDownConfirmationPane.addPropertyChangeListener(new PropertyChangeListener() {
                public void propertyChange(PropertyChangeEvent event) {
                    if (event.getPropertyName().equals(JOptionPane.VALUE_PROPERTY)) {
                        int lastOptionAnswer = Integer.valueOf(event.getNewValue().toString());
                        parentFrame.hideSheet();
                        if (lastOptionAnswer == JOptionPane.YES_OPTION) {
                            spreadsheetFunctions.copyRowDownwards(row);
                        }
                    }
                }
            });
            parentFrame.showJDialogAsSheet(
                    copyRowDownConfirmationPane.createDialog(Spreadsheet.this, "Copy Row Down?"));
        }
    });

    addProtocol = new JLabel(addProtocolButton);
    addProtocol.setToolTipText(
            "<html><b>add a protocol column</b>" + "<p>Add a protocol column to the table</p></html>");
    addProtocol.addMouseListener(new MouseAdapter() {

        public void mouseEntered(MouseEvent mouseEvent) {
            addProtocol.setIcon(addProtocolButtonOver);
        }

        public void mouseExited(MouseEvent mouseEvent) {
            addProtocol.setIcon(addProtocolButton);
        }

        public void mousePressed(MouseEvent mouseEvent) {
            addProtocol.setIcon(addProtocolButton);
            if (addProtocol.isEnabled()) {
                FieldObject fo = new FieldObject(table.getColumnCount(), "Protocol REF",
                        "Protocol used for experiment", DataTypes.LIST, "", false, false, false);

                fo.setFieldList(studyDataEntryEnvironment.getProtocolNames());

                spreadsheetFunctions.addFieldToReferenceObject(fo);

                spreadsheetFunctions.addColumnAfterPosition("Protocol REF", null, fo.isRequired(), -1);
            }
        }
    });

    addFactor = new JLabel(addFactorButton);
    addFactor.setToolTipText(
            "<html><b>add a factor column</b>" + "<p>Add a factor column to the table</p></html>");
    addFactor.addMouseListener(new MouseAdapter() {
        public void mouseEntered(MouseEvent mouseEvent) {
            addFactor.setIcon(addFactorButtonOver);
        }

        public void mouseExited(MouseEvent mouseEvent) {
            addFactor.setIcon(addFactorButton);
        }

        public void mousePressed(MouseEvent mouseEvent) {
            addFactor.setIcon(addFactorButton);
            if (addFactor.isEnabled()) {
                showAddColumnsGUI(AddColumnGUI.ADD_FACTOR_COLUMN);
            }
        }
    });

    addCharacteristic = new JLabel(addCharacteristicButton);
    addCharacteristic.setToolTipText("<html><b>add a characteristic column</b>"
            + "<p>Add a characteristic column to the table</p></html>");
    addCharacteristic.addMouseListener(new MouseAdapter() {
        public void mouseEntered(MouseEvent mouseEvent) {
            addCharacteristic.setIcon(addCharacteristicButtonOver);
        }

        public void mouseExited(MouseEvent mouseEvent) {
            addCharacteristic.setIcon(addCharacteristicButton);
        }

        public void mousePressed(MouseEvent mouseEvent) {
            addCharacteristic.setIcon(addCharacteristicButton);
            if (addCharacteristic.isEnabled()) {
                showAddColumnsGUI(AddColumnGUI.ADD_CHARACTERISTIC_COLUMN);
            }
        }
    });

    addParameter = new JLabel(addParameterButton);
    addParameter.setToolTipText(
            "<html><b>add a parameter column</b>" + "<p>Add a parameter column to the table</p></html>");
    addParameter.addMouseListener(new MouseAdapter() {
        public void mouseEntered(MouseEvent mouseEvent) {
            addParameter.setIcon(addParameterButtonOver);
        }

        public void mouseExited(MouseEvent mouseEvent) {
            addParameter.setIcon(addParameterButton);
        }

        public void mousePressed(MouseEvent mouseEvent) {
            addParameter.setIcon(addParameterButton);
            if (addParameter.isEnabled()) {
                showAddColumnsGUI(AddColumnGUI.ADD_PARAMETER_COLUMN);
            }
        }
    });

    undo = new JLabel(undoButton);
    undo.setToolTipText("<html><b>undo previous action<b></html>");
    undo.setEnabled(undoManager.canUndo());
    undo.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent mouseEvent) {
            undo.setIcon(undoButton);
            undoManager.undo();

            if (highlightActive) {
                setRowsToDefaultColor();
            }
            table.addNotify();
        }

        public void mouseEntered(MouseEvent mouseEvent) {
            undo.setIcon(undoButtonOver);
        }

        public void mouseExited(MouseEvent mouseEvent) {
            undo.setIcon(undoButton);
        }
    });

    redo = new JLabel(redoButton);
    redo.setToolTipText("<html><b>redo action<b></html>");
    redo.setEnabled(undoManager.canRedo());
    redo.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent mouseEvent) {
            redo.setIcon(redoButton);
            undoManager.redo();

            if (highlightActive) {
                setRowsToDefaultColor();
            }
            table.addNotify();

        }

        public void mouseEntered(MouseEvent mouseEvent) {
            redo.setIcon(redoButtonOver);
        }

        public void mouseExited(MouseEvent mouseEvent) {
            redo.setIcon(redoButton);
        }
    });

    transpose = new JLabel(transposeIcon);
    transpose.setToolTipText("<html>View a transposed version of this spreadsheet</html>");
    transpose.addMouseListener(new MouseAdapter() {

        public void mouseExited(MouseEvent mouseEvent) {
            transpose.setIcon(transposeIcon);
        }

        public void mouseEntered(MouseEvent mouseEvent) {
            transpose.setIcon(transposeIconOver);
        }

        public void mousePressed(MouseEvent mouseEvent) {
            showTransposeSpreadsheetGUI();
        }
    });

    addButtons();

    if (studyDataEntryEnvironment != null) {
        JPanel labelContainer = new JPanel(new GridLayout(1, 1));
        labelContainer.setBackground(UIHelper.BG_COLOR);

        JLabel lab = UIHelper.createLabel(spreadsheetTitle, UIHelper.VER_10_PLAIN, UIHelper.DARK_GREEN_COLOR,
                JLabel.RIGHT);
        lab.setBackground(UIHelper.BG_COLOR);
        lab.setVerticalAlignment(JLabel.CENTER);
        lab.setPreferredSize(new Dimension(200, 30));

        labelContainer.add(lab);

        spreadsheetFunctionPanel.add(labelContainer);
        spreadsheetFunctionPanel.add(Box.createHorizontalStrut(10));
    }

    add(spreadsheetFunctionPanel, BorderLayout.NORTH);
}

From source file:org.jajuk.base.Device.java

/**
 * Prepare manual refresh./*from w w  w.  j av a2  s.  c  o m*/
 * 
 * @param bAsk ask user to perform deep or fast refresh 
 * 
 * @return the user choice (deep or fast)
 * 
 * @throws JajukException if user canceled, device cannot be refreshed or device already
 * refreshing
 */
int prepareRefresh(final boolean bAsk) throws JajukException {
    if (bAsk) {
        final Object[] possibleValues = { Messages.getString("FilesTreeView.60"), // fast
                Messages.getString("FilesTreeView.61"), // deep
                Messages.getString("Cancel") };// cancel
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                @Override
                public void run() {
                    choice = JOptionPane.showOptionDialog(JajukMainWindow.getInstance(),
                            Messages.getString("FilesTreeView.59"), Messages.getString("Option"),
                            JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, possibleValues,
                            possibleValues[0]);
                }
            });
        } catch (Exception e) {
            Log.error(e);
            choice = Device.OPTION_REFRESH_CANCEL;
        }
        if (choice == Device.OPTION_REFRESH_CANCEL) { // Cancel
            return choice;
        }
    }
    // JajukException are not trapped, will be thrown to the caller
    final Device device = this;
    if (!device.isMounted()) {
        // Leave if user canceled device mounting
        if (!device.mount(true)) {
            return Device.OPTION_REFRESH_CANCEL;
        }
    }
    if (bAlreadyRefreshing) {
        throw new JajukException(107);
    }
    return choice;
}

From source file:org.jcurl.demo.tactics.JCurlShotPlanner.java

/** File Menu Action */
@Action/*  w w w .jav  a  2 s .c  om*/
public void fileOpenURL() {
    final String a = "fileOpenURL";
    if (!askDiscardUnsaved(gui.findAction(a)))
        return;
    final ResourceMap r = getContext().getResourceMap();
    final String title = r.getString(a + ".Dialog" + ".title");
    final String msg = r.getString(a + ".Dialog" + ".message");
    for (;;) {
        final String url = JOptionPane.showInputDialog(getMainFrame(), msg, title,
                JOptionPane.QUESTION_MESSAGE);
        if (url == null)
            return;
        try {
            setDocument(new URL(url));
            return;
        } catch (final IOException e) {
            showErrorDialog(r.getString(a + ".Dialog" + ".error", url), e);
        }
    }
}

From source file:org.jets3t.apps.cockpitlite.CockpitLite.java

/**
 * Performs the real work of downloading files by comparing the download candidates against
 * existing files, prompting the user whether to overwrite any pre-existing file versions,
 * and starting {@link S3ServiceMulti#downloadObjects} where the real work is done.
 *
 *//*  ww w  .  ja va2  s.  c  o m*/
private void performObjectsDownload(FileComparerResults comparisonResults, Map s3DownloadObjectsMap) {
    try {

        // Determine which files to download, prompting user whether to over-write existing files
        List objectKeysForDownload = new ArrayList();
        objectKeysForDownload.addAll(comparisonResults.onlyOnServerKeys);

        int newFiles = comparisonResults.onlyOnServerKeys.size();
        int unchangedFiles = comparisonResults.alreadySynchronisedKeys.size();
        int changedFiles = comparisonResults.updatedOnClientKeys.size()
                + comparisonResults.updatedOnServerKeys.size();

        if (unchangedFiles > 0 || changedFiles > 0) {
            // Ask user whether to replace existing unchanged and/or existing changed files.
            log.debug(
                    "Files for download clash with existing local files, prompting user to choose which files to replace");
            List options = new ArrayList();
            String message = "Of the " + (newFiles + unchangedFiles + changedFiles)
                    + " object(s) being downloaded:\n\n";

            if (newFiles > 0) {
                message += newFiles + " file(s) are new.\n\n";
                options.add(DOWNLOAD_NEW_FILES_ONLY);
            }
            if (changedFiles > 0) {
                message += changedFiles + " file(s) have changed.\n\n";
                options.add(DOWNLOAD_NEW_AND_CHANGED_FILES);
            }
            if (unchangedFiles > 0) {
                message += unchangedFiles + " file(s) already exist and are unchanged.\n\n";
                options.add(DOWNLOAD_ALL_FILES);
            }
            message += "Please choose which file(s) you wish to download:";

            Object response = JOptionPane.showInputDialog(ownerFrame, message, "Replace file(s)?",
                    JOptionPane.QUESTION_MESSAGE, null, options.toArray(), DOWNLOAD_NEW_AND_CHANGED_FILES);

            if (response == null) {
                return;
            }

            if (DOWNLOAD_NEW_FILES_ONLY.equals(response)) {
                // No change required to default objectKeysForDownload list.
            } else if (DOWNLOAD_ALL_FILES.equals(response)) {
                objectKeysForDownload.addAll(comparisonResults.updatedOnClientKeys);
                objectKeysForDownload.addAll(comparisonResults.updatedOnServerKeys);
                objectKeysForDownload.addAll(comparisonResults.alreadySynchronisedKeys);
            } else if (DOWNLOAD_NEW_AND_CHANGED_FILES.equals(response)) {
                objectKeysForDownload.addAll(comparisonResults.updatedOnClientKeys);
                objectKeysForDownload.addAll(comparisonResults.updatedOnServerKeys);
            } else {
                // Download cancelled.
                return;
            }
        }

        log.debug("Downloading " + objectKeysForDownload.size() + " objects");
        if (objectKeysForDownload.size() == 0) {
            return;
        }

        // Create array of objects for download.
        final S3Object[] objects = new S3Object[objectKeysForDownload.size()];
        int objectIndex = 0;
        for (Iterator iter = objectKeysForDownload.iterator(); iter.hasNext();) {
            objects[objectIndex++] = (S3Object) s3DownloadObjectsMap.get(iter.next());
        }

        (new Thread() {
            @Override
            public void run() {
                try {
                    SignatureRequest[] signedRequests = requestSignedRequests(
                            SignatureRequest.SIGNATURE_TYPE_GET, objects);

                    if (signedRequests != null) {
                        // Setup files to write to, creating parent directories when necessary.
                        downloadObjectsToFileMap = new HashMap();
                        ArrayList downloadPackageList = new ArrayList();
                        for (int i = 0; i < signedRequests.length; i++) {
                            S3Object object = signedRequests[i].buildObject();

                            File file = new File(downloadDirectory, object.getKey());

                            // Create local directories corresponding to objects flagged as dirs.
                            if (object.isDirectoryPlaceholder()) {
                                file = new File(downloadDirectory,
                                        ObjectUtils.convertDirPlaceholderKeyNameToDirName(objects[i].getKey()));
                                file.mkdirs();
                            }

                            DownloadPackage downloadPackage = ObjectUtils.createPackageForDownload(object, file,
                                    true, false, null);
                            if (downloadPackage == null) {
                                continue;
                            }
                            downloadPackage.setSignedUrl(signedRequests[i].getSignedUrl());

                            downloadObjectsToFileMap.put(object.getKey(), file);
                            downloadPackageList.add(downloadPackage);
                        }
                        DownloadPackage[] downloadPackagesArray = (DownloadPackage[]) downloadPackageList
                                .toArray(new DownloadPackage[downloadPackageList.size()]);

                        // Perform downloads.
                        s3ServiceMulti.downloadObjects(downloadPackagesArray);
                    }
                } catch (Exception e) {
                    log.error("Download failed", e);
                    ErrorDialog.showDialog(ownerFrame, null, cockpitLiteProperties.getProperties(),
                            "Download failed, please try again", e);
                }
            }
        }).start();
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        String message = "Unable to download objects";
        log.error(message, e);
        ErrorDialog.showDialog(ownerFrame, this, cockpitLiteProperties.getProperties(), message, e);
    }
}

From source file:org.jets3t.apps.cockpitlite.CockpitLite.java

private void performFilesUpload(FileComparerResults comparisonResults,
        Map<String, String> objectKeyToFilepathMap) {
    try {/*  w w  w.  jav  a2 s.  c o  m*/
        // Determine which files to upload, prompting user whether to over-write existing files
        List fileKeysForUpload = new ArrayList();
        fileKeysForUpload.addAll(comparisonResults.onlyOnClientKeys);

        int newFiles = comparisonResults.onlyOnClientKeys.size();
        int unchangedFiles = comparisonResults.alreadySynchronisedKeys.size();
        int changedFiles = comparisonResults.updatedOnClientKeys.size()
                + comparisonResults.updatedOnServerKeys.size();

        if (unchangedFiles > 0 || changedFiles > 0) {
            // Ask user whether to replace existing unchanged and/or existing changed files.
            log.debug(
                    "Files for upload clash with existing S3 objects, prompting user to choose which files to replace");
            List options = new ArrayList();
            String message = "Of the " + objectKeyToFilepathMap.size() + " file(s) being uploaded:\n\n";

            if (newFiles > 0) {
                message += newFiles + " file(s) are new.\n\n";
                options.add(UPLOAD_NEW_FILES_ONLY);
            }
            if (changedFiles > 0) {
                message += changedFiles + " file(s) have changed.\n\n";
                options.add(UPLOAD_NEW_AND_CHANGED_FILES);
            }
            if (unchangedFiles > 0) {
                message += unchangedFiles + " file(s) already exist and are unchanged.\n\n";
                options.add(UPLOAD_ALL_FILES);
            }
            message += "Please choose which file(s) you wish to upload:";

            Object response = JOptionPane.showInputDialog(ownerFrame, message, "Replace file(s)?",
                    JOptionPane.QUESTION_MESSAGE, null, options.toArray(), UPLOAD_NEW_AND_CHANGED_FILES);

            if (response == null) {
                return;
            }

            if (UPLOAD_NEW_FILES_ONLY.equals(response)) {
                // No change required to default fileKeysForUpload list.
            } else if (UPLOAD_ALL_FILES.equals(response)) {
                fileKeysForUpload.addAll(comparisonResults.updatedOnClientKeys);
                fileKeysForUpload.addAll(comparisonResults.updatedOnServerKeys);
                fileKeysForUpload.addAll(comparisonResults.alreadySynchronisedKeys);
            } else if (UPLOAD_NEW_AND_CHANGED_FILES.equals(response)) {
                fileKeysForUpload.addAll(comparisonResults.updatedOnClientKeys);
                fileKeysForUpload.addAll(comparisonResults.updatedOnServerKeys);
            } else {
                // Upload cancelled.
                stopProgressDialog();
                return;
            }
        }

        if (fileKeysForUpload.size() == 0) {
            return;
        }

        final String[] statusText = new String[1];
        statusText[0] = "Prepared 0 of " + fileKeysForUpload.size() + " file(s) for upload";
        startProgressDialog(statusText[0], "", 0, 100, null, null);

        long bytesToProcess = 0;
        for (Iterator iter = fileKeysForUpload.iterator(); iter.hasNext();) {
            File file = new File(objectKeyToFilepathMap.get(iter.next().toString()));
            bytesToProcess += file.length();
        }

        BytesProgressWatcher progressWatcher = new BytesProgressWatcher(bytesToProcess) {
            @Override
            public void updateBytesTransferred(long byteCount) {
                super.updateBytesTransferred(byteCount);

                String detailsText = formatBytesProgressWatcherDetails(this, false);
                int progressValue = (int) ((double) getBytesTransferred() * 100 / getBytesToTransfer());
                updateProgressDialog(statusText[0], detailsText, progressValue);
            }
        };

        // Populate S3Objects representing upload files with metadata etc.
        final S3Object[] objects = new S3Object[fileKeysForUpload.size()];
        int objectIndex = 0;
        for (Iterator iter = fileKeysForUpload.iterator(); iter.hasNext();) {
            String fileKey = iter.next().toString();
            File file = new File(objectKeyToFilepathMap.get(fileKey));

            S3Object newObject = ObjectUtils.createObjectForUpload(fileKey, file, null, false, progressWatcher);

            statusText[0] = "Prepared " + (objectIndex + 1) + " of " + fileKeysForUpload.size()
                    + " file(s) for upload";

            objects[objectIndex++] = newObject;
        }

        stopProgressDialog();

        // Confirm we have permission to do this.
        SignatureRequest[] signedRequests = requestSignedRequests(SignatureRequest.SIGNATURE_TYPE_PUT, objects);

        if (signedRequests != null) {
            // Upload the files.
            SignedUrlAndObject[] urlAndObjs = new SignedUrlAndObject[signedRequests.length];
            for (int i = 0; i < signedRequests.length; i++) {
                urlAndObjs[i] = new SignedUrlAndObject(signedRequests[i].getSignedUrl(), objects[i]);
            }

            s3ServiceMulti.putObjects(urlAndObjs);
        }

    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        stopProgressDialog();
        String message = "Unable to upload object(s)";
        log.error(message, e);
        ErrorDialog.showDialog(ownerFrame, this, cockpitLiteProperties.getProperties(), message, e);
    }
}