Oberfläche angepasst

This commit is contained in:
Normal 2019-06-09 00:02:20 +02:00
parent df6c26245d
commit 45600d2365
9 changed files with 383 additions and 52 deletions

View File

@ -6,15 +6,12 @@
package controller;
import controller.commands.CommandInvite;
import controller.commands.CommandRegister;
import gui.Hauptfenster;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.ParseException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sdp.SdpException;
import javax.sip.InvalidArgumentException;
import javax.sip.SipException;
import logger.OhmLogger;
import model.VoIP;
@ -27,10 +24,12 @@ public class CommandController implements ActionListener
private static final Logger lc = OhmLogger.getLogger();
private VoIP model;
private Hauptfenster view;
private CommandInvoker invoker;
public CommandController(VoIP model, Hauptfenster view)
{
this.model = model;
this.view = view;
invoker = new CommandInvoker();
}
public void registerEvents()
@ -38,33 +37,20 @@ public class CommandController implements ActionListener
view.getBtn1().addActionListener(this);
view.getBtn2().addActionListener(this);
}
public void registerCommands()
{
//invoker.addCommand(view.getMnuioeffnen(), new CommandOpen(view, model));
invoker.addCommand(view.getBtn1(), new CommandRegister(model, view));
invoker.addCommand(view.getBtn2(), new CommandInvite(model, view));
}
@Override
public void actionPerformed(ActionEvent e)
{
Object key = e.getSource();
if (key.equals(view.getBtn1()))
{
lc.info("Register Butten geklickt");
try
{
model.sendRegister("123123", 1);
}
catch (ParseException|InvalidArgumentException|SipException ex)
{
lc.getLogger(CommandController.class.getName()).log(Level.SEVERE, null, ex);
}
}
if(key.equals(view.getBtn2()))
{
try {
lc.info("Invite Button geklickt");
model.sendInvitation("23", 2);
}
catch (ParseException|InvalidArgumentException|SdpException|SipException ex) {
lc.getLogger(CommandController.class.getName()).log(Level.SEVERE, null, ex);
}
}
invoker.executeCommand(key);
}
}

View File

@ -0,0 +1,17 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package controller;
/**
*
* @author Normal
*/
public interface CommandInterface
{
public void execute();
public void undo();
public Boolean isundoable();
}

View File

@ -0,0 +1,53 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package controller;
import java.util.HashMap;
import java.util.Stack;
/**
*
* @author Normal
*/
public class CommandInvoker
{
private HashMap<Object, CommandInterface> commands;
private Stack<CommandInterface> undoStack;
public CommandInvoker()
{
commands = new HashMap<>();
undoStack = new Stack<>();
}
public void addCommand(Object key,CommandInterface value)
{
commands.put(key,value);
}
public void executeCommand(Object key)
{
commands.get(key).execute();
if(commands.get(key).isundoable()==true)
{
undoStack.push(commands.get(key));
}
}
public void undoCommand(Object key)
{
try
{
undoStack.pop().undo();
}
catch (Exception e)
{
}
}
}

View File

@ -0,0 +1,61 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package controller.commands;
import controller.CommandInterface;
import gui.Hauptfenster;
import java.text.ParseException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sdp.SdpException;
import javax.sip.InvalidArgumentException;
import javax.sip.SipException;
import logger.OhmLogger;
import model.VoIP;
/**
*
* @author Normal
*/
public class CommandInvite implements CommandInterface
{
private static final Logger lginvite = OhmLogger.getLogger();
private VoIP model;
private Hauptfenster view;
public CommandInvite(VoIP model, Hauptfenster view)
{
this.model = model;
this.view = view;
}
@Override
public void execute()
{
try
{ view.getTxtArea().append("Einladung an " + view.getTxtServerIP().getText() + " gesendet\n");
model.sendInvitation(view.getTxtcallIP().getText(), 5078);
}
catch (ParseException|InvalidArgumentException|SdpException|SipException ex)
{
view.getTxtArea().append("Einladung fehlgeschlagen");
lginvite.getLogger(CommandInvite.class.getName()).log(Level.SEVERE, null, ex);
}
}
@Override
public void undo()
{
}
@Override
public Boolean isundoable()
{
return false;
}
}

View File

@ -0,0 +1,62 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package controller.commands;
import controller.CommandInterface;
import gui.Hauptfenster;
import java.text.ParseException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sip.InvalidArgumentException;
import javax.sip.SipException;
import logger.OhmLogger;
import model.VoIP;
/**
*
* @author Normal
*/
public class CommandRegister implements CommandInterface
{
private static final Logger lgregister = OhmLogger.getLogger();
private VoIP model;
private Hauptfenster view;
public CommandRegister(VoIP model, Hauptfenster view)
{
this.model = model;
this.view = view;
}
@Override
public void execute()
{
try
{
view.getTxtArea().append("Registrierung an " + view.getTxtServerIP().getText() + " gesendet\n");
model.sendRegister(view.getTxtServerIP().getText(), 5078);
}
catch (ParseException|InvalidArgumentException|SipException ex)
{
view.getTxtArea().append("Registrierung fehlgeschlagen");
lgregister.getLogger(CommandRegister.class.getName()).log(Level.SEVERE, null, ex);
}
}
@Override
public void undo()
{
}
@Override
public Boolean isundoable()
{
return false;
}
}

