]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/function/PhotoPopupFunction.java
Version 14, October 2012
[GpsPrune.git] / tim / prune / function / PhotoPopupFunction.java
1 package tim.prune.function;
2
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
12 import javax.swing.JButton;
13 import javax.swing.JFrame;
14 import javax.swing.JLabel;
15 import javax.swing.JPanel;
16 import tim.prune.App;
17 import tim.prune.GenericFunction;
18 import tim.prune.I18nManager;
19 import tim.prune.data.Photo;
20 import tim.prune.gui.PhotoThumbnail;
21
22 /**
23  * Class to show a popup window for a photo
24  */
25 public class PhotoPopupFunction extends GenericFunction
26 {
27         /** popup window */
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;
33
34         /**
35          * Constructor
36          * @param inApp app object
37          */
38         public PhotoPopupFunction(App inApp)
39         {
40                 super(inApp);
41         }
42
43         /**
44          * Get the name key
45          */
46         public String getNameKey() {
47                 return "function.photopopup";
48         }
49
50         /**
51          * Show the screen
52          */
53         public void begin()
54         {
55                 if (_frame == null)
56                 {
57                         _frame = new JFrame(I18nManager.getText(getNameKey()));
58                         _frame.setIconImage(_parentFrame.getIconImage());
59                         _frame.getContentPane().add(makeContents());
60                         _frame.pack();
61                         _frame.setLocationRelativeTo(_parentFrame);
62                 }
63                 initFrame();
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());
68                 }
69                 else {
70                         _frame.setVisible(true);
71                 }
72         }
73
74         /**
75          * Initialise the frame to show the current photo
76          */
77         private void initFrame()
78         {
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);
85         }
86
87         /**
88          * @return the contents of the window as a Component
89          */
90         private Component makeContents()
91         {
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()
104                 {
105                         public void actionPerformed(ActionEvent e) {
106                                 _frame.dispose();
107                         }
108                 });
109                 okButton.addKeyListener(new KeyListener() {
110                         public void keyPressed(KeyEvent e) {
111                                 if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {_frame.dispose();}
112                         }
113                         public void keyTyped(KeyEvent e) {}
114                         public void keyReleased(KeyEvent e) {}
115                 });
116                 okPanel.add(okButton);
117                 mainPanel.add(okPanel, BorderLayout.SOUTH);
118                 return mainPanel;
119         }
120 }