Skip to content

Commit b44f91c

Browse files
committed
finally made rest client a bit more like a web browser with a larger url field
1 parent 9b350c6 commit b44f91c

File tree

2 files changed

+114
-37
lines changed

2 files changed

+114
-37
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.thedeanda.ajaxproxy.ui.border;
2+
3+
import java.awt.Color;
4+
import java.awt.Component;
5+
import java.awt.Graphics;
6+
import java.awt.Graphics2D;
7+
import java.awt.Insets;
8+
9+
import javax.swing.UIDefaults;
10+
import javax.swing.border.Border;
11+
12+
public class BottomBorder implements Border {
13+
14+
@Override
15+
public void paintBorder(Component c, Graphics g, int x, int y0, int width,
16+
int height) {
17+
Graphics2D g2 = (Graphics2D) g;
18+
UIDefaults defaults = javax.swing.UIManager.getDefaults();
19+
final Color light = defaults.getColor("SplitPane.highlight");
20+
final Color dark = defaults.getColor("SplitPane.darkShadow");
21+
22+
for (int i = 0; i < width; i += 4) {
23+
int y = height - 2;
24+
g.setColor(light);
25+
g.fillRect(i, y, 2, 2);
26+
g.setColor(dark);
27+
g.fillRect(i, y, 1, 1);
28+
}
29+
//g.drawLine(0, height - 1, width, height - 1);
30+
}
31+
32+
@Override
33+
public Insets getBorderInsets(Component c) {
34+
return new Insets(0, 0, 2, 0);
35+
}
36+
37+
@Override
38+
public boolean isBorderOpaque() {
39+
return true;
40+
}
41+
42+
}

src/main/java/com/thedeanda/ajaxproxy/ui/rest/RestClientPanel.java

Lines changed: 72 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.thedeanda.ajaxproxy.ui.rest;
22

3-
import java.awt.BorderLayout;
3+
import java.awt.Color;
44
import java.awt.Dimension;
55
import java.awt.event.ActionEvent;
66
import java.awt.event.ActionListener;
@@ -18,6 +18,7 @@
1818
import javax.swing.JTextArea;
1919
import javax.swing.JTextField;
2020
import javax.swing.SpringLayout;
21+
import javax.swing.UIDefaults;
2122

2223
import org.apache.commons.io.IOUtils;
2324
import org.apache.commons.lang3.StringUtils;
@@ -28,6 +29,7 @@
2829
import com.thedeanda.ajaxproxy.http.HttpClient.RequestMethod;
2930
import com.thedeanda.ajaxproxy.http.RequestListener;
3031
import com.thedeanda.ajaxproxy.ui.SwingUtils;
32+
import com.thedeanda.ajaxproxy.ui.border.BottomBorder;
3133
import com.thedeanda.ajaxproxy.ui.viewer.RequestViewer;
3234

