source: trunk/gli/src/org/greenstone/gatherer/gui/NewFolderPrompt.java@ 6540

Last change on this file since 6540 was 6318, checked in by jmt12, 21 years ago

Changed JButtons for GLIButtons, which know whether they should paint their background depending on what platform they are run on, and finished keyboard shortcuts

  • Property svn:keywords set to Author Date Id Revision
File size: 4.9 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * <BR><BR>
9 *
10 * Author: John Thompson, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 1999 New Zealand Digital Library Project
15 *
16 * <BR><BR>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * <BR><BR>
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * <BR><BR>
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *########################################################################
36 */
37package org.greenstone.gatherer.gui;
38
39import java.awt.*;
40import java.awt.event.*;
41import java.io.*;
42import javax.swing.*;
43import org.greenstone.gatherer.Dictionary;
44import org.greenstone.gatherer.Gatherer;
45import org.greenstone.gatherer.file.FileNode;
46import org.greenstone.gatherer.gui.GLIButton;
47
48public class NewFolderPrompt
49 extends JDialog
50 implements ActionListener {
51 private FileNode node;
52 private JButton cancel_button;
53 private JButton ok_button;
54 private JTextField name_field;
55 private String name;
56 static final private Dimension LABEL_SIZE = new Dimension(150,25);
57 static final private Dimension SIZE = new Dimension(350,115);
58
59 public NewFolderPrompt(FileNode node) {
60 super(Gatherer.g_man, Dictionary.get("NewFolderPrompt.Title"), true);
61 this.node = node;
62 }
63
64 public void actionPerformed(ActionEvent event) {
65 if (event.getSource() == ok_button) {
66 name = name_field.getText();
67 }
68 else if(event.getSource() == cancel_button) {
69 name = null;
70 }
71 dispose();
72 }
73
74 public String display() {
75 setSize(SIZE);
76 JPanel content_pane = (JPanel) getContentPane();
77
78 JPanel destination_pane = new JPanel();
79 JLabel destination_label = new JLabel();
80 destination_label.setPreferredSize(LABEL_SIZE);
81 Dictionary.setText(destination_label, "NewFolderPrompt.Destination_Name");
82 JTextField destination_textfield = new JTextField(node.getFile().getName());
83 destination_textfield.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
84 destination_textfield.setEditable(false);
85
86 JPanel name_pane = new JPanel();
87 JLabel name_label = new JLabel();
88 name_label.setPreferredSize(LABEL_SIZE);
89 Dictionary.setText(name_label, "NewFolderPrompt.Folder_Name");
90 name_field = new JTextField(getAutomaticName());
91 Dictionary.setTooltip(name_field, "NewFolderPrompt.Folder_Name_Tooltip");
92
93 JPanel button_pane = new JPanel();
94 ok_button = new GLIButton();
95 ok_button.setMnemonic(KeyEvent.VK_O);
96 Dictionary.setBoth(ok_button, "General.OK", "General.OK_Tooltip");
97 cancel_button = new GLIButton();
98 cancel_button.setMnemonic(KeyEvent.VK_C);
99 Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip");
100
101 // Connection
102 cancel_button.addActionListener(this);
103 ok_button.addActionListener(this);
104
105 // Layout
106 destination_pane.setLayout(new BorderLayout());
107 destination_pane.add(destination_label, BorderLayout.WEST);
108 destination_pane.add(destination_textfield, BorderLayout.CENTER);
109
110 name_pane.setBorder(BorderFactory.createEmptyBorder(2,0,0,0));
111 name_pane.setLayout(new BorderLayout());
112 name_pane.add(name_label, BorderLayout.WEST);
113 name_pane.add(name_field, BorderLayout.CENTER);
114
115 button_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
116 button_pane.setLayout(new GridLayout(1,2,0,5));
117 button_pane.add(ok_button);
118 button_pane.add(cancel_button);
119
120 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
121 content_pane.setLayout(new BorderLayout());
122 content_pane.add(destination_pane, BorderLayout.NORTH);
123 content_pane.add(name_pane, BorderLayout.CENTER);
124 content_pane.add(button_pane, BorderLayout.SOUTH);
125
126 // Display
127 Rectangle frame_bounds = Gatherer.g_man.getBounds();
128 setLocation(frame_bounds.x + (frame_bounds.width - SIZE.width) / 2, frame_bounds.y + (frame_bounds.height - SIZE.height) / 2);
129 show();
130 return name;
131 }
132
133 private String getAutomaticName()
134 {
135 File file = node.getFile();
136 String default_name = Dictionary.get("NewFolderPrompt.Default_Folder_Name");
137 File temp_file = new File(file, default_name);
138 int count = 1;
139 while (temp_file.exists()) {
140 temp_file = new File(file, default_name + " " + count);
141 count++;
142 }
143 return temp_file.getName();
144 }
145}
Note: See TracBrowser for help on using the repository browser.