예제 #1
1
파일: Game.java 프로젝트: cpetosky/o2d-lib
  // --------------------------------actionConnect------------------------------
  private void actionConnect() {
    if (oParty == null) {
      JOptionPane.showMessageDialog(frame, "Make a party before trying to connect.");
      return;
    }

    String[] oResults = (String[]) DialogManager.show(DialogManager.CONNECT, frame);

    if (oResults[DialogManager.RETURN_IP].equals("cancel")) return;

    lblStatus3.setText("Connecting...");
    try {
      oConn.connect(
          oResults[DialogManager.RETURN_IP], Integer.parseInt(oResults[DialogManager.RETURN_PORT]));
    } catch (UnknownHostException e) {
      JOptionPane.showMessageDialog(
          frame,
          "The IP of the host cannot be determined.",
          "Unknown Host Exception",
          JOptionPane.ERROR_MESSAGE);
      frame.repaint();
      return;
    } catch (IOException e) {
      JOptionPane.showMessageDialog(
          frame, e.getMessage(), "Input/Output Exception", JOptionPane.ERROR_MESSAGE);
      frame.repaint();
      return;
    }
    echo("Connected to opponent!");

    tConn = new Thread(oConn, "conn");
    tConn.start();
    tMain = new Thread(this, "main");
    tMain.start();
  }
예제 #2
0
  /**
   * Repeats the capture with the current settings.
   *
   * @param aParent the parent window to use, can be <code>null</code>.
   */
  public boolean repeatCaptureData(final Window aParent) {
    final DeviceController devCtrl = getDeviceController();
    if (devCtrl == null) {
      return false;
    }

    try {
      setStatus(
          "Capture from {0} started at {1,date,medium} {1,time,medium} ...",
          devCtrl.getName(), new Date());

      devCtrl.captureData(this);

      return true;
    } catch (IOException exception) {
      captureAborted("I/O problem: " + exception.getMessage());

      exception.printStackTrace();

      // Make sure to handle IO-interrupted exceptions properly!
      HostUtils.handleInterruptedException(exception);

      return false;
    } finally {
      updateActions();
    }
  }
예제 #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);
    }
  }
예제 #4
0
파일: Client.java 프로젝트: Eneru/l3s6
  public void init() {
    add(intitule);
    add(texte);
    add(bouton);
    bouton.addActionListener(this);

    try {
      ORB orb = ORB.init(this, null);
      FileReader file = new FileReader(iorfile.value);
      BufferedReader in = new BufferedReader(file);
      String ior = in.readLine();
      file.close();
      org.omg.CORBA.Object obj = orb.string_to_object(ior);
      annuaire = AnnuaireHelper.narrow(obj);

    } catch (org.omg.CORBA.SystemException ex) {
      System.err.println("Error");
      ex.printStackTrace();
    } catch (FileNotFoundException fnfe) {
      System.err.println(fnfe.getMessage());
    } catch (IOException io) {
      System.err.println(io.getMessage());
    } catch (Exception e) {
      System.err.println(e.getMessage());
    }
  }
예제 #5
0
  /**
   * 向服务器发送命令行,给服务器端处理
   *
   * @param lines 命令行
   */
  public static void clientSend(String[] lines) {
    if (lines != null && lines.length <= 0) {
      return;
    }
    Socket socket = null;
    PrintWriter writer = null;
    try {
      socket = new Socket("localhost", port);

      writer =
          new PrintWriter(
              new BufferedWriter(
                  new OutputStreamWriter(
                      socket.getOutputStream(), EncodeConstants.ENCODING_UTF_8)));
      for (int i = 0; i < lines.length; i++) {
        writer.println(lines[i]);
      }

      writer.flush();
    } catch (Exception e) {
      FRContext.getLogger().error(e.getMessage(), e);
    } finally {
      try {
        writer.close();
        socket.close();
      } catch (IOException e) {
        FRContext.getLogger().error(e.getMessage(), e);
      }
    }
  }
