Пример #1
0
 public void sendEmail() {
   String email = person.getEmail();
   errorMessage.setForeground(Color.blue);
   String recipientEmail = person.getEmail();
   String recipientName = person.getName();
   person.getUsername();
   person.getId();
   String newPassword = "";
   char[] newChar = new char[10];
   for (int i = 0; i < 10; i++) {
     newChar[i] = getRandomString(10).charAt(i);
     newPassword = newPassword + newChar[i];
     try {
       // if you generate more than 1 time, you must
       // put the process to sleep for awhile
       // otherwise it will return the same random
       // string
       Thread.sleep(100);
     } catch (InterruptedException d) {
       d.printStackTrace();
     }
   }
   if (sendEmail(
       "*****@*****.**", "oopjpass", recipientEmail, recipientName, newPassword)) {
     errorMessage.setText(
         errorMessage.getText() + "A replacement password has been sent to \n" + recipientEmail);
   } else {
     errorMessage.setText(errorMessage.getText() + "Sending failed.");
   }
   DesEncryption encryption = new DesEncryption("Password");
   inputPassword = encryption.encrypt(newPassword);
 }
Пример #2
0
    public void actionPerformed(ActionEvent a) {
      String command = a.getActionCommand();
      if (command.equals("e")) {
        // Log toggle.
        if (consoleDisplayed = !consoleDisplayed) {
          splitter.add(outputScroll);
          splitter.setDividerLocation(.8);
        } else {
          splitter.remove(outputScroll);
        }
      } else if (command.equals("k")) {
        if (text.getText().contains("class")) {
          // This means we should try to compile this as normal.

          // Pulls out class name
          String code = text.getText();
          int firstPos = code.indexOf("class");
          int secondPos = code.indexOf("{");
          String name = code.substring(firstPos + "class".length() + 1, secondPos).trim();

          compileAndRun(name, text.getText());
        } else {
          // This means we should compile this as a playground.
          String code = text.getText();

          // Common import statements built-in
          String importDump = new String();
          importDump +=
              ("import java.util.*;\n"
                  + "import javax.swing.*;\n"
                  + "import javax.swing.event.*;\n"
                  + "import java.awt.*;\n"
                  + "import java.awt.event.*;\n"
                  + "import java.io.*;\n");

          // Pulls out any "import" statements and appends them to the import dump.
          int i = code.indexOf("import");
          while (i >= 0) {
            String s = code.substring(i, code.indexOf(";", i) + 1);
            code = code.replaceFirst(s, "");
            importDump += s + "\n";
            i = code.indexOf("import", i + 1);
          }

          // Inject the class header and main method
          code =
              "//User and auto-imports pre-defined\n"
                  + importDump
                  + "//Autogenerated class\npublic class Main {\npublic static void main(String[] args) {\n"
                  + code
                  + "\n}\n}";

          compileAndRun("Main", code);
        }
      }
    }
Пример #3
0
 public void createStudent(RemoteController control) {
   try {
     control.createStudent(
         txtName.getText(),
         Integer.parseInt(txtNOG.getText()),
         txtFaculty.getText(),
         txtDOE.getText());
   } catch (Exception iae) {
     JOptionPane.showMessageDialog(
         null, iae.getMessage(), "Inane error", JOptionPane.ERROR_MESSAGE);
   }
 }
Пример #4
0
  public void printSystemMsg(String s) {
    textPane.setEditable(true);
    if (lastEnd >= 0) {
      textPane.setSelectionStart(lastEnd);
      lastEnd = -1;
    } else textPane.setSelectionStart(textPane.getText().length());
    textPane.setSelectionEnd(textPane.getText().length());
    textPane.replaceSelection("");

    textPane.setSelectionStart(textPane.getText().length());
    textPane.setSelectionEnd(textPane.getText().length());
    textPane.setCharacterAttributes(textPane.getStyle("SystemMessage"), true);
    textPane.replaceSelection(s);
    textPane.setEditable(false);
  }
 public void saveLog() {
   File file = new File("." + File.separator);
   String logFile = null;
   try {
     logFile =
         RapidMinerGUI.getMainFrame()
             .getProcess()
             .getRootOperator()
             .getParameterAsString(ProcessRootOperator.PARAMETER_LOGFILE);
   } catch (UndefinedParameterError ex) {
     // tries to use process file name for initialization
   }
   if (logFile != null) {
     file = RapidMinerGUI.getMainFrame().getProcess().resolveFileName(logFile);
   }
   file = SwingTools.chooseFile(RapidMinerGUI.getMainFrame(), file, false, "log", "log file");
   if (file != null) {
     PrintWriter out = null;
     try {
       out = new PrintWriter(new FileWriter(file));
       out.println(textArea.getText());
     } catch (IOException ex) {
       SwingTools.showSimpleErrorMessage("cannot_write_log_file", ex);
     } finally {
       if (out != null) {
         out.close();
       }
     }
   }
 }
