source: trunk/gli/src/org/greenstone/gatherer/gui/GPrompt.java@ 4802

Last change on this file since 4802 was 4675, checked in by jmt12, 21 years ago

Sunday's work

  • Property svn:keywords set to Author Date Id Revision
File size: 5.1 KB
Line 
1package org.greenstone.gatherer.gui;
2/**
3 *#########################################################################
4 *
5 * A component of the Gatherer application, part of the Greenstone digital
6 * library suite from the New Zealand Digital Library Project at the
7 * University of Waikato, New Zealand.
8 *
9 * <BR><BR>
10 *
11 * Author: John Thompson, Greenstone Digital Library, University of Waikato
12 *
13 * <BR><BR>
14 *
15 * Copyright (C) 1999 New Zealand Digital Library Project
16 *
17 * <BR><BR>
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * <BR><BR>
25 *
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
30 *
31 * <BR><BR>
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the Free Software
35 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
36 *########################################################################
37 */
38import java.awt.*;
39import java.awt.event.*;
40import javax.swing.*;
41import org.greenstone.gatherer.Gatherer;
42import org.greenstone.gatherer.util.Utility;
43/**
44 * @author John Thompson, Greenstone Digital Library, University of Waikato
45 * @version 2.1
46 */
47public class GPrompt
48 extends JDialog
49 implements ActionListener {
50
51 private JButton close;
52
53 private JPanel content_pane;
54
55 // Static
56 static private Dimension SIZE = new Dimension(420, 140);
57 static private Dimension TEXT_SIZE = new Dimension(380, 60);
58
59 public GPrompt(Dialog owner, String title, String message, String left_image, String right_image) {
60 super(owner);
61 build_dialog(title, message, left_image, right_image);
62 }
63
64 public GPrompt(Frame owner, String title, String message, String left_image, String right_image) {
65 super(owner);
66 build_dialog(title, message, left_image, right_image);
67 }
68
69 public void actionPerformed(ActionEvent event) {
70 if(event.getSource() == close) {
71 // Check the show setting.
72 this.dispose();
73 }
74 }
75
76 public void destroy() {
77 close = null;
78 content_pane = null;
79 }
80
81 public void display() {
82 this.show();
83 }
84
85 /** This private method creates and lays out the components within this
86 * dialog box based on its arguments.
87 * @param message A String content to be displayed.
88 * @param left_name The name of the left image as a String.
89 * @param right_name The name of the right image as a String.
90 */
91 private void build_dialog(String title, String message, String left_name, String right_name) {
92 this.setModal(true);
93 this.setSize(SIZE);
94 this.setTitle(title);
95
96 // Create components
97 content_pane = (JPanel) this.getContentPane();
98 content_pane.setBackground(Gatherer.config.getColor("coloring.collection_heading_background", false));
99
100 JLabel image_left_label = null;
101 if(left_name != null) {
102 ImageIcon image_left = Utility.getImage(left_name);
103 image_left_label = new JLabel(image_left);
104 image_left_label.setOpaque(false);
105 }
106
107 JPanel text_pane = new JPanel();
108 text_pane.setOpaque(false);
109
110 JTextArea text = new JTextArea(message);
111 text.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
112 text.setColumns(40);
113 text.setEditable(false);
114 text.setLineWrap(true);
115 text.setRows(3);
116 text.setWrapStyleWord(true);
117
118 JLabel image_right_label = null;
119 if(right_name != null) {
120 ImageIcon image_right = Utility.getImage(right_name);
121 image_right_label = new JLabel(image_right);
122 image_right_label.setOpaque(false);
123 }
124
125 close = new JButton(get("General.Close"));
126 close.addActionListener(this);
127 close.setBackground(Gatherer.config.getColor("coloring.button_background", false));
128
129 // Layout components
130 text_pane.setBorder(BorderFactory.createEmptyBorder(0,5,5,5));
131 text_pane.setLayout(new BorderLayout());
132 text_pane.add(text, BorderLayout.CENTER);
133
134 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
135 content_pane.setLayout(new BorderLayout());
136 if(image_left_label != null) {
137 content_pane.add(image_left_label, BorderLayout.WEST);
138 }
139 content_pane.add(text_pane, BorderLayout.CENTER);
140 content_pane.add(close, BorderLayout.SOUTH);
141 if(image_right_label != null) {
142 content_pane.add(image_right_label, BorderLayout.EAST);
143 }
144 // Locate dialog on screen.
145 Dimension screen_size = Gatherer.config.screen_size;
146 this.setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
147 }
148
149 private String get(String key) {
150 return get(key, null);
151 }
152
153 private String get(String key, String args[]) {
154 if(key.indexOf(".") == -1) {
155 key = "GPrompt."+key;
156 }
157 return Gatherer.dictionary.get(key, args);
158 }
159}
Note: See TracBrowser for help on using the repository browser.