View File

@ -43,13 +43,6 @@
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JTextField" name="textField">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
<BorderConstraints direction="First"/>
</Constraint>
</Constraints>
</Component>
<Container class="javax.swing.JPanel" name="jPanel1">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
@ -77,5 +70,66 @@
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="jPanel3">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
<BorderConstraints direction="First"/>
</Constraint>
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout"/>
<SubComponents>
<Container class="javax.swing.JPanel" name="jPanel4">
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout">
<Property name="axis" type="int" value="1"/>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="jLabel1">
<Properties>
<Property name="text" type="java.lang.String" value="My IP:"/>
<Property name="focusable" type="boolean" value="false"/>
<Property name="inheritsPopupMenu" type="boolean" value="false"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabel2">
<Properties>
<Property name="text" type="java.lang.String" value="Server IP:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabel3">
<Properties>
<Property name="text" type="java.lang.String" value="Call IP:"/>
</Properties>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="jPanel2">
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout">
<Property name="axis" type="int" value="1"/>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="lblmyIP">
<Properties>
<Property name="text" type="java.lang.String" value="xxx.xxx.xxx.xxx"/>
<Property name="toolTipText" type="java.lang.String" value=""/>
<Property name="verticalAlignment" type="int" value="1"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtServerIP">
<Properties>
<Property name="text" type="java.lang.String" value="xxx.xxx.xxx.xxx"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtcallIP">
<Properties>
<Property name="text" type="java.lang.String" value="xxx.xxx.xxx.xxx"/>
</Properties>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Container>
</SubComponents>
</Form>

View File

@ -30,18 +30,11 @@ public class Hauptfenster extends javax.swing.JFrame
/**
* @return the textField
*/
public javax.swing.JTextField getTextField()
{
return textField;
}
/**
* @param textField the textField to set
*/
public void setTextField(javax.swing.JTextField textField)
{
this.textField = textField;
}
/**
* @return the txtArea
@ -79,11 +72,19 @@ public class Hauptfenster extends javax.swing.JFrame
jScrollPane1 = new javax.swing.JScrollPane();
txtArea = new javax.swing.JTextArea();
textField = new javax.swing.JTextField();
jPanel1 = new javax.swing.JPanel();
btn1 = new javax.swing.JButton();
btn2 = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
jPanel3 = new javax.swing.JPanel();
jPanel4 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jPanel2 = new javax.swing.JPanel();
lblmyIP = new javax.swing.JLabel();
txtServerIP = new javax.swing.JTextField();
txtcallIP = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
@ -92,7 +93,6 @@ public class Hauptfenster extends javax.swing.JFrame
jScrollPane1.setViewportView(txtArea);
getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
getContentPane().add(textField, java.awt.BorderLayout.PAGE_START);
btn1.setText("Register");
btn1.setToolTipText("Registrierung am Server");
@ -106,6 +106,38 @@ public class Hauptfenster extends javax.swing.JFrame
getContentPane().add(jPanel1, java.awt.BorderLayout.PAGE_END);
jPanel4.setLayout(new javax.swing.BoxLayout(jPanel4, javax.swing.BoxLayout.Y_AXIS));
jLabel1.setText("My IP:");
jLabel1.setFocusable(false);
jLabel1.setInheritsPopupMenu(false);
jPanel4.add(jLabel1);
jLabel2.setText("Server IP:");
jPanel4.add(jLabel2);
jLabel3.setText("Call IP:");
jPanel4.add(jLabel3);
jPanel3.add(jPanel4);
jPanel2.setLayout(new javax.swing.BoxLayout(jPanel2, javax.swing.BoxLayout.Y_AXIS));
lblmyIP.setText("xxx.xxx.xxx.xxx");
lblmyIP.setToolTipText("");
lblmyIP.setVerticalAlignment(javax.swing.SwingConstants.TOP);
jPanel2.add(lblmyIP);
txtServerIP.setText("xxx.xxx.xxx.xxx");
jPanel2.add(txtServerIP);
txtcallIP.setText("xxx.xxx.xxx.xxx");
jPanel2.add(txtcallIP);
jPanel3.add(jPanel2);
getContentPane().add(jPanel3, java.awt.BorderLayout.PAGE_START);
pack();
setLocationRelativeTo(null);
}// </editor-fold>//GEN-END:initComponents
@ -163,9 +195,49 @@ public class Hauptfenster extends javax.swing.JFrame
private javax.swing.JButton btn1;
private javax.swing.JButton btn2;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextField textField;
private javax.swing.JLabel lblmyIP;
private javax.swing.JTextArea txtArea;
private javax.swing.JTextField txtServerIP;
private javax.swing.JTextField txtcallIP;
// End of variables declaration//GEN-END:variables
/**
* @return the lblmyIP
*/
public javax.swing.JLabel getLblmyIP()
{
return lblmyIP;
}
/**
* @param lblmyIP the lblmyIP to set
*/
public void setLblmyIP(javax.swing.JLabel lblmyIP)
{
this.lblmyIP = lblmyIP;
}
/**
* @return the txtServerIP
*/
public javax.swing.JTextField getTxtServerIP()
{
return txtServerIP;
}
/**
* @return the txtcallIP
*/
public javax.swing.JTextField getTxtcallIP()
{
return txtcallIP;
}
}

