Initial commit.

This commit is contained in:
Woody Folsom
2012-03-06 11:42:35 -05:00
commit 8e83234a87
124 changed files with 9621 additions and 0 deletions

BIN
src/dk/itu/mario/engine/util/.DS_Store vendored Normal file

Binary file not shown.

View File

@@ -0,0 +1,37 @@
package dk.itu.mario.engine.util;
import java.io.BufferedReader;
import java.io.FileReader;
public class FileHandler {
public static String readFile(String fileName){
String info = "";
try {
FileReader input = new FileReader(fileName);
BufferedReader bufRead = new BufferedReader(input);
String line;
int count = 0;
line = bufRead.readLine();
info = line +"\n";
count++;
while (line != null){
// System.out.println(count+": "+line);
line = bufRead.readLine();
info += line + "\n";
count++;
}
bufRead.close();
}catch (Exception e){
// If another exception is generated, print a stack trace
e.printStackTrace();
}
return info;
}
}

View File

@@ -0,0 +1,22 @@
package dk.itu.mario.engine.util;
import java.awt.Graphics;
public abstract class UIItem{
protected int x,y;
protected boolean selected;
protected int width,height;
public abstract void render(Graphics g);
public abstract void prev();
public abstract void next();
public void setSelected(){
selected = true;
}
public void setUnselected(){
selected = false;
}
}

View File

@@ -0,0 +1,83 @@
package dk.itu.mario.engine.util;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
public class UITextArea extends UIItem{
protected String text;
protected int width, height;
protected Font font;
protected ArrayList<String> lines = new ArrayList<String>();
public static boolean showBox = false;
public UITextArea(String text, Font font, int x, int y, int width){
this.text = text;
this.font = font;
this.x = x;
this.y = y;
this.width = width;
}
public void next() {
}
public void prev() {
}
public void render(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
g.setFont(font);
lines.clear();
Rectangle2D rec = font.getStringBounds(text,g2.getFontRenderContext());
String tempText = new String();
if(rec.getWidth()>width){
for(int i=0;i<text.length();++i){
tempText += text.charAt(i);
rec = font.getStringBounds(tempText+"A",g2.getFontRenderContext());
if(rec.getWidth()>=width){
lines.add(tempText);
tempText = new String();
}
}
lines.add(tempText);
}
else{
lines.add(text);
}
for(int j=0;j<lines.size();++j){
rec = font.getStringBounds(lines.get(j),g2.getFontRenderContext());
g.drawString(lines.get(j),x,y+(int)rec.getHeight()*(j+1));
}
if(showBox){
height = (int)rec.getHeight()*lines.size();
g.setColor(Color.BLUE);
g.drawRect(x,y,width,height);
}
}
public int getWidth(){
return width;
}
public int getHeight(){
return height;
}
}