]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/function/PhotoPopupFunction.java
1a81be110ad7636a6a314b8e44942be8e71887b1
[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                 _frame.setVisible(true);
65         }
66
67         /**
68          * Initialise the frame to show the current photo
69          */
70         private void initFrame()
71         {
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);
78         }
79
80         /**
81          * @return the contents of the window as a Component
82          */
83         private Component makeContents()
84         {
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()
97                 {
98                         public void actionPerformed(ActionEvent e) {
99                                 _frame.dispose();
100                         }
101                 });
102                 okButton.addKeyListener(new KeyListener() {
103                         public void keyPressed(KeyEvent e) {
104                                 if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {_frame.dispose();}
105                         }
106                         public void keyTyped(KeyEvent e) {}
107                         public void keyReleased(KeyEvent e) {}
108                 });
109                 okPanel.add(okButton);
110                 mainPanel.add(okPanel, BorderLayout.SOUTH);
111                 return mainPanel;
112         }
113 }