IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Interfaces Graphiques en Java Discussion :

[débutant]Déplacer un équipement


Sujet :

Interfaces Graphiques en Java

  1. #1
    Membre habitué Avatar de pingoui
    Homme Profil pro
    Activité professionnelle sans liens avec le developpement
    Inscrit en
    Juillet 2004
    Messages
    582
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Activité professionnelle sans liens avec le developpement
    Secteur : Industrie

    Informations forums :
    Inscription : Juillet 2004
    Messages : 582
    Points : 185
    Points
    185
    Par défaut [débutant]Déplacer un objet
    Bonjour,

    Je galère depuis plusieurs jours sur un petit problème.... Il me manque pas grand chose.... mais je galère grave !!

    J'ai un équipement électrique
    Cet equipement, à un descriptif et une représentation graphique:


    Mon equipement
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
     
    /**
     * Classe d' équipment du schéma
     */
     
    public class SlipEquipment implements Equipment{
    	  private static final long serialVersionUID = 1L;	  
    	  /** 
               * les propriétés de chaques equipement peuvent être trié  
               */
    	  public enum SortableProperty {NAME, STATION, DEPARTURE, NUMBER,
    	                                 ACTION,MANOEUVRABLE, X, Y, ANGLE, WIDTH, HEIGHT,VISIBLE};	  
     
    	  private String  				name;
    	  private Content 				icon;
    	  private String    			model;
    	  private String 				station;
    	  private String 				departure;
    	  private String  				action;
    	  private boolean 				manoeuvrable;	  
    	  private int     				number;
    	  private float   				x;
    	  private float   				y;
    	  private float   				angle;
    	  private float   				width;
    	  private float   				height;
    	  private boolean    			visible;
     
    	  private GraphicEquipment 		graphicEquipment;
    	  private Equipment 			equipment;
     
    	  private transient Shape 		shapeCache;
     
     
    	  public SlipEquipment(Equipment equipment) {
    		  this.equipment= equipment;
    	    this.name = equipment.getName();
    	    this.icon = equipment.getIcon();
    	    this.model = equipment.getModel();
    	    this.station = equipment.getStation();
    	    this.departure = equipment.getDeparture();
    	    this.action = equipment.getAction();
    	    this.manoeuvrable = equipment.isManoeuvrable();
    	    this.number = equipment.getNumber();
    	    this.width = equipment.getWidth();
    	    this.height = equipment.getHeight();
    	    if (equipment instanceof SlipEquipment) {
    	    	SlipEquipment slipPiece = 
    	            (SlipEquipment)equipment;
    	    	this.graphicEquipment = slipPiece.getGraphicEquipment();
    	        this.visible = slipPiece.isVisible();
    	        this.angle = slipPiece.getAngle();
    	        this.x = slipPiece.getX();
    	        this.y = slipPiece.getY();
    	      } else {
    	        this.visible = true;
    	        this.x = this.width / 2;
    	        this.y = this.height / 2;
    	      }
    	  }
     
    	  /**
               * Renvoie le nom de l'équipement
               */
    	   public String getName() {
    	    return this.name;
    	  }
     
    	   /**
                * Sets the name of this equipment.
                */
    	   void setName(String name) {
    	     this.name = name;
    	   }
     
    	  /**
               * Renvoie l'icone de l'équipement
               */
    	  public Content getIcon() {
    	    return this.icon;
    	  }
     
    	  /**
               * Renvoie le model de l'équipment
               */
    	  public String getModel() {
    	    return this.model;
    	  }
     
    	  /**
               * Renvoie si l'équipement est manoeuvrable
               */
    	  public boolean isManoeuvrable() {
    	    return this.manoeuvrable;
    	  }
     
    	  /**
               * Sets the manoeuvrabilty of this equipment
               */
    	  void setManoeuvrable(boolean manoeuvrable) {
    	    this.manoeuvrable = manoeuvrable;
    	  }
     
    	  /**
               * Returns <code>true</code> if this piece of furniture is visible.
               */
    	  public boolean isVisible() {
    	    return this.visible;
    	  }
     
    	  /**
               * Sets whether this equipment is visible or not.
               * This method should be called from {@link Slip}, which
               * controls notifications when a piece changed.
               */
    	  void setVisible(boolean visible) {
    	    this.visible = visible;
    	  }
     
    	  /**
               * Renvoie le poste d'appartenance de l'équipement
               */
    	  public String getStation() {
    	    return this.station;
    	  }
     
    	   /**
                * Sets the station of this equipment.
                */
    	   void setStation(String station) {
    	     this.station = station;
    	   }
     
    	  /**
               * Renvoie le départ de l'équipement
               */
    	  public String getDeparture() {
    	    return this.departure;
    	  }
     
    	   /**
                * Sets the departure of this equipment.
                */
    	   void setDeparture(String departure) {
    	     this.departure = departure;
    	   }
     
    	  /**
               * Renvoie l'action réaliser par l'équipement
               */
    	  public String getAction() {
    	    return this.action;
    	  }
     
    	   /**
                * Sets the action of this equipment.
                */
    	   void setAction(String action) {
    	     this.action = action;
    	   }
     
    	  /**
               * Renvoie le numéro chronologique de l'action
               */
    	  public int getNumber() {
    	    return this.number;
    	  }
     
    	   /**
                * Sets the number of this equipment.
                */
    	   void setNumber(int number) {
    	     this.number = number;
    	   }
     
    	   /**
                * Returns the width of this equipment.
                */
    	   public float getWidth() {
    		 this.width = getGraphicEquipment().getWidth();
    	     return this.width;
    	   }
     
    	   /**
                * Sets the width of this equipment.
                * This method should be called from {@link Slip}, which
                * controls notifications when a equipment changed.
                */
    	   void setWidth(float width) {
    	     this.width = width;
    	     getGraphicEquipment().setWidth(width);
    	   }
     
    	   /**
                * Returns the height of this piece of furniture.
                */
    	   public float getHeight() {
    		 this.height = getGraphicEquipment().getHeight();
    	     return this.height;
    	   }
     
    	   /**
                * Sets the height of this equipment.
                * This method should be called from {@link Slip}, which
                * controls notifications when a piece changed.
                */
    	   void setHeight(float height) {
    	     this.height = height;
    	     getGraphicEquipment().setHeight(height);
    	   }
     
    	  /**
               * Renvoie l'abscisse de l'équipement
               */
    	  public float getX() {
    		this.x = getGraphicEquipment().getX();
    	    return this.x;
    	  }
     
    	  /**
               * 
               * Modifie l'abscisse de l'équipement
               */
    	  void setX(float x) {
    	    this.x = x;
    	    System.out.println("SlipEquipment setX "+this.x);
    	    getGraphicEquipment().setX(x);	    
    	  }
    	  /**
               * Renvoie l'ordonnée de l'équipement
               */
    	  public float getY() {
    		this.y = getGraphicEquipment().getY();
    	    return this.y;
    	  }
     
    	  /**
               * Modifie l'ordonnée de l'équipement
               */
    	  void setY(float y) {
    	    this.y = y;
    	    System.out.println("SlipEquipment setY "+this.y);
    	    getGraphicEquipment().setY(y);
    	  }
     
    	  /**
               * Renvoie l'angle en radian de l'équipement
               */
    	  public float getAngle() {
    		this.angle = getGraphicEquipment().getAngle();
    	    return this.angle;
    	  }
     
    	  /**
               * Modifie l'angle de l'équipement
               */
    	  void setAngle(float angle) {
    	    this.angle = angle;
    	    getGraphicEquipment().setAngle(angle);
    	  }
     
    	  /**
               * Renvoie l'equipment graphique
               */
    	  public GraphicEquipment getGraphicEquipment() {
    		this.graphicEquipment = GraphicEquipmentManager.getInstance().readGraphicsEquipment(this.equipment.getModel());
    	    return this.graphicEquipment;
    	  }
     
     
     
    	  /**
               * Revoie les points de  contour d'un équipement
               * @return une liste de 4 points de coordonnées(x,y) d'un équipement
               */
    /*	  public float [][] getPoints() {
    	    float [][] piecePoints = new float[4][2];
    	    PathIterator it = getShape().getPathIterator(null);
    	    for (int i = 0; i < piecePoints.length; i++) {
    	      it.currentSegment(piecePoints [i]);
    	      it.next();
    	    }
    	    return piecePoints;
    	  }*/
     
    	  /**
               * Renvoie <code>true</code> si l'équipement est détecté
               * Returns <code>true</code> if this piece intersects
               * with the horizontal rectangle which opposite corners are at points
               * (<code>x0</code>, <code>y0</code>) and (<code>x1</code>, <code>y1</code>).
               */
    	  public boolean intersectsRectangle(float x0, float y0, 
    	                                     float x1, float y1) {
    	    Rectangle2D rectangle = new Rectangle2D.Float(x0, y0, 0, 0);
    	    rectangle.add(x1, y1);
    	    return getGraphicEquipment().getShape().intersects(rectangle);
    	  }
     
    	  /**
               * Renvoie <code>true</code> si l'équipement contient
               * les points (<code>x</code>, <code>y</code>) avec 
               * une marge donnée
               */
    	  public boolean containsPoint(float x, float y, float margin) {
    	    return getGraphicEquipment().getShape().intersects(x - margin, y - margin, 2 * margin, 2 * margin);
    	  }
     
    	  /**
               * Renvoie <code>true</code> si un  des sommets du
               * contour d'un équipement est à une certaine position
               * de la souris
               */
    	  public boolean isVertexAt(float x, float y, float margin) {
    	    for (float [] point : getGraphicEquipment().getPoints()) {
    	      if (Math.abs(x - point[0]) <= margin && Math.abs(y - point[1]) <= margin) {
    	        return true;
    	      }
    	    } 
    	    return false;
    	  }
     
    	  /**
               * Returns <code>true</code> if the top left vertex of this piece is 
               * the point at (<code>x</code>, <code>y</code>)
               * with a given <code>margin</code>.
               */
    	  public boolean isTopLeftVertexAt(float x, float y, float margin) {
    	    float [][] points = getGraphicEquipment().getPoints();
    	    return (Math.abs(x - points[0][0]) <= margin && Math.abs(y - points[0][1]) <= margin);
    	  }
     
    	  /**
               * Returns <code>true</code> if the top right vertex of this piece is 
               * the point at (<code>x</code>, <code>y</code>)
               * with a given <code>margin</code>.
               */
    	  public boolean isTopRightVertexAt(float x, float y, float margin) {
    	    float [][] points = getGraphicEquipment().getPoints();
    	    return Math.abs(x - points[1][0]) <= margin && Math.abs(y - points[1][1]) <= margin;
    	  }
     
    	  /**
               * Returns <code>true</code> if the bottom left vertex of this piece is 
               * the point at (<code>x</code>, <code>y</code>)
               * with a given <code>margin</code>.
               */
    	  public boolean isBottomLeftVertexAt(float x, float y, float margin) {
    	    float [][] points = getGraphicEquipment().getPoints();
    	    return Math.abs(x - points[3][0]) <= margin && Math.abs(y - points[3][1]) <= margin;
    	  }
     
    	  /**
               * Returns <code>true</code> if the bottom right vertex of this piece is 
               * the point at (<code>x</code>, <code>y</code>)
               * with a given <code>margin</code>.
               */
    	  public boolean isBottomRightVertexAt(float x, float y, float margin) {
    	    float [][] points = getGraphicEquipment().getPoints();
    	    return (Math.abs(x - points[2][0]) <= margin && Math.abs(y - points[2][1]) <= margin);
    	  }
    La representation graphique de mon équipement
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    /**
     * Classe de l'équipement dessiné
     * @author Vincent DAMIENS
     */
     
    public class GraphicEquipment implements Serializable{
    	  //Version de la classe
    	  private static final long serialVersionUID = 1L;
    	  public static final long CURRENT_VERSION = 1000;
     
    	  public enum Property {NAME, MODIFIED,
    		    EQUIPMENT_SORTED_PROPERTY, EQUIPMENT_DESCENDING_SORTED,EQUIPMENT_VISIBLE_PROPERTIES,
    		    BACKGROUND_IMAGE, PRINT};
     
    	  private transient List<Object>               		selectedItems;
    	  private transient List<SelectionListener>    		selectionListeners;//Liste des listeners
    	  private Collection<EquipmentLine>                 equipmentLines;//Ensemble de ligne constituant l'équipement
    	  private transient List<EquipmentLineListener>     equipmentLineListeners;//Ensemble des listeners notifiés après une modification des lignes
     
    	  private Shape 									graphicEquipmentArea;
     
    	  private float   									width;
    	  private float   									height;
    	  private float   									x;
    	  private float   									y;
    	  private float   									angle;
     
    	  private transient Shape 							shapeCache;
     
     
    	  private transient boolean                    		modified;
    	  private String                               		name;
    	  private long                                      version;
    	  private transient PropertyChangeSupport     		propertyChangeSupport;
     
     
     
    	  /**
               * Crée un schéma sans équipement
               */
    	  public GraphicEquipment() {
    		    this(new ArrayList<EquipmentLine>());
    		    this.width = getWidth();
    		    this.height = getHeight();
    		    this.x = getX();
    		    this.y = getY();
    		  }
     
     
    	  /**
               * Création des lignes
               */
    	  public GraphicEquipment(List<EquipmentLine> equipmentLines) {
    	    //Initialisation de l'ensemble des lignes 
    	    this.equipmentLines = equipmentLines;
    	    init();
    	  }
     
    	  /**
               * Initializes new and transient home fields to their default values 
               * and reads home from <code>in</code> stream with default reading method.
               */
    	  private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    	    init();
    	    in.defaultReadObject();
    	  }
     
    	  private void init() {		  
    	    // Init transient lists
    	    this.selectedItems = new ArrayList<Object>();
    	    this.selectionListeners = new ArrayList<SelectionListener>();
    	    this.equipmentLineListeners = new ArrayList<EquipmentLineListener>();
    	    this.version = CURRENT_VERSION;
     
    	    this.propertyChangeSupport = new PropertyChangeSupport(this);
    	  }
     
    	  /**
               * Sets the version of this home and writes it to <code>out</code> stream
               * with default writing method. 
               */
    	  private void writeObject(java.io.ObjectOutputStream out) throws IOException {
    		this.version = CURRENT_VERSION;
    	    out.defaultWriteObject();
    	  }
     
    	   /**
                * Returns the width of this piece of furniture.
                */
    	   public float getWidth() {
    		 this.width = (float)getGraphicEquipmentArea().getBounds().getWidth();
    	     return this.width;
    	   }
     
    	   /**
                * Sets the width of this piece of furniture.
                * This method should be called from {@link Home}, which
                * controls notifications when a piece changed.
                */
    	   void setWidth(float width) {
    	     this.width = width;
    	     this.shapeCache = null;
    	   }
     
    	   /**
                * Returns the height of this piece of furniture.
                */
    	   public float getHeight() {
    		 this.height = (float)getGraphicEquipmentArea().getBounds().getHeight();	 
    		 return this.height;
    	   }
     
    	   /**
                * Sets the height of this piece of furniture.
                * This method should be called from {@link Home}, which
                * controls notifications when a piece changed.
                */
    	   void setHeight(float height) {
    	     this.height = height;
    	     this.shapeCache = null;
    	   }
     
    	  /**
               * Renvoie l'abscisse de l'équipement
               */
    	  public float getX() {
    		this.x = (float)getGraphicEquipmentArea().getBounds().getX();
    	    return this.x;
    	  }
     
    	  /**
               * 
               * Modifie l'abscisse de l'équipement
               */
    	  void setX(float x) {
    	    this.x = x;
    	    System.out.println("GraphicEquipment setX() x "+this.x);
    	    setXEquipmentLine(x);
    	    this.shapeCache = null;		
    	  }
     
    	  /**
               * Renvoie l'ordonnée de l'équipement
               */
    	  public float getY() {
    		this.y = (float)getGraphicEquipmentArea().getBounds().getY();		
    	    return this.y;
    	  }
     
    	  /**
               * Modifie l'ordonnée de l'équipement
               */
    	  void setY(float y) {
    	    this.y = y;
    	    System.out.println("GraphicEquipment setY() y "+this.y);
    	    setYEquipmentLine(y);
    	    this.shapeCache = null;
    	  }
     
    	  /**
               * Renvoie l'angle en radian de l'équipement
               */
    	  public float getAngle() {
    	    return this.angle;
    	  }
     
    	  /**
               * Modifie l'angle de l'équipement
               */
    	  void setAngle(float angle) {
    	    this.angle = angle;
    	    this.shapeCache = null;
    	  }
     
     
    	  /**
               * Returns an area matching the union of all <code>lines</code> to do the shapes. 
               */
    	  public Area getGraphicEquipmentArea() {
    		  Area graphicEquipmentArea = new Area();
    		  for (EquipmentLine equipmentLine : this.equipmentLines) {
    			  graphicEquipmentArea.add(new Area(getShape(equipmentLine.getPoints())));			  
    		  }
    		  return graphicEquipmentArea;
    	  }
     
     
    	  public void setXEquipmentLine(float dx) {
    		  System.out.println("GraphicEquipment setBoundsOfEquipmentLine dx "+dx);
    		  for (EquipmentLine equipmentLine : this.equipmentLines) {
    			  equipmentLine.setXStart(dx);
    			  equipmentLine.setXEnd(dx);
    		  }
    	  }
     
    	  public void setYEquipmentLine(float dy) {
    		  System.out.println("GraphicEquipment setBoundsOfEquipmentLine dx "+dy);
    		  for (EquipmentLine equipmentLine : this.equipmentLines) {
    			  equipmentLine.setYStart(dy);
    			  equipmentLine.setYEnd(dy);
    		  }
    	  }
     
     
    	  /**
               * Création d'un chemin qui relie le premier
               * point au autres point.
               */
    	  private Shape getShape(float [][] points) {
    		GeneralPath path = new GeneralPath();
    		path.moveTo(points [0][0], points [0][1]);
    	    for (int i = 1; i < points.length; i++) {
    	    	path.lineTo(points [i][0], points [i][1]);
    	    }
    	    path.closePath();//fermeture du chemin
    	    return path;
    	  }
    [...]
    }

  2. #2
    Membre habitué Avatar de pingoui
    Homme Profil pro
    Activité professionnelle sans liens avec le developpement
    Inscrit en
    Juillet 2004
    Messages
    582
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Activité professionnelle sans liens avec le developpement
    Secteur : Industrie

    Informations forums :
    Inscription : Juillet 2004
    Messages : 582
    Points : 185
    Points
    185
    Par défaut
    suite...

    La representation graphique (symbole) est un assemblage de ligne
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
     
    /**
     * Les traits permettants de créer un équipement
     */
    public class EquipmentLine implements Serializable {
      private static final long serialVersionUID = 1L;
      private float xStart;
      private float yStart;
      private float xEnd;
      private float yEnd; 
      private EquipmentLine  lineAtStart;
      private EquipmentLine  lineAtEnd;
      private float thickness;
     
      private transient float [][] pointsCache;
     
      /**
       * Création de lignes depuis (<code>xStart</code>,<code>yStart</code>)
       * to (<code>xEnd</code>, <code>yEnd</code>), avec une épaiseur donnée 
       */
      public EquipmentLine(float xStart, float yStart, float xEnd, float yEnd, float thickness) {
        this.xStart = xStart;
        this.yStart = yStart;
        this.xEnd = xEnd;
        this.yEnd = yEnd;
        this.thickness = thickness;
      }
     
      /**
       * Créations de lignes depuis une ligne donnée
       */
      public EquipmentLine(EquipmentLine line) {
        this(line.getXStart(), line.getYStart(), 
        	 line.getXEnd(), line.getYEnd(), line.getEquipmentThickness());
      }
     
      /**
       * Renvoie le point d'abscisse de début de ce trait
       */
      public float getXStart() {
        return this.xStart;
      }
     
      /**
       * Modifie le point d'abscisse de début de ce trait
       */
      void setXStart(float xStart) {
        this.xStart = xStart;
        System.out.println("EquipmentLine setXStart "+xStart);
        clearPointsCache();
      }
     
      /**
       * Renvoie le point d'ordonnée de début de ce trait
       */
      public float getYStart() {
        return this.yStart;
      }
     
      /**
       * Modifie le point d'ordonnée de début de ce trait
       */
      void setYStart(float yStart) {
        this.yStart = yStart;
        System.out.println("EquipmentLine setYStart "+yStart);
        clearPointsCache();
      }
     
      /**
       * Renvoie le point d'abscisse de fin de ce trait
       */
      public float getXEnd() {
        return this.xEnd;
      }
     
      /**
       * Modifie le point d'abscisse de fin de ce trait
       */
      void setXEnd(float xEnd) {
        this.xEnd = xEnd;
        System.out.println("EquipmentLine setXEnd "+xEnd);
        clearPointsCache();
      }
     
      /**
       * Renvoie le point d'ordonnée de fin de ce trait
       */
      public float getYEnd() {
        return this.yEnd;
      }
     
      /**
       * Modifie le point d'ordonnée de fin de ce trait
       */
      void setYEnd(float yEnd) {
        this.yEnd = yEnd;
        System.out.println("EquipmentLine setYEnd "+yEnd);
        clearPointsCache();
      }
     
      /**
       * Renvoie le trait joint à ce trait au point de début
       */
      public EquipmentLine getEquipmentLineAtStart() {
        return this.lineAtStart;
      }
     
      /**
       * Modifie le trait joint à ce trait au point de début
       * cette methode ne peut être appeller uniquement par {@link Slip}
       * avec une notification lorsque le trait à été modifié
       */
      void setEquipmentLineAtStart(EquipmentLine lineAtStart) {
        this.lineAtStart = lineAtStart;
        clearPointsCache();
      }
     
      /**
       * Renvoie le trait joint à ce trait au point de fin
       */
      public EquipmentLine getEquipmentLineAtEnd() {
        return this.lineAtEnd;
      }
     
     
      /**
       * Modifie le trait joint à ce trait au point de fin
       * cette methode ne peut être appeller uniquement par {@link Slip}
       * avec une notification lorsque le trait à été modifié
       */
      void setEquipmentLineAtEnd(EquipmentLine lineAtEnd) {
        this.lineAtEnd = lineAtEnd;
        clearPointsCache();
      }
     
      /**
       * Renvoie l'épaisseur du trait
       */
      public float getEquipmentThickness() {
        return this.thickness;
      }
     
      /**
       * Set wall thickness.
       * This method should be called only from {@link Home}, which
       * controls notifications when a wall changed.
       */
      void setEquipmentThickness(float thickness) {
        this.thickness = thickness;
        clearPointsCache();
      }
     
      /**
       * Clears the points cache of this line and of the lines attached to it.
       */
      private void clearPointsCache() {
        this.pointsCache = null;
        if (this.lineAtStart != null ) {
          this.lineAtStart.pointsCache = null;
        }
        if (this.lineAtEnd != null) {
          this.lineAtEnd.pointsCache = null;
        }
      }
     
      /**
       * Renvoie les coordonées des quatres points
       *  décrivant le contour de ce trait
       * @return an array of the 4 (x,y) coordinates of the line corners.
       */
      public float [][] getPoints() {
    	  if (this.pointsCache == null) {
    		  //Calcul des points du contour du rectangle de ce trait
    		  float [][] linePoints = getRectanglePoints();
    		  float limit = 2 * this.thickness;
    		  // Si le trait est joint à son extremité de départ 
    		  // à un autre trait lineAtStart.... 
    		  if (this.lineAtStart != null) {
    			  float [][] lineAtStartPoints = this.lineAtStart.getRectanglePoints();
    			  // Si le trait lineAtStart est joint à ce trait 
    			  // à son extremité de fin....
    			  if (this.lineAtStart.getEquipmentLineAtEnd() == this) {
    				  //....calcul de l'intersection POi de la ligne
    				  //(P0,P1) du trait avec la ligne(P1,P0) du trait
    				  // lineAtStart, et de l'intersection P3i de la ligne
    				  //(P3,P2) de cetrait avec la ligne (P2,P3)
    				  //du trait lineAtStart...
    				  computeIntersection(linePoints [0], linePoints [1], 
    						  lineAtStartPoints [1], lineAtStartPoints [0], limit);
    				  computeIntersection(linePoints [3], linePoints [2],  
    						  lineAtStartPoints [2], lineAtStartPoints [3], limit);
    				  //...si le trait lineAtStart est joint à ce trait
    				  //à son extrémité de départ, faire le m^me calcul
    				  //en inversant les points P0,P1,P2,P3 du trait lineAtStart
    			  } else if (this.lineAtStart.getEquipmentLineAtStart() == this) {
    				  computeIntersection(linePoints [0], linePoints [1], 
    						  lineAtStartPoints [2], lineAtStartPoints [3], limit);
    				  computeIntersection(linePoints [3], linePoints [2],  
    						  lineAtStartPoints [0], lineAtStartPoints [1], limit);
    			  }
    		  }  
    		  // Si le trait à son extremité de fin à un autre
    		  //trait lineAtEnd...
    		  if (this.lineAtEnd != null) {
    			  float [][] lineAtEndPoints = this.lineAtEnd.getRectanglePoints();
    			  //Si le trait lineAtEnd est joint à ce trait
    			  //à son extrémité de départ...
    			  if (lineAtEnd.getEquipmentLineAtStart() == this) {
    				  //....calcul de l'intersection P1i de la ligne
    				  //(P1,P0) du trait avec la ligne(P0,P1) du trait
    				  // lineAtEnd, et de l'intersection P2i de la ligne
    				  //(P2,P3) de cetrait avec la ligne (P3,P2)
    				  //du trait lineAtEnd...
    				  computeIntersection(linePoints [1], linePoints [0], 
    						  lineAtEndPoints [0], lineAtEndPoints [1], limit);
    				  computeIntersection(linePoints [2], linePoints [3], 
    						  lineAtEndPoints [3], lineAtEndPoints [2], limit);
    				  //...si le trait lineAtEnd est joint à ce trait
    				  //à son extrémité de fin, faire le même calcul
    				  //en inversant les points P0,P1,P2,P3 du trait lineAtEnd
    			  } else if (lineAtEnd.getEquipmentLineAtEnd() == this) {
    				  computeIntersection(linePoints [1], linePoints [0],  
    						  lineAtEndPoints [3], lineAtEndPoints [2], limit);
    				  computeIntersection(linePoints [2], linePoints [3], 
    						  lineAtEndPoints [0], lineAtEndPoints [1], limit);
    			  }
    		  }
    	      // Cache shape
    	      this.pointsCache = linePoints;
    	  }
     
    	    return new float [][] {
    	            {this.pointsCache [0][0], this.pointsCache [0][1]},
    	            {this.pointsCache [1][0], this.pointsCache [1][1]},
    	            {this.pointsCache [2][0], this.pointsCache [2][1]},
    	            {this.pointsCache [3][0], this.pointsCache [3][1]}};
      }
     
      /**
       * Renvoie les points du controleur du rectangle de ce trait
       */  
      private float [][] getRectanglePoints() {
        double angle = Math.atan2(this.yEnd - this.yStart, 
                                  this.xEnd - this.xStart);
        float dx = (float)Math.sin(angle) * this.thickness / 2;
        float dy = (float)Math.cos(angle) * this.thickness / 2;
        //renvoie d'un tableau qui contient les coordonées
        // des quatres points P0,P1,P2,P3 du rectangle du trait
        return new float [][] {
                {this.xStart + dx, this.yStart - dy},
                {this.xEnd   + dx, this.yEnd   - dy},
                {this.xEnd   - dx, this.yEnd   + dy},
                {this.xStart - dx, this.yStart + dy}};
     
      }
     
      /**
       * Calcule l'intersection entre la droite joignant les points
       * point1 et point2 et la droite joignant les points point3
       *  et point4, puis stocke le résultat dans le point point1
       */
      private void computeIntersection(float [] point1, float [] point2, 
                                       float [] point3, float [] point4, float limit) {
        float x = point1 [0];
        float y = point1 [1];
        //Calcul des coefficient a1, b1,et a2 b2
        //des équations des deux droites
        float alpha1 = (point2 [1] - point1 [1]) / (point2 [0] - point1 [0]);
        float beta1  = point2 [1] - alpha1 * point2 [0];
        float alpha2 = (point4 [1] - point3 [1]) / (point4 [0] - point3 [0]);
        float beta2  = point4 [1] - alpha2 * point4 [0];
        // Si les deux droites ne sont pas parallèles...
        if (alpha1 != alpha2) {
          // ...calcul de l'intersection si la première
          //droite est verticale
          if (point1 [0] == point2 [0]) {
            x = point1 [0];
            y = alpha2 * x + beta2;
            //...calcul de l'intersection si la seconde
            //droite est verticale
          } else if (point3 [0] == point4 [0]) {
            x = point3 [0];
            y = alpha1 * x + beta1;
            //...sinon calcul de l'intesection et le point
            //point est inférieur à la limite fixée, stockage
            // de l'intersection dans point1        
          } else  {
            x = (beta2 - beta1) / (alpha1 - alpha2);
            y = alpha1 * x + beta1;
          } 
        }
        //Si la distance entre l'intersection et le point
        //point1 est inférieure à la limite fixée, stockage
        //de l'intersection dans point1
        if (Point2D.distanceSq(x, y, point1 [0], point1 [1]) < limit * limit) {
          point1 [0] = x;
          point1 [1] = y;
        }
      }
     
      /**
       * Renvoie true si ce trait a une intersection non vide
       *  avec le rectangle de points opposées (x0,y0) et (x1,y1)
       */
      public boolean intersectsRectangle(float x0, float y0, float x1, float y1) {
        Rectangle2D rectangle = new Rectangle2D.Float(x0, y0, 0, 0);
        rectangle.add(x1, y1);
        return getShape().intersects(rectangle);
      }
     
      /**
       * Renvoie true si ce trait line contient le point
       *  de coordonnées(x,y) avec une tolérance de margin cm
       */
      public boolean containsPoint(float x, float y, float margin) {
        return containsShapeAtWithMargin(getShape(), x, y, margin);
      }
     
      /**
       * Renvoie true si l'extremité de départ de ce trait
       * contient le point(x,y)
       */
      public boolean containsEquipmentLineStartAt(float x, float y, float margin) {
        //Récuparation des points du trait  
    	float [][] linePoints = getPoints();
    	//recherche avec une tolérance margin de
    	//l'intersection entre le point (x,y) et
    	//la ligne(P0,P3) qui correspond à l'extrémité
    	//de départ du trait
        Line2D startLine = new Line2D.Float(linePoints [0][0], linePoints [0][1], linePoints [3][0], linePoints [3][1]);
        return containsShapeAtWithMargin(startLine, x, y, margin);
      }
     
      /**
       * Renvoie true si l'extremité de fin de ce trait
       * contient le point(x,y)
       */
      public boolean containsEquipmentLineEndAt(float x, float y, float margin) {
        //Récuparation des points du trait 
    	float [][] linePoints = getPoints();
    	//recherche avec une tolérance margin de
    	//l'intersection entre le point (x,y) et
    	//la ligne(P1,P2) qui correspond à l'extrémité
    	//de fin du trait
        Line2D endLine = new Line2D.Float(linePoints [1][0], linePoints [1][1], linePoints [2][0], linePoints [2][1]); 
        return containsShapeAtWithMargin(endLine, x, y, margin);
      }
     
      /**
       * Renvoie true si la forme shape contient le point
       * de coordonées (x,y)avec une tolérance de 2 pixels
       */
      private boolean containsShapeAtWithMargin(Shape shape, float x, float y, float margin) {
        return shape.intersects(x - margin, y - margin, 2 * margin, 2 * margin);
      }
     
      /**
       * Renvoie la forme de ce trait
       */
      private Shape getShape() {
    	  float [][] linePoints = getPoints();
        GeneralPath linePath = new GeneralPath();
        linePath.moveTo(linePoints [0][0], linePoints [0][1]);
        for (int i = 1; i < linePoints.length; i++) {
          linePath.lineTo(linePoints [i][0], linePoints [i][1]);
        }
        linePath.closePath();
        return linePath;
      }

    Mon problème lorsque je fais un setX() ou setY() dans SlipEquipment j'aimerai modifier les coordonnées de la representation graphique (GraphicEquipment). mais celui-ci garde ses coordonnée d'origine et ne bouge pas

    Je me doute que c'est pas grand chose... mais je ne trouve pas ce qui bloque

    Merci pour votre aide

  3. #3
    Expert éminent sénior
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Points : 12 977
    Points
    12 977
    Par défaut
    Bah oui mais bon, c'est bien beau tout çà, mais où est ton code de dessin?
    Hey, this is mine. That's mine. All this is mine. I'm claiming all this as mine. Except that bit. I don't want that bit. But all the rest of this is mine. Hey, this has been a really good day. I've eaten five times, I've slept six times, and I've made a lot of things mine. Tomorrow, I'm gonna see if I can't have sex with something.

  4. #4
    Membre habitué Avatar de pingoui
    Homme Profil pro
    Activité professionnelle sans liens avec le developpement
    Inscrit en
    Juillet 2004
    Messages
    582
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Activité professionnelle sans liens avec le developpement
    Secteur : Industrie

    Informations forums :
    Inscription : Juillet 2004
    Messages : 582
    Points : 185
    Points
    185
    Par défaut
    Effectivement

    Ma méthode pour ajouter un equipement à un JComponent
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
      private void paintGraphicEquipment(Graphics2D g2D, List<Object> selectedItems,  
    		  Paint selectionOutlinePaint, Stroke selectionOutlineStroke, 
    		  Paint indicatorPaint, float planScale, 
    		  Color backgroundColor, Color foregroundColor, PaintMode paintMode){
     
      BasicStroke pieceBorderStroke = new BasicStroke(1f / planScale);
      GraphicEquipment graphicEquipment;
    Collection<EquipmentLine> paintedEquipmentLines;
      Shape equipmentLinesArea;
      if (this.sortedSlipEquipment == null) {
    	  // Sort slip equipment
    	  this.sortedSlipEquipment = 
    		  new ArrayList<SlipEquipment>(this.slip.getEquipment());
      }
      // Draw equipment
      for (SlipEquipment piece : this.sortedSlipEquipment) {
          //Je récupere l'équipement graphique
    	  graphicEquipment = piece.getGraphicEquipment();
     
          paintedEquipmentLines = graphicEquipment.getEquipmentLines();
    	  if (piece.isVisible()) {
    			boolean selectedPiece = selectedItems.contains(piece);
      			// In clipboard paint mode, paint piece only if it is selected
      			if (paintMode != PaintMode.CLIPBOARD
      					|| selectedPiece) {
     
     
      				equipmentLinesArea = graphicEquipment.getGraphicEquipmentArea();
      				// Fill equipment area
      				g2D.fill(equipmentLinesArea);
     
      				if (selectedPiece
      						&& paintMode == PaintMode.PAINT) {
      					// Draw selection border
      					g2D.setPaint(selectionOutlinePaint);
      					g2D.setStroke(selectionOutlineStroke);
      					g2D.draw(equipmentLinesArea);
      				}        
      				// Draw its border
      				g2D.setPaint(foregroundColor);
      				g2D.setStroke(pieceBorderStroke);
      				g2D.draw(equipmentLinesArea);
      			}
    	  }
      }
    }

  5. #5
    Expert éminent sénior
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Points : 12 977
    Points
    12 977
    Par défaut
    OK, cf mon post dans ton autre topic, c'est le même problème
    Hey, this is mine. That's mine. All this is mine. I'm claiming all this as mine. Except that bit. I don't want that bit. But all the rest of this is mine. Hey, this has been a really good day. I've eaten five times, I've slept six times, and I've made a lot of things mine. Tomorrow, I'm gonna see if I can't have sex with something.

  6. #6
    Membre habitué Avatar de pingoui
    Homme Profil pro
    Activité professionnelle sans liens avec le developpement
    Inscrit en
    Juillet 2004
    Messages
    582
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Activité professionnelle sans liens avec le developpement
    Secteur : Industrie

    Informations forums :
    Inscription : Juillet 2004
    Messages : 582
    Points : 185
    Points
    185
    Par défaut
    Salut sinok,

    Citation Envoyé par sinok Voir le message
    OK, cf mon post dans ton autre topic, c'est le même problème
    http://www.developpez.net/forums/sho...d.php?t=488021

    Merci pour ton aide


    ps: si toi ou un autre modo peut supprimer l'autre post, il y a pas de problème. je l'ai mis en delestage

  7. #7
    Membre habitué Avatar de pingoui
    Homme Profil pro
    Activité professionnelle sans liens avec le developpement
    Inscrit en
    Juillet 2004
    Messages
    582
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Activité professionnelle sans liens avec le developpement
    Secteur : Industrie

    Informations forums :
    Inscription : Juillet 2004
    Messages : 582
    Points : 185
    Points
    185
    Par défaut
    Bonjour,
    Je suis toujours avec mon problème.
    J'ai inserer des System.out.println() pour suivre la modification de mes coordonnées et arrivé dans ma dernière classe : EquipmentLine ,ma méthode
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    float [][] getRectanglePoints()
    ne prend pas en compte la modification des coordonnées

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
     
      private float [][] getRectanglePoints() {
        double angle = Math.atan2(this.yEnd - this.yStart, 
                                  this.xEnd - this.xStart);
        float dx = (float)Math.sin(angle) * this.thickness / 2;
        float dy = (float)Math.cos(angle) * this.thickness / 2;
     
        System.out.println("EquipmentLine getRectangle x start "+this.xStart );
        System.out.println("EquipmentLine getRectangle y start "+this.yStart );
        //renvoie d'un tableau qui contient les coordonées
        // des quatres points P0,P1,P2,P3 du rectangle du trait
        return new float [][] {
                {this.xStart + dx, this.yStart - dy},
                {this.xEnd   + dx, this.yEnd   - dy},
                {this.xEnd   - dx, this.yEnd   + dy},
                {this.xStart - dx, this.yStart + dy}};
      }

  8. #8
    Membre habitué Avatar de pingoui
    Homme Profil pro
    Activité professionnelle sans liens avec le developpement
    Inscrit en
    Juillet 2004
    Messages
    582
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Activité professionnelle sans liens avec le developpement
    Secteur : Industrie

    Informations forums :
    Inscription : Juillet 2004
    Messages : 582
    Points : 185
    Points
    185
    Par défaut
    Bonjour,
    Je me permets de faire remonter ce post car je n'ai toujours pas trouvé de solution

    Je suis persuadé que ça doit pas être compliqué et que je ne suis pas loin du résultat mais je n'y arrive pas

    Désespérément votre

Discussions similaires

  1. [XL-2007] Débutant : déplacer et empêcher toute modification sur colonne
    Par Mihtsyou dans le forum Macros et VBA Excel
    Réponses: 14
    Dernier message: 14/09/2010, 00h58
  2. [Débutant] Déplacer des fichiers dans un répertoire
    Par nekcorp dans le forum Fortran
    Réponses: 5
    Dernier message: 10/10/2008, 19h59
  3. [C#] [Débutant] Déplacer MessageBox.Show
    Par roque66 dans le forum C#
    Réponses: 4
    Dernier message: 01/03/2008, 19h43
  4. [Débutant] Déplacer un Vertex
    Par tomlev dans le forum DirectX
    Réponses: 3
    Dernier message: 06/09/2007, 11h40
  5. [débutant]déplacer une ligne dans CListCtrl
    Par mouss31 dans le forum MFC
    Réponses: 4
    Dernier message: 30/10/2006, 15h32

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo