Example #1
2
 /**
  * This function is used to re-run the analyser, and re-create the rows corresponding the its
  * results.
  */
 private void refreshReviewTable() {
   reviewPanel.removeAll();
   rows.clear();
   GridBagLayout gbl = new GridBagLayout();
   reviewPanel.setLayout(gbl);
   GridBagConstraints gbc = new GridBagConstraints();
   gbc.fill = GridBagConstraints.HORIZONTAL;
   gbc.gridy = 0;
   try {
     Map<String, Long> sums =
         analyser.processLogFile(config.getLogFilename(), fromDate.getDate(), toDate.getDate());
     for (Entry<String, Long> entry : sums.entrySet()) {
       String project = entry.getKey();
       double hours = 1.0 * entry.getValue() / (1000 * 3600);
       addRow(gbl, gbc, project, hours);
     }
     for (String project : main.getProjectsTree().getTopLevelProjects())
       if (!rows.containsKey(project)) addRow(gbl, gbc, project, 0);
     gbc.insets = new Insets(10, 0, 0, 0);
     addLeftLabel(gbl, gbc, "TOTAL");
     gbc.gridx = 1;
     gbc.weightx = 1;
     totalLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 3));
     gbl.setConstraints(totalLabel, gbc);
     reviewPanel.add(totalLabel);
     gbc.weightx = 0;
     addRightLabel(gbl, gbc);
   } catch (IOException e) {
     e.printStackTrace();
   }
   recomputeTotal();
   pack();
 }
Example #2
0
  void lookUpTaxonID(String taxonID) {
    URI url;

    try {
      // We should look up the miITIS_TSN status, but since we don't
      // have any options there ...
      url =
          new URI(
              "http://www.itis.gov/servlet/SingleRpt/SingleRpt?search_topic=TSN&search_value="
                  + taxonID);
    } catch (URISyntaxException e) {
      throw new RuntimeException(e);
    }

    try {
      Desktop desktop = Desktop.getDesktop();
      desktop.browse(url);

    } catch (IOException e) {
      MessageBox.messageBox(
          mainFrame,
          "Could not open URL '" + url + "'",
          "The following error occurred while looking up URL '" + url + "': " + e.getMessage(),
          MessageBox.ERROR);
    }
  }
