1 package tim.prune.function;
3 import java.awt.BorderLayout;
4 import java.awt.Component;
5 import java.awt.Dimension;
6 import java.awt.FlowLayout;
7 import java.awt.event.ActionEvent;
8 import java.awt.event.ActionListener;
9 import java.awt.event.KeyEvent;
10 import java.awt.event.KeyListener;
12 import javax.swing.JButton;
13 import javax.swing.JFrame;
14 import javax.swing.JLabel;
15 import javax.swing.JPanel;
17 import tim.prune.GenericFunction;
18 import tim.prune.I18nManager;
19 import tim.prune.data.Photo;
20 import tim.prune.gui.PhotoThumbnail;
23 * Class to show a popup window for a photo
25 public class PhotoPopupFunction extends GenericFunction
28 private JFrame _frame = null; // would be a JDialog but that doesn't allow max button
29 /** label for filename */
30 private JLabel _label = null;
31 /** Photo thumbnail */
32 private PhotoThumbnail _photoThumb = null;
36 * @param inApp app object
38 public PhotoPopupFunction(App inApp)
46 public String getNameKey() {
47 return "function.photopopup";
57 _frame = new JFrame(I18nManager.getText(getNameKey()));
58 _frame.setIconImage(_parentFrame.getIconImage());
59 _frame.getContentPane().add(makeContents());
61 _frame.setLocationRelativeTo(_parentFrame);
64 final Photo photo = _app.getTrackInfo().getCurrentPhoto();
65 if (photo.getWidth() <= 0 || photo.getHeight() <= 0) {
66 _app.showErrorMessageNoLookup(getNameKey(), I18nManager.getText("error.showphoto.failed")
67 + " : " + photo.getName());
70 _frame.setVisible(true);
75 * Initialise the frame to show the current photo
77 private void initFrame()
79 _frame.setVisible(false);
80 Photo photo = _app.getTrackInfo().getCurrentPhoto();
81 _frame.setTitle(photo.getName());
82 _label.setText("'" + photo.getName() + "' ("
83 + photo.getWidth() + " x " + photo.getHeight() + ")");
84 _photoThumb.setPhoto(photo);
88 * @return the contents of the window as a Component
90 private Component makeContents()
92 JPanel mainPanel = new JPanel();
93 mainPanel.setLayout(new BorderLayout());
94 _label = new JLabel("Photo popup");
95 mainPanel.add(_label, BorderLayout.NORTH);
96 _photoThumb = new PhotoThumbnail(false); // specify not in details panel
97 _photoThumb.setPreferredSize(new Dimension(300, 300));
98 mainPanel.add(_photoThumb, BorderLayout.CENTER);
99 // Close button at bottom
100 JPanel okPanel = new JPanel();
101 okPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
102 JButton okButton = new JButton(I18nManager.getText("button.ok"));
103 okButton.addActionListener(new ActionListener()
105 public void actionPerformed(ActionEvent e) {
109 okButton.addKeyListener(new KeyListener() {
110 public void keyPressed(KeyEvent e) {
111 if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {_frame.dispose();}
113 public void keyTyped(KeyEvent e) {}
114 public void keyReleased(KeyEvent e) {}
116 okPanel.add(okButton);
117 mainPanel.add(okPanel, BorderLayout.SOUTH);