コード例 #1
0
  public void save() {
    for (String key : fields.keySet()) {
      JComponent comp = fields.get(key);

      if (comp instanceof JTextField) {
        JTextField c = (JTextField) comp;

        if (c.getText().trim().equals("")) {
          sketch.configFile.unset(key);
        } else {
          sketch.configFile.set(key, c.getText());
        }
      } else if (comp instanceof JTextArea) {
        JTextArea c = (JTextArea) comp;

        if (c.getText().trim().equals("")) {
          sketch.configFile.unset(key);
        } else {
          sketch.configFile.set(key, c.getText());
        }
      }
    }

    sketch.saveConfig();
  }
コード例 #2
0
  /** The listener method. */
  public void actionPerformed(ActionEvent event) {
    Object source = event.getSource();

    if (source == b1) // click button
    {
      try {
        String message = tf.getText();
        server.sendPrivateMessage(parent, selfIdentity, message);
        ta.append("<" + parent.getUserName() + ">: " + message + lineSeparator);
        ta.setCaretPosition(ta.getText().length());
        tf.setText("");
      } catch (RemoteException ex) {
        System.out.print("Exception encountered while sending" + " private message.");
      }
    }

    if (source == tf) // press return
    {
      try {
        String message = tf.getText();
        server.sendPrivateMessage(parent, selfIdentity, message);
        ta.append("<" + parent.getUserName() + ">: " + message + lineSeparator);
        ta.setCaretPosition(ta.getText().length());
        tf.setText("");
      } catch (RemoteException ex) {
        System.out.print("Exception encountered while sending" + " private message.");
      }
    }
    if (source == jMenuItem3) {
      JFileChooser fileChooser = new JFileChooser();

      fileChooser.setDialogTitle("Choose or create a new file to store the conversation");
      fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
      fileChooser.setDoubleBuffered(true);

      fileChooser.showOpenDialog(this);

      File file = fileChooser.getSelectedFile();

      try {
        if (file != null) {

          Writer writer = new BufferedWriter(new FileWriter(file));

          writer.write(ta.getText());
          writer.flush();
          writer.close();
        }
      } catch (IOException ex) {
        System.out.println("Can't write to file. " + ex);
      }
    }
    if (source == jMenuItem4) {
      selfRemove();
      this.dispose();
    }
  }
コード例 #3
0
ファイル: JConsoleOutLinker.java プロジェクト: antoniou/vfork
  public synchronized void run() {

    byte[] buffer = new byte[BUFFER_SIZE];

    for (; ; ) {
      try {
        this.wait(100);
      } catch (InterruptedException ie) {
      }

      int len = 0;
      try {
        int noBytes = pin.available();

        if (noBytes > 0) {
          len = pin.read(buffer, 0, Math.min(noBytes, BUFFER_SIZE));
          if (len > 0) {
            jTextArea.append(new String(buffer, 0, len));
            jTextArea.setCaretPosition(jTextArea.getText().length());
          }
        }
      } catch (IOException ioe) {
        throw new UIError("Unable to read from input stream! " + ioe.getMessage());
      }
    }
  }
コード例 #4
0
ファイル: IdeMain.java プロジェクト: aimozg/ja-dcpu
 private void saveSrc() {
   fileChooser.resetChoosableFileFilters();
   fileChooser.addChoosableFileFilter(asmFilter);
   fileChooser.setFileFilter(asmFilter);
   if (fileChooser.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) {
     try {
       File file = fileChooser.getSelectedFile();
       if (fileChooser.getFileFilter() == asmFilter && !asmFilter.accept(file)) {
         file = new File(file.getAbsolutePath() + asmFilter.getExtensions()[0]);
       }
       if (file.exists()) {
         if (JOptionPane.showConfirmDialog(
                 frame, "File exists. Overwrite?", "Confirm", JOptionPane.YES_NO_OPTION)
             != JOptionPane.YES_OPTION) {
           return;
         }
       }
       PrintStream output = new PrintStream(file);
       output.print(sourceTextarea.getText());
       output.close();
     } catch (IOException e1) {
       JOptionPane.showMessageDialog(
           frame, "Unable to open file", "Error", JOptionPane.ERROR_MESSAGE);
       e1.printStackTrace();
     }
   }
 }
