org.jcpsim.util
Class util

java.lang.Object
  extended by org.jcpsim.util.util

public final class util
extends java.lang.Object

Various utility routines


Nested Class Summary
static class util.H
           
static class util.V
           
 
Method Summary
static void centerFrame(javax.swing.JFrame frame, double ratio)
           
static java.lang.String chars(char c, int n)
           
 int clipToByte(int x)
           
static int dpPosition(double x)
          Position of the decimal point.
static java.lang.String fnum(double x, int integer, int fraction)
           
static java.lang.String format(double value, double min, double max, double step)
           
static double fraction(double x)
           
static int fractionNeeded(double x)
          TODO: This is not very elegant.
static java.awt.Color gamma(java.awt.Color c, double gamma)
          Gamma filter for colors.
static java.lang.String getClassName(java.lang.Object o)
           
static java.lang.String getExtension(java.io.File f)
          Returns the (lowercase) extension of the name of the file.
static java.net.URL[] getJarURLs(java.lang.String directory)
           
static org.w3c.dom.Document getNewDocument()
           
static org.w3c.dom.Document getXmlDocument(java.io.File file)
           
static org.w3c.dom.Document getXmlDocument(java.io.InputStream is)
           
static java.lang.String I18N(java.util.ResourceBundle rb, java.lang.String s)
          Fetches a string from a ResourceBundle.
static java.lang.String[] I18Ns(java.util.ResourceBundle rb, java.lang.String s)
          Fetches a string array from a ResourceBundle.
static int integerNeeded(double x)
          Calculates the number digits before the decimal point (including the minus sign).
static double log10(double x)
           
static java.lang.String lpos(int n, java.lang.String s)
           
static void paintButtonBg(java.awt.Graphics2D g2, double w, double h, java.awt.Color c)
           
static void paintButtonBg(java.awt.Graphics2D g2, double w, double h, double m, java.awt.Color c)
           
static void paintButtonBg(java.awt.Graphics2D g2, double wd, double hd, double md, java.awt.Color c, java.awt.Color c1, java.awt.Color c2)
           
static void paintText(java.awt.Graphics2D g2, java.lang.String s, util.H h, util.V v, double x, double y)
           
static void paintTextCA(java.awt.Graphics2D g2, java.lang.String s, double x, double y)
           
static void paintTextCB(java.awt.Graphics2D g2, java.lang.String s, double x, double y)
           
static void paintTextCC(java.awt.Graphics2D g2, java.lang.String s, double x, double y)
           
static void paintTextCD(java.awt.Graphics2D g2, java.lang.String s, double x, double y)
           
static void paintTextLA(java.awt.Graphics2D g2, java.lang.String s, double x, double y)
           
static void paintTextLB(java.awt.Graphics2D g2, java.lang.String s, double x, double y)
           
static void paintTextLC(java.awt.Graphics2D g2, java.lang.String s, double x, double y)
           
static void paintTextLD(java.awt.Graphics2D g2, java.lang.String s, double x, double y)
           
static void paintTextRA(java.awt.Graphics2D g2, java.lang.String s, double x, double y)
           
static void paintTextRB(java.awt.Graphics2D g2, java.lang.String s, double x, double y)
           
static void paintTextRC(java.awt.Graphics2D g2, java.lang.String s, double x, double y)
           
static void paintTextRD(java.awt.Graphics2D g2, java.lang.String s, double x, double y)
           
static void printResourceBundle(java.util.ResourceBundle rb)
          Outputs all elements of a ResourceBundle.
static double quadEquationBigger(double a, double b, double c)
          Returns the bigger result of a quadratic equation (ax2 + bx + c = 0).
static double quadEquationSmaller(double a, double b, double c)
          Returns the smaller result of a quadratic equation (ax2 + bx + c = 0).
static java.lang.String rpos(int n, java.lang.String s)
           
static int sign(double x)
           
 int toRGB(double r, double g, double b)
           
static java.awt.Color withAlpha(java.awt.Color c, int alpha)
           
static void writeXmlFile(org.w3c.dom.Document document, java.io.File file, boolean indent)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

gamma

public static java.awt.Color gamma(java.awt.Color c,
                                   double gamma)
Gamma filter for colors. A gamma of 0.0 turns the color into white. With 1.0 there is no change. Positive infinity is black. Has no effect when one color component is 1.0 !!!

Parameters:
c - the color to be changed
gamma - the gamma factor
Returns:
the changed color

withAlpha

public static java.awt.Color withAlpha(java.awt.Color c,
                                       int alpha)

I18N

public static java.lang.String I18N(java.util.ResourceBundle rb,
                                    java.lang.String s)
Fetches a string from a ResourceBundle.


I18Ns

public static java.lang.String[] I18Ns(java.util.ResourceBundle rb,
                                       java.lang.String s)
Fetches a string array from a ResourceBundle.


printResourceBundle

public static void printResourceBundle(java.util.ResourceBundle rb)
Outputs all elements of a ResourceBundle. TODO: Sort for key; TODO: Justify output.


quadEquationBigger

public static double quadEquationBigger(double a,
                                        double b,
                                        double c)