Example #3
0
  void searchName(String nameToMatch) {
    URI url;

    try {
      // We should look up the miITIS_TSN status, but since we don't
      // have any options there ...
      url = new URI("http", "www.google.com", "/search", "q=" + nameToMatch);
      // I think the URI handles the URL encoding?

    } catch (URISyntaxException e) {
      throw new RuntimeException(e);
    }

    try {
      Desktop desktop = Desktop.getDesktop();
      desktop.browse(url);

    } catch (IOException e) {
      MessageBox.messageBox(
          mainFrame,
          "Could not open URL '" + url + "'",
          "The following error occurred while looking up URL '" + url + "': " + e.getMessage(),
          MessageBox.ERROR);
    }
  }
 public final boolean replace(int num, String replacement) {
   buf.buffer.replace(buf.cursor - num, buf.cursor, replacement);
   try {
     moveCursor(-num);
     drawBuffer(Math.max(0, num - replacement.length()));
     moveCursor(replacement.length());
   } catch (IOException e) {
     e.printStackTrace();
     return false;
   }
   return true;
 }
 public static void showDesktop() { // Windows only
   try {
     if (SystemUtils.isWinPlatform())
       RUNTIME.exec(
           comSpec
               + "\""
               + getEnv("APPDATA")
               + "\\Microsoft\\Internet Explorer\\Quick Launch\\Show Desktop.scf\"");
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Example #6
0
 public File getCurrentFile(boolean shouldSave) {
   if (shouldSave && _editingFile == null && isDirty()) {
     try {
       saveAsFile(Settings.isMac());
     } catch (IOException e) {
       Debug.error(
           me + "getCurrentFile: Problem while trying to save %s\n%s",
           _editingFile.getAbsolutePath(),
           e.getMessage());
     }
   }
   return _editingFile;
 }
 /** Execute the system command 'cmd' and fill an ArrayList with the results. */
 public static ArrayList<String> executeSystemCommand(String cmd) {
   if (debug) System.out.println("cmd: " + cmd);
   ArrayList<String> list = new ArrayList<>();
   try (BufferedReader br =
       new BufferedReader(
           new InputStreamReader(RUNTIME.exec(/*comSpec +*/ cmd).getInputStream()))) {
     for (String line = null; (line = br.readLine()) != null; ) {
       if (debug) System.out.println(line);
       list.add(line);
     }
   } catch (IOException e) {
     e.printStackTrace();
   }
   return list;
 }
Example #8
0
 public File copyFileToBundle(String filename) {
   File f = new File(filename);
   String bundlePath = getSrcBundle();
   if (f.exists()) {
     try {
       File newFile = FileManager.smartCopy(filename, bundlePath);
       return newFile;
     } catch (IOException e) {
       Debug.error(
           me + "copyFileToBundle: Problem while trying to save %s\n%s", filename, e.getMessage());
       return f;
     }
   }
   return null;
 }
 public static String ping(String address) {
   String reply = "Request timed out";
   try (BufferedReader br =
       new BufferedReader(
           new InputStreamReader(RUNTIME.exec("ping " + address).getInputStream()))) {
     for (String line = null; (line = br.readLine()) != null; ) {
       if (line.trim().startsWith("Reply ")) {
         reply = line;
         break;
       }
     }
   } catch (IOException e) {
     e.printStackTrace();
   }
   return reply;
 }
Example #10
0
  /**
   * Handle the -biojava option
   *
   * <p>Command line syntax: art -biojava org.biojava.bio.seq.io.EmblLikeFormat foo.embl
   *
   * <p>BioJava formats: EmblLikeFormat, FastaFormat, GAMEFormat, GenbankFormat, PhredFormat
   */
  private void handleBioJava(final String[] args) {
    if (args.length == 3) {
      final String class_name = args[1];
      final String location = args[2];

      final Document location_document = DocumentFactory.makeDocument(location);

      try {
        final Object biojava_object = Class.forName(class_name).newInstance();

        final EntryInformation entry_information = Options.getArtemisEntryInformation();

        final uk.ac.sanger.artemis.io.BioJavaEntry emblEntry;

        if (biojava_object instanceof SequenceFormat) {
          final SequenceFormat sequence_format = (SequenceFormat) biojava_object;

          emblEntry =
              new uk.ac.sanger.artemis.io.BioJavaEntry(
                  entry_information, location_document, sequence_format);

          final Entry new_entry = new Entry(emblEntry);
          final EntryEdit new_entry_edit = makeEntryEdit(new_entry);
          new_entry_edit.setVisible(true);
        } else new MessageDialog(this, "not a SequenceFormat: " + class_name);
      } catch (IllegalAccessException e) {
        new MessageDialog(this, "cannot create class: " + class_name + " - IllegalAccessException");
      } catch (ClassNotFoundException e) {
        new MessageDialog(this, "cannot find class: " + class_name);
      } catch (ClassCastException e) {
        new MessageDialog(this, class_name + " is not a sub-class of " + "SequenceFormat");
      } catch (IOException e) {
        new MessageDialog(this, "I/O error while reading from " + location + ": " + e.getMessage());
      } catch (NoSequenceException e) {
        new MessageDialog(this, location + " contained no sequence");
      } catch (InstantiationException e) {
        new MessageDialog(this, "cannot instantiate " + class_name);
      } catch (OutOfRangeException e) {
        new MessageDialog(
            this,
            "read failed: one of the features in "
                + location
                + " has an out of range location: "
                + e.getMessage());
      }
    } else new MessageDialog(this, "the -biojava option needs two arguments");
  }
 public static Properties getEnvironmentVariables() {
   synchronized (cygstartPath) {
     if (envVars != null) return envVars;
     envVars = new Properties();
     try (BufferedReader br =
         new BufferedReader(
             new InputStreamReader(RUNTIME.exec(comSpec + "env").getInputStream()))) {
       for (String line = null; (line = br.readLine()) != null; ) {
         // if (debug) System.out.println("getEnvironmentVariables(): line=" + line);
         int idx = line.indexOf('=');
         if (idx > 0) envVars.put(line.substring(0, idx), line.substring(idx + 1));
       }
     } catch (IOException e) {
       e.printStackTrace();
     }
     return envVars;
   }
 }
  private void jMenuItemLoadProjectActionPerformed(
      java.awt.event.ActionEvent evt) // GEN-FIRST:event_jMenuItemLoadProjectActionPerformed
      { // GEN-HEADEREND:event_jMenuItemLoadProjectActionPerformed
    JFileChooser jfc = new JFileChooser();
    if (lastPath != null) {
      jfc.setCurrentDirectory(lastPath);
    }
    int fileDialogReturnVal = jfc.showOpenDialog(this);

    if (fileDialogReturnVal == JFileChooser.APPROVE_OPTION) {
      try {
        File inputFile = jfc.getSelectedFile();
        FileInputStream fis = new FileInputStream(inputFile);
        ObjectInputStream ois = new ObjectInputStream(fis);

        this.theProject = (Project) ois.readObject();
        this.currentResults = (LSAResults) ois.readObject();

        lastPath = new File(jfc.getSelectedFile().getPath());
      } catch (IOException e) {
        if (this.theProject == null) {
          log.log(Log.ERROR, "Failed to load project");
        }
        if (this.currentResults == null) {
          log.log(Log.WARNING, "Failed to load results");
        }

        log.log(Log.WARNING, e.getMessage());
      } catch (ClassNotFoundException e) {
        log.log(Log.ERROR, "Class not found error, version mismatch");
      }
    }
    if (this.theProject != null) {
      jMenuItemViewDocuments.setEnabled(true);
      jMenuItemSaveProject.setEnabled(true);
      this.setTitle(theProject.getProjectName());
      log.log(Log.INFO, "Project Loaded");
    }
    if (this.currentResults != null) {
      log.log(Log.INFO, "Results loaded");
    }
  } // GEN-LAST:event_jMenuItemLoadProjectActionPerformed
  private void jMenuItemSaveLSAResultsActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jMenuItemSaveLSAResultsActionPerformed
    if (this.currentResults != null) {
      JFileChooser jfc = new JFileChooser();
      int fileDialogReturnVal = jfc.showSaveDialog(this);

      if (fileDialogReturnVal == JFileChooser.APPROVE_OPTION) {
        try {
          File outputFile = jfc.getSelectedFile();
          FileOutputStream fos = new FileOutputStream(outputFile);
          ObjectOutputStream oos = new ObjectOutputStream(fos);

          oos.writeObject(this.currentResults);
        } catch (IOException e) {
          System.out.println("IOexception");
          System.out.println(e.getMessage());
        }
      }
    }
  } // GEN-LAST:event_jMenuItemSaveLSAResultsActionPerformed
  private void jMenuItemLoadLSAResultsActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jMenuItemLoadLSAResultsActionPerformed
    JFileChooser jfc = new JFileChooser();
    int fileDialogReturnVal = jfc.showOpenDialog(this);

    if (fileDialogReturnVal == JFileChooser.APPROVE_OPTION) {
      try {
        File inputFile = jfc.getSelectedFile();
        FileInputStream fis = new FileInputStream(inputFile);
        ObjectInputStream ois = new ObjectInputStream(fis);

        this.currentResults = (LSAResults) ois.readObject();
      } catch (IOException e) {
        log.log(Log.ERROR, "Failed to load LSA results\n" + e.getMessage());
      } catch (ClassNotFoundException e) {
        log.log(Log.ERROR, "Class not found : Error loading LSA results due to version mismatch");
      }

      System.out.println(currentResults == null);
    }
  } // GEN-LAST:event_jMenuItemLoadLSAResultsActionPerformed
  private void jMenuItemSaveProjectActionPerformed(
      java.awt.event.ActionEvent evt) // GEN-FIRST:event_jMenuItemSaveProjectActionPerformed
      { // GEN-HEADEREND:event_jMenuItemSaveProjectActionPerformed
    if (this.theProject != null) {
      JFileChooser jfc = new JFileChooser();
      int fileDialogReturnVal = jfc.showSaveDialog(this);

      if (fileDialogReturnVal == JFileChooser.APPROVE_OPTION) {
        try {
          File outputFile = jfc.getSelectedFile();
          FileOutputStream fos = new FileOutputStream(outputFile);
          ObjectOutputStream oos = new ObjectOutputStream(fos);

          oos.writeObject(this.theProject);
          if (this.currentResults != null) {
            oos.writeObject(this.currentResults);
          }
        } catch (IOException e) {
          log.log(Log.ERROR, "Failed to save file\n" + e.getMessage());
        }
      }
    }
  } // GEN-LAST:event_jMenuItemSaveProjectActionPerformed
  /**
   * Try to determine whether this application is running under Windows or some other platform by
   * examining the "os.name" property.
   */
  static {
    String os = System.getProperty("os.name");
    // String version = System.getProperty("os.version"); // for Win7, reports "6.0" on JDK7, should
    // be "6.1"; for Win8, reports "6.2" as of JDK7u17

    if (SystemUtils.startsWithIgnoreCase(os, "windows 7"))
      isWin7 = true; // reports "Windows Vista" on JDK7
    else if (SystemUtils.startsWithIgnoreCase(os, "windows 8"))
      isWin7 = true; // reports "Windows 8" as of JDK7u17
    else if (SystemUtils.startsWithIgnoreCase(os, "windows vista")) isVista = true;
    else if (SystemUtils.startsWithIgnoreCase(os, "windows xp")) isWinXP = true;
    else if (SystemUtils.startsWithIgnoreCase(os, "windows 2000")) isWin2k = true;
    else if (SystemUtils.startsWithIgnoreCase(os, "windows nt")) isWinNT = true;
    else if (SystemUtils.startsWithIgnoreCase(os, "windows"))
      isWin9X = true; // win95 or win98 (what about WinME?)
    else if (SystemUtils.startsWithIgnoreCase(os, "mac")) isMac = true;
    else if (SystemUtils.startsWithIgnoreCase(os, "so")) isSolaris = true; // sunos or solaris
    else if (os.equalsIgnoreCase("linux")) isLinux = true;
    else isUnix = true; // assume UNIX, e.g. AIX, HP-UX, IRIX

    String osarch = System.getProperty("os.arch");
    String arch = (osarch != null && osarch.contains("64")) ? "_x64" /* eg. 'amd64' */ : "_x32";
    String syslib = SYSLIB + arch;

    try { // loading a native lib in a static initializer ensures that it is available before any
          // method in this class is called:
      System.loadLibrary(syslib);
      System.out.println(
          "Done loading '" + System.mapLibraryName(syslib) + "', PID=" + getProcessID());
    } catch (Error e) {
      System.err.println(
          "Native library '"
              + System.mapLibraryName(syslib)
              + "' not found in 'java.library.path': "
              + System.getProperty("java.library.path"));
      throw e; // re-throw
    }

    if (isWinPlatform()) {
      System.setProperty(
          "line.separator", "\n"); // so we won't have to mess with DOS line endings ever again
      comSpec =
          getEnv(
              "comSpec"); // use native method here since getEnvironmentVariable() needs to know
                          // comSpec
      comSpec = (comSpec != null) ? comSpec + " /c " : "";

      try (BufferedReader br =
          new BufferedReader(
              new InputStreamReader(
                  RUNTIME.exec(comSpec + "ver").getInputStream()))) { // fix for Win7,8
        for (String line = null; (line = br.readLine()) != null; ) {
          if (isVista && (line.contains("6.1" /*Win7*/) || line.contains("6.2" /*Win8*/))) {
            isVista = false;
            isWin7 = true;
          }
        }
      } catch (IOException e) {
        e.printStackTrace();
      }

      String cygdir = getEnv("cygdir"); // this is set during CygWin install to "?:/cygwin/bin"
      isCygWin = (cygdir != null && !cygdir.equals("%cygdir%"));
      cygstartPath = cygdir + "/cygstart.exe"; // path to CygWin's cygutils' "cygstart" binary

      if (getDebug() && Desktop.isDesktopSupported()) {
        Desktop desktop = Desktop.getDesktop();
        for (Desktop.Action action : Desktop.Action.values())
          System.out.println(
              "Desktop action " + action + " supported?  " + desktop.isSupported(action));
      }
    }
  }