Пример #6
0
  /** Attempts to log in. */
  private void login() {
    firePropertyChange(TO_FRONT_PROPERTY, Boolean.valueOf(false), Boolean.valueOf(true));
    requestFocusOnField();
    StringBuffer buf = new StringBuffer();
    buf.append(pass.getPassword());
    String usr = user.getText(), psw = buf.toString();
    String s = serverText.getText();
    if (CommonsLangUtils.isBlank(usr)
        || CommonsLangUtils.isBlank(s)
        || s.trim().equals(DEFAULT_SERVER)) {
      requestFocusOnField();
      return;
    }
    if (usr != null) usr = usr.trim();
    if (s != null) s = s.trim();
    setControlsEnabled(false);
    LoginCredentials lc;
    if (groupsBox == null) {
      lc = new LoginCredentials(usr, psw, s, speedIndex, selectedPort, encrypted);
    } else {
      long id = -1L;
      if (hasGroupOption() && groupsBox.isVisible())
        // id = getGroupId(groupsBox.getText());
        id = getGroupId(groupNames.get(groupsBox.getSelectedIndex()));

      lc = new LoginCredentials(usr, psw, s, speedIndex, selectedPort, id, encrypted);
    }
    setUserName(usr);
    setEncrypted();
    setControlsEnabled(false);
    loginAttempt = true;
    login.setEnabled(false);
    firePropertyChange(LOGIN_PROPERTY, null, lc);
  }
Пример #7
0
 public void evaluate() {
   try {
     // clear problems and console messages
     problemsView.setText("");
     consoleView.setText("");
     // update status view
     statusView.setText(" Parsing ...");
     tabbedPane.setSelectedIndex(0);
     LispExpr root = Parser.parse(textView.getText());
     statusView.setText(" Running ...");
     tabbedPane.setSelectedIndex(1);
     // update run button
     runButton.setIcon(stopImage);
     runButton.setActionCommand("Stop");
     // start run thread
     runThread = new RunThread(root);
     runThread.start();
   } catch (SyntaxError e) {
     tabbedPane.setSelectedIndex(0);
     System.err.println(
         "Syntax Error at " + e.getLine() + ", " + e.getColumn() + " : " + e.getMessage());
   } catch (Error e) {
     // parsing error
     System.err.println(e.getMessage());
     statusView.setText(" Errors.");
   }
 }
Пример #8
0
 /** Sets the enabled flag of the {@link #login} button. */
 private void enableControls() {
   boolean enabled = true;
   String s = serverText.getText();
   char[] name = pass.getPassword();
   String usr = user.getText().trim();
   if (CommonsLangUtils.isBlank(s) || CommonsLangUtils.isBlank(usr)) {
     enabled = false;
   } else {
     s = s.trim();
     if (DEFAULT_SERVER.equals(s)) {
       enabled = false;
     }
   }
   login.setEnabled(enabled);
   if (enabled) {
     ActionListener[] listeners = login.getActionListeners();
     if (listeners != null) {
       boolean set = false;
       for (int i = 0; i < listeners.length; i++) {
         if (listeners[i] == this) {
           set = true;
           break;
         }
       }
       if (!set) login.addActionListener(this);
     }
     login.setForeground(defaultForeground);
   } else {
     login.setForeground(FOREGROUND_COLOR);
   }
   layout(hasGroupOption());
 }
