Esempio 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();
    }
  }
Esempio n. 2
0
 public void goToBookmark(int viewRow) {
   if (viewRow == -1 || table.getRowCount() == 0) {
     return;
   }
   LocationController lc = LocationController.getInstance();
   BookmarksTableModel tableModel = (BookmarksTableModel) table.getModel();
   Bookmark bookmark = tableModel.getData().get(table.convertRowIndexToModel(viewRow));
   lc.setLocation(bookmark.getReference(), (Range) bookmark.getRange());
 }
Esempio n. 3
0
  private static void saveBookmarks(JTable table) {
    BookmarksTableModel btm = (BookmarksTableModel) table.getModel();
    List<Bookmark> bookmarks = btm.getData();

    // get the path (null if none selected)
    File selectedFile = DialogUtils.chooseFileForSave("Save Bookmarks", "Bookmarks.txt");

    // set the genome
    if (selectedFile != null) {
      try {
        saveBookmarks(selectedFile.getAbsolutePath(), bookmarks);
      } catch (IOException ex) {
        DialogUtils.displayError("Error", "Unable to save bookmarks: " + ex.getMessage());
      }
    }
  }