コード例 #5
0
ファイル: EditFrame.java プロジェクト: BrotherPhil/ROPE
  public void save() {
    BufferedWriter sourceFile = null;

    try {
      String sourceText = sourceArea.getText();

      String cleanText = cleanupSource(sourceText);

      if (cleanText.length() != sourceText.length()) {
        sourceArea.setText(cleanText);

        String message =
            String.format(
                "One or more invalid characters at the end of the source file have been removed.");
        JOptionPane.showMessageDialog(this, message, "ROPE", JOptionPane.INFORMATION_MESSAGE);
      }

      sourceFile = new BufferedWriter(new FileWriter(sourcePath, false));
      sourceFile.write(cleanText);

      setSourceChanged(false);

      setupMenus();
    } catch (IOException ex) {
      ex.printStackTrace();
    } finally {
      if (sourceFile != null) {
        try {
          sourceFile.close();
        } catch (IOException ignore) {
        }
      }
    }
  }
コード例 #6
0
 @Override
 public synchronized void write(byte[] ba, int str, int len) {
   try {
     curLength += len;
     if (bytesEndWith(ba, str, len, LINE_SEP)) {
       lineLengths.addLast(new Integer(curLength));
       curLength = 0;
       if (lineLengths.size() > maxLines) {
         textArea.replaceRange(null, 0, lineLengths.removeFirst().intValue());
       }
     }
     for (int xa = 0; xa < 10; xa++) {
       try {
         textArea.append(new String(ba, str, len));
         break;
       } catch (
           Throwable
               thr) { // sometimes throws a java.lang.Error: Interrupted attempt to aquire write
                      // lock
         if (xa == 9) {
           thr.printStackTrace();
         }
       }
     }
     textArea.setCaretPosition(textArea.getText().length());
   } catch (Throwable thr) {
     CharArrayWriter caw = new CharArrayWriter();
     thr.printStackTrace(new PrintWriter(caw, true));
     textArea.append(System.getProperty("line.separator", "\n"));
     textArea.append(caw.toString());
   }
 }
コード例 #7
0
ファイル: ListInputPanel.java プロジェクト: MrSampson/jMIR
  /**
   * Takes the contents of the text area and breaks them into an array with an entry for each line
   * in the text area. Blank lines are removed but no other processing is performed.
   *
   * @return The lines found in text area. Blank lines are removed. Null is returned if the text
   *     area is empty.
   */
  public String[] getStrings() {
    String field_contents = text_area.getText();
    if (field_contents == null) return null;
    if (field_contents.equals("")) return null;

    String[] search_strings =
        mckay.utilities.staticlibraries.StringMethods.breakIntoTokens(field_contents, "\n");
    if (search_strings.length == 0) return null;

    return search_strings;
  }
コード例 #8
0
 public boolean saveToFile(String namefile) {
   try {
     File file = new File(namefile);
     FileWriter out = new FileWriter(file);
     String text = textArea.getText();
     out.write(text);
     out.close();
     return true;
   } catch (IOException e) {
     System.out.println("Error saving file.");
   }
   return false;
 }
