Merge origin/master
Conflicts: src/wuerfelthreads/Start.java src/wuerfelthreads/view/WuerfelView.form src/wuerfelthreads/view/WuerfelView.java
This commit is contained in:
parent
6b02d2b0da
commit
4cba85021a
@ -7,7 +7,9 @@
|
||||
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;
|
||||
@ -28,9 +30,11 @@ public class Start
|
||||
GrafikMenuView view = new GrafikMenuView();
|
||||
GrafikModel model = new GrafikModel();
|
||||
view.getGrafikView1().setModel(model);
|
||||
// view.setModel(model);
|
||||
GrafikController controller = new GrafikController(view, 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);
|
||||
|
109
src/mvcgrafik/controller/BtnController.java
Normal file
109
src/mvcgrafik/controller/BtnController.java
Normal file
@ -0,0 +1,109 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,40 +7,29 @@
|
||||
package mvcgrafik.controller;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.event.MouseMotionListener;
|
||||
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;
|
||||
import mvcgrafik.view.GrafikView;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author le
|
||||
*/
|
||||
public class GrafikController implements MouseMotionListener, MouseListener, ActionListener
|
||||
public class GrafikController implements MouseMotionListener, MouseListener
|
||||
{
|
||||
private GrafikMenuView view;
|
||||
//private GrafikMenuView menuview;
|
||||
private GrafikView view;
|
||||
private GrafikModel model;
|
||||
private Figure figure;
|
||||
private Point p_old;
|
||||
private static Logger lg = OhmLogger.getLogger();
|
||||
|
||||
public GrafikController(GrafikMenuView view, GrafikModel model)
|
||||
public GrafikController(GrafikView view, GrafikModel model)
|
||||
{
|
||||
this.view = view;
|
||||
this.model = model;
|
||||
@ -50,8 +39,6 @@ public class GrafikController implements MouseMotionListener, MouseListener, Act
|
||||
{
|
||||
view.addMouseMotionListener(this);
|
||||
view.addMouseListener(this);
|
||||
view.getBtnOpen().addActionListener(this);
|
||||
view.getBtnSafe().addActionListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -65,7 +52,7 @@ public class GrafikController implements MouseMotionListener, MouseListener, Act
|
||||
Point p = evt.getPoint();
|
||||
if(p_old != null){
|
||||
// view.drawLine(p, p_old);
|
||||
view.getGrafikView1().drawLine(p, p_old);
|
||||
view.drawLine(p, p_old);
|
||||
}
|
||||
p_old = p;
|
||||
figure.addPoint(p);
|
||||
@ -99,7 +86,7 @@ public class GrafikController implements MouseMotionListener, MouseListener, Act
|
||||
if (evt.getButton() == MouseEvent.BUTTON3)
|
||||
{
|
||||
// view.doPrint();
|
||||
view.getGrafikView1().doPrint();
|
||||
view.doPrint();
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,64 +99,5 @@ public class GrafikController implements MouseMotionListener, MouseListener, Act
|
||||
public void mouseExited(MouseEvent e)
|
||||
{
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,7 @@
|
||||
</NonVisualComponents>
|
||||
<Properties>
|
||||
<Property name="defaultCloseOperation" type="int" value="3"/>
|
||||
<Property name="title" type="java.lang.String" value="Zeichentool"/>
|
||||
</Properties>
|
||||
<SyntheticProperties>
|
||||
<SyntheticProperty name="menuBar" type="java.lang.String" value="jMenuBar1"/>
|
||||
@ -55,6 +56,7 @@
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<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"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
|
||||
|
@ -12,6 +12,14 @@ package mvcgrafik.view;
|
||||
public class GrafikMenuView extends javax.swing.JFrame
|
||||
{
|
||||
|
||||
/**
|
||||
* @return the jPanel1
|
||||
*/
|
||||
public javax.swing.JPanel getjPanel1()
|
||||
{
|
||||
return jPanel1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new form GrafikMenuView
|
||||
*/
|
||||
@ -42,6 +50,7 @@ public class GrafikMenuView extends javax.swing.JFrame
|
||||
jMenu2 = new javax.swing.JMenu();
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||
setTitle("Zeichentool");
|
||||
|
||||
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
|
||||
jPanel1.setLayout(jPanel1Layout);
|
||||
|
@ -31,7 +31,7 @@ import mvcgrafik.logger.OhmLogger;
|
||||
public class GrafikView extends JComponent implements Printable
|
||||
{
|
||||
private final static Dimension EINS = new Dimension(1, 1);
|
||||
private final static Logger lg = Logger.getLogger("mvcGrafik");
|
||||
private static Logger lg = OhmLogger.getLogger();
|
||||
private Rectangle2D.Float pixel;
|
||||
private GrafikModel model;
|
||||
private Point old_punkt = null;
|
||||
@ -51,11 +51,16 @@ public class GrafikView extends JComponent implements Printable
|
||||
{
|
||||
Graphics2D g2 = (Graphics2D) this.getGraphics();
|
||||
Line2D.Double line = new Line2D.Double(p.getX(),p.getY(),p_old.getX(),p_old.getY());
|
||||
// pixel.setFrame(p, EINS);
|
||||
g2.draw(line);
|
||||
g2.dispose(); // VERY, VERY WICHTIG
|
||||
}
|
||||
|
||||
public void drawLineG2(Point p, Point p_old, Graphics2D g2)
|
||||
{
|
||||
Line2D.Double line = new Line2D.Double(p.getX(),p.getY(),p_old.getX(),p_old.getY());
|
||||
g2.draw(line);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g)
|
||||
{
|
||||
@ -71,11 +76,9 @@ public class GrafikView extends JComponent implements Printable
|
||||
model.getFigures().forEach(figure -> {
|
||||
old_punkt = null;
|
||||
figure.getPunkte().forEach(punkt -> {
|
||||
// pixel.setFrame(punkt, EINS);
|
||||
// g2.draw(pixel);
|
||||
if(old_punkt != null)
|
||||
{
|
||||
drawLine(punkt, old_punkt);
|
||||
drawLineG2(punkt, old_punkt, g2);
|
||||
}
|
||||
old_punkt = punkt;
|
||||
});
|
||||
@ -110,8 +113,8 @@ public class GrafikView extends JComponent implements Printable
|
||||
if (pageIndex == 1)
|
||||
{
|
||||
g2p.translate(pf.getImageableX(), pf.getImageableY());
|
||||
g2p.scale(pf.getImageableWidth()/pf.getWidth(),
|
||||
pf.getImageableHeight() / pf.getHeight());
|
||||
g2p.scale(pf.getImageableWidth()/this.getWidth(),
|
||||
pf.getImageableHeight() / this.getHeight());
|
||||
super.print(g2p);
|
||||
return Printable.PAGE_EXISTS;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user