Ejemplo n.º 1
0
  private void loadBookmarks(JTable table) {
    final BookmarksTableModel btm = (BookmarksTableModel) table.getModel();
    List<Bookmark> bookmarks = btm.getData();

    if (bookmarks.size() > 0) {
      String message = "Clear existing bookmarks?";
      String title = "Clear Bookmarks";
      // display the JOptionPane showConfirmDialog
      int reply = JOptionPane.showConfirmDialog(null, message, title, JOptionPane.YES_NO_OPTION);
      if (reply == JOptionPane.YES_OPTION) {
        btm.clearData();
        BookmarkController.getInstance().clearBookmarks();
      }
    }

    final File selectedFile = DialogUtils.chooseFileForOpen("Load Bookmarks", null, null);

    // set the genome
    if (selectedFile != null) {

      int result =
          JOptionPane.showOptionDialog(
              null,
              "Would you like to add padding to each bookmark range?",
              "Add a margin?",
              JOptionPane.YES_NO_OPTION,
              JOptionPane.QUESTION_MESSAGE,
              null,
              null,
              null);
      final boolean addMargin = (result == JOptionPane.YES_OPTION);

      Window w = SwingUtilities.getWindowAncestor(BookmarkSheet.this);
      JOptionPane optionPane =
          new JOptionPane(
              "<html>Loading bookmarks from file.<br>This may take a moment.</html>",
              JOptionPane.INFORMATION_MESSAGE,
              JOptionPane.CANCEL_OPTION);
      final JDialog dialog = new JDialog(w, "Loading Bookmarks", Dialog.ModalityType.MODELESS);
      dialog.setContentPane(optionPane);
      dialog.pack();
      dialog.setLocationRelativeTo(w);
      dialog.setVisible(true);
      new Thread("BookmarkSheet.loadBookmarks") {
        @Override
        public void run() {
          try {
            BookmarkController.getInstance().addBookmarksFromFile(selectedFile, addMargin);
            btm.fireTableDataChanged();
          } catch (Exception ex) {
            DialogUtils.displayError("Error", "Unable to load bookmarks: " + ex.getMessage());
          } finally {
            dialog.setVisible(false);
            dialog.dispose();
          }
        }
      }.start();
    }
  }
Ejemplo n.º 2
0
 @Override
 public void handleEvent(BookmarksChangedEvent event) {
   refreshData(BookmarkController.getInstance().getBookmarks());
 }