3335
public class RestClientPanel extends JPanel implements ActionListener {
@@ -47,10 +49,15 @@ public class RestClientPanel extends JPanel implements ActionListener {
4749

4850
public RestClientPanel() {
4951
httpClient = new HttpClient();
52+
SpringLayout layout = new SpringLayout();
53+
setLayout(layout);
54+
55+
JPanel urlPanel = initUrlPanel();
56+
urlPanel.setBorder(new BottomBorder());
57+
add(urlPanel);
5058

5159
JSplitPane mainSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
5260
SwingUtils.flattenSplitPane(mainSplit);
53-
setLayout(new BorderLayout());
5461
add(mainSplit);
5562

5663
JPanel leftPanel = initLeftPanel();
@@ -60,68 +67,96 @@ public RestClientPanel() {
6067
mainSplit.setRightComponent(outputPanel);
6168
mainSplit.setDividerLocation(400);
6269

70+
layout.putConstraint(SpringLayout.NORTH, urlPanel, 0,
71+
SpringLayout.NORTH, this);
72+
layout.putConstraint(SpringLayout.EAST, urlPanel, 0, SpringLayout.EAST,
73+
this);
74+
layout.putConstraint(SpringLayout.WEST, urlPanel, 0, SpringLayout.WEST,
75+
this);
76+
layout.putConstraint(SpringLayout.SOUTH, urlPanel, 50,
77+
SpringLayout.NORTH, this);
78+
79+
layout.putConstraint(SpringLayout.EAST, mainSplit, 0,
80+
SpringLayout.EAST, this);
81+
layout.putConstraint(SpringLayout.WEST, mainSplit, 0,
82+
SpringLayout.WEST, this);
83+
layout.putConstraint(SpringLayout.SOUTH, mainSplit, 0,
84+
SpringLayout.SOUTH, this);
85+
layout.putConstraint(SpringLayout.NORTH, mainSplit, 0,
86+
SpringLayout.SOUTH, urlPanel);
6387
}
6488

65-
public void setDefaultButton() {
66-
getRootPane().setDefaultButton(submitButton);
67-
}
68-
69-
private JPanel initLeftPanel() {
89+
private JPanel initUrlPanel() {
7090
JPanel panel = new JPanel();
7191
SpringLayout layout = new SpringLayout();
7292
panel.setLayout(layout);
73-
panel.setMinimumSize(new Dimension(200, 350));
93+
panel.setMinimumSize(new Dimension(200, 50));
7494

75-
JLabel urlLabel = SwingUtils.newJLabel("Request URL");
95+
JLabel urlLabel = SwingUtils.newJLabel("URL");
7696
urlField = SwingUtils.newJTextField();
97+
panel.add(urlLabel);
7798

78-
JComboBox<String> methods = createMethodDropDown();
79-
panel.add(methods);
99+
urlField = SwingUtils.newJTextField();
100+
panel.add(urlField);
80101

81102
submitButton = new JButton("Submit");
82103
submitButton.addActionListener(this);
83104
panel.add(submitButton);
84105

85-
panel.add(urlLabel);
86-
panel.add(urlField);
87-
88-
JSplitPane split = initLeftSplit();
89-
panel.add(split);
90-
91-
// methods
92-
layout.putConstraint(SpringLayout.EAST, methods, -10,
93-
SpringLayout.EAST, panel);
94-
layout.putConstraint(SpringLayout.NORTH, methods, 20,
95-
SpringLayout.NORTH, panel);
106+
JComboBox<String> methods = createMethodDropDown();
107+
methodCombo = methods;
108+
panel.add(methods);
96109

97110
// url label
98111
layout.putConstraint(SpringLayout.WEST, urlLabel, 10,
99112
SpringLayout.WEST, panel);
100113
layout.putConstraint(SpringLayout.VERTICAL_CENTER, urlLabel, 0,
101114
SpringLayout.VERTICAL_CENTER, methods);
102115

103-
// url field
104-
layout.putConstraint(SpringLayout.NORTH, urlField, 10,
105-
SpringLayout.SOUTH, urlLabel);
106-
layout.putConstraint(SpringLayout.EAST, urlField, -10,
116+
// submit button
117+
layout.putConstraint(SpringLayout.EAST, submitButton, -10,
107118
SpringLayout.EAST, panel);
119+
layout.putConstraint(SpringLayout.VERTICAL_CENTER, submitButton, 0,
120+
SpringLayout.VERTICAL_CENTER, panel);
121+
122+
// method list
123+
layout.putConstraint(SpringLayout.EAST, methods, -10,
124+
SpringLayout.WEST, submitButton);
125+
layout.putConstraint(SpringLayout.VERTICAL_CENTER, methods, 0,
126+
SpringLayout.VERTICAL_CENTER, panel);
127+
128+
// input field
108129
layout.putConstraint(SpringLayout.WEST, urlField, 10,
109-
SpringLayout.WEST, panel);
130+
SpringLayout.EAST, urlLabel);
131+
layout.putConstraint(SpringLayout.VERTICAL_CENTER, urlField, 0,
132+
SpringLayout.VERTICAL_CENTER, methods);
133+
layout.putConstraint(SpringLayout.EAST, urlField, -10,
134+
SpringLayout.WEST, methods);
135+
136+
return panel;
137+
}
138+
139+
public void setDefaultButton() {
140+
getRootPane().setDefaultButton(submitButton);
141+
}
142+
143+
private JPanel initLeftPanel() {
144+
JPanel panel = new JPanel();
145+
SpringLayout layout = new SpringLayout();
146+
panel.setLayout(layout);
147+
panel.setMinimumSize(new Dimension(200, 350));
148+
149+
JSplitPane split = initLeftSplit();
150+
panel.add(split);
110151

111152
// split
112-
layout.putConstraint(SpringLayout.NORTH, split, 10, SpringLayout.SOUTH,
113-
urlField);
153+
layout.putConstraint(SpringLayout.NORTH, split, 24, SpringLayout.NORTH,
154+
panel);
114155
layout.putConstraint(SpringLayout.EAST, split, 0, SpringLayout.EAST,
115156
panel);
116157
layout.putConstraint(SpringLayout.WEST, split, 0, SpringLayout.WEST,
117158
panel);
118159
layout.putConstraint(SpringLayout.SOUTH, split, -10,
119-
SpringLayout.NORTH, submitButton);
120-
121-
// submit button
122-
layout.putConstraint(SpringLayout.EAST, submitButton, -10,
123-
SpringLayout.EAST, panel);
124-
layout.putConstraint(SpringLayout.SOUTH, submitButton, -10,
125160
SpringLayout.SOUTH, panel);
126161

127162
return panel;
@@ -176,7 +211,7 @@ private JPanel initHeadersPanel() {
176211
SpringLayout layout = new SpringLayout();
177212
panel.setLayout(layout);
178213

179-
JLabel headersLabel = SwingUtils.newJLabel("Headers");
214+
JLabel headersLabel = SwingUtils.newJLabel("Request Headers");
180215
headersField = SwingUtils.newJTextArea();
181216

182217
JScrollPane headersScroll = new JScrollPane(headersField);
@@ -230,7 +265,7 @@ private JComboBox<String> createMethodDropDown() {
230265
}
231266
String[] stmp = new String[tmp.size()];
232267
tmp.toArray(stmp);
233-
methodCombo = new JComboBox<String>(stmp);
268+
JComboBox methodCombo = new JComboBox<String>(stmp);
234269
methodCombo.addActionListener(this);
235270
return methodCombo;
236271
}

0 commit comments

Comments
 (0)