Package view

Source Code of view.ServerListItem

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package view;

import java.awt.Component;
import java.awt.GridLayout;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;
import model.Server;

/**
*
* @author Joel Clay
*/
class ServerListItem extends JPanel implements ListCellRenderer {

    public ServerListItem() {
        setOpaque(true);
    }
    private String upPath = "/green_dot.png";
    private String downPath = "/red_dot.png";
    private boolean currentStatus = true;
    @Override
    public Component getListCellRendererComponent(JList list, Object server, int index, boolean isSelected, boolean cellHasFocus) {
        Server thisServer = null;
        thisServer = (Server) server;
        GridLayout gridLayout = new GridLayout(0, 2);
        setSize(10, 200);
        setLayout(gridLayout);
        removeAll();
       
        add(new JLabel(thisServer.getURL()));
        if (thisServer.isCurrentStatus()) {
            add(new JLabel(createImageIcon(upPath, "up")));
        } else {
            add(new JLabel(createImageIcon(downPath, "down")));

        }

        return this;
    }
   
    public void setServerStatus(boolean status) {
        if (status) {
            currentStatus = true;
        } else {
            currentStatus = false;
        }
        this.repaint();
    }

    protected ImageIcon createImageIcon(String path,
            String description) {
        java.net.URL imgURL = getClass().getResource(path);
        if (imgURL != null) {
            return new ImageIcon(imgURL, description);
        } else {
            System.err.println("Couldn't find file: " + path);
            return null;
        }
    }
}
TOP

Related Classes of view.ServerListItem

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.