View File

@ -7,6 +7,7 @@ package model;
import gov.nist.javax.sip.DialogTimeoutEvent;
import gov.nist.javax.sip.SipListenerExt;
import gui.Hauptfenster;
import java.net.InetAddress;
import java.text.ParseException;
import java.util.*;
@ -38,6 +39,7 @@ import logger.OhmLogger;
*/
public class VoIP implements SipListenerExt
{
Hauptfenster view; //später entfernen wegen Zugriff
private static final Logger lg = OhmLogger.getLogger();
SipFactory sipFactory; // Used to access the SIP API.
SipStack sipStack; // The SIP stack.
@ -61,9 +63,9 @@ public class VoIP implements SipListenerExt
public VoIP() //Konstruktor für eigene Daten
public VoIP(Hauptfenster view) //Konstruktor für eigene Daten
{
this.view = view;
try
{
//wird an sich erstmal nicht gebraucht aber später sinnvoll um eigene Daten zu initialisieren
@ -76,7 +78,7 @@ public class VoIP implements SipListenerExt
this.properties = new Properties();
this.properties.setProperty("javax.sip.STACK_NAME", "stack");
this.sipStack = this.sipFactory.createSipStack(this.properties);
this.messageFactory = this.sipFactory.createMessageFactory();
this.messageFactory = this.sipFactory.createMessageFactory();
this.headerFactory = this.sipFactory.createHeaderFactory();
this.addressFactory = this.sipFactory.createAddressFactory();
this.listeningPoint = this.sipStack.createListeningPoint(this.myIPAddress, this.myPort, this.protocolTyp);
@ -119,6 +121,7 @@ public class VoIP implements SipListenerExt
request.addHeader(allow);
request.addHeader(expire);
this.sipProvider.sendRequest(request);
view.getTxtArea().append("Erfolgreiche Registierung\n");
lg.info("Erfolgreiches Senden der Registrierung");
}
public void sendInvitation(String sipaddresse, int serverPort)throws ParseException, InvalidArgumentException, SipException, SdpException
@ -179,6 +182,7 @@ public class VoIP implements SipListenerExt
response.addHeader(allow);
response.addHeader(allowevents);
this.sipProvider.sendResponse(response);
view.getTxtArea().append("Server Option Request erfolgreich beantwortet\n");
lg.info("Erfolgreiches senden des Headers");
}
catch (ParseException | SipException ex)
@ -189,6 +193,7 @@ public class VoIP implements SipListenerExt
//Aktive Kommunikation
else if ((Request.INVITE).equals(requestEvent.getRequest().getMethod())) // Invite von anderem Benutzer
{
view.getTxtArea().append("Werde von xxx angerufen");
lg.info("Hab Invitation bekommen");
try
{
@ -359,6 +364,20 @@ public class VoIP implements SipListenerExt
return sessionDescription;
}
//Get Methoden falls man mal die Parameter braucht
public String getmyName()
{
return myName;
}
public Integer getMyPort()
{
return myPort;
}
public String getMyIPAdress()
{
return myIPAddress;
}
@Override
public void processTimeout(TimeoutEvent timeoutEvent)

View File

@ -8,6 +8,8 @@ package phone;
import controller.CommandController;
import gui.Hauptfenster;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.ParseException;
import model.VoIP;
/**
@ -16,14 +18,19 @@ import model.VoIP;
*/
public class Start
{
public Start() throws ParseException
public Start() throws ParseException, UnknownHostException
{
Hauptfenster view = new Hauptfenster();
VoIP model = new VoIP();
VoIP model = new VoIP(view);
CommandController controller = new CommandController(model, view);
controller.registerEvents();
//view.setExtendedState(Frame.MAXIMIZED_BOTH);
controller.registerCommands();
view.getLblmyIP().setText(InetAddress.getLocalHost().getHostAddress());
view.getTxtServerIP().setText("192.168.100.11");
view.getTxtcallIP().setText("192.168.100.xxx");
view.setExtendedState(view.MAXIMIZED_BOTH);
view.setTitle("TestOberfläche VoIP Phone");
view.setVisible(true);
@ -32,7 +39,7 @@ public class Start
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws ParseException
public static void main(String[] args) throws ParseException, UnknownHostException
{
new Start();
}