factored out finderwindow reference again

master
flying sheep 2013-04-12 14:52:10 +02:00
parent 187fa40413
commit 9062622933
5 changed files with 37 additions and 40 deletions

View File

@ -51,7 +51,7 @@ public class FinderWindow extends JFrame {
//UI Manager: //UI Manager:
pane.setLayout(new BorderLayout()); pane.setLayout(new BorderLayout());
loadMinecraft(); loadMinecraft();
(new UpdateManager(this, true)).start(); new UpdateManager(this, true).start();
setJMenuBar(menuBar = new AmidstMenu(this)); setJMenuBar(menuBar = new AmidstMenu(this));
setVisible(true); setVisible(true);
Image icon = ResourceLoader.getImage("icon.png"); Image icon = ResourceLoader.getImage("icon.png");

View File

@ -8,21 +8,16 @@ import java.io.IOException;
public class Amidst { public class Amidst {
public final static int version_major = 3; public final static int version_major = 3;
public final static int version_minor = 0; public final static int version_minor = 0;
private static FinderWindow mainWindow;
public static void main(String args[]) throws IOException { public static void main(String args[]) throws IOException {
Util.setLookAndFeel(); Util.setLookAndFeel();
Google.startTracking(); Google.startTracking();
Google.track("Run"); Google.track("Run");
//TODO: load options //TODO: load options
mainWindow = new FinderWindow(); new FinderWindow(); //as long as we design it well, we wont need a reference to it ;)
} }
public static String version() { public static String version() {
return version_major + "." + version_minor; return version_major + "." + version_minor;
} }
public static FinderWindow getActiveWindow() {
return mainWindow;
}
} }

View File

@ -4,28 +4,28 @@ public class Log {
private static LogListener listener; private static LogListener listener;
private static boolean isUsingListener; private static boolean isUsingListener;
public static void i(Object s) { public static void i(Object... s) {
System.out.println("[info] " + s); printwithTag("info", s);
if (isUsingListener) if (isUsingListener)
listener.info(s); listener.info(s);
} }
public static void debug(Object s) { public static void debug(Object... s) {
System.out.println("[debug] " + s); printwithTag("debug", s);
if (isUsingListener) if (isUsingListener)
listener.debug(s); listener.debug(s);
} }
public static void w(Object s) { public static void w(Object... s) {
System.err.println("[warning] " + s); printwithTag("warning", s);
if (isUsingListener) if (isUsingListener)
listener.warning(s); listener.warning(s);
} }
public static void e(Object s) { public static void e(Object... s) {
System.err.println("[error] " + s); printwithTag("error", s);
if (isUsingListener) if (isUsingListener)
listener.error(s); listener.error(s);
} }
public static void kill(Object s) { public static void kill(Object... s) {
System.err.println("[kill] " + s); printwithTag("kill", s);
if (isUsingListener) if (isUsingListener)
listener.kill(s); listener.kill(s);
System.exit(0); System.exit(0);
@ -35,4 +35,12 @@ public class Log {
listener = l; listener = l;
isUsingListener = (l != null); isUsingListener = (l != null);
} }
private static void printwithTag(String tag, Object... msgs) {
System.out.print("[" + tag + "] ");
for (int i=0; i<msgs.length; i++) {
System.out.print(msgs[i]);
System.out.print((i < msgs.length) ? ", " : "\n");
}
}
} }

View File

@ -1,9 +1,9 @@
package amidst; package amidst;
public interface LogListener { public interface LogListener {
public void debug(Object o); public void debug(Object... o);
public void info(Object o); public void info(Object... o);
public void warning(Object o); public void warning(Object... o);
public void error(Object o); public void error(Object... o);
public void kill(Object o); public void kill(Object... o);
} }

View File

@ -1,7 +1,6 @@
package amidst.map; package amidst.map;
import java.awt.Color; import java.awt.*;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform; import java.awt.geom.AffineTransform;
import java.util.Stack; import java.util.Stack;
@ -28,7 +27,7 @@ public class Map {
private boolean isLoaded = false; private boolean isLoaded = false;
private Object resizeLock = new Object(); private final Object resizeLock = new Object();
private AffineTransform mat; private AffineTransform mat;
private ChunkManager chunkManager; private ChunkManager chunkManager;
@ -41,13 +40,11 @@ public class Map {
public void draw(Graphics2D g) { public void draw(Graphics2D g) {
if (!isLoaded) return; if (!isLoaded) return;
// TODO : Change this to directly reference the window that renders it. Rectangle b = g.getClipBounds();
int width = Amidst.getActiveWindow().getWidth();
int height = Amidst.getActiveWindow().getHeight();
double size = ((double)Fragment.SIZE)*scale; int size = (int) (Fragment.SIZE * scale);
int w = (width) / (int)size + 2; int w = b.width / size + 2;
int h = (height) / (int)size + 2; int h = b.height / size + 2;
while (tileWidth < w) addColumn(END); while (tileWidth < w) addColumn(END);
while (tileWidth > w) removeColumn(END); while (tileWidth > w) removeColumn(END);
@ -63,7 +60,7 @@ public class Map {
//g.fillRect(5, 5, width - 10, height - 10); //g.fillRect(5, 5, width - 10, height - 10);
Fragment frag = startNode; Fragment frag = startNode;
size = (double)Fragment.SIZE; size = Fragment.SIZE;
if (frag.hasNext) { if (frag.hasNext) {
Fragment corner = frag.nextFragment; Fragment corner = frag.nextFragment;
double drawX = startX; double drawX = startX;
@ -187,7 +184,6 @@ public class Map {
frag.setNext(newFrag); frag.setNext(newFrag);
} }
} }
} }
public void removeColumn(boolean start) { public void removeColumn(boolean start) {
synchronized (resizeLock) { synchronized (resizeLock) {
@ -237,8 +233,8 @@ public class Map {
addStart(0, 0); addStart(0, 0);
isLoaded = true; isLoaded = true;
} }
public void setZoom(double scale) { public void setZoom(double scale) {
this.scale = scale; this.scale = scale;
} }
@ -247,13 +243,11 @@ public class Map {
} }
public double getScaledX(double oldScale, double newScale, double x) { public double getScaledX(double oldScale, double newScale, double x) {
double baseX = x - startX; double baseX = x - startX;
double dif = baseX - (baseX/oldScale) * newScale; return baseX - (baseX/oldScale) * newScale;
return dif;
} }
public double getScaledY(double oldScale, double newScale, double y) { public double getScaledY(double oldScale, double newScale, double y) {
double baseY = y - startY; double baseY = y - startY;
double dif = baseY - (baseY/oldScale) * newScale; return baseY - (baseY/oldScale) * newScale;
return dif;
} }
public void close() { public void close() {
isLoaded = false; isLoaded = false;