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
|
public abstract class Materiel extends JPanel implements ActionListener {
private Point position;
private int width;
private int height;
private JPopupMenu monPopup;
private JMenu liaison;
private JMenuItem delete;
private JMenuItem proprietes;
private static int cpt = 0;
private int id;
private String label;
/** Creates a new instance of Dessin */
public Materiel(String image) {
cpt++;
id = cpt;
label = "RITA_"+id;
ImageIcon img = new ImageIcon(image);
width = img.getIconWidth()+5;
height = img.getIconHeight()+5;
this.add(new JLabel(img));
position = new Point(0,0);
this.creerPopup();
}
public Object clone() {
cpt++;
this.id = cpt;
try {
Materiel s = (Materiel) super.clone();
return s;
}
catch (CloneNotSupportedException e) {
return this;
}
}
public boolean equals(Object o) {
return (this.id == ((Materiel)o).id);
}
public Point getPosition() {
return position;
}
public int getId() {
return this.id;
}
public String getLabel() {
return this.label;
}
public void setPosition(Point point) {
position = new Point ((point.x)-(getWidth()/2), (point.y)-(getHeight()/2));
this.setBounds(position.x, position.y, getWidth(), getHeight());
}
public Dimension getDimension() {
return new Dimension (width, height);
}
private void creerPopup() {
monPopup = new JPopupMenu ();
liaison = new JMenu("liaison to");
delete = new JMenuItem ("delete");
delete.addActionListener (this);
proprietes = new JMenuItem ("properties");
proprietes.addActionListener (this);
monPopup.add(liaison);
monPopup.add(delete);
monPopup.add(proprietes);
}
public void showPopup () {
monPopup.show(this, getWidth()/2, getHeight()/2);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == this.delete) {
int reponse = JOptionPane.showConfirmDialog(this,
"Are you sure you want to delete this item ?",
"Delete confirmation",
JOptionPane.YES_NO_OPTION);
if (reponse == JOptionPane.YES_NO_OPTION) {
//Tableau.getInstance().retireMateriel(this);
}
}
if (e.getSource() == this.proprietes) {
afficheDialogue();
}
}
public abstract void afficheDialogue();
} |