private void updateFields() { deLongNameValueLabel.setText(tempDE.getLongName()); deIdValueLabel.setText(ConventionUtil.publicIdVersion(tempDE)); if (tempDE.getContext() != null) deContextNameValueLabel.setText(tempDE.getContext().getName()); else deContextNameValueLabel.setText(""); if (tempDE.getValueDomain() != null) vdLongNameValueLabel.setText(tempDE.getValueDomain().getLongName()); else vdLongNameValueLabel.setText(""); if (prefs.getShowConceptCodeNameSummary()) { List<gov.nih.nci.ncicb.cadsr.domain.Concept> concepts = cadsrModule.getConcepts(tempDE.getDataElementConcept().getProperty()); if (concepts != null && concepts.size() > 0) { StringBuffer conceptCodeSummary = new StringBuffer(); StringBuffer conceptNameSummary = new StringBuffer(); for (Concept con : concepts) { conceptCodeSummary.append(con.getPreferredName()); conceptCodeSummary.append(" "); conceptNameSummary.append(con.getLongName()); conceptNameSummary.append(" "); } conceptCodeSummaryValue.setText(conceptCodeSummary.toString()); conceptNameSummaryValue.setText(conceptNameSummary.toString()); } } enableCDELinks(); }
static int checkAck(InputStream in) throws IOException { int b = in.read(); // b may be 0 for success, // 1 for error, // 2 for fatal error, // -1 if (b == 0) return b; if (b == -1) return b; if (b == 1 || b == 2) { StringBuffer sb = new StringBuffer(); int c; do { c = in.read(); sb.append((char) c); } while (c != '\n'); if (b == 1) { // error System.out.print(sb.toString()); } if (b == 2) { // fatal error System.out.print(sb.toString()); } } return b; }
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(); }
public ArrayList getClassesRuns() { classesRuns = new ArrayList<String>(); StringBuffer classRun = new StringBuffer(); StringBuffer testClassRun; for (int run = 1; run < 3; run++) { for (RaceRun r : getCompletedRunsByClassTime()) { if (r.getRunNumber() == run) { testClassRun = new StringBuffer(); testClassRun.append(r.getBoat().getBoatClass()); testClassRun.append(":"); testClassRun.append(run); testClassRun.append(":"); testClassRun.append(r.getStatusString()); if (testClassRun.toString().compareTo(classRun.toString()) != 0) { classRun = testClassRun; classesRuns.add(classRun.toString()); } } } } return (classesRuns); }
/** * 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); }
private void setCoordsText(final Coord[] coords, String description) { StringBuffer linebuf; Coord vertex; YaxisTreeNode node; TreeNode[] nodes; Integer lineID; double duration; int coords_length; int idx, ii; linebuf = new StringBuffer(); coords_length = coords.length; if (coords_length > 1) { duration = coords[coords_length - 1].time - coords[0].time; linebuf.append("duration" + description + " = " + tfmt.format(duration)); if (num_cols < linebuf.length()) num_cols = linebuf.length(); num_rows++; strbuf.append(linebuf.toString() + "\n"); } for (idx = 0; idx < coords_length; idx++) { linebuf = new StringBuffer("[" + idx + "]: "); vertex = coords[idx]; lineID = new Integer(vertex.lineID); node = (YaxisTreeNode) map_line2treenodes.get(lineID); nodes = node.getPath(); linebuf.append("time" + description + " = " + fmt.format(vertex.time)); for (ii = 1; ii < nodes.length; ii++) linebuf.append(", " + y_colnames[ii - 1] + " = " + nodes[ii]); if (num_cols < linebuf.length()) num_cols = linebuf.length(); num_rows++; strbuf.append(linebuf.toString()); if (idx < coords_length - 1) strbuf.append("\n"); } }
private void outdentText(JTextComponent textComponent) throws BadLocationException { int tabSize = ((Integer) textComponent.getDocument().getProperty(PlainDocument.tabSizeAttribute)) .intValue(); String selectedText = textComponent.getSelectedText(); int newLineIndex = selectedText != null ? selectedText.indexOf('\n') : -1; if (newLineIndex >= 0) { int originalSelectionStart = textComponent.getSelectionStart(); int selectionStart = originalSelectionStart; int selectionEnd = textComponent.getSelectionEnd(); int lastNewLineBeforeSelection = textComponent.getText(0, selectionStart).lastIndexOf('\n'); int begin = lastNewLineBeforeSelection >= 0 ? lastNewLineBeforeSelection : 0; int end = selectionEnd; String text = textComponent.getText(begin, end - begin); if (lastNewLineBeforeSelection < 0) { text = "\n" + text; } int len = text.length(); StringBuffer out = new StringBuffer(len); for (int i = 0; i < len; i++) { char ch = text.charAt(i); out.append(ch); if (ch == '\n' && i < len - 1) { char next = text.charAt(i + 1); int stripCount = 0; if (next == '\t') { stripCount = 1; } else { for (; stripCount < tabSize && i + 1 + stripCount < len; stripCount++) { next = text.charAt(i + 1 + stripCount); if (next != ' ' && next != '\t') { break; } } } selectionEnd -= stripCount; if (i + begin < originalSelectionStart - 1) { selectionStart -= stripCount; } i += stripCount; } } textComponent.select(begin, end); textComponent.replaceSelection( lastNewLineBeforeSelection < 0 ? out.toString().substring(1) : out.toString()); textComponent.select(selectionStart, selectionEnd); } }
private String generateHTML(final RefEntity refEntity, final InspectionTool tool) { final StringBuffer buf = new StringBuffer(); if (refEntity instanceof RefElement) { final Runnable action = new Runnable() { @Override public void run() { tool.getComposer().compose(buf, refEntity); } }; ApplicationManager.getApplication().runReadAction(action); } else { tool.getComposer().compose(buf, refEntity); } uppercaseFirstLetter(buf); if (refEntity instanceof RefElement) { appendSuppressSection(buf); } insertHeaderFooter(buf); return buf.toString(); }
/** * 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(); }
/** 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 static void main(String[] args) { StringBuffer result = new StringBuffer("<html><body><h1>Fibonacci Sequence</h1><ol>"); long f1 = 0; long f2 = 1; for (int i = 0; i < 50; i++) { result.append("<li>"); result.append(f1); long temp = f2; f2 = f1 + f2; f1 = temp; } result.append("</ol></body></html>"); JEditorPane jep = new JEditorPane("text/html", result.toString()); jep.setEditable(false); // new FibonocciRectangles().execute(); JScrollPane scrollPane = new JScrollPane(jep); JFrame f = new JFrame("Fibonacci Sequence"); f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); f.setContentPane(scrollPane); f.setSize(512, 342); EventQueue.invokeLater(new FrameShower(f)); }
/** * 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
private static String buildAllMethodNamesString( String allMethodNames, List<MethodEntry> parents) { StringBuffer allMN = new StringBuffer(120); allMN.append(allMethodNames); if (allMN.length() > 0) { allMN.append("."); } if (parents.size() > 1) { allMN.append("["); } { boolean first = true; for (MethodEntry entry : parents) { if (!first) { allMN.append(","); } first = false; allMN.append(((PsiMethod) entry.myEnd).getName()); } } if (parents.size() > 1) { allMN.append("]"); } return allMN.toString(); }
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; }
public String toString() { StringBuffer st = new StringBuffer(); st.append(" Cut Panels: "); for (int i = 0; i < visibleViewIds.size(); i++) { st.append(" " + Constants.cpNames[((Integer) visibleViewIds.elementAt(i)).intValue()]); } st.append(" \nCutPanelSize: "); st.append(cutPanelSize); st.append(" \nlonReference: "); st.append(lonReference); st.append(" \ngeoDisplayFormat: "); st.append(geoDisplayFormat); st.append(" \nuseCenterWidthOrMinMax: "); st.append(useCenterWidthOrMinMax); st.append(" \ntimeDisplayFormat: "); st.append(timeDisplayFormat); st.append(" \ntimeAxisMode: "); st.append(timeAxisMode); st.append(" \ntimeAxisReference: "); st.append(timeAxisReference); st.append(" \ntimeSinceUnits: "); st.append(timeSinceUnits); st.append(" \ndisplayPanelAxes: "); st.append(displayPanelAxes); st.append(" \nindependentHandles: "); st.append(independentHandles); return st.toString(); }
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); } }
private void handleSerialCommEvent(final SerialPortEvent serialPortEvent) { switch (serialPortEvent.getEventType()) { case SerialPortEvent.BI: case SerialPortEvent.OE: case SerialPortEvent.FE: case SerialPortEvent.PE: case SerialPortEvent.CD: case SerialPortEvent.CTS: case SerialPortEvent.DSR: case SerialPortEvent.RI: case SerialPortEvent.OUTPUT_BUFFER_EMPTY: break; case SerialPortEvent.DATA_AVAILABLE: final StringBuffer readBuffer = new StringBuffer(); int c; try { while ((c = _inputStream.read()) != 10) { if (c != 13) { readBuffer.append((char) c); } } _inputStream.close(); notifyDataReceived(readBuffer.toString()); } catch (IOException e) { e.printStackTrace(); } break; } }
/** Import the given stream data into the text component. */ protected void handleReaderImport(Reader in, JTextComponent c) throws BadLocationException, IOException { char[] buff = new char[1024]; int nch; boolean lastWasCR = false; int last; StringBuffer sbuff = null; // Read in a block at a time, mapping \r\n to \n, as well as single // \r to \n. while ((nch = in.read(buff, 0, buff.length)) != -1) { if (sbuff == null) { sbuff = new StringBuffer(nch); } last = 0; for (int counter = 0; counter < nch; counter++) { switch (buff[counter]) { case '\r': if (lastWasCR) { if (counter == 0) sbuff.append('\n'); else buff[counter - 1] = '\n'; } else lastWasCR = true; break; case '\n': if (lastWasCR) { if (counter > (last + 1)) sbuff.append(buff, last, counter - last - 1); // else nothing to do, can skip \r, next write will // write \n lastWasCR = false; last = counter; } break; default: if (lastWasCR) { if (counter == 0) sbuff.append('\n'); else buff[counter - 1] = '\n'; lastWasCR = false; } break; } // End fo switch (buff[counter]). } // End of for (int counter = 0; counter < nch; counter++). if (last < nch) { if (lastWasCR) { if (last < (nch - 1)) sbuff.append(buff, last, nch - last - 1); } else sbuff.append(buff, last, nch - last); } } // End of while ((nch = in.read(buff, 0, buff.length)) != -1). if (withinSameComponent) { ((RTextArea) c).beginAtomicEdit(); } if (lastWasCR) sbuff.append('\n'); c.replaceSelection(sbuff != null ? sbuff.toString() : ""); }
/** * Check if the server is ok * * @return status code */ protected int checkIfServerIsOk() { try { StringBuffer buff = getUrl(REQ_TEXT); appendKeyValue(buff, PROP_FILE, FILE_PUBLICSRV); URL url = new URL(buff.toString()); URLConnection urlc = url.openConnection(); InputStream is = urlc.getInputStream(); is.close(); return STATUS_OK; } catch (AddeURLException ae) { String aes = ae.toString(); if (aes.indexOf("Invalid project number") >= 0) { LogUtil.userErrorMessage("Invalid project number"); return STATUS_NEEDSLOGIN; } if (aes.indexOf("Invalid user id") >= 0) { LogUtil.userErrorMessage("Invalid user ID"); return STATUS_NEEDSLOGIN; } if (aes.indexOf("Accounting data") >= 0) { return STATUS_NEEDSLOGIN; } if (aes.indexOf("cannot run server 'txtgserv") >= 0) { return STATUS_OK; } LogUtil.userErrorMessage("Error connecting to server. " + ae.getMessage()); return STATUS_ERROR; } catch (Exception exc) { logException("Connecting to server:" + getServer(), exc); return STATUS_ERROR; } }
/** * Build a string representing a sequence of method calls needed to reach a particular child * method. * * @param allMethods previous method call sequence * @param newMethods names of each of the methods in callingMethods * @param callingMethods MethodEntry objects for each method * @param currentMethod current method being handled * @param rms contains setting determining if depth-first or breadth-first traversal has taken * place. * @return */ private String appendMN( String allMethods, String[] newMethods, List callingMethods, MethodEntry currentMethod, RelatedMethodsSettings rms) { StringBuffer result = new StringBuffer(allMethods.length() + 80); result.append(allMethods); if (rms.isDepthFirstOrdering()) { if (newMethods.length > 0) { if (result.length() > 0) result.append('.'); } int index = callingMethods.indexOf(currentMethod); result.append(newMethods[index]); result.append("()"); } else { if (newMethods.length > 0) { if (result.length() > 0) result.append('.'); if (newMethods.length > 1) { result.append('['); } for (int i = 0; i < newMethods.length; i++) { if (i > 0) result.append(','); result.append(newMethods[i]); result.append("()"); } if (newMethods.length > 1) { result.append(']'); } } } return result.toString(); }
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()); }
/* (non-Javadoc) * @see org.jdesktop.swingworker.SwingWorker#doInBackground() */ @Override protected Void doInBackground() throws Exception { if (errorInfo != null) { Throwable t = errorInfo.getErrorException(); String osMessage = "An error occurred on " + System.getProperty("os.name") + " version " + System.getProperty("os.version"); StringBuffer message = new StringBuffer(); message.append("System Info : ").append(osMessage).append(NEW_LINE_CHAR); message.append("Message : ").append(t.toString()).append(NEW_LINE_CHAR); message.append("Level : ").append(errorInfo.getErrorLevel()).append(NEW_LINE_CHAR); message.append("Stack Trace : ").append(NEW_LINE_CHAR); message.append(stackTraceToString(t)); // copy error message to system clipboard StringSelection stringSelection = new StringSelection(message.toString()); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(stringSelection, null); // open errorReportingURL OpenBrowserAction openBrowserAction = new OpenBrowserAction(errorReportingURL); openBrowserAction.actionPerformed(null); } return null; }
public Properties internalToProperties() { Properties props = new Properties(); StringBuffer st = new StringBuffer(); st.append(" "); for (int i = 0; i < visibleViewIds.size(); i++) { st.append(" " + Constants.cpNames[((Integer) visibleViewIds.elementAt(i)).intValue()]); } // System.out.println(" visibleViewIds: " + st.toString()); props.setProperty("ndedit.visibleViewIds", st.toString()); props.setProperty("ndedit.cutPanelSizeW", (new Integer(cutPanelSize.width).toString())); props.setProperty("ndedit.cutPanelSizeH", (new Integer(cutPanelSize.height).toString())); props.setProperty("ndedit.cutPanelWMin", (new Integer(cutPanelMinSize.width).toString())); props.setProperty("ndedit.cutPanelHMin", (new Integer(cutPanelMinSize.height).toString())); props.setProperty("ndedit.cutPanelWMax", (new Integer(cutPanelMaxSize.width).toString())); props.setProperty("ndedit.cutPanelHMax", (new Integer(cutPanelMaxSize.height).toString())); props.setProperty("ndedit.lonReference", (new Double(lonReference).toString())); props.setProperty("ndedit.geoDisplayFormat", (new Integer(geoDisplayFormat).toString())); props.setProperty("ndedit.timeDisplayFormat", (new Integer(timeDisplayFormat).toString())); props.setProperty("ndedit.timeAxisMode", (new Integer(timeAxisMode).toString())); props.setProperty("ndedit.timeAxisReference", (new Double(timeAxisReference).toString())); String dpa = new Boolean(displayPanelAxes).toString(); props.setProperty("ndedit.displayPanelAxes", dpa); dpa = new Boolean(independentHandles).toString(); props.setProperty("ndedit.independentHandles", dpa); return props; }
/** * @return the clipboard content as a String (DataFlavor.stringFlavor) Code snippet adapted from * jEdit (Registers.java), http://www.jedit.org. Returns null if clipboard is empty. */ public static String getClipboardStringContent(Clipboard clipboard) { // Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); try { String selection = (String) (clipboard.getContents(null).getTransferData(DataFlavor.stringFlavor)); if (selection == null) return null; boolean trailingEOL = (selection.endsWith("\n") || selection.endsWith(System.getProperty("line.separator"))); // Some Java versions return the clipboard contents using the native line separator, // so have to convert it here , see jEdit's "registers.java" BufferedReader in = new BufferedReader(new StringReader(selection)); StringBuffer buf = new StringBuffer(); String line; while ((line = in.readLine()) != null) { buf.append(line); buf.append('\n'); } // remove trailing \n if (!trailingEOL) buf.setLength(buf.length() - 1); return buf.toString(); } catch (Exception e) { e.printStackTrace(); return null; } }
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 static String fill( String source, char fillerCharacter, int length, int aligment, boolean fillInclusiveEmptyString) { // if (StringUtils.isEmpty(source) || length<0) { if (length < 0) { return source; } if (source == null) source = ""; if (source.length() > length) return source.substring(0, length); // throw new AWBusinessException("No se puede llenar '"+source+"' pues tamaƱo excede "+length); source = source.trim(); if (source.length() == length) return source; if (!fillInclusiveEmptyString && source.length() == 0) return source; if (source.length() > length) return source.substring(0, length); StringBuffer buf = new StringBuffer(length); if (aligment == SwingConstants.CENTER) { int left = (length - source.length()) / 2; int right = length - (source.length() + left); fill(buf, fillerCharacter, left); buf.append(source); fill(buf, fillerCharacter, right); } else { if (aligment == SwingConstants.LEFT) buf.append(source); fill(buf, fillerCharacter, length - source.length()); if (aligment == SwingConstants.RIGHT) buf.append(source); } return buf.toString(); }
public void run() { while (_connected) { try { Thread.sleep(25); if (_specialRequest != null) { for (final char c : _specialRequest.toCharArray()) { final StringBuffer buf = new StringBuffer(); buf.append(c); sendMessage(buf.toString()); Thread.sleep(2000); } _specialRequest = null; } else if (_transmitterValue != null) { _lastRequest = _lastRequest.equals(FLIGHT_DATA_REQUEST) ? SENSORS_DATA_REQUEST : FLIGHT_DATA_REQUEST; _transmitterValue += _lastRequest; sendMessage(_transmitterValue); _transmitterValue = null; } } catch (Exception e) { e.printStackTrace(); } } }
private Pattern getCurrentPattern() { String pattern = getFindTextField().getText(); int flags = Pattern.DOTALL; if (!getRegexButton().isSelected()) { StringBuffer newpattern = new StringBuffer(); // 'quote' the pattern for (int i = 0; i < pattern.length(); i++) { if ("\\[]^$&|().*+?{}".indexOf(pattern.charAt(i)) >= 0) { newpattern.append('\\'); } newpattern.append(pattern.charAt(i)); } pattern = newpattern.toString(); // make "*" .* and "?" . if (getWildCardsButton().isSelected()) { pattern = pattern.replaceAll("\\\\\\*", ".+?"); pattern = pattern.replaceAll("\\\\\\?", "."); } } if (!getCaseSensitiveCheckBox().isSelected()) { flags |= Pattern.CASE_INSENSITIVE; } if (getWholeWordCheckBox().isSelected()) { pattern = "\\b" + pattern + "\\b"; } return Pattern.compile(pattern, flags); }
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(); }
/** * format a given Font to a string, following "Font.decode()" format, ie fontname-style-pointsize, * fontname-pointsize, fontname-style or fontname, where style is one of "BOLD", "ITALIC", * "BOLDITALIC" (default being PLAIN) */ public static String formatFontAsProperties(Font font) { // jpicedt.Log.debug(new MiscUtilities(),"formatFontAsProperties","font="+font); String family = font.getFamily(); /* System.out.println("family="+family); String faceName = font.getFontName(); System.out.println("faceName="+faceName); String logicalName = font.getName(); System.out.println("logicalName"+logicalName); String psName = font.getPSName(); System.out.println("PSName="+psName); */ StringBuffer buf = new StringBuffer(20); buf.append(family); buf.append("-"); switch (font.getStyle()) { case Font.ITALIC: buf.append("ITALIC-"); break; case Font.BOLD: buf.append("BOLD-"); break; case Font.BOLD | Font.ITALIC: buf.append("BOLDITALIC-"); break; default: // PLAIN -> nothing } buf.append(Integer.toString(font.getSize())); return buf.toString(); }