Пример #9
0
  private boolean checkForSave() {
    // build warning message
    String message;
    if (file == null) {
      message = "File has been modified.  Save changes?";
    } else {
      message = "File \"" + file.getName() + "\" has been modified.  Save changes?";
    }

    // show confirm dialog
    int r =
        JOptionPane.showConfirmDialog(
            this,
            new JLabel(message),
            "Warning!",
            JOptionPane.YES_NO_CANCEL_OPTION,
            JOptionPane.WARNING_MESSAGE);

    if (r == JOptionPane.YES_OPTION) {
      // Save File
      if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
        // write the file
        physWriteTextFile(fileChooser.getSelectedFile(), textView.getText());
      } else {
        // user cancelled save after all
        return false;
      }
    }
    return r != JOptionPane.CANCEL_OPTION;
  }
Пример #10
0
 private void updateDisplay() {
   // first, set block colours
   textView.setBackground(getColour(backgroundColour("text-background-colour")));
   textView.setForeground(getColour(foregroundColour("text-foreground-colour")));
   textView.setCaretColor(getColour(foregroundColour("text-caret-colour")));
   problemsView.setBackground(getColour(backgroundColour("problems-background-colour")));
   problemsView.setForeground(getColour(foregroundColour("problems-foreground-colour")));
   consoleView.setBackground(getColour(backgroundColour("console-background-colour")));
   consoleView.setForeground(getColour(foregroundColour("console-foreground-colour")));
   // second, set colours on the code!
   java.util.List<Lexer.Token> tokens = Lexer.tokenise(textView.getText(), true);
   int pos = 0;
   for (Lexer.Token t : tokens) {
     int len = t.toString().length();
     if (t instanceof Lexer.RightBrace || t instanceof Lexer.LeftBrace) {
       highlightArea(pos, len, foregroundColour("text-brace-colour"));
     } else if (t instanceof Lexer.Strung) {
       highlightArea(pos, len, foregroundColour("text-string-colour"));
     } else if (t instanceof Lexer.Comment) {
       highlightArea(pos, len, foregroundColour("text-comment-colour"));
     } else if (t instanceof Lexer.Quote) {
       highlightArea(pos, len, foregroundColour("text-quote-colour"));
     } else if (t instanceof Lexer.Comma) {
       highlightArea(pos, len, foregroundColour("text-comma-colour"));
     } else if (t instanceof Lexer.Identifier) {
       highlightArea(pos, len, foregroundColour("text-identifier-colour"));
     } else if (t instanceof Lexer.Integer) {
       highlightArea(pos, len, foregroundColour("text-integer-colour"));
     }
     pos += len;
   }
 }
Пример #11
0
 /** Quits the application. */
 private void quit() {
   String usr = user.getText().trim();
   String server = serverText.getText();
   if (usr == null) usr = "";
   if (server == null) server = "";
   firePropertyChange(QUIT_PROPERTY, Boolean.valueOf(false), Boolean.valueOf(true));
 }
Пример #12
0
  private void save() {
    // The name of the file to open.
    String fileName = project.getPath() + File.separator + jClass.fileName;

    try {
      // Assume default encoding.
      FileWriter fileWriter = new FileWriter(fileName);

      // Always wrap FileWriter in BufferedWriter.
      BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);

      // Note that write() does not automatically
      // append a newline character.
      bufferedWriter.write(editPane.getText());

      // Always close files.
      bufferedWriter.close();
      System.out.println("Saved!");
    } catch (IOException ex) {
      System.out.println("Error writing to file '" + fileName + "'");
      // Or we could just do this:
      // ex.printStackTrace();
    }
    if (RedJ.compiledClasses.contains(jClass.getName())) {
      RedJ.compiledClasses.remove(jClass.getName());
    }
  }
Пример #13
0
  public void printInputMsg(String name) {
    textPane.setEditable(true);
    if (lastEnd >= 0) {
      textPane.setSelectionStart(lastEnd);
      lastEnd = -1;
    } else textPane.setSelectionStart(textPane.getText().length());
    lastEnd = textPane.getSelectionStart();
    textPane.setSelectionEnd(textPane.getText().length());
    textPane.replaceSelection("");

    textPane.setSelectionStart(textPane.getText().length());
    textPane.setSelectionEnd(textPane.getText().length());
    textPane.setCharacterAttributes(textPane.getStyle("SystemMessage"), true);
    textPane.replaceSelection(name + "\u6b63\u5728\u8f38\u5165\u8a0a\u606f..");
    textPane.setEditable(false);
  }
