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

Last change on this file since 12119 was 12119, checked in by kjdon, 18 years ago

Changed text handling to use Dictionary.get rather than Dictionary.setText or Dictionary.registerBoth etc. also removed mnemonics cos they suck for other languages

  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 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(Dictionary.get("NewFolderOrFilePrompt.Destination_Name"));
95
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 name_label.setText(Dictionary.get("NewFolderOrFilePrompt.File_Name"));
104 name_field.setToolTipText(Dictionary.get("NewFolderOrFilePrompt.File_Name_Tooltip"));
105 } else {
106 name_label.setText(Dictionary.get("NewFolderOrFilePrompt.Folder_Name"));
107 name_field.setToolTipText(Dictionary.get("NewFolderOrFilePrompt.Folder_Name_Tooltip"));
108 }
109 JPanel button_pane = new JPanel();
110 ok_button = new GLIButton(Dictionary.get("General.OK"), Dictionary.get("General.OK_Tooltip"));
111
112 cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Pure_Cancel_Tooltip"));
113
114 // Connection
115 cancel_button.addActionListener(this);
116 ok_button.addActionListener(this);
117
118 // Layout
119 labels_pane.setLayout(new GridLayout(2,1, 5,0));
120 labels_pane.add(destination_label);
121 labels_pane.add(name_label);
122
123 fields_pane.setLayout(new GridLayout(2,1,0,5));
124 fields_pane.add(destination_textfield);
125 fields_pane.add(name_field);
126
127 info_pane.setLayout(new BorderLayout(5,0));
128 info_pane.add(labels_pane, BorderLayout.WEST);
129 info_pane.add(fields_pane, BorderLayout.CENTER);
130
131 button_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
132 button_pane.setLayout(new GridLayout(1,2,0,5));
133 button_pane.add(ok_button);
134 button_pane.add(cancel_button);
135
136 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
137 content_pane.setLayout(new BorderLayout());
138 content_pane.add(info_pane, BorderLayout.CENTER);
139 content_pane.add(button_pane, BorderLayout.SOUTH);
140
141 // Display
142 Rectangle frame_bounds = Gatherer.g_man.getBounds();
143 setLocation(frame_bounds.x + (frame_bounds.width - SIZE.width) / 2, frame_bounds.y + (frame_bounds.height - SIZE.height) / 2);
144 setVisible(true);
145 return name;
146 }
147
148 private String getAutomaticName()
149 {
150 File file = node.getFile();
151 String default_name;
152 if (type == FileManager.FILE_TYPE) {
153 default_name = Dictionary.get("NewFolderOrFilePrompt.Default_File_Name");
154 } else {
155 default_name = Dictionary.get("NewFolderOrFilePrompt.Default_Folder_Name");
156 }
157
158 File temp_file = new File(file, default_name+extension);
159 int count = 1;
160 while (temp_file.exists()) {
161 temp_file = new File(file, default_name + " " + count+extension);
162 count++;
163 }
164 if (extension.equals("")) {
165 return temp_file.getName();
166 }
167 String name = temp_file.getName();
168 // remove the extension
169 return name.substring(0, name.length()-extension.length());
170
171 }
172}
Note: See TracBrowser for help on using the repository browser.