GitBucket
4.21.2
Toggle navigation
Snippets
Sign in
Files
Branches
1
Releases
Issues
Pull requests
Labels
Priorities
Milestones
Wiki
Forks
mark.george
/
democall3
Browse code
Added 'always on top' mode for Tutor Client.
master
1 parent
4fbc387
commit
fe6c4f70c2e69c75f7d443a4a4ad4f240eb6e371
Mark
authored
on 8 Aug 2012
Patch
Showing
1 changed file
src/clients/TutorClient.java
Ignore Space
Show notes
View
src/clients/TutorClient.java
package clients; import constants.Constants; import discovery.ServiceLocator; import gui.Lab; import gui.LabRegistry; import gui.QueuePanel; import gui.processors.TutorLabelProcessor; import java.awt.BorderLayout; import java.util.Collection; import java.util.Timer; import java.util.TimerTask; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; import network.RequestSender; /** * * @author Mark */ public class TutorClient { private String serverIp; @SuppressWarnings("rawtypes") public TutorClient(String compName) { try { String[] nameBits = compName.split("-"); String labName = nameBits[0]; LabRegistry registry = new LabRegistry(); Object[] labs = registry.getLabs().toArray(); Lab currentLab = registry.getLab(labName); Lab lab = (Lab) JOptionPane.showInputDialog(null, "Which lab?", "Which lab?", JOptionPane.QUESTION_MESSAGE, null, labs, currentLab); if(lab==null) { JOptionPane.showMessageDialog(null, "There is no map for this lab yet.", "No map", JOptionPane.ERROR_MESSAGE); System.exit(Constants.EXIT_NO_MAP_FOUND); } else { labName = lab.getLabName(); } serverIp = new ServiceLocator().locateServer(labName); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setAlwaysOnTop( true ); JPanel mapPanel = lab.getPanel(); final TutorLabelProcessor processor = new TutorLabelProcessor(serverIp); processor.processLabels(mapPanel); frame.setTitle(String.format("Democall %1s - Tutor Client (%1s)", Constants.VERSION, lab.getLabDescription())); frame.setLayout(new BorderLayout()); frame.add(BorderLayout.NORTH, new QueuePanel()); frame.add(BorderLayout.CENTER, mapPanel); frame.pack(); frame.setVisible(true); Timer timer = new Timer(true); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { Collection<Integer> queue = new RequestSender(serverIp).requestQueue(); processor.update(queue); } }, 0, Constants.TUTOR_CLIENT_POLL); } catch (Exception ex) { Logger.getLogger(TutorClient.class.getName()).log(Level.SEVERE, null, ex); } } @SuppressWarnings("ResultOfObjectAllocationIgnored") public static void main(String[] args) { // String compName = System.getenv("COMPUTERNAME"); String compName = "SBEASTCAL1-30"; if(args.length > 0) { compName = args[0]; } new TutorClient(compName); } }
package clients; import constants.Constants; import discovery.ServiceLocator; import gui.Lab; import gui.LabRegistry; import gui.QueuePanel; import gui.processors.TutorLabelProcessor; import java.awt.BorderLayout; import java.util.Set; import java.util.Timer; import java.util.TimerTask; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; import network.RequestSender; /** * * @author mark */ public class TutorClient { private String serverIp; @SuppressWarnings("rawtypes") public TutorClient(String compName) { try { String[] nameBits = compName.split("-"); String labName = nameBits[0]; LabRegistry registry = new LabRegistry(); Object[] labs = registry.getLabs().toArray(); Lab currentLab = registry.getLab(labName); Lab lab = (Lab) JOptionPane.showInputDialog(null, "Which lab?", "Which lab?", JOptionPane.QUESTION_MESSAGE, null, labs, currentLab); if(lab==null) { JOptionPane.showMessageDialog(null, "There is no map for this lab yet.", "No map", JOptionPane.ERROR_MESSAGE); System.exit(Constants.EXIT_NO_MAP_FOUND); } else { labName = lab.getLabName(); } serverIp = new ServiceLocator().locateServer(labName); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel mapPanel = lab.getPanel(); final TutorLabelProcessor processor = new TutorLabelProcessor(serverIp); processor.processLabels(mapPanel); frame.setTitle(String.format("Democall %1s - Tutor Client (%1s)", Constants.VERSION, lab.getLabDescription())); frame.setLayout(new BorderLayout()); frame.add(BorderLayout.NORTH, new QueuePanel()); frame.add(BorderLayout.CENTER, mapPanel); frame.pack(); frame.setVisible(true); Timer timer = new Timer(true); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { Set<Integer> queue = new RequestSender(serverIp).requestQueue(); processor.update(queue); } }, 0, Constants.TUTOR_CLIENT_POLL); } catch (Exception ex) { Logger.getLogger(TutorClient.class.getName()).log(Level.SEVERE, null, ex); } } @SuppressWarnings("ResultOfObjectAllocationIgnored") public static void main(String[] args) { // String compName = System.getenv("COMPUTERNAME"); String compName = "SBEASTCAL1-30"; if(args.length > 0) { compName = args[0]; } new TutorClient(compName); } }
Show line notes below