-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDNSResolverWindow.java
More file actions
148 lines (129 loc) · 4.25 KB
/
DNSResolverWindow.java
File metadata and controls
148 lines (129 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import javax.swing.JCheckBox;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.BoxLayout;
public class DNSResolverWindow extends JFrame {
/**
* A button used to begin resolving a url
*/
private JButton goButton;
/**
* A field containing the url to resolve.
*/
private JTextField urlField;
/**
* Label for urlField
*/
private JLabel urlLabel;
/**
* Checkbox to indicate if a recursive lookup is desired.
*/
private JCheckBox recursiveCheck;
/**
* ActionListener for urlField that will enable and disable
* the go button depending on wether the entered text is in the
* form of a url.
*/
private class urlFieldListener implements DocumentListener {
/**
* Enables or disables goButton based on wether the text in
* urlField is a valid url.
*/
private void setState() {
/*
if (urlField.getText().matches(
"[A-z0-9]+\\.[A-z0-9]+\\.[A-z0-9]+(\\.[A-z0-9]+)*")) {
goButton.setEnabled(true);
} else {
goButton.setEnabled(false);
}
*/
goButton.setEnabled(true);
}
/**
* Invoked when text is added into urlField
*
* @param e the event that generated this signal
*/
public void insertUpdate(DocumentEvent e) {
setState();
}
/**
* Invoked when text is removed from urlField
*
* @param e the event that generated this signal
*/
public void removeUpdate(DocumentEvent e) {
setState();
}
/**
* Invoked when text is changed in urlField
*
* @param e the event that generated this signal
*/
public void changedUpdate(DocumentEvent e) {
setState();
}
}
private class GoButtonListener implements ActionListener {
/**
* Called when goButton is pressed.
*
* @param e the event that cause this call
*/
public void actionPerformed(ActionEvent e) {
boolean recursion = recursiveCheck.isSelected();
DNSResolver resolver = new DNSResolver(urlField.getText(),
recursion);
}
}
/**
* Constructs a new DNSResolverWindow with the given title.
*
* @param title the title of the window
*/
public DNSResolverWindow(String title) {
super(title);
// container will eventually be added to this, used only because
// you can't pass a JFrame as a target to BoxLayout
JPanel container = new JPanel();
container.setLayout(new BoxLayout(container, BoxLayout.PAGE_AXIS));
//
// construct the upper part of the window
urlLabel = new JLabel("URL:");
urlField = new JTextField(30);
urlField.getDocument().addDocumentListener(new urlFieldListener());
goButton = new JButton("Resolve");
goButton.setEnabled(false);
goButton.addActionListener(new GoButtonListener());
JPanel upperPanel = new JPanel();
upperPanel.setLayout(new BoxLayout(upperPanel, BoxLayout.LINE_AXIS));
upperPanel.add(urlLabel);
upperPanel.add(urlField);
upperPanel.add(goButton);
container.add(upperPanel);
//
//add bottom part of window
//
recursiveCheck = new JCheckBox("Recursive Desired");
container.add(recursiveCheck);
// add container
this.add(container);
// misc. initialization
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
BoxLayout layout = (BoxLayout)container.getLayout();
this.setSize(
(int)layout.preferredLayoutSize(container).getWidth(),
74);
this.setResizable(false);
this.setVisible(true);
}
}