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
Fix the fix that fixes the fuxored fix. Fuckit.
master
1 parent
f66852e
commit
f9ee6979e665cee76b616154a387268b3af65dff
Mark
authored
on 4 Mar 2015
Patch
Showing
2 changed files
src/discovery/computername/OtagoComputerNameResolver.java
src/server/Server.java
Ignore Space
Show notes
View
src/discovery/computername/OtagoComputerNameResolver.java
package discovery.computername; import java.util.List; import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * @author Mark */ public final class OtagoComputerNameResolver implements ComputerNameResolver { private final String computerName; private String labName; private String machineId; private List<String> regexes = new ArrayList<String>(); /** * <p> * Otago University lab machines usually have a COMPUTERNAME environment * variable in the form "labname-machineId", eg SB316-23.</p> * * <p> * If the name parameter is set then use that, otherwise use the envVar * parameter to get the name from an environment variable.</p> * * @param name the computer name to use (or null). * @param envVar the environment variable to use if name is not set. * */ public OtagoComputerNameResolver(final String name, final String envVar) { super(); if (name == null) { computerName = System.getenv(envVar); } else { computerName = name; } regexes.add("(SB\\d\\d\\d)-(\\d\\d)"); // SoB old style regexes.add("(SB\\d\\d\\d)(\\d\\d)"); // SoB incompetent-tech style regexes.add("(TF\\d\\d)(\\d\\d)"); // Teaching facilities 4 digit style regexes.add("(TF\\d\\d\\d)(\\d\\d)"); // Teaching facilities 5 digit style } @Override public void resolve() { if (computerName == null) { throw new InvalidComputerNameException("The computer name has not been provided via a recognisable method.\nTry setting the CLIENTNAME environment variable, or passing the name as an argument when starting the application."); } for (String labRegex : regexes) { Matcher matcher = Pattern.compile(labRegex).matcher(computerName); if(matcher.matches()) { this.labName = matcher.group(1); this.machineId = matcher.group(2); return; } } throw new InvalidComputerNameException("The computer name '" + computerName + "' does not match a recognised lab!"); // this.labName = nameBits[0]; // this.machineId = nameBits[1]; } @Override public String getComputerName() { return this.computerName; } @Override public String getLabName() { return this.labName; } @Override public String getMachineId() { return this.machineId; } }
package discovery.computername; import java.util.List; import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * @author Mark */ public final class OtagoComputerNameResolver implements ComputerNameResolver { private final String computerName; private String labName; private String machineId; private List<String> regexes = new ArrayList<String>(); /** * <p> * Otago University lab machines usually have a COMPUTERNAME environment * variable in the form "labname-machineId", eg SB316-23.</p> * * <p> * If the name parameter is set then use that, otherwise use the envVar * parameter to get the name from an environment variable.</p> * * @param name the computer name to use (or null). * @param envVar the environment variable to use if name is not set. * */ public OtagoComputerNameResolver(final String name, final String envVar) { super(); if (name == null) { computerName = System.getenv(envVar); } else { computerName = name; } regexes.add("(SB\\d\\d\\d)-(\\d\\d)"); // SoB old style regexes.add("(SB\\d\\d\\d)(\\d\\d)"); // SoB incompetent-tech style regexes.add("(TF\\d\\d)(\\d\\d)"); // Teaching facilities 4 digit style regexes.add("(TF\\d\\d\\d)(\\d\\d)"); // Teaching facilities 5 digit style } @Override public void resolve() { if (computerName == null) { throw new InvalidComputerNameException("The computer name has not been provided via a recognisable method.\nTry setting the COMPUTERNAME environment variable, or passing the name as an argument when starting the application."); } for (String labRegex : regexes) { Matcher matcher = Pattern.compile(labRegex).matcher(computerName); if(matcher.matches()) { this.labName = matcher.group(1); this.machineId = matcher.group(2); return; } } throw new InvalidComputerNameException("The computer name '" + computerName + "' does not match a recognised lab!"); // this.labName = nameBits[0]; // this.machineId = nameBits[1]; } @Override public String getComputerName() { return this.computerName; } @Override public String getLabName() { return this.labName; } @Override public String getMachineId() { return this.machineId; } }
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 = new OtagoComputerNameResolver(name, "CLIENTNAME"); try { nameResolver.resolve(); } catch (InvalidComputerNameException ex) { JOptionPane.showMessageDialog(null, "There is no map for this lab yet.\nThe machine ID is : " + nameResolver.getComputerName(), "No map", JOptionPane.ERROR_MESSAGE); System.exit(Constants.EXIT_NO_MAP_FOUND); } 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.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 = new OtagoComputerNameResolver(name, "CLIENTNAME"); try { nameResolver.resolve(); } 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); } 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(); } }
Show line notes below