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 package com.drazzib.netpisteur.monitor;
28
29 import java.io.BufferedWriter;
30 import java.io.FileWriter;
31 import java.io.IOException;
32 import java.io.PrintWriter;
33 import java.io.WriteAbortedException;
34 import java.util.ArrayList;
35
36 import org.apache.commons.logging.Log;
37 import org.apache.commons.logging.LogFactory;
38
39 /**
40 * Represents the list of the placements of the mouse
41 *
42 * @author NetPisteur Team
43 */
44
45 public class ListPlacement {
46
47 private static Log log = LogFactory.getLog(ListPlacement.class);
48
49
50
51
52
53 private ArrayList lesPlacements;
54
55
56 private int nbrePlacement;
57
58
59
60
61 public ListPlacement() {
62 this.lesPlacements = new ArrayList();
63 this.nbrePlacement = 0;
64 }
65
66
67
68 /**
69 * add a new object Placement in the array
70 *
71 * @param placCourant :
72 * object Placement which you want to add
73 */
74 public void addPlacement(Placement placCourant) {
75 this.lesPlacements.add(this.nbrePlacement, placCourant);
76 this.nbrePlacement++;
77 }
78
79 /**
80 * give the object Placement corresponding with the index of array. if the
81 * object doesn't exist, the method return a null object
82 *
83 * @param index :
84 * index of the array
85 *
86 * @return object Placement which has been found
87 */
88 public Placement getPlacement(int index) {
89 Placement lePlacement;
90 if (index >= this.nbrePlacement) {
91
92 throw new RuntimeException("Any placement found\n");
93 }
94 lePlacement = (Placement) this.lesPlacements.get(index);
95
96 return lePlacement;
97 }
98
99 /**
100 * writeListePlacementToDisk() : write all the informations wich the array
101 * has compil:
102 *
103 * @return boolean (true if there is no problem with the write. else it's
104 * false )
105 *
106 */
107 public boolean writeListePlacementToDisk(String fic, String sep) {
108 int ord, abs;
109 Placement lePlacement;
110 PrintWriter out;
111 String file = fic;
112 boolean retour = false;
113
114 try {
115
116 out = new PrintWriter(new BufferedWriter(new FileWriter(file)));
117 if (this.nbrePlacement <= 0) {
118 out.println("\nAucun dplacements de la souris\n");
119
120 }
121 else {
122 out.println("# Liste des placements de la souris : ");
123 for (int i = 0; i < this.nbrePlacement; i++) {
124 lePlacement = (Placement) this.lesPlacements.get(i);
125 abs = lePlacement.getAbs();
126 ord = lePlacement.getOrd();
127 out.println(abs + "x" + ord + sep + lePlacement.getHours()
128 + ":" + lePlacement.getMinutes() + ":"
129 + lePlacement.getSeconds() + "");
130 }
131
132 }
133
134
135 out.close();
136 retour = true;
137
138 } catch (WriteAbortedException e) {
139 log.error("Erreur d'écriture du fichier", e);
140
141 } catch (IOException e) {
142 log.error("Erreur physique de lecture", e);
143
144 }
145
146 return (retour);
147 }
148
149 }
150