Exemple #1
0
  /**
   * Make the view menu
   *
   * @param viewMenu view menu
   * @return The view menu
   */
  public JMenu makeViewMenu(JMenu viewMenu) {
    showAlignmentPointsMI = new JCheckBoxMenuItem("Show Alignment Points", true);
    viewMenu.add(showAlignmentPointsMI);
    showAlignmentPointsMI.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            repaint();
          }
        });

    viewMenu.addSeparator();
    super.makeViewMenu(viewMenu);
    viewMenu.addSeparator();
    viewMenu.add(makeMenuItem("Black background", CMD_BLACKBG));
    viewMenu.add(makeMenuItem("White background", CMD_WHITEBG));
    return viewMenu;
  }
Exemple #2
0
  /**
   * Show the saved results on the server.
   *
   * @param mysettings jemboss settings
   * @param frameName title name for frame
   */
  public ShowSavedResults(final JembossParams mysettings, final JFrame f) {

    this("Saved results list" + (Jemboss.withSoap ? " on server" : ""));

    try {
      final ResultList reslist = new ResultList(mysettings);
      JMenu resFileMenu = new JMenu("File");
      resMenu.add(resFileMenu);

      final JCheckBoxMenuItem listByProgram = new JCheckBoxMenuItem("List by program");
      listByProgram.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              listByProgramName();
            }
          });
      resFileMenu.add(listByProgram);

      JCheckBoxMenuItem listByDate = new JCheckBoxMenuItem("List by date", true);
      listByDate.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              listByDateRun(reslist, false);
            }
          });
      resFileMenu.add(listByDate);

      ButtonGroup group = new ButtonGroup();
      group.add(listByProgram);
      group.add(listByDate);

      JButton refresh = new JButton(rfii);
      refresh.setMargin(new Insets(0, 1, 0, 1));
      refresh.setToolTipText("Refresh");
      resMenu.add(refresh);

      refresh.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              try {
                setCursor(cbusy);
                ResultList newlist = new ResultList(mysettings);
                setCursor(cdone);
                if (newlist.getStatus().equals("0")) {
                  reslist.updateRes(newlist.hash());
                  datasets.removeAllElements();

                  StringTokenizer tok = new StringTokenizer((String) reslist.get("list"), "\n");
                  while (tok.hasMoreTokens()) datasets.addElement(convertToPretty(tok.nextToken()));

                  if (listByProgram.isSelected()) listByProgramName();
                  else listByDateRun(reslist, false);
                } else {
                  JOptionPane.showMessageDialog(
                      null, newlist.getStatusMsg(), "Soap Error", JOptionPane.ERROR_MESSAGE);
                }
              } catch (JembossSoapException eae) {
                AuthPopup ap = new AuthPopup(mysettings, f);
                ap.setBottomPanel();
                ap.setSize(380, 170);
                ap.pack();
                ap.setVisible(true);
              }
            }
          });

      resFileMenu.addSeparator();
      JMenuItem resFileMenuExit = new JMenuItem("Close");
      resFileMenuExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.CTRL_MASK));

      resFileMenuExit.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              dispose();
            }
          });
      resFileMenu.add(resFileMenuExit);
      setJMenuBar(resMenu);

      // this is the list of saved results
      listByDateRun(reslist, true);

      final JList st = new JList(datasets);
      st.setCellRenderer(new TabListCellRenderer());

      st.addListSelectionListener(
          new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
              if (e.getValueIsAdjusting()) return;

              JList theList = (JList) e.getSource();
              if (theList.isSelectionEmpty()) {
                System.out.println("Empty selection");
              } else {
                int index = theList.getSelectedIndex();
                String thisdata = convertToOriginal(datasets.elementAt(index));
                aboutRes.setText((String) reslist.get(thisdata));
                aboutRes.setCaretPosition(0);
              }
            }
          });

      st.addMouseListener(
          new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
              if (e.getClickCount() == 2) {
                try {
                  setCursor(cbusy);
                  String project = convertToOriginal(st.getSelectedValue());
                  ResultList thisres = new ResultList(mysettings, project, "show_saved_results");
                  new ShowResultSet(thisres.hash(), project, mysettings);
                  setCursor(cdone);
                } catch (JembossSoapException eae) {
                  AuthPopup ap = new AuthPopup(mysettings, f);
                  ap.setBottomPanel();
                  ap.setSize(380, 170);
                  ap.pack();
                  ap.setVisible(true);
                }
              }
            }
          });
      sp.add(st);

      // display retrieves all files and shows them in a window
      JPanel resButtonPanel = new JPanel();
      JButton showResButton = new JButton("Display");
      showResButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              String sel = convertToOriginal(st.getSelectedValue());
              if (sel != null) {
                try {
                  setCursor(cbusy);
                  ResultList thisres = new ResultList(mysettings, sel, "show_saved_results");
                  if (thisres.hash().size() == 0)
                    JOptionPane.showMessageDialog(
                        sp,
                        "This application launch '" + sel + "' didn't produce any result files.");
                  else new ShowResultSet(thisres.hash(), sel, mysettings);
                  setCursor(cdone);
                } catch (JembossSoapException eae) {
                  AuthPopup ap = new AuthPopup(mysettings, f);
                  ap.setBottomPanel();
                  ap.setSize(380, 170);
                  ap.pack();
                  ap.setVisible(true);
                }
              } else {
                statusField.setText("Nothing selected to be displayed.");
              }
            }
          });

      // add a users note for that project
      JButton addNoteButton = new JButton("Edit Notes");
      addNoteButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              String sel = convertToOriginal(st.getSelectedValue());
              if (sel != null) {
                try {
                  setCursor(cbusy);
                  ResultList thisres =
                      new ResultList(mysettings, sel, "Notes", "show_saved_results");
                  new ShowResultSet(thisres.hash(), sel, mysettings);
                  setCursor(cdone);
                } catch (JembossSoapException eae) {
                  AuthPopup ap = new AuthPopup(mysettings, f);
                  ap.setBottomPanel();
                  ap.setSize(380, 170);
                  ap.pack();
                  ap.setVisible(true);
                }
              } else {
                statusField.setText("Selected a project!");
              }
            }
          });

      // delete removes the file on the server & edits the list
      JButton delResButton = new JButton("Delete");
      delResButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              Object sel[] = st.getSelectedValues();
              if (sel != null) {
                String selList = new String("");
                JTextPane delList = new JTextPane();
                FontMetrics fm = delList.getFontMetrics(delList.getFont());
                int maxWidth = 0;
                for (int i = 0; i < sel.length; i++) {
                  if (i == sel.length - 1) selList = selList.concat((String) sel[i]);
                  else selList = selList.concat(sel[i] + "\n");

                  int width = fm.stringWidth((String) sel[i]);
                  if (width > maxWidth) maxWidth = width;
                }
                int ok = JOptionPane.OK_OPTION;
                if (sel.length > 1) {
                  JScrollPane scrollDel = new JScrollPane(delList);
                  delList.setText(selList);
                  delList.setEditable(false);
                  delList.setCaretPosition(0);

                  Dimension d1 = delList.getPreferredSize();
                  int maxHeight = (int) d1.getHeight() + 5;
                  if (maxHeight > 350) maxHeight = 350;
                  else if (maxHeight < 50) maxHeight = 50;

                  scrollDel.setPreferredSize(new Dimension(maxWidth + 30, maxHeight));

                  ok =
                      JOptionPane.showConfirmDialog(
                          null, scrollDel, "Confirm Deletion", JOptionPane.YES_NO_OPTION);
                }
                if (ok == JOptionPane.OK_OPTION) {
                  try // ask the server to delete these results
                  {
                    setCursor(cbusy);
                    selList = convertToOriginal(selList);
                    new ResultList(mysettings, selList, "delete_saved_results");
                    setCursor(cdone);

                    // amend the list
                    for (int i = 0; i < sel.length; i++) datasets.removeElement(sel[i]);

                    statusField.setText("Deleted " + sel.length + "  result(s)");

                    aboutRes.setText("");
                    st.setSelectedIndex(-1);
                  } catch (JembossSoapException eae) {
                    AuthPopup ap = new AuthPopup(mysettings, f);
                    ap.setBottomPanel();
                    ap.setSize(380, 170);
                    ap.pack();
                    ap.setVisible(true);
                  }
                }
              } else {
                statusField.setText("Nothing selected for deletion.");
              }
            }
          });
      resButtonPanel.add(delResButton);
      resButtonPanel.add(addNoteButton);
      resButtonPanel.add(showResButton);
      resButtonStatus.add(resButtonPanel, BorderLayout.CENTER);
      resButtonStatus.add(statusField, BorderLayout.SOUTH);

      Container c = getContentPane();
      c.add(ss, BorderLayout.WEST);
      c.add(aboutScroll, BorderLayout.CENTER);
      c.add(resButtonStatus, BorderLayout.SOUTH);
      pack();

      setVisible(true);
    } catch (JembossSoapException eae) {
      AuthPopup ap = new AuthPopup(mysettings, f);
      ap.setBottomPanel();
      ap.setSize(380, 170);
      ap.pack();
      ap.setVisible(true);
    }
  }
    /** Create the UI for this editor */
    void makeUI() {

      JPanel mainPanel = new JPanel(new BorderLayout());
      mainPanel.setBorder(new LineBorder(Color.blue));
      getContentPane().add(mainPanel, BorderLayout.CENTER);

      // the map and associated toolbar
      npEditControl = new NPController();
      mapEditPanel = npEditControl.getNavigatedPanel(); // here's where the map will be drawn
      mapEditPanel.setPreferredSize(new Dimension(250, 250));
      mapEditPanel.setSelectRegionMode(true);
      JToolBar navToolbar = mapEditPanel.getNavToolBar();
      navToolbar.setFloatable(false);
      JToolBar moveToolbar = mapEditPanel.getMoveToolBar();
      moveToolbar.setFloatable(false);
      // toolbar.remove("setReference");

      JPanel toolbar = new JPanel();
      List localMaps = maps;
      if (localMaps == null) {
        localMaps = getDefaultMaps();
      }
      JMenu mapMenu = new JMenu("Maps");
      JMenuBar menuHolder = new JMenuBar();
      menuHolder.setBorder(null);
      menuHolder.add(mapMenu);
      toolbar.add(menuHolder);
      for (int mapIdx = 0; mapIdx < localMaps.size(); mapIdx++) {
        final MapData mapData = (MapData) localMaps.get(mapIdx);
        final JCheckBoxMenuItem cbx =
            new JCheckBoxMenuItem(mapData.getDescription(), mapData.getVisible());
        if (mapData.getVisible()) {
          toggleMap(mapData, true);
        }
        mapMenu.add(cbx);
        cbx.addItemListener(
            new ItemListener() {
              public void itemStateChanged(ItemEvent event) {
                toggleMap(mapData, cbx.isSelected());
              }
            });
      }
      GuiUtils.limitMenuSize(mapMenu, "Maps ", 20);

      toolbar.add(navToolbar);
      toolbar.add(moveToolbar);

      JPanel mapSide = new JPanel();
      mapSide.setLayout(new BorderLayout());
      TitledBorder mapBorder =
          new TitledBorder(
              standardBorder, "Edit Projection", TitledBorder.ABOVE_TOP, TitledBorder.CENTER);
      mapSide.setBorder(mapBorder);
      mapSide.add(toolbar, BorderLayout.NORTH);
      mapSide.add(mapEditPanel, BorderLayout.CENTER);
      mainPanel.add(mapSide, BorderLayout.WEST);

      // the projection parameters

      // the Projection name
      JLabel nameLabel = GuiUtils.rLabel("Name: ");
      nameTF = new JTextField(20);

      // the list of Projection classes is kept in a comboBox
      typeLabel = GuiUtils.rLabel("Type: ");
      projClassCB = new JComboBox();
      // standard list of projection classes
      List classNames = getDefaultProjections();
      for (int i = 0; i < classNames.size(); i++) {
        String className = (String) classNames.get(i);
        try {
          projClassCB.addItem(new ProjectionClass(className));
        } catch (ClassNotFoundException ee) {
          System.err.println("ProjectionManager failed on " + className + " " + ee);
        } catch (IntrospectionException ee) {
          System.err.println("ProjectionManager failed on " + className + " " + ee);
        }
      }
      GuiUtils.tmpInsets = new Insets(4, 4, 4, 4);
      JPanel topPanel =
          GuiUtils.doLayout(
              new Component[] {nameLabel, nameTF, typeLabel, projClassCB},
              2,
              GuiUtils.WT_N,
              GuiUtils.WT_N);

      // the Projection parameter area
      paramPanel = new JPanel();
      paramPanel.setLayout(new BorderLayout());
      paramPanel.setBorder(
          new TitledBorder(
              standardBorder,
              "Projection Parameters",
              TitledBorder.ABOVE_TOP,
              TitledBorder.CENTER));

      // the bottom button panel
      JPanel buttPanel = new JPanel();
      JButton acceptButton = new JButton("Save");
      JButton previewButton = new JButton("Preview");
      JButton cancelButton = new JButton("Cancel");
      buttPanel.add(acceptButton, null);
      buttPanel.add(previewButton, null);
      buttPanel.add(cancelButton, null);

      JPanel mainBox = GuiUtils.topCenterBottom(topPanel, paramPanel, buttPanel);
      mainPanel.add(mainBox, BorderLayout.CENTER);
      pack();

      // enable event listeners when we're done constructing the UI
      projClassCB.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              ProjectionClass selectClass = (ProjectionClass) projClassCB.getSelectedItem();
              setProjection(selectClass.makeDefaultProjection());
            }
          });

      acceptButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
              accept();
            }
          });
      previewButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
              ProjectionClass projClass = findProjectionClass(editProjection);
              if (null != projClass) {
                setProjFromDialog(projClass, editProjection);
                setProjection(editProjection);
              }
            }
          });
      cancelButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
              NewProjectionDialog.this.setVisible(false);
            }
          });
    }
Exemple #4
0
  /**
   * Set up the menu bar.
   *
   * @return The JMenuBar we set up.
   */
  private JMenuBar setupMenuBar() {
    JMenuBar menuBar = new JMenuBar();

    /* File */
    JMenu fileMenu = new JMenu("File");
    menuBar.add(fileMenu);

    /* File -> Open CSV */
    JMenuItem miFileOpenCSV =
        new JMenuItem(
            new AbstractAction("Open CSV") {
              @Override
              public void actionPerformed(ActionEvent e) {
                FileDialog fd =
                    new FileDialog(mainFrame, "Open Darwin CSV file ...", FileDialog.LOAD);
                fd.setVisible(true);
                File file;
                if (fd.getDirectory() != null) {
                  file = new File(fd.getDirectory(), fd.getFile());
                } else if (fd.getFile() != null) {
                  file = new File(fd.getFile());
                } else {
                  return;
                }

                // Clear out old file.
                loadFile(null);

                // SwingWorker MAGIC!
                new MainFrameWorker("loading file '" + file + "'", file) {
                  @Override
                  protected Object doInBackground() throws Exception {
                    System.err.println("Loading file: " + input);
                    loadFile((File) input, DarwinCSV.FILE_CSV_DELIMITED);

                    return null;
                  }
                }.execute();
              }
            });
    fileMenu.add(miFileOpenCSV);

    /* File -> Open CSV without UI */
    JMenuItem miFileOpenCSVnoUI =
        new JMenuItem(
            new AbstractAction("Open CSV without UI") {
              @Override
              public void actionPerformed(ActionEvent e) {
                FileDialog fd =
                    new FileDialog(mainFrame, "Open Darwin CSV file ...", FileDialog.LOAD);
                fd.setVisible(true);

                File file;
                if (fd.getDirectory() != null) {
                  file = new File(fd.getDirectory(), fd.getFile());
                } else if (fd.getFile() != null) {
                  file = new File(fd.getFile());
                } else {
                  return;
                }

                // Clear out old file
                loadFile(null);

                loadFile(file, DarwinCSV.FILE_CSV_DELIMITED);
              }
            });
    fileMenu.add(miFileOpenCSVnoUI);

    /* File -> Open tab-delimited */
    JMenuItem miFileOpenTab =
        new JMenuItem(
            new AbstractAction("Open tab-delimited") {
              @Override
              public void actionPerformed(ActionEvent e) {
                FileDialog fd =
                    new FileDialog(
                        mainFrame, "Open Darwin tab-delimited file ...", FileDialog.LOAD);
                fd.setVisible(true);

                File file;
                if (fd.getDirectory() != null) {
                  file = new File(fd.getDirectory(), fd.getFile());
                } else if (fd.getFile() != null) {
                  file = new File(fd.getFile());
                } else {
                  return;
                }

                // Clear out old file
                loadFile(null);

                // SwingWorker MAGIC!
                new MainFrameWorker("loading file '" + file + "'", file) {
                  @Override
                  protected Object doInBackground() throws Exception {
                    loadFile((File) input, DarwinCSV.FILE_TAB_DELIMITED);

                    return null;
                  }
                }.execute();
              }
            });
    fileMenu.add(miFileOpenTab);

    /* File -> Save CSV */
    JMenuItem miFileSave =
        new JMenuItem(
            new AbstractAction("Save as CSV") {
              @Override
              public void actionPerformed(ActionEvent e) {
                FileDialog fd =
                    new FileDialog(mainFrame, "Save Darwin CSV file ...", FileDialog.SAVE);
                fd.setVisible(true);

                File file;
                if (fd.getDirectory() != null) {
                  file = new File(fd.getDirectory(), fd.getFile());
                } else if (fd.getFile() != null) {
                  file = new File(fd.getFile());
                } else {
                  return;
                }

                // SwingWorker MAGIC!
                new MainFrameWorker("saving CSV file '" + file + "'", file) {
                  @Override
                  protected Object doInBackground() throws Exception {
                    currentCSV.saveToFile((File) input, DarwinCSV.FILE_CSV_DELIMITED);

                    return null;
                  }
                }.execute();
              }
            });
    fileMenu.add(miFileSave);

    /* File -> Exit */
    JMenuItem miFileExit =
        new JMenuItem(
            new AbstractAction("Exit") {
              @Override
              public void actionPerformed(ActionEvent e) {
                mainFrame.setVisible(false);
                mainFrame.dispose();
              }
            });
    fileMenu.add(miFileExit);

    /* Match */
    JMenu matchMenu = new JMenu("Match");
    menuBar.add(matchMenu);

    /* Match -> Against CSV */
    JMenuItem miMatchCSV =
        new JMenuItem(
            new AbstractAction("Match against CSV") {
              @Override
              public void actionPerformed(ActionEvent e) {
                FileDialog fd =
                    new FileDialog(
                        mainFrame, "Open Darwin CSV file for matching ...", FileDialog.LOAD);
                fd.setVisible(true);

                if (fd.getFile() == null) return;

                File file = new File(fd.getFile());
                if (fd.getDirectory() != null) {
                  file = new File(fd.getDirectory(), fd.getFile());
                }

                // Clear out old match against.
                matchAgainst(null);

                // SwingWorker MAGIC!
                new MainFrameWorker("matching against file '" + file + "'", file) {
                  @Override
                  protected Object doInBackground() throws Exception {
                    matchAgainst(new DarwinCSV((File) input, DarwinCSV.FILE_CSV_DELIMITED));

                    return null;
                  }
                }.execute();
              }
            });
    matchMenu.add(miMatchCSV);

    /* Match -> Against ITIS */
    JMenuItem miMatchITIS =
        new JMenuItem(
            new AbstractAction("Match against ITIS") {
              @Override
              public void actionPerformed(ActionEvent e) {
                DarwinCSV csv = DownloadITIS.getIt(mainFrame);
                matchAgainst(csv);
                table.repaint();
              }
            });
    matchMenu.add(miMatchITIS);

    /* TaxonID */
    JMenu taxonIDMenu = new JMenu("TaxonIDs");
    menuBar.add(taxonIDMenu);

    /* TaxonID -> Treat TaxonIDs as ... */
    JMenu treatTaxonIDsAs = new JMenu("Treat TaxonIDs as ...");
    taxonIDMenu.add(treatTaxonIDsAs);

    /* TaxonID -> Treat -> ITIS TSNs */
    JCheckBoxMenuItem miITIS_TSNs =
        new JCheckBoxMenuItem(
            new AbstractAction("ITIS TSNs") {
              @Override
              public void actionPerformed(ActionEvent e) {
                // Don't let the user unselect this.
                ((JCheckBoxMenuItem) e.getSource()).setSelected(true);
              }
            });
    miITIS_TSNs.setSelected(true);
    treatTaxonIDsAs.add(miITIS_TSNs);

    /* TaxonID -> Create family column */
    JMenuItem miTaxonID_createFamily =
        new JMenuItem(
            new AbstractAction("Create family column") {
              @Override
              public void actionPerformed(ActionEvent e) {
                /*
                if(currentCSV == null)
                	return;

                if(currentMatch == null)
                	return;

                int col = getJTable().getSelectedColumn();
                if(col == -1)
                	return;

                RowIndex rowIndex = currentCSV.getRowIndex();

                String colName = rowIndex.getColumnName(col);
                if(rowIndex.hasColumn(colName + "_family")) {
                	// TODO MessageBox
                	return;
                }

                if(Name.class.isAssignableFrom(currentCSV.getRowIndex().getColumnClass(col))) {
                	// A name class! Make a new column!
                	currentCSV.getRowIndex().setColumnClass(colName + "_family", String.class);
                	currentCSV.getRowIndex().createNewColumn(colName + "_family", col + 1, colName, new MapOperation() {
                		@Override
                		public Object mapTo(Object value) {
                			return "family";
                		}
                	});

                	// Repaint the table.
                	getJTable().repaint();
                }
                */
              }
            });
    taxonIDMenu.add(miTaxonID_createFamily);

    /* Help */
    JMenu helpMenu = new JMenu("Help");
    menuBar.add(helpMenu);

    /* Help -> Memory information */
    JMenuItem miHelpMemory =
        new JMenuItem(
            new AbstractAction("Memory information") {
              @Override
              public void actionPerformed(ActionEvent e) {
                System.gc();

                MessageBox.messageBox(
                    mainFrame,
                    "Memory information",
                    "Maximum memory: "
                        + Runtime.getRuntime().maxMemory() / (1024 * 1024)
                        + " MB\n"
                        + "Total memory: "
                        + Runtime.getRuntime().totalMemory() / (1024 * 1024)
                        + " MB\n"
                        + "Used memory: "
                        + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())
                            / (1024 * 1024)
                        + " MB\n"
                        + "Free memory: "
                        + Runtime.getRuntime().freeMemory() / (1024 * 1024)
                        + " MB\n"
                        + "Available memory: "
                        + (Runtime.getRuntime().maxMemory()
                                - Runtime.getRuntime().totalMemory()
                                + Runtime.getRuntime().freeMemory())
                            / (1024 * 1024)
                        + " MB");
              }
            });
    helpMenu.add(miHelpMemory);

    return menuBar;
  }
Exemple #5
0
 /**
  * Should we draw the alignment points in the canvas
  *
  * @return Draw the alignment points in the canvas
  */
 public boolean shouldShowAlignmentPoints() {
   if (showAlignmentPointsMI != null) {
     return showAlignmentPointsMI.isSelected();
   }
   return true;
 }