1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
|
package paint;
import java.awt.Color;
import java.awt.event.ItemListener;
import javax.swing.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.Graphics;
import java.awt.Point;
import java.io.File;
import java.awt.Dimension;
import java.util.*;
import java.awt.Image;
import java.io.File;
import java.awt.Cursor;
import java.awt.BorderLayout;
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.awt.Rectangle;
import javax.swing.JMenuItem;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
//import java.awt.Rectangle;
/**
*
* @author Aurelie
*/
public class ZoneDeDessin extends JPanel implements MouseListener, MouseMotionListener {
public int type;
public boolean select = false;
public boolean rot = false;
private boolean imgvue = false;
private boolean del = false;
public Point p1 = new Point();
public Point p2 = new Point();
private Color Fcouleur = Color.WHITE;
private Color Ocouleur = Color.BLACK;
public boolean in = true;
private Dimension dim = new Dimension();
public boolean first = true;
public int angle;
public int depart;
public Image image = null;
StairsInfos st = new StairsInfos();
private int j = 0;
public IMoveDrawing LastOneSelc;
// Créaction d'une liste pour dessiner les différents composants
private List drawing = new LinkedList();
// Constructeur
@SuppressWarnings("OverridableMethodCallInConstructor")
public ZoneDeDessin() {
this.setSize(300, 500);
this.setCursor(java.awt.Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
//JScrollPane Scroll = new JScrollPane(this);
this.repaint();
this.setVisible(true);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
/*if (image != null) // Si l'image existe, ...
{
if (this.imgvue) {
Dimension v = this.getSize();
g.drawImage(image, 20, 20, v.width*2, v.height*2, this); // ... on la dessine
}
}*/
for (Iterator it = drawing.iterator(); it.hasNext();) {
IDrawing d = (IDrawing) it.next();
d.draw(g, 2);
}
this.setBackground(Fcouleur);
this.Dessiner(g);
}
public void DelImg() {
this.imgvue = false;
this.repaint();
}
public void MontImg() {
this.imgvue = true;
this.repaint();
}
public void addDrawing(IDrawing d) {
drawing.add(d);
this.repaint();
}
public void Defbackground(Color coul) {
Fcouleur = coul;
this.repaint();
}
public void DefCouleur(Color coul) {
Ocouleur = coul;
}
/**
* Méthode appelée lorsque l'on relâche le clic de souris
*/
public void mouseReleased(MouseEvent event) {
if (select) {
select = false;
}
if (!del) {
switch (type)
{
case 3:
{
dim.height = p2.y - p1.y;
dim.width = p2.x - p1.x;
IDrawing line = new LineDrawing(Ocouleur, p1, dim);
this.addDrawing(line);
} case 1: {
dim.height = p2.x - p1.x;
dim.width = p2.y - p1.y;
IDrawing Rec = new RectangleDrawing(Ocouleur, p1, dim);
this.addDrawing(Rec);
break;
} case 5: {
dim.height = p2.x - p1.x;
dim.width = p2.y - p1.y;
IDrawing Arc = new ArcDrawing(Ocouleur, p1, dim, depart, angle);
this.addDrawing(Arc);
break;
} case 2: {
dim.height = p2.x - p1.x;
dim.width = p2.y - p1.y;
IDrawing cercle = new CercleDrawing(Ocouleur, p1, dim);
this.addDrawing(cercle);
break;
} case 6: {
dim.height = st.ht;
dim.width = st.lm;
IDrawing porte = new StairsDrawing(Ocouleur, p1, dim, st.nbm);
this.addDrawing(porte);
break;
} case 7: {
dim.height = 180;
dim.width = 180;
IDrawing porte = new DoorDrawing(Ocouleur, p1, dim);
this.addDrawing(porte);
break;
}
}
}
}
public void mouseMoved(MouseEvent event) {
}
public void Dessiner(Graphics g) {
if (!del) {
this.setCursor(java.awt.Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
switch (type)
{
case 3:
{
g.drawLine(p1.x, p1.y, p2.x, p2.y);
break;
}
case 1: {
dim.height = p2.x - p1.x;
dim.width = p2.y - p1.y;
g.drawRect(p1.x, p1.y, dim.height, dim.width);
break;
}
case 5: {
dim.height = p2.x - p1.x;
dim.width = p2.y - p1.y;
g.drawArc(p1.x, p1.y, dim.height, dim.width, depart, angle);
break;
}
case 2: {
dim.height = p2.x - p1.x;
dim.width = p2.y - p1.y;
g.drawOval(p1.x, p1.y, dim.width, dim.height);
break;
//CercleDrawing(Color color, Point pos, Dimension dim);
}
}
}
}
} |
Partager