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
Fixed unrecognised machine ID in server.
master
1 parent
ed0c845
commit
f6956b696c0835e4d7bf5307edb23c01469bf38e
Mark
authored
on 4 Mar 2015
Patch
Showing
1 changed file
src/server/Server.java
Ignore Space
Show notes
View
src/server/Server.java
package server; import constants.Constants; import discovery.computername.ComputerNameResolver; import discovery.computername.InvalidComputerNameException; import discovery.computername.OtagoComputerNameResolver; import discovery.server.BroadcastResponder; import gui.Lab; import gui.LabRegistry; import gui.QueuePanel; import gui.processors.RequestProcessor; import gui.processors.ServerLabelProcessor; import java.awt.BorderLayout; import java.awt.event.*; import java.io.IOException; import java.util.Collection; import java.util.LinkedHashSet; import javax.swing.GroupLayout; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.LayoutStyle; /** * * @author Mark */ public final class Server { private Server() { } public static void main(final String[] args) throws IOException { // System.out.println("Server"); // final String name = "SBEASTCAL1-01"; // final String name = "SB316-01"; // final String name = "SB317-1"; // final String name = "SB318-1"; final String name = args.length > 0 ? args[0] : null; ComputerNameResolver nameResolver = null; try { nameResolver = new OtagoComputerNameResolver(name, "COMPUTERNAME"); } catch (InvalidComputerNameException ex) { JOptionPane.showMessageDialog(null, "There is no map for this lab yet.\nThe machine ID is : " + name, "No map", JOptionPane.ERROR_MESSAGE); System.exit(Constants.EXIT_NO_MAP_FOUND); } nameResolver.resolve(); final String labName = nameResolver.getLabName(); final JFrame frame = new JFrame(); frame.setLayout(new BorderLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final LabRegistry registry = new LabRegistry(); final Lab lab = registry.getLab(labName); final JPanel mapPanel = lab.getPanel(); final Collection<Integer> helpQueue = new LinkedHashSet<Integer>(); final Collection<Integer> markingQueue = new LinkedHashSet<Integer>(); QueuePanel helpPanel = new QueuePanel(helpQueue); QueuePanel markingPanel = new QueuePanel(markingQueue); final RequestProcessor processor = new ServerLabelProcessor(helpPanel, markingPanel); processor.processLabels(mapPanel); frame.setTitle(String.format("Democall %1s - Server (%1s)", Constants.VERSION, lab.getLabDescription())); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(frame.getContentPane()); frame.getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(helpPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE) .addComponent(markingPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE) .addComponent(mapPanel, GroupLayout.Alignment.CENTER, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); layout.setVerticalGroup( layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(helpPanel, Constants.QUEUE_MIN_HEIGHT, GroupLayout.DEFAULT_SIZE, Constants.QUEUE_MAX_HEIGHT) .addComponent(markingPanel, Constants.QUEUE_MIN_HEIGHT, GroupLayout.DEFAULT_SIZE, Constants.QUEUE_MAX_HEIGHT) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(mapPanel, 100, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED))); frame.pack(); frame.setVisible(true); // dynamic font resize based on window size final int defaultFontSize = Constants.DEFAULT_MAP_FONT_SIZE; final int currentHeight = mapPanel.getHeight(); frame.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { int newHeight = mapPanel.getHeight(); float scaleFactor = (float) newHeight / (float) currentHeight * 0.8f; int newFontSize = Math.round(defaultFontSize * scaleFactor); processor.resizeFonts(newFontSize); } }); new ApplicationHandler(processor).start(); new BroadcastResponder(labName).start(); } }
package server; import constants.Constants; import discovery.computername.ComputerNameResolver; import discovery.computername.OtagoComputerNameResolver; import discovery.server.BroadcastResponder; import gui.Lab; import gui.LabRegistry; import gui.QueuePanel; import gui.processors.RequestProcessor; import gui.processors.ServerLabelProcessor; import java.awt.BorderLayout; import java.awt.event.*; import java.io.IOException; import java.util.Collection; import java.util.LinkedHashSet; import javax.swing.GroupLayout; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.LayoutStyle; /** * * @author Mark */ public final class Server { private Server() { } public static void main(final String[] args) throws IOException { // System.out.println("Server"); // final String name = "SBEASTCAL1-01"; // final String name = "SB316-01"; // final String name = "SB317-1"; // final String name = "SB318-1"; final String name = args.length > 0 ? args[0] : null; final ComputerNameResolver nameResolver = new OtagoComputerNameResolver(name, "COMPUTERNAME"); nameResolver.resolve(); final String labName = nameResolver.getLabName(); final JFrame frame = new JFrame(); frame.setLayout(new BorderLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final LabRegistry registry = new LabRegistry(); final Lab lab = registry.getLab(labName); if (lab == null) { JOptionPane.showMessageDialog(frame, "There is no map for this lab yet.\nThe lab ID is : " + labName, "No map", JOptionPane.ERROR_MESSAGE); System.exit(Constants.EXIT_NO_MAP_FOUND); } final JPanel mapPanel = lab.getPanel(); final Collection<Integer> helpQueue = new LinkedHashSet<Integer>(); final Collection<Integer> markingQueue = new LinkedHashSet<Integer>(); QueuePanel helpPanel = new QueuePanel(helpQueue); QueuePanel markingPanel = new QueuePanel(markingQueue); final RequestProcessor processor = new ServerLabelProcessor(helpPanel, markingPanel); processor.processLabels(mapPanel); frame.setTitle(String.format("Democall %1s - Server (%1s)", Constants.VERSION, lab.getLabDescription())); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(frame.getContentPane()); frame.getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(helpPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE) .addComponent(markingPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE) .addComponent(mapPanel, GroupLayout.Alignment.CENTER, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); layout.setVerticalGroup( layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(helpPanel, Constants.QUEUE_MIN_HEIGHT, GroupLayout.DEFAULT_SIZE, Constants.QUEUE_MAX_HEIGHT) .addComponent(markingPanel, Constants.QUEUE_MIN_HEIGHT, GroupLayout.DEFAULT_SIZE, Constants.QUEUE_MAX_HEIGHT) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addComponent(mapPanel, 100, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED))); frame.pack(); frame.setVisible(true); // dynamic font resize based on window size final int defaultFontSize = Constants.DEFAULT_MAP_FONT_SIZE; final int currentHeight = mapPanel.getHeight(); frame.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { int newHeight = mapPanel.getHeight(); float scaleFactor = (float) newHeight / (float) currentHeight * 0.8f; int newFontSize = Math.round(defaultFontSize * scaleFactor); processor.resizeFonts(newFontSize); } }); new ApplicationHandler(processor).start(); new BroadcastResponder(labName).start(); } }
Show line notes below