Newer
Older
democall3 / src / gui / QueuePanel.java
package gui;

import java.awt.Font;
import java.util.Collection;

/**
 *
 * @author Mark
 */
public class QueuePanel extends javax.swing.JPanel {

	private Collection<Integer> queue;

	/**
	 * Creates new form QueuePanel
	 */
	public QueuePanel(Collection queue) {
		super();
		this.queue = queue;
		initComponents();
	}

	public void addRequest(int id) {
		queue.add(id);
		updateQueue();
	}

	public void removeRequest(int id) {
		queue.remove(id);
		updateQueue();
	}

	private void updateQueue() {
		String text = queue.toString();
		lblQueue.setText(text.substring(1, text.length() - 1));
	}

	public void setQueueFont(Font font) {
		lblQueue.setFont(font);
	}

	public Collection<Integer> getQueue() {
		return queue;
	}

	public void clear() {
		for (Integer machine : queue) {
			removeRequest(machine);
		}
	}

	/**
	 * This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
   // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
   private void initComponents() {

      scrollPane.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
      scrollPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
      scrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
      scrollPane.setName("scrollPane"); // NOI18N

      lblQueue.setFont(new java.awt.Font("Tahoma", 1, 48)); // NOI18N
      lblQueue.setMaximumSize(new java.awt.Dimension(0, 30));
      lblQueue.setName("lblQueue"); // NOI18N
      scrollPane.setViewportView(lblQueue);

      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
      this.setLayout(layout);
      layout.setHorizontalGroup(
         layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(scrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
            .addContainerGap())
      );
      layout.setVerticalGroup(
         layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(scrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE))
      );
   }// </editor-fold>//GEN-END:initComponents
   // Variables declaration - do not modify//GEN-BEGIN:variables
   private final javax.swing.JLabel lblQueue = new javax.swing.JLabel();
   private final javax.swing.JScrollPane scrollPane = new javax.swing.JScrollPane();
   // End of variables declaration//GEN-END:variables
}