com.swath
Class Tools

java.lang.Object
  extended bycom.swath.Tools

public final class Tools
extends java.lang.Object

This class contains help functions that can be useful when writing scripts. It will be extended with more functionality continously, so make sure you check it out in every new release.

Since:
SWATH 1.6

Nested Class Summary
static class Tools.PortSearchParameters
          This class contains parameters used when searching for ports and port pairs.
static class Tools.SectorSearchParameters
          This class contains parameters used when searching for sectors.
static class Tools.TextRange
          This class contains the start and end index for a text range.
 
Method Summary
static void centerWindow(java.awt.Window window)
          Centers a window on the screen.
static java.awt.Frame createFrame(java.lang.String title, int width, int height)
          Creates an AWT window frame.
static javax.swing.JFrame createJFrame(java.lang.String title, int width, int height)
          Creates a Swing window frame.
static javax.swing.JPanel createJPanel()
          Creates a Swing panel.
static java.awt.Panel createPanel()
          Creates an AWT panel.
static int[][] findPortPairs(Tools.PortSearchParameters params1, Tools.PortSearchParameters params2, boolean fighterSearch, int maxDistance)
          Finds port pairs in the SWATH database that matches the given parameters.
static int[] findPorts(Tools.PortSearchParameters params, boolean fighterSearch, int maxDistance)
          Finds ports in the SWATH database that matches the given parameters.
static int[] findRoute(int fromSector, int toSector)
          Deprecated. Use the other findRoute method instead.
static int[] findRoute(int fromSector, int toSector, boolean ignoreAvoids)
          Finds the route between two sectors by using the SWATH database.
static int[] findSectors(Tools.SectorSearchParameters params)
          Finds sectors in the SWATH database that matches the given parameters.
static Tools.TextRange findText(java.lang.String str, java.lang.String text)
          Searches for a given text in a string.
static Tools.TextRange findText(java.lang.String str, java.lang.String start, java.lang.String end)
          Searches for a text in a string given its start and end.
static java.lang.String getClassName(java.lang.Class cls)
          Gets the class name.
static int getDistance(int fromSector, int toSector, boolean ignoreAvoids)
          Gets the distance between two sectors by using the SWATH database.
static int getInteger(java.lang.String str)
          Gets the integer value of a given text string.
static java.net.URL getResource(java.lang.String resource)
          Finds a resource with a given name.
static java.lang.String getText(java.lang.String str, Tools.TextRange range)
          Gets text from a string given a text range.
static java.lang.String[] getWords(java.lang.String str)
          Splits a given text string into words.
static java.lang.String[] parseText(java.lang.String str, java.lang.String pattern)
          Parses a text string using a given pattern.
static void playSoundFile(java.io.File file)
          Plays the sound from a given file.
static void playSoundFileAsync(java.io.File file)
          Plays the sound from a given file asynchronously.
static void playSoundURL(java.net.URL url)
          Plays the sound from a given URL.
static void playSoundURLAsync(java.net.URL url)
          Plays the sound from a given URL asynchronously.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

findRoute

public static int[] findRoute(int fromSector,
                              int toSector)
                       throws java.lang.Exception
Deprecated. Use the other findRoute method instead.

Finds the route between two sectors by using the SWATH database.

Parameters:
fromSector - The start sector.
toSector - The end sector.
Returns:
An array with the sector path.
Throws:
java.lang.Exception
Since:
SWATH 1.5
See Also:
findRoute(int, int, boolean)

findRoute

public static int[] findRoute(int fromSector,
                              int toSector,
                              boolean ignoreAvoids)
                       throws java.lang.Exception
Finds the route between two sectors by using the SWATH database.

Parameters:
fromSector - The start sector.
toSector - The end sector.
ignoreAvoids - true to ignore avoided sectors, otherwise false.
Returns:
An array with the sector path.
Throws:
java.lang.Exception
Since:
SWATH 1.7
See Also:
getDistance(int, int, boolean)

getDistance

public static int getDistance(int fromSector,
                              int toSector,
                              boolean ignoreAvoids)
                       throws java.lang.Exception
Gets the distance between two sectors by using the SWATH database.

Parameters:
fromSector - The start sector.
toSector - The end sector.
ignoreAvoids - true to ignore avoided sectors, otherwise false.
Returns:
The distance between the sectors.
Throws:
java.lang.Exception
Since:
SWATH 1.7
See Also:
findRoute(int, int, boolean)

findSectors

