Skip to content

Commit c9f48b9

Browse files
committed
更改界面实现方式
1 parent f2b044b commit c9f48b9

File tree

9 files changed

+36
-61
lines changed

9 files changed

+36
-61
lines changed

lib/jxbrowser-win32-6.20.jar

-41.1 MB
Binary file not shown.

mac/META-INF/MANIFEST.MF

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Manifest-Version: 1.0
2+
Main-Class: com.longforus.apidebugger.MainKt
3+

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,16 @@
8080
</scrollpane>
8181
<scrollpane id="86e31">
8282
<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"/>
83+
<grid row="9" column="0" row-span="1" col-span="13" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
8484
<forms defaultalign-horz="false" defaultalign-vert="false"/>
8585
</constraints>
8686
<properties>
8787
<horizontalScrollBarPolicy value="31"/>
8888
</properties>
8989
<border type="none" title="Response"/>
9090
<children>
91-
<component id="368c1" class="javax.swing.JTextPane" binding="mTpResponse">
91+
<component id="61514" class="com.teamdev.jxbrowser.chromium.swing.BrowserView" binding="mBrowserView1" custom-create="true" default-binding="true">
9292
<constraints/>
93-
<properties>
94-
<preferredSize width="500" height="600"/>
95-
</properties>
9693
</component>
9794
</children>
9895
</scrollpane>
@@ -119,17 +116,6 @@
119116
</component>
120117
</children>
121118
</scrollpane>
122-
<grid id="5f8bc" class="com.longforus.apidebugger.ui.JsonEditPanel" binding="mJep" custom-create="true" layout-manager="FormLayout">
123-
<rowspec value="center:d:grow"/>
124-
<colspec value="fill:d:grow"/>
125-
<constraints>
126-
<grid row="7" column="12" row-span="3" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
127-
<forms/>
128-
</constraints>
129-
<properties/>
130-
<border type="none" title="Json Tree"/>
131-
<children/>
132-
</grid>
133119
<component id="a1a29" class="javax.swing.JComboBox" binding="mCbEncrypt">
134120
<constraints>
135121
<grid row="1" column="10" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>

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

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22