コード例 #9
0
ファイル: Secondtry.java プロジェクト: japanna/unit6.1
  public void calc() {

    if (operator == "+") {
      firstNum += secondNum;
      System.out.println("firstNum plus secondNum is: " + firstNum);
    }
    if (operator == "-") {
      firstNum -= secondNum;
      System.out.println("firstNum minus secondNum is: " + firstNum);
    }
    if (operator == "*") {
      firstNum *= secondNum;
      System.out.println("firstNum times secondNum is: " + firstNum);
    }
    if ((operator == "/") && secondNum != 0.0) {
      System.out.println("firstNum div by secondNum is: " + firstNum);
      firstNum /= secondNum;
    }
    if ((operator == "/") && secondNum == 0.0) {
      display.setText("ERROR");
      System.out.println(display.getText());
      firstNum = 0.0;
      secondNum = 0.0;
      operators = true;
      doClear = true;
    }

    if (!(display.getText().equals("ERROR"))) {
      operators = true;
      decPoint = false;

      display.setText(String.valueOf(firstNum));

      secondNum = firstNum;

      System.out.println("SecondNum is: " + firstNum);
    }
  }
コード例 #10
0
ファイル: prologApplet.java プロジェクト: mberionni/uni
  protected void compile() {
    Sexp curClause;
    goal = new NilSexp();
    prog = new NilSexp();
    prog2 = new NilSexp();
    String codice = code.getText();

    try {
      ProParser p = new ProParser(codice, intmsg);
      for (; ; ) {
        curClause = p.getClause(); // seleziono una singola clausola
        intmsg.append("compiled: " + curClause + "\n");
        if (!(curClause instanceof eofToken)) {
          prog = Sexp.append(prog, Sexp.list1(curClause));
        }
        if (p.atEOF()) {
          break;
        }
      }
      String codice2 = code.getText();
      ProParser p2 = new ProParser(codice2, intmsg);
      for (; ; ) {
        curClause = p2.getClause(); // seleziono una singola clausola
        // intmsg.append( "compiled: " + curClause + "\n" );
        if (!(curClause instanceof eofToken)) {
          prog2 = Sexp.append(prog2, Sexp.list1(curClause));
        }
        if (p2.atEOF()) {
          break;
        }
      }

      showProg(prog, outp);
      // showProg( prog2, outp );
    } catch (Exception e) {
      outp.append("error" + e + " \n");
    }
  }
コード例 #11
0
ファイル: ListInputPanel.java プロジェクト: MrSampson/jMIR
  /**
   * Appends each string in the new_strings parameter as a new line in the text area. Sets the caret
   * is set to the beginning of the text.
   *
   * @param new_strings The strings to add. Each entry is added to a new line. This method performs
   *     no action if this parameter is empty or null.
   */
  public void appendStrings(String[] new_strings) {
    if (new_strings != null)
      if (new_strings.length != 0) {
        // Append the text
        for (int i = 0; i < new_strings.length; i++) {
          if (i == 0) {
            if (!text_area.getText().equals("")) text_area.append("\n");
          } else text_area.append("\n");

          text_area.append(new_strings[i]);
        }

        // Reset the caret position
        text_area.setCaretPosition(0);
      }
  }
コード例 #12
0
ファイル: EditFrame.java プロジェクト: BrotherPhil/ROPE
  void doCaretUpdate(int dot, int mark) {
    if (dot == mark) {
      mainFrame.cutItem.setEnabled(false);
      mainFrame.copyItem.setEnabled(false);
      mainFrame.deleteItem.setEnabled(false);
    } else {
      mainFrame.cutItem.setEnabled(true);
      mainFrame.copyItem.setEnabled(true);
      mainFrame.deleteItem.setEnabled(true);
    }

    int length = sourceArea.getText().length();
    if (length == 0 || abs(mark - dot) == length) {
      mainFrame.selectAllItem.setEnabled(false);
    } else {
      mainFrame.selectAllItem.setEnabled(true);
    }

    try {
      if (length == 0) {
        mainFrame.selectLineItem.setEnabled(false);
      } else {
        int lineNum = sourceArea.getLineOfOffset(dot);
        int startLine = sourceArea.getLineStartOffset(lineNum);
        int endLine = sourceArea.getLineEndOffset(lineNum);
        if (endLine - startLine <= 1) {
          mainFrame.selectLineItem.setEnabled(false);
        } else {
          mainFrame.selectLineItem.setEnabled(true);
        }
      }
    } catch (BadLocationException ex) {
      ex.printStackTrace();
    }

    try {
      int line = sourceArea.getLineOfOffset(dot);
      lineText.setText(Integer.toString(line + 1));
      int column = dot - sourceArea.getLineStartOffset(line);
      columnText.setText(Integer.toString(column + 1));
    } catch (BadLocationException ex) {
      ex.printStackTrace();
    }
  }