public static int[] findSectors(Tools.SectorSearchParameters params)
                         throws java.lang.Exception
Finds sectors in the SWATH database that matches the given parameters.

Parameters:
params - The sector parameters.
Returns:
An array with the matching sectors.
Throws:
java.lang.Exception
Since:
SWATH 1.6.2
See Also:
Tools.SectorSearchParameters

findPorts

public static int[] findPorts(Tools.PortSearchParameters params,
                              boolean fighterSearch,
                              int maxDistance)
                       throws java.lang.Exception
Finds ports in the SWATH database that matches the given parameters.

Parameters:
params - The port parameters.
fighterSearch - true to include fighters in the search, otherwise false.
maxDistance - The maximum distance to search from the current sector or -1 for no limit.
Returns:
An array with the matching port sectors (closest ports first).
Throws:
java.lang.Exception
Since:
SWATH 1.6.2
See Also:
Tools.PortSearchParameters, findPortPairs(com.swath.Tools.PortSearchParameters, com.swath.Tools.PortSearchParameters, boolean, int)

findPortPairs

public static int[][] findPortPairs(Tools.PortSearchParameters params1,
                                    Tools.PortSearchParameters params2,
                                    boolean fighterSearch,
                                    int maxDistance)
                             throws java.lang.Exception
Finds port pairs in the SWATH database that matches the given parameters.

Parameters:
params1 - The first port parameters.
params2 - The second port parameters.
fighterSearch - true to include fighters in the search, otherwise false.
maxDistance - The maximum distance to search from the current sector or -1 for no limit.
Returns:
An array with the matching port pair sectors (closest port pairs first).
Throws:
java.lang.Exception
Since:
SWATH 1.6.2
See Also:
Tools.PortSearchParameters, findPorts(com.swath.Tools.PortSearchParameters, boolean, int)

getClassName

public static java.lang.String getClassName(java.lang.Class cls)
Gets the class name.

Parameters:
cls - The class.
Returns:
The class name.
Since:
SWATH 1.6.5

getResource

public static java.net.URL getResource(java.lang.String resource)
Finds a resource with a given name. The search is done using the class path.

Parameters:
resource - The name of the wanted resource.
Returns:
The URL to the wanted resource or null if not found.
Since:
SWATH 1.6.2

findText

public static Tools.TextRange findText(java.lang.String str,
                                       java.lang.String text)
Searches for a given text in a string.

Parameters:
str - The string to search in.
text - The text to search for.
Returns:
The text range or null if not found.
Since:
SWATH 1.7
See Also:
findText(String, String, String), getText(java.lang.String, com.swath.Tools.TextRange), getWords(java.lang.String), getInteger(java.lang.String), parseText(java.lang.String, java.lang.String)

findText

public static Tools.TextRange findText(java.lang.String str,
                                       java.lang.String start,
                                       java.lang.String end)
Searches for a text in a string given its start and end.

Parameters:
str - The string to search in.
start - The first part of the text to search for.
end - The last part of the text to search for.
Returns:
The text range or null if not found.
Since:
SWATH 1.7
See Also:
findText(String, String), getText(java.lang.String, com.swath.Tools.TextRange), getWords(java.lang.String), getInteger(java.lang.String), parseText(java.lang.String, java.lang.String)

getText

public static java.lang.String getText(java.lang.String str,
                                       Tools.TextRange range)
Gets text from a string given a text range.

Parameters:
str - The string that contains the text.
range - The given text range.
Returns:
The wanted text or an empty string if the range was invalid.
Since:
SWATH 1.7
See Also:
findText(String, String), findText(String, String, String), getWords(java.lang.String), getInteger(java.lang.String), parseText(java.lang.String, java.lang.String)

getWords

public static java.lang.String[] getWords(java.lang.String str)
                                   throws java.lang.Exception
Splits a given text string into words.

Parameters:
str - The string to split.
Returns:
A string array with all the words.
Throws:
java.lang.Exception
Since:
SWATH 1.7
See Also:
findText(String, String), findText(String, String, String), getText(java.lang.String, com.swath.Tools.TextRange), getInteger(java.lang.String), parseText(java.lang.String, java.lang.String)

getInteger

public static int getInteger(java.lang.String str)
Gets the integer value of a given text string. This method also handles TradeWars numbers like "9,700".

Parameters:
str - The string.
Returns:
The integer value.
Since:
SWATH 1.7
See Also:
findText(String, String), findText(String, String, String), getText(java.lang.String, com.swath.Tools.TextRange), getWords(java.lang.String), parseText(java.lang.String, java.lang.String)

