[4675] | 1 | package org.greenstone.gatherer.gui;
|
---|
| 2 |
|
---|
| 3 | import java.awt.*;
|
---|
| 4 | import java.awt.event.*;
|
---|
| 5 | import java.io.*;
|
---|
| 6 | import javax.swing.*;
|
---|
| 7 | import org.greenstone.gatherer.Dictionary;
|
---|
| 8 | import org.greenstone.gatherer.Gatherer;
|
---|
| 9 | import org.greenstone.gatherer.file.FileNode;
|
---|
| 10 | import org.greenstone.gatherer.gui.GUIManager;
|
---|
| 11 |
|
---|
| 12 | public class NewFolderPrompt
|
---|
| 13 | extends JDialog
|
---|
| 14 | implements ActionListener {
|
---|
| 15 | private FileNode node;
|
---|
| 16 | private JButton cancel_button;
|
---|
| 17 | private JButton ok_button;
|
---|
| 18 | private JTextField name_field;
|
---|
| 19 | private String name;
|
---|
| 20 | static final private Dimension LABEL_SIZE = new Dimension(100,25);
|
---|
| 21 | static final private Dimension SIZE = new Dimension(300,100);
|
---|
| 22 | public NewFolderPrompt(FileNode node) {
|
---|
| 23 | super(Gatherer.g_man, Gatherer.dictionary.get("NewFolderPrompt.Title"), true);
|
---|
| 24 | this.node = node;
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | public void actionPerformed(ActionEvent event) {
|
---|
| 28 | if(event.getSource() == ok_button) {
|
---|
| 29 | name = name_field.getText();
|
---|
| 30 | }
|
---|
| 31 | else if(event.getSource() == cancel_button) {
|
---|
| 32 | name = null;
|
---|
| 33 | }
|
---|
| 34 | dispose();
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | public String display() {
|
---|
| 38 | setSize(SIZE);
|
---|
| 39 | JPanel content_pane = (JPanel) getContentPane();
|
---|
| 40 | JPanel name_pane = new JPanel();
|
---|
| 41 | JLabel name_label = new JLabel(Gatherer.dictionary.get("NewFolderPrompt.Folder_Name"));
|
---|
| 42 | name_label.setPreferredSize(LABEL_SIZE);
|
---|
| 43 | name_field = new JTextField(getAutomaticName());
|
---|
| 44 | JPanel button_pane = new JPanel();
|
---|
| 45 | ok_button = new JButton(Gatherer.dictionary.get("General.OK"));
|
---|
| 46 | cancel_button = new JButton(Gatherer.dictionary.get("General.Cancel"));
|
---|
| 47 | // Connection
|
---|
| 48 | cancel_button.addActionListener(this);
|
---|
| 49 | ok_button.addActionListener(this);
|
---|
| 50 | // Layout
|
---|
| 51 | name_pane.setLayout(new BorderLayout());
|
---|
| 52 | name_pane.add(name_label, BorderLayout.WEST);
|
---|
| 53 | name_pane.add(name_field, BorderLayout.CENTER);
|
---|
| 54 |
|
---|
| 55 | button_pane.setLayout(new GridLayout(1,2,0,5));
|
---|
| 56 | button_pane.add(ok_button);
|
---|
| 57 | button_pane.add(cancel_button);
|
---|
| 58 |
|
---|
| 59 | content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
| 60 | content_pane.setLayout(new BorderLayout());
|
---|
| 61 | content_pane.add(name_pane, BorderLayout.CENTER);
|
---|
| 62 | content_pane.add(button_pane, BorderLayout.SOUTH);
|
---|
| 63 | // Display
|
---|
| 64 | Rectangle frame_bounds = Gatherer.g_man.getBounds();
|
---|
| 65 | setLocation(frame_bounds.x + (frame_bounds.width - SIZE.width) / 2, frame_bounds.y + (frame_bounds.height - SIZE.height) / 2);
|
---|
| 66 | show();
|
---|
| 67 | return name;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | private String getAutomaticName() {
|
---|
| 71 | File file = node.getFile();
|
---|
| 72 | String default_name = Gatherer.dictionary.get("NewFolderPrompt.Default_Folder_Name");
|
---|
| 73 | File temp_file = new File(file, default_name);
|
---|
| 74 | int count = 1;
|
---|
| 75 | if(temp_file.exists()) {
|
---|
| 76 | temp_file = new File(file, default_name + " " + count);
|
---|
| 77 | count++;
|
---|
| 78 | }
|
---|
| 79 | return temp_file.getName();
|
---|
| 80 | }
|
---|
| 81 | }
|
---|