Skip to content

Commit 79e0e8f

Browse files
committed
优化参数列表,优化参数获取方式
1 parent fb732f7 commit 79e0e8f

File tree

10 files changed

+297
-56
lines changed

10 files changed

+297
-56
lines changed

src/main/java/com/longforus/apidebugger/ui/MainPanel.form

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
<rowspec value="top:4dlu:noGrow"/>
1111
<rowspec value="center:200px:noGrow"/>
1212
<rowspec value="top:4dlu:noGrow"/>
13+
<rowspec value="center:max(d;4px):noGrow"/>
14+
<rowspec value="top:4dlu:noGrow"/>
1315
<rowspec value="center:max(p;600px):grow"/>
1416
<rowspec value="center:max(d;4px):noGrow"/>
1517
<colspec value="fill:d:noGrow"/>
@@ -24,9 +26,9 @@
2426
<colspec value="left:4dlu:noGrow"/>
2527
<colspec value="fill:d:noGrow"/>
2628
<colspec value="left:4dlu:noGrow"/>
27-
<colspec value="fill:max(p;600px):grow"/>
29+
<colspec value="fill:600px:grow"/>
2830
<constraints>
29-
<xy x="20" y="20" width="1375" height="981"/>
31+
<xy x="20" y="20" width="1375" height="996"/>
3032
</constraints>
3133
<properties>
3234
<name value="Api debugger"/>
@@ -80,7 +82,7 @@
8082
</scrollpane>
8183
<scrollpane id="86e31">
8284
<constraints>
83-
<grid row="9" column="0" row-span="1" col-span="11" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
85+
<grid row="11" column="0" row-span="1" col-span="11" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
8486
<forms defaultalign-horz="false" defaultalign-vert="false"/>
8587
</constraints>
8688
<properties>
@@ -98,7 +100,7 @@
98100
</scrollpane>
99101
<component id="8b0f0" class="javax.swing.JLabel" binding="lbStatus">
100102
<constraints>
101-
<grid row="10" column="0" row-span="1" col-span="11" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
103+
<grid row="12" column="0" row-span="1" col-span="11" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
102104
<forms/>
103105
</constraints>
104106
<properties>
@@ -123,7 +125,7 @@
123125
<rowspec value="center:d:grow"/>
124126
<colspec value="fill:d:grow"/>
125127
<constraints>
126-
<grid row="8" column="12" row-span="2" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
128+
<grid row="8" column="12" row-span="4" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
127129
<forms/>
128130
</constraints>
129131
<properties/>
@@ -225,6 +227,24 @@
225227
<text value="Send"/>
226228
</properties>
227229
</component>
230+
<component id="a3dc4" class="javax.swing.JButton" binding="btnAddRow">
231+
<constraints>
232+
<grid row="9" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
233+
<forms/>
234+
</constraints>
235+
<properties>
236+
<text value="Add Row"/>
237+
</properties>
238+
</component>
239+
<component id="5088b" class="javax.swing.JButton" binding="btnDelRow">
240+
<constraints>
241+
<grid row="9" column="4" row-span="1" col-span="7" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
242+
<forms/>
243+
</constraints>
244+
<properties>
245+
<text value="Delete Selected Row"/>
246+
</properties>
247+
</component>
228248
</children>
229249
</grid>
230250
</form>

src/main/java/com/longforus/apidebugger/ui/MainPanel.java

Lines changed: 72 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import java.awt.Dimension;
1212
import java.awt.HeadlessException;
1313
import java.awt.Toolkit;
14+
import java.awt.event.KeyEvent;
15+
import java.awt.event.KeyListener;
1416
import java.awt.event.MouseEvent;
1517
import javax.swing.BorderFactory;
1618
import javax.swing.DefaultComboBoxModel;
@@ -27,7 +29,6 @@
2729
import javax.swing.JTextPane;
2830
import javax.swing.SizeRequirements;
2931
import javax.swing.event.MouseInputAdapter;
30-
import javax.swing.table.DefaultTableModel;
3132
import javax.swing.text.Element;
3233
import javax.swing.text.View;
3334
import javax.swing.text.ViewFactory;
@@ -41,6 +42,7 @@
4142
*/
4243

