mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-07 16:49:10 +00:00
Updated ServerSelector + Added Awt/Swing Utility
This commit is contained in:
@@ -26,5 +26,4 @@ public final class Landing {
|
|||||||
ServerSelector.getInstance().setVisible(true);
|
ServerSelector.getInstance().setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ import org.parabot.core.ui.components.BotToolbar;
|
|||||||
import org.parabot.core.ui.components.GamePanel;
|
import org.parabot.core.ui.components.GamePanel;
|
||||||
import org.parabot.core.ui.components.LogArea;
|
import org.parabot.core.ui.components.LogArea;
|
||||||
import org.parabot.core.ui.images.Images;
|
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
|
* Bot frame
|
||||||
@@ -62,29 +63,13 @@ public class BotUI extends JFrame {
|
|||||||
pane.addLoader();
|
pane.addLoader();
|
||||||
getContentPane().setLayout(layout);
|
getContentPane().setLayout(layout);
|
||||||
setJMenuBar(bar);
|
setJMenuBar(bar);
|
||||||
setTitle("parabot v2");
|
setTitle("Parabot");
|
||||||
setIconImage(Images.getResource("/org/parabot/core/ui/images/icon.png"));
|
setIconImage(Images.getResource("/org/parabot/core/ui/images/icon.png"));
|
||||||
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||||
setResizable(false);
|
setResizable(false);
|
||||||
Center.centerFramea(this, 775, 683);
|
SwingUtil.center(this);
|
||||||
layout.setHorizontalGroup(layout
|
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));
|
||||||
.createParallelGroup(GroupLayout.Alignment.LEADING)
|
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)));
|
||||||
.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");
|
LogArea.log("Welcome to Parabot v2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.parabot.core.ui;
|
package org.parabot.core.ui;
|
||||||
|
|
||||||
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
@@ -10,49 +11,64 @@ import javax.swing.JScrollPane;
|
|||||||
|
|
||||||
import org.parabot.core.desc.ServerDescription;
|
import org.parabot.core.desc.ServerDescription;
|
||||||
import org.parabot.core.parsers.ServerManifestParser;
|
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;
|
import org.parabot.core.ui.widgets.ServerWidget;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Dane
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
public class ServerSelector extends JFrame {
|
public class ServerSelector extends JFrame {
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
private static final long serialVersionUID = 5238720307271493899L;
|
||||||
private static ServerSelector instance = null;
|
private static ServerSelector instance = null;
|
||||||
|
private JPanel panel;
|
||||||
|
|
||||||
public static ServerSelector getInstance() {
|
public static ServerSelector getInstance() {
|
||||||
if (instance != null) {
|
if (instance == null) {
|
||||||
instance.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
instance = new ServerSelector();
|
||||||
return instance;
|
|
||||||
}
|
}
|
||||||
return instance = new ServerSelector();
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServerSelector() {
|
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();
|
Queue<ServerWidget> widgets = getServers();
|
||||||
JPanel p = new JPanel();
|
|
||||||
p.setBounds(0, 0, 400, 800);
|
JPanel interior = new JPanel(null);
|
||||||
p.setLayout(null);
|
interior.setPreferredSize(new Dimension(400, widgets.size() * 100));
|
||||||
p.setPreferredSize(new Dimension(400, widgets.size() * 100));
|
|
||||||
JScrollPane pane = new JScrollPane(p);
|
int i = 0;
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
for (ServerWidget w : widgets) {
|
||||||
final int count = widgets.size() - 1;
|
w.setSize(400, 100);
|
||||||
while (widgets.size() > 0) {
|
w.setLocation(0, i * 100);
|
||||||
final ServerWidget widget = widgets.poll();
|
interior.add(w);
|
||||||
widget.setBounds(0, (count - widgets.size()) * 100, 400, 100);
|
i++;
|
||||||
p.add(widget);
|
|
||||||
}
|
}
|
||||||
pane.setBounds(0, 0, 400, 200);
|
|
||||||
pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
JScrollPane scrlInterior = new JScrollPane(interior);
|
||||||
getContentPane().add(pane);
|
scrlInterior.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
||||||
setResizable(false);
|
|
||||||
setTitle("Servers");
|
this.panel.add(scrlInterior, BorderLayout.CENTER);
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
this.add(panel);
|
||||||
Center.centerFramea(this, 406, 228);
|
|
||||||
|
SwingUtil.finalize(this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Queue<ServerWidget> getServers() {
|
public Queue<ServerWidget> getServers() {
|
||||||
final Queue<ServerWidget> widgets = new LinkedList<ServerWidget>();
|
final Queue<ServerWidget> widgets = new LinkedList<ServerWidget>();
|
||||||
for (ServerDescription desc : new ServerManifestParser()
|
for (ServerDescription desc : new ServerManifestParser().getDescriptions()) {
|
||||||
.getDescriptions()) {
|
|
||||||
widgets.add(new ServerWidget(desc));
|
widgets.add(new ServerWidget(desc));
|
||||||
}
|
}
|
||||||
return widgets;
|
return widgets;
|
||||||
|
|||||||
@@ -15,26 +15,20 @@ import javax.swing.JPanel;
|
|||||||
public class ServerPanel extends JPanel {
|
public class ServerPanel extends JPanel {
|
||||||
private static final long serialVersionUID = 6034139911394898295L;
|
private static final long serialVersionUID = 6034139911394898295L;
|
||||||
|
|
||||||
|
|
||||||
public ServerPanel() {
|
public ServerPanel() {
|
||||||
setBorder(null);
|
setBorder(null);
|
||||||
setOpaque(false);
|
setOpaque(false);
|
||||||
setPreferredSize(new Dimension(765, 503));
|
setPreferredSize(new Dimension(765, 503));
|
||||||
GroupLayout layout = new GroupLayout(this);
|
GroupLayout layout = new GroupLayout(this);
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
layout.setHorizontalGroup(layout.createParallelGroup(
|
layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGap(0, 706, Short.MAX_VALUE));
|
||||||
GroupLayout.Alignment.LEADING).addGap(0, 706, Short.MAX_VALUE));
|
layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGap(0, 418, Short.MAX_VALUE));
|
||||||
layout.setVerticalGroup(layout.createParallelGroup(
|
|
||||||
GroupLayout.Alignment.LEADING).addGap(0, 418, Short.MAX_VALUE));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintComponent(Graphics g) {
|
protected void paintComponent(Graphics g) {
|
||||||
g.setColor(Color.LIGHT_GRAY);
|
g.setColor(Color.LIGHT_GRAY);
|
||||||
g.fillRect(0, 0, getWidth(), getHeight());
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user