예제 #6
0
파일: Load.java 프로젝트: madhadron/mroi
 public Zipper<Map<Integer, MZipper<RoiContainer>>> exec(
     Zipper<Map<Integer, MZipper<RoiContainer>>> z, int frame) {
   JFileChooser fc = new JFileChooser();
   int returnVal = fc.showOpenDialog(WindowManager.getCurrentWindow().getCanvas());
   Map<Integer, MZipper<RoiContainer>> newRois;
   if (returnVal == JFileChooser.APPROVE_OPTION) {
     try {
       FileInputStream f = new FileInputStream(fc.getSelectedFile().getCanonicalPath());
       MroiLisp parser = new MroiLisp(f);
       parser.ReInit(f);
       newRois = parser.roiFile();
       //				z.rights.clear();
       //				z.rights.add(newRois);
       //				z = z.right();
       //				return z;
       return z.insertAndStep(newRois);
     } catch (IOException e) {
       IJ.error("Couldn't open from " + fc.getSelectedFile().getName() + ": " + e.getMessage());
     } catch (mroi.ParseException e) {
       IJ.error("Failed in parsing: " + e.getMessage());
     } catch (Exception e) {
       IJ.error("Malformed input file: " + e.getMessage());
     }
   }
   return z;
 }
예제 #7
0
  boolean doSaveNcml(String text, String filename) {
    if (debugNcmlWrite) {
      System.out.println("filename=" + filename);
      System.out.println("text=" + text);
    }

    File out = new File(filename);
    if (out.exists()) {
      int val =
          JOptionPane.showConfirmDialog(
              null,
              filename + " already exists. Do you want to overwrite?",
              "WARNING",
              JOptionPane.YES_NO_OPTION);
      if (val != JOptionPane.YES_OPTION) return false;
    }

    try {
      IO.writeToFile(text, out);
      JOptionPane.showMessageDialog(this, "File successfully written");
      return true;
    } catch (IOException ioe) {
      JOptionPane.showMessageDialog(this, "ERROR: " + ioe.getMessage());
      ioe.printStackTrace();
      return false;
    }
    // saveNcmlDialog.setVisible(false);
  }
예제 #8
0
  public void lire() {
    int x = 0;
    try {
      File f = new File(_cheminInit);
      FileReader fr = new FileReader(f);
      BufferedReader br = new BufferedReader(fr);
      try {
        // initialisation
        String line = br.readLine();
        _poids = Double.parseDouble(line) * 9.81;
        line = br.readLine();
        _pasTemps = Double.parseDouble(line);

        line = br.readLine();
        while (line != null) {
          _tabDonnee.add(Double.parseDouble(line));
          ++x;
          line = br.readLine();
        }
        br.close();
        fr.close();
      } catch (IOException exception) {
        System.out.println("Erreur : " + exception.getMessage());
      }
    } catch (FileNotFoundException exception) {
      System.out.println("Erreur : Fichier non trouvé");
    }
  }
예제 #9
0
  private void saveData(DataOutputStream sv, String directory) {
    try {
      // 8 bit registers
      sv.write(registers[a]);
      sv.write(registers[b]);
      sv.write(registers[c]);
      sv.write(registers[d]);
      sv.write(registers[e]);
      sv.write(f);

      // 16 bit registers
      sv.writeInt(sp);
      sv.writeInt(pc);
      sv.writeInt(hl);

      sv.writeInt(gbcRamBank);

      // write ram 8Kb
      sv.write(mainRam);

      // write oam (used mainly for registers) 256 bytes
      sv.write(oam);

    } catch (IOException e) {
      System.out.println("Dmgcpu.saveState.saveData: Could not write to file " + directory);
      System.out.println("Error Message: " + e.getMessage());
      System.exit(-1);
    }
  }