コード例 #13
0
ファイル: EditFrame.java プロジェクト: BrotherPhil/ROPE
  public void saveAs() {
    Vector<RopeFileFilter> filters = new Vector<RopeFileFilter>();

    if (fileExt.equals("m") || fileExt.equals("mac")) {
      filters.add(new RopeFileFilter(new String[] {".m", ".mac"}, "Macro files (*.m *.mac)"));
      filters.add(
          new RopeFileFilter(
              new String[] {".a", ".asm", ".aut", ".s"}, "Assembly files (*.a *.asm *.aut *.s)"));
    } else {
      filters.add(
          new RopeFileFilter(
              new String[] {".a", ".asm", ".aut", ".s"}, "Assembly files (*.a *.asm *.aut *.s)"));
      filters.add(new RopeFileFilter(new String[] {".m", ".mac"}, "Macro files (*.m *.mac)"));
    }
    filters.add(new RopeFileFilter(new String[] {".txt"}, "Text files (*.txt)"));

    RopeFileChooser chooser = new RopeFileChooser(selectedPath, null, filters);
    chooser.setDialogTitle("Save Source File");
    String fileName = String.format("%s.%s", baseName, fileExt);
    chooser.setSelectedFile(new File(selectedPath, fileName));
    JTextField field = chooser.getTextField();
    field.setSelectionStart(0);
    field.setSelectionEnd(baseName.length());
    File file = chooser.save(ROPE.mainFrame);
    if (file != null) {
      selectedPath = file.getParent();

      BufferedWriter writer = null;
      try {
        writer = new BufferedWriter(new FileWriter(file));
        writer.write(sourceArea.getText());
      } catch (IOException ex) {
        ex.printStackTrace();
      } finally {
        try {
          if (writer != null) {
            writer.close();
          }
        } catch (IOException ex) {
          ex.printStackTrace();
        }
      }
    }
  }
コード例 #14
0
ファイル: SISCFrame.java プロジェクト: igorhvr/bedlam
 public void actionPerformed(ActionEvent e) {
   if (e.getActionCommand().equals("Clear")) input.setText("");
   else {
     String s = input.getText().trim();
     if (s.length() > 1 && s.charAt(s.length() - 1) == '\n') s = s.substring(0, s.length() - 1);
     PushbackReader ip = new PushbackReader(new BufferedReader(new StringReader(s)));
     Value v = Util.VOID;
     try {
       v = sp.dynenv.parser.nextExpression(ip);
     } catch (EOFException eof) {
       // eof.printStackTrace();
       return;
     } catch (Exception ie) {
       System.err.println(ie);
     }
     if (autoClear.isSelected()) input.setText("");
     sp.eval(s);
   }
 }
