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

Last change on this file since 20957 was 18370, checked in by kjdon, 15 years ago

committed code submitted by Amin Hedjazi for making the GLI right to left. I worked on this code on the rtl-gli branch, then merged the branch back to the trunk at revision 18368. The branch code was slightly different in a couple of places where it shouldn't have been. So don't use the branch code next time. Start a new branch.

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