Initial revision
[old-projects.git] / ekit / com / hexidec / ekit / component / UserInputAnchorDialog.java
1 /*
2 GNU Lesser General Public License
3
4 UserInputDialog
5 Copyright (C) 2000-2003 Howard Kistler
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22 package com.hexidec.ekit.component;
23
24 import com.hexidec.ekit.EkitCore;
25 import java.awt.Container;
26 import java.awt.Frame;
27 import java.awt.event.ActionEvent;
28 import java.awt.event.ActionListener;
29 import javax.swing.border.*;
30 import javax.swing.BorderFactory;
31 import javax.swing.BoxLayout;
32 import javax.swing.JButton;
33 import javax.swing.JDialog;
34 import javax.swing.JLabel;
35 import javax.swing.JOptionPane;
36 import javax.swing.JPanel;
37 import javax.swing.JTextField;
38 import javax.swing.SwingConstants;
39 import javax.swing.WindowConstants;
40
41 public class UserInputAnchorDialog extends JDialog implements ActionListener
42 {
43 private EkitCore parentEkit;
44 private String inputText = null;
45 private final JTextField jtxfInput = new JTextField(32);
46
47 public UserInputAnchorDialog(EkitCore peKit, String title, boolean bModal, String defaultAnchor)
48 {
49 super(peKit.getFrame(), title, bModal);
50 parentEkit = peKit;
51 jtxfInput.setText(defaultAnchor);
52 init();
53 }
54
55 public void actionPerformed(ActionEvent e)
56 {
57 if(e.getActionCommand().equals("accept"))
58 {
59 inputText = jtxfInput.getText();
60 setVisible(false);
61 }
62 if(e.getActionCommand().equals("cancel"))
63 {
64 inputText = null;
65 setVisible(false);
66 }
67 else if(e.getActionCommand().equals("files"))
68 {
69 String selectedFile = parentEkit.insertFile();
70 if(selectedFile != null)
71 {
72 jtxfInput.setText(selectedFile);
73 }
74 }
75 }
76
77 public void init()
78 {
79 Container contentPane = getContentPane();
80 contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
81 setBounds(100,100,400,300);
82 setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
83
84 JPanel centerPanel = new JPanel();
85 centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.X_AXIS));
86 JLabel anchorLabel = new JLabel("Anchor:", SwingConstants.LEFT);
87 centerPanel.add(anchorLabel);
88 centerPanel.add(jtxfInput);
89
90 JPanel buttonPanel= new JPanel();
91 buttonPanel.setBorder(new SoftBevelBorder(BevelBorder.LOWERED));
92
93 JButton saveButton = new JButton("Accept");
94 saveButton.setActionCommand("accept");
95 saveButton.addActionListener(this);
96
97 JButton cancelButton = new JButton("Cancel");
98 cancelButton.setActionCommand("cancel");
99 cancelButton.addActionListener(this);
100
101 JButton filesButton = new JButton("Server Files...");
102 filesButton.setActionCommand("files");
103 filesButton.addActionListener(this);
104
105 buttonPanel.add(saveButton);
106 buttonPanel.add(cancelButton);
107 buttonPanel.add(filesButton);
108
109 contentPane.add(centerPanel);
110 contentPane.add(buttonPanel);
111
112 this.pack();
113 this.setVisible(true);
114 }
115
116 public String getInputText()
117 {
118 return inputText;
119 }
120
121 public void setAnchor(String anchor)
122 {
123 jtxfInput.setText(anchor);
124 }
125
126
127 }
128