User avatar
Alligator
Posts: 60
Joined: Tue Jun 26, 2012 6:18 pm
Contact: Website

Queue Management for Raspberry Pi?

Tue Nov 28, 2017 6:03 pm

I need a really simple queue manager (by a person's name) so we know who is next in line. Is anyone aware of anything that will run on a Pi that does this?

User avatar
DougieLawson
Posts: 35823
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Queue Management for Raspberry Pi?

Tue Nov 28, 2017 6:07 pm

Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

knute
Posts: 463
Joined: Thu Oct 23, 2014 12:14 am
Location: Texas
Contact: Website

Re: Queue Management for Raspberry Pi?

Wed Nov 29, 2017 10:51 pm

Alligator wrote:
Tue Nov 28, 2017 6:03 pm
I need a really simple queue manager (by a person's name) so we know who is next in line. Is anyone aware of anything that will run on a Pi that does this?
Kept me entertained for an afternoon!

Code: Select all

//package com.knutejohnson.pi;

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;

public class Queue extends JPanel {
    private final DefaultListModel<String> model;
    private final JList<String> list;
    private final JPopupMenu menu;

    public Queue() {
        super(new BorderLayout());

        model = new DefaultListModel<>();
        list = new JList<>(model);
        list.setPrototypeCellValue("Alexander Washington");
        menu = new JPopupMenu();
        menu.add(new AddAction("Add Name"));
        menu.add(new InsertAction("Insert Name"));
        menu.add(new DeleteAction("Delete Name(s)"));
        menu.add(new MoveUpAction("Move Up"));
        menu.add(new MoveDownAction("Move Down"));
        list.setComponentPopupMenu(menu);
        JScrollPane pane = new JScrollPane(list);
        add(pane,BorderLayout.CENTER);

        setPreferredSize(new Dimension(250,400));
    }

    private class AddAction extends AbstractAction {
        public AddAction(String name) {
            putValue(NAME,name);
        }

        public void actionPerformed(ActionEvent ae) {
            String name = JOptionPane.showInputDialog(list,"Add Name");
            if (name != null) {
                model.addElement(name);
                list.clearSelection();
                list.ensureIndexIsVisible(model.size() - 1);
            }
        }
    }            

    private class InsertAction extends AbstractAction {
        public InsertAction(String name) {
            putValue(NAME,name);
        }

        public void actionPerformed(ActionEvent ae) {
            int index = list.getSelectedIndex();
            if (index != -1) {
                String name = JOptionPane.showInputDialog(list,"Insert Name");
                if (name != null) {
                    model.insertElementAt(name,index);
                    list.clearSelection();
                    list.ensureIndexIsVisible(index);
                }
            }
        }
    }

    private class DeleteAction extends AbstractAction {
        public DeleteAction(String name) {
            putValue(NAME,name);
        }

        public void actionPerformed(ActionEvent ae) {
            int[] sel = list.getSelectedIndices();
            if (sel.length > 0) {
                int option =
                 JOptionPane.showConfirmDialog(list,"Are You Sure?");
                if (option == JOptionPane.YES_OPTION) {
                    for (int i=sel.length-1; i>=0; i--)
                        model.remove(sel[i]);
                    list.clearSelection();
                    list.ensureIndexIsVisible(sel[0]);
                }
            }
        }
    }

    private class MoveUpAction extends AbstractAction {
        public MoveUpAction(String name) {
            putValue(NAME,name);
        }

        public void actionPerformed(ActionEvent ae) {
            int[] indices = list.getSelectedIndices();
            if (indices.length == 1 && indices[0] != 0) {
                int index = list.getSelectedIndex();
                String temp = model.getElementAt(index - 1);
                model.setElementAt(model.getElementAt(index),index - 1);
                model.setElementAt(temp,index);
                list.clearSelection();
                list.ensureIndexIsVisible(index - 1);
            }
        }
    }

    private class MoveDownAction extends AbstractAction {
        public MoveDownAction(String name) {
            putValue(NAME,name);
        }

        public void actionPerformed(ActionEvent ae) {
            int[] indices = list.getSelectedIndices();
            if (indices.length == 1 && indices[0] != model.size() - 1) {
                int index = list.getSelectedIndex();
                String temp = model.getElementAt(index);
                model.setElementAt(model.getElementAt(index + 1),index);
                model.setElementAt(temp,index + 1);
                list.clearSelection();
                list.ensureIndexIsVisible(index + 1);
            }
        }
    }
       
    public static void main(String... args) {
        Queue queue = new Queue();
        JFrame frame = new JFrame("Queue");
        frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent we) {
                int option =
                 JOptionPane.showConfirmDialog(frame,"Exit Program?");
                if (option == JOptionPane.YES_OPTION)
                    frame.dispose();
            }
        });
        frame.add(queue,BorderLayout.CENTER);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

Return to “General discussion”