Пример #14
0
  private void saveNotes() {
    String note = textPane.getText();

    // Check for empty note.
    if (!ModelUtil.hasLength(note)) {
      return;
    }

    // Save note.
    AgentSession agentSession = FastpathPlugin.getAgentSession();
    try {
      agentSession.setNote(sessionID, note);
      saveButton.setEnabled(false);
      statusLabel.setText(" " + FpRes.getString("message.notes.updated"));
      SwingWorker worker =
          new SwingWorker() {
            public Object construct() {
              try {
                Thread.sleep(3000);
              } catch (InterruptedException e1) {
                Log.error(e1);
              }
              return true;
            }

            public void finished() {
              statusLabel.setText("");
            }
          };
      worker.start();
    } catch (XMPPException e1) {
      showError(FpRes.getString("message.unable.to.update.notes"));
      Log.error("Could not commit note.", e1);
    }
  }
Пример #15
0
  public static List<Integer> getBracketGroups(JTextPane tp) {
    int groupNumber = 0;
    List<Integer> groupsTmp = new ArrayList<Integer>();
    List<Integer[]> groupsPos = new ArrayList<Integer[]>();
    List<Integer> output = new ArrayList<Integer>();

    int caretPos = tp.getCaretPosition();

    try {

      for (int i = 0; i < tp.getText().length(); i++) {
        char tempChar = tp.getText().charAt(i);
        if (tempChar == "(".charAt(0)) { // if open
          groupsTmp.add(groupNumber);
          Integer[] tmpPos = new Integer[2];
          tmpPos[0] = Integer.valueOf(i);
          groupsPos.add(tmpPos);
          groupNumber++;
        }
        if (tempChar == ")".charAt(0)) { // if close
          int tmpGroupNumber = groupsTmp.get(groupsTmp.size() - 1);
          Integer[] tmpPos = groupsPos.get(tmpGroupNumber);
          tmpPos[1] = Integer.valueOf(i);
          groupsPos.set(tmpGroupNumber, tmpPos);
          groupsTmp.remove(groupsTmp.size() - 1);
        }
      }

      groupsTmp = null;
      groupNumber = 0;

      for (Integer[] tmpPos : groupsPos) {
        if (caretPos >= tmpPos[0] && caretPos <= tmpPos[1]) {
          output.clear();
          output.add(0, tmpPos[0]);
          output.add(1, tmpPos[1]);
        }
      }

      return output;
    } catch (NullPointerException e) {
      return null;
    } catch (ArrayIndexOutOfBoundsException e) {
      return null;
    }
  }
