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 _frame.setVisible(true);
68 * Initialise the frame to show the current photo
70 private void initFrame()
72 _frame.setVisible(false);
73 Photo photo = _app.getTrackInfo().getCurrentPhoto();
74 _frame.setTitle(photo.getName());
75 _label.setText("'" + photo.getName() + "' ("
76 + photo.getWidth() + " x " + photo.getHeight() + ")");
77 _photoThumb.setPhoto(photo);
81 * @return the contents of the window as a Component
83 private Component makeContents()
85 JPanel mainPanel = new JPanel();
86 mainPanel.setLayout(new BorderLayout());
87 _label = new JLabel("Photo popup");
88 mainPanel.add(_label, BorderLayout.NORTH);
89 _photoThumb = new PhotoThumbnail(false); // specify not in details panel
90 _photoThumb.setPreferredSize(new Dimension(300, 300));
91 mainPanel.add(_photoThumb, BorderLayout.CENTER);
92 // Close button at bottom
93 JPanel okPanel = new JPanel();
94 okPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
95 JButton okButton = new JButton(I18nManager.getText("button.ok"));
96 okButton.addActionListener(new ActionListener()
98 public void actionPerformed(ActionEvent e) {
102 okButton.addKeyListener(new KeyListener() {
103 public void keyPressed(KeyEvent e) {
104 if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {_frame.dispose();}
106 public void keyTyped(KeyEvent e) {}
107 public void keyReleased(KeyEvent e) {}
109 okPanel.add(okButton);
110 mainPanel.add(okPanel, BorderLayout.SOUTH);