1 package tim.prune.function;
3 import java.awt.BorderLayout;
4 import java.awt.Component;
5 import java.awt.FlowLayout;
6 import java.awt.GridLayout;
7 import java.awt.event.ActionEvent;
8 import java.awt.event.ActionListener;
9 import java.awt.event.KeyAdapter;
10 import java.awt.event.KeyEvent;
11 import java.awt.event.MouseAdapter;
13 import javax.swing.BorderFactory;
14 import javax.swing.JButton;
15 import javax.swing.JDialog;
16 import javax.swing.JLabel;
17 import javax.swing.JPanel;
18 import javax.swing.SwingConstants;
21 import tim.prune.Config;
22 import tim.prune.GenericFunction;
23 import tim.prune.I18nManager;
24 import tim.prune.gui.WholeNumberField;
27 * Class to provide the function to set the image size for kmz output
29 public class SetKmzImageSize extends GenericFunction
31 private JDialog _dialog = null;
32 private JButton _okButton = null;
33 private WholeNumberField _widthField = null, _heightField = null;
38 * @param inApp application object for callback
40 public SetKmzImageSize(App inApp)
45 /** Get the name key */
46 public String getNameKey() {
47 return "function.setkmzimagesize";
58 _dialog = new JDialog(_parentFrame, I18nManager.getText(getNameKey()), true);
59 _dialog.setLocationRelativeTo(_parentFrame);
60 _dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
61 _dialog.getContentPane().add(makeDialogComponents());
64 // Initialise values from config
65 _widthField.setValue(Config.getConfigInt(Config.KEY_KMZ_IMAGE_WIDTH));
66 _heightField.setValue(Config.getConfigInt(Config.KEY_KMZ_IMAGE_HEIGHT));
67 _dialog.setVisible(true);
72 * Create dialog components
73 * @return Panel containing all gui elements in dialog
75 private Component makeDialogComponents()
77 JPanel dialogPanel = new JPanel();
78 dialogPanel.setLayout(new BorderLayout());
80 // Make a central panel with the text boxes
81 JPanel mainPanel = new JPanel();
82 mainPanel.setLayout(new GridLayout(0, 2));
83 mainPanel.add(makeRightLabel("dialog.saveconfig.prune.kmzimagewidth"));
84 _widthField = new WholeNumberField(4);
85 mainPanel.add(_widthField);
86 mainPanel.add(makeRightLabel("dialog.saveconfig.prune.kmzimageheight"));
87 _heightField = new WholeNumberField(4);
88 mainPanel.add(_heightField);
89 dialogPanel.add(mainPanel, BorderLayout.CENTER);
91 // Listeners to enable/disable ok button
92 KeyAdapter keyListener = new KeyAdapter() {
94 public void keyReleased(KeyEvent arg0) {
95 _okButton.setEnabled(_widthField.getValue()>0 && _heightField.getValue()>0);
98 MouseAdapter mouseListener = new MouseAdapter() {
99 public void mouseReleased(java.awt.event.MouseEvent arg0) {
100 _okButton.setEnabled(_widthField.getValue()>0 && _heightField.getValue()>0);
103 _widthField.addKeyListener(keyListener);
104 _heightField.addKeyListener(keyListener);
105 _widthField.addMouseListener(mouseListener);
106 _heightField.addMouseListener(mouseListener);
108 // button panel at bottom
109 JPanel buttonPanel = new JPanel();
110 buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
111 _okButton = new JButton(I18nManager.getText("button.ok"));
112 ActionListener okListener = new ActionListener() {
113 public void actionPerformed(ActionEvent e)
118 _okButton.addActionListener(okListener);
119 _okButton.setEnabled(false);
120 buttonPanel.add(_okButton);
121 JButton cancelButton = new JButton(I18nManager.getText("button.cancel"));
122 cancelButton.addActionListener(new ActionListener() {
123 public void actionPerformed(ActionEvent e)
128 buttonPanel.add(cancelButton);
129 dialogPanel.add(buttonPanel, BorderLayout.SOUTH);
130 dialogPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 15));
135 * @param inKey text key
136 * @return right-aligned label
138 private static final JLabel makeRightLabel(String inKey)
140 JLabel label = new JLabel(I18nManager.getText(inKey) + " : ");
141 label.setHorizontalAlignment(SwingConstants.RIGHT);
147 * Finish the dialog when OK pressed
149 private void finish()
151 if (_widthField.getValue() > 0 && _heightField.getValue() > 0)
153 // Set entered values in Config
154 Config.setConfigInt(Config.KEY_KMZ_IMAGE_WIDTH, _widthField.getValue());
155 Config.setConfigInt(Config.KEY_KMZ_IMAGE_HEIGHT, _heightField.getValue());