Quellcode durchsuchen

Improves/Fixes JavaDoc comments

Andreas T. Meyer-Berg vor 5 Jahren
Ursprung
Commit
3bca27e235

+ 2 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/Packet.java

@@ -24,6 +24,8 @@ public abstract class Packet {
 	/**
 	 * Creates a new packet with the given timestamp
 	 * @param timestamp time the packet was sent
+	 * @param source Source of the packet
+	 * @param destination destination of the packet
 	 */
 	protected Packet(long timestamp, Port source, Port destination){
 		this.timestamp = timestamp;

+ 14 - 14
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/protocols/packets/MQTT_packet.java

@@ -28,59 +28,59 @@ public class MQTT_packet extends Packet {
 	 */
 	public static final byte RESERVED = (byte) 0x00;
 	/**
-	 * Client request to connect to Server (Client->Server)
+	 * Client request to connect to Server (Client-{@literal >}Server)
 	 */
 	public static final byte CONNECT = (byte) 0x10;
 	/**
-	 * Connect acknowledgement (Client<-Server)
+	 * Connect acknowledgement (Client{@literal <}-Server)
 	 */
 	public static final byte CONNACK = (byte) 0x20;
 	/**
-	 * Publish message (Client<->Server)
+	 * Publish message (Client{@literal <}-{@literal >}Server)
 	 */
 	public static final byte PUBLISH = (byte) 0x30;
 	/**
-	 * Publish acknowledgement (Client<->Server)
+	 * Publish acknowledgement (Client{@literal <}-{@literal >}Server)
 	 */
 	public static final byte PUBACK = (byte) 0x40;
 	/**
-	 * Publish received (assured delivery part 1) (Client<->Server)
+	 * Publish received (assured delivery part 1) (Client{@literal <}-{@literal >}Server)
 	 */
 	public static final byte PUBREC = (byte) 0x50;
 	/**
-	 * Publish received (assured delivery part 2) (Client<->Server)
+	 * Publish received (assured delivery part 2) (Client{@literal <}-{@literal >}Server)
 	 */
 	public static final byte PUBREL = (byte) 0x62;
 	/**
-	 * Publish received (assured delivery part 3) (Client<->Server)
+	 * Publish received (assured delivery part 3) (Client{@literal <}-{@literal >}Server)
 	 */
 	public static final byte PUBCOMP = (byte) 0x70;
 	/**
-	 * Client subscribe request (Client->Server)
+	 * Client subscribe request (Client-{@literal >}Server)
 	 */
 	public static final byte SUBSCRIBE = (byte) 0x82;
 	/**
-	 * Subscribe acknowledgement (Client<-Server)
+	 * Subscribe acknowledgement (Client{@literal <}-Server)
 	 */
 	public static final byte SUBACK = (byte) 0x90;
 	/**
-	 * Unsubscribe request (Client->Server)
+	 * Unsubscribe request (Client-{@literal >}Server)
 	 */
 	public static final byte UNSUBSCRIBE = (byte) 0xA2;
 	/**
-	 * Unsubscribe acknowledgement (Client<-Server)
+	 * Unsubscribe acknowledgement (Client{@literal <}-Server)
 	 */
 	public static final byte UNSUBACK = (byte) 0xB0;
 	/**
-	 * PING request (Client->Server)
+	 * PING request (Client-{@literal >}Server)
 	 */
 	public static final byte PINGREQ = (byte) 0xC0;
 	/**
-	 * PING response (Client<-Server)
+	 * PING response (Client{@literal <}-Server)
 	 */
 	public static final byte PINGRESP = (byte) 0xD0;
 	/**
-	 * Client is disconnecting (Client->Server)
+	 * Client is disconnecting (Client-{@literal >}Server)
 	 */
 	public static final byte DISCONNECT = (byte) 0xE0;
 	/**

+ 1 - 1
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/PortEditorPanel.java

@@ -199,7 +199,7 @@ public class PortEditorPanel extends JPanel
      
     /**
      * Updates the labels to the given Port
-     * @param port
+     * @param port Port which should be showed in this panel
      */
     protected void updateLabel (Port port) {
     	if(port == null)return;

+ 115 - 54
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/SimulationConfigurator.java

@@ -14,162 +14,223 @@ import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SimulationManager;
 import java.awt.Rectangle;
 import javax.swing.JCheckBox;
 
+/**
+ * Window for configuring, starting and stopping the Simulation
+ * 
+ * @author Andreas T. Meyer-Berg
+ */
 @SuppressWarnings("serial")
 public class SimulationConfigurator extends JFrame {
+	/**
+	 * Textfield for editing the start time
+	 */
 	private JTextField tfStartTimeLong;
+	/**
+	 * Textfield for editing the step duration
+	 */
 	private JTextField tfStepDuration;
+	/**
+	 * Textfield for editing the end time
+	 */
 	private JTextField tfEndTimeLong;
+	/**
+	 * Button for starting/stopping the simulation
+	 */
+	private JButton btnStartStop;
+	/**
+	 * Label which shows the current Time of the simulation
+	 */
 	private JLabel lbCurrentTimeShow;
 	/**
-	 * Progress between 0-10000
+	 * ProgressionBar which shows the progression. Values are between 0 and
+	 * 10000 where 0 represents the start time, and 10000 represents the end
+	 * time.
+	 */
+	private JProgressBar progressBar;
+	/**
+	 * Timer which triggers each simulation step
 	 */
-	private JProgressBar progressBar; 
 	private Timer timer;
+	/**
+	 * SimulationManager, which simulates the network
+	 */
 	private SimulationManager sim;
+	/**
+	 * Current Time in the simulation
+	 */
 	private long currentTime = 0;
+	/**
+	 * Start Time of the Simulation, as presented in long
+	 */
 	private long startTime = 0;
+	/**
+	 * Duration of each simulation step
+	 */
 	private long duration = 100;
+	/**
+	 * End Time of the simulation
+	 */
 	private long endTime = 1000;
-	
+
+	/**
+	 * Create a new SimulationConfigurator Panel, which controls the given
+	 * SimulationManager
+	 * 
+	 * @param sim SimulationManager, which simulates the network
+	 */
 	public SimulationConfigurator(SimulationManager sim) {
 		this.sim = sim;
 		setBounds(new Rectangle(0, 0, 460, 300));
 		setResizable(false);
 		getContentPane().setLayout(null);
-		
-		JButton btnStartStop = new JButton("Start Simulation");
+
+		btnStartStop = new JButton("Start Simulation");
 		btnStartStop.setBounds(12, 189, 149, 37);
 		getContentPane().add(btnStartStop);
-		btnStartStop.addActionListener(a->startStopButtonAction());
-		
+		btnStartStop.addActionListener(a -> startStopButtonAction());
+
 		JButton btnReset = new JButton("Reset");
 		btnReset.setBounds(173, 189, 123, 37);
 		getContentPane().add(btnReset);
-		btnReset.addActionListener(a->resetAction());
-		
+		btnReset.addActionListener(a -> resetAction());
+
 		JButton btnChooseStartDate = new JButton("Choose Start Date");
 		btnChooseStartDate.setBounds(12, 13, 161, 25);
 		getContentPane().add(btnChooseStartDate);
-		
+
 		JButton btnStartTime = new JButton("Choose End Date");
 		btnStartTime.setBounds(271, 13, 161, 25);
 		getContentPane().add(btnStartTime);
-		
+
 		JLabel lblStarttimeLong = new JLabel("StartTime (long):");
 		lblStarttimeLong.setBounds(12, 70, 128, 16);
 		getContentPane().add(lblStarttimeLong);
-		
+
 		JLabel lblStepDuration = new JLabel("Step duration:");
 		lblStepDuration.setBounds(12, 99, 97, 16);
 		getContentPane().add(lblStepDuration);
-		
+
 		tfStartTimeLong = new JTextField();
-		tfStartTimeLong.setText(""+startTime);
+		tfStartTimeLong.setText("" + startTime);
 		tfStartTimeLong.setBounds(116, 67, 116, 22);
 		getContentPane().add(tfStartTimeLong);
 		tfStartTimeLong.setColumns(10);
-		
+
 		tfStepDuration = new JTextField();
-		tfStepDuration.setText(""+duration);
+		tfStepDuration.setText("" + duration);
 		tfStepDuration.setBounds(116, 99, 116, 22);
 		getContentPane().add(tfStepDuration);
 		tfStepDuration.setColumns(10);
-		
+
 		JLabel lblEndtimeLong = new JLabel("EndTime (long):");
 		lblEndtimeLong.setBounds(244, 70, 93, 16);
 		getContentPane().add(lblEndtimeLong);
-		
+
 		tfEndTimeLong = new JTextField();
-		tfEndTimeLong.setText(""+endTime);
+		tfEndTimeLong.setText("" + endTime);
 		tfEndTimeLong.setBounds(347, 67, 85, 22);
 		getContentPane().add(tfEndTimeLong);
 		tfEndTimeLong.setColumns(10);
-		
+
 		JLabel lblCurrentTime = new JLabel("Current Time:");
 		lblCurrentTime.setBounds(12, 160, 97, 16);
 		getContentPane().add(lblCurrentTime);
-		
+
 		lbCurrentTimeShow = new JLabel("0 ms");
 		lbCurrentTimeShow.setBounds(121, 160, 111, 16);
 		getContentPane().add(lbCurrentTimeShow);
-		
+
 		progressBar = new JProgressBar();
 		progressBar.setBounds(0, 251, 442, 14);
 		getContentPane().add(progressBar);
 		progressBar.setValue(0);
 		progressBar.setMinimum(0);
 		progressBar.setMaximum(10000);
-		
+
 		JCheckBox chckbxPrintpackets = new JCheckBox("printPackets");
 		chckbxPrintpackets.setBounds(116, 127, 113, 25);
 		chckbxPrintpackets.setSelected(sim.getPrintPackets());
 		getContentPane().add(chckbxPrintpackets);
-		chckbxPrintpackets.addActionListener(l->sim.setPrintPackets(chckbxPrintpackets.isSelected()));
-		chckbxPrintpackets.setToolTipText("Print Packets as human readable String to testPackets.log in the projekt folder.");
+		chckbxPrintpackets.addActionListener(l -> sim.setPrintPackets(chckbxPrintpackets.isSelected()));
+		chckbxPrintpackets
+				.setToolTipText("Print Packets as human readable String to testPackets.log in the projekt folder.");
 	}
-	
-	private void startStopButtonAction(){
-		if(timer == null){
+
+	/**
+	 * Action which should happen if the StartStop Button is pressed
+	 */
+	private void startStopButtonAction() {
+		if (timer == null) {
 			try {
-				timer = new Timer(0, a->simulateTimeStep());
+				timer = new Timer(0, a -> simulateTimeStep());
 				currentTime = Long.parseLong(tfStartTimeLong.getText());
 				endTime = Long.parseLong(tfEndTimeLong.getText());
 				startTime = Long.parseLong(tfStartTimeLong.getText());
 				duration = Long.parseLong(tfStepDuration.getText());
 				progressBar.setValue(0);
-				lbCurrentTimeShow.setText(currentTime+" ms");				
+				lbCurrentTimeShow.setText(currentTime + " ms");
 			} catch (Exception e) {
-				JOptionPane.showMessageDialog(this,
-					    "Following Error occured: "+e.toString(),
-					    "Error while configuring simulation ",
-					    JOptionPane.ERROR_MESSAGE);
-				//Don't start the timer
+				JOptionPane.showMessageDialog(this, "Following Error occured: " + e.toString(),
+						"Error while configuring simulation ", JOptionPane.ERROR_MESSAGE);
+				// Don't start the timer
 				timer.stop();
 				timer = null;
 				return;
 			}
 		}
-		if(timer.isRunning()){
+		if (timer.isRunning()) {
 			timer.stop();
-		}else{
+			btnStartStop.setText("Start Simulation");
+		} else {
 			timer.start();
+			btnStartStop.setText("Stop Simulation");
 		}
 	}
-	
-	private void resetAction(){
+
+	/**
+	 * Action for the reset Button
+	 */
+	private void resetAction() {
 		try {
 			currentTime = Long.parseLong(tfStartTimeLong.getText());
 			endTime = Long.parseLong(tfEndTimeLong.getText());
 			startTime = Long.parseLong(tfStartTimeLong.getText());
 			duration = Long.parseLong(tfStepDuration.getText());
 			progressBar.setValue(0);
-			lbCurrentTimeShow.setText(currentTime+" ms");
+			lbCurrentTimeShow.setText(currentTime + " ms");
 		} catch (Exception e) {
-			JOptionPane.showMessageDialog(this,
-				    "Following Error occured:\n"+e.toString(),
-				    "Error while configuring simulation ",
-				    JOptionPane.ERROR_MESSAGE);
+			JOptionPane.showMessageDialog(this, "Following Error occured:\n" + e.toString(),
+					"Error while configuring simulation ", JOptionPane.ERROR_MESSAGE);
 		}
-		if(timer == null)return;
+		if (timer == null)
+			return;
 		timer.stop();
 	}
-	
-	private void simulateTimeStep(){
-		if(currentTime>=endTime){
+
+	/**
+	 * Simulates the next TimeStep
+	 */
+	private void simulateTimeStep() {
+		if (currentTime >= endTime) {
 			timer.stop();
+			btnStartStop.setText("Start Simulation");
 			return;
 		}
-		duration = currentTime + duration > endTime ? endTime-currentTime : duration;
-		sim.simulateTimeIntervall(currentTime,duration);
+		duration = currentTime + duration > endTime ? endTime - currentTime : duration;
+		sim.simulateTimeIntervall(currentTime, duration);
 		currentTime += duration;
-		progressBar.setValue((int)((currentTime-startTime)*10000/(endTime-startTime)));
-		lbCurrentTimeShow.setText(currentTime+"");
+		progressBar.setValue((int) ((currentTime - startTime) * 10000 / (endTime - startTime)));
+		lbCurrentTimeShow.setText(currentTime + "");
 	}
-	
+
+	/**
+	 * Test the gui
+	 * @param args none specified
+	 */
 	public static void main(String[] args) {
 		SimulationConfigurator simConfig = new SimulationConfigurator(new SimulationManager(new Model()));
 		simConfig.setEnabled(true);
 		simConfig.setVisible(true);
-		
+
 	}
 }