コード例 #15
0
ファイル: Viewer.java プロジェクト: SuperMarcus/LevelDBViewer
 public void update(JTextArea area) {
   DBItem item = dataList.getSelectedValue();
   if (item != null && !isSet) {
     isSet = true;
     try {
       if (area == hexKey) {
         if (area.getText().isEmpty()) {
           return;
         }
         item.key =
             new BigInteger(area.getText().replaceAll("\n", "").replaceAll("%\\{EOL}", "\n"), 16)
                 .toByteArray();
         stringKey.setText(cutToLine(new String(item.key), 64));
         dataList.updateUI();
       } else if (area == stringKey) {
         if (area.getText().isEmpty()) {
           return;
         }
         item.key = area.getText().replaceAll("\n", "").replaceAll("%\\{EOL}", "\n").getBytes();
         hexKey.setText(cutToLine(LevelDBViewer.toHexString(item.key), 64));
         dataList.updateUI();
       } else if (area == hexValue) {
         item.value =
             new BigInteger(area.getText().replaceAll("\n", "").replaceAll("%\\{EOL}", "\n"), 16)
                 .toByteArray();
         stringValue.setText(cutToLine(new String(item.value), 64));
       } else if (area == stringValue) {
         item.value = area.getText().replaceAll("\n", "").replaceAll("%\\{EOL}", "\n").getBytes();
         hexValue.setText(cutToLine(LevelDBViewer.toHexString(item.value), 64));
       }
       notice.setVisible(false);
       notice.setText("");
       saveButton.setEnabled(true);
     } catch (Exception e) {
       notice.setVisible(true);
       notice.setText("Invalid number!");
     } finally {
       lengthLabel.setText(String.valueOf(item.value.length + item.key.length));
       keyLength.setText(String.valueOf(item.key.length));
       valueLength.setText(String.valueOf(item.value.length));
       isSet = false;
     }
   }
 }
