source: trunk/gli/src/org/greenstone/gatherer/gui/NewFolderOrFilePrompt.java@ 12065

Last change on this file since 12065 was 9112, checked in by kjdon, 19 years ago

renamed NewFolderPrompt to NewFolderOrFilePrompt, now handles file creation too - used for dummy documents

  • Property svn:keywords set to Author Date Id Revision
File size: 5.7 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.Configuration;
44import org.greenstone.gatherer.Dictionary;
45import org.greenstone.gatherer.Gatherer;
46import org.greenstone.gatherer.collection.CollectionTreeNode;
47import org.greenstone.gatherer.file.FileManager;
48
49public class NewFolderOrFilePrompt
50 extends JDialog
51 implements ActionListener {
52 private CollectionTreeNode node;
53 private JButton cancel_button;
54 private JButton ok_button;
55 private JTextField name_field;
56 private String name;
57
58 private int type;
59 private String extension="";
60 static final private Dimension SIZE = new Dimension(350,115);
61
62 public NewFolderOrFilePrompt(CollectionTreeNode node, int type, String extension) {
63 super(Gatherer.g_man, true);
64 if (type == FileManager.FILE_TYPE) {
65 setTitle(Dictionary.get("NewFolderOrFilePrompt.Title_File"));
66 } else {
67 setTitle(Dictionary.get("NewFolderOrFilePrompt.Title_Folder"));
68 }
69 this.type = type;
70 if (extension != null) {
71 this.extension = extension;
72 }
73 this.node = node;
74 }
75
76 public void actionPerformed(ActionEvent event) {
77 if (event.getSource() == ok_button) {
78 name = name_field.getText()+extension;
79 }
80 else if(event.getSource() == cancel_button) {
81 name = null;
82 }
83 dispose();
84 }
85
86 public String display() {
87 setSize(SIZE);
88 JPanel content_pane = (JPanel) getContentPane();
89
90 JPanel labels_pane = new JPanel();
91 JPanel fields_pane = new JPanel();
92 JPanel info_pane = new JPanel();
93
94 JLabel destination_label = new JLabel();
95 Dictionary.setText(destination_label, "NewFolderOrFilePrompt.Destination_Name");
96 JTextField destination_textfield = new JTextField(node.getFile().getName());
97 destination_textfield.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
98 destination_textfield.setEditable(false);
99
100 JLabel name_label = new JLabel();
101 name_field = new JTextField(getAutomaticName());
102 if (type == FileManager.FILE_TYPE) {
103 Dictionary.setText(name_label, "NewFolderOrFilePrompt.File_Name");
104 Dictionary.setTooltip(name_field, "NewFolderOrFilePrompt.File_Name_Tooltip");
105 } else {
106 Dictionary.setText(name_label, "NewFolderOrFilePrompt.Folder_Name");
107 Dictionary.setTooltip(name_field, "NewFolderOrFilePrompt.Folder_Name_Tooltip");
108 }
109 JPanel button_pane = new JPanel();
110 ok_button = new GLIButton();
111 ok_button.setMnemonic(KeyEvent.VK_O);
112 Dictionary.setBoth(ok_button, "General.OK", "General.OK_Tooltip");
113 cancel_button = new GLIButton();
114 cancel_button.setMnemonic(KeyEvent.VK_C);
115 Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip");
116
117 // Connection
118 cancel_button.addActionListener(this);
119 ok_button.addActionListener(this);
120
121 // Layout
122 labels_pane.setLayout(new GridLayout(2,1, 5,0));
123 labels_pane.add(destination_label);
124 labels_pane.add(name_label);
125
126 fields_pane.setLayout(new GridLayout(2,1,0,5));
127 fields_pane.add(destination_textfield);
128 fields_pane.add(name_field);
129
130 info_pane.setLayout(new BorderLayout(5,0));
131 info_pane.add(labels_pane, BorderLayout.WEST);
132 info_pane.add(fields_pane, BorderLayout.CENTER);
133
134 button_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
135 button_pane.setLayout(new GridLayout(1,2,0,5));
136 button_pane.add(ok_button);
137 button_pane.add(cancel_button);
138
139 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
140 content_pane.setLayout(new BorderLayout());
141 content_pane.add(info_pane, BorderLayout.CENTER);
142 content_pane.add(button_pane, BorderLayout.SOUTH);
143
144 // Display
145 Rectangle frame_bounds = Gatherer.g_man.getBounds();
146 setLocation(frame_bounds.x + (frame_bounds.width - SIZE.width) / 2, frame_bounds.y + (frame_bounds.height - SIZE.height) / 2);
147 setVisible(true);
148 return name;
149 }
150
151 private String getAutomaticName()
152 {
153 File file = node.getFile();
154 String default_name;
155 if (type == FileManager.FILE_TYPE) {
156 default_name = Dictionary.get("NewFolderOrFilePrompt.Default_File_Name");
157 } else {
158 default_name = Dictionary.get("NewFolderOrFilePrompt.Default_Folder_Name");
159 }
160
161 File temp_file = new File(file, default_name+extension);
162 int count = 1;
163 while (temp_file.exists()) {
164 temp_file = new File(file, default_name + " " + count+extension);
165 count++;
166 }
167 if (extension.equals("")) {
168 return temp_file.getName();
169 }
170 String name = temp_file.getName();
171 // remove the extension
172 return name.substring(0, name.length()-extension.length());
173
174 }
175}
Note: See TracBrowser for help on using the repository browser.