예제 #10
0
  public void saveState(String extension) {
    String directory = (cartridge.romFileName + extension);

    try {
      FileOutputStream fl = new FileOutputStream(directory);
      DataOutputStream sv = new DataOutputStream(fl);

      saveData(sv, directory);

      // write battery ram
      cartridge.saveData(sv, directory);

      // write graphic memory
      graphicsChip.saveData(sv, directory);

      // write io state
      ioHandler.saveData(sv, directory);

      // stats.printStats();

      sv.close();
      fl.close();

    } catch (FileNotFoundException e) {
      System.out.println("Dmgcpu.saveState: Could not open file " + directory);
      System.out.println("Error Message: " + e.getMessage());
      System.exit(-1);
    } catch (IOException e) {
      System.out.println("Dmgcpu.saveState: Could not write to file " + directory);
      System.out.println("Error Message: " + e.getMessage());
      System.exit(-1);
    }

    System.out.println("Saved stage!");
  }
예제 #11
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);
    }
  }
 public static void writeArray(String s, int[] x) {
   try {
     RandomAccessFile output = new RandomAccessFile(s, "rw");
     for (int i = 0; i < x.length; i++) output.writeInt(x[i]);
   } catch (IOException e) {
     System.out.println(e.getMessage());
   }
 }
예제 #13
0
  public void openLink(String link) {
    if (WWUtil.isEmpty(link)) return;

    try {
      try {
        // See if the link is a URL, and invoke the browser if it is
        URL url = new URL(link.replace(" ", "%20"));
        Desktop.getDesktop().browse(url.toURI());
        return;
      } catch (MalformedURLException ignored) { // just means that the link is not a URL
      }

      // It's not a URL, so see if it's a file and invoke the desktop to open it if it is.
      File file = new File(link);
      if (file.exists()) {
        Desktop.getDesktop().open(new File(link));
        return;
      }

      String message = "Cannot open resource. It's not a valid file or URL.";
      Util.getLogger().log(Level.SEVERE, message);
      this.showErrorDialog(null, "No Reconocido V\u00ednculo", message);
    } catch (UnsupportedOperationException e) {
      String message =
          "Unable to open resource.\n"
              + link
              + (e.getMessage() != null ? "\n" + e.getMessage() : "");
      Util.getLogger().log(Level.SEVERE, message, e);
      this.showErrorDialog(e, "Error Opening Resource", message);
    } catch (IOException e) {
      String message =
          "I/O error while opening resource.\n"
              + link
              + (e.getMessage() != null ? ".\n" + e.getMessage() : "");
      Util.getLogger().log(Level.SEVERE, message, e);
      this.showErrorDialog(e, "I/O Error", message);
    } catch (Exception e) {
      String message =
          "Error attempting to open resource.\n"
              + link
              + (e.getMessage() != null ? "\n" + e.getMessage() : "");
      Util.getLogger().log(Level.SEVERE, message);
      this.showMessageDialog(message, "Error Opening Resource", JOptionPane.ERROR_MESSAGE);
    }
  }
예제 #14
0
  // read text from textArea through NcMLReader
  // then write it back out via resulting dataset
  private void checkNcml(Formatter f) {
    if (ncmlLocation == null) return;
    try {
      NetcdfDataset ncd = NetcdfDataset.openDataset(ncmlLocation);
      ncd.check(f);

    } catch (IOException ioe) {
      JOptionPane.showMessageDialog(this, "ERROR: " + ioe.getMessage());
      ioe.printStackTrace();
    }
  }
예제 #15
0
  private NetcdfDataset openDataset(String location, boolean addCoords, CancelTask task) {
    try {
      return NetcdfDataset.openDataset(location, addCoords, task);

      // if (setUseRecordStructure)
      //   ncd.sendIospMessage(NetcdfFile.IOSP_MESSAGE_ADD_RECORD_STRUCTURE);
    } catch (IOException ioe) {
      JOptionPane.showMessageDialog(null, "NetcdfDataset.open cant open " + ioe.getMessage());
      if (!(ioe instanceof java.io.FileNotFoundException)) ioe.printStackTrace();
      return null;
    }
  }
