trex
Class TRexUtil

java.lang.Object
  |
  +--trex.TRexUtil

public class TRexUtil
extends Object

This class provides a couple of helper functions commonly used in TRex (and maybe others... ;) Methods are static and can be called from outside without instantiating TRexUtil.

Version:
$Revision: 1.17 $
Author:
Bastian Friedrich <bastian@bastian-friedrich.de>

Constructor Summary
TRexUtil()
           
 
Method Summary
static int bytesToInt(byte[] in)
          generate an integer from a byte array with 4 elements
static String bytesToString(byte[] in)
          print a byte array as a comma seperated string
static byte[] concatByteArrays(byte[] in1, byte[] in2)
          concatenate two byte arrays.
static byte getBit(byte[] in, int pos)
          Return a bit (0 || 1) from a byte array indexed as pos.
static BufferedImage iitobi(ImageIcon ii, Frame parent)
          create a BufferedImage from an ImageIcon
static String intsToString(int[] in)
          print a int array as a comma seperated string
static byte[] intToBytes(int in)
          Convert an integer to an array of 4 bytes.
static Component makeImagePanel(ImageIcon img)
          Creates a JPanel only containing an ImageIcon.
static Component makeImagePanel(String filename)
          Creates a JPanel only containing an ImageIcon read from a file.
static Component makePanel(ImageIcon img, String text)
          Construct a panel displaying an ImageIcon (if available) or a text (as a fallback).
static Component makePanel(String filename, String text)
          Construct a panel displaying an ImageIcon (if available) or a text (as a fallback).
static JPanel makeTextPanel(String text)
          Creates a JPanel only containing a text label.
static int maxArray(int[] array)
          Find largest value in an array.
static void printDebug(String x)
           
static void setBit(byte[] in, int pos, int value)
          Set a bit in a byte array.
static BufferedImage simpleAddImages(Frame parent, ImageIcon img1, ImageIcon img2)
          This method adds two images and returns their "OR" picture.
static BufferedImage simpleAddImages(Frame parent, Image img1, Image img2, int w, int h)
          This method adds two images by returning their "OR" picture.
static byte[] subArray(byte[] in, int start, int len)
          return a part of an array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TRexUtil

public TRexUtil()
Method Detail

makeTextPanel

public static JPanel makeTextPanel(String text)
Creates a JPanel only containing a text label.

Parameters:
text - Text to display in panel's label.
Returns:
Panel containing text.

makeImagePanel

public static Component makeImagePanel(ImageIcon img)
Creates a JPanel only containing an ImageIcon.

Parameters:
img - Icon to display.
Returns:
Panel containing an ImageIcon.

makeImagePanel

public static Component makeImagePanel(String filename)
Creates a JPanel only containing an ImageIcon read from a file.

Parameters:
filename - File containing the image.
Returns:
Panel containin an ImageIcon.

makePanel

public static Component makePanel(ImageIcon img,
                                  String text)
Construct a panel displaying an ImageIcon (if available) or a text (as a fallback).

Parameters:
img - Image to display, or null
text - Text to display if img is null
Returns:
Panel containing either an ImageIcon or a text

makePanel

public static Component makePanel(String filename,
                                  String text)
Construct a panel displaying an ImageIcon (if available) or a text (as a fallback).

Parameters:
filename - File containing image to display, or null
text - Text to display if filename is null
Returns:
Panel containing either an ImageIcon or a text

getBit

public static byte getBit(byte[] in,
                          int pos)
Return a bit (0 || 1) from a byte array indexed as pos.

Parameters:
in - byte array to get bit from.
pos - bit number.
Returns:
A bit

setBit

public static void setBit(byte[] in,
                          int pos,
                          int value)
Set a bit in a byte array. In fact, this _could_ set more than only one bit at a time - but behaviour is unknown, so set value _only_ to 0 or 1.

Parameters:
in - byte array to set bit in
pos - bit number in array
value - value to set (0 || 1)

intToBytes

public static byte[] intToBytes(int in)
Convert an integer to an array of 4 bytes.

Parameters:
in - integer to transform.
Returns:
the byte array.

bytesToInt

public static int bytesToInt(byte[] in)
generate an integer from a byte array with 4 elements

Parameters:
in - Input byte array.
Returns:
int value consisting of input.

concatByteArrays

public static byte[] concatByteArrays(byte[] in1,
                                      byte[] in2)
concatenate two byte arrays.

Parameters:
in1 - First input array.
in2 - Latter input array.
Returns:
concatenated byte array.

subArray

public static byte[] subArray(byte[] in,
                              int start,
                              int len)
return a part of an array.

Parameters:
in - Byte array.
start - First element to return.
len - Number of elements to return.
Returns:
Byte array with desired elements.

bytesToString

public static String bytesToString(byte[] in)
print a byte array as a comma seperated string

Parameters:
in - Byte array.
Returns:
String representation of array.

intsToString

public static String intsToString(int[] in)
print a int array as a comma seperated string

Parameters:
in - Int array.
Returns:
String representation of array.

maxArray

public static int maxArray(int[] array)
Find largest value in an array.


iitobi

public static BufferedImage iitobi(ImageIcon ii,
                                   Frame parent)
create a BufferedImage from an ImageIcon

Parameters:
ii - An ImageIcon to transform
parent - A Frame to display error messages in
Returns:
Buffered image with same contents

simpleAddImages

public static BufferedImage simpleAddImages(Frame parent,
                                            Image img1,
                                            Image img2,
                                            int w,
                                            int h)
This method adds two images by returning their "OR" picture. This can be used to construct a picture consisting of two channels from original pics.

Parameters:
parent - Parent window.
img1 - First image.
img2 - Second image.
w - Picture's width.
h - Picutre's height.

simpleAddImages

public static BufferedImage simpleAddImages(Frame parent,
                                            ImageIcon img1,
                                            ImageIcon img2)
This method adds two images and returns their "OR" picture. This can be used to construct a picture consisting of two channels from original pics.

Parameters:
parent - Parent window.
img1 - First image.
img2 - Second image.

printDebug

public static void printDebug(String x)