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
| public void addPhotoMiniatures(LinkedList<String> listOfPhotosInsideDirectory) {
panelMiniaturesPhotos.removeAll();
Iterator<String> i = listOfPhotosInsideDirectory.iterator();
String path;
JLabel tmp1 = null, tmp2 = null, tmp3 = null;
double number = 0;
while(i.hasNext()) {
path = i.next();
ImageIcon photoSelected = new ImageIcon(path);
JLabel pp = new JLabel(photoSelected);
pp.setPreferredSize(new Dimension(190,120));
pp.repaint();
pp.addMouseListener(new OneExifPhotoListener(this, path, pp));
panelMiniaturesPhotos.add(pp);
if(number < 3) { //Pour les 3 premières images
if(number == 0) { //Si c'est la première photo, on la place en haut à gauche
((SpringLayout)panelMiniaturesPhotos.getLayout()).putConstraint(SpringLayout.WEST, pp, 5, SpringLayout.WEST, jsp);
} else { //Sinon, pour les 2eme et 3eme photos, on les place horizontalement à 5 unités de la précédente
((SpringLayout)panelMiniaturesPhotos.getLayout()).putConstraint(SpringLayout.WEST, pp, 5, SpringLayout.EAST, tmp1);
} //La nouvelle photo est placé à 5 unités du bord supérieur du layout
((SpringLayout)panelMiniaturesPhotos.getLayout()).putConstraint(SpringLayout.NORTH, pp, 5, SpringLayout.NORTH, jsp);
} else { //Pour les autres
if(number/3 - Math.round(number/3) == 0) { //Si elle est dans la premiere colonne (multiple de 3), on crée des contraintes pour que la photo soit a 5 unités du bord du layout (horizontalement)
((SpringLayout)panelMiniaturesPhotos.getLayout()).putConstraint(SpringLayout.WEST, pp, 5, SpringLayout.WEST, jsp);
} else { //Sinon, elle est placée horizontalement à 5 unité de la photo précédente
((SpringLayout)panelMiniaturesPhotos.getLayout()).putConstraint(SpringLayout.WEST, pp, 5, SpringLayout.EAST, tmp1);
} //La nouvelle photo est placée 5 unités en dessous de celle placée en avant-avant-dernier.
((SpringLayout)panelMiniaturesPhotos.getLayout()).putConstraint(SpringLayout.NORTH, pp, 5, SpringLayout.SOUTH, tmp3);
}
tmp3 = tmp2;
tmp2 = tmp1;
tmp1 = pp;
number++;
}
panelMiniaturesPhotos.repaint();
} |
Partager