Skip to content

Commit 3a03e52

Browse files
Merge pull request #12 from vykio/LatexMatrix
Latex matrix
2 parents 0abd6c3 + e5c68b1 commit 3a03e52

File tree

9 files changed

+95
-12
lines changed

9 files changed

+95
-12
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
.mtj.tmp/
1212

1313
# Package Files #
14-
*.jar
1514
*.war
1615
*.nar
1716
*.ear

.idea/artifacts/java_rdp_jar.xml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/java-rdp.iml

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/libraries/lib.xml

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/jlatexmath-1.0.7.jar

654 KB
Binary file not shown.

src/com/tech/app/models/Model.java

+48-4
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ private void clearMatrices() {
184184

185185
public void clearAll() {
186186
clearMatrices();
187+
this.nbPlace = 0;
188+
this.nbTransition = 0;
187189
this.placeVector = new ArrayList<Place>();
188190
this.transitionVector = new ArrayList<Transition>();
189191
}
@@ -289,16 +291,58 @@ public void print_W_moins() {
289291
}
290292

291293
public String get_C() {
294+
295+
//Code pour un matrice LaTeX avec labels pour lignes et colonnes
296+
292297
StringBuilder result = new StringBuilder();
293-
result.append("C:\n");
298+
299+
// on utilise un tableau 2X2 ->
300+
// premiere ligne premiere colonne : rien
301+
// première ligne deuxieme colonne : vecteur transitions
302+
// deuxieme ligne première colonne : vecteur places
303+
// deuxieme ligne deuxieme colonne : matrice C
304+
305+
306+
// déclaration du tableau principal, on remplit la premiere case par du vide, et on commence à creer la deuxieme case
307+
result.append("C =\\begin{array}{c c}\\phantom{}&\\begin{array}{");
308+
309+
310+
311+
// centrer les éléments en fonction du nombre de colonnes
312+
for(int k = 0; k < this.transitionVector.size();k++){
313+
result.append("c");
314+
}
315+
result.append("}");
316+
317+
//boucle pour créer la première ligne -> liste de tous les noms des transitions
318+
for(int k = 0; k < this.transitionVector.size();k++){
319+
result.append(this.transitionVector.get(k).getName());
320+
if(k != this.transitionVector.size()-1) result.append("&");
321+
}
322+
323+
result.append("\\end{array}\\\\\\begin{matrix}");
324+
325+
//boucle pour mettre les noms des places
326+
for(int k = 0; k < this.placeVector.size();k++){
327+
result.append(this.placeVector.get(k).getName()).append("\\\\");
328+
}
329+
330+
result.append("\\end{matrix}&\\begin{pmatrix}");
331+
332+
294333
for (int i = 0; i < this.C.size(); i++) {
295-
result.append(i).append(". \t");
334+
if(i>0) result.append("\\\\");
296335
for (int j = 0; j < this.C.get(i).size(); j++) {
297-
result.append(this.C.get(i).get(j)).append(" \t");
336+
if (this.C.get(i).get(j) >= 0) result.append("\\phantom{-}");
337+
result.append(this.C.get(i).get(j));
338+
if(j != this.C.get(i).size()-1) result.append("&");
298339
}
299-
result.append("\n");
340+
300341
}
342+
result.append("\\end{pmatrix}\\end{array}");
343+
System.out.println(result.toString());
301344
return (result.toString());
345+
302346
}
303347

304348
}

src/com/tech/app/models/Transition.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,15 @@ public class Transition {
1414
private double x, y;
1515
private List<Arc> childrens, parents;
1616

17-
private int orientation; // 0 : Verticale; 1 : Horizontale
18-
1917
private final int LARGE_SIDE = 40, MIN_SIDE = 10;
20-
public int WIDTH=MIN_SIDE, HEIGHT=LARGE_SIDE;
18+
public int WIDTH=LARGE_SIDE, HEIGHT=MIN_SIDE;
2119

2220
public Transition(String name, double x, double y, ArrayList<Arc> childrens, ArrayList<Arc> parents) {
2321
this.name = name;
2422
this.x = x;
2523
this.y = y;
2624
this.childrens = childrens;
2725
this.parents = parents;
28-
this.orientation = 0;
2926
this.forme = new Rectangle2D.Float((float) (this.x-(WIDTH/2)), (float) (this.y-(HEIGHT/2)), WIDTH ,HEIGHT );
3027
}
3128

src/com/tech/app/windows/panels/DrawPanel.java

+19-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66
import com.tech.app.models.Model;
77
import com.tech.app.models.Place;
88
import com.tech.app.models.Transition;
9+
import org.scilab.forge.jlatexmath.TeXConstants;
10+
import org.scilab.forge.jlatexmath.TeXFormula;
11+
import org.scilab.forge.jlatexmath.TeXIcon;
912

1013
import javax.swing.*;
1114
import java.awt.*;
1215
import java.awt.geom.AffineTransform;
16+
import java.awt.image.BufferedImage;
1317

1418
/**
1519
* Ordre d'affichage :
@@ -244,9 +248,21 @@ public Object getSelectedObject(double x, double y) {
244248

245249
/* Afficher dans la console le système */
246250
public void showModel() {
247-
model.updateMatrices();
248-
System.out.println(model);
249-
JOptionPane.showMessageDialog(frame.getContentPane(), model.get_C());
251+
if(model.placeVector.size() != 0 && model.transitionVector.size() != 0){
252+
model.updateMatrices();
253+
System.out.println(model);
254+
255+
// mise au format latex de la matrice
256+
TeXFormula formula = new TeXFormula(String.valueOf(model.get_C()));
257+
TeXIcon ti = formula.createTeXIcon(TeXConstants.STYLE_DISPLAY,20);
258+
BufferedImage b = new BufferedImage(ti.getIconWidth(), ti.getIconHeight(), BufferedImage.TYPE_4BYTE_ABGR);
259+
ti.paintIcon(new JOptionPane(), b.getGraphics(), 0, 0);
260+
261+
JOptionPane.showMessageDialog(frame.getContentPane(), null, "Matrice C", JOptionPane.PLAIN_MESSAGE,ti);
262+
} else {
263+
JOptionPane.showMessageDialog(frame.getContentPane(), "Veuillez créer un RDP pour pouvoir créer une matrice", "Erreur", JOptionPane.ERROR_MESSAGE);
264+
}
265+
250266
}
251267

252268
public void showOptions(Object obj) {

0 commit comments

Comments
 (0)