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;
11 import java.awt.event.WindowAdapter;
12 import java.awt.event.WindowEvent;
14 import javax.swing.JButton;
15 import javax.swing.JDialog;
16 import javax.swing.JFrame;
17 import javax.swing.JLabel;
18 import javax.swing.JPanel;
20 import tim.prune.DataSubscriber;
21 import tim.prune.GenericFunction;
22 import tim.prune.I18nManager;
23 import tim.prune.UpdateMessageBroker;
24 import tim.prune.data.Photo;
25 import tim.prune.gui.PhotoThumbnail;
28 * Class to show a popup window for a photo
30 public class PhotoPopupFunction extends GenericFunction implements DataSubscriber
33 private JFrame _frame = null; // would be a JDialog but that doesn't allow max button
34 /** label for filename */
35 private JLabel _label = null;
36 /** Photo thumbnail */
37 private PhotoThumbnail _photoThumb = null;
41 * @param inApp app object
43 public PhotoPopupFunction(App inApp)
51 public String getNameKey() {
52 return "function.photopopup";
62 _frame = new JFrame(I18nManager.getText(getNameKey()));
63 _frame.setIconImage(_parentFrame.getIconImage());
64 _frame.getContentPane().add(makeContents());
66 _frame.setLocationRelativeTo(_parentFrame);
67 _frame.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
68 _frame.addWindowListener(new WindowAdapter() {
69 public void windowClosed(WindowEvent e) {
70 UpdateMessageBroker.removeSubscriber(PhotoPopupFunction.this);
71 super.windowClosed(e);
76 final Photo photo = _app.getTrackInfo().getCurrentPhoto();
77 if (photo.getWidth() <= 0 || photo.getHeight() <= 0)
79 _frame.setVisible(false);
80 _app.showErrorMessageNoLookup(getNameKey(), I18nManager.getText("error.showphoto.failed")
81 + " : " + photo.getName());
85 _frame.setVisible(true);
86 // Add listener to Broker
87 UpdateMessageBroker.addSubscriber(this);
92 * Initialise the frame to show the current photo
94 private void initFrame()
96 Photo photo = _app.getTrackInfo().getCurrentPhoto();
99 _frame.setTitle("GpsPrune - " + I18nManager.getText("details.nophoto"));
100 _label.setText(I18nManager.getText("details.nophoto"));
104 _frame.setTitle(photo.getName());
105 _label.setText("'" + photo.getName() + "' ("
106 + photo.getWidth() + " x " + photo.getHeight() + ")");
108 _photoThumb.setPhoto(photo);
112 * @return the contents of the window as a Component
114 private Component makeContents()
116 JPanel mainPanel = new JPanel();
117 mainPanel.setLayout(new BorderLayout());
118 _label = new JLabel("Photo popup");
119 mainPanel.add(_label, BorderLayout.NORTH);
120 _photoThumb = new PhotoThumbnail(false); // specify not in details panel
121 _photoThumb.setPreferredSize(new Dimension(300, 300));
122 mainPanel.add(_photoThumb, BorderLayout.CENTER);
123 // Close button at bottom
124 JPanel okPanel = new JPanel();
125 okPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
126 JButton okButton = new JButton(I18nManager.getText("button.ok"));
127 okButton.addActionListener(new ActionListener()
129 public void actionPerformed(ActionEvent e) {
133 okButton.addKeyListener(new KeyListener() {
134 public void keyPressed(KeyEvent e) {
135 if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {_frame.dispose();}
137 public void keyTyped(KeyEvent e) {}
138 public void keyReleased(KeyEvent e) {}
140 okPanel.add(okButton);
141 mainPanel.add(okPanel, BorderLayout.SOUTH);
145 public void dataUpdated(byte inUpdateType)
147 // Update photo if selection changes
148 if ((inUpdateType & DataSubscriber.SELECTION_CHANGED) > 0)
154 public void actionCompleted(String inMessage) {}