Ejemplo n.º 1
0
  /** Read the entries given in the uk.ac.sanger.artemis.ini file. */
  private void readDefaultEntries() {
    final EntryInformation artemis_entry_information = Options.getArtemisEntryInformation();

    final String default_sequence_file_name = Options.getOptions().getDefaultSequenceFileName();

    final String default_feature_file_name = Options.getOptions().getDefaultFeatureFileName();

    if (default_sequence_file_name != null) {
      final String default_sequence_file_name_embl = default_sequence_file_name + "_embl";

      uk.ac.sanger.artemis.io.Entry new_embl_entry = null;

      // try opening the default sequence file with "_embl" added to the name
      // if that fails try the plain sequence file name

      final Document entry_document = DocumentFactory.makeDocument(default_sequence_file_name_embl);

      final InputStreamProgressListener progress_listener = getInputStreamProgressListener();

      entry_document.addInputStreamProgressListener(progress_listener);

      if (entry_document.readable()) {
        new_embl_entry =
            EntryFileDialog.getEntryFromFile(
                this, entry_document, artemis_entry_information, false);
      }

      if (new_embl_entry == null
          || new_embl_entry.getSequence() == null
          || new_embl_entry.getSequence().length() == 0) {
        final File entry_file = new File(default_sequence_file_name);

        if (entry_file.exists()) {
          new_embl_entry =
              EntryFileDialog.getEntryFromFile(
                  this, entry_document, artemis_entry_information, false);
        } else {
          // read failed
          System.err.println(
              "file does not exist: " + default_sequence_file_name + "(given in options files)");
          return;
        }
      }

      if (new_embl_entry == null
          || new_embl_entry.getSequence() == null
          || new_embl_entry.getSequence().length() == 0) {
        // read failed
        System.err.println(
            "failed to read " + default_sequence_file_name + "(given in options files)");
        return;
      }

      getStatusLabel().setText("");

      try {
        final Entry entry = new Entry(new_embl_entry);

        final EntryEdit new_entry_edit = makeEntryEdit(entry);

        new_entry_edit.setVisible(true);

        if (default_feature_file_name != null) {
          final Document feature_document = DocumentFactory.makeDocument(default_feature_file_name);

          final uk.ac.sanger.artemis.io.Entry new_embl_table_entry =
              EntryFileDialog.getEntryFromFile(
                  this, feature_document, artemis_entry_information, false);

          if (new_embl_table_entry == null) // open failed
          return;

          final EntryGroup entry_group = new_entry_edit.getEntryGroup();

          final Entry new_table_entry = new Entry(entry.getBases(), new_embl_table_entry);

          entry_group.add(new_table_entry);
        }
      } catch (OutOfRangeException e) {
        new MessageDialog(
            this,
            "read failed: one of the features in "
                + default_feature_file_name
                + " has an out of range location: "
                + e.getMessage());
      } catch (NoSequenceException e) {
        new MessageDialog(
            this, "read failed: " + new_embl_entry.getName() + " contains no sequence");
      }
    }
  }
Ejemplo n.º 2
0
  /**
   * Create a new FeatureListFrame component. The constructor does not call setVisible (true).
   *
   * @param title The title to use for the new JFrame.
   * @param feature_list The FeatureList to show.
   * @param selection The Selection that the commands in the menus will operate on.
   * @param entry_group The EntryGroup object where new features/entries will be added.
   * @param goto_event_source The object that the menu item will call makeBaseVisible() on.
   */
  public FeatureListFrame(
      final String title,
      final Selection selection,
      final GotoEventSource goto_event_source,
      final EntryGroup entry_group,
      final BasePlotGroup base_plot_group) {
    super(title);

    this.entry_group = entry_group;

    feature_list = new FeatureList(entry_group, selection, goto_event_source, base_plot_group);

    final Font default_font = Options.getOptions().getFont();
    setFont(default_font);

    final JMenuBar menu_bar = new JMenuBar();
    menu_bar.setFont(default_font);
    setJMenuBar(menu_bar);

    final JMenu file_menu = new JMenu("File");
    final JMenuItem close = new JMenuItem("Close");
    close.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            setVisible(false);
            FeatureListFrame.this.dispose();
            feature_list.stopListening();
          }
        });

    file_menu.add(close);
    menu_bar.add(file_menu);

    final JMenu select_menu =
        new SelectMenu(this, selection, goto_event_source, entry_group, base_plot_group);
    menu_bar.add(select_menu);

    final JMenu view_menu =
        new ViewMenu(this, selection, goto_event_source, entry_group, base_plot_group);
    menu_bar.add(view_menu);

    final JMenu goto_menu = new GotoMenu(this, selection, goto_event_source, entry_group);
    menu_bar.add(goto_menu);

    if (Options.readWritePossible()) {
      final JMenu edit_menu =
          new EditMenu(this, selection, goto_event_source, entry_group, base_plot_group, null);
      menu_bar.add(edit_menu);

      final JMenu write_menu = new WriteMenu(this, selection, entry_group);
      menu_bar.add(write_menu);

      final JMenu run_menu = new RunMenu(this, selection);
      menu_bar.add(run_menu);
    }

    final JScrollPane jsp_feature_list = new JScrollPane(feature_list);
    getContentPane().add(jsp_feature_list, "Center");

    final JPanel panel = new JPanel();

    final JButton close_button = new JButton("Close");

    panel.add(close_button);
    close_button.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            setVisible(false);
            FeatureListFrame.this.dispose();
            feature_list.stopListening();
          }
        });

    getContentPane().add(panel, "South");
    pack();

    addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent event) {
            setVisible(false);
            entry_group.removeEntryGroupChangeListener(FeatureListFrame.this);
            FeatureListFrame.this.dispose();
            feature_list.stopListening();
          }
        });

    entry_group.addEntryGroupChangeListener(this);

    final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();

    int screen_height = screen.height;
    int screen_width = screen.width;

    if (screen_width <= 700 || screen_height <= 400)
      setSize(screen_width * 9 / 10, screen_height * 9 / 10);
    else setSize(700, 400);

    final int hgt = entry_group.getAllFeaturesCount() * feature_list.getLineHeight();
    feature_list.setPreferredSize(new Dimension(getSize().width * 4, hgt));
    jsp_feature_list.getVerticalScrollBar().setUnitIncrement(feature_list.getLineHeight());

    setLocation(
        new Point((screen.width - getSize().width) / 2, (screen.height - getSize().height) / 2));
  }