33
import com.jgoodies.forms.layout.CellConstraints;
44
import com.jgoodies.forms.layout.FormLayout;
5+
import com.longforus.apidebugger.ExtFunKt;
56
import com.longforus.apidebugger.MyValueHandler;
67
import com.longforus.apidebugger.OB;
78
import com.longforus.apidebugger.UIActionHandler;
89
import com.longforus.apidebugger.UILifecycleHandler;
910
import com.longforus.apidebugger.bean.ApiBean;
1011
import com.longforus.apidebugger.encrypt.IEncryptHandler;
12+
import com.teamdev.jxbrowser.chromium.Browser;
13+
import com.teamdev.jxbrowser.chromium.BrowserException;
14+
import com.teamdev.jxbrowser.chromium.swing.BrowserView;
1115
import java.awt.Dimension;
1216
import java.awt.FlowLayout;
1317
import java.awt.HeadlessException;
@@ -50,10 +54,8 @@ public class MainPanel extends JFrame {
5054
private JComboBox mCbApiUrl;
5155
private JButton mBtnSend;
5256
private JComboBox mCbEncrypt;
53-
private JTextPane mTpResponse;
5457
private JTable mTbParams;
5558
private JTextPane mTpInfo;
56-
private JsonEditPanel mJep;
5759
private JButton mBtnSaveApi;
5860
private JButton mBtnNewApi;
5961
private JLabel lbStatus;
@@ -64,6 +66,8 @@ public class MainPanel extends JFrame {
6466
private JButton btnAddRow;
6567
private JButton btnDelRow;
6668
private JButton btnClear;
69+
private BrowserView mBrowserView1;
70+
private Browser mBrowser;
6771

6872
public JComboBox getCbMethod() {
6973
return mCbMethod;
@@ -81,18 +85,10 @@ public JComboBox getCbEncrypt() {
8185
return mCbEncrypt;
8286
}
8387

84-
public JsonEditPanel getJep() {
85-
return mJep;
86-
}
87-
8888
public JLabel getLbStatus() {
8989
return lbStatus;
9090
}
9191

92-
public JTextPane getTpResponse() {
93-
return mTpResponse;
94-
}
95-
9692
public JTextPane getTpInfo() {
9793
return mTpInfo;
9894
}
@@ -124,14 +120,24 @@ public MainPanel(String title) throws HeadlessException {
124120
//mCbApiUrl.setRenderer(new DeleteBtnComboBoxRenderer(o -> UIActionHandler.INSTANCE.onDelApiUrl((ApiBean) o)));
125121
//mCbBaseUrl.setRenderer(new DeleteBtnComboBoxRenderer(UIActionHandler.INSTANCE :: onDelBaseUrl));
126122
initTextPanel();
127-
mJep.jTree.setCellRenderer(new JsonTreeCellRenderer());
128123
initTable();
129124
pack();
130125
Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();
131126
int x = (int) screensize.getWidth() / 2 - baseP.getPreferredSize().width / 2;
132127
int y = 0;
133128
setLocation(x, y);
134129
setVisible(true);
130+
String resource = getClass().getResource("").getPath();
131+
int index = resource.indexOf(".jar");
132+
String path;
133+
if (index > 0) {
134+
int last = resource.lastIndexOf("/", index);
135+
path = resource.substring(0, last) + "/jsonView/index.html";
136+
} else {//debug model
137+
path = resource.substring(1) + "/jsonView/index.html";
138+
}
139+
mBrowser.loadURL(path);
140+
mBrowser.executeJavaScript("app.setData('123')");
135141
}
136142

137143
private void initEvent() {
@@ -152,23 +158,7 @@ private void initEvent() {
152158
}
153159

154160
private void initTextPanel() {
155-
mTpResponse.addMouseListener(new MouseInputAdapter() {
156-
@Override
157-
public void mouseClicked(MouseEvent e) {
158-
super.mouseClicked(e);
159-
if (e.getButton() == MouseEvent.BUTTON3) {
160-
JPopupMenu menu = new JPopupMenu("Clear");
161-
JMenuItem clear1 = menu.add(new JMenuItem("clear"));
162-
JMenuItem copyAll = menu.add(new JMenuItem("copy all"));
163-
clear1.addActionListener(e1 -> {
164-
mJep.setJson("{}", JsonEditPanel.UpdateType.REPLACE);
165-
mTpResponse.setText("");
166-
});
167-
copyAll.addActionListener(e1 -> MyValueHandler.INSTANCE.setSysClipboardText(MyValueHandler.INSTANCE.getCurShowJsonStr()));
168-
menu.show(mTpResponse, e.getX(), e.getY());
169-
}
170-
}
171-
});
161+
172162
mTpInfo.addMouseListener(new MouseInputAdapter() {
173163
@Override
174164
public void mouseClicked(MouseEvent e) {
@@ -229,7 +219,6 @@ protected SizeRequirements calculateMinorAxisRequirements(int axis, SizeRequirem
229219
};
230220
}
231221
};
232-
mTpResponse.setEditorKit(editorKit);
233222
mTpInfo.setEditorKit(editorKit);
234223
}
235224

@@ -272,7 +261,12 @@ public void keyReleased(KeyEvent e) {
272261
}
273262

274263
private void createUIComponents() {
275-
mJep = new JsonEditPanel();
264+
try {
265+
mBrowser = new Browser();
266+
} catch (BrowserException e) {
267+
ExtFunKt.showErrorMsg("already been opened !!!");
268+
}
269+
mBrowserView1 = new BrowserView(mBrowser);
276270
}
277271

278272
@Override
@@ -332,11 +326,9 @@ public String getCurBaseUrl() {
332326
scrollPane1.setViewportView(mTbParams);
333327
final JScrollPane scrollPane2 = new JScrollPane();
334328
scrollPane2.setHorizontalScrollBarPolicy(31);
335-
baseP.add(scrollPane2, cc.xyw(1, 10, 11, CellConstraints.FILL, CellConstraints.FILL));
329+
baseP.add(scrollPane2, cc.xyw(1, 10, 13, CellConstraints.FILL, CellConstraints.FILL));
336330
scrollPane2.setBorder(BorderFactory.createTitledBorder("Response"));
337-
mTpResponse = new JTextPane();
338-
mTpResponse.setPreferredSize(new Dimension(500, 600));
339-
scrollPane2.setViewportView(mTpResponse);
331+
scrollPane2.setViewportView(mBrowserView1);
340332
lbStatus = new JLabel();
341333
lbStatus.setText("Status:");
342334
baseP.add(lbStatus, cc.xyw(1, 11, 11));
@@ -345,8 +337,6 @@ public String getCurBaseUrl() {
345337
scrollPane3.setBorder(BorderFactory.createTitledBorder("Request Information"));
346338
mTpInfo = new JTextPane();
347339
scrollPane3.setViewportView(mTpInfo);
348-
baseP.add(mJep, cc.xywh(13, 8, 1, 3));
349-
mJep.setBorder(BorderFactory.createTitledBorder("Json Tree"));
350340
mCbEncrypt = new JComboBox();
351341
baseP.add(mCbEncrypt, cc.xy(11, 2));
352342
btnDelUrl = new JButton();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ fun JTextPane.append(str:String,color: Color? = null,autoScroll:Boolean = true){
3333
}
3434

3535
fun showErrorMsg(msg:String){
36-
JOptionPane.showMessageDialog(null, msg,"Error", JOptionPane.ERROR)
36+
JOptionPane.showMessageDialog(null, msg,"Error", JOptionPane.ERROR_MESSAGE)
3737
}

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.longforus.apidebugger
22

33
import com.google.gson.JsonObject
44
import com.longforus.apidebugger.MyValueHandler.mGson
5-
import com.longforus.apidebugger.ui.JsonEditPanel
65
import com.longforus.apidebugger.ui.MainPanel
76
import okhttp3.*
87
import java.awt.Color
@@ -38,7 +37,6 @@ object HttpManage {
3837
// val byteArrayOutputStream = ByteArrayOutputStream()
3938
// val ps = PrintStream(byteArrayOutputStream)
4039
// e.printStackTrace(ps)
41-
mainPanel.tpResponse.append(e.toString() + "\n",autoScroll = false)
4240

4341
mainPanel.tpInfo.append("consuming: ${System.currentTimeMillis() - startTime}ms \n ", Color.BLUE)
4442

@@ -56,9 +54,7 @@ object HttpManage {
5654
val json = mGson.fromJson<JsonObject>(resStr, JsonObject::class.java)
5755
val jsonStr = mGson.toJson(json, JsonObject::class.java)
5856
MyValueHandler.curShowJsonStr = jsonStr
59-
mainPanel.tpResponse.text = ""
60-
mainPanel.tpResponse.append(jsonStr,autoScroll = false)
61-
mainPanel.jep.setJson(resStr, JsonEditPanel.UpdateType.REPLACE)
57+
6258
} else {
6359
mainPanel.tpInfo.append("\non response but not success\n", Color.RED)
6460
mainPanel.tpInfo.append("code = ${response.code()} \n ", Color.RED)

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.longforus.apidebugger
22

33
import com.longforus.apidebugger.ui.MainPanel
44
import com.teamdev.jxbrowser.chromium.az
5-
import java.awt.Component
65
import java.awt.EventQueue
76
import java.lang.reflect.Field
87
import java.lang.reflect.Modifier
@@ -24,8 +23,6 @@ fun main(args: Array<String>) {
2423
// Notepad()
2524
mainPanel = MainPanel(appName)
2625
UILifecycleHandler.onResume(mainPanel)
27-
mainPanel.jep.alignmentX = Component.LEFT_ALIGNMENT
28-
mainPanel.jep.addTreeSelectionListener(JsonTreeActionHandler)
2926
HttpManage.mainPanel = mainPanel
3027
}
3128
}

win/META-INF/MANIFEST.MF

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Manifest-Version: 1.0
2+
Main-Class: com.longforus.apidebugger.MainKt
3+

0 commit comments

Comments
 (0)