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 | */
|
---|
37 | package org.greenstone.gatherer.gui;
|
---|
38 |
|
---|
39 | import java.awt.*;
|
---|
40 | import java.awt.event.*;
|
---|
41 | import java.io.*;
|
---|
42 | import javax.swing.*;
|
---|
43 | import org.greenstone.gatherer.Configuration;
|
---|
44 | import org.greenstone.gatherer.Dictionary;
|
---|
45 | import org.greenstone.gatherer.Gatherer;
|
---|
46 | import org.greenstone.gatherer.file.FileNode;
|
---|
47 |
|
---|
48 | public 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 SIZE = new Dimension(350,115);
|
---|
57 |
|
---|
58 | public NewFolderPrompt(FileNode node) {
|
---|
59 | super(Gatherer.g_man, Dictionary.get("NewFolderPrompt.Title"), true);
|
---|
60 | this.node = node;
|
---|
61 | }
|
---|
62 |
|
---|
63 | public void actionPerformed(ActionEvent event) {
|
---|
64 | if (event.getSource() == ok_button) {
|
---|
65 | name = name_field.getText();
|
---|
66 | }
|
---|
67 | else if(event.getSource() == cancel_button) {
|
---|
68 | name = null;
|
---|
69 | }
|
---|
70 | dispose();
|
---|
71 | }
|
---|
72 |
|
---|
73 | public String display() {
|
---|
74 | setSize(SIZE);
|
---|
75 | JPanel content_pane = (JPanel) getContentPane();
|
---|
76 |
|
---|
77 | JPanel labels_pane = new JPanel();
|
---|
78 | JPanel fields_pane = new JPanel();
|
---|
79 | JPanel info_pane = new JPanel();
|
---|
80 |
|
---|
81 | JLabel destination_label = new JLabel();
|
---|
82 | Dictionary.setText(destination_label, "NewFolderPrompt.Destination_Name");
|
---|
83 | JTextField destination_textfield = new JTextField(node.getFile().getName());
|
---|
84 | destination_textfield.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
|
---|
85 | destination_textfield.setEditable(false);
|
---|
86 |
|
---|
87 | JLabel name_label = new JLabel();
|
---|
88 | Dictionary.setText(name_label, "NewFolderPrompt.Folder_Name");
|
---|
89 | name_field = new JTextField(getAutomaticName());
|
---|
90 | Dictionary.setTooltip(name_field, "NewFolderPrompt.Folder_Name_Tooltip");
|
---|
91 |
|
---|
92 | JPanel button_pane = new JPanel();
|
---|
93 | ok_button = new GLIButton();
|
---|
94 | ok_button.setMnemonic(KeyEvent.VK_O);
|
---|
95 | Dictionary.setBoth(ok_button, "General.OK", "General.OK_Tooltip");
|
---|
96 | cancel_button = new GLIButton();
|
---|
97 | cancel_button.setMnemonic(KeyEvent.VK_C);
|
---|
98 | Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip");
|
---|
99 |
|
---|
100 | // Connection
|
---|
101 | cancel_button.addActionListener(this);
|
---|
102 | ok_button.addActionListener(this);
|
---|
103 |
|
---|
104 | // Layout
|
---|
105 | labels_pane.setLayout(new GridLayout(2,1, 5,0));
|
---|
106 | labels_pane.add(destination_label);
|
---|
107 | labels_pane.add(name_label);
|
---|
108 |
|
---|
109 | fields_pane.setLayout(new GridLayout(2,1,0,5));
|
---|
110 | fields_pane.add(destination_textfield);
|
---|
111 | fields_pane.add(name_field);
|
---|
112 |
|
---|
113 | info_pane.setLayout(new BorderLayout(5,0));
|
---|
114 | info_pane.add(labels_pane, BorderLayout.WEST);
|
---|
115 | info_pane.add(fields_pane, BorderLayout.CENTER);
|
---|
116 |
|
---|
117 | button_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
|
---|
118 | button_pane.setLayout(new GridLayout(1,2,0,5));
|
---|
119 | button_pane.add(ok_button);
|
---|
120 | button_pane.add(cancel_button);
|
---|
121 |
|
---|
122 | content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
123 | content_pane.setLayout(new BorderLayout());
|
---|
124 | content_pane.add(info_pane, BorderLayout.CENTER);
|
---|
125 | content_pane.add(button_pane, BorderLayout.SOUTH);
|
---|
126 |
|
---|
127 | // Display
|
---|
128 | Rectangle frame_bounds = Gatherer.g_man.getBounds();
|
---|
129 | setLocation(frame_bounds.x + (frame_bounds.width - SIZE.width) / 2, frame_bounds.y + (frame_bounds.height - SIZE.height) / 2);
|
---|
130 | show();
|
---|
131 | return name;
|
---|
132 | }
|
---|
133 |
|
---|
134 | private String getAutomaticName()
|
---|
135 | {
|
---|
136 | File file = node.getFile();
|
---|
137 | String default_name = Dictionary.get("NewFolderPrompt.Default_Folder_Name");
|
---|
138 | File temp_file = new File(file, default_name);
|
---|
139 | int count = 1;
|
---|
140 | while (temp_file.exists()) {
|
---|
141 | temp_file = new File(file, default_name + " " + count);
|
---|
142 | count++;
|
---|
143 | }
|
---|
144 | return temp_file.getName();
|
---|
145 | }
|
---|
146 | }
|
---|