Updated ServerSelector + Added Awt/Swing Utility

This commit is contained in:
Dane
2013-06-20 15:56:47 -04:00
parent d08640127a
commit 244588f5b6
8 changed files with 113 additions and 93 deletions
-1
View File
@@ -25,6 +25,5 @@ public final class Landing {
Core.enableDevMode();
ServerSelector.getInstance().setVisible(true);
}
}
@@ -33,7 +33,7 @@ public class ServerManifestParser {
if(Core.isDevMode()) {
return localDesc();
}
return publicDesc();
return publicDesc();
}
private ServerDescription[] publicDesc() {
+9 -24
View File
@@ -17,13 +17,14 @@ import org.parabot.core.ui.components.BotToolbar;
import org.parabot.core.ui.components.GamePanel;
import org.parabot.core.ui.components.LogArea;
import org.parabot.core.ui.images.Images;
import org.parabot.core.ui.utils.Center;
import org.parabot.core.ui.utils.AwtUtil;
import org.parabot.core.ui.utils.SwingUtil;
/**
* Bot frame
*
* @author Clisprail
*
*
*/
public class BotUI extends JFrame {
@@ -47,7 +48,7 @@ public class BotUI extends JFrame {
new Thread(new Runnable() {
@Override
public void run() {
}
}).start();
}
@@ -62,32 +63,16 @@ public class BotUI extends JFrame {
pane.addLoader();
getContentPane().setLayout(layout);
setJMenuBar(bar);
setTitle("parabot v2");
setTitle("Parabot");
setIconImage(Images.getResource("/org/parabot/core/ui/images/icon.png"));
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setResizable(false);
Center.centerFramea(this, 775, 683);
layout.setHorizontalGroup(layout
.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout
.createSequentialGroup()
.addContainerGap()
.addGroup(layout
.createParallelGroup(GroupLayout.Alignment.LEADING)))
.addComponent(tool, 768, 768, 768)
.addComponent(pane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(textPane, 768, 768, 768));
layout.setVerticalGroup(layout
.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout
.createSequentialGroup()
.addComponent(tool, 30, 30, 30)
.addComponent(pane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(textPane, 100, 100, 100)
.addContainerGap(58, Short.MAX_VALUE)));
SwingUtil.center(this);
layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING))).addComponent(tool, 768, 768, 768).addComponent(pane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(textPane, 768, 768, 768));
layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addComponent(tool, 30, 30, 30).addComponent(pane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(textPane, 100, 100, 100).addContainerGap(58, Short.MAX_VALUE)));
LogArea.log("Welcome to Parabot v2");
}
public JMenuBar getBar() {
return bar;
}
@@ -1,5 +1,6 @@
package org.parabot.core.ui;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.util.LinkedList;
import java.util.Queue;
@@ -10,49 +11,64 @@ import javax.swing.JScrollPane;
import org.parabot.core.desc.ServerDescription;
import org.parabot.core.parsers.ServerManifestParser;
import org.parabot.core.ui.utils.Center;
import org.parabot.core.ui.utils.AwtUtil;
import org.parabot.core.ui.utils.SwingUtil;
import org.parabot.core.ui.widgets.ServerWidget;
/**
*
* @author Dane
*
*/
public class ServerSelector extends JFrame {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 5238720307271493899L;
private static ServerSelector instance = null;
private JPanel panel;
public static ServerSelector getInstance() {
if (instance != null) {
instance.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
return instance;
if (instance == null) {
instance = new ServerSelector();
}
return instance = new ServerSelector();
return instance;
}
public ServerSelector() {
setLayout(null);
this.setTitle("Servers");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
this.panel = new JPanel(new BorderLayout());
this.panel.setPreferredSize(new Dimension(400, 200));
Queue<ServerWidget> widgets = getServers();
JPanel p = new JPanel();
p.setBounds(0, 0, 400, 800);
p.setLayout(null);
p.setPreferredSize(new Dimension(400, widgets.size() * 100));
JScrollPane pane = new JScrollPane(p);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final int count = widgets.size() - 1;
while (widgets.size() > 0) {
final ServerWidget widget = widgets.poll();
widget.setBounds(0, (count - widgets.size()) * 100, 400, 100);
p.add(widget);
JPanel interior = new JPanel(null);
interior.setPreferredSize(new Dimension(400, widgets.size() * 100));
int i = 0;
for (ServerWidget w : widgets) {
w.setSize(400, 100);
w.setLocation(0, i * 100);
interior.add(w);
i++;
}
pane.setBounds(0, 0, 400, 200);
pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
getContentPane().add(pane);
setResizable(false);
setTitle("Servers");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Center.centerFramea(this, 406, 228);
JScrollPane scrlInterior = new JScrollPane(interior);
scrlInterior.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
this.panel.add(scrlInterior, BorderLayout.CENTER);
this.add(panel);
SwingUtil.finalize(this);
}
public Queue<ServerWidget> getServers() {
final Queue<ServerWidget> widgets = new LinkedList<ServerWidget>();
for (ServerDescription desc : new ServerManifestParser()
.getDescriptions()) {
for (ServerDescription desc : new ServerManifestParser().getDescriptions()) {
widgets.add(new ServerWidget(desc));
}
return widgets;
@@ -10,31 +10,25 @@ import javax.swing.JPanel;
/**
*
* @author Clisprail
*
*
*/
public class ServerPanel extends JPanel {
private static final long serialVersionUID = 6034139911394898295L;
public ServerPanel() {
setBorder(null);
setOpaque(false);
setPreferredSize(new Dimension(765, 503));
GroupLayout layout = new GroupLayout(this);
setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(
GroupLayout.Alignment.LEADING).addGap(0, 706, Short.MAX_VALUE));
layout.setVerticalGroup(layout.createParallelGroup(
GroupLayout.Alignment.LEADING).addGap(0, 418, Short.MAX_VALUE));
layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGap(0, 706, Short.MAX_VALUE));
layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGap(0, 418, Short.MAX_VALUE));
}
@Override
protected void paintComponent(Graphics g) {
g.setColor(Color.LIGHT_GRAY);
g.fillRect(0, 0, getWidth(), getHeight());
}
}
@@ -0,0 +1,29 @@
package org.parabot.core.ui.utils;
import java.awt.Dimension;
import java.awt.Toolkit;
public class AwtUtil {
private static Toolkit toolkit;
public static Toolkit getToolkit() {
if (toolkit == null) {
toolkit = Toolkit.getDefaultToolkit();
}
return toolkit;
}
public static Dimension getScreenSize() {
return AwtUtil.getToolkit().getScreenSize();
}
public static int getScreenWidth() {
return AwtUtil.getScreenSize().width;
}
public static int getScreenHeight() {
return AwtUtil.getScreenSize().height;
}
}
@@ -1,30 +0,0 @@
package org.parabot.core.ui.utils;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JFrame;
/**
*
* @author Clisprail
*
*/
public final class Center {
/**
* Centers a JFrame
* @param frame
* @param width
* @param height
*/
public static final void centerFramea(final JFrame f, final int width, final int height) {
final Dimension fscreen = Toolkit.getDefaultToolkit().getScreenSize();
final int x = (fscreen.width - width) / 2;
final int y = (fscreen.height - height) / 2;
f.setBounds(x, y, width, height);
}
}
@@ -0,0 +1,27 @@
package org.parabot.core.ui.utils;
import javax.swing.JFrame;
public class SwingUtil {
/**
* Centers the frame.
*
* @param f
*/
public static void center(JFrame f) {
f.setLocation((AwtUtil.getScreenWidth() - f.getWidth()) / 2, (AwtUtil.getScreenHeight() - f.getHeight()) / 2);
}
/**
* Packs, centers, and shows the frame.
*
* @param f
*/
public static void finalize(JFrame f) {
f.pack();
center(f);
f.setVisible(true);
}
}