parseText

public static java.lang.String[] parseText(java.lang.String str,
                                           java.lang.String pattern)
                                    throws java.lang.Exception
Parses a text string using a given pattern. The result is an array of strings that follow the pattern.

Use {0} to mark the first string part and {1} to mark the second etc. The extracted strings will then be placed at index 0 and 1 etc. in the resulting string array.

For example:
parseText("How many [45]?", "{0} [{1}]?") -> "How many" and "45"

Parameters:
str - The string to parse.
pattern - The pattern to follow when parsing.
Returns:
The array of string parts.
Throws:
java.lang.Exception
Since:
SWATH 1.7
See Also:
findText(String, String), findText(String, String, String), getText(java.lang.String, com.swath.Tools.TextRange), getWords(java.lang.String), getInteger(java.lang.String)

playSoundFile

public static void playSoundFile(java.io.File file)
                          throws java.lang.Exception
Plays the sound from a given file. The method does not return until the complete file is played.
Supported file formats: WAV, AU, SND, AIFF, AIFC

Parameters:
file - The sound file to play.
Throws:
java.lang.Exception
Since:
SWATH 1.5
See Also:
playSoundFileAsync(java.io.File), playSoundURL(java.net.URL), playSoundURLAsync(java.net.URL)

playSoundFileAsync

public static void playSoundFileAsync(java.io.File file)
                               throws java.lang.Exception
Plays the sound from a given file asynchronously. The method plays the sound in the background and returns immediately.
Supported file formats: WAV, AU, SND, AIFF, AIFC

Parameters:
file - The sound file to play.
Throws:
java.lang.Exception
Since:
SWATH 1.6
See Also:
playSoundFile(java.io.File), playSoundURL(java.net.URL), playSoundURLAsync(java.net.URL)

playSoundURL

public static void playSoundURL(java.net.URL url)
                         throws java.lang.Exception
Plays the sound from a given URL. The method does not return until the complete audio stream is played.
Supported file formats: WAV, AU, SND, AIFF, AIFC

Parameters:
url - The URL with the sound to play.
Throws:
java.lang.Exception
Since:
SWATH 1.5
See Also:
playSoundFile(java.io.File), playSoundFileAsync(java.io.File), playSoundURLAsync(java.net.URL)

playSoundURLAsync

public static void playSoundURLAsync(java.net.URL url)
                              throws java.lang.Exception
Plays the sound from a given URL asynchronously. The method plays the sound in the background and returns immediately.
Supported file formats: WAV, AU, SND, AIFF, AIFC

Parameters:
url - The URL with the sound to play.
Throws:
java.lang.Exception
Since:
SWATH 1.6
See Also:
playSoundFile(java.io.File), playSoundFileAsync(java.io.File), playSoundURL(java.net.URL)

createPanel

public static java.awt.Panel createPanel()
                                  throws java.lang.Exception
Creates an AWT panel.

Returns:
The new Panel.
Throws:
java.lang.Exception
Since:
SWATH 1.4
See Also:
createJPanel()

createJPanel

public static javax.swing.JPanel createJPanel()
                                       throws java.lang.Exception
Creates a Swing panel.

Returns:
The new JPanel.
Throws:
java.lang.Exception
Since:
SWATH 1.5
See Also:
createPanel()

createFrame

public static java.awt.Frame createFrame(java.lang.String title,
                                         int width,
                                         int height)
                                  throws java.lang.Exception
Creates an AWT window frame.

Parameters:
title - The window title.
width - The width of the window.
height - The height of the window.
Returns:
The new Frame.
Throws:
java.lang.Exception
Since:
SWATH 1.5
See Also:
createJFrame(java.lang.String, int, int), centerWindow(java.awt.Window)

createJFrame

public static javax.swing.JFrame createJFrame(java.lang.String title,
                                              int width,
                                              int height)
                                       throws java.lang.Exception
Creates a Swing window frame.

Parameters:
title - The window title.
width - The width of the window.
height - The height of the window.
Returns:
The new JFrame.
Throws:
java.lang.Exception
Since:
SWATH 1.5
See Also:
createFrame(java.lang.String, int, int), centerWindow(java.awt.Window)

centerWindow

public static void centerWindow(java.awt.Window window)
Centers a window on the screen.

Parameters:
window - The window to center.
Since:
SWATH 1.7