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

Java tutorial

Introduction

Here is the source code for net.chunkyhosting.Roe.computer.CHGManager.gui.panels.ServerList.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.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;

import javax.swing.*;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormSpecs;
import com.jgoodies.forms.layout.RowSpec;
import javax.swing.LayoutStyle.ComponentPlacement;

import org.json.JSONObject;

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

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

    private static final long serialVersionUID = 1076579355867222584L;
    private ArrayList<Server> servers = new ArrayList<Server>();
    private Servers serversUI;

    public ServerList(Servers serversUI) {

        this.serversUI = serversUI;
        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

    }

    public void retriveServerList() {

        try {

            JSONObject json = CHGManager.getInstance().getGameCPX()
                    .performAPICall(new String[] { "command", "service_list" });
            for (int x = 0; x < json.getJSONArray("result").length(); x++) {

                JSONObject server = json.getJSONArray("result").getJSONObject(x);
                Server theServer = new Server();
                ServerDisplay test = new ServerDisplay(server);
                test.setBorder(BorderFactory.createTitledBorder("Server 1"));
                test.setAlignmentX(Component.CENTER_ALIGNMENT);
                test.setMaximumSize(new Dimension(99999, 80));
                add(test);

            }

            /*ServerDisplay test2 = new ServerDisplay();
            test2.setBorder(BorderFactory.createTitledBorder("Server 2"));
            test2.setAlignmentX(Component.CENTER_ALIGNMENT);
            test2.setMaximumSize(new Dimension(99999, 70));
            add(test2);*/

        } catch (UnsupportedEncodingException e) {

            e.printStackTrace();

        } catch (EmptyAPIResponseException e) {

            e.printStackTrace();

        }

    }

    public ArrayList<Server> getServers() {

        return this.servers;

    }

}