Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/* -*- tab-width: 4 -*-
*
* Electric(tm) VLSI Design System
*
* File: TextUtils.java
*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
*
* Electric(tm) is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Electric(tm) is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Electric(tm); see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, Mass 02111-1307, USA.
*/
package com.sun.electric.database.text;
import com.sun.electric.database.hierarchy.Cell;
import com.sun.electric.database.hierarchy.View;
import com.sun.electric.database.network.Network;
import com.sun.electric.database.topology.Connection;
import com.sun.electric.database.variable.TextDescriptor;
import com.sun.electric.technology.Technology;
import com.sun.electric.tool.Client;
import com.sun.electric.tool.Job;
import com.sun.electric.tool.lang.EvalJavaBsh;
import com.sun.electric.tool.user.User;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLDecoder;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TimeZone;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
/**
* This class is a collection of text utilities.
*/
public class TextUtils extends com.sun.electric.util.TextUtils {
/**
* Method to parse the floating-point number in a string, assuming that it is a distance value in the current technology.
* @param text the string to convert to a double.
* @param tech the technology to use for the conversion.
* If it is not a layout technology, then use pure numbers.
* @return the numeric value in internal database units.
*/
public static double atofDistance(String text, Technology tech) {
if (tech != null && tech.isLayout()) {
return atof(text, null, TextDescriptor.Unit.DISTANCE, tech);
}
return atof(text);
}
/**
* Method to parse the floating-point number in a string, assuming that it is a distance value in the current technology.
* @param text the string to convert to a double.
* @return the numeric value in internal database units.
*/
public static double atofDistance(String text) {
return atof(text, null, TextDescriptor.Unit.DISTANCE, Technology.getCurrent());
}
/**
* Method to parse the floating-point number in a string, using a default value if no number can be determined,
* and presuming a type of unit.
* @param text the string to convert to a double.
* @param defaultVal the value to return if the string cannot be converted to a double.
* If 'defaultVal' is null and the text cannot be converted to a number, the method returns 0.
* @param unitType the type of unit being examined (handles postfix characters).
* @return the numeric value.
*/
public static double atof(String text, Double defaultVal, TextDescriptor.Unit unitType, Technology tech) {
if (unitType != null) {
// strip off postfix characters if present
String pf = unitType.getPostfixChar();
if (text.endsWith(pf)) {
text = text.substring(0, text.length() - pf.length());
}
}
if (unitType == TextDescriptor.Unit.DISTANCE) {
UnitScale us = User.getDistanceUnits();
if (us != null) {
// remove commas that denote 1000's separators
text = text.replaceAll(",", "");
double v = 0;
try {
v = parsePostFixNumber(text, us).doubleValue();
} catch (NumberFormatException ex) {
v = atof(text, defaultVal);
}
return v / Technology.getCurrent().getScale() / UnitScale.NANO.getMultiplier().doubleValue();
}
}
return atof(text, defaultVal);
}
/**
* Method to get the numeric value of a string that may be an expression.
* @param expression the string that may be an expression.
* @return the numeric value of the expression.
* This method uses the Bean Shell to evaluate non-numeric strings.
*/
public static double getValueOfExpression(String expression) {
if (isANumber(expression)) {
double res = atof(expression);
return res;
}
Object o = EvalJavaBsh.evalJavaBsh.doEvalLine(expression);
if (o == null) {
return 0;
}
if (o instanceof Double) {
return ((Double) o).doubleValue();
}
if (o instanceof Integer) {
return ((Integer) o).intValue();
}
return 0;
}
/**
* Method to convert a distance to a string, using scale from the current technology if necessary.
* If the value has no precision past the decimal, none will be shown.
* If the units are not scalable, then appropriate values will be shown
* @param v the distance value to format.
* @return the string representation of the number.
*/
public static String formatDistance(double v, Technology tech) {
if (tech != null && tech.isLayout()) {
return displayedUnits(v, TextDescriptor.Unit.DISTANCE, User.getDistanceUnits(), tech);
}
return formatDouble(v);
}
/**
* Method to convert a distance to a string, using scale from the current technology if necessary.
* If the value has no precision past the decimal, none will be shown.
* If the units are not scalable, then appropriate values will be shown
* @param v the distance value to format.
* @return the string representation of the number.
*/
public static String formatDistance(double v) {
return displayedUnits(v, TextDescriptor.Unit.DISTANCE, User.getDistanceUnits(), Technology.getCurrent());
}
/**
* Method to convert a database coordinate into real spacing.
* @param value the database coordinate to convert.
* @param tech the technology to use for conversion (provides a real scaling).
* @param unitScale the type of unit desired.
* @return the database coordinate in the desired units.
* For example, if the given technology has a scale of 200 nanometers per unit,
* and the value 7 is given, then that is 1.4 microns (1400 nanometers).
* If the desired units are UnitScale.MICRO, then the returned value will be 1.4.
*/
public static double convertDistance(double value, Technology tech, UnitScale unitScale) {
double scale = tech.getScale();
double distanceScale = 0.000000001 / unitScale.getMultiplier().doubleValue() * scale;
return value * distanceScale;
}
/**
* Method to convert real spacing into a database coordinate.
* @param value the real distance to convert.
* @param tech the technology to use for conversion (provides a real scaling).
* @param unitScale the type of unit desired.
* @return the real spacing in the database units.
* For example, if the given technology has a scale of 200 nanometers per unit,
* and the value 1.6 is given with the scale UnitScale.MICRO, then that is 1.6 microns (1600 nanometers).
* Since the technology has 200 nanometers per unit, this converts to 8 units.
*/
public static double convertFromDistance(double value, Technology tech, UnitScale unitScale) {
double scale = tech.getScale();
double distanceScale = 0.000000001 / unitScale.getMultiplier().doubleValue() * scale;
return value / distanceScale;
}
/**
* Method to express "value" as a string in "unittype" electrical units.
* The scale of the units is in "unitscale".
*/
private static String displayedUnits(double value, TextDescriptor.Unit unitType, UnitScale unitScale, Technology tech) {
if (unitType == TextDescriptor.Unit.DISTANCE && unitScale != null) {
value *= UnitScale.NANO.getMultiplier().doubleValue() * tech.getScale();
}
String postFix = "";
if (unitScale != null) {
value /= unitScale.getMultiplier().doubleValue();
postFix = unitScale.getPostFix() + unitType.getPostfixChar();
}
return formatDouble(value) + postFix;
}
/**
* Method to convert a floating point value to a string, given that it is a particular type of unit.
* Each unit has a default scale. For example, if Capacitance value 0.0000012 is being converted, and
* Capacitance is currently using microFarads, then the result will be "1.2m".
* If, however, capacitance is currently using milliFarads, the result will be 0.0012u".
* @param value the floating point value.
* @param units the type of unit.
* @return a string describing that value in the current unit.
*/
public static String makeUnits(double value, TextDescriptor.Unit units) {
if (units == TextDescriptor.Unit.NONE) {
return formatDouble(value);
}
if (units == TextDescriptor.Unit.DISTANCE) {
return displayedUnits(value, units, User.getDistanceUnits(), Technology.getCurrent());
}
// if (units == TextDescriptor.Unit.RESISTANCE)
// return displayedUnits(value, units, User.getResistanceUnits());
// if (units == TextDescriptor.Unit.CAPACITANCE)
// return displayedUnits(value, units, User.getCapacitanceUnits());
// if (units == TextDescriptor.Unit.INDUCTANCE)
// return displayedUnits(value, units, User.getInductanceUnits());
// if (units == TextDescriptor.Unit.CURRENT)
// return displayedUnits(value, units, User.getAmperageUnits());
// if (units == TextDescriptor.Unit.VOLTAGE)
// return displayedUnits(value, units, User.getVoltageUnits());
// if (units == TextDescriptor.Unit.TIME)
// return displayedUnits(value, units, User.getTimeUnits());
return (formatDoublePostFix(value));
}
/****************************** FOR SORTING OBJECTS ******************************/
/**
* Comparator class for sorting Objects by their string name.
*/
public static class ObjectsByToString implements Comparator