📄 jelib.java
字号:
if (offX != 0) ret.append("X" + TextUtils.formatDouble(offX, 0) + ";"); double offY = td.getYOff(); if (offY != 0) ret.append("Y" + TextUtils.formatDouble(offY, 0) + ";"); } return ret.toString(); } /** * Method to write the variables on an ImmutableElectricObject. * If object is ImmuatbleNodeInst write variables on its PortInsts also. */ private void printlnVars(ImmutableElectricObject d) { // write the variables if (d instanceof ImmutableNodeInst) { if (d instanceof ImmutableIconInst) { for (Iterator<Variable> it = ((ImmutableIconInst)d).getDefinedParameters(); it.hasNext(); ) printVar(null, it.next()); } ImmutableNodeInst nid = (ImmutableNodeInst)d; printVars(null, nid); if (nid.hasPortInstVariables()) { ArrayList<PortProtoId> portsWithVariables = new ArrayList<PortProtoId>(); for (Iterator<PortProtoId> it = nid.getPortsWithVariables(); it.hasNext(); ) portsWithVariables.add(it.next()); Collections.sort(portsWithVariables, PORTS_BY_EXTERNAL_ID); for (PortProtoId portProtoId: portsWithVariables) printVars(portProtoId.externalId, nid.getPortInst(portProtoId)); } } else { if (d instanceof ImmutableCell) { for (Iterator<Variable> it = ((ImmutableCell)d).getParameters(); it.hasNext(); ) printVar(null, it.next()); } printVars(null, d); } printWriter.println(); } private static Comparator<PortProtoId> PORTS_BY_EXTERNAL_ID = new Comparator<PortProtoId>() { public int compare(PortProtoId pp1, PortProtoId pp2) { return TextUtils.STRING_NUMBER_ORDER.compare(pp1.externalId, pp2.externalId); } }; /** * Method to write the variables on an object. */ private void printVars(String portName, ImmutableElectricObject d) { // write the variables for(Iterator<Variable> it = d.getVariables(); it.hasNext(); ) { Variable var = it.next(); printVar(portName, var); } } /** * Method to write the variable on an object. */ private void printVar(String portName, Variable var) { // write the variables Object varObj = var.getObject(); TextDescriptor td = var.getTextDescriptor(); boolean isParam = td.isParam(); String tdString = describeDescriptor(var, td, isParam); printWriter.print("|" + convertVariableName(diskName(portName, var)) + "(" + tdString + ")"); String pt = makeString(varObj); if (pt == null) pt = ""; printWriter.print(pt);} /** * Method to write the project settings on an object. */ private void printlnSettings(Collection<Setting> settings) { for (Setting setting : settings) { Object value = setting.getValue(); projectSettings.put(setting, value); printWriter.print("|" + convertVariableName(setting.getPrefName()) + "()" + makeString(value)); } printWriter.println(); } /** * Method to convert variable "var" to a string for printing in the text file. * returns zero on error */ private String makeString(Object obj) { StringBuffer infstr = new StringBuffer(); char type = getVarType(obj); infstr.append(type); if (obj instanceof Object[]) { Object [] objArray = (Object [])obj; int len = objArray.length; infstr.append('['); for(int i=0; i<len; i++) { Object oneObj = objArray[i]; if (i != 0) infstr.append(','); makeStringVar(infstr, type, oneObj, true); } infstr.append(']'); } else { makeStringVar(infstr, type, obj, false); } return infstr.toString(); } /** * Method to make a string from the value in "addr" which has a type in * "type". */ private void makeStringVar(StringBuffer infstr, char type, Object obj, boolean inArray) { if (obj == null) return; switch (type) { case 'B': infstr.append(((Boolean)obj).booleanValue() ? 'T' : 'F'); return; case 'C': infstr.append(convertString(((CellId)obj).toString(), inArray)); return; case 'D': infstr.append(((Double)obj).doubleValue()); return; case 'E': infstr.append(convertString(((ExportId)obj).toString(), inArray)); return; case 'F': infstr.append(((Float)obj).floatValue()); return; case 'G': infstr.append(((Long)obj).longValue()); return; case 'H': infstr.append(((Short)obj).shortValue()); return; case 'I': infstr.append(((Integer)obj).intValue()); return; case 'L': infstr.append(convertString(((LibId)obj).libName, inArray)); return; case 'O': infstr.append(convertString(((Tool)obj).getName(), inArray)); return; case 'P': infstr.append(convertString(((PrimitiveNodeId)obj).fullName, inArray)); return; case 'R': infstr.append(convertString(((ArcProtoId)obj).fullName, inArray)); return; case 'S': infstr.append(convertString(obj.toString(), inArray)); return; case 'T': infstr.append(convertString(((TechId)obj).techName, inArray)); return; case 'V': { EPoint pt2 = (EPoint)obj; infstr.append(TextUtils.formatDouble(pt2.getX(), 0) + "/" + TextUtils.formatDouble(pt2.getY(), 0)); return; } case 'Y': infstr.append(((Byte)obj).byteValue()); return; } } private String getPortName(PortProtoId portId) { String externalId = portId.externalId; if (externalId.length() > 0) externalId = convertString(externalId); return externalId; } /** * Method to make a char from the value in "addr" which has a type in * "type". */ private char getVarType(Object obj) { if (obj instanceof String || obj instanceof String []) return 'S'; if (obj instanceof CodeExpression) return 'S'; if (obj instanceof Boolean || obj instanceof Boolean []) return 'B'; if (obj instanceof CellId || obj instanceof CellId []) return 'C'; if (obj instanceof Double || obj instanceof Double []) return 'D'; if (obj instanceof ExportId || obj instanceof ExportId []) return 'E'; if (obj instanceof Float || obj instanceof Float []) return 'F'; if (obj instanceof Long || obj instanceof Long []) return 'G'; if (obj instanceof Short || obj instanceof Short []) return 'H'; if (obj instanceof Integer || obj instanceof Integer []) return 'I'; if (obj instanceof LibId || obj instanceof LibId []) return 'L'; if (obj instanceof Tool || obj instanceof Tool []) return 'O'; if (obj instanceof PrimitiveNodeId || obj instanceof PrimitiveNodeId []) return 'P'; if (obj instanceof ArcProtoId || obj instanceof ArcProtoId []) return 'R'; if (obj instanceof TechId || obj instanceof TechId []) return 'T'; if (obj instanceof EPoint || obj instanceof EPoint []) return 'V'; if (obj instanceof Byte || obj instanceof Byte []) return 'Y'; throw new AssertionError(); } /** * Method convert a string that is going to be quoted. * Inserts the quote character (^) before any quotation character (') or quote character (^) in the string. * Converts newlines to "^\n" (makeing the "\" and "n" separate characters). * @param str the string to convert. * @return the string with the appropriate quote characters. * If no conversion is necessary, the input string is returned. */ private static String convertQuotedString(String str) { StringBuffer infstr = new StringBuffer(); int len = str.length(); for(int i=0; i<len; i++) { char ch = str.charAt(i); if (ch == '\n') { infstr.append("\\n"); continue; } if (ch == '\r') { infstr.append("\\r"); continue; } if (ch == '"' || ch == '\\') infstr.append('\\'); infstr.append(ch); } return infstr.toString(); } /** * Method convert a string that is not going to be quoted. * Inserts a quote character (^) before any separator (|), quotation character (") or quote character (^) in the string. * Converts newlines to spaces. * @param str the string to convert. * @return the string with the appropriate quote characters. * If no conversion is necessary, the input string is returned. */ static String convertString(String str) { return convertString(str, (char)0, (char)0); } /** * Method convert a string that is not going to be quoted. * Inserts a quote character (^) before any separator (|), quotation character (") or quote character (^) in the string. * Converts newlines to spaces. * @param str the string to convert. * @return the string with the appropriate quote characters. * If no conversion is necessary, the input string is returned. */ private static String convertString(String str, char delim1, char delim2) { if (str.length() != 0 && str.indexOf('\n') < 0 && str.indexOf('\r') < 0 && str.indexOf('\\') < 0 && str.indexOf('"') < 0 && str.indexOf('|') < 0 && (delim1 == 0 || str.indexOf(delim1) < 0) && (delim2 == 0 || str.indexOf(delim2) < 0)) return str; return '"' + convertQuotedString(str) + '"'; } /** * Method convert a string that is a variable name. * If string contains end-of-lines, backslashes, bars, quotation characters, open parenthesis, * encloses string in quotational characters. * @param str the string to convert. * @return the string with the appropriate quote characters. * If no conversion is necessary, the input string is returned. */ private String convertVariableName(String str) { return convertString(str, '(', (char)0); } /** * Method convert a string that is a variable value. * If string contains end-of-lines, backslashes, bars, quotation characters, comma, * close bracket, returns string enclosed in quotational characters. * @param str the string to convert. * @param inArray true if string is element of array/ * @return the string with the appropriate quote characters. * If no conversion is necessary, the input string is returned. */ private String convertString(String str, boolean inArray) { return inArray ? convertString(str, ',', ']') : convertString(str, (char)0, (char)0); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -