/** * Create a Transferable to use as the source for a data transfer. * * @param c The component holding the data to be transfered. This argument is provided to enable * sharing of TransferHandlers by multiple components. * @return The representation of the data to be transfered. */ protected Transferable createTransferable(JComponent c) { Object[] values = null; if (c instanceof JList) { values = ((JList) c).getSelectedValues(); } else if (c instanceof JTable) { JTable table = (JTable) c; int[] rows = table.getSelectedRows(); if (rows != null) { values = new Object[rows.length]; for (int i = 0; i < rows.length; i++) { values[i] = table.getValueAt(rows[i], 0); } } } if (values == null || values.length == 0) { return null; } StringBuffer plainBuf = new StringBuffer(); StringBuffer htmlBuf = new StringBuffer(); htmlBuf.append("<html>\n<body>\n<ul>\n"); for (Object obj : values) { String val = ((obj == null) ? "" : obj.toString()); plainBuf.append(val + "\n"); htmlBuf.append(" <li>" + val + "\n"); } // remove the last newline plainBuf.deleteCharAt(plainBuf.length() - 1); htmlBuf.append("</ul>\n</body>\n</html>"); return new FileTransferable(plainBuf.toString(), htmlBuf.toString(), values); }
protected void setToolTip() { TileI currentTile = orUIManager.getGameUIManager().getGameManager().getTileManager().getTile(internalId); StringBuffer tt = new StringBuffer("<html>"); tt.append("<b>Tile</b>: ").append(currentTile.getName()); // or // getId() if (currentTile.hasStations()) { // for (Station st : currentTile.getStations()) int cityNumber = 0; // TileI has stations, but for (Station st : currentTile.getStations()) { cityNumber++; // = city.getNumber(); tt.append("<br> ") .append(st.getType()) .append(" ") .append(cityNumber) // .append("/").append(st.getNumber()) .append(": value "); tt.append(st.getValue()); if (st.getBaseSlots() > 0) { tt.append(", ").append(st.getBaseSlots()).append(" slots"); } } } tt.append("</html>"); toolTip = tt.toString(); }
/** * Get the Lincese text from a text file specified in the PropertyBox. * * @return String - License text. */ public String getLicenseText() { StringBuffer textBuffer = new StringBuffer(); try { String fileName = RuntimeProperties.GPL_EN_LICENSE_FILE_NAME; if (cbLang != null && cbLang.getSelectedItem() != null && cbLang.getSelectedItem().toString().equalsIgnoreCase("Eesti")) { fileName = RuntimeProperties.GPL_EE_LICENSE_FILE_NAME; } InputStream is = this.getClass().getClassLoader().getResourceAsStream(fileName); if (is == null) return ""; BufferedReader in = new BufferedReader(new InputStreamReader(is)); String str; while ((str = in.readLine()) != null) { textBuffer.append(str); textBuffer.append("\n"); } in.close(); } catch (IOException e) { logger.error(null, e); } return textBuffer.toString(); } // getLicenseText
void applyDirectives() { findRemoveDirectives(true); StringBuffer buffer = new StringBuffer(); String head = "", toe = "; \n"; if (crispBox.isSelected()) buffer.append(head + "crisp=true" + toe); if (!fontField.getText().trim().equals("")) buffer.append(head + "font=\"" + fontField.getText().trim() + "\"" + toe); if (globalKeyEventsBox.isSelected()) buffer.append(head + "globalKeyEvents=true" + toe); if (pauseOnBlurBox.isSelected()) buffer.append(head + "pauseOnBlur=true" + toe); if (!preloadField.getText().trim().equals("")) buffer.append(head + "preload=\"" + preloadField.getText().trim() + "\"" + toe); /*if ( transparentBox.isSelected() ) buffer.append( head + "transparent=true" + toe );*/ Sketch sketch = editor.getSketch(); SketchCode code = sketch.getCode(0); // first tab if (buffer.length() > 0) { code.setProgram("/* @pjs " + buffer.toString() + " */\n\n" + code.getProgram()); if (sketch.getCurrentCode() == code) // update textarea if on first tab { editor.setText(sketch.getCurrentCode().getProgram()); editor.setSelection(0, 0); } sketch.setModified(false); sketch.setModified(true); } }
protected String getFeatureText() { String txt = ""; try { txt = ((HTMLDocument) getDocument()).getText(0, getDocument().getLength()).trim(); StringBuffer buff = new StringBuffer(); StringTokenizer tok = new StringTokenizer(txt, "/"); int ntok = 0; while (tok.hasMoreTokens()) { String tokTxt = "/" + tok.nextToken().trim(); int ind = tokTxt.indexOf("="); if (ntok != 0 && ind > -1 && qualifier.contains(tokTxt.substring(0, ind + 1))) buff.append("\n" + tokTxt); else buff.append(tokTxt); ntok++; } txt = buff.toString(); } catch (BadLocationException ble) { ble.printStackTrace(); } return txt; }
/** Add import statements to the current tab for all of packages inside the specified jar file. */ public void handleImportLibrary(String jarPath) { // make sure the user didn't hide the sketch folder sketch.ensureExistence(); // import statements into the main sketch file (code[0]) // if the current code is a .java file, insert into current // if (current.flavor == PDE) { if (mode.isDefaultExtension(sketch.getCurrentCode())) { sketch.setCurrentCode(0); } // could also scan the text in the file to see if each import // statement is already in there, but if the user has the import // commented out, then this will be a problem. String[] list = Base.packageListFromClassPath(jarPath); StringBuffer buffer = new StringBuffer(); for (int i = 0; i < list.length; i++) { buffer.append("import "); buffer.append(list[i]); buffer.append(".*;\n"); } buffer.append('\n'); buffer.append(getText()); setText(buffer.toString()); setSelection(0, 0); // scroll to start sketch.setModified(true); }
public StringBuffer saveStringBuffer() { StringBuffer save = new StringBuffer(); for (java.util.Enumeration<Editor> e = pageList.elements(); e.hasMoreElements(); ) { Editor page = e.nextElement(); save.append( "<" + name + ".Page>\n" + "<Type>" + typeOfPage(page) + "</Type>\n" + "<Name>" + page.getName() + "</Name>\n" + "<Active>" + page.isActive() + "</Active>\n" + "<" + contentDelim + ">\n"); save.append(page.saveStringBuffer()); save.append("</" + contentDelim + ">\n" + "</" + name + ".Page>\n"); } return save; }
/** Capture an image for all ViewManagers */ public void captureAll() { List vms = getViewManagers(); String filename = FileManager.getWriteFile(FileManager.FILTER_IMAGE, FileManager.SUFFIX_JPG); if (filename == null) { return; } String root = IOUtil.stripExtension(filename); String ext = IOUtil.getFileExtension(filename); StringBuffer sb = new StringBuffer("<html>"); sb.append("Since there were multiple images they were written out as:<ul>"); for (int i = 0; i < vms.size(); i++) { ViewManager vm = (ViewManager) vms.get(i); String name = vm.getName(); if ((name == null) || (name.trim().length() == 0)) { name = "" + (i + 1); } if (vms.size() != 1) { filename = root + name + ext; } sb.append("<li> " + filename); vm.writeImage(filename); } sb.append("</ul></html>"); if (vms.size() > 1) { GuiUtils.showDialog("Captured Images", GuiUtils.inset(new JLabel(sb.toString()), 5)); } }
/** * ** Reads a line from the specified socket's input stream ** @param socket The socket to read a * line from ** @param maxLen The maximum length of of the line to read ** @param sb The string * buffer to use ** @throws IOException if an error occurs or the server has stopped */ protected static String socketReadLine(Socket socket, int maxLen, StringBuffer sb) throws IOException { if (socket != null) { int dataLen = 0; StringBuffer data = (sb != null) ? sb : new StringBuffer(); InputStream input = socket.getInputStream(); while ((maxLen < 0) || (maxLen > dataLen)) { int ch = input.read(); // Print.logInfo("ReadLine char: " + ch); if (ch < 0) { // this means that the server has stopped throw new IOException("End of input"); } else if (ch == LineTerminatorChar) { // include line terminator in String data.append((char) ch); dataLen++; break; } else { // append character data.append((char) ch); dataLen++; } } return data.toString(); } else { return null; } }
protected String gettitle(String strFreq) { StringBuffer sbufTitle = new StringBuffer().append("VnmrJ "); String strPath = FileUtil.openPath(FileUtil.SYS_VNMR + "/vnmrrev"); BufferedReader reader = WFileUtil.openReadFile(strPath); String strLine; String strtype = ""; if (reader == null) return sbufTitle.toString(); try { while ((strLine = reader.readLine()) != null) { strtype = strLine; } strtype = strtype.trim(); if (strtype.equals("merc")) strtype = "Mercury"; else if (strtype.equals("mercvx")) strtype = "Mercury-Vx"; else if (strtype.equals("mercplus")) strtype = "MERCURY plus"; else if (strtype.equals("inova")) strtype = "INOVA"; String strHostName = m_strHostname; if (strHostName == null) strHostName = ""; sbufTitle.append(" ").append(strHostName); sbufTitle.append(" ").append(strtype); sbufTitle.append(" - ").append(strFreq); reader.close(); } catch (Exception e) { // e.printStackTrace(); Messages.logError(e.toString()); } return sbufTitle.toString(); }
/** * A utility method to make a name=value part of the adde request string * * @param buf The buffer to append to * @param name The property name * @param value The value */ protected void appendKeyValue(StringBuffer buf, String name, String value) { if ((buf.length() == 0) || (buf.charAt(buf.length() - 1) != '?')) { buf.append("&"); } buf.append(name); buf.append("="); buf.append(value); }
{ StringBuffer sb = new StringBuffer(); StringTokenizer st = new StringTokenizer(cfg.REQPARAM_CONTACT_LIST_LOGIN_IDS, ","); while (st.hasMoreTokens()) { sb.append(st.nextToken()); if (st.hasMoreTokens()) sb.append("\n"); } contactList.setText(sb.toString()); }
private String bigIntToHexString(BigInteger bi) { StringBuffer buf = new StringBuffer(); buf.append("0x"); String val = bi.toString(16); for (int i = 0; i < ((2 * addressSize) - val.length()); i++) { buf.append('0'); } buf.append(val); return buf.toString(); }
/** * ** Returns the bean method name for the specified field ** @param prefix Either "get" or "set" * ** @param fieldName The field name ** @return The 'getter'/'setter' method name */ protected static String _beanMethodName(String prefix, String fieldName) { if ((prefix != null) && (fieldName != null)) { StringBuffer sb = new StringBuffer(prefix); sb.append(fieldName.substring(0, 1).toUpperCase()); sb.append(fieldName.substring(1)); return sb.toString(); } else { return ""; } }
public String getSelectedRobotsAsString() { StringBuffer sb = new StringBuffer(); for (int i = 0; i < selectedRobots.size(); i++) { if (i != 0) { sb.append(','); } sb.append(selectedRobots.get(i).getItem().getUniqueFullClassNameWithVersion()); } return sb.toString(); }
void setTextFromTile(TileI tile) { StringBuffer text = new StringBuffer(); if (Util.hasValue(tile.getExternalId())) { text.append("<HTML><BODY>" + tile.getExternalId()); if (tile.countFreeTiles() != -1) { text.append("<BR> (" + tile.countFreeTiles() + ")"); } text.append("</BODY></HTML>"); } this.setText(text.toString()); }
protected void _save() { jEdit.setBooleanProperty("view.showToolbar", showToolbar.isSelected()); StringBuffer buf = new StringBuffer(); for (int i = 0; i < listModel.getSize(); i++) { if (i != 0) buf.append(' '); Button button = (Button) listModel.elementAt(i); buf.append(button.actionName); jEdit.setProperty(button.actionName + ".icon", button.iconName); } jEdit.setProperty("view.toolbar", buf.toString()); }
/** * This method is activated on the Keystrokes we are listening to in this implementation. Here it * listens for Copy and Paste ActionCommands. Selections comprising non-adjacent cells result in * invalid selection and then copy action cannot be performed. Paste is done by aligning the upper * left corner of the selection with the 1st element in the current selection of the JTable. */ public void actionPerformed(ActionEvent e) { if (e.getActionCommand().compareTo("Copy") == 0) { StringBuffer sbf = new StringBuffer(); // Check to ensure we have selected only a contiguous block of // cells int numcols = jTable1.getSelectedColumnCount(); int numrows = jTable1.getSelectedRowCount(); int[] rowsselected = jTable1.getSelectedRows(); int[] colsselected = jTable1.getSelectedColumns(); if (!((numrows - 1 == rowsselected[rowsselected.length - 1] - rowsselected[0] && numrows == rowsselected.length) && (numcols - 1 == colsselected[colsselected.length - 1] - colsselected[0] && numcols == colsselected.length))) { JOptionPane.showMessageDialog( null, "Invalid Copy Selection", "Invalid Copy Selection", JOptionPane.ERROR_MESSAGE); return; } for (int i = 0; i < numrows; i++) { for (int j = 0; j < numcols; j++) { sbf.append(jTable1.getValueAt(rowsselected[i], colsselected[j])); if (j < numcols - 1) sbf.append("\t"); } sbf.append("\n"); } stsel = new StringSelection(sbf.toString()); system = Toolkit.getDefaultToolkit().getSystemClipboard(); system.setContents(stsel, stsel); } if (e.getActionCommand().compareTo("Paste") == 0) { System.out.println("Trying to Paste"); int startRow = (jTable1.getSelectedRows())[0]; int startCol = (jTable1.getSelectedColumns())[0]; try { String trstring = (String) (system.getContents(this).getTransferData(DataFlavor.stringFlavor)); System.out.println("String is:" + trstring); StringTokenizer st1 = new StringTokenizer(trstring, "\n"); for (int i = 0; st1.hasMoreTokens(); i++) { rowstring = st1.nextToken(); StringTokenizer st2 = new StringTokenizer(rowstring, "\t"); for (int j = 0; st2.hasMoreTokens(); j++) { value = (String) st2.nextToken(); if (startRow + i < jTable1.getRowCount() && startCol + j < jTable1.getColumnCount()) jTable1.setValueAt(value, startRow + i, startCol + j); System.out.println( "Putting " + value + "at row = " + startRow + i + "column = " + startCol + j); } } } catch (Exception ex) { ex.printStackTrace(); } } }
private String safe(String src) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < src.length(); i++) { char c = src.charAt(i); if (c >= 32 && c < 128) { sb.append(c); } else { sb.append("<" + (int) c + ">"); } } return sb.toString(); }
public String toString() { if (StringUtil.isEmptyString(alias)) return name; if (isShowFileName()) { StringBuffer sb = new StringBuffer(); sb.append(alias); sb.append("("); sb.append(name); sb.append(")"); return sb.toString(); } else { return alias; } }
/** * Get a String representation of this object * * @return a string representation */ public String toString() { StringBuffer buf = new StringBuffer(); buf.append("Interval: "); buf.append(interval); buf.append(" ms, paths: "); buf.append(filePaths); buf.append(", pattern: "); buf.append(filePattern); buf.append(", active: "); buf.append(isActive); buf.append(", hidden OK?: "); buf.append(isHiddenOk); return buf.toString(); }
/** Handle remove. */ public void remove(int offs, int length) throws BadLocationException { int sourceLength = getLength(); // Allow user to restore uninitialized state again by removing all if (offs == 0 && sourceLength == length) { super.remove(0, sourceLength); return; } // Do custom remove String sourceText = getText(0, sourceLength); StringBuffer strBuffer = new StringBuffer(sourceText.substring(0, offs)); int counter; for (counter = offs; counter < offs + length; counter++) { // Only remove digits and intDelims char currChar = sourceText.charAt(counter); if (Character.isDigit(currChar) || currChar == intDelim) { continue; } strBuffer.append(currChar); } // Append last part of sourceText if (counter < sourceLength) { strBuffer.append(sourceText.substring(counter)); } // Set text in field super.remove(0, sourceLength); insertString(0, strBuffer.toString(), (AttributeSet) getDefaultRootElement()); // Set caret pos int newDiff = sourceLength - getLength() - 1; if (newDiff < 0) { newDiff = 0; } if (offs - newDiff < 0) { newDiff = 0; } textField.setCaretPosition(offs - newDiff); }
private void commit() { String serverName = (String) server.getSelectedItem(); if (serverName == null || serverName.equals("")) { vlog.error("No server name specified!"); if (VncViewer.nViewers == 1) if (cc.viewer instanceof VncViewer) { ((VncViewer) cc.viewer).exit(1); } ret = false; endDialog(); } // set params if (opts.via != null && opts.via.indexOf(':') >= 0) { opts.serverName = serverName; } else { opts.serverName = Hostname.getHost(serverName); opts.port = Hostname.getPort(serverName); } // Update the history list String valueStr = UserPreferences.get("ServerDialog", "history"); String t = (valueStr == null) ? "" : valueStr; StringTokenizer st = new StringTokenizer(t, ","); StringBuffer sb = new StringBuffer().append((String) server.getSelectedItem()); while (st.hasMoreTokens()) { String str = st.nextToken(); if (!str.equals((String) server.getSelectedItem()) && !str.equals("")) { sb.append(','); sb.append(str); } } UserPreferences.set("ServerDialog", "history", sb.toString()); UserPreferences.save("ServerDialog"); }
public boolean shutdown(int port, boolean ssl) { try { String protocol = "http" + (ssl ? "s" : ""); URL url = new URL(protocol, "127.0.0.1", port, "shutdown"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setRequestProperty("servicemanager", "shutdown"); conn.connect(); StringBuffer sb = new StringBuffer(); BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8")); int n; char[] cbuf = new char[1024]; while ((n = br.read(cbuf, 0, cbuf.length)) != -1) sb.append(cbuf, 0, n); br.close(); String message = sb.toString().replace("<br>", "\n"); if (message.contains("Goodbye")) { cp.appendln("Shutting down the server:"); String[] lines = message.split("\n"); for (String line : lines) { cp.append("..."); cp.appendln(line); } return true; } } catch (Exception ex) { } cp.appendln("Unable to shutdown CTP"); return false; }
/** * Implement the interface for validating and converting to internal object. Null is a valid * successful return, so errors are indicated only by existance or not of a message in the * messageBuffer. */ public Object validateAndConvert(String value, Object originalValue, StringBuffer messageBuffer) { // handle null, which is shown as the special string "<null>" if (value.equals("<null>") || value.equals("")) return null; // Do the conversion into the object in a safe manner try { if (useJavaDefaultFormat) { // allow the user to enter just the hour or just hour and minute // and assume the un-entered values are 0 int firstColon = value.indexOf(":"); if (firstColon == -1) { // user just entered the hour, so append min & sec value = value + ":0:0"; } else { // user entered hour an min. See if they also entered secs if (value.indexOf(":", firstColon + 1) == -1) { // user did not enter seconds value = value + ":0"; } } Object obj = Time.valueOf(value); return obj; } else { // use the DateFormat to parse java.util.Date javaDate = dateFormat.parse(value); return new Time(javaDate.getTime()); } } catch (Exception e) { messageBuffer.append(e.toString() + "\n"); // ?? do we need the message also, or is it automatically part of the toString()? // messageBuffer.append(e.getMessage()); return null; } }
public StringBuffer generateCode(int _type, String _info) { StringBuffer code = new StringBuffer(); String genName, passName; int index = name.lastIndexOf('.'); if (index >= 0) genName = name.substring(index + 1).toLowerCase(); else genName = name.toLowerCase(); if (_info != null && _info.trim().length() > 0) passName = _info; else { passName = getName(); if (passName.startsWith("Osejs.")) passName = passName.substring(6); } index = 0; for (Editor editor : pageList) { if (editor instanceof CodeEditor) { index++; ((CodeEditor) editor).setCodeName(genName + index); } else if (editor instanceof EquationEditor) { index++; ((EquationEditor) editor).setCodeName(genName + index); } // if (editor.isActive()) code.append(editor.generateCode(_type, passName)); } return code; }
String[] getContactList() { java.util.List cl = new java.util.LinkedList(); StringTokenizer st = new StringTokenizer(contactList.getText()); StringBuffer sb = new StringBuffer(); StringBuffer dbg = new StringBuffer("test applet contactlist: "); while (st.hasMoreTokens()) { String loginId = st.nextToken().trim(); if (loginId.length() == 0) continue; dbg.append("'" + loginId + "' "); cl.add(loginId); sb.append(loginId).append('\n'); } CAT.info(dbg.toString()); contactList.setText(sb.toString()); return (String[]) cl.toArray(new String[cl.size()]); }
/** * Get the <code>String</code> that represents this <code>MetSymbol</code>. * * @return <code>String</code> representation. */ public String toString() { StringBuffer sb = new StringBuffer(super.toString()); for (String s : paramIds) { sb.append(" param:" + s); } return sb.toString(); }
private void processKey(char c) { if (c == '\n') { AppUser user = null; try { user = m_dlSystem.findPeopleByCard(inputtext.toString()); } catch (BasicException e) { e.printStackTrace(); } if (user == null) { // user not found MessageInf msg = new MessageInf(MessageInf.SGN_WARNING, AppLocal.getIntString("message.nocard")); msg.show(this); } else { openAppView(user); } inputtext = new StringBuffer(); } else { inputtext.append(c); } }
public void doActionOnButton3() { // Sector sector = Sector.fromDegrees( 44d, 46d, -123.3d, -123.2d ); ArrayList<LatLon> latlons = new ArrayList<LatLon>(); latlons.add(LatLon.fromDegrees(45.50d, -123.3d)); // latlons.add( LatLon.fromDegrees( 45.51d, -123.3d ) ); latlons.add(LatLon.fromDegrees(45.52d, -123.3d)); // latlons.add( LatLon.fromDegrees( 45.53d, -123.3d ) ); latlons.add(LatLon.fromDegrees(45.54d, -123.3d)); // latlons.add( LatLon.fromDegrees( 45.55d, -123.3d ) ); latlons.add(LatLon.fromDegrees(45.56d, -123.3d)); // latlons.add( LatLon.fromDegrees( 45.57d, -123.3d ) ); latlons.add(LatLon.fromDegrees(45.58d, -123.3d)); // latlons.add( LatLon.fromDegrees( 45.59d, -123.3d ) ); latlons.add(LatLon.fromDegrees(45.60d, -123.3d)); ElevationModel model = this.wwd.getModel().getGlobe().getElevationModel(); StringBuffer sb = new StringBuffer(); for (LatLon ll : latlons) { double e = model.getElevation(ll.getLatitude(), ll.getLongitude()); sb.append("\n").append(e); } Logging.logger().info(sb.toString()); }