Example #1
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!");
  }
  private void saveCurrent() {
    PrintWriter writer = null;

    try {
      writer = new PrintWriter("config.txt", "UTF-8");
      writer.println("PhoneNumbers:");

      for (String s : Main.getEmails()) {
        writer.println(s);
      }

      writer.println("Items:");

      for (Item s : Main.getItems()) {
        writer.println(s.getName() + "," + s.getWebsite());
      }

      results.setText("Current settings have been saved sucessfully.");
    } catch (FileNotFoundException e1) {
      e1.printStackTrace();
    } catch (UnsupportedEncodingException e1) {
      e1.printStackTrace();
    }

    writer.close();
  }
Example #3
0
  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());
    }
  }
Example #4
0
  private void onOK() {
    // add your code here
    try {
      PrintWriter pw = new PrintWriter("data\\out.txt");
      pw.println(textField1.getText());
      pw.close();

    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }
  }
Example #5
0
 /**
  * xlsxファイルを読み込み<b>XSSFWorkbook</b>を生成する
  *
  * @param filePath ファイルパス
  * @return <b>XSSFWorkbook</b>
  */
 public static XSSFWorkbook load(String filePath) {
   try {
     InputStream inputStream = new FileInputStream(filePath);
     XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
     return workbook;
   } catch (FileNotFoundException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
   return null;
 }
Example #6
0
  private Scanner scanFile() {

    Scanner s = null;

    try {
      s = new Scanner(new BufferedReader(new FileReader("./lab3/Liv.xml")));
      s.nextLine();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }

    return s;
  }
Example #7
0
  private OutputStream createFile(String fileName) {

    OutputStream outputStream = null;

    File outputFile = new File(fileName);

    try {
      outputStream = new FileOutputStream(outputFile);
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }

    return outputStream;
  }
Example #8
0
  protected void initUI() {
    File f = new File("Top100");
    String Str;
    String WORDS[] = new String[100];
    int FREQ[] = new int[100];
    String shuffle[] = new String[100];
    ArrayList<String> shuffling = new ArrayList<String>();
    int count = 0, i, temp = 1000000;
    try {
      Scanner br = new Scanner(f);

      while (br.hasNextLine()) {
        Str = br.nextLine();
        shuffling.add(Str);
      }
      br.close();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }
    Collections.shuffle(shuffling);
    for (String str : shuffling) {

      WORDS[count] = str.substring(0, str.indexOf(' '));
      FREQ[count] = Integer.parseInt(str.substring(str.indexOf(' ') + 1, str.length()));
      if (FREQ[count] < temp) temp = FREQ[count];
      count++;
    }
    JFrame frame = new JFrame(TestOpenCloud.class.getSimpleName());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel();
    // Cloud cloud = new Cloud();
    Random random = new Random();
    for (i = 0; i < 100; i++) {

      final int red = (int) (Math.random() * 150);
      final int green = (int) (Math.random() * 150);
      final int blue = (int) (Math.random() * 150);
      final JLabel label = new JLabel(WORDS[i]);
      label.setOpaque(false);
      label.setFont(new Font("Andalus", Font.PLAIN, ((FREQ[i] * 11) / temp)));
      Color color = new Color(red, green, blue);
      label.setForeground(color);
      panel.add(label);
    }
    frame.add(panel);
    frame.setSize(1366, 768);
    frame.setVisible(true);
  }
  /** Sets some ui properties and loads oroperties from .whatswrong */
  static {
    System.setProperty("apple.laf.useScreenMenuBar", "true");

    try {
      File file = new File(System.getProperty("user.home") + "/.whatswrong");
      if (file.exists()) {
        properties.load(new FileInputStream(file));
      } else {
        properties.setProperty("whatswrong.golddir", System.getProperty("user.dir"));
        properties.setProperty("whatswrong.guessdir", System.getProperty("user.dir"));
      }
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Example #10
0
 /**
  * Opens an InputStream.
  *
  * @return the stream
  */
 public InputStream openInputStream() {
   if (getFile() != null) {
     try {
       return new FileInputStream(getFile());
     } catch (FileNotFoundException ex) {
       ex.printStackTrace();
     }
   }
   if (getURL() != null) {
     try {
       return getURL().openStream();
     } catch (IOException ex) {
       ex.printStackTrace();
     }
   }
   return null;
 }
Example #11
0
  public Vector<Integer> getHighScore(String chemin) {
    BufferedReader reader;
    Vector<Integer> highScores = new Vector<Integer>();
    try {
      reader = new BufferedReader(new FileReader(new File(chemin)));

      do {
        highScores.add(Integer.parseInt(reader.readLine()));
      } while (reader != null);

    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (NumberFormatException e) {
    }

    return highScores;
  }
Example #12
0
  public static void main(final String[] args) {

    File logdir = new File(LOG_DIR);
    if (!logdir.exists()) logdir.mkdirs();
    File log = new File(logdir, "client.log");
    // redirect all console output to the file
    try {
      PrintStream out = new PrintStream(new FileOutputStream(log, true), true);
      out.format("[%s] ===== Client started =====%n", timestampf.format(new Date()));
      System.setOut(out);
      System.setErr(out);
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }

    /* Set up the error handler as early as humanly possible. */
    ThreadGroup g = new ThreadGroup("Haven main group");
    String ed;
    if (!(ed = Utils.getprop("haven.errorurl", "")).equals("")) {
      try {
        final haven.error.ErrorHandler hg = new haven.error.ErrorHandler(new java.net.URL(ed));
        hg.sethandler(
            new haven.error.ErrorGui(null) {
              public void errorsent() {
                hg.interrupt();
              }
            });
        g = hg;
      } catch (java.net.MalformedURLException e) {
      }
    }
    Thread main =
        new HackThread(
            g,
            new Runnable() {
              public void run() {
                main2(args);
              }
            },
            "Haven main thread");
    main.start();
  }
Example #13
0
 @FXML
 private void handleImportItemAction(ActionEvent event) {
   File fileLocation = new FileChooser().showOpenDialog(Main.stage);
   try (BufferedReader br = new BufferedReader(new FileReader(fileLocation))) {
     String line;
     while ((line = br.readLine()) != null) {
       final File folder = new File(line);
       if (folder.isDirectory()) {
         listFilesForFolder(folder);
       } else {
         Image img = new Image(folder.toURI().toString());
         imgMan.images.add(
             new ImageInformation(
                 img,
                 folder.toURI().toString(),
                 new ImageInformation.Type[] {
                   ImageInformation.Type.SAND, ImageInformation.Type.FISH,
                   ImageInformation.Type.ALGA, ImageInformation.Type.CORAL,
                   ImageInformation.Type.SAND
                 },
                 new Point[] {
                   new Point((int) (img.getWidth() * 0.25), (int) (img.getHeight() * 0.25)),
                   new Point((int) (img.getWidth() * 0.75), (int) (img.getHeight() * 0.25)),
                   new Point((int) (img.getWidth() * 0.5), (int) (img.getHeight() * 0.5)),
                   new Point((int) (img.getWidth() * 0.25), (int) (img.getHeight() * 0.75)),
                   new Point((int) (img.getWidth() * 0.75), (int) (img.getHeight() * 0.75))
                 },
                 new double[] {0.86, 0.76, 0.99, 0.65, 0.54}));
       }
     }
   } catch (FileNotFoundException e1) {
     e1.printStackTrace();
   } catch (IOException e1) {
     e1.printStackTrace();
   }
   imgMan.NextImage();
 }
Example #14
0
  private static boolean readScript() {
    try {
      FileReader scriptReader = new FileReader(getScriptFileName());
      BufferedReader bf = new BufferedReader(scriptReader);

      String aLine;
      int numberOfLines = 0;
      while ((aLine = bf.readLine()) != null) {
        commands.add(aLine);
      }

      scriptReader.close();
      bf.close();
      File f = new File(getScriptFileName());
      f.delete();
      f.createNewFile();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace(); // To change body of catch statement use File | Settings | File
      // Templates.
    }
    return false;
  }
Example #15
0
  public void loadState(String extension) {
    String directory = cartridge.romFileName + extension;

    try {
      reset();

      FileInputStream fl = new FileInputStream(directory);
      DataInputStream sv = new DataInputStream(fl);

      // write cpu data
      loadData(sv, directory);

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

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

      // writes io state
      ioHandler.loadData(sv, directory);

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

    } catch (FileNotFoundException ex) {
      System.out.println("Dmgcpu.loadState: Could not open file " + directory);
      System.out.println("Error Message: " + ex.getMessage());
      System.exit(-1);
    } catch (IOException ex) {
      System.out.println("Dmgcpu.loadState: Could not read file " + directory);
      System.out.println("Error Message: " + ex.getMessage());
      System.exit(-1);
    }

    System.out.println("Loaded stage!");
  }
Example #16
0
  public void jFileChooserActionPerformed(java.awt.event.ActionEvent evt)
      throws FileNotFoundException, IOException {
    File initialBoard = this.jFileChooser.getSelectedFile();
    InputStream inputStream = new FileInputStream(initialBoard);
    Scanner scanner = new Scanner(inputStream);

    if (!initialBoard
        .getName()
        .toLowerCase()
        .contains("initialboard")) { // .toLowerCase().compareTo("initialboard")!=0){
      JOptionPane.showMessageDialog(
          frame, "Wrong File \n Please select InitialBoard.txt", "Eror", JOptionPane.ERROR_MESSAGE);
    } else {

      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

      try {
        in = new BufferedReader(new FileReader(initialBoard.getAbsolutePath()));

      } catch (FileNotFoundException e) {
        System.out.println(e.getCause());
        System.out.println("Error loading initial board");
      }

      int[] boardRows = new int[15];

      // ----------------
      String text = in.readLine();

      StringTokenizer tokenizer = new StringTokenizer(text, " ");

      int boardSize = 0;
      while (tokenizer.hasMoreElements()) {
        boardRows[boardSize] = Integer.parseInt(tokenizer.nextToken());
        boardSize++;
      }

      int[] newBoard = new int[boardSize * boardSize + 1];
      System.arraycopy(boardRows, 0, newBoard, 1, boardSize);

      int index = 0;
      while (in.ready()) {
        index++;
        text = in.readLine();

        tokenizer = new StringTokenizer(text, " ");
        int pos = 0;
        while (tokenizer.hasMoreElements()) {
          pos++;
          newBoard[index * boardSize + pos] = Integer.parseInt(tokenizer.nextToken());
        }
      }

      this.jFrameFileChooser.setVisible(false);
      // this.boardPanel.s

      gameInitialBoard = new Board(newBoard, boardSize);
      gameBoard = new Board(newBoard, boardSize);
      init();
    }
  }
Example #17
0
  private void savePhone() {

    if (phone.getText().length() == 10) {
      File f = new File("config.txt");
      Scanner sc;

      ArrayList<String> config = new ArrayList<String>();

      try {
        sc = new Scanner(f);

        while (sc.hasNext()) {
          String s = sc.nextLine();
          config.add(s);
        }
        sc.close();

      } catch (FileNotFoundException e2) {
        results.setText("Error reading config.txt");
      }

      int i = 0;

      for (String s : config) {

        if (s.equals("PhoneNumbers:")) {
          break;
        }
        i++;
      }

      if (carriers.getSelectedIndex() == 0) {
        config.add(i + 1, phone.getText() + "@txt.att.net");
      }
      if (carriers.getSelectedIndex() == 1) {
        config.add(i + 1, phone.getText() + "@myboostmobile.com");
      }
      if (carriers.getSelectedIndex() == 2) {
        config.add(i + 1, phone.getText() + "@mobile.celloneusa.com");
      }
      if (carriers.getSelectedIndex() == 3) {
        config.add(i + 1, phone.getText() + "@messaging.nextel.com");
      }
      if (carriers.getSelectedIndex() == 4) {
        config.add(i + 1, phone.getText() + "@tmomail.net");
      }
      if (carriers.getSelectedIndex() == 5) {
        config.add(i + 1, phone.getText() + "@txt.att.net");
      }
      if (carriers.getSelectedIndex() == 6) {
        config.add(i + 1, phone.getText() + "@email.uscc.net");
      }
      if (carriers.getSelectedIndex() == 7) {
        config.add(i + 1, phone.getText() + "@messaging.sprintpcs.com");
      }
      if (carriers.getSelectedIndex() == 8) {
        config.add(i + 1, phone.getText() + "@vtext.com");
      }
      if (carriers.getSelectedIndex() == 9) {
        config.add(i + 1, phone.getText() + "@vmobl.com");
      }

      PrintWriter writer = null;
      try {
        writer = new PrintWriter("config.txt", "UTF-8");
        for (String s : config) {
          writer.println(s);
        }

      } catch (FileNotFoundException e1) {
        e1.printStackTrace();
      } catch (UnsupportedEncodingException e1) {
        e1.printStackTrace();
      }
      writer.close();
      addPhone();
    } else {
      results.setText("Please add 10 digit cell number.");
    }
  }
  public void addPackageClass(PackageClass pClass) {

    Document doc;
    try {
      doc = getDocument();
    } catch (Exception e) {
      e.printStackTrace();
      return;
    }

    String name = pClass.getName();

    // check if such class exists and remove duplicates
    Element rootEl = doc.getDocumentElement();
    NodeList classEls = rootEl.getElementsByTagName(EL_CLASS);
    for (int i = 0; i < classEls.getLength(); i++) {
      Element nameEl = getElementByName((Element) classEls.item(i), EL_NAME);
      if (name.equals(nameEl.getTextContent())) {
        rootEl.removeChild(classEls.item(i));
      }
    }

    Element classNode = doc.createElement(EL_CLASS);
    doc.getDocumentElement().appendChild(classNode);
    classNode.setAttribute(ATR_TYPE, PackageClass.ComponentType.SCHEME.getXmlName());
    classNode.setAttribute(ATR_STATIC, "false");

    Element className = doc.createElement(EL_NAME);
    className.setTextContent(name);
    classNode.appendChild(className);

    Element desrc = doc.createElement(EL_DESCRIPTION);
    desrc.setTextContent(pClass.getDescription());
    classNode.appendChild(desrc);

    Element icon = doc.createElement(EL_ICON);
    icon.setTextContent(pClass.getIcon());
    classNode.appendChild(icon);

    // graphics
    classNode.appendChild(generateGraphicsNode(doc, pClass.getGraphics()));

    // ports
    List<Port> ports = pClass.getPorts();
    if (!ports.isEmpty()) {
      Element portsEl = doc.createElement(EL_PORTS);
      classNode.appendChild(portsEl);

      for (Port port : ports) {
        portsEl.appendChild(generatePortNode(doc, port));
      }
    }

    // fields
    Collection<ClassField> fields = pClass.getFields();
    if (!fields.isEmpty()) {
      Element fieldsEl = doc.createElement(EL_FIELDS);
      classNode.appendChild(fieldsEl);

      for (ClassField cf : fields) {
        fieldsEl.appendChild(generateFieldNode(doc, cf));
      }
    }

    // write
    try {
      writeDocument(doc, new FileOutputStream(xmlFile));
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }
  }
Example #19
0
  // Thread's run method aimed at creating a bitmap asynchronously
  public void run() {
    Drawing drawing = new Drawing();
    PicText rawPicText = new PicText();
    String s = ((PicText) element).getText();
    rawPicText.setText(s);
    drawing.add(
        rawPicText); // bug fix: we must add a CLONE of the PicText, otherwise it loses it former
                     // parent... (then pb with the view )
    drawing.setNotparsedCommands(
        "\\newlength{\\jpicwidth}\\settowidth{\\jpicwidth}{"
            + s
            + "}"
            + CR_LF
            + "\\newlength{\\jpicheight}\\settoheight{\\jpicheight}{"
            + s
            + "}"
            + CR_LF
            + "\\newlength{\\jpicdepth}\\settodepth{\\jpicdepth}{"
            + s
            + "}"
            + CR_LF
            + "\\typeout{JPICEDT INFO: \\the\\jpicwidth, \\the\\jpicheight,  \\the\\jpicdepth }"
            + CR_LF);
    RunExternalCommand.Command commandToRun = RunExternalCommand.Command.BITMAP_CREATION;
    // RunExternalCommand command = new RunExternalCommand(drawing, contentType,commandToRun);
    boolean isWriteTmpTeXfile = true;
    String bitmapExt = "png"; // [pending] preferences
    String cmdLine =
        "{i}/unix/tetex/create_bitmap.sh {p} {f} "
            + bitmapExt
            + " "
            + fileDPI; // [pending] preferences
    ContentType contentType = getContainer().getContentType();
    RunExternalCommand.isGUI = false; // System.out, no dialog box // [pending] debug
    RunExternalCommand command =
        new RunExternalCommand(drawing, contentType, cmdLine, isWriteTmpTeXfile);
    command
        .run(); // synchronous in an async. thread => it's ok (anyway, we must way until the LaTeX
                // process has completed)

    if (wantToComputeLatexDimensions) {
      // load size of text:
      try {
        File logFile = new File(command.getTmpPath(), command.getTmpFilePrefix() + ".log");
        BufferedReader reader = null;
        try {
          reader = new BufferedReader(new FileReader(logFile));
        } catch (FileNotFoundException fnfe) {
          System.out.println("Cannot find log file! " + fnfe.getMessage());
          System.out.println(logFile);
        } catch (IOException ioex) {
          System.out.println("Log file IO exception");
          ioex.printStackTrace();
        } // utile ?
        System.out.println("Log file created! file=" + logFile);
        getDimensionsFromLogFile(reader, (PicText) element);
        syncStringLocation(); // update dimensions
        syncBounds();
        syncFrame();
        SwingUtilities.invokeLater(
            new Thread() {
              public void run() {
                repaint(null);
              }
            });
        // repaint(null); // now that dimensions are available, we force a repaint() [pending]
        // smart-repaint ?
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    if (wantToGetBitMap) {
      // load image:
      try {
        File bitmapFile =
            new File(command.getTmpPath(), command.getTmpFilePrefix() + "." + bitmapExt);
        this.image = ImageIO.read(bitmapFile);
        System.out.println(
            "Bitmap created! file="
                + bitmapFile
                + ", width="
                + image.getWidth()
                + "pixels, height="
                + image.getHeight()
                + "pixels");
        if (image == null) return;
        syncStringLocation(); // sets strx, stry, and dimensions of text
        syncBounds();
        // update the AffineTransform that will be applied to the bitmap before displaying on screen
        PicText te = (PicText) element;
        text2ModelTr.setToIdentity(); // reset
        PicPoint anchor = te.getCtrlPt(TextEditable.P_ANCHOR, ptBuf);
        text2ModelTr.rotate(getRotation(), anchor.x, anchor.y); // rotate along P_ANCHOR !
        text2ModelTr.translate(te.getLeftX(), te.getTopY());
        text2ModelTr.scale(
            te.getWidth() / image.getWidth(),
            -(te.getHeight() + te.getDepth()) / image.getHeight());
        // [pending]  should do something special to avoid dividing by 0 or setting a rescaling
        // factor to 0 [non invertible matrix] (java will throw an exception)
        syncFrame();
        SwingUtilities.invokeLater(
            new Thread() {
              public void run() {
                repaint(null);
              }
            });
        // repaint(null); // now that bitmap is available, we force a repaint() [pending]
        // smart-repaint ?
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }