Import of Ekit 0.9h
[old-projects.git] / ekit / com / hexidec / ekit / component / UserInputAnchorDialog.java
CommitLineData
c2da4d40
JL
1/*
2GNU Lesser General Public License
3
6ce136da
JL
4UserInputAnchorDialog
5Copyright (C) 2000 Howard Kistler
c2da4d40
JL
6
7This library is free software; you can redistribute it and/or
8modify it under the terms of the GNU Lesser General Public
9License as published by the Free Software Foundation; either
10version 2.1 of the License, or (at your option) any later version.
11
12This library is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public
18License along with this library; if not, write to the Free Software
19Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20*/
21
22package com.hexidec.ekit.component;
23
24import com.hexidec.ekit.EkitCore;
25import java.awt.Container;
26import java.awt.Frame;
27import java.awt.event.ActionEvent;
28import java.awt.event.ActionListener;
29import javax.swing.border.*;
30import javax.swing.BorderFactory;
31import javax.swing.BoxLayout;
32import javax.swing.JButton;
33import javax.swing.JDialog;
34import javax.swing.JLabel;
35import javax.swing.JOptionPane;
36import javax.swing.JPanel;
37import javax.swing.JTextField;
38import javax.swing.SwingConstants;
39import javax.swing.WindowConstants;
40
41public 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