4344
public class MainPanel extends JFrame {
45+
private final MyTableModel mMyTableModel;
4446
private JComboBox mCbBaseUrl;
4547
private JButton mBtnSaveBaseUrl;
4648
private JComboBox mCbApiUrl;
@@ -57,6 +59,8 @@ public class MainPanel extends JFrame {
5759
private JButton btnDelUrl;
5860
private JButton btnDelApi;
5961
private JComboBox mCbMethod;
62+
private JButton btnAddRow;
63+
private JButton btnDelRow;
6064

6165
public JComboBox getCbMethod() {
6266
return mCbMethod;
@@ -66,6 +70,10 @@ public JTable getTbParame() {
6670
return mTbParame;
6771
}
6872

73+
public MyTableModel getMyTableModel() {
74+
return mMyTableModel;
75+
}
76+
6977
public JComboBox getCbEncrypt() {
7078
return mCbEncrypt;
7179
}
@@ -99,7 +107,7 @@ public int getSelectedEncryptID() {
99107
}
100108

101109
public int getSelectedMethodType() {
102-
return MyValueHandler.INSTANCE.encryptIndex2Id(mCbEncrypt.getSelectedIndex());
110+
return mCbMethod.getSelectedIndex();
103111
}
104112

105113
public MainPanel(String title) throws HeadlessException {
@@ -109,7 +117,8 @@ public MainPanel(String title) throws HeadlessException {
109117
mCbMethod.setModel(new DefaultComboBoxModel(new String[] { "POST", "GET" }));
110118
setContentPane(baseP);
111119
setJMenuBar(UILifecycleHandler.INSTANCE.getMenuBar());
112-
mTbParame.setModel(new DefaultTableModel(new Object[] { "key", "value" }, MyValueHandler.PARAME_TABLE_ROW_COUNT));
120+
mMyTableModel = new MyTableModel();
121+
mTbParame.setModel(mMyTableModel);
113122
mBtnSaveBaseUrl.addActionListener(e -> UIActionHandler.INSTANCE.onSaveBaseUrl(mCbBaseUrl.getModel().getSelectedItem()));
114123
btnDelUrl.addActionListener(e -> UIActionHandler.INSTANCE.onDelBaseUrl(mCbBaseUrl.getModel().getSelectedItem()));
115124
btnDelApi.addActionListener(e -> UIActionHandler.INSTANCE.onDelApiUrl((ApiBean) mCbApiUrl.getModel().getSelectedItem()));
@@ -147,7 +156,7 @@ public void mouseClicked(MouseEvent e) {
147156
}
148157
});
149158
//支持自动换行
150-
mTpResponse.setEditorKit(new HTMLEditorKit() {
159+
HTMLEditorKit editorKit = new HTMLEditorKit() {
151160
@Override
152161
public ViewFactory getViewFactory() {
153162

@@ -193,9 +202,39 @@ protected SizeRequirements calculateMinorAxisRequirements(int axis, SizeRequirem
193202
}
194203
};
195204
}
196-
});
197-
205+
};
206+
mTpResponse.setEditorKit(editorKit);
207+
mTpInfo.setEditorKit(editorKit);
198208
mJep.jTree.setCellRenderer(new JsonTreeCellRenderer());
209+
mTbParame.addKeyListener(new KeyListener() {
210+
@Override
211+
public void keyTyped(KeyEvent e) {
212+
213+
}
214+
215+
@Override
216+
public void keyPressed(KeyEvent e) {
217+
218+
}
219+
220+
@Override
221+
public void keyReleased(KeyEvent e) {
222+
if (e.getKeyCode() == KeyEvent.VK_DELETE) {
223+
mMyTableModel.removeRow(mTbParame.getSelectedRow());
224+
}
225+
}
226+
});
227+
mTbParame.getColumnModel().getColumn(0).setPreferredWidth(50);
228+
mTbParame.getColumnModel().getColumn(1).setPreferredWidth(120);
229+
mTbParame.getColumnModel().getColumn(2).setPreferredWidth(350);
230+
btnAddRow.addActionListener(e -> {
231+
mMyTableModel.addEmptyRow();
232+
mTbParame.requestFocus();
233+
int index = mMyTableModel.getRowCount() - 1;
234+
mTbParame.setRowSelectionInterval(index, index);//最后一行获得焦点
235+
mTbParame.editCellAt(index, 1);
236+
});
237+
btnDelRow.addActionListener(e -> mMyTableModel.removeRow(mTbParame.getSelectedRow()));
199238
pack();
200239
Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();
201240
int x = (int) screensize.getWidth() / 2 - baseP.getPreferredSize().width / 2;
@@ -214,6 +253,22 @@ protected void finalize() throws Throwable {
214253
OB.INSTANCE.onExit();
215254
}
216255

256+
public String getCurApiUrl() {
257+
return mCbApiUrl.getSelectedItem().toString();
258+
}
259+
260+
public int getCurMethod() {
261+
return mCbMethod.getSelectedIndex();
262+
}
263+
264+
public int getCurEncryptCode() {
265+
return mCbMethod.getSelectedIndex();
266+
}
267+
268+
public String getCurBaseUrl() {
269+
return (String) mCbBaseUrl.getSelectedItem();
270+
}
271+
217272
/**
218273
* Method generated by IntelliJ IDEA GUI Designer
219274
* >>> IMPORTANT!! <<<
@@ -226,9 +281,9 @@ protected void finalize() throws Throwable {
226281
baseP = new JPanel();
227282
baseP.setLayout(new FormLayout(
228283
"fill:d:noGrow,left:4dlu:noGrow,fill:300px:noGrow,left:4dlu:noGrow,fill:d:noGrow,left:4dlu:noGrow,fill:max(d;4px):noGrow,left:4dlu:noGrow,fill:d:noGrow," +
229-
"left:4dlu:noGrow,fill:d:noGrow,left:4dlu:noGrow,fill:max(p;600px):grow",
284+
"left:4dlu:noGrow,fill:d:noGrow,left:4dlu:noGrow,fill:600px:grow",
230285
"center:d:noGrow,center:max(d;4px):noGrow,top:4dlu:noGrow,center:max(d;4px):noGrow,top:4dlu:noGrow,center:max(d;4px):noGrow,top:4dlu:noGrow,center:200px:noGrow," +
231-
"top:4dlu:noGrow,center:max(p;600px):grow,center:max(d;4px):noGrow"));
286+
"top:4dlu:noGrow,center:max(d;4px):noGrow,top:4dlu:noGrow,center:max(p;600px):grow,center:max(d;4px):noGrow"));
232287
baseP.setName("Api debugger");
233288
baseP.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1), null));
234289
final JLabel label1 = new JLabel();
@@ -249,20 +304,20 @@ protected void finalize() throws Throwable {
249304
scrollPane1.setViewportView(mTbParame);
250305
final JScrollPane scrollPane2 = new JScrollPane();
251306
scrollPane2.setHorizontalScrollBarPolicy(31);
252-
baseP.add(scrollPane2, cc.xyw(1, 10, 11, CellConstraints.FILL, CellConstraints.FILL));
307+
baseP.add(scrollPane2, cc.xyw(1, 12, 11, CellConstraints.FILL, CellConstraints.FILL));
253308
scrollPane2.setBorder(BorderFactory.createTitledBorder("Response"));
254309
mTpResponse = new JTextPane();
255310
mTpResponse.setPreferredSize(new Dimension(500, 600));
256311
scrollPane2.setViewportView(mTpResponse);
257312
lbStatus = new JLabel();
258313
lbStatus.setText("Status:");
259-
baseP.add(lbStatus, cc.xyw(1, 11, 11));
314+
baseP.add(lbStatus, cc.xyw(1, 13, 11));
260315
final JScrollPane scrollPane3 = new JScrollPane();
261316
baseP.add(scrollPane3, cc.xywh(13, 1, 1, 8, CellConstraints.FILL, CellConstraints.FILL));
262317
scrollPane3.setBorder(BorderFactory.createTitledBorder("Request Information"));
263318
mTpInfo = new JTextPane();
264319
scrollPane3.setViewportView(mTpInfo);
265-
baseP.add(mJep, cc.xywh(13, 9, 1, 2));
320+
baseP.add(mJep, cc.xywh(13, 9, 1, 4));
266321
mJep.setBorder(BorderFactory.createTitledBorder("Json Tree"));
267322
final JLabel label2 = new JLabel();
268323
label2.setText("Encryption:");
@@ -295,6 +350,12 @@ protected void finalize() throws Throwable {
295350
mBtnSend = new JButton();
296351
mBtnSend.setText("Send");
297352
baseP.add(mBtnSend, cc.xy(11, 6));
353+
btnAddRow = new JButton();
354+
btnAddRow.setText("Add Row");
355+
baseP.add(btnAddRow, cc.xyw(1, 10, 3));
356+
btnDelRow = new JButton();
357+
btnDelRow.setText("Delete Selected Row");
358+
baseP.add(btnDelRow, cc.xyw(5, 10, 7));
298359
}
299360

300361
/** @noinspection ALL */
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
package com.longforus.apidebugger.ui;
2+
3+
import com.longforus.apidebugger.bean.TableBean;
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
import javax.swing.event.TableModelEvent;
7+
import javax.swing.table.AbstractTableModel;
8+
9+
public class MyTableModel extends AbstractTableModel {
10+
//单元格元素类型
11+
private Class[] cellType = { Boolean.class, String.class, String.class};
12+
//表头
13+
private String title[] = { "select", "key", "value" };
14+
//模拟数据
15+
//private Object data[][] = {
16+
// { "1", new ImageIcon("e://image/3.jpg"), new Boolean(true), 0, new JButton("start1") }, {
17+
// "2", new ImageIcon("e://image/1.jpg"), new Boolean(false), 60, new JButton("start2") }, {
18+
// "3", new ImageIcon("e://image/4.png"), new Boolean(false), 25, new JButton("start3") } };
19+
20+
private List<TableBean> data = new ArrayList<>();
21+
22+
public MyTableModel() {
23+
}
24+
25+
public List<TableBean> getData() {
26+
return data;
27+
}
28+
29+
public void setData(List<TableBean> data) {
30+
this.data.clear();
31+
this.data.addAll(data);
32+
fireTableChanged(new TableModelEvent(this, 0, data.size()));
33+
}
34+
35+
public void addEmptyRow() {
36+
data.add(new TableBean(true, "", ""));
37+
fireTableRowsInserted(data.size()-1,data.size()-1);
38+
}
39+
40+
41+
public void removeRow(int row) {
42+
if (row > -1 && row < data.size()) {
43+
data.remove(row);
44+
}
45+
fireTableRowsDeleted(row, row);
46+
}
47+
48+
@Override
49+
public Class<?> getColumnClass(int arg0) {
50+
return cellType[arg0];
51+
}
52+
53+
@Override
54+
public String getColumnName(int arg0) {
55+
return title[arg0];
56+
}
57+
58+
@Override
59+
public int getColumnCount() {
60+
return title.length;
61+
}
62+
63+
@Override
64+
public int getRowCount() {
65+
return data.size();
66+
}
67+
68+
@Override
69+
public Object getValueAt(int rowIndex, int columnIndex) {
70+
if (rowIndex<data.size()) {
71+
switch (columnIndex) {
72+
case 0:
73+
return data.get(rowIndex).getSelected();
74+
case 1:
75+
return data.get(rowIndex).getKey();
76+
case 2:
77+
return data.get(rowIndex).getValue();
78+
}
79+
}
80+
return null;
81+
}
82+
83+
//重写isCellEditable方法
84+
85+
@Override
86+
public boolean isCellEditable(int rowIndex, int columnIndex) {
87+
return true;
88+
}
89+
90+
//重写setValueAt方法
91+
92+
@Override
93+
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
94+
if (rowIndex<data.size()) {
95+
switch (columnIndex) {
96+
case 0:
97+
data.get(rowIndex).setSelected((Boolean) aValue);
98+
break;
99+
case 1:
100+
data.get(rowIndex).setKey((String) aValue);
101+
break;
102+
case 2:
103+
data.get(rowIndex).setValue((String) aValue);
104+
break;
105+
}
106+
}
107+
this.fireTableCellUpdated(rowIndex, columnIndex);
108+
}
109+
110+
111+
}

src/main/kotlin/com/longforus/apidebugger/ExtFun.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import javax.swing.text.StyleConstants
1212
* Created by XQ Yang on 8/30/2018 3:05 PM.
1313
* Description :
1414
*/
15-
fun JTextPane.append(str:String,color: Color? = null){
15+
fun JTextPane.append(str:String,color: Color? = null,autoScroll:Boolean = true){
1616
val doc = this.document
1717
if (doc != null) {
1818
try {
@@ -23,6 +23,9 @@ fun JTextPane.append(str:String,color: Color? = null){
2323
StyleConstants.setBold(attr, true)
2424
}
2525
doc.insertString(doc.length, str, attr)
26+
if (autoScroll) {
27+
this.caretPosition = this.styledDocument.length
28+
}
2629
} catch (e: BadLocationException) {
2730
}
2831

0 commit comments

Comments
 (0)