net.chunkyhosting.Roe.computer.CHGManager.gui.panels.ServerDisplay.java Source code

Java tutorial

Introduction

Here is the source code for net.chunkyhosting.Roe.computer.CHGManager.gui.panels.ServerDisplay.java

Source

/*
 * CHGManager Computer Edition
 * Copyright (C) 2013 Chunky Hosting LLC
 * Made by: ImThatPedoBear
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package net.chunkyhosting.Roe.computer.CHGManager.gui.panels;

import java.io.File;

import javax.swing.*;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;

import org.json.JSONObject;

import net.chunkyhosting.Roe.computer.CHGManager.CHGManager;

/**
 * @author ImThatPedoBear
 *
 */
public class ServerDisplay extends JPanel {

    private static final long serialVersionUID = -5459417878661177824L;

    public ServerDisplay(JSONObject server) {

        JLabel game = new JLabel(server.getString("gametype"));
        JLabel statusImg = new JLabel(
                new ImageIcon(CHGManager.getInstance().getSettings().getWorkingDirectory().toString()
                        + File.separator + "img" + File.separator + "icons" + File.separator + "ball_green.gif"));
        JLabel statusDetail = new JLabel("284/500");
        JLabel ip = new JLabel(server.getString("ip") + ":" + server.getString("port"));
        JButton console = new JButton(
                new ImageIcon(CHGManager.getInstance().getSettings().getWorkingDirectory().toString()
                        + File.separator + "img" + File.separator + "icons" + File.separator + "console.gif"));
        JButton restart = new JButton(
                new ImageIcon(CHGManager.getInstance().getSettings().getWorkingDirectory().toString()
                        + File.separator + "img" + File.separator + "icons" + File.separator + "restart.gif"));
        JButton stop = new JButton(
                new ImageIcon(CHGManager.getInstance().getSettings().getWorkingDirectory().toString()
                        + File.separator + "img" + File.separator + "icons" + File.separator + "stop.gif"));
        JButton edit = new JButton(
                new ImageIcon(CHGManager.getInstance().getSettings().getWorkingDirectory().toString()
                        + File.separator + "img" + File.separator + "icons" + File.separator + "edit.gif"));
        GroupLayout gl_panel = new GroupLayout(this);
        gl_panel.setHorizontalGroup(gl_panel.createParallelGroup(Alignment.LEADING)
                .addGroup(gl_panel.createSequentialGroup().addContainerGap().addComponent(game).addGap(18)
                        .addComponent(statusImg).addGap(18).addComponent(statusDetail).addGap(18).addComponent(ip)
                        .addPreferredGap(ComponentPlacement.RELATED, 178, Short.MAX_VALUE).addComponent(console)
                        .addPreferredGap(ComponentPlacement.RELATED).addComponent(restart)
                        .addPreferredGap(ComponentPlacement.RELATED).addComponent(stop)
                        .addPreferredGap(ComponentPlacement.RELATED).addComponent(edit)));
        gl_panel.setVerticalGroup(gl_panel.createParallelGroup(Alignment.LEADING)
                .addGroup(gl_panel.createSequentialGroup().addContainerGap()
                        .addGroup(gl_panel.createParallelGroup(Alignment.BASELINE).addComponent(edit)
                                .addComponent(stop).addComponent(restart).addComponent(console))
                        .addContainerGap(23, Short.MAX_VALUE))
                .addGroup(Alignment.TRAILING,
                        gl_panel.createSequentialGroup().addContainerGap(15, Short.MAX_VALUE)
                                .addGroup(gl_panel.createParallelGroup(Alignment.BASELINE).addComponent(game)
                                        .addComponent(statusImg).addComponent(statusDetail).addComponent(ip))
                                .addGap(14)));
        this.setLayout(gl_panel);

    }

}