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 package fr.ifremer.isisfish.entity;
27
28 import static org.nuiton.i18n.I18n.t;
29
30 import java.awt.HeadlessException;
31 import java.util.ArrayList;
32 import java.util.List;
33
34 import javax.swing.Box;
35 import javax.swing.JDialog;
36 import javax.swing.JOptionPane;
37 import javax.swing.SwingUtilities;
38
39 import org.apache.commons.logging.Log;
40 import org.apache.commons.logging.LogFactory;
41 import org.nuiton.math.matrix.MatrixFactory;
42 import org.nuiton.math.matrix.MatrixIterator;
43 import org.nuiton.math.matrix.MatrixND;
44 import org.nuiton.math.matrix.gui.MatrixPanelEditor;
45 import org.junit.Test;
46
47 import fr.ifremer.isisfish.AbstractIsisFishTest;
48
49
50
51
52
53
54
55
56
57
58
59
60 public class PopulationSeasonInfoTest extends AbstractIsisFishTest {
61
62
63 private static final Log log = LogFactory.getLog(PopulationSeasonInfoTest.class);
64
65
66
67
68 @Test
69 public void testGetGroupChangeMatrix() throws InterruptedException {
70
71 int nbrAge = 3;
72 int nbrZone = 2;
73 boolean groupplus = true;
74
75 List<String> sem = new ArrayList<String>();
76
77 for (int i = 0; i < nbrAge; i++) {
78 for (int j = 0; j < nbrZone; j++) {
79 sem.add("g" + i + "/z" + j);
80 }
81 }
82
83 MatrixND mat = MatrixFactory.getInstance().create(
84 new List[] { sem, sem });
85 for (MatrixIterator mi = mat.iterator(); mi.next();) {
86 int[] dim = mi.getCoordinates();
87 int i = dim[0];
88 int j = dim[1];
89
90 if (
91
92 (i + nbrZone == j) ||
93 (groupplus
94
95 && (nbrAge - 1 == i / nbrZone)
96
97 && (i == j))) {
98 mi.setValue(1);
99 }
100 }
101
102 final MatrixPanelEditor panel = new MatrixPanelEditor(false, 800, 300);
103 panel.setMatrix(mat);
104 try {
105 final JDialog dialog = new JDialog();
106 SwingUtilities.invokeLater(new Runnable() {
107 @Override
108 public void run() {
109
110 JOptionPane.showMessageDialog(dialog, panel,
111 t("Spacialized visualisation"),
112 JOptionPane.INFORMATION_MESSAGE);
113
114 }
115 });
116
117 Thread t = new Thread(new Runnable() {
118 public void run() {
119 try {
120 Thread.sleep(1000);
121 } catch (InterruptedException e) {
122
123 }
124 dialog.dispose();
125 }
126 });
127 t.start();
128
129
130
131 t.join();
132 } catch (HeadlessException he) {
133 if (log.isErrorEnabled()) {
134 log.error("No X11 display available", he);
135 }
136 }
137 }
138
139
140
141
142 @Test
143 public void testSpacializeLengthChangeMatrix() throws InterruptedException {
144
145 int nbsecteurs = 2;
146 int nbclasses = 3;
147
148 MatrixND mat = MatrixFactory.getInstance().create(
149 new int[] { nbclasses, nbclasses });
150 int i = 1;
151 for (MatrixIterator mi = mat.iterator(); mi.next();) {
152 mi.setValue(i++);
153 }
154
155 List<String> sem = new ArrayList<String>();
156
157 for (i = 0; i < nbclasses; i++) {
158 for (int j = 0; j < nbsecteurs; j++) {
159 sem.add("g" + i + "/z" + j);
160 }
161 }
162
163 MatrixND bigmat = MatrixFactory.getInstance().create(
164 new List[] { sem, sem });
165
166 for (i = 0; i < nbclasses; i++) {
167 for (int j = 0; j < nbclasses; j++) {
168 MatrixND matId = MatrixFactory.getInstance().matrixId(
169 nbsecteurs);
170 matId.mults(mat.getValue(i, j));
171 bigmat.paste(new int[] { i * nbsecteurs, j * nbsecteurs },
172 matId);
173 }
174 }
175
176 MatrixPanelEditor panel = new MatrixPanelEditor(false, 800, 300);
177 panel.setMatrix(mat);
178 MatrixPanelEditor bigpanel = new MatrixPanelEditor(false, 800, 300);
179 bigpanel.setMatrix(bigmat);
180
181 final Box box = Box.createVerticalBox();
182 box.add(panel);
183 box.add(bigpanel);
184
185 try {
186 final JDialog dialog = new JDialog();
187 SwingUtilities.invokeLater(new Runnable() {
188 @Override
189 public void run() {
190
191 JOptionPane.showMessageDialog(dialog, box,
192 t("Spacialized visualisation"),
193 JOptionPane.INFORMATION_MESSAGE);
194
195 }
196 });
197
198 Thread t = new Thread(new Runnable() {
199 public void run() {
200 try {
201 Thread.sleep(1000);
202 } catch (InterruptedException e) {
203
204 }
205 dialog.dispose();
206 }
207 });
208 t.start();
209
210
211
212 t.join();
213 } catch (HeadlessException he) {
214 if (log.isErrorEnabled()) {
215 log.error("No X11 display available", he);
216 }
217 }
218 }
219
220 }