예제 #16
0
    @Override
    @SuppressWarnings("SleepWhileHoldingLock")
    public void run() {
      try {
        // initialize the statusbar
        status.removeAll();
        JProgressBar progress = new JProgressBar();
        progress.setMinimum(0);
        progress.setMaximum(doc.getLength());
        status.add(progress);
        status.revalidate();

        // start writing
        Writer out = new FileWriter(f);
        Segment text = new Segment();
        text.setPartialReturn(true);
        int charsLeft = doc.getLength();
        int offset = 0;
        while (charsLeft > 0) {
          doc.getText(offset, Math.min(4096, charsLeft), text);
          out.write(text.array, text.offset, text.count);
          charsLeft -= text.count;
          offset += text.count;
          progress.setValue(offset);
          try {
            Thread.sleep(10);
          } catch (InterruptedException e) {
            Logger.getLogger(FileSaver.class.getName()).log(Level.SEVERE, null, e);
          }
        }
        out.flush();
        out.close();
      } catch (IOException e) {
        final String msg = e.getMessage();
        SwingUtilities.invokeLater(
            new Runnable() {

              public void run() {
                JOptionPane.showMessageDialog(
                    getFrame(),
                    "Could not save file: " + msg,
                    "Error saving file",
                    JOptionPane.ERROR_MESSAGE);
              }
            });
      } catch (BadLocationException e) {
        System.err.println(e.getMessage());
      }
      // we are done... get rid of progressbar
      status.removeAll();
      status.revalidate();
    }
예제 #17
0
    @Override
    public void run() {
      try {
        // initialize the statusbar
        status.removeAll();
        JProgressBar progress = new JProgressBar();
        progress.setMinimum(0);
        progress.setMaximum((int) f.length());
        status.add(progress);
        status.revalidate();

        // try to start reading
        Reader in = new FileReader(f);
        char[] buff = new char[4096];
        int nch;
        while ((nch = in.read(buff, 0, buff.length)) != -1) {
          doc.insertString(doc.getLength(), new String(buff, 0, nch), null);
          progress.setValue(progress.getValue() + nch);
        }
      } catch (IOException e) {
        final String msg = e.getMessage();
        SwingUtilities.invokeLater(
            new Runnable() {

              public void run() {
                JOptionPane.showMessageDialog(
                    getFrame(),
                    "Could not open file: " + msg,
                    "Error opening file",
                    JOptionPane.ERROR_MESSAGE);
              }
            });
      } catch (BadLocationException e) {
        System.err.println(e.getMessage());
      }
      doc.addUndoableEditListener(undoHandler);
      // we are done... get rid of progressbar
      status.removeAll();
      status.revalidate();

      resetUndoManager();

      if (elementTreePanel != null) {
        SwingUtilities.invokeLater(
            new Runnable() {

              public void run() {
                elementTreePanel.setEditor(getEditor());
              }
            });
      }
    }
예제 #18
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;
 }
예제 #19
0
 public String getData() {
   ByteArrayOutputStream out = new ByteArrayOutputStream();
   try {
     getDrawing().getOutputFormats().get(0).write(out, getDrawing());
     return out.toString("UTF8");
   } catch (IOException e) {
     SVGTextFigure tf = new SVGTextFigure();
     tf.setText(e.getMessage());
     tf.setBounds(new Point2D.Double(10, 10), new Point2D.Double(100, 100));
     getDrawing().add(tf);
     e.printStackTrace();
     return "";
   }
 }
