client.framework
Class Utils

java.lang.Object
  extended by client.framework.Utils

public abstract class Utils
extends java.lang.Object

This class contains utilities used in different parts of the framework. These utilities are static methods that offer functionality that may be needed several times. The utilities are: sorting of a list, drawing list of players to a graphics object, drawing message list, drawing list of settings and creating an image.

Author:
Eivind Sorteberg, Martin Jarrett

Field Summary
static int LINE_HEIGHT
           
 
Constructor Summary
Utils()
           
 
Method Summary
static java.lang.String buildString(java.lang.Object[] objects)
          Builds a string using a StringBuffer object.
static Image createImage(int width, int height, int red, int green, int blue)
          Creates a monocolored Image object.
static void drawPlayerList(Graphics graphics, int screenWidth, int screenHeight, AbstractGame model, boolean inGame)
          Draws a list of players to the provided graphics object.
static java.util.Vector sort(java.util.Hashtable list)
          Sorts a list of comparable elements so that the element with the highest value is returned at the start of the list and the element with the lowest value is returned at the end (descending).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LINE_HEIGHT

public static final int LINE_HEIGHT
See Also:
Constant Field Values
Constructor Detail

Utils

public Utils()
Method Detail

sort

public static java.util.Vector sort(java.util.Hashtable list)
Sorts a list of comparable elements so that the element with the highest value is returned at the start of the list and the element with the lowest value is returned at the end (descending).

Parameters:
list - The list to sort. All elements must implement the Comparable interface.
Returns:
A list sorted descending.
See Also:
Comparable

drawPlayerList

public static void drawPlayerList(Graphics graphics,
                                  int screenWidth,
                                  int screenHeight,
                                  AbstractGame model,
                                  boolean inGame)
Draws a list of players to the provided graphics object. This method is used by both GameView and LobbyView to draw their lists of players. If the game is drawn in the lobby view, indicators to show whether the players are ready or not are also drawn. If teams are enabled, the player list is first sorted according to the teams, and the players within each team are sorted by their score.

Parameters:
graphics - The graphics object to use for the drawing.
screenWidth - The available screen width.
screenHeight - The available screen height.
model - The game's model.
inGame - Whether the drawing is performed in-game or not.

createImage

public static Image createImage(int width,
                                int height,
                                int red,
                                int green,
                                int blue)
Creates a monocolored Image object. This method is used to create user sprites and background images.

Parameters:
width - The width of the image.
height - The height of the image.
red - The amound of red.
green - The amount of green.
blue - The amount of blue.
Returns:
An Image object.

buildString

public static java.lang.String buildString(java.lang.Object[] objects)
Builds a string using a StringBuffer object. This method is faster than using the '+' operator when building many and large strings.

Parameters:
objects - The contents of the string.
Returns:
A string object with the specified content.