ist mal n Anfang
wenn du das Programm über Start.java startest, erscheint die View + Dialog zum Auswählen, es passiert aber noch nix
This commit is contained in:
1 parent
f431fc9147
commit
4a7f17b1dc
18 files changed
+900
-73
No files matched your search
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
|
||||
package ChatProgramm.controller;
|
||||
|
||||
import ChatProgramm.controller.commands.CommandConnect;
|
||||
import ChatProgramm.controller.commands.CommandInvoker;
|
||||
import ChatProgramm.controller.commands.CommandSend;
|
||||
import ChatProgramm.model.Transmitter;
|
||||
import ChatProgramm.view.ChatView;
|
||||
import java.awt.Component;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ahren
|
||||
*/
|
||||
public class CommandController implements ActionListener{
|
||||
|
||||
private ChatView view;
|
||||
private Transmitter transmitter;
|
||||
private CommandInvoker invoker;
|
||||
|
||||
public CommandController(ChatView view, Transmitter transmitter){
|
||||
this.view = view;
|
||||
this.transmitter = transmitter;
|
||||
this.invoker = new CommandInvoker();
|
||||
}
|
||||
|
||||
public void registerEvents(){
|
||||
view.getBtnConnect().addActionListener(this);
|
||||
view.getTfNachricht().addActionListener(this);
|
||||
}
|
||||
|
||||
public void registerCommands(){
|
||||
invoker.addCommand(view.getBtnConnect(), new CommandConnect());
|
||||
invoker.addCommand(view.getTfNachricht(), new CommandSend());
|
||||
}
|
||||
|
||||
/**
|
||||
* Ausführen des jeweiligen Kommandos
|
||||
* @param e Referenz auf das Event
|
||||
*/
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Component key = (Component)e.getSource();
|
||||
invoker.executeCommand(key);
|
||||
// if(key == view.getBtnOpen()|| key==view.getMiOpen())
|
||||
// invoker.deleteStack();
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
|
||||
package ChatProgramm.controller;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ahren
|
||||
*/
|
||||
class Nachricht
|
||||
{
|
||||
public Nachricht()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
|
||||
package ChatProgramm.controller;
|
||||
|
||||
import java.util.concurrent.Flow;
|
||||
import java.util.concurrent.Flow.Subscriber;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ahren
|
||||
*/
|
||||
public class ReceiveAdapter implements Subscriber<Nachricht>
|
||||
{
|
||||
public ReceiveAdapter()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubscribe(Flow.Subscription subscription)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(Nachricht item)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable throwable)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
|
||||
package ChatProgramm.controller.commands;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ahren
|
||||
*/
|
||||
public class CommandConnect implements CommandInterface
|
||||
{
|
||||
public CommandConnect()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUndoable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
|
||||
package ChatProgramm.controller.commands;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ahren
|
||||
*/
|
||||
public interface CommandInterface
|
||||
{
|
||||
public void execute();
|
||||
public void undo();
|
||||
// public void redo();
|
||||
public boolean isUndoable();
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
|
||||
package ChatProgramm.controller.commands;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.util.HashMap;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ahren
|
||||
*/
|
||||
public class CommandInvoker {
|
||||
|
||||
private HashMap<Component, CommandInterface> commands;
|
||||
private Stack <CommandInterface> undoStack;
|
||||
|
||||
public CommandInvoker(){
|
||||
commands = new HashMap<>();
|
||||
undoStack = new Stack();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fügt ein Kommando zur Kommando-"Datenbank" = HashMap hinzu
|
||||
* @param key Quelle des Events
|
||||
* @param value Referenz auf das zugehörige Kommando-Objekt
|
||||
*/
|
||||
public void addCommand(Component key, CommandInterface value){
|
||||
commands.put(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Führt Kommando der Eventquelle "key" aus und legt die Referenz
|
||||
* des Kommando in den Undo-Stack
|
||||
* @param key Referenz auf die Eventquelle
|
||||
*/
|
||||
public void executeCommand(Component key){
|
||||
CommandInterface command = commands.get(key);
|
||||
command.execute();
|
||||
if (command.isUndoable())
|
||||
{
|
||||
undoStack.push(command);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Falls der Stack Elemente enthält, wird das oberste Element geholt
|
||||
* und die Methode "undo" des Commands aufgerufen
|
||||
*/
|
||||
public void undoCommand()
|
||||
{
|
||||
if (!undoStack.isEmpty())
|
||||
{
|
||||
undoStack.pop().undo();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Löscht bei Öffnen einer neuen Datei den Stack
|
||||
*/
|
||||
public void deleteStack()
|
||||
{
|
||||
while(!undoStack.isEmpty())
|
||||
undoStack.pop();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
|
||||
package ChatProgramm.controller.commands;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ahren
|
||||
*/
|
||||
public class CommandSend implements CommandInterface
|
||||
{
|
||||
public CommandSend()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUndoable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo()
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user