Esempio n. 1
0
  public void newItem() {
    Date dtn = new Date();
    SimpleDateFormat formatter1 = new SimpleDateFormat("dd.MM.yyyy HH-mm");
    String dt = formatter1.format(dtn);
    KOptionPane.showInputDialog(
        ctx.getRootContainer(),
        i18n.getString("new_note_name"),
        dt,
        new InputDialogListener() {

          public void onClose(String arg0) {
            if (arg0 == null) return;
            File file = new File(ctx.getHomeDirectory(), arg0 + ".txt");
            if (!file.exists()) {
              try {
                file.createNewFile();
                addHomeItem(arg0, 0);
              } catch (IOException e) {
                e.printStackTrace();
              }
            }
            openAndEditFile(arg0);
          }
        });
  }
Esempio n. 2
0
  public void openFile(String filename) {
    currentFileName = ctx.getHomeDirectory().getAbsolutePath() + "/" + filename + ".txt";
    String text = new String();
    String str;
    try {
      BufferedReader in = new BufferedReader(new FileReader(currentFileName));
      try {
        while ((str = in.readLine()) != null) {
          text = text + str + "\n";
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
      try {
        in.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    } catch (FileNotFoundException e) {
      KOptionPane.showMessageDialog(
          null,
          i18n.getString("not_found"),
          new MessageDialogListener() {

            public void onClose() {
              // nothing
            }
          });
      e.printStackTrace();
      return;
    }
    this.newItem.setEnabled(false);
    ctx.getRootContainer().remove(this.homeMenu);
    //			ctx.getRootContainer().remove(this.searchField);
    ctx.getRootContainer().remove(this.northPanel);
    ctx.getRootContainer().remove(this.pageLabel);
    plainText.setText(text);
    ctx.getRootContainer().add(plainText);
    plainText.requestFocus();
    ctx.setSubTitle(filename);
  }