1 | package org.greenstone.gatherer.gui;
|
---|
2 |
|
---|
3 | import java.awt.*;
|
---|
4 | import java.awt.event.*;
|
---|
5 | import javax.swing.*;
|
---|
6 | import org.greenstone.gatherer.Configuration;
|
---|
7 | import org.greenstone.gatherer.Dictionary;
|
---|
8 | import org.greenstone.gatherer.Gatherer;
|
---|
9 | import org.greenstone.gatherer.gui.SmarterTextArea;
|
---|
10 | import org.greenstone.gatherer.util.Utility;
|
---|
11 |
|
---|
12 | /** Warn a user that they are about to add folder level metadata. */
|
---|
13 | public class WarningDialog
|
---|
14 | extends JDialog
|
---|
15 | implements ActionListener {
|
---|
16 |
|
---|
17 | static final private Dimension SIZE = new Dimension(400,160);
|
---|
18 |
|
---|
19 | private int result = JOptionPane.CANCEL_OPTION;
|
---|
20 | private JButton cancel_button;
|
---|
21 | private JButton ok_button;
|
---|
22 | private JCheckBox show_check;
|
---|
23 | private String full_property;
|
---|
24 | private String warning_name;
|
---|
25 |
|
---|
26 | public WarningDialog(String full_property, boolean can_cancel) {
|
---|
27 | super(Gatherer.g_man, "Warning", true);
|
---|
28 | // Determine the name of this prompt.
|
---|
29 | this.full_property = full_property;
|
---|
30 | warning_name = full_property.substring(full_property.indexOf(".") + 1);
|
---|
31 | // Now build dialog.
|
---|
32 | setSize(SIZE);
|
---|
33 | setTitle(get("Title"));
|
---|
34 | // Creation
|
---|
35 | JPanel content_pane = (JPanel) getContentPane();
|
---|
36 | JPanel text_pane = new JPanel();
|
---|
37 | JLabel icon_label = new JLabel(Utility.getImage("gatherer_medium.gif"));
|
---|
38 | SmarterTextArea text_area = new SmarterTextArea(get("Message"), false);
|
---|
39 | text_area.setCaretPosition(0);
|
---|
40 | text_area.setLineWrap(true);
|
---|
41 | text_area.setWrapStyleWord(true);
|
---|
42 | JPanel bottom_pane = new JPanel();
|
---|
43 | show_check = new JCheckBox(get("WarningDialog.Dont_Show_Again"), false);
|
---|
44 | JPanel control_pane = new JPanel();
|
---|
45 | ok_button = new JButton(get("General.OK"));
|
---|
46 | cancel_button = new JButton(get("General.Cancel"));
|
---|
47 | // Connection
|
---|
48 | ok_button.addActionListener(this);
|
---|
49 | cancel_button.addActionListener(this);
|
---|
50 | // Layout
|
---|
51 | icon_label.setBorder(BorderFactory.createEmptyBorder(0,0,0,5));
|
---|
52 |
|
---|
53 | text_pane.setLayout(new BorderLayout());
|
---|
54 | text_pane.add(icon_label, BorderLayout.WEST);
|
---|
55 | text_pane.add(new JScrollPane(text_area), BorderLayout.CENTER);
|
---|
56 |
|
---|
57 | if(can_cancel) {
|
---|
58 | control_pane.setLayout(new GridLayout(1,2,5,0));
|
---|
59 | control_pane.add(ok_button);
|
---|
60 | control_pane.add(cancel_button);
|
---|
61 | }
|
---|
62 | else {
|
---|
63 | control_pane.setLayout(new BorderLayout());
|
---|
64 | control_pane.add(ok_button, BorderLayout.EAST);
|
---|
65 | }
|
---|
66 |
|
---|
67 | bottom_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
|
---|
68 | bottom_pane.setLayout(new BorderLayout());
|
---|
69 | bottom_pane.add(show_check, BorderLayout.CENTER);
|
---|
70 | bottom_pane.add(control_pane, BorderLayout.EAST);
|
---|
71 |
|
---|
72 | content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
73 | content_pane.setLayout(new BorderLayout());
|
---|
74 | content_pane.add(text_pane, BorderLayout.CENTER);
|
---|
75 | content_pane.add(bottom_pane, BorderLayout.SOUTH);
|
---|
76 | // Position
|
---|
77 | if(Gatherer.g_man != null) {
|
---|
78 | Rectangle frame_bounds = Gatherer.g_man.getBounds();
|
---|
79 | setLocation(frame_bounds.x + (frame_bounds.width - SIZE.width) / 2, frame_bounds.y + (frame_bounds.height - SIZE.height) / 2);
|
---|
80 | }
|
---|
81 | else {
|
---|
82 | Dimension screen_size = Toolkit.getDefaultToolkit().getScreenSize();
|
---|
83 | setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
|
---|
84 | }
|
---|
85 | }
|
---|
86 |
|
---|
87 | public void actionPerformed(ActionEvent event) {
|
---|
88 | if(event.getSource() == ok_button) {
|
---|
89 | result = JOptionPane.OK_OPTION;
|
---|
90 | }
|
---|
91 | // Store the state of the show message checkbox.
|
---|
92 | Gatherer.config.set(full_property, true, !show_check.isSelected());
|
---|
93 | // Done.
|
---|
94 | dispose();
|
---|
95 | }
|
---|
96 |
|
---|
97 | public int display() {
|
---|
98 | ///ystem.err.println("Show " + full_property + ": " + Gatherer.config.get(full_property, false));
|
---|
99 | if(Gatherer.config.get(full_property, false)) {
|
---|
100 | // We only show if the warning has not been disabled.
|
---|
101 | show();
|
---|
102 | }
|
---|
103 | // We are no longer showing this dialog, so result must always be true.
|
---|
104 | else {
|
---|
105 | result = JOptionPane.OK_OPTION;
|
---|
106 | }
|
---|
107 | return result;
|
---|
108 | }
|
---|
109 |
|
---|
110 | private String get(String key) {
|
---|
111 | if(key.indexOf(".") == -1) {
|
---|
112 | key = warning_name + "." + key;
|
---|
113 | }
|
---|
114 | return Gatherer.dictionary.get(key);
|
---|
115 | }
|
---|
116 | }
|
---|