/* | |||||
* 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 graphicChat; | |||||
import javax.swing.JFrame; | |||||
import javax.swing.WindowConstants; | |||||
import graphicChat.controller.CommandConnect; | |||||
import graphicChat.controller.CommandSend; | |||||
import graphicChat.controller.GraphicsController; | |||||
import graphicChat.controller.ReceiveAdapter; | |||||
import graphicChat.view.ChatView; | |||||
import graphicChat.model.ChatModel; | |||||
import javax.swing.JOptionPane; | |||||
import javax.swing.UIManager; | |||||
/** | |||||
* Builder Class | |||||
* @author le | |||||
*/ | |||||
public class Start | |||||
{ | |||||
public Start() | |||||
{ | |||||
JFrame frm = new JFrame(); | |||||
frm.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); | |||||
ChatView view = new ChatView(); | |||||
ChatModel model = new ChatModel(); | |||||
view.getGrafikView1().setModel(model); | |||||
GraphicsController controller = new GraphicsController(view.getGrafikView1(), model); | |||||
controller.registerEvents(); | |||||
CommandConnect cmdConnect = new CommandConnect(view, model); | |||||
cmdConnect.registerEvents(); | |||||
CommandSend cmdSend = new CommandSend(view, model); | |||||
cmdSend.registerEvents(); | |||||
ReceiveAdapter recAdapter = new ReceiveAdapter(view, model); | |||||
recAdapter.subscribe(); | |||||
view.setVisible(true); | |||||
view.setTitle("Chat"); | |||||
view.setSize(800, 600); | |||||
view.setVisible(true); | |||||
} | |||||
/** | |||||
* @param args the command line arguments | |||||
*/ | |||||
public static void main(String[] args) | |||||
{ | |||||
try | |||||
{ | |||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
JOptionPane.showMessageDialog(null, ex.toString()); | |||||
} | |||||
new Start(); | |||||
new Start(); | |||||
} | |||||
} |
/* | |||||
* 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 graphicChat.controller; | |||||
import java.awt.event.ActionEvent; | |||||
import java.awt.event.ActionListener; | |||||
import java.io.IOException; | |||||
import java.util.logging.Logger; | |||||
import graphicChat.logger.OhmLogger; | |||||
import graphicChat.model.ChatModel; | |||||
import graphicChat.view.ChatView; | |||||
/** | |||||
* | |||||
* @author hd, chris | |||||
*/ | |||||
public class CommandConnect implements ActionListener | |||||
{ | |||||
private static Logger lg = OhmLogger.getLogger(); | |||||
ChatView view; | |||||
ChatModel model; | |||||
private static final int PORT = 35000; | |||||
private static final String IP_ADRESSE = "127.0.0.1"; | |||||
public CommandConnect(ChatView view, ChatModel model) | |||||
{ | |||||
this.view = view; | |||||
this.model = model; | |||||
} | |||||
public void registerEvents(){ | |||||
view.getBtnServer().addActionListener(this); | |||||
view.getBtnClient().addActionListener(this); | |||||
} | |||||
@Override | |||||
public void actionPerformed(ActionEvent e) { | |||||
Object src = e.getSource(); | |||||
// connect to server | |||||
if(src == view.getBtnServer()){ | |||||
synchronized (this){ | |||||
try { | |||||
view.getLblType().setText("Server"); | |||||
model.setServer(PORT); | |||||
} catch (IOException ex) { | |||||
lg.severe(ex.toString()); | |||||
} | |||||
} | |||||
} | |||||
// connect to client | |||||
if(src == view.getBtnClient()){ | |||||
synchronized (this){ | |||||
try { | |||||
view.getLblType().setText("Client"); | |||||
model.setClient(PORT, IP_ADRESSE); | |||||
} catch (IOException ex) { | |||||
lg.severe(ex.toString()); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} |
/* | |||||
* 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 graphicChat.controller; | |||||
import java.awt.event.ActionEvent; | |||||
import java.awt.event.ActionListener; | |||||
import java.util.logging.Logger; | |||||
import graphicChat.logger.OhmLogger; | |||||
import graphicChat.model.ChatModel; | |||||
import graphicChat.model.Figure; | |||||
import graphicChat.view.ChatView; | |||||
import java.util.List; | |||||
/** | |||||
* | |||||
* @author hd, christ | |||||
*/ | |||||
public class CommandSend implements ActionListener | |||||
{ | |||||
private static Logger lg = OhmLogger.getLogger(); | |||||
ChatView view; | |||||
ChatModel model; | |||||
private List<Figure> msg; | |||||
public CommandSend(ChatView view, ChatModel model) | |||||
{ | |||||
this.view = view; | |||||
this.model = model; | |||||
} | |||||
public void registerEvents(){ | |||||
view.getBtnSend().addActionListener(this); | |||||
} | |||||
@Override | |||||
public void actionPerformed(ActionEvent e) | |||||
{ | |||||
Object src = e.getSource(); | |||||
if(src == view.getBtnSend()){ | |||||
/* view get figures*/ | |||||
msg = model.getFigures(); | |||||
model.sendMessage(msg); | |||||
view.getLblStatus().setText("Nachricht gesendet"); | |||||
} | |||||
} | |||||
} |
* and open the template in the editor. | * and open the template in the editor. | ||||
*/ | */ | ||||
package mvcgrafik.controller; | |||||
package graphicChat.controller; | |||||
import java.awt.Point; | import java.awt.Point; | ||||
import java.awt.event.MouseEvent; | import java.awt.event.MouseEvent; | ||||
import java.awt.event.MouseListener; | import java.awt.event.MouseListener; | ||||
import java.awt.event.MouseMotionListener; | import java.awt.event.MouseMotionListener; | ||||
import java.util.logging.Logger; | import java.util.logging.Logger; | ||||
import mvcgrafik.model.Figure; | |||||
import mvcgrafik.model.GrafikModel; | |||||
import mvcgrafik.logger.OhmLogger; | |||||
import mvcgrafik.view.GrafikView; | |||||
import graphicChat.model.Figure; | |||||
import graphicChat.model.ChatModel; | |||||
import graphicChat.logger.OhmLogger; | |||||
import graphicChat.view.Surface; | |||||
/** | /** | ||||
* | * | ||||
* @author le | * @author le | ||||
*/ | */ | ||||
public class GrafikController implements MouseMotionListener, MouseListener | |||||
public class GraphicsController implements MouseMotionListener, MouseListener | |||||
{ | { | ||||
private GrafikView view; | |||||
private GrafikModel model; | |||||
private Surface view; | |||||
private ChatModel model; | |||||
private Figure figure; | private Figure figure; | ||||
private Point p_old; | private Point p_old; | ||||
private static Logger lg = OhmLogger.getLogger(); | private static Logger lg = OhmLogger.getLogger(); | ||||
public GrafikController(GrafikView view, GrafikModel model) | |||||
public GraphicsController(Surface view, ChatModel model) | |||||
{ | { | ||||
this.view = view; | this.view = view; | ||||
this.model = model; | this.model = model; | ||||
} | } | ||||
Point p = evt.getPoint(); | Point p = evt.getPoint(); | ||||
if(p_old != null){ | if(p_old != null){ | ||||
// view.drawLine(p, p_old); | |||||
view.drawLine(p, p_old); | view.drawLine(p, p_old); | ||||
} | } | ||||
p_old = p; | p_old = p; | ||||
p_old = null; | p_old = null; | ||||
figure = null; | figure = null; | ||||
lg.info("Figure finished"); | lg.info("Figure finished"); | ||||
if (evt.getButton() == MouseEvent.BUTTON3) | |||||
{ | |||||
// view.doPrint(); | |||||
view.doPrint(); | |||||
} | |||||
} | } | ||||
@Override | @Override |
/* | |||||
* 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 graphicChat.controller; | |||||
import java.util.concurrent.Flow; | |||||
import java.util.logging.Logger; | |||||
import graphicChat.logger.OhmLogger; | |||||
import graphicChat.model.ChatModel; | |||||
import graphicChat.model.Figure; | |||||
import graphicChat.view.ChatView; | |||||
import java.util.List; | |||||
/** | |||||
* | |||||
* @author hd, chris | |||||
*/ | |||||
public class ReceiveAdapter implements Flow.Subscriber<List<Figure>> | |||||
{ | |||||
private static Logger lg = OhmLogger.getLogger(); | |||||
private ChatView view; | |||||
private ChatModel model; | |||||
private Flow.Subscription subscription; | |||||
public ReceiveAdapter(ChatView view, ChatModel model) | |||||
{ | |||||
this.view = view; | |||||
this.model = model; | |||||
} | |||||
public void subscribe() | |||||
{ | |||||
model.addSubscription(this); | |||||
} | |||||
@Override | |||||
public void onSubscribe(Flow.Subscription subscription) | |||||
{ | |||||
this.subscription = subscription; | |||||
subscription.request(1); | |||||
} | |||||
@Override | |||||
public void onNext(List<Figure> msg) | |||||
{ | |||||
view.getLblStatus().setText("Nachricht empfangen"); | |||||
model.addList(msg); | |||||
subscription.request(1); | |||||
} | |||||
@Override | |||||
public void onError(Throwable throwable) | |||||
{ | |||||
} | |||||
@Override | |||||
public void onComplete() | |||||
{ | |||||
} | |||||
} |
* and open the template in the editor. | * and open the template in the editor. | ||||
*/ | */ | ||||
package mvcgrafik.logger; | |||||
package graphicChat.logger; | |||||
import java.util.Date; | import java.util.Date; | ||||
import java.util.logging.Formatter; | import java.util.logging.Formatter; |
* To change this template file, choose Tools | Templates | * To change this template file, choose Tools | Templates | ||||
* and open the template in the editor. | * and open the template in the editor. | ||||
*/ | */ | ||||
package mvcgrafik.logger; | |||||
package graphicChat.logger; | |||||
import mvcgrafik.logger.MyFormatter; | |||||
import graphicChat.logger.MyFormatter; | |||||
import java.io.File; | import java.io.File; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.util.logging.*; | import java.util.logging.*; |
/* | |||||
* 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 graphicChat.model; | |||||
import graphicChat.logger.OhmLogger; | |||||
import java.io.BufferedReader; | |||||
import java.io.InputStream; | |||||
import java.io.InputStreamReader; | |||||
import java.io.OutputStream; | |||||
import java.io.OutputStreamWriter; | |||||
import java.io.PrintWriter; | |||||
import java.net.ServerSocket; | |||||
import java.net.Socket; | |||||
import java.util.concurrent.ExecutorService; | |||||
import java.util.concurrent.Executors; | |||||
import java.util.concurrent.Flow; | |||||
import java.util.concurrent.SubmissionPublisher; | |||||
import java.util.logging.Level; | |||||
import java.util.logging.Logger; | |||||
import java.io.IOException; | |||||
import java.io.ObjectInputStream; | |||||
import java.util.List; | |||||
/** | |||||
* | |||||
* @author hd, chris | |||||
*/ | |||||
public class ChatModel implements Runnable | |||||
{ | |||||
private static final Logger lg = OhmLogger.getLogger(); | |||||
private final ExecutorService eService; | |||||
private final SubmissionPublisher<List<Figure>> iPublisher; | |||||
private volatile boolean laufend; | |||||
private final GraphicData gdata; | |||||
List<Figure> msg; | |||||
BufferedReader in; | |||||
PrintWriter out; | |||||
ObjectInputStream objectisr; | |||||
private Socket socket; | |||||
public ChatModel() | |||||
{ | |||||
laufend = false; | |||||
iPublisher = new SubmissionPublisher<>(); | |||||
eService = Executors.newSingleThreadExecutor(); | |||||
gdata = new GraphicData(); | |||||
} | |||||
public void addSubscription(Flow.Subscriber<List<Figure>> subscriber) | |||||
{ | |||||
iPublisher.subscribe(subscriber); | |||||
} | |||||
public synchronized void start(){ | |||||
laufend = true; | |||||
eService.submit(this); | |||||
this.notifyAll();//muss sync | |||||
lg.info("startet"); | |||||
} | |||||
@Override | |||||
public void run() | |||||
{ | |||||
while(true){ | |||||
try { | |||||
try | |||||
{ | |||||
msg = (List<Figure>)objectisr.readObject(); | |||||
} | |||||
catch (ClassNotFoundException ex) | |||||
{ | |||||
lg.log(Level.SEVERE, null, ex); | |||||
} | |||||
lg.info("Nachricht empfangen: "); | |||||
addList(msg); | |||||
iPublisher.submit(msg);//wenn neue Nachricht | |||||
} catch (IOException ex) { | |||||
lg.log(Level.SEVERE, ex.toString()); | |||||
} | |||||
} | |||||
} | |||||
public void setSocket(Socket s) throws IOException { | |||||
lg.info("start communication\n"); | |||||
InputStream iStream = s.getInputStream(); | |||||
OutputStream oStream = s.getOutputStream(); | |||||
ObjectInputStream oisr = new ObjectInputStream(iStream); | |||||
InputStreamReader isr = new InputStreamReader(iStream, "UTF-8"); | |||||
OutputStreamWriter osr = new OutputStreamWriter(oStream, "UTF-8"); | |||||
// BufferedWriter out = new BufferedWriter(osr); | |||||
objectisr = oisr; | |||||
out = new PrintWriter(osr); | |||||
in = new BufferedReader(isr); | |||||
start(); | |||||
} | |||||
public void setClient(int PORT, String IP_ADRESSE) throws IOException | |||||
{ | |||||
Thread connectThread; | |||||
connectThread = new Thread(new Runnable() { | |||||
@Override | |||||
public void run() { | |||||
try { | |||||
lg.info("Client: verbinde ..."); | |||||
Socket s = new Socket(IP_ADRESSE, PORT); // Achtung: blockiert! | |||||
lg.info("Client: Verbindung hergestellt"); | |||||
setSocket(s); | |||||
} catch (IOException e) { | |||||
lg.info("io exception in setClient"); | |||||
} | |||||
} | |||||
}); | |||||
connectThread.start(); | |||||
} | |||||
public void setServer(int PORT) throws IOException | |||||
{ | |||||
Thread connectThread; | |||||
connectThread = new Thread(new Runnable() { | |||||
@Override | |||||
public void run() { | |||||
try { | |||||
ServerSocket sSocket = new ServerSocket(PORT); | |||||
lg.info("Server: Warte auf Verbindung ..."); | |||||
Socket s = sSocket.accept(); // Achtung: blockiert! | |||||
lg.info("Server: Verbindung akzeptiert"); | |||||
setSocket(s); | |||||
} catch (IOException e) { | |||||
lg.info("io exception in setServer"); | |||||
} | |||||
} | |||||
}); | |||||
connectThread.start(); | |||||
} | |||||
public void sendMessage(List<Figure> msg) | |||||
{ | |||||
if(laufend){ | |||||
lg.log(Level.INFO, "Sende Nachricht: "); | |||||
out.println(msg); | |||||
out.flush(); | |||||
} | |||||
else{ | |||||
lg.log(Level.INFO, "Keine Verbindung!"); | |||||
} | |||||
} | |||||
public Figure addFigure() | |||||
{ | |||||
return gdata.addFigure(); | |||||
} | |||||
public List<Figure> getFigures() | |||||
{ | |||||
return gdata.getFigures(); | |||||
} | |||||
public void addList(List<Figure> list) | |||||
{ | |||||
gdata.addList(list); | |||||
} | |||||
// public void speichereDatei(String dateiname) throws FileNotFoundException, IOException | |||||
// { | |||||
// FileOutputStream fos = new FileOutputStream(dateiname); | |||||
// BufferedOutputStream buffout = new BufferedOutputStream(fos); | |||||
// ObjectOutputStream oos = new ObjectOutputStream(buffout); | |||||
// oos.writeObject(figures); | |||||
// oos.flush(); | |||||
// oos.close(); | |||||
// | |||||
// } | |||||
// | |||||
// public void ladeDatei(String dateiname) throws FileNotFoundException, IOException, ClassNotFoundException | |||||
// { | |||||
// FileInputStream fis = new FileInputStream(dateiname); | |||||
// BufferedInputStream buffin = new BufferedInputStream(fis); | |||||
// ObjectInputStream ois = new ObjectInputStream(buffin); | |||||
// Object obj = ois.readObject(); | |||||
//// if (obj instanceof ArrayList) | |||||
//// { | |||||
//// punkte = (ArrayList<Point>) obj; | |||||
//// } | |||||
//// else | |||||
//// { | |||||
//// Fehler .... | |||||
//// } | |||||
// figures = (ArrayList<Figure>) ois.readObject(); | |||||
// ois.close(); | |||||
// } | |||||
} |
* and open the template in the editor. | * and open the template in the editor. | ||||
*/ | */ | ||||
package mvcgrafik.model; | |||||
package graphicChat.model; | |||||
import java.awt.Point; | import java.awt.Point; | ||||
import java.util.ArrayList; | import java.util.ArrayList; |
/* | |||||
* 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 graphicChat.model; | |||||
import java.io.BufferedInputStream; | |||||
import java.io.BufferedOutputStream; | |||||
import java.io.FileInputStream; | |||||
import java.io.FileNotFoundException; | |||||
import java.io.FileOutputStream; | |||||
import java.io.IOException; | |||||
import java.io.ObjectInputStream; | |||||
import java.io.ObjectOutputStream; | |||||
import java.util.ArrayList; | |||||
import java.util.Collections; | |||||
import java.util.List; | |||||
/** | |||||
* | |||||
* @author hd, chris | |||||
*/ | |||||
public class GraphicData | |||||
{ | |||||
private ArrayList<Figure> figures; | |||||
public GraphicData() | |||||
{ | |||||
figures = new ArrayList<>(); | |||||
} | |||||
public void addList(List<Figure> list) | |||||
{ | |||||
figures.addAll(list); | |||||
} | |||||
public Figure addFigure() | |||||
{ | |||||
figures.add(new Figure()); | |||||
return figures.get(figures.size() - 1); | |||||
} | |||||
public List<Figure> getFigures() | |||||
{ | |||||
return Collections.unmodifiableList(figures); | |||||
} | |||||
} |
<?xml version="1.0" encoding="UTF-8" ?> | <?xml version="1.0" encoding="UTF-8" ?> | ||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo"> | <Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo"> | ||||
<NonVisualComponents> | |||||
<Component class="javax.swing.JFileChooser" name="jFileChooser1"> | |||||
</Component> | |||||
<Menu class="javax.swing.JMenuBar" name="jMenuBar1"> | |||||
<SubComponents> | |||||
<Menu class="javax.swing.JMenu" name="jMenu1"> | |||||
<Properties> | |||||
<Property name="text" type="java.lang.String" value="File"/> | |||||
</Properties> | |||||
<SubComponents> | |||||
<MenuItem class="javax.swing.JMenuItem" name="btnOpen"> | |||||
<Properties> | |||||
<Property name="text" type="java.lang.String" value="Open"/> | |||||
</Properties> | |||||
<Events> | |||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnOpenActionPerformed"/> | |||||
</Events> | |||||
</MenuItem> | |||||
<MenuItem class="javax.swing.JMenuItem" name="btnSafe"> | |||||
<Properties> | |||||
<Property name="text" type="java.lang.String" value="Safe"/> | |||||
</Properties> | |||||
<Events> | |||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnSafeActionPerformed"/> | |||||
</Events> | |||||
</MenuItem> | |||||
</SubComponents> | |||||
</Menu> | |||||
<Menu class="javax.swing.JMenu" name="jMenu2"> | |||||
<Properties> | |||||
<Property name="text" type="java.lang.String" value="Edit"/> | |||||
</Properties> | |||||
</Menu> | |||||
</SubComponents> | |||||
</Menu> | |||||
</NonVisualComponents> | |||||
<Properties> | <Properties> | ||||
<Property name="defaultCloseOperation" type="int" value="3"/> | <Property name="defaultCloseOperation" type="int" value="3"/> | ||||
<Property name="title" type="java.lang.String" value="Zeichentool"/> | <Property name="title" type="java.lang.String" value="Zeichentool"/> | ||||
</Properties> | </Properties> | ||||
<SyntheticProperties> | <SyntheticProperties> | ||||
<SyntheticProperty name="menuBar" type="java.lang.String" value="jMenuBar1"/> | |||||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/> | <SyntheticProperty name="formSizePolicy" type="int" value="1"/> | ||||
<SyntheticProperty name="generateCenter" type="boolean" value="false"/> | <SyntheticProperty name="generateCenter" type="boolean" value="false"/> | ||||
</SyntheticProperties> | </SyntheticProperties> | ||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> | <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> | ||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> | <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> | ||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> | <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> | ||||
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/> | |||||
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,48,0,0,1,-52"/> | |||||
</AuxValues> | </AuxValues> | ||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/> | <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/> | ||||
<Layout> | <Layout> | ||||
<DimensionLayout dim="0"> | <DimensionLayout dim="0"> | ||||
<Group type="103" groupAlignment="0" attributes="0"> | <Group type="103" groupAlignment="0" attributes="0"> | ||||
<Component id="grafikView1" alignment="0" pref="400" max="32767" attributes="0"/> | |||||
<Component id="grafikView1" alignment="0" max="32767" attributes="0"/> | |||||
</Group> | </Group> | ||||
</DimensionLayout> | </DimensionLayout> | ||||
<DimensionLayout dim="1"> | <DimensionLayout dim="1"> | ||||
</DimensionLayout> | </DimensionLayout> | ||||
</Layout> | </Layout> | ||||
<SubComponents> | <SubComponents> | ||||
<Container class="mvcgrafik.view.GrafikView" name="grafikView1"> | |||||
<Container class="graphicChat.view.Surface" name="grafikView1"> | |||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout"> | <Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout"> | ||||
<Property name="useNullLayout" type="boolean" value="true"/> | <Property name="useNullLayout" type="boolean" value="true"/> | ||||
</Container> | </Container> | ||||
</SubComponents> | </SubComponents> | ||||
</Container> | </Container> | ||||
<Container class="javax.swing.JPanel" name="jPanel2"> | |||||
<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.DesignGridLayout"> | |||||
<Property name="columns" type="int" value="0"/> | |||||
<Property name="rows" type="int" value="1"/> | |||||
</Layout> | |||||
<SubComponents> | |||||
<Component class="javax.swing.JLabel" name="lblType"> | |||||
</Component> | |||||
<Component class="javax.swing.JButton" name="btnClient"> | |||||
<Properties> | |||||
<Property name="text" type="java.lang.String" value="Client"/> | |||||
</Properties> | |||||
<Events> | |||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnClientActionPerformed"/> | |||||
</Events> | |||||
</Component> | |||||
<Component class="javax.swing.JButton" name="btnServer"> | |||||
<Properties> | |||||
<Property name="text" type="java.lang.String" value="Server"/> | |||||
</Properties> | |||||
<Events> | |||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnServerActionPerformed"/> | |||||
</Events> | |||||
</Component> | |||||
</SubComponents> | |||||
</Container> | |||||
<Component class="javax.swing.JButton" name="btnSend"> | |||||
<Properties> | |||||
<Property name="text" type="java.lang.String" value="Send"/> | |||||
</Properties> | |||||
<Events> | |||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnSendActionPerformed"/> | |||||
</Events> | |||||
<Constraints> | |||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription"> | |||||
<BorderConstraints direction="After"/> | |||||
</Constraint> | |||||
</Constraints> | |||||
</Component> | |||||
<Component class="javax.swing.JLabel" name="lblStatus"> | |||||
<Constraints> | |||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription"> | |||||
<BorderConstraints direction="Last"/> | |||||
</Constraint> | |||||
</Constraints> | |||||
</Component> | |||||
</SubComponents> | </SubComponents> | ||||
</Form> | </Form> |
* To change this template file, choose Tools | Templates | * To change this template file, choose Tools | Templates | ||||
* and open the template in the editor. | * and open the template in the editor. | ||||
*/ | */ | ||||
package mvcgrafik.view; | |||||
package graphicChat.view; | |||||
/** | /** | ||||
* | * | ||||
* @author hd | * @author hd | ||||
*/ | */ | ||||
public class GrafikMenuView extends javax.swing.JFrame | |||||
public class ChatView extends javax.swing.JFrame | |||||
{ | { | ||||
/** | |||||
* @return the btnClient | |||||
*/ | |||||
public javax.swing.JButton getBtnClient() | |||||
{ | |||||
return btnClient; | |||||
} | |||||
/** | |||||
* @return the btnSend | |||||
*/ | |||||
public javax.swing.JButton getBtnSend() | |||||
{ | |||||
return btnSend; | |||||
} | |||||
/** | |||||
* @return the btnServer | |||||
*/ | |||||
public javax.swing.JButton getBtnServer() | |||||
{ | |||||
return btnServer; | |||||
} | |||||
/** | |||||
* @return the lblStatus | |||||
*/ | |||||
public javax.swing.JLabel getLblStatus() | |||||
{ | |||||
return lblStatus; | |||||
} | |||||
/** | |||||
* @return the lblType | |||||
*/ | |||||
public javax.swing.JLabel getLblType() | |||||
{ | |||||
return lblType; | |||||
} | |||||
/** | /** | ||||
* @return the jPanel1 | * @return the jPanel1 | ||||
*/ | */ | ||||
/** | /** | ||||
* Creates new form GrafikMenuView | * Creates new form GrafikMenuView | ||||
*/ | */ | ||||
public GrafikMenuView() | |||||
public ChatView() | |||||
{ | { | ||||
initComponents(); | initComponents(); | ||||
} | } | ||||
private void initComponents() | private void initComponents() | ||||
{ | { | ||||
jFileChooser1 = new javax.swing.JFileChooser(); | |||||
jPanel1 = new javax.swing.JPanel(); | jPanel1 = new javax.swing.JPanel(); | ||||
grafikView1 = new mvcgrafik.view.GrafikView(); | |||||
jMenuBar1 = new javax.swing.JMenuBar(); | |||||
jMenu1 = new javax.swing.JMenu(); | |||||
btnOpen = new javax.swing.JMenuItem(); | |||||
btnSafe = new javax.swing.JMenuItem(); | |||||
jMenu2 = new javax.swing.JMenu(); | |||||
grafikView1 = new graphicChat.view.Surface(); | |||||
jPanel2 = new javax.swing.JPanel(); | |||||
lblType = new javax.swing.JLabel(); | |||||
btnClient = new javax.swing.JButton(); | |||||
btnServer = new javax.swing.JButton(); | |||||
btnSend = new javax.swing.JButton(); | |||||
lblStatus = new javax.swing.JLabel(); | |||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); | setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); | ||||
setTitle("Zeichentool"); | setTitle("Zeichentool"); | ||||
jPanel1.setLayout(jPanel1Layout); | jPanel1.setLayout(jPanel1Layout); | ||||
jPanel1Layout.setHorizontalGroup( | jPanel1Layout.setHorizontalGroup( | ||||
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | ||||
.addComponent(grafikView1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE) | |||||
.addComponent(grafikView1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) | |||||
); | ); | ||||
jPanel1Layout.setVerticalGroup( | jPanel1Layout.setVerticalGroup( | ||||
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) | ||||
getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER); | getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER); | ||||
jMenu1.setText("File"); | |||||
jPanel2.setLayout(new java.awt.GridLayout(1, 0)); | |||||
jPanel2.add(lblType); | |||||
btnOpen.setText("Open"); | |||||
btnOpen.addActionListener(new java.awt.event.ActionListener() | |||||
btnClient.setText("Client"); | |||||
btnClient.addActionListener(new java.awt.event.ActionListener() | |||||
{ | { | ||||
public void actionPerformed(java.awt.event.ActionEvent evt) | public void actionPerformed(java.awt.event.ActionEvent evt) | ||||
{ | { | ||||
btnOpenActionPerformed(evt); | |||||
btnClientActionPerformed(evt); | |||||
} | } | ||||
}); | }); | ||||
jMenu1.add(btnOpen); | |||||
jPanel2.add(btnClient); | |||||
btnSafe.setText("Safe"); | |||||
btnSafe.addActionListener(new java.awt.event.ActionListener() | |||||
btnServer.setText("Server"); | |||||
btnServer.addActionListener(new java.awt.event.ActionListener() | |||||
{ | { | ||||
public void actionPerformed(java.awt.event.ActionEvent evt) | public void actionPerformed(java.awt.event.ActionEvent evt) | ||||
{ | { | ||||
btnSafeActionPerformed(evt); | |||||
btnServerActionPerformed(evt); | |||||
} | } | ||||
}); | }); | ||||
jMenu1.add(btnSafe); | |||||
jMenuBar1.add(jMenu1); | |||||
jPanel2.add(btnServer); | |||||
jMenu2.setText("Edit"); | |||||
jMenuBar1.add(jMenu2); | |||||
getContentPane().add(jPanel2, java.awt.BorderLayout.PAGE_START); | |||||
setJMenuBar(jMenuBar1); | |||||
btnSend.setText("Send"); | |||||
btnSend.addActionListener(new java.awt.event.ActionListener() | |||||
{ | |||||
public void actionPerformed(java.awt.event.ActionEvent evt) | |||||
{ | |||||
btnSendActionPerformed(evt); | |||||
} | |||||
}); | |||||
getContentPane().add(btnSend, java.awt.BorderLayout.LINE_END); | |||||
getContentPane().add(lblStatus, java.awt.BorderLayout.PAGE_END); | |||||
pack(); | pack(); | ||||
}// </editor-fold>//GEN-END:initComponents | }// </editor-fold>//GEN-END:initComponents | ||||
private void btnOpenActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnOpenActionPerformed | |||||
{//GEN-HEADEREND:event_btnOpenActionPerformed | |||||
private void btnClientActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnClientActionPerformed | |||||
{//GEN-HEADEREND:event_btnClientActionPerformed | |||||
// TODO add your handling code here: | |||||
}//GEN-LAST:event_btnClientActionPerformed | |||||
private void btnServerActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnServerActionPerformed | |||||
{//GEN-HEADEREND:event_btnServerActionPerformed | |||||
// TODO add your handling code here: | // TODO add your handling code here: | ||||
}//GEN-LAST:event_btnOpenActionPerformed | |||||
}//GEN-LAST:event_btnServerActionPerformed | |||||
private void btnSafeActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnSafeActionPerformed | |||||
{//GEN-HEADEREND:event_btnSafeActionPerformed | |||||
private void btnSendActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnSendActionPerformed | |||||
{//GEN-HEADEREND:event_btnSendActionPerformed | |||||
// TODO add your handling code here: | // TODO add your handling code here: | ||||
}//GEN-LAST:event_btnSafeActionPerformed | |||||
}//GEN-LAST:event_btnSendActionPerformed | |||||
/** | /** | ||||
* @param args the command line arguments | * @param args the command line arguments | ||||
} | } | ||||
catch (ClassNotFoundException ex) | catch (ClassNotFoundException ex) | ||||
{ | { | ||||
java.util.logging.Logger.getLogger(GrafikMenuView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |||||
java.util.logging.Logger.getLogger(ChatView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |||||
} | } | ||||
catch (InstantiationException ex) | catch (InstantiationException ex) | ||||
{ | { | ||||
java.util.logging.Logger.getLogger(GrafikMenuView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |||||
java.util.logging.Logger.getLogger(ChatView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |||||
} | } | ||||
catch (IllegalAccessException ex) | catch (IllegalAccessException ex) | ||||
{ | { | ||||
java.util.logging.Logger.getLogger(GrafikMenuView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |||||
java.util.logging.Logger.getLogger(ChatView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |||||
} | } | ||||
catch (javax.swing.UnsupportedLookAndFeelException ex) | catch (javax.swing.UnsupportedLookAndFeelException ex) | ||||
{ | { | ||||
java.util.logging.Logger.getLogger(GrafikMenuView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |||||
java.util.logging.Logger.getLogger(ChatView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |||||
} | } | ||||
//</editor-fold> | //</editor-fold> | ||||
//</editor-fold> | |||||
/* Create and display the form */ | /* Create and display the form */ | ||||
java.awt.EventQueue.invokeLater(new Runnable() | java.awt.EventQueue.invokeLater(new Runnable() | ||||
{ | { | ||||
public void run() | public void run() | ||||
{ | { | ||||
new GrafikMenuView().setVisible(true); | |||||
new ChatView().setVisible(true); | |||||
} | } | ||||
}); | }); | ||||
} | } | ||||
// Variables declaration - do not modify//GEN-BEGIN:variables | // Variables declaration - do not modify//GEN-BEGIN:variables | ||||
private javax.swing.JMenuItem btnOpen; | |||||
private javax.swing.JMenuItem btnSafe; | |||||
private mvcgrafik.view.GrafikView grafikView1; | |||||
private javax.swing.JFileChooser jFileChooser1; | |||||
private javax.swing.JMenu jMenu1; | |||||
private javax.swing.JMenu jMenu2; | |||||
private javax.swing.JMenuBar jMenuBar1; | |||||
private javax.swing.JButton btnClient; | |||||
private javax.swing.JButton btnSend; | |||||
private javax.swing.JButton btnServer; | |||||
private graphicChat.view.Surface grafikView1; | |||||
private javax.swing.JPanel jPanel1; | private javax.swing.JPanel jPanel1; | ||||
private javax.swing.JPanel jPanel2; | |||||
private javax.swing.JLabel lblStatus; | |||||
private javax.swing.JLabel lblType; | |||||
// End of variables declaration//GEN-END:variables | // End of variables declaration//GEN-END:variables | ||||
/** | /** | ||||
* @return the grafikView1 | * @return the grafikView1 | ||||
*/ | */ | ||||
public mvcgrafik.view.GrafikView getGrafikView1() | |||||
public graphicChat.view.Surface getGrafikView1() | |||||
{ | { | ||||
return grafikView1; | return grafikView1; | ||||
} | } | ||||
/** | |||||
* @return the jFileChooser1 | |||||
*/ | |||||
public javax.swing.JFileChooser getjFileChooser1() | |||||
{ | |||||
return jFileChooser1; | |||||
} | |||||
/** | |||||
* @return the btnOpen | |||||
*/ | |||||
public javax.swing.JMenuItem getBtnOpen() | |||||
{ | |||||
return btnOpen; | |||||
} | |||||
/** | |||||
* @return the btnSafe | |||||
*/ | |||||
public javax.swing.JMenuItem getBtnSafe() | |||||
{ | |||||
return btnSafe; | |||||
} | |||||
} | } |
* To change this template file, choose Tools | Templates | * To change this template file, choose Tools | Templates | ||||
* and open the template in the editor. | * and open the template in the editor. | ||||
*/ | */ | ||||
package mvcgrafik.view; | |||||
package graphicChat.view; | |||||
import java.awt.Color; | import java.awt.Color; | ||||
import java.awt.Dimension; | import java.awt.Dimension; | ||||
import java.awt.Point; | import java.awt.Point; | ||||
import java.awt.geom.Line2D; | import java.awt.geom.Line2D; | ||||
import java.awt.geom.Rectangle2D; | import java.awt.geom.Rectangle2D; | ||||
import java.awt.print.PageFormat; | |||||
import java.awt.print.Printable; | |||||
import java.awt.print.PrinterException; | |||||
import java.awt.print.PrinterJob; | |||||
import java.util.logging.Logger; | import java.util.logging.Logger; | ||||
import javax.print.attribute.HashPrintRequestAttributeSet; | |||||
import javax.print.attribute.standard.DialogTypeSelection; | |||||
import javax.swing.JComponent; | import javax.swing.JComponent; | ||||
import javax.swing.JOptionPane; | |||||
import mvcgrafik.model.GrafikModel; | |||||
import mvcgrafik.logger.OhmLogger; | |||||
import graphicChat.logger.OhmLogger; | |||||
import graphicChat.model.ChatModel; | |||||
/** | /** | ||||
* | * | ||||
* @author hd, chris | * @author hd, chris | ||||
*/ | */ | ||||
public class GrafikView extends JComponent implements Printable | |||||
public class Surface extends JComponent | |||||
{ | { | ||||
private final static Dimension EINS = new Dimension(1, 1); | private final static Dimension EINS = new Dimension(1, 1); | ||||
private static Logger lg = OhmLogger.getLogger(); | private static Logger lg = OhmLogger.getLogger(); | ||||
private Rectangle2D.Float pixel; | private Rectangle2D.Float pixel; | ||||
private GrafikModel model; | |||||
private ChatModel model; | |||||
private Point old_punkt = null; | private Point old_punkt = null; | ||||
public GrafikView() | |||||
public Surface() | |||||
{ | { | ||||
pixel = new Rectangle2D.Float(); | pixel = new Rectangle2D.Float(); | ||||
this.setBackground(Color.WHITE); | this.setBackground(Color.WHITE); | ||||
} | } | ||||
public void setModel(GrafikModel model) | |||||
public void setModel(ChatModel model) | |||||
{ | { | ||||
this.model = model; | this.model = model; | ||||
} | } | ||||
Graphics2D g2 = (Graphics2D) this.getGraphics(); | Graphics2D g2 = (Graphics2D) this.getGraphics(); | ||||
Line2D.Double line = new Line2D.Double(p.getX(),p.getY(),p_old.getX(),p_old.getY()); | Line2D.Double line = new Line2D.Double(p.getX(),p.getY(),p_old.getX(),p_old.getY()); | ||||
g2.draw(line); | g2.draw(line); | ||||
g2.dispose(); // VERY, VERY WICHTIG | |||||
g2.dispose(); // VERY, VERY IMPORTANT | |||||
} | } | ||||
public void drawLineG2(Point p, Point p_old, Graphics2D g2) | public void drawLineG2(Point p, Point p_old, Graphics2D g2) | ||||
{ | { | ||||
}); | }); | ||||
}); | }); | ||||
} | } | ||||
public void doPrint() | |||||
{ | |||||
HashPrintRequestAttributeSet printSet = | |||||
new HashPrintRequestAttributeSet(); | |||||
printSet.add(DialogTypeSelection.NATIVE); | |||||
PrinterJob pj = PrinterJob.getPrinterJob(); | |||||
pj.setPrintable(this); | |||||
// Druckdialog | |||||
if (pj.printDialog(printSet)) | |||||
{ | |||||
try | |||||
{ | |||||
pj.print(printSet); | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
JOptionPane.showMessageDialog(this, ex.toString()); | |||||
} | |||||
} | |||||
} | |||||
@Override | |||||
public int print(Graphics gp, PageFormat pf, int pageIndex) throws PrinterException | |||||
{ | |||||
Graphics2D g2p = (Graphics2D) gp; | |||||
if (pageIndex == 1) | |||||
{ | |||||
g2p.translate(pf.getImageableX(), pf.getImageableY()); | |||||
g2p.scale(pf.getImageableWidth()/this.getWidth(), | |||||
pf.getImageableHeight() / this.getHeight()); | |||||
super.print(g2p); | |||||
return Printable.PAGE_EXISTS; | |||||
} | |||||
else | |||||
{ | |||||
return Printable.NO_SUCH_PAGE; | |||||
} | |||||
} | |||||
} | } |
/* | |||||
* 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 mvcgrafik; | |||||
import javax.swing.JFrame; | |||||
import javax.swing.JPanel; | |||||
import javax.swing.WindowConstants; | |||||
import mvcgrafik.controller.BtnController; | |||||
import mvcgrafik.controller.GrafikController; | |||||
import mvcgrafik.model.GrafikModel; | |||||
import mvcgrafik.view.GrafikMenuView; | |||||
import mvcgrafik.view.GrafikView; | |||||
//import mvcgrafik.ohmLogger; | |||||
/** | |||||
* Builder Class | |||||
* @author le | |||||
*/ | |||||
public class Start | |||||
{ | |||||
public Start() | |||||
{ | |||||
JFrame frm = new JFrame(); | |||||
frm.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); | |||||
GrafikMenuView view = new GrafikMenuView(); | |||||
GrafikModel model = new GrafikModel(); | |||||
view.getGrafikView1().setModel(model); | |||||
GrafikController controller = new GrafikController(view.getGrafikView1(), model); | |||||
BtnController btncontroller = new BtnController(view, model); | |||||
controller.registerEvents(); | |||||
btncontroller.registerEvents(); | |||||
view.setSize(800, 600); | |||||
view.setVisible(true); | |||||
} | |||||
/** | |||||
* @param args the command line arguments | |||||
*/ | |||||
public static void main(String[] args) | |||||
{ | |||||
new Start(); | |||||
} | |||||
} |
/* | |||||
* 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 mvcgrafik.controller; | |||||
import java.awt.Point; | |||||
import java.awt.event.ActionEvent; | |||||
import java.awt.event.ActionListener; | |||||
import java.io.File; | |||||
import java.io.IOException; | |||||
import java.io.UnsupportedEncodingException; | |||||
import java.util.logging.Level; | |||||
import java.util.logging.Logger; | |||||
import java.util.prefs.Preferences; | |||||
import javax.swing.JFileChooser; | |||||
import mvcgrafik.model.Figure; | |||||
import mvcgrafik.model.GrafikModel; | |||||
import mvcgrafik.view.GrafikMenuView; | |||||
import mvcgrafik.logger.OhmLogger; | |||||
/** | |||||
* | |||||
* @author le | |||||
*/ | |||||
public class BtnController implements ActionListener | |||||
{ | |||||
private GrafikMenuView view; | |||||
//private GrafikMenuView menuview; | |||||
private GrafikModel model; | |||||
private Figure figure; | |||||
private Point p_old; | |||||
private static Logger lg = OhmLogger.getLogger(); | |||||
public BtnController(GrafikMenuView view, GrafikModel model) | |||||
{ | |||||
this.view = view; | |||||
this.model = model; | |||||
} | |||||
public void registerEvents() | |||||
{ | |||||
view.getBtnOpen().addActionListener(this); | |||||
view.getBtnSafe().addActionListener(this); | |||||
} | |||||
@Override | |||||
public void actionPerformed(ActionEvent ae) | |||||
{ | |||||
if(ae.getSource() == view.getBtnSafe()) | |||||
{ | |||||
Preferences pref = Preferences.userNodeForPackage(this.getClass()); | |||||
String path = pref.get("DEFAULT_PATH", ""); | |||||
view.getjFileChooser1().setCurrentDirectory(new File(path)); | |||||
int choice = view.getjFileChooser1().showSaveDialog(view); | |||||
if (choice == JFileChooser.APPROVE_OPTION) | |||||
{ | |||||
File selectedFile = view.getjFileChooser1().getSelectedFile(); | |||||
pref.put("DEFAULT_PATH", selectedFile.getAbsolutePath()); | |||||
try | |||||
{ | |||||
//model.datenSpeichern(selectedFile); | |||||
model.speichereDatei("TEST"); | |||||
} | |||||
catch (UnsupportedEncodingException ex) | |||||
{ | |||||
Logger.getLogger(GrafikController.class.getName()).log(Level.SEVERE, null, ex); | |||||
} | |||||
catch (IOException ex) | |||||
{ | |||||
Logger.getLogger(GrafikController.class.getName()).log(Level.SEVERE, null, ex); | |||||
} | |||||
} | |||||
} | |||||
if(ae.getSource() == view.getBtnOpen()) | |||||
{ | |||||
Preferences pref = Preferences.userNodeForPackage(this.getClass()); | |||||
String path = pref.get("DEFAULT_PATH", ""); | |||||
view.getjFileChooser1().setCurrentDirectory(new File(path)); | |||||
int choice = view.getjFileChooser1().showOpenDialog(view); | |||||
if (choice == JFileChooser.APPROVE_OPTION) | |||||
{ | |||||
File selectedFile = view.getjFileChooser1().getSelectedFile(); | |||||
pref.put("DEFAULT_PATH", selectedFile.getAbsolutePath()); | |||||
try | |||||
{ | |||||
//model.datenLesen(selectedFile); | |||||
model.ladeDatei("TEST"); | |||||
} | |||||
catch (UnsupportedEncodingException ex) | |||||
{ | |||||
Logger.getLogger(GrafikController.class.getName()).log(Level.SEVERE, null, ex); | |||||
} | |||||
catch (IOException | ClassNotFoundException ex) | |||||
{ | |||||
Logger.getLogger(GrafikController.class.getName()).log(Level.SEVERE, null, ex); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} | |||||
/* | |||||
* 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 mvcgrafik.model; | |||||
import java.awt.Point; | |||||
import java.io.BufferedInputStream; | |||||
import java.io.BufferedOutputStream; | |||||
import java.io.FileInputStream; | |||||
import java.io.FileNotFoundException; | |||||
import java.io.FileOutputStream; | |||||
import java.io.IOException; | |||||
import java.io.ObjectInputStream; | |||||
import java.io.ObjectOutputStream; | |||||
import java.util.ArrayList; | |||||
import java.util.Collections; | |||||
import java.util.List; | |||||
/** | |||||
* | |||||
* @author le | |||||
*/ | |||||
public class GrafikModel | |||||
{ | |||||
private ArrayList<Figure> figures; | |||||
public GrafikModel() | |||||
{ | |||||
figures = new ArrayList<>(); | |||||
} | |||||
public Figure addFigure() | |||||
{ | |||||
figures.add(new Figure()); | |||||
return figures.get(figures.size() - 1); | |||||
} | |||||
public List<Figure> getFigures() | |||||
{ | |||||
return Collections.unmodifiableList(figures); | |||||
} | |||||
public void speichereDatei(String dateiname) throws FileNotFoundException, IOException | |||||
{ | |||||
FileOutputStream fos = new FileOutputStream(dateiname); | |||||
BufferedOutputStream buffout = new BufferedOutputStream(fos); | |||||
ObjectOutputStream oos = new ObjectOutputStream(buffout); | |||||
oos.writeObject(figures); | |||||
oos.flush(); | |||||
oos.close(); | |||||
} | |||||
public void ladeDatei(String dateiname) throws FileNotFoundException, IOException, ClassNotFoundException | |||||
{ | |||||
FileInputStream fis = new FileInputStream(dateiname); | |||||
BufferedInputStream buffin = new BufferedInputStream(fis); | |||||
ObjectInputStream ois = new ObjectInputStream(buffin); | |||||
Object obj = ois.readObject(); | |||||
// if (obj instanceof ArrayList) | |||||
// { | |||||
// punkte = (ArrayList<Point>) obj; | |||||
// } | |||||
// else | |||||
// { | |||||
// Fehler .... | |||||
// } | |||||
figures = (ArrayList<Figure>) ois.readObject(); | |||||
ois.close(); | |||||
} | |||||
} |