public void deleteSelectedPhoto() { if (clickedPhoto != null) { if (!album.deletePhoto(clickedPhoto.getFilePath())) JOptionPane.showMessageDialog(null, "Failed to remove photo!", "Error", 2); clickedPhoto = null; updatePhotos(); } }
/** Draws all photos in the album. TODO make photos clickable */ public void drawPhotoThumbnails() { List<PhotoModel> photos = new ArrayList<PhotoModel>(); photos = album.getPhotos(); if (photos.size() > 0) { for (final PhotoModel photo : photos) { BufferedImage img; String name = null; try { File f = new File(photo.getFilePath()); name = f.getName(); img = ImageIO.read(f); // img = ImageIO.read(new File("data//error.png")); } catch (IOException e) { img = errorImage; } ImageIcon icon = new ImageIcon(ImageUtil.getScaledImage(img, 100, 100)); final JButton lbl = new JButton(); lbl.setSize(100, 100); lbl.setIcon(icon); if (name != null) lbl.setText(name); lbl.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (photoClickedCount == 1 && photo.equals(clickedPhoto)) { showPhotoInfoPopup(photo); photoClickedCount = 0; return; } clickedPhoto = photo; photoClickedCount = 1; } }); photosPanel.add(lbl); } } }