/** * Returns date in the format: neededDatePattern, in case if year or month isn't entered, current * year/month is put. * * @return correct date. */ private Date getCorrectedDate(String enteredDate) { Queue<String> dateParts = new ArrayDeque<>(3); StringBuilder number = new StringBuilder(); for (char symbol : enteredDate.toCharArray()) { if (Character.isDigit(symbol)) { number.append(symbol); } else if (number.length() > 0) { dateParts.add(number.toString()); number = new StringBuilder(); } } if (number.length() > 0) { dateParts.add(number.toString()); } Calendar currentDate = Calendar.getInstance(); switch (dateParts.size()) { case 1: dateParts.add(Integer.toString(currentDate.get(Calendar.MONTH) + 1)); case 2: dateParts.add(Integer.toString(currentDate.get(Calendar.YEAR))); } try { return new SimpleDateFormat("dd.MM.yyyy") .parse(dateParts.remove() + '.' + dateParts.remove() + '.' + dateParts.remove()); } catch (ParseException e) { throw new RuntimeException(e); // todo change exception } }
public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException { StringBuilder builder = new StringBuilder(string); for (int i = builder.length() - 1; i >= 0; i--) { int cp = builder.codePointAt(i); if (!Character.isDigit(cp) && cp != '-') { builder.deleteCharAt(i); if (Character.isSupplementaryCodePoint(cp)) { i--; builder.deleteCharAt(i); } } } super.insertString(fb, offset, builder.toString(), attr); }
@Override public void insertString(final int offs, final String str, final AttributeSet a) throws BadLocationException { // NavigatorLogger.printMessage("Offset:"+offs+" STr:"+str+"L:"+getLength()+"attr:"+a); if ((getLength() + str.length()) <= maxLength) { final char[] source = str.toCharArray(); final char[] result = new char[source.length]; int j = 0; for (int i = 0; i < result.length; i++) { if (Character.isDigit(source[i])) { result[j++] = source[i]; } else { toolkit.beep(); if (log.isDebugEnabled()) { log.debug("insertString: " + source[i]); // NOI18N } } } super.insertString(offs, new String(result, 0, j), a); checked = false; } else { toolkit.beep(); } if ((getLength()) == maxLength) { // getLength() ist schon aktualisiert if (bringFocus2Next == true) { checked = true; nextField.requestFocus(); } // NavigatorLogger.printMessage("Sprung"); // NavigatorLogger.printMessage(nextField); } }
public static boolean isNumeric(String str) { for (int i = str.length(); --i >= 0; ) { if (!Character.isDigit(str.charAt(i))) { return false; } } return true; }
private String readInt(JTextComponent textComponent) throws IncorrectInputException { String text = textComponent.getText(); if (Character.isDigit(text.charAt(0))) { return text; } else { throw new IncorrectInputException("wrong input"); } }
@Override protected void processKeyEvent(KeyEvent e) { if (e.getID() == KeyEvent.KEY_TYPED) { if (!Character.isDigit(e.getKeyChar()) && !(!positiveOnly && e.getKeyChar() == '-')) { e.consume(); } } super.processKeyEvent(e); }
public void processKeyEvent(KeyEvent evt) { evt = KeyEventWorkaround.processKeyEvent(evt); if (evt == null) return; switch (evt.getID()) { case KeyEvent.KEY_TYPED: char ch = evt.getKeyChar(); if (!nonDigit && Character.isDigit(ch)) { super.processKeyEvent(evt); repeat = true; repeatCount = Integer.parseInt(action.getText()); } else { nonDigit = true; if (repeat) { passToView(evt); } else super.processKeyEvent(evt); } break; case KeyEvent.KEY_PRESSED: int keyCode = evt.getKeyCode(); if (evt.isActionKey() || evt.isControlDown() || evt.isAltDown() || evt.isMetaDown() || keyCode == KeyEvent.VK_BACK_SPACE || keyCode == KeyEvent.VK_DELETE || keyCode == KeyEvent.VK_ENTER || keyCode == KeyEvent.VK_TAB || keyCode == KeyEvent.VK_ESCAPE) { nonDigit = true; if (repeat) { passToView(evt); break; } else if (keyCode == KeyEvent.VK_TAB) { complete(true); evt.consume(); } else if (keyCode == KeyEvent.VK_ESCAPE) { evt.consume(); if (popup != null) { popup.dispose(); popup = null; action.requestFocus(); } else { if (temp) view.removeToolBar(ActionBar.this); view.getEditPane().focusOnTextArea(); } break; } else if ((keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_DOWN) && popup != null) { popup.list.processKeyEvent(evt); break; } } super.processKeyEvent(evt); break; } }
/** * Checks if a string contains anything but spaces - needed for text field validation * * @param inputSting * @return * @param inputString */ private static boolean containsText(final String inputString) { boolean stringContainsText = false; if (!inputString.equals("")) { for (int i = 0; i < inputString.length(); i++) { char chr = inputString.charAt(i); if (Character.isDigit(chr) || Character.isLetter(chr)) stringContainsText = true; } } return stringContainsText; }
// The insert string method public void insertString(int offs, String src, AttributeSet a) throws BadLocationException { char[] source = src.toCharArray(); char[] result = new char[source.length]; int j = 0; for (int i = 0; i < result.length; i++) { if (Character.isDigit(source[i])) result[j++] = source[i]; } super.insertString(offs, new String(result, 0, j), a); }
// helper function to check if String is either a number or a string (first and last name) public static boolean isValidInput(String x) { boolean hasNumber = false; for (int i = 0; i < x.trim().length(); i++) { if (Character.isDigit(x.trim().charAt(i))) { hasNumber = true; break; } } // if it has a number, check that it is all numbers if (hasNumber) { for (int i = 0; i < x.trim().length(); i++) { if (!Character.isDigit(x.trim().charAt(i)) && !(x.trim().charAt(i) == '-')) { return false; } } return isValidNumber(x); } // else check that there are 2 inputs for first and last name; else return (x.split("\\s+")).length >= 2; // delimiting using any kind of white space }
/** 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); }
public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { char[] source = str.toCharArray(); char[] result = new char[source.length]; int j = 0; for (int i = 0; i < result.length; i++) { if (Character.isDigit(source[i])) result[j++] = source[i]; else { toolkit.beep(); // System.err.println("insertString: " + source[i]); } } super.insertString(offs, new String(result, 0, j), a); }
public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { final boolean rgb = isRGBMode(); char[] source = str.toCharArray(); if (mySrc != null) { final int selected = mySrc.getSelectionEnd() - mySrc.getSelectionStart(); int newLen = mySrc.getText().length() - selected + str.length(); if (newLen > (myHex ? 6 : 3)) { Toolkit.getDefaultToolkit().beep(); return; } } char[] result = new char[source.length]; int j = 0; for (int i = 0; i < result.length; i++) { if (myHex ? "0123456789abcdefABCDEF".indexOf(source[i]) >= 0 : Character.isDigit(source[i])) { result[j++] = source[i]; } else { Toolkit.getDefaultToolkit().beep(); } } final String toInsert = StringUtil.toUpperCase(new String(result, 0, j)); final String res = new StringBuilder(mySrc.getText()).insert(offs, toInsert).toString(); try { if (!myHex) { final int num = Integer.parseInt(res); if (rgb) { if (num > 255) { Toolkit.getDefaultToolkit().beep(); return; } } else { if ((mySrc == myRed && num > 359) || ((mySrc == myGreen || mySrc == myBlue) && num > 100)) { Toolkit.getDefaultToolkit().beep(); return; } } } } catch (NumberFormatException ignore) { } super.insertString(offs, toInsert, a); }
public void actionPerformed(ActionEvent arg0) { // String s = arg0.getActionCommand(); if (faxNumButton.isSelected()) { if (Character.isDigit(s.charAt(0))) faxNumberWork(s); if (s.equals("-")) faxNumberWork(s); } else { if (!(check_control_key(s))) { BroadcastDBWork(s); } } if (s.equals("Send")) { SendWork(s); } else if (s.equals("Clear")) { ClearWork(s); } else if (s.equals("Cancel")) { CancelWork(s); } }
@Override public void replace( DocumentFilter.FilterBypass fp, int offset, int length, String string, AttributeSet aset) throws BadLocationException { Document doc = fp.getDocument(); String oldText = doc.getText(0, doc.getLength()); StringBuilder sb = new StringBuilder(oldText); sb.replace(offset, offset + length, oldText); int len = string.length(); boolean isValidInteger = true; for (int i = 0; i < len; i++) { if (!Character.isDigit(string.charAt(i))) { isValidInteger = false; break; } } if (isValidInteger && verifyText(sb.toString())) { super.replace(fp, offset, length, string, aset); } else Toolkit.getDefaultToolkit().beep(); }
/** Remove delimiters */ public String getRealString(String oldString) { char addChar; String newString = ""; realDelimFound = false; int length = oldString.length(); for (int i = 0; i < length; i++) { addChar = oldString.charAt(i); if (Character.isDigit(addChar)) { newString += addChar; } else if (addChar == realDelim) { if (realDelimFound == true) { break; } realDelimFound = true; newString += "."; } } return newString; }
public static double getOSVersion() { if (osVersion == null) { try { String ver = System.getProperties().getProperty("os.version"); String version = ""; boolean firstPoint = true; for (int i = 0; i < ver.length(); i++) { if (ver.charAt(i) == '.') { if (firstPoint) { version += ver.charAt(i); } firstPoint = false; } else if (Character.isDigit(ver.charAt(i))) { version += ver.charAt(i); } } osVersion = new Double(version); } catch (Exception ex) { osVersion = new Double(1.0); } } return osVersion.doubleValue(); }
private DarkBotMCSpambot( DarkBot darkBot, String server, String username, String password, String sessionId, String loginProxy, String proxy, String owner) { synchronized (bots) { bots.add(this); // slotsTaken.incrementAndGet(); synchronized (slotsTaken) { slotsTaken.notifyAll(); } } MinecraftBotData.Builder builder = MinecraftBotData.builder(); // botData.nickname = ""; // for(int i = 0; i < 10; i++) // botData.nickname += alphas[random.nextInt(alphas.length)]; if (proxy != null && !proxy.isEmpty()) { int port = 80; ProxyType type = ProxyType.SOCKS; if (proxy.contains(":")) { String[] parts = proxy.split(":"); proxy = parts[0]; port = Integer.parseInt(parts[1]); if (parts.length > 2) type = ProxyType.values()[Integer.parseInt(parts[2]) - 1]; } builder.withSocksProxy(new ProxyData(proxy, port, type)); this.proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(proxy, port)); } if (loginProxy != null && !loginProxy.isEmpty()) { int port = 80; if (loginProxy.contains(":")) { String[] parts = loginProxy.split(":"); loginProxy = parts[0]; port = Integer.parseInt(parts[1]); } builder.withHttpProxy(new ProxyData(loginProxy, port, ProxyType.HTTP)); this.loginProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(loginProxy, port)); } builder.withUsername(username); if (sessionId != null) builder.withSessionId(sessionId); else builder.withPassword(password); if (server != null && !server.isEmpty()) { int port = 25565; if (server.contains(":")) { String[] parts = server.split(":"); server = parts[0]; port = Integer.parseInt(parts[1]); } builder.withServer(server).withPort(port); } else throw new IllegalArgumentException("Unknown server!"); this.owner = owner; MinecraftBotData botData = builder.build(); System.setProperty("socksProxyHost", ""); System.setProperty("socksProxyPort", ""); System.out.println("[" + username + "] Connecting..."); bot = new MinecraftBot(darkBot, botData); bot.setMovementDisabled(true); connectionHandler = bot.getConnectionHandler(); Session session = bot.getSession(); // System.gc(); System.out.println("[" + username + "] Done! (" + amountJoined.incrementAndGet() + ")"); bot.getEventManager().registerListener(this); bot.getGameHandler().registerListener(this); long lastShoutTime = System.currentTimeMillis(); while (bot.isConnected()) { if (die) { connectionHandler.sendPacket(new Packet255KickDisconnect("Goodbye")); return; } try { Thread.sleep(3000 + random.nextInt(1000)); } catch (InterruptedException exception) { exception.printStackTrace(); } if (!bot.hasSpawned()) continue; connectionHandler.sendPacket(new Packet0KeepAlive(random.nextInt())); if (spamMessage == null || !canSpam) continue; String message = spamMessage; if (message.contains("%skill")) message = message.replace("%skill", skills[nextSkill++]); if (nextSkill >= skills.length) nextSkill = 0; if (message.contains("%bot")) { synchronized (bots) { message = message.replace( "%bot", bots.get(nextBot > bots.size() ? (nextBot = 0) * 0 : nextBot++) .bot .getSession() .getUsername()); } } if (message.contains("%spamlist")) message = message.replace("%spamlist", spamList[nextSpamList++]); if (nextSpamList >= spamList.length) nextSpamList = 0; if (message.contains("%rnd")) { int length = 1; int index = message.indexOf("%rnd") + "%rnd".length(); int lastIndex; for (lastIndex = index; lastIndex < message.length(); lastIndex++) if (Character.isDigit(message.charAt(lastIndex))) lastIndex++; else break; if (lastIndex > message.length()) lastIndex--; try { System.out.println(index + "," + lastIndex + "," + message.length()); length = Integer.parseInt(message.substring(index, lastIndex)); } catch (Exception exception) { } String randomChars = ""; for (int i = 0; i < length; i++) randomChars += alphas[random.nextInt(alphas.length)]; message = message.replace("%rnd", randomChars); } if (message.contains("%msg")) message = "/msg " + msgChars[nextMsgChar++] + " " + message.replace("%msg", ""); if (message.contains("%ernd")) { message = message.replace("%ernd", ""); int extraMessageLength = 15 + random.nextInt(6); message = message.substring(0, Math.min(100 - extraMessageLength, message.length())) + " ["; extraMessageLength -= 3; for (int i = 0; i < extraMessageLength; i++) message += alphas[random.nextInt(alphas.length)]; message += "]"; } else message = message.substring(0, Math.min(100, message.length())); connectionHandler.sendPacket(new Packet3Chat(message)); } synchronized (bots) { bots.remove(this); } amountJoined.decrementAndGet(); slotsTaken.decrementAndGet(); synchronized (slotsTaken) { slotsTaken.notifyAll(); } }
@NotNull private Pattern getPattern(String pattern) { if (!Comparing.strEqual(pattern, myPattern)) { myCompiledPattern = null; myPattern = pattern; } if (myCompiledPattern == null) { boolean allowToLower = true; final int eol = pattern.indexOf('\n'); if (eol != -1) { pattern = pattern.substring(0, eol); } if (pattern.length() >= 80) { pattern = pattern.substring(0, 80); } final @NonNls StringBuffer buffer = new StringBuffer(); if (containsOnlyUppercaseLetters(pattern)) { allowToLower = false; } if (allowToLower) { buffer.append(".*"); } boolean firstIdentifierLetter = true; for (int i = 0; i < pattern.length(); i++) { final char c = pattern.charAt(i); if (Character.isLetterOrDigit(c)) { // This logic allows to use uppercase letters only to catch the name like PDM for // PsiDocumentManager if (Character.isUpperCase(c) || Character.isDigit(c)) { if (!firstIdentifierLetter) { buffer.append("[^A-Z]*"); } buffer.append("["); buffer.append(c); if (allowToLower || i == 0) { buffer.append('|'); buffer.append(Character.toLowerCase(c)); } buffer.append("]"); } else if (Character.isLowerCase(c)) { buffer.append('['); buffer.append(c); buffer.append('|'); buffer.append(Character.toUpperCase(c)); buffer.append(']'); } else { buffer.append(c); } firstIdentifierLetter = false; } else if (c == '*') { buffer.append(".*"); firstIdentifierLetter = true; } else if (c == '.') { buffer.append("\\."); firstIdentifierLetter = true; } else if (c == ' ') { buffer.append("[^A-Z]*\\ "); firstIdentifierLetter = true; } else { firstIdentifierLetter = true; // for standard RegExp engine // buffer.append("\\u"); // buffer.append(Integer.toHexString(c + 0x20000).substring(1)); // for OROMATCHER RegExp engine buffer.append("\\x"); buffer.append(Integer.toHexString(c + 0x20000).substring(3)); } } buffer.append(".*"); try { myCompiledPattern = new Perl5Compiler().compile(buffer.toString()); } catch (MalformedPatternException e) { // do nothing } } return myCompiledPattern; }
private int findItOffset( @NotNull Editor editor, int startOffset, int count, int dir, boolean noSmartCase) { boolean wrap = Options.getInstance().isSet("wrapscan"); TextRange range = findIt(editor, startOffset, count, dir, noSmartCase, wrap, true, true); if (range == null) { return -1; } // highlightMatch(editor, range.getStartOffset(), range.getEndOffset()); ParsePosition pp = new ParsePosition(0); int res = range.getStartOffset(); if (lastOffset == null) { return -1; } if (lastOffset.length() == 0) { return range.getStartOffset(); } else if (Character.isDigit(lastOffset.charAt(0)) || lastOffset.charAt(0) == '+' || lastOffset.charAt(0) == '-') { int lineOffset = 0; if (lastOffset.equals("+")) { lineOffset = 1; } else if (lastOffset.equals("-")) { lineOffset = -1; } else { if (lastOffset.charAt(0) == '+') { lastOffset = lastOffset.substring(1); } NumberFormat nf = NumberFormat.getIntegerInstance(); pp = new ParsePosition(0); Number num = nf.parse(lastOffset, pp); if (num != null) { lineOffset = num.intValue(); } } int line = editor.offsetToLogicalPosition(range.getStartOffset()).line; int newLine = EditorHelper.normalizeLine(editor, line + lineOffset); res = VimPlugin.getMotion().moveCaretToLineStart(editor, newLine); } else if ("ebs".indexOf(lastOffset.charAt(0)) != -1) { int charOffset = 0; if (lastOffset.length() >= 2) { if ("+-".indexOf(lastOffset.charAt(1)) != -1) { charOffset = 1; } NumberFormat nf = NumberFormat.getIntegerInstance(); pp = new ParsePosition(lastOffset.charAt(1) == '+' ? 2 : 1); Number num = nf.parse(lastOffset, pp); if (num != null) { charOffset = num.intValue(); } } int base = range.getStartOffset(); if (lastOffset.charAt(0) == 'e') { base = range.getEndOffset() - 1; } res = Math.max(0, Math.min(base + charOffset, EditorHelper.getFileSize(editor) - 1)); } int ppos = pp.getIndex(); if (ppos < lastOffset.length() - 1 && lastOffset.charAt(ppos) == ';') { int flags; if (lastOffset.charAt(ppos + 1) == '/') { flags = Command.FLAG_SEARCH_FWD; } else if (lastOffset.charAt(ppos + 1) == '?') { flags = Command.FLAG_SEARCH_REV; } else { return res; } if (lastOffset.length() - ppos > 2) { ppos++; } res = search(editor, lastOffset.substring(ppos + 1), res, 1, flags); return res; } else { return res; } }
/* * Carries out a number of tests, generates NEURON, GENESIS and NeuroML code etc. */ private static void doTests(neuronEditorFrame nef, String fileName) { System.out.println( "Testing Cvapp/NeuroMorpho.Org by generating NEURON, GENESIS and NeuroML files for " + fileName); File tempDir = new File("temp"); if (!tempDir.exists()) tempDir.mkdir(); neuronEditorPanel nep = nef.getNeuronEditorPanel(); String rootFileName = fileName; if (rootFileName.toLowerCase().endsWith(".swc")) { rootFileName = rootFileName.substring(0, rootFileName.length() - 4); } if (rootFileName.lastIndexOf(System.getProperty("file.separator")) > 0) { rootFileName = rootFileName.substring( rootFileName.lastIndexOf(System.getProperty("file.separator")) + 1); } // NEURON save... String neuronFileName = rootFileName + ".hoc"; File neuronFile = new File(tempDir, neuronFileName); File neuronTestFile = new File(tempDir, rootFileName + "_test.hoc"); nep.writeStringToFile(nep.getCell().HOCwriteNS(), neuronFile.getAbsolutePath()); StringBuilder sbNeuTest = new StringBuilder(); sbNeuTest.append("load_file(\"nrngui.hoc\")\n"); sbNeuTest.append("load_file(\"../neuronUtils/nCtools.hoc\")\n"); sbNeuTest.append("load_file(\"../neuronUtils/cellCheck.hoc\")\n"); sbNeuTest.append("load_file(\"nrngui.hoc\")\n"); sbNeuTest.append("load_file(\"" + neuronFileName + "\")\n\n"); sbNeuTest.append("forall morph()\n"); System.out.println("--------------------------------------------------------------"); nep.writeStringToFile(sbNeuTest.toString(), neuronTestFile.getAbsolutePath()); System.out.println( "Saved NEURON representation of the file to: " + neuronFile.getAbsolutePath() + ": " + neuronFile.exists()); System.out.println("--------------------------------------------------------------"); // GENESIS save... String genesisFileName = rootFileName + ".p"; File genesisFile = new File(tempDir, genesisFileName); File genesisTestFile = new File(tempDir, rootFileName + "_test.g"); nep.writeStringToFile(nep.getCell().GENESISwriteHR(), genesisFile.getAbsolutePath()); StringBuilder sbGenTest = new StringBuilder(); sbGenTest.append("include compartments \n"); sbGenTest.append("create neutral /library\n"); sbGenTest.append("disable /library\n"); sbGenTest.append("ce /library\n"); sbGenTest.append("make_cylind_compartment\n"); sbGenTest.append("make_cylind_symcompartment\n"); sbGenTest.append("make_sphere_compartment\n"); sbGenTest.append("ce /\n"); sbGenTest.append( "echo \"Prototype compartments created, reading cell from " + genesisFileName + "\"\n"); sbGenTest.append("readcell " + genesisFileName + " /mycell\n\n"); sbGenTest.append("create xform /form [0,0,400,400] -nolabel\n"); sbGenTest.append( "create xdraw /form/draw [0,0,100%,100%] -wx 0.002 -wy 0.002 -transform ortho3d -bg white\n"); sbGenTest.append( "setfield /form/draw xmin -3.0E-4 xmax 3.0E-4 ymin -3.0E-4 ymax 3.0E-4 vx 0.0 vy 0.0 vz -0.002\n"); sbGenTest.append( "create xcell /form/draw/cell -path \"/mycell/##[][TYPE=compartment],/mycell/##[][TYPE=symcompartment]\" -colfield Vm -colmin -0.07 -colmax 0.03 -diarange -5\n"); sbGenTest.append("xcolorscale hot\n"); sbGenTest.append("xshow /form\n\n"); sbGenTest.append("showfield /mycell/##[][TYPE=compartment] **\n\n"); nep.writeStringToFile(sbGenTest.toString(), genesisTestFile.getAbsolutePath()); System.out.println( "Saved GENESIS representation of the file to: " + genesisFile.getAbsolutePath() + ": " + genesisFile.exists()); System.out.println("--------------------------------------------------------------"); // NeuroML save... String nml1FileName = rootFileName + ".xml"; File nml1File = new File(tempDir, nml1FileName); nep.writeStringToFile(nep.getCell().writeNeuroML_v1_8_1(), nml1File.getAbsolutePath()); System.out.println( "Saved NeuroML representation of the file to: " + nml1File.getAbsolutePath() + ": " + nml1File.exists()); File v1schemaFile = new File("Schemas/v1.8.1/Level3/NeuroML_Level3_v1.8.1.xsd"); validateXML(nml1File, v1schemaFile); String nml2FileName = rootFileName + ".cell.nml"; if (Character.isDigit(nml2FileName.charAt(0))) { nml2FileName = "Cell_" + nml2FileName; } File nml2File = new File(tempDir, nml2FileName); nep.writeStringToFile(nep.getCell().writeNeuroML_v2beta(), nml2File.getAbsolutePath()); System.out.println( "Saved NeuroML representation of the file to: " + nml2File.getAbsolutePath() + ": " + nml2File.exists()); validateXMLWithURL(nml2File, "Schemas/v2/NeuroML_v2beta4.xsd"); }
public void run() { // String a = // "http://neuromorpho.org/neuroMorpho/dableFiles/borst/CNG%20version/dCH-cobalt.CNG.swc"; // // For developer use if (myArgs.length == 0) { String usage = "\nError, missing SWC file containing morphology!\n\nUsage: \n java -cp build cvapp.main swc_file [-test]" + "\n or:\n ./run.sh swc_file [" + TEST_FLAG + "|" + TEST_NOGUI_FLAG + "|" + NEUROML1_EXPORT_FLAG + "|" + NEUROML2_EXPORT_FLAG + "]\n\n" + "where swc_file is the file name or URL of the SWC morphology file\n"; System.out.println(usage); System.exit(0); } String a = myArgs[0]; File baseDir = new File("."); if ((new File(a)).exists()) { baseDir = (new File(a)).getParentFile(); } try { File root = new File(main.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()) .getParentFile(); if (!a.startsWith("http://") && !a.startsWith("file://")) { a = "file://" + (new File(a)).getCanonicalPath(); } boolean supressGui = false; if (myArgs.length == 2 && (myArgs[1].equals(TEST_NOGUI_FLAG) || myArgs[1].equals(NEUROML1_EXPORT_FLAG) || myArgs[1].equals(NEUROML2_EXPORT_FLAG))) { supressGui = true; } neuronEditorFrame nef = null; nef = new neuronEditorFrame(700, 600, supressGui); // nef.validate(); nef.pack(); centerWindow(nef); nef.setVisible(!supressGui); nef.setReadWrite(true, true); int indexof = a.lastIndexOf('/') + 1; String directory = a.substring(0, indexof); String fileName = a.substring(indexof, a.length()); URL u = new URL(a); String sdata[] = readStringArrayFromURL(u); nef.setTitle("3DViewer (Modified from CVAPP with permission)-Neuron: " + fileName); nef.loadFile(sdata, directory, fileName); System.out.println("Loaded: " + fileName); if (myArgs.length == 2 && myArgs[1].equals(TEST_ONE_FLAG)) { // Thread.sleep(1000); doTests(nef, fileName); } else if (myArgs.length == 2 && myArgs[1].equals(NEUROML1_EXPORT_FLAG)) { File rootFile = (new File(baseDir, fileName)).getAbsoluteFile(); String nml1FileName = rootFile.getName().endsWith(".swc") ? rootFile.getName().substring(0, rootFile.getName().length() - 4) + ".xml" : rootFile.getName() + ".xml"; File nml1File = new File(rootFile.getParentFile(), nml1FileName); neuronEditorPanel nep = nef.getNeuronEditorPanel(); nep.writeStringToFile(nep.getCell().writeNeuroML_v1_8_1(), nml1File.getAbsolutePath()); System.out.println( "Saved NeuroML representation of the file to: " + nml1File.getAbsolutePath() + ": " + nml1File.exists()); File v1schemaFile = new File(root, "Schemas/v1.8.1/Level3/NeuroML_Level3_v1.8.1.xsd"); validateXML(nml1File, v1schemaFile); System.exit(0); } else if (myArgs.length == 2 && myArgs[1].equals(NEUROML2_EXPORT_FLAG)) { File rootFile = (new File(baseDir, fileName)).getAbsoluteFile(); String nml2FileName = rootFile.getName().endsWith(".swc") ? rootFile.getName().substring(0, rootFile.getName().length() - 4) + ".cell.nml" : rootFile.getName() + ".cell.nml"; if (Character.isDigit(nml2FileName.charAt(0))) { nml2FileName = "Cell_" + nml2FileName; } File nml2File = new File(rootFile.getParentFile(), nml2FileName); neuronEditorPanel nep = nef.getNeuronEditorPanel(); nep.writeStringToFile(nep.getCell().writeNeuroML_v2beta(), nml2File.getAbsolutePath()); System.out.println( "Saved the NeuroML representation of the file to: " + nml2File.getAbsolutePath() + ": " + nml2File.exists()); validateXML(nml2File, new File(root, "Schemas/v2/NeuroML_v2beta4.xsd")); System.exit(0); } else if (myArgs.length == 2 && (myArgs[1].equals(TEST_FLAG) || (myArgs[1].equals(TEST_NOGUI_FLAG)))) { // Thread.sleep(1000); doTests(nef, fileName); File exampleDir = new File("twoCylSwc"); for (File f : exampleDir.listFiles()) { if (f.getName().endsWith(".swc")) { sdata = fileString.readStringArrayFromFile(f.getAbsolutePath()); nef.setTitle("3DViewer (Modified from CVAPP with permission)-Neuron: " + f.getName()); nef.loadFile(sdata, f.getParent(), f.getName()); doTests(nef, f.getAbsolutePath()); } } exampleDir = new File("spherSomaSwc"); for (File f : exampleDir.listFiles()) { if (f.getName().endsWith(".swc")) { sdata = fileString.readStringArrayFromFile(f.getAbsolutePath()); nef.setTitle("3DViewer (Modified from CVAPP with permission)-Neuron: " + f.getName()); nef.loadFile(sdata, f.getParent(), f.getName()); doTests(nef, f.getAbsolutePath()); } } exampleDir = new File("caseExamples"); for (File f : exampleDir.listFiles()) { if (f.getName().endsWith(".swc")) { sdata = fileString.readStringArrayFromFile(f.getAbsolutePath()); nef.setTitle("3DViewer (Modified from CVAPP with permission)-Neuron: " + f.getName()); nef.loadFile(sdata, f.getParent(), f.getName()); doTests(nef, f.getAbsolutePath()); } } if (supressGui) System.exit(0); } } catch (Exception exception) { System.err.println("Error while handling SWC file (" + a + ")"); exception.printStackTrace(); } }
@Override public boolean isValidInputCharacter(final char c, final int offs) { return Character.isDigit(c) && offs < DBSchema.getFieldLength(DBSchema.OWNER_INDEX); }