コード例 #16
0
ファイル: IdeMain.java プロジェクト: aimozg/ja-dcpu
 private void assemble() {
   Assembler assembler = new Assembler();
   assembler.genMap = true;
   try {
     binary = new char[] {};
     binary = assembler.assemble(sourceTextarea.getText());
     cpu.upload(binary);
     memoryModel.fireUpdate(0, binary.length);
     asmMap = assembler.asmmap;
     for (Character addr : debugger.getBreakpoints()) {
       debugger.setBreakpoint(addr, false);
     }
     for (Integer breakpoint : srcBreakpoints) {
       Character addr = asmMap.src2bin(breakpoint);
       if (addr != null) { // TODO if null, mark breakpoint somehow
         debugger.setBreakpoint(addr, true);
       }
     }
   } catch (Exception ex) {
     JOptionPane.showMessageDialog(
         frame, "Compilation error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
     ex.printStackTrace();
   }
 }
コード例 #17
0
 // called by the Client to append text in the TextArea
 void append(String str) {
   chatArea.append(str);
   chatArea.setCaretPosition(chatArea.getText().length() - 1);
 }
コード例 #18
0
 /** Displays a new incomming private message. */
 public void displayPrivateMessage(ClientInterface from, String message) throws RemoteException {
   ta.append("<" + from.getUserName() + ">: " + message + lineSeparator);
   ta.setCaretPosition(ta.getText().length());
 }
コード例 #19
0
ファイル: FileManager2.java プロジェクト: OUHK/Java-Lab
 public String getOut() {
   return out.getText();
 }
コード例 #20
0
ファイル: ShowComp.java プロジェクト: vishalshar/NetMon
 void show() {
   if (connectFinish != 0) ta.setText(ta.getText() + "\n" + add);
   shown = true;
 }
コード例 #21
0
  /**
   * waitForConnection waits for incomming connections. There are two cases. If we receive a
   * JoinNetworkRequest it means that a new peer tries to get into the network. We lock the entire
   * system, and sends a ConnectionData object to the new peer, from which he can connect to every
   * other peer. We add this new peer to our data.
   *
   * <p>If we receive a NewPeerDataRequest, it means that a new peer has received ConnectionData
   * from another peer in the network, and he is now trying to connect to everyone, including me. We
   * then update our data with the new peer.
   */
  private void waitForConnection() {
    while (active) {
      Socket client = waitForConnectionFromClient();
      if (client != null) {
        try {
          ObjectOutputStream output = new ObjectOutputStream(client.getOutputStream());
          ObjectInputStream input = new ObjectInputStream(client.getInputStream());
          Object o = input.readObject();

          if (o instanceof JoinNetworkRequest) {
            JoinNetworkRequest request = (JoinNetworkRequest) o;
            dec.sendObjectToAllPeers(new LockRequest(lc.getTimeStamp()));
            waitForAllToLock();
            setLocked(true);
            Thread.sleep(500);
            int id = getNewId();
            Peer p =
                new Peer(
                    editor,
                    er,
                    id,
                    client,
                    output,
                    input,
                    lc,
                    client.getInetAddress().getHostAddress(),
                    request.getPort());
            ConnectionData cd =
                new ConnectionData(
                    er.getEventHistory(),
                    er.getAcknowledgements(),
                    er.getCarets(),
                    id,
                    area1.getText(),
                    lc.getTimeStamp(),
                    lc.getID(),
                    dec.getPeers(),
                    serverSocket.getLocalPort());
            p.writeObjectToStream(cd);
            dec.addPeer(p);
            Thread t = new Thread(p);
            t.start();
            er.addCaretPos(id, 0);
          } else if (o instanceof NewPeerDataRequest) {
            NewPeerDataRequest request = (NewPeerDataRequest) o;
            Peer newPeer =
                new Peer(
                    editor,
                    er,
                    request.getId(),
                    client,
                    output,
                    input,
                    lc,
                    client.getInetAddress().getHostAddress(),
                    request.getPort());
            dec.addPeer(newPeer);
            er.addCaretPos(request.getId(), request.getCaretPos());
            newPeer.writeObjectToStream(new NewPeerDataAcknowledgement(lc.getTimeStamp()));
            Thread t = new Thread(newPeer);
            t.start();
          }
        } catch (IOException | ClassNotFoundException | InterruptedException e) {
          e.printStackTrace();
        }
      }
    }
  }
コード例 #22
0
ファイル: Secondtry.java プロジェクト: japanna/unit6.1
  public void actionPerformed(ActionEvent ae) {
    // clear display if new number is to be entered
    if (doClear) display.setText(null);

    // if decimal point is entered for the first time in number
    if ((ae.getSource() == point) && decPoint == false) {
      display.append(".");
      // disallow more decimal points
      decPoint = true;
    }

    // if decimal point is the first in a number, display "0."
    if (display.getText().equals(".")) display.setText("0.");

    // check if a digit was clicked
    for (int i = 0; i < 10; i++) {

      // append digits to number while number is less than 15 digits long
      if ((ae.getSource() == jb[i]) && (display.getText().length() < 15)) {

        display.append(((JButton) ae.getSource()).getText());

        // disallow leading zeros
        if (display.getText().equals("0")) display.setText("0.");

        // store as a Double
        secondNum = Double.parseDouble(display.getText());
        System.out.println("SecondNum is: " + secondNum);

        doClear = false;
        // only if you click another digit
        oldOp = false;
      }
    }

    // check if an operator was clicked
    if ((ae.getSource() == plus)
        || (ae.getSource() == minus)
        || (ae.getSource() == div)
        || (ae.getSource() == mult)) {
      decPoint = false;
      if (oldOp == false) {
        // if this is the first time an operator was clicked
        if (operators) {
          // the number last entered becomes the first number
          firstNum = secondNum;
          System.out.println("firstNum is: " + secondNum);
        } else {

          calc();
        }

        // store the operator that was clicked
        JButton temp = (JButton) ae.getSource();
        operator = temp.getText();
        System.out.println("Operator is: " + operator);
        operators = false;
        doClear = true;
        oldOp = true;
      }
      // if an operator was clicked without a digit having been entered between
      else {
        // store the operator that was clicked
        JButton temp = (JButton) ae.getSource();
        operator = temp.getText();
        System.out.println("Operator is: " + operator);
        display.setText(String.valueOf(firstNum));
      }
    }

    if (ae.getSource() == root) {
      squareRoot();
      decPoint = false;
    }

    if (ae.getSource() == clear) {
      clear();
    }

    if (ae.getSource() == equals) {
      calc();
    }
  }
コード例 #23
0
ファイル: ListInputPanel.java プロジェクト: MrSampson/jMIR
 /**
  * Returns a dump of the contents of the text area.
  *
  * @return The contents of the text area.
  */
 public String getText() {
   return text_area.getText();
 }