Пример #16
0
  private void _setTagForSelectedText(String tagElement) {
    try {

      System.out.println(mTextEditor.getText());
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Пример #17
0
  private void display_(String s) {
    String text = textDetails.getText();
    if (text.length() > 0) text += "\n";

    text += s;
    textDetails.setText(text);
    panelMessage.setVisible(true);
  }
Пример #18
0
 /** Brings up the server dialog to select an existing server or enter a new server address. */
 private void config() {
   ServerDialog d;
   String s = serverText.getText().trim();
   if (connectionSpeed) d = new ServerDialog(this, editor, s, speedIndex);
   else d = new ServerDialog(this, editor, s);
   if (editor.getRowCount() == 0 && configureServerName != null)
     editor.addRow(configureServerName);
   d.addPropertyChangeListener(this);
   UIUtilities.centerAndShow(d);
 }
 private void updatePage() {
   isUpdating = true;
   // HTMLDocument htmlDocument = (HTMLDocument) evt.getNewValue();
   String text = editorPane.getText();
   text = text.replaceAll("@time_of_day", getTimeOfDay());
   text = text.replaceAll("@username", getUsername());
   editorPane.setText(text);
   editorPane.setVisible(true);
   isUpdating = false;
 }
Пример #20
0
  public TextFilterWorker(
      File file,
      JProgressBar progress,
      JTextPane _textForOpen,
      JTextPane _textForClose,
      JButton _okButton,
      File outputFile) {
    _videoFile = file;
    _bar = progress;
    _openTextFont = _textForOpen.getFont();
    _openTextColour = _textForOpen.getForeground();
    _openText = _textForOpen.getText();

    _closeTextFont = _textForClose.getFont();
    _closeTextColour = _textForClose.getForeground();
    _closeText = _textForClose.getText();
    _button = _okButton;
    _outputFile = outputFile;
  }
Пример #21
0
  /*
   * (non-Javadoc)
   *
   * @see
   * java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
   */
  public void actionPerformed(ActionEvent e) {
    if ("Set".equals(e.getActionCommand())) {
      EditDialog.value = (String) (jTextPane.getText());
    }

    if ("Cancel".equals(e.getActionCommand())) {
      EditDialog.value = initialValue;
    }

    EditDialog.dialog.setVisible(false);
  }
Пример #22
0
    /** Write the panel values to the given PlayerMetadata object. */
    public void write(PlayerMetadata pmd) {
      pmd.setName(name.getText());
      pmd.setURI(convertURI(uri.getText()));
      pmd.setNotes(notes.getText());

      String[] tmpEmail = new String[email.length];
      for (int i = 0; i < email.length; i++) {
        tmpEmail[i] = email[i].getText().trim();
      }

      pmd.setEmailAddresses(tmpEmail);
    } // write()
Пример #23
0
 /** Saves event into the list. */
 public synchronized void save() {
   myEvent.setNEID(myNE.getId());
   myEvent.setEnabled(true);
   myEvent.setDescription(desc.getText());
   int h = (Integer) hh.getValue();
   int m = (Integer) mm.getValue();
   double s = (Double) ss.getValue();
   myEvent.setTime(h + (m / 60.0) + (s / 3600.0));
   myEventManager.clearEvent(myEvent);
   myEventManager.addEvent(myEvent);
   if (eventTable != null) eventTable.updateData();
   return;
 }
Пример #24
0
 public void saveFile() {
   if (file == null) {
     // first save file, so prompt for name.
     saveFileAs();
   } else {
     // file already named so just write it.
     physWriteTextFile(file, textView.getText());
     // update status
     statusView.setText(" Saved file \"" + file.getName() + "\".");
     // reset dirty bit
     dirty = false;
   }
 }
Пример #25
0
    /** Set GameMetadata object from the entered panel values. */
    public void write(GameMetadata gmd) {
      gmd.setNotes(notes.getText());
      gmd.setComment(comment.getText());
      gmd.setGameName(gameName.getText());
      gmd.setGameID(gameID.getText());
      gmd.setGameURI(convertURI(gameURI.getText()));

      gmd.setJudgeName((judgeName.getText().length() == 0) ? null : judgeName.getText());

      gmd.setModeratorName((modName.getText().length() == 0) ? null : modName.getText());
      gmd.setModeratorEmail((modEmail.getText().length() == 0) ? null : modEmail.getText());
      gmd.setModeratorURI(convertURI(modURI.getText()));
    } // write()
Пример #26
0
 private void addLineBreaksToHexDump(byte[] id, byte[] data) {
   // add linefeeds to the dump
   int lnCount = _hexDumpArea.getText().length() / 48;
   int rest = _hexDumpArea.getText().length() % 48;
   for (int i = 1; i <= lnCount; i++) {
     int pos = i * 67 - 20;
     try {
       int idx = i - 1;
       String ansci =
           idx == 0
               ? (Util.toAnsci(id, 0, id.length) + Util.toAnsci(data, 0, 16 - id.length))
               : Util.toAnsci(data, idx * 16 - id.length, idx * 16 + 16 - id.length);
       _hexStyledDoc.replace(pos, 1, "   " + ansci + "\n", _hexStyledDoc.getStyle("base"));
       // _hexStyledDoc.remove(pos,1);
       // _hexStyledDoc.insertString(pos, "\n", _hexStyledDoc.getStyle("base"));
     } catch (BadLocationException e1) {
       // TODO Auto-generated catch block
       e1.printStackTrace();
     }
   }
   // rest
   if (rest != 0) {
     try {
       int pos = lnCount * 67 + rest;
       String space = "";
       int spaceCount = 48 - rest;
       while (spaceCount-- > 0) space += " ";
       String ansci =
           lnCount == 0
               ? (Util.toAnsci(id, 0, id.length) + Util.toAnsci(data, 0, data.length - id.length))
               : Util.toAnsci(data, lnCount * 16 - id.length, data.length - id.length);
       _hexStyledDoc.insertString(pos, space + "  " + ansci, _hexStyledDoc.getStyle("base"));
     } catch (BadLocationException e1) {
       // TODO Auto-generated catch block
       e1.printStackTrace();
     }
   }
 }
Пример #27
0
 private static boolean checkPane(final JTextPane pane) {
   final int startIdx = pane.getSelectionStart();
   final int endIdx = pane.getSelectionEnd();
   if (endIdx > 0) {
     comment(pane, startIdx, endIdx);
   } else {
     final String text = pane.getText();
     if (text.length() == 0) {
       return false;
     }
     comment(pane, startIdx, endIdx);
   }
   return true;
 }
Пример #28
0
 public void saveFileAs() {
   // Force user to enter new file name
   if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
     file = fileChooser.getSelectedFile();
   } else {
     // user cancelled save after all
     return;
   }
   // file selected, so write it.
   physWriteTextFile(file, textView.getText());
   // update status
   statusView.setText(" Saved file \"" + file.getName() + "\".");
   // reset dirty bit
   dirty = false;
 }
  /** @param formatter */
  protected void setFormatterFromTextPane(final DataObjSwitchFormatter formatter) {
    // visit every character in the document text looking for fields
    // store characters not associated with components (jbutton) to make up the separator text
    DefaultStyledDocument doc = (DefaultStyledDocument) formatEditor.getStyledDocument();
    String text = formatEditor.getText();
    int docLen = doc.getLength();
    int lastFieldPos = 0;

    Vector<DataObjDataField> fields = new Vector<DataObjDataField>();
    // int cnt = 0;
    for (int i = 0; i < docLen; ++i) {
      Element element = doc.getCharacterElement(i);
      AttributeSet attrs = element.getAttributes();
      Object obj = attrs.getAttribute(StyleConstants.ComponentAttribute);
      // System.out.print(String.format("i: %d, lastFieldPos: %d cnt: %d, F: %s", i, lastFieldPos,
      // cnt, (obj instanceof FieldDefinitionComp ? "Y" : "N")));
      if (obj instanceof FieldDefinitionComp) {
        // System.out.println(cnt+"  "+(obj instanceof FieldDefinitionComp));
        // found button at the current position
        // create corresponding field
        String sepStr = (lastFieldPos <= i - 1) ? text.substring(lastFieldPos, i) : "";

        FieldDefinitionComp fieldDefBtn = (FieldDefinitionComp) obj;
        DataObjDataField fmtField = fieldDefBtn.getValue();
        fmtField.setSep(sepStr);
        fields.add(fmtField);

        // System.out.print(" Sep: ["+sepStr+"]");

        lastFieldPos = i + 1;
        // cnt++;
      }
    }

    // XXX: what do we do with the remaining of the text? right now we ignore it
    // That's because we can't create an empty formatter field just to use the separator...

    DataObjDataField[] fieldsArray = new DataObjDataField[fields.size()];
    for (int i = 0; i < fields.size(); ++i) {
      fieldsArray[i] = fields.elementAt(i);
    }

    DataObjDataFieldFormat singleFormatter =
        fieldsArray.length == 0
            ? null
            : new DataObjDataFieldFormat("", tableInfo.getClassObj(), false, "", "", fieldsArray);
    formatter.setSingle(singleFormatter);
  }
Пример #30
0
 public void prettyPrint() {
   try {
     // clear old problem messages
     problemsView.setText("");
     // update status view
     statusView.setText(" Parsing ...");
     LispExpr root = Parser.parse(textView.getText());
     statusView.setText(" Pretty Printing ...");
     String newText = PrettyPrinter.prettyPrint(root);
     textView.setText(newText);
     statusView.setText(" Done.");
   } catch (Error e) {
     System.err.println(e.getMessage());
     statusView.setText(" Errors.");
   }
 }