Returns the bigger result of a quadratic equation (ax2 + bx + c = 0).


quadEquationSmaller

public static double quadEquationSmaller(double a,
                                         double b,
                                         double c)
Returns the smaller result of a quadratic equation (ax2 + bx + c = 0).


sign

public static int sign(double x)

paintButtonBg

public static void paintButtonBg(java.awt.Graphics2D g2,
                                 double w,
                                 double h,
                                 java.awt.Color c)

paintButtonBg

public static void paintButtonBg(java.awt.Graphics2D g2,
                                 double w,
                                 double h,
                                 double m,
                                 java.awt.Color c)

paintButtonBg

public static void paintButtonBg(java.awt.Graphics2D g2,
                                 double wd,
                                 double hd,
                                 double md,
                                 java.awt.Color c,
                                 java.awt.Color c1,
                                 java.awt.Color c2)

paintText

public static void paintText(java.awt.Graphics2D g2,
                             java.lang.String s,
                             util.H h,
                             util.V v,
                             double x,
                             double y)

paintTextLB

public static void paintTextLB(java.awt.Graphics2D g2,
                               java.lang.String s,
                               double x,
                               double y)

paintTextCB

public static void paintTextCB(java.awt.Graphics2D g2,
                               java.lang.String s,
                               double x,
                               double y)

paintTextRB

public static void paintTextRB(java.awt.Graphics2D g2,
                               java.lang.String s,
                               double x,
                               double y)

paintTextLA

public static void paintTextLA(java.awt.Graphics2D g2,
                               java.lang.String s,
                               double x,
                               double y)

paintTextCA

public static void paintTextCA(java.awt.Graphics2D g2,
                               java.lang.String s,
                               double x,
                               double y)

paintTextRA

public static void paintTextRA(java.awt.Graphics2D g2,
                               java.lang.String s,
                               double x,
                               double y)

paintTextLC

public static void paintTextLC(java.awt.Graphics2D g2,
                               java.lang.String s,
                               double x,
                               double y)

paintTextCC

public static void paintTextCC(java.awt.Graphics2D g2,
                               java.lang.String s,
                               double x,
                               double y)

paintTextRC

public static void paintTextRC(java.awt.Graphics2D g2,
                               java.lang.String s,
                               double x,
                               double y)

paintTextLD

public static void paintTextLD(java.awt.Graphics2D g2,
                               java.lang.String s,
                               double x,
                               double y)

paintTextCD

public static void paintTextCD(java.awt.Graphics2D g2,
                               java.lang.String s,
                               double x,
                               double y)

paintTextRD

public static void paintTextRD(java.awt.Graphics2D g2,
                               java.lang.String s,
                               double x,
                               double y)

chars

public static java.lang.String chars(char c,
                                     int n)

lpos

public static java.lang.String lpos(int n,
                                    java.lang.String s)

rpos

public static java.lang.String rpos(int n,
                                    java.lang.String s)

getClassName

public static java.lang.String getClassName(java.lang.Object o)

log10

public static double log10(double x)

fraction

public static double fraction(double x)

dpPosition

public static int dpPosition(double x)
Position of the decimal point.
Negative values are treated just like positive ones.
Zero (0.0) is handeled different!

Parameters:
x - The value to check.
Returns:
  • if >0 : the number of digits before the point (123 --> 3)
  • if 0 : values (< 1.0 and >= 0.1) or (> -1.0 and <= -0.1)
  • if &li;0 : the negative number of zeros after the point (0.0012 --> -2)

integerNeeded

public static int integerNeeded(double x)
Calculates the number digits before the decimal point (including the minus sign).


fractionNeeded

public static int fractionNeeded(double x)
TODO: This is not very elegant.


fnum

public static java.lang.String fnum(double x,
                                    int integer,
                                    int fraction)
Parameters:
x -
integer -
fraction -
Returns:
The formatted number. TODO: No leading zeroes. TODO: Minus sign counts as part of integer. TODO: Test it. TODO: Parameter boolean fill (leading spaces). TODO: Parameter int align.

format

public static java.lang.String format(double value,
                                      double min,
                                      double max,
                                      double step)

clipToByte

public int clipToByte(int x)

toRGB

public int toRGB(double r,
                 double g,
                 double b)

getXmlDocument

public static org.w3c.dom.Document getXmlDocument(java.io.File file)

getXmlDocument

public static org.w3c.dom.Document getXmlDocument(java.io.InputStream is)

getNewDocument

public static org.w3c.dom.Document getNewDocument()

writeXmlFile

public static void writeXmlFile(org.w3c.dom.Document document,
                                java.io.File file,
                                boolean indent)

getExtension

public static java.lang.String getExtension(java.io.File f)
Returns the (lowercase) extension of the name of the file.


getJarURLs

public static java.net.URL[] getJarURLs(java.lang.String directory)

centerFrame

public static void centerFrame(javax.swing.JFrame frame,
                               double ratio)
Parameters:
frame - the frame that schall be resized and centered on the screen
ratio - 0.5: half width and half height of screen


jCpSim (Java CardioPulmonary SIMulations), v0.2.01
Dr. Frank Fischer, frank@jcpsim.org, http://www.jcpsim.org