net.sf.magicproject.tools
Class MToolKit

java.lang.Object
  extended by net.sf.magicproject.tools.MToolKit

public final class MToolKit
extends java.lang.Object

MToolKit.java Created on 18 d�c. 2003

Since:
0.53, 0.54 added "save..." methods
Author:
Fabrice Daugan, brius

Field Summary
static java.lang.String CHARSET
          The default charset used by this application.
static java.awt.Font defaultFont
          Represents the default font
static javax.swing.JFileChooser fileChooser
          represents the file chooser
static java.lang.String mdbFile
          Represents the MDB file corresponding to the current TBS name.
static java.util.Random random
          The current random sequence.
static java.lang.String tbsName
          Represents the default mdb name.
static XmlDeckTranslator translator
          The translator tranforming a card name into a file-serializable value.
 
Method Summary
static void addOverlay(javax.swing.JComponent superPanel)
          Specifies that a component should have overlay functionality.
static javax.swing.LookAndFeel geLookAndFeel(java.lang.String laf)
          Return the L&F instance from the givent name.
static java.awt.Point getAbsoluteLocation(javax.swing.JComponent component)
          Return absolute location of given component.
static int getConstant(int idToken)
           
static java.lang.String getDeckFile()
          Return the deck file choosen with an "open" dialog.
static java.lang.String getDeckFile(int type)
          Return the deck file choosen
static java.lang.String getDeckFile(javax.swing.JFrame parent, int type)
          Return the deck file choosen
static java.lang.String getExactKeyName(java.lang.String cardName)
          Return the specified card name without any special char.
static java.io.File getFile(java.lang.String fileName)
          Return the File associated to the given fileName.
static java.lang.String getHtmlMana(int idColor, int amount)
          Return the mana picture specific to the current TBS
static java.net.URLConnection getHttpConnection(java.net.URL url)
          Create, and return the connection etablished with a http server.
static java.lang.String getIconPath(java.lang.String fileName)
          Returns the absolute path of an icon used for the UI.
static java.lang.String getKeyName(java.lang.String cardName)
          Return the specified card name without any special char.
static java.awt.Image getLocalPicture(java.lang.String localFile)
          Return the loaded picture from a local place.
static java.lang.String getLogCardInfo(MCard card)
          Return logging info of the given card.
static java.lang.String getMdbFile(java.lang.String oldFile, javax.swing.JFrame parent)
          Open a DialogFile dialog and return the choosen mdb file.
static java.lang.String getPictureFile(java.lang.String oldFile, javax.swing.JFrame parent)
          return the picture file choosen
static int getRandom()
          Return 0 or 1 at random way
static int getRandom(int length)
          Return a number [0,length[ at random way
static java.lang.String getRelativePath()
          Return the canonical path of working directory.
static java.lang.String getRelativePath(java.lang.String canonicalPath)
          Returns the given path with '\' char replaced by '/' char.
static java.net.URL getResource(java.lang.String resource, boolean mustExist)
          Return the URL associated to the given resource.
static java.io.InputStream getResourceAsStream(java.lang.String resource)
          Return the stream associated to the given resource.
static java.lang.String getShortDeckFile(java.lang.String deckFile)
          Return the given deck file without the current path off application.
static java.util.Properties getSmtpProperties()
          Create, and return the connection etablished with a http server.
static java.lang.String getSoundFile(java.lang.String soundFile)
          Return the sound specific to the current TBS
static javax.swing.ImageIcon getTbsBigManaPicture(int idColor)
          Return the mana picture specific to the current TBS
static java.lang.String getTbsFile(java.lang.String file)
          Return the file specific to the current TBS
static java.lang.String getTbsFile(java.lang.String file, boolean mustExist)
          Return the file specific to the current TBS
static java.lang.String getTbsHtmlPicture(java.lang.String pictureFile)
          Return the picture specific to the current TBS
static java.lang.String getTbsPicture(java.lang.String pictureFile)
          Return the picture specific to the current TBS
static java.lang.String getTbsPicture(java.lang.String pictureFile, boolean mustExist)
          Return the picture specific to the current TBS
static boolean isAvailableLookAndFeel(java.lang.String laf)
          An utility function that layers on top of the LookAndFeel's isSupportedLookAndFeel() method.
static void loadClip(java.lang.String soundFile)
          loadClip loads the sound-file into a clip.
static int manaPool(int[] registers)
          Sum the mana.
static int parseInt(java.lang.String s)
          Parses the string argument as a signed integer in the radix specified by the second argument.
static byte[] readByteArray(java.io.InputStream inputStream)
          Read a byte array 256*256*256 bytes maximum sized from the given stream.
static java.awt.Image readImage(java.io.InputStream inputStream)
          Read an image from the given stream.
static javax.swing.ImageIcon readImageIcon(java.io.InputStream inputStream)
          Read an icon from the given stream.
static int readInt16(java.io.InputStream inputFile)
          Read the next 2 bytes from the specified input stream and return the integer value coded with 32bits
static int readInt24(java.io.InputStream inputFile)
          Read the next 3 bytes from the specified input stream and return the integer value coded with 48bits
static java.lang.String readString(java.io.InputStream inputStream)
          read a string from inputStream ending with \0.
static java.lang.String readText(java.io.InputStream inputStream)
          read a string from inputFile The strings read end with \0 with no limit of size
static java.lang.String replaceAll(java.lang.String data, java.lang.String from, java.lang.String to)
          Replace occurrences into a string.
static java.lang.String replaceWhiteSpaces(java.lang.String string)
          Return the specfied string without any local white spaces.
static java.io.File showDialogFile(java.lang.String titreBoite, java.lang.String etiquetteBouton, java.lang.String infoBulle, char raccourciBouton, java.io.File fichier, FileFilterPlus fileFilter, javax.swing.JFrame parent, int type, int mode)
          Disp a file dialog with many options
static void writeFile(java.io.File src, java.io.OutputStream out)
          Copy the src file throw the output stream.
static void writeInt16(java.io.OutputStream out, int int16)
          Write the specified positive short coded on 2 bytes to the specified input stream
static void writeInt24(java.io.OutputStream out, int int24)
          Write the specified positive int coded on 3 bytes to the specified input stream
static void writeString(java.io.OutputStream out, java.lang.String string)
          write a string to output stream ending with \0.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHARSET

public static final java.lang.String CHARSET
The default charset used by this application.


defaultFont

public static java.awt.Font defaultFont
Represents the default font


mdbFile

public static java.lang.String mdbFile
Represents the MDB file corresponding to the current TBS name. Is null if no TBS is currently defined.


tbsName

public static java.lang.String tbsName
Represents the default mdb name. This is not the full name of selected TBS.


fileChooser

public static javax.swing.JFileChooser fileChooser
represents the file chooser


random

public static java.util.Random random
The current random sequence. May be initialized at the beginning of each play.


translator

public static XmlDeckTranslator translator
The translator tranforming a card name into a file-serializable value. Is null while not used.

Method Detail

replaceAll

public static java.lang.String replaceAll(java.lang.String data,
                                          java.lang.String from,
                                          java.lang.String to)
Replace occurrences into a string.

Parameters:
data - the string to replace occurrences into
from - the occurrence to replace.
to - the occurrence to be used as a replacement.
Returns:
the new string with replaced occurrences.

getConstant

public static int getConstant(int idToken)
Parameters:
idToken - the value to translate.
Returns:
the real value of the specified value. If the value is a constant the returned value can be positive or negative.

readString

public static java.lang.String readString(java.io.InputStream inputStream)
                                   throws java.io.IOException
read a string from inputStream ending with \0. The mximum size of this string is 200 chars.

Parameters:
inputStream - is the input stream
Returns:
the read string
Throws:
java.io.IOException - If some other I/O error occurs

writeString

public static void writeString(java.io.OutputStream out,
                               java.lang.String string)
write a string to output stream ending with \0.

Parameters:
out - is the input stream
string - the string to write

readText

public static java.lang.String readText(java.io.InputStream inputStream)
read a string from inputFile The strings read end with \0 with no limit of size

Parameters:
inputStream - is the input stream containing content
Returns:
the read string from the specified input stream

readByteArray

public static byte[] readByteArray(java.io.InputStream inputStream)
                            throws java.io.IOException
Read a byte array 256*256*256 bytes maximum sized from the given stream.

Parameters:
inputStream - is the input stream containing content.
Returns:
the byte array.
Throws:
java.io.IOException - If some other I/O error occurs

readImageIcon

public static javax.swing.ImageIcon readImageIcon(java.io.InputStream inputStream)
                                           throws java.io.IOException
Read an icon from the given stream.

Parameters:
inputStream - is the input stream containing content.
Returns:
the read icon.
Throws:
java.io.IOException - If some other I/O error occurs

readImage

public static java.awt.Image readImage(java.io.InputStream inputStream)
                                throws java.io.IOException
Read an image from the given stream.

Parameters:
inputStream - is the input stream containing content.
Returns:
the read image.
Throws:
java.io.IOException - If some other I/O error occurs

getRandom

public static int getRandom()
Return 0 or 1 at random way

Returns:
0 or 1 at random way

getRandom

public static int getRandom(int length)
Return a number [0,length[ at random way

Parameters:
length - maximum+1 value to return.
Returns:
a number [0,length[ at random way

writeFile

public static void writeFile(java.io.File src,
                             java.io.OutputStream out)
                      throws java.io.IOException
Copy the src file throw the output stream.

Parameters:
src - the source file.
out - the output stream.
Throws:
java.io.IOException

getDeckFile

public static java.lang.String getDeckFile()
Return the deck file choosen with an "open" dialog.

Returns:
the file choosen, or the previous one if cancelled.

getDeckFile

public static java.lang.String getDeckFile(int type)
Return the deck file choosen

Parameters:
type - open or save option
Returns:
the file choosen, or the previous one if cancelled.

getDeckFile

public static java.lang.String getDeckFile(javax.swing.JFrame parent,
                                           int type)
Return the deck file choosen

Parameters:
parent - is parent of this dialog
type - open or save option
Returns:
the file choosen, or the previous one if cancelled.

getMdbFile

public static java.lang.String getMdbFile(java.lang.String oldFile,
                                          javax.swing.JFrame parent)
Open a DialogFile dialog and return the choosen mdb file.

Parameters:
oldFile - the old mdb file, will be returned if user cancel operation
parent - is parent of this dialog
Returns:
the file choosen, or oldFile if cancelled

getPictureFile

public static java.lang.String getPictureFile(java.lang.String oldFile,
                                              javax.swing.JFrame parent)
return the picture file choosen

Parameters:
oldFile - the old picture, will be returned if user cancel operation
parent - is parent of this dialog
Returns:
the picture file choosen, or oldFile if cancelled

showDialogFile

public static java.io.File showDialogFile(java.lang.String titreBoite,
                                          java.lang.String etiquetteBouton,
                                          java.lang.String infoBulle,
                                          char raccourciBouton,
                                          java.io.File fichier,
                                          FileFilterPlus fileFilter,
                                          javax.swing.JFrame parent,
                                          int type,
                                          int mode)
Disp a file dialog with many options

Parameters:
titreBoite - title of this dialog box
etiquetteBouton - button "yes"
infoBulle - tooltip
raccourciBouton - shortcut for "yes" button
fichier - old file
fileFilter - file filter to apply
parent - is parent of this dialog
type - the dialog type
mode -
Returns:
the File object correponding to the user's choice
See Also:
JFileChooser.setDialogType(int)

isAvailableLookAndFeel

public static boolean isAvailableLookAndFeel(java.lang.String laf)
An utility function that layers on top of the LookAndFeel's isSupportedLookAndFeel() method. Returns true if the LookAndFeel is supported. Returns false if the LookAndFeel is not supported and/or if there is any kind of error checking if the LookAndFeel is supported. The L&F menu will use this method to detemine whether the various L&F options should be active or inactive.

Parameters:
laf - L1F name
Returns:
true if successfully loaded

geLookAndFeel

public static javax.swing.LookAndFeel geLookAndFeel(java.lang.String laf)
                                             throws java.lang.InstantiationException,
                                                    java.lang.IllegalAccessException,
                                                    java.lang.ClassNotFoundException
Return the L&F instance from the givent name.

Parameters:
laf - the L&F class name
Returns:
the L&F instance
Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.ClassNotFoundException

readInt16

public static int readInt16(java.io.InputStream inputFile)
                     throws java.io.IOException
Read the next 2 bytes from the specified input stream and return the integer value coded with 32bits

Parameters:
inputFile - is the file containing the short (2bytes)to read
Returns:
the read integer built with the 2 next bytes read from the specified input stream
Throws:
java.io.IOException - if error occurred during the reading process from the specified input stream

readInt24

public static int readInt24(java.io.InputStream inputFile)
                     throws java.io.IOException
Read the next 3 bytes from the specified input stream and return the integer value coded with 48bits

Parameters:
inputFile - is the file containing the short (3bytes)to read
Returns:
the read integer built with the 3 next bytes read from the specified input stream
Throws:
java.io.IOException - if error occurred during the reading process from the specified input stream

writeInt16

public static void writeInt16(java.io.OutputStream out,
                              int int16)
Write the specified positive short coded on 2 bytes to the specified input stream

Parameters:
out - is the output stream where the specified integer would be written
int16 - the 2 bytes integer to write

writeInt24

public static void writeInt24(java.io.OutputStream out,
                              int int24)
Write the specified positive int coded on 3 bytes to the specified input stream

Parameters:
out - is the output stream where the specified integer would be written
int24 - the 3 bytes integer to write

getSmtpProperties

public static java.util.Properties getSmtpProperties()
Create, and return the connection etablished with a http server. May use a http proxy if the settings have been set

Returns:
the SMTP properties.

getHttpConnection

public static java.net.URLConnection getHttpConnection(java.net.URL url)
Create, and return the connection etablished with a http server. May use a http proxy if the settings have been set

Parameters:
url - the requested url.
Returns:
Http connection.

getLocalPicture

public static java.awt.Image getLocalPicture(java.lang.String localFile)
                                      throws java.lang.InterruptedException
Return the loaded picture from a local place.

Parameters:
localFile - the local file name.
Returns:
the local picture.
Throws:
java.lang.InterruptedException

getTbsHtmlPicture

public static java.lang.String getTbsHtmlPicture(java.lang.String pictureFile)
Return the picture specific to the current TBS

Parameters:
pictureFile - the path of picture to load. This file must not begin with '/'
Returns:
the picture specific to the current TBS

getTbsPicture

public static java.lang.String getTbsPicture(java.lang.String pictureFile)
Return the picture specific to the current TBS

Parameters:
pictureFile - the path of picture to load. This file must not begin with '/'
Returns:
the picture specific to the current TBS

getTbsPicture

public static java.lang.String getTbsPicture(java.lang.String pictureFile,
                                             boolean mustExist)
Return the picture specific to the current TBS

Parameters:
pictureFile - the path of picture to load. This file must not begin with '/'
mustExist - true if the ressource to search must exists, false either
Returns:
the picture specific to the current TBS

getTbsBigManaPicture

public static javax.swing.ImageIcon getTbsBigManaPicture(int idColor)
Return the mana picture specific to the current TBS

Parameters:
idColor - the color of mana
Returns:
the mana picture specific to the current TBS

getHtmlMana

public static java.lang.String getHtmlMana(int idColor,
                                           int amount)
Return the mana picture specific to the current TBS

Parameters:
idColor - the color of mana
amount - requested amount.
Returns:
the mana picture specific to the current TBS

getTbsFile

public static java.lang.String getTbsFile(java.lang.String file)
Return the file specific to the current TBS

Parameters:
file - the path of file to load. This file must not begin with '/'
Returns:
the picture specific to the current TBS

getTbsFile

public static java.lang.String getTbsFile(java.lang.String file,
                                          boolean mustExist)
Return the file specific to the current TBS

Parameters:
file - the path of file to load. This file must not begin with '/'
mustExist - true if the ressource to search must exists, false either
Returns:
the file specific to the current TBS

getSoundFile

public static java.lang.String getSoundFile(java.lang.String soundFile)
Return the sound specific to the current TBS

Parameters:
soundFile - the path of picture to load. This file must not begin with '/'
Returns:
the sound specific to the current TBS

loadClip

public static void loadClip(java.lang.String soundFile)
loadClip loads the sound-file into a clip.

Parameters:
soundFile - file to be loaded and played.

getAbsoluteLocation

public static java.awt.Point getAbsoluteLocation(javax.swing.JComponent component)
Return absolute location of given component.

Parameters:
component - the component to locate
Returns:
the absolute POINT location of given component.

parseInt

public static int parseInt(java.lang.String s)
Parses the string argument as a signed integer in the radix specified by the second argument. The characters in the string must all be digits of 10 radix (as determined by whether Character.digit(char, int) returns a nonnegative value), except that the first character may be an ASCII minus sign '-' ('\u002D') to indicate a negative value. The resulting integer value is returned.

The Integer#MIN_VALUE value is returned if any of the following situations occurs:

Examples:

parseInt("0") returns 0
parseInt("473") returns 473
parseInt("-0") returns 0
parseInt("2147483647") returns 2147483647
parseInt("-2147483648") returns -2147483648
parseInt("2147483648") returns Integer#MIN_VALUE
parseInt("Kona") returns Integer#MIN_VALUE

Parameters:
s - the String containing the integer representation to be parsed
Returns:
the integer represented by the string argument in the 10 radix. Return Integer.MIN_VALUE when error
See Also:
Integer.MIN_VALUE

getRelativePath

public static java.lang.String getRelativePath()
                                        throws java.io.IOException
Return the canonical path of working directory.

Returns:
the canonical path of working directory.
Throws:
java.io.IOException

getKeyName

public static java.lang.String getKeyName(java.lang.String cardName)
Return the specified card name without any special char. The returned name may be used to build a file. The returned string is in lower case.

Parameters:
cardName - the card name as it is displayed.
Returns:
the specified card name without any special char.

getExactKeyName

public static java.lang.String getExactKeyName(java.lang.String cardName)
Return the specified card name without any special char. The returned name may be used to build a file.

Parameters:
cardName - the card name as it is displayed.
Returns:
the specified card name without any special char.

getRelativePath

public static java.lang.String getRelativePath(java.lang.String canonicalPath)
                                        throws java.io.IOException
Returns the given path with '\' char replaced by '/' char.

Parameters:
canonicalPath -
Returns:
the given path with '\' char replaced by '/' char.
Throws:
java.io.IOException

getLogCardInfo

public static java.lang.String getLogCardInfo(MCard card)
Return logging info of the given card.

Parameters:
card - the card to Log.
Returns:
logging info of the given card.

replaceWhiteSpaces

public static java.lang.String replaceWhiteSpaces(java.lang.String string)
Return the specfied string without any local white spaces. Would be replaced when StringUtils.deleteWhitespace(String) would work.

Parameters:
string - the string to normalize.
Returns:
the given string without any space char.
See Also:
Character.isWhitespace(char)

getResourceAsStream

public static java.io.InputStream getResourceAsStream(java.lang.String resource)
Return the stream associated to the given resource.

Parameters:
resource - the resource path to search.
Returns:
the stream associated to the given resource.

getResource

public static java.net.URL getResource(java.lang.String resource,
                                       boolean mustExist)
Return the URL associated to the given resource.

Parameters:
resource - the resource path to search.
mustExist - true if the ressource to search must exists, false either
Returns:
the URL associated to the given resource.

getFile

public static java.io.File getFile(java.lang.String fileName)
Return the File associated to the given fileName.

Parameters:
fileName - the file name path to search.
Returns:
the File associated to the given fileName.

getIconPath

public static java.lang.String getIconPath(java.lang.String fileName)
Returns the absolute path of an icon used for the UI.

Parameters:
fileName - the icon path relative to the images dir
Returns:
the absolute path of an icon used for the UI

getShortDeckFile

public static java.lang.String getShortDeckFile(java.lang.String deckFile)
Return the given deck file without the current path off application. If the given deck is valid, it becomes the new deck reference.

Parameters:
deckFile - the full deck file.
Returns:
the given deck file without the current path off application.

addOverlay

public static void addOverlay(javax.swing.JComponent superPanel)
Specifies that a component should have overlay functionality.

Parameters:
superPanel - the panel to overlay.

manaPool

public static int manaPool(int[] registers)
Sum the mana.

Parameters:
registers - teh array of mana.
Returns:
the sum of mana.


Copyright © 2003-2007 Magic-Project. All Rights Reserved.