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(); }
@Override public void actionPerformed(ActionEvent e) { ID = (Integer) hashRoomType.get(boxRoomTypeID.getSelectedItem().toString()); IDSTATUS = (Integer) hashRoomStatus.get(boxRoomStatusID.getSelectedItem().toString()); if (e.getSource() == buttonInsert) { try { Rooms rooms = new Rooms(txtRoomNumber.getText(), txtDescription.getText(), ID, IDSTATUS); RoomsController.roomsController.save(rooms); int c = model.getRowCount(); for (int i = c - 1; i >= 0; i--) { model.removeRow(i); jRoom.revalidate(); } all(); JOptionPane.showMessageDialog(this, "ok"); } catch (Exception ex) { ex.printStackTrace(); } } if (e.getSource() == buttonUpdate) { try { Rooms rooms = new Rooms(txtRoomNumber.getText(), txtDescription.getText(), ID, IDSTATUS); rooms.setRoomID(IDROOM); RoomsController.roomsController.update(rooms); int c = model.getRowCount(); for (int i = c - 1; i >= 0; i--) { model.removeRow(i); jRoom.revalidate(); } all(); JOptionPane.showMessageDialog(this, "Update to succeed !"); } catch (Exception ex) { ex.printStackTrace(); } } if (e.getSource() == buttonDelete) { try { List<CheckIn> temp = CheckInController.checkInController.all(); for (int i = 0; i < temp.size(); i++) { if (IDROOM == temp.get(i).getRoomID()) { this.error = 0; } else { this.error = 0; RoomsController.roomsController.delete(IDROOM); int c = model.getRowCount(); for (int ii = c - 1; ii >= 0; ii--) { model.removeRow(ii); jRoom.revalidate(); } all(); } } JOptionPane.showMessageDialog(this, "Delete to succeed !"); } catch (Exception ex) { JOptionPane.showMessageDialog(this, "can't delete row bcause check still !"); } } if (e.getSource() == buttonRefresh) {} }
/** 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(); } }
public void inventory() { txtTranscript.insert("You are carrying:\n", txtTranscript.getText().length()); for (String item : inventory) { txtTranscript.insert(item + "\n", txtTranscript.getText().length()); } if (inventory.isEmpty()) { txtTranscript.insert("No items.\n", txtTranscript.getText().length()); } }
public void autoinventory() { inv.setText(""); inv.insert("You are carrying:\n", inv.getText().length()); for (String item : inventory) { inv.insert(item + "\n", inv.getText().length()); } if (inventory.isEmpty()) { inv.insert("No items.\n", inv.getText().length()); } }
private void copyTo() { config.setName(nameText.getText().trim()); config.setTitle(Strings.emptyToNull(titleText.getText().trim())); config.setGameVersion(gameVersionText.getText().trim()); LaunchModifier launchModifier = config.getLaunchModifier(); FnPatternList userFiles = config.getUserFiles(); launchModifier.setFlags(SwingHelper.linesToList(launchFlagsArea.getText())); userFiles.setInclude(SwingHelper.linesToList(userFilesIncludeArea.getText())); userFiles.setExclude(SwingHelper.linesToList(userFilesExcludeArea.getText())); }
public void take(String takable) { String takeItem = null; int[] mapKey = null; int[] pair = {row, col}; for (int[] key : myMap.items.keySet()) { if (Arrays.equals(pair, key)) { mapKey = key; } } if (mapKey != null) { ArrayList<String> loot = myMap.items.get(mapKey); for (String item : loot) { if (item.toUpperCase().equals(takable.toUpperCase())) { takeItem = item; } } if (takeItem != null) { inventory.add(takeItem); loot.remove(takeItem); txtTranscript.insert( "You picked up a " + takeItem + "\n", txtTranscript.getText().length()); if (takeItem.equals("BLASTER")) { txtTranscript.insert( "You roll your eyes\nSo uncivilized...\n", txtTranscript.getText().length()); } else if (takeItem.toUpperCase().equals("LIGHT SABER")) { txtTranscript.insert( "Now we're talking!\nA key weapon in defeating Vader.\n", txtTranscript.getText().length()); } else if (takeItem.toUpperCase().equals("BAG OF YODA SNACKS")) { txtTranscript.insert( "You roll your eyes\nSo uncivilized..\n", txtTranscript.getText().length()); } else if (takeItem.equals("HAIR BRUSH")) { txtTranscript.insert( "Perhaps these will help convince Yoda to train you.\n", txtTranscript.getText().length()); } else if (takeItem.equals("STORM TROOPER HELMET")) { txtTranscript.insert( "A disguise to sneek up on Vader?\n", txtTranscript.getText().length()); } else if (takeItem.equals("GLOWING HULK MASK")) { txtTranscript.insert( "Maybe you could scare Vader to death?\n", txtTranscript.getText().length()); } else if (takeItem.equals("MIDICHLORIANS")) { txtTranscript.insert( "You feel the power of the force surging through you.\n", txtTranscript.getText().length()); } } } if (mapKey == null || takeItem == null) { txtTranscript.insert( "You can't find \"" + takable + "\" to pick up.\n", txtTranscript.getText().length()); } autoinventory(); }
public void actionPerformed(ActionEvent e) { if (e.getSource() == b1) { System.out.println("You Clicked Click me"); System.out.println("And the textarea has: " + text.getText()); x = x + 10; y = y + 10; canvas.update(canvas.getGraphics()); } else if (e.getSource() == labeler) { label.setText(text.getText()); // pane.add(new JLabel(text.getText())); text.setText(""); } else if (e.getSource() == b2) { System.out.println("Shutting down"); System.exit(0); } }
/** * Will select the Mars Messages tab error message that matches the given specifications, if it is * found. Matching is done by constructing a string using the parameter values and searching the * text area for the last occurrance of that string. * * @param fileName A String containing the file path name. * @param line Line number for error message * @param column Column number for error message */ public void selectErrorMessage(String fileName, int line, int column) { String errorReportSubstring = new java.io.File(fileName).getName() + ErrorList.LINE_PREFIX + line + ErrorList.POSITION_PREFIX + column; int textPosition = assemble.getText().lastIndexOf(errorReportSubstring); if (textPosition >= 0) { int textLine = 0; int lineStart = 0; int lineEnd = 0; try { textLine = assemble.getLineOfOffset(textPosition); lineStart = assemble.getLineStartOffset(textLine); lineEnd = assemble.getLineEndOffset(textLine); assemble.setSelectionColor(Color.YELLOW); assemble.select(lineStart, lineEnd); assemble.getCaret().setSelectionVisible(true); assemble.repaint(); } catch (BadLocationException ble) { // If there is a problem, simply skip the selection } } }
public boolean isModified() { boolean isModified = false; HttpConfigurable httpConfigurable = myHttpConfigurable; if (!Comparing.equal(myProxyExceptions.getText().trim(), httpConfigurable.PROXY_EXCEPTIONS)) return true; isModified |= httpConfigurable.USE_PROXY_PAC != myAutoDetectProxyRb.isSelected(); isModified |= httpConfigurable.USE_PAC_URL != myPacUrlCheckBox.isSelected(); isModified |= !Comparing.strEqual(httpConfigurable.PAC_URL, myPacUrlTextField.getText()); isModified |= httpConfigurable.USE_HTTP_PROXY != myUseHTTPProxyRb.isSelected(); isModified |= httpConfigurable.PROXY_AUTHENTICATION != myProxyAuthCheckBox.isSelected(); isModified |= httpConfigurable.KEEP_PROXY_PASSWORD != myRememberProxyPasswordCheckBox.isSelected(); isModified |= httpConfigurable.PROXY_TYPE_IS_SOCKS != mySocks.isSelected(); isModified |= !Comparing.strEqual(httpConfigurable.PROXY_LOGIN, myProxyLoginTextField.getText()); isModified |= !Comparing.strEqual( httpConfigurable.getPlainProxyPassword(), new String(myProxyPasswordTextField.getPassword())); try { isModified |= httpConfigurable.PROXY_PORT != Integer.valueOf(myProxyPortTextField.getText()).intValue(); } catch (NumberFormatException e) { isModified = true; } isModified |= !Comparing.strEqual(httpConfigurable.PROXY_HOST, myProxyHostTextField.getText()); return isModified; }
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) { } } } }
public void mouseMoved(MouseEvent e) { int k = html.viewToModel(e.getPoint()); if (html.hasFocus() && html.getSelectionStart() <= k && k < html.getSelectionEnd()) { setMessage("(on selection)", MOVE); return; } String s = text.getText(); // ""; int m = s.length(); // html.getDocument().getLength(); /*try { s = html.getText(0, m); } catch (BadLocationException x) { setMessage("BadLocation "+m, TEXT); return; } */ if (!Character.isLetter(s.charAt(k))) { setMessage("(not a letter)", TEXT); return; } selB = k; selE = k + 1; while (!Character.isWhitespace(s.charAt(selB - 1))) selB--; while (!Character.isWhitespace(s.charAt(selE))) selE++; setMessage(selB + "-" + selE, HAND); word = ""; for (int i = selB; i < selE; i++) if (Character.isLetter(s.charAt(i))) word += s.charAt(i); html.setToolTipText(word); }
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(); } } }
@Override public void actionPerformed(ActionEvent e) { String text = textArea.getText(); textArea.append("\n\nbutton clicked"); JOptionPane.showMessageDialog(null, "Your message is: " + text); System.out.println(text); }
// for update a record private void update() { boolean status = true; if (rack == null) { status = false; new ValidationMSG( this, "Please Select A Row from Table Then Click on View to Update Rack Details"); } else if (valid.isEmpty(textField1.getText())) { status = false; new ValidationMSG(this, "Please Insert Rack Name"); } if (status) { rack.setRackName(textField1.getText()); if (!valid.isEmpty(textArea1.getText())) rack.setRackDesc(textArea1.getText()); dbupdate.updateRack(rack); reset(); loadTableData(); rack = null; } }
/** * 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; }
public void go(String[] userInput) { if (userInput.length == 0) { txtTranscript.insert("You did not specify a direction.\n", txtTranscript.getText().length()); } else { char direction = Character.toLowerCase(userInput[0].charAt(0)); if (direction == 'n') { if (row > MINROW) { txtTranscript.insert("Moving north . . .\n", txtTranscript.getText().length()); row--; } else { txtTranscript.insert("North is out of bounds..\n", txtTranscript.getText().length()); } } else if (direction == 'e') { if (col < MAXCOL) { txtTranscript.insert("Moving east . . .\n", txtTranscript.getText().length()); col++; } else { txtTranscript.insert("East is out of bounds..\n", txtTranscript.getText().length()); } } else if (direction == 's') { if (row < MAXROW) { txtTranscript.insert("Moving south . . .\n", txtTranscript.getText().length()); row++; } else { txtTranscript.insert("South is out of bounds..\n", txtTranscript.getText().length()); } } else if (direction == 'w') { if (col > MINCOL) { txtTranscript.insert("Moving west . . .\n", txtTranscript.getText().length()); col--; } else { txtTranscript.insert("West is out of bounds.\n", txtTranscript.getText().length()); } } else { txtTranscript.insert( "Which direction did you want to go?\n", txtTranscript.getText().length()); } printLocation(); } }
public void drop(String dropped) { int[] pair = {row, col}; String takeItem = null; for (String item : inventory) { if (item.equals(dropped)) { takeItem = item; } } if (takeItem != null) { inventory.remove(takeItem); myMap.addItems(pair, takeItem); txtTranscript.insert( "You dropped a \"" + takeItem + "\".\n", txtTranscript.getText().length()); } else { txtTranscript.insert( "You aren't carrying a \"" + dropped + "\" to drop.\n", txtTranscript.getText().length()); } autoinventory(); }
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; }
// counts lines public static int countLines(JTextArea textArea) { AttributedString text = new AttributedString(textArea.getText()); FontRenderContext frc = textArea.getFontMetrics(textArea.getFont()).getFontRenderContext(); int lines = 0; if (!textArea.getText().equals("")) { AttributedCharacterIterator charIt = text.getIterator(); LineBreakMeasurer lineMeasurer = new LineBreakMeasurer(charIt, frc); float formatWidth = (float) textArea.getSize().width; lineMeasurer.setPosition(charIt.getBeginIndex()); while (lineMeasurer.getPosition() < charIt.getEndIndex()) { lineMeasurer.nextLayout(formatWidth); lines++; } for (int i = 0; i < textArea.getText().length(); i++) { if (textArea.getText().charAt(i) == '\r' || textArea.getText().charAt(i) == '\n') lines++; } } else { lines = 1; } return lines; }
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); } }
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"); } }
public void mouseClicked(MouseEvent e) { if (e.getClickCount() != 1) return; // String s = html.getToolTipText(); if (word == null) return; setMessage(word); String s = text.getText(); String h = s.substring(0, selB) + " <FONT color=blue> " + s.substring(selB, selE) + " </FONT> " + s.substring(selE); setHTML(h); }
// used to save a new record private void save() { // check validation for empty field boolean status = true; if (valid.isEmpty(textField1.getText())) { status = false; new ValidationMSG(this, "Please Insert Rack Name"); } // /insert rack when all inputs are valid if (status) { RackModel rack = new RackModel(); rack.setRackId(0); rack.setRackName(textField1.getText()); if (!valid.isEmpty(textArea1.getText())) rack.setRackDesc(textArea1.getText()); rack.setFirmId(1); rack.setStoreId(tableid.getStoreId(comboBox1.getSelectedItem().toString())); dbinsert.insertRack(rack); rack.setDefault(); loadTableData(); reset(); } }
private boolean sendMail() { if (mailToField.getText().trim().length() == 0) { JOptionPane.showMessageDialog( this, strings.getString("error_emptytofield"), "", JOptionPane.ERROR_MESSAGE); return (false); } if (!checkMailAddress(mailToField.getText())) { JOptionPane.showMessageDialog( this, strings.getString("error_invalidtofield"), "", JOptionPane.ERROR_MESSAGE); return (false); } if (mailFromField.getText().trim().length() == 0) { JOptionPane.showMessageDialog( this, strings.getString("error_emptyfromfield"), "", JOptionPane.ERROR_MESSAGE); return (false); } if (!checkMailAddress(mailFromField.getText())) { JOptionPane.showMessageDialog( this, strings.getString("error_invalidfromfield"), "", JOptionPane.ERROR_MESSAGE); return (false); } String mailText = mailBodyArea.getText(); boolean value; try { value = LoginContext.server.sendmail( mailFromField.getText(), mailToField.getText(), mailSubjectField.getText(), mailText, LoginContext.sessionKey); } catch (RemoteException ex) { JOptionPane.showMessageDialog( this, strings.getString("error_sendingfailed"), "Error", JOptionPane.ERROR_MESSAGE); log.error("Could not send email beacuse of a server-side error", ex); return false; } if (!value) { JOptionPane.showMessageDialog( this, strings.getString("error_sendingfailed"), "Error", JOptionPane.ERROR_MESSAGE); log.error("Could not send email beacuse of a server-side error"); return false; } return true; }
public static void showResult(JTextArea txt, String result) { try { if (txt.getText().length() == 0) { txt.setText(result); txt.setSelectionStart(txt.getText().length()); txt.setSelectionEnd(txt.getText().length() - 1); } else { if (txt.getText().length() > MAX_LOG_SIZE) txt.getDocument().remove(0, txt.getText().length() - MAX_LOG_SIZE); txt.setSelectionStart(txt.getText().length()); txt.getDocument().insertString(txt.getText().length(), result, null); txt.setSelectionEnd(txt.getText().length()); } } catch (Exception e) { e.printStackTrace(); } }
public void printLocation() { txtTranscript.insert( "You are at location " + row + "," + col + " in terrain: " + myMap.terrainTypes.get(Character.toString(myMap.terrain(row, col))) + "\n", txtTranscript.getText().length()); if (myMap.terrain(row, col) == '*') { Dragon found = new Dragon(); found.Dragon(); } }
/** * 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); } }
@Override public void actionPerformed(ActionEvent e) { String prefix = ""; String userName = settingsPane.returnSetting("IRC_nick"); String input = "<b><font color=blue>[" + userName + "]:</font></b> " + chatInput.getText(); if (e.getSource() == g_start) { substarterBegin(prefix, userName, input); } if (e.getSource() == g_end) { substarterEnd(prefix, userName, input); } if (e.getSource() == sendButton) { if (!chatInput.getText().equals("")) { // toChatScreen(input); // chatScreen.append(input + "\n"); if (chatInput.getText().startsWith("/")) { if (chatInput.getText().equals("/substart")) { substarterBegin(prefix, userName, input); } if (chatInput.getText().equals("/substartend")) { substarterEnd(prefix, userName, input); } } else { sock.outputToChannel(chatInput.getText(), channelName); try { // chatter.printScreen(); toChatScreen(prefix + input, false); } catch (IOException | BadLocationException ex) { Logger.getLogger(IRCBOT.class.getName()).log(Level.SEVERE, null, ex); } } chatInput.setText(""); // chatter.addTo(input); } else { chatInput.setText(""); } chatInput.requestFocus(); } if (e.getSource() == settings) { // makeNewWindow("Window " + frameCounter, JFrame.DISPOSE_ON_CLOSE, 800, 500, 2); settingsPane.showPane(); } }
private void updateViewerForSelection() { if (myAllContents.isEmpty()) return; String fullString = getSelectedText(); if (myViewer != null) { EditorFactory.getInstance().releaseEditor(myViewer); } if (myUseIdeaEditor) { myViewer = createIdeaEditor(fullString); JComponent component = myViewer.getComponent(); component.setPreferredSize(JBUI.size(300, 500)); mySplitter.setSecondComponent(component); } else { final JTextArea textArea = new JTextArea(fullString); textArea.setRows(3); textArea.setWrapStyleWord(true); textArea.setLineWrap(true); textArea.setSelectionStart(0); textArea.setSelectionEnd(textArea.getText().length()); textArea.setEditable(false); mySplitter.setSecondComponent(ScrollPaneFactory.createScrollPane(textArea)); } mySplitter.revalidate(); }