예제 #20
0
  @Override
  public void actionPerformed(ActionEvent ev) {
    if (ev.getSource() == btn) {
      File file;
      String string = "";
      try {
        if (radioRead.isSelected()) {
          file = new File(txt.getText());
          DataInputStream input = new DataInputStream(new FileInputStream(file));
          int inByte;
          while ((inByte = input.read()) != -1) {
            string += (char) inByte;
          }
          input.close();

        } else if (radioEncrypt.isSelected()) {
          string = fileContent.getOut();
          String strEncrypt = new String();
          for (int i = 0; i < string.length(); i++) {
            char ch = string.charAt(i);
            if (ch >= 'A' && ch <= 'Z') {
              ch += 13;
              if (ch > 'Z') {
                ch -= 26;
              }
            } else if (ch >= 'a' && ch <= 'z') {
              ch += 13;
              if (ch > 'z') {
                ch -= 26;
              }
            }
            strEncrypt += ch;
          }
          string = strEncrypt;
        }

        if (fileContent == null) {
          fileContent = new FileContent(string);
        } else {
          fileContent.setVisible(true);
          fileContent.setOut(string);
        }

      } catch (FileNotFoundException e) {
        JOptionPane.showMessageDialog(this, "Can't find the file.");
      } catch (IOException e) {
        JOptionPane.showMessageDialog(this, "IO Exception " + e.getMessage());
      }
    }
  }
 private static void doImport(
     @NotNull File newConfigDir,
     @NotNull File oldConfigDir,
     ConfigImportSettings settings,
     File installationHome) {
   try {
     copy(oldConfigDir, newConfigDir, settings, installationHome);
   } catch (IOException e) {
     JOptionPane.showMessageDialog(
         JOptionPane.getRootFrame(),
         ApplicationBundle.message("error.unable.to.import.settings", e.getMessage()),
         ApplicationBundle.message("title.settings.import.failed"),
         JOptionPane.WARNING_MESSAGE);
   }
 }
예제 #22
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;
 }
예제 #23
0
  // read text from textArea through NcMLReader
  // then write it back out via resulting dataset
  void doTransform(String text) {
    try {
      StringReader reader = new StringReader(text);
      NetcdfDataset ncd = NcMLReader.readNcML(reader, null);
      StringWriter sw = new StringWriter(10000);
      ncd.writeNcML(sw, null);
      editor.setText(sw.toString());
      editor.setCaretPosition(0);
      JOptionPane.showMessageDialog(this, "File successfully transformed");

    } catch (IOException ioe) {
      JOptionPane.showMessageDialog(this, "ERROR: " + ioe.getMessage());
      ioe.printStackTrace();
    }
  }
예제 #24
0
파일: IdeMain.java 프로젝트: aimozg/ja-dcpu
 private void openBin() {
   fileChooser.resetChoosableFileFilters();
   fileChooser.addChoosableFileFilter(binFilter);
   fileChooser.setFileFilter(binFilter);
   if (fileChooser.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) {
     try {
       FileInputStream inbinf = new FileInputStream(fileChooser.getSelectedFile());
       int len = inbinf.available();
       if (len % 2 == 1) throw new IOException(String.format("Odd file size (0x%x)\n", len));
       len /= 2;
       if (len > 0x10000) throw new IOException(String.format("Too large file (0x%x)\n", len));
       binary = new char[len];
       for (int i = 0; i < len; i++) {
         int lo = inbinf.read();
         int hi = inbinf.read();
         if (lo == -1 || hi == -1) throw new IOException("Unable to read\n");
         binary[i] = (char) ((hi << 8) | lo);
       }
       asmMap = new AsmMap();
       Disassembler dasm = new Disassembler();
       dasm.init(binary);
       // TODO attach asmmap
       StringBuilder sb = new StringBuilder();
       while (dasm.getAddress() < binary.length) {
         int addr = dasm.getAddress();
         sb.append(String.format("%-26s ; [%04x] =", dasm.next(true), addr));
         int addr2 = dasm.getAddress();
         while (addr < addr2) {
           char i = binary[addr++];
           sb.append(
               String.format(" %04x '%s'", (int) i, (i >= 0x20 && i < 0x7f) ? (char) i : '.'));
         }
         sb.append("\n");
       }
       srcBreakpoints.clear();
       sourceRowHeader.breakpointsChanged();
       sourceTextarea.setText(sb.toString());
     } catch (IOException e1) {
       JOptionPane.showMessageDialog(
           frame, "Unable to open file: %s" + e1.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
       e1.printStackTrace();
     }
   }
 }
예제 #25
0
  private void loadData(DataInputStream sv, String directory) {
    try {
      int size = 0;
      // 8 bit registers
      registers[a] = sv.read();
      registers[b] = sv.read();
      registers[c] = sv.read();
      registers[d] = sv.read();
      registers[e] = sv.read();
      f = sv.read();

      // 16 bit registers
      sp = sv.readInt();
      pc = sv.readInt();
      hl = sv.readInt();

      gbcRamBank = sv.readInt();

      // write ram 8Kb
      size = mainRam.length;
      if (sv.read(mainRam) != size) {
        System.out.println("Dmgcpu.loadState.loadData: mainRam loaded has different size!");
        System.exit(-1);
      }

      // write oam (used mainly for registers) 256 bytes
      size = oam.length;
      if (sv.read(oam) != size) {
        System.out.println("Dmgcpu.loadState.loadData: oam loaded has different size!");
        System.exit(-1);
      }

      saveInterrupt = false;
      loadStateInterrupt = false;
      saveCheckpointInterrupt = false;
      loadCheckpointInterrupt = false;

    } catch (IOException e) {
      System.out.println("Dmgcpu.saveState.loadData: Could not read file " + directory);
      System.out.println("Error Message: " + e.getMessage());
      System.exit(-1);
    }
  }
  private void writeAll() {
    List<MessageBean> beans = messageTable.getBeans();
    HashMap<Integer, Message> map = new HashMap<Integer, Message>(2 * beans.size());

    for (MessageBean mb : beans) {
      map.put(mb.m.hashCode(), mb.m);
    }

    if (fileChooser == null)
      fileChooser = new FileManager(null, null, null, (PreferencesExt) prefs.node("FileManager"));

    String defloc = (raf.getLocation() == null) ? "." : raf.getLocation();
    String dirName = fileChooser.chooseDirectory(defloc);
    if (dirName == null) return;

    try {
      int count = 0;
      for (Message m : map.values()) {
        String header = m.getHeader();
        if (header != null) {
          header = header.split(" ")[0];
        } else {
          header = Integer.toString(Math.abs(m.hashCode()));
        }

        File file = new File(dirName + "/" + header + ".bufr");
        FileOutputStream fos = new FileOutputStream(file);
        WritableByteChannel wbc = fos.getChannel();
        wbc.write(ByteBuffer.wrap(m.getHeader().getBytes()));
        byte[] raw = scan.getMessageBytes(m);
        wbc.write(ByteBuffer.wrap(raw));
        wbc.close();
        count++;
      }
      JOptionPane.showMessageDialog(
          BufrMessageViewer.this, count + " successfully written to " + dirName);

    } catch (IOException e1) {
      JOptionPane.showMessageDialog(BufrMessageViewer.this, e1.getMessage());
      e1.printStackTrace();
    }
  }
  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
예제 #28
0
  public BinaryDictionary(File wordList) throws FileNotFoundException {
    try {
      if (!wordList.exists())
        throw new FileNotFoundException("Error reading: " + wordList.getName());

      FileReader fr = new FileReader(wordList);
      BufferedReader br = new BufferedReader(fr);
      String word;

      // Populate list of words.
      while ((word = br.readLine()) != null) {
        words.add(word);
      }

      br.close();
      fr.close();
    } catch (IOException e) {
      System.out.println("Error: " + e.getMessage());
    }
  }
예제 #29
0
 private static String writeFileBytes(String path, byte[] data) {
   try {
     if (data.length>=524288 && !path.endsWith("JmolApplet.jar") ){ //gzip it
       path += ".gz";
       GZIPOutputStream gzFile = new GZIPOutputStream(new FileOutputStream(path));
       gzFile.write(data);
       LogPanel.log("      ..." + GT._("compressing large data file to") + "\n");
       gzFile.flush();
       gzFile.close();
     } else {
       FileOutputStream os = new FileOutputStream(path);
       os.write(data);
       os.flush();
       os.close();
     }
   } catch (IOException e) {
     LogPanel.log(e.getMessage());
   }
   return path;
 }
  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