vector) {
134 | this.datas.add(vector);
135 | this.fireTableRowsInserted(vector.size()-1, vector.size()-1);
136 | }
137 |
138 | @Override
139 | public void setValueAt(Object aValue, final int rowIndex, int columnIndex) {
140 | if(columnIndex==1)
141 | {
142 | final Vector data = new Vector();
143 | String oldname = "";
144 | String newname = "";
145 | String newfolder = "";
146 | final int col = columnIndex;
147 | final Object newdata = aValue;
148 | String tmp = filemanagerpanel.getPath().getText();
149 | String path = Common.getAbsolutePath(tmp);
150 | for (int i = 0; i < this.getColumnCount(); i++) {
151 | if (i == 1) {
152 | oldname = this.datas.get(rowIndex).get(i).toString();
153 | newname = aValue.toString();
154 | newfolder = oldname;
155 | data.add(aValue);
156 | } else {
157 | data.add(this.datas.get(rowIndex).get(i));
158 | }
159 | }
160 | if (newfolder.equals("newFolder")) {
161 | if (aValue.equals(newfolder) || aValue.equals("")) {
162 | this.remove(this.getRowCount() - 1);
163 | } else {
164 | Vector exists = new Vector();
165 | int ei=0;
166 | for (Vector vec : this.datas) {
167 | exists.add(vec.get(1));
168 | }
169 | if (exists.contains(aValue)) {
170 | this.remove(this.getRowCount() - 1);
171 | JTable list = filemanagerpanel.getList();
172 | int row = exists.indexOf(aValue);
173 | list.setRowSelectionInterval(row,row);
174 | Rectangle rect = list.getCellRect(row, 0, true);
175 | list.scrollRectToVisible(rect);
176 | filemanagerpanel.getStatus().setText("目录已存在");
177 | } else {
178 | final String np = path + aValue.toString() + Safe.SYSTEMSP;
179 | Runnable newrun = new Runnable() {
180 | public void run() {
181 | ret = "-1";
182 | filemanagerpanel.getStatus().setText(
183 | "正在新建文件夹...请稍等");
184 | ret = filemanagerpanel.getFm().doAction("newdict",
185 | np);
186 | SwingUtilities.invokeLater(new Runnable() {
187 | public void run() {
188 | if (ret.equals("1")) {
189 | datas.get(rowIndex).setElementAt(newdata, col);
190 | fireTableCellUpdated(rowIndex, col);
191 | JTree tree = filemanagerpanel.getTree();
192 | String[] trees = new String[]{getValueAt(getRowCount()-1, 1).toString()};
193 | TreePath tp = tree.getSelectionPath();
194 | DefaultMutableTreeNode select = (DefaultMutableTreeNode) tp
195 | .getLastPathComponent();
196 | select.setAllowsChildren(true);
197 | TreeMethod.addTree(trees, select, filemanagerpanel.getModel());
198 | int row = getRowCount()-1;
199 | filemanagerpanel.getList().setRowSelectionInterval(row, row);
200 | filemanagerpanel.getStatus().setText(
201 | "新建文件夹成功");
202 | } else {
203 | remove(getRowCount() - 1);
204 | filemanagerpanel.getStatus().setText(
205 | "新建文件夹失败");
206 | }
207 | }
208 | });
209 | }
210 | };
211 | new Thread(newrun).start();
212 | }
213 | }
214 | } else {
215 | final String op = path + oldname;
216 | final String np = path + newname;
217 | final String roldname = oldname;
218 | final String rnewname = newname;
219 | Runnable rerun = new Runnable() {
220 | public void run() {
221 | ret = "-1";
222 | filemanagerpanel.getStatus().setText("正在重命名...请稍等");
223 | ret = filemanagerpanel.getFm().doAction("rename", op, np);
224 | SwingUtilities.invokeLater(new Runnable() {
225 | public void run() {
226 | if (ret.equals("1")) {
227 | datas.get(rowIndex).setElementAt(newdata, col);
228 | fireTableCellUpdated(rowIndex, col);
229 | try {
230 | JTree tree = filemanagerpanel.getTree();
231 | DefaultMutableTreeNode dmt = TreeMethod.searchNode(filemanagerpanel.getRoot(), roldname);
232 | filemanagerpanel.getModel().valueForPathChanged(tree.getSelectionPath().pathByAddingChild(dmt), rnewname);
233 | // 非model模式更新界面需要执行updateUI
234 | // dmt.setUserObject(rnewname);
235 | // tree.updateUI();
236 | filemanagerpanel.getList().setRowSelectionInterval(rowIndex,rowIndex);
237 | } catch (Exception e) {
238 | } finally {
239 | filemanagerpanel.getStatus().setText("重命名成功");
240 | }
241 | } else {
242 | filemanagerpanel.getStatus().setText("重命名失败");
243 | }
244 | }
245 | });
246 | }
247 | };
248 | new Thread(rerun).start();
249 | }
250 | } else
251 | {
252 | datas.get(rowIndex).setElementAt(aValue, columnIndex);
253 | fireTableCellUpdated(rowIndex, columnIndex);
254 | }
255 | }
256 |
257 | public void remove(int id) {
258 | this.datas.remove(id);
259 | this.fireTableRowsDeleted(id, id);
260 | }
261 |
262 | @Override
263 | public boolean isCellEditable(int rowIndex, int columnIndex) {
264 | // TODO Auto-generated method stub
265 | return this.isEdit;
266 | }
267 | }
268 |
--------------------------------------------------------------------------------
/src/com/ms509/ui/AboutDialog.java:
--------------------------------------------------------------------------------
1 | package com.ms509.ui;
2 |
3 | import java.awt.Color;
4 | import java.awt.Cursor;
5 | import java.awt.Desktop;
6 | import java.awt.Dialog;
7 | import java.awt.GridBagLayout;
8 | import java.awt.event.MouseAdapter;
9 | import java.awt.event.MouseEvent;
10 | import java.net.URI;
11 |
12 | import javax.swing.*;
13 | import javax.swing.event.HyperlinkEvent;
14 | import javax.swing.event.HyperlinkListener;
15 |
16 | import com.ms509.util.GBC;
17 |
18 | public class AboutDialog extends JDialog {
19 | private JPanel about_pane;
20 | private JLabel img_label;
21 | private JEditorPane about_info;
22 | private Icon icon;
23 |
24 | public AboutDialog() {
25 |
26 | super(MainFrame.main, "添加shell", true);
27 | this.setComponent();
28 | // 初始化布局和控件
29 |
30 | this.setVisible(true);
31 |
32 | }
33 |
34 | private void setComponent() {
35 | about_pane = new JPanel();
36 | about_pane.setLayout(new GridBagLayout());
37 | about_pane.setOpaque(true);
38 | about_pane.setBackground(Color.white);
39 |
40 | GBC gbclogo = new GBC(0, 0, 1, 1).setFill(GBC.BOTH).setInsets(0, 0, 0, 0);
41 | GBC gbccontent1 = new GBC(1, 0, 1, 1).setFill(GBC.BOTH).setWeight(1, 1).setInsets(20, 0, 0, 0);
42 |
43 | // img
44 | img_label = new JLabel();
45 |
46 | try {
47 | icon = new ImageIcon(getClass().getResource("/com/ms509/images/logo.png"));
48 | } catch (Exception e1) {
49 | e1.printStackTrace();
50 | }
51 | img_label.setSize(50, 50);
52 | img_label.setBackground(Color.white);
53 | img_label.setIcon(icon);
54 | img_label.setOpaque(true);
55 |
56 | // text
57 | JEditorPane about_info = new JEditorPane();
58 | about_info.setEditable(false);
59 | about_info.setContentType("text/html");
60 | String copy = "Copyright(c) 2015-2016 MS509 Team
"
61 | + ""
62 | + "
免责声明:本工具仅限于安全研究与教学使用,用户使用本工具所造成的所有后果,由用户承担全部法律及连带责任!作者不承担任何法律及连带责任。
"
63 | + "Powered by Chora & MelodyZX
"
64 | + "";
65 | about_info.setText(copy.toString());
66 | // 超链接事件
67 | about_info.addHyperlinkListener(new HyperlinkListener() {
68 | @Override
69 | public void hyperlinkUpdate(HyperlinkEvent e) {
70 | // TODO Auto-generated method stub
71 | if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
72 | try {
73 | Desktop.getDesktop().browse(new URI("http://www.ms509.com"));
74 | } catch (Exception e1) {
75 | e1.printStackTrace();
76 | }
77 | }
78 | }
79 |
80 | });
81 | about_info.setOpaque(false);
82 | about_info.setBackground(Color.white);
83 |
84 | about_pane.add(about_info, gbccontent1);
85 | about_pane.add(img_label, gbclogo);
86 |
87 | this.add(about_pane);
88 | this.setSize(400, 250);
89 | this.setResizable(false);
90 | this.setTitle("关于 Cknife");
91 | this.setLocationRelativeTo(MainFrame.main);
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/src/com/ms509/ui/AddDialog.java:
--------------------------------------------------------------------------------
1 | package com.ms509.ui;
2 |
3 | import java.awt.BorderLayout;
4 | import java.awt.Dimension;
5 | import java.awt.FlowLayout;
6 | import java.awt.HeadlessException;
7 | import java.awt.Toolkit;
8 | import java.awt.event.ActionEvent;
9 | import java.awt.event.ActionListener;
10 | import java.awt.event.KeyAdapter;
11 | import java.awt.event.KeyEvent;
12 | import java.sql.ResultSet;
13 | import java.sql.SQLException;
14 | import java.sql.Statement;
15 | import java.util.Vector;
16 |
17 | import javax.swing.BorderFactory;
18 | import javax.swing.JButton;
19 | import javax.swing.JComboBox;
20 | import javax.swing.JDialog;
21 | import javax.swing.JLabel;
22 | import javax.swing.JOptionPane;
23 | import javax.swing.JPanel;
24 | import javax.swing.JScrollPane;
25 | import javax.swing.JTextArea;
26 | import javax.swing.JTextField;
27 |
28 | import com.ms509.ui.panel.ListPanel;
29 | import com.ms509.util.DbDao;
30 |
31 | public class AddDialog extends JDialog {
32 | private String id,ip,time;
33 | private JButton button;
34 | private JTextField urltext, passtext;
35 | private JTextArea configtext;
36 | private JComboBox atype, acode;
37 |
38 | public AddDialog() {
39 | super(MainFrame.main, "添加SHELL", true);
40 | this.setComponent();
41 | this.setEvent();
42 | this.setVisible(true); // 模态对话框必须在添加完组件后设置可见,不然会显示不了。
43 | }
44 |
45 | public AddDialog(String s) {
46 | super(MainFrame.main, "修改SHELL", true);
47 | String[] tmp = s.split("\t");
48 | this.setComponent();
49 | this.setEvent();
50 | this.id = tmp[0];
51 | urltext.setText(tmp[1]);
52 | passtext.setText(tmp[2]);
53 | configtext.setText(tmp[3]);
54 | button.setText("编辑");
55 | atype.setSelectedItem(tmp[4]);
56 | acode.setSelectedItem(tmp[5]);
57 | this.ip = tmp[6];
58 | this.time = tmp[7];
59 | this.setVisible(true); // 模态对话框必须在添加完组件后设置可见,不然会显示不了。
60 | }
61 |
62 | private void setComponent() {
63 | Toolkit t = Toolkit.getDefaultToolkit();
64 | Dimension d = t.getScreenSize();
65 | this.setResizable(false);
66 | this.setSize(450, 240);
67 | this.setLocation((d.width - this.getWidth()) / 2,
68 | (d.height - this.getHeight()) / 2);
69 | this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
70 | JPanel north = new JPanel();
71 | JPanel center = new JPanel();
72 | JPanel south = new JPanel();
73 | north.setLayout(new FlowLayout(FlowLayout.LEFT, 3, 8));
74 | center.setLayout(new FlowLayout(FlowLayout.LEFT, 3, 0));
75 | south.setLayout(new FlowLayout(FlowLayout.RIGHT, 3, 8));
76 | JLabel urllabel = new JLabel("地址:");
77 | urllabel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
78 | JLabel configlabel = new JLabel("配置:");
79 | configlabel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
80 | JLabel actionlabel = new JLabel("");
81 | actionlabel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
82 | urltext = new JTextField("http://");
83 | passtext = new JTextField();
84 | configtext = new JTextArea();
85 | JScrollPane configscroll = new JScrollPane(configtext);
86 | button = new JButton("添加");
87 | String[] strtype = new String[] { "脚本类型", "ASP(Eval)", "ASPX(Eval)", "PHP(Eval)",
88 | "JSP(Eval)", "Customize" };
89 | String[] strcode = new String[] { "字符编码", "GB2312", "GBK", "UTF-8",
90 | "BIG5", "ISO-8859-1" };
91 | atype = new JComboBox<>(strtype);
92 | acode = new JComboBox<>(strcode);
93 | urltext.setPreferredSize(new Dimension(320,23));
94 | passtext.setPreferredSize(new Dimension(56,23));
95 | configtext.setLineWrap(true);
96 | configtext.setPreferredSize(new Dimension(369,128));
97 | configscroll.setBorder(urltext.getBorder());
98 | north.add(urllabel);
99 | north.add(urltext);
100 | north.add(passtext);
101 | center.add(configlabel);
102 | center.add(configscroll);
103 | south.add(atype);
104 | south.add(acode);
105 | south.add(button);
106 | south.add(actionlabel);
107 | this.getContentPane().add(north, BorderLayout.NORTH);
108 | this.getContentPane().add(center, BorderLayout.CENTER);
109 | this.getContentPane().add(south, BorderLayout.SOUTH);
110 | this.getRootPane().setDefaultButton(button);
111 | }
112 |
113 | private void setEvent() {
114 | urltext.addKeyListener(new KeyAdapter() {
115 | @Override
116 | public void keyReleased(KeyEvent e) {
117 | // TODO Auto-generated method stub
118 | String url = urltext.getText();
119 | int pos = 0;
120 | if((pos = url.lastIndexOf("."))>0)
121 | {
122 | String ext = url.substring(pos+1);
123 | switch (ext.toLowerCase()) {
124 | case "asp":
125 | atype.setSelectedItem("ASP(Eval)");
126 | break;
127 | case "aspx":
128 | atype.setSelectedItem("ASPX(Eval)");
129 | break;
130 | case "php":
131 | atype.setSelectedItem("PHP(Eval)");
132 | break;
133 | case "jsp":
134 | atype.setSelectedItem("JSP(Eval)");
135 | break;
136 | case "jspx":
137 | atype.setSelectedItem("JSP(Eval)");
138 | break;
139 | }
140 | }
141 | }
142 | });
143 | button.addActionListener(new ActionListener() {
144 | @Override
145 | public void actionPerformed(ActionEvent e) {
146 | // TODO Auto-generated method stub
147 | String url = urltext.getText().replaceAll("'", "''");
148 | String pass = passtext.getText().replaceAll("'", "''");
149 | String config = configtext.getText().replaceAll("'", "''");
150 | String type = atype.getSelectedItem().toString();
151 | String code = acode.getSelectedItem().toString();
152 | Statement stmt = DbDao.getInstance().getStmt();
153 |
154 | if (!type.equals("脚本类型")) {
155 |
156 | if (code.equals("字符编码")) {
157 | code = "UTF-8";
158 | }
159 | if (e.getActionCommand().equals("添加")) {
160 | String sql = "insert into data(url,pass,config,type,code) values('"
161 | + url
162 | + "','"
163 | + pass
164 | + "','"
165 | + config
166 | + "','"
167 | + type + "','" + code + "')";
168 | Vector vector = new Vector();
169 | try {
170 | if (stmt.executeUpdate(sql) < 1) {
171 | JOptionPane
172 | .showMessageDialog(MainFrame.main,
173 | "添加失败", "错误",
174 | JOptionPane.ERROR_MESSAGE);
175 | return;
176 | }
177 | ResultSet rs = stmt
178 | .executeQuery("select last_insert_rowid()");
179 | String id = rs.getString(1);
180 | vector.add(id);
181 | vector.add(url.replaceAll("''", "'"));
182 | vector.add(pass.replaceAll("''", "'"));
183 | vector.add(config.replaceAll("''", "'"));
184 | vector.add(type);
185 | vector.add(code);
186 | vector.add(" ");
187 | vector.add(" ");
188 | ListPanel listpanel= (ListPanel)MainFrame.tab.getSelectedComponent();
189 | listpanel.getModel().addRow(vector);
190 | } catch (SQLException e1) {
191 | // TODO Auto-generated catch block
192 | e1.printStackTrace();
193 | }
194 | } else {
195 | String sql = "update data set url='"+url+"',pass='"+pass+"',config='"+config+"',type='"+type+"',code='"+code+"' where id="+id;
196 | Vector vector = new Vector();
197 | try {
198 | if (stmt.executeUpdate(sql) < 1) {
199 | JOptionPane
200 | .showMessageDialog(MainFrame.main,
201 | "修改失败", "错误",
202 | JOptionPane.ERROR_MESSAGE);
203 | return;
204 | }
205 | vector.add(id);
206 | vector.add(url.replaceAll("''", "'"));
207 | vector.add(pass.replaceAll("''", "'"));
208 | vector.add(config.replaceAll("''", "'"));
209 | vector.add(type);
210 | vector.add(code);
211 | vector.add(ip);
212 | vector.add(time);
213 | ListPanel listpanel= (ListPanel)MainFrame.tab.getSelectedComponent();
214 | listpanel.getModel().update(id, vector);
215 | } catch (HeadlessException e1) {
216 | // TODO Auto-generated catch block
217 | e1.printStackTrace();
218 | } catch (SQLException e1) {
219 | // TODO Auto-generated catch block
220 | e1.printStackTrace();
221 | }
222 | }
223 | setVisible(false);
224 |
225 | } else {
226 | JOptionPane.showMessageDialog(MainFrame.main, "请填写脚本类型",
227 | "错误", JOptionPane.ERROR_MESSAGE);
228 | }
229 |
230 | }
231 | });
232 | }
233 | }
234 |
--------------------------------------------------------------------------------
/src/com/ms509/ui/Cknife.java:
--------------------------------------------------------------------------------
1 | package com.ms509.ui;
2 |
3 | import java.awt.EventQueue;
4 |
5 | import javax.swing.JDialog;
6 | import javax.swing.JFrame;
7 | import javax.swing.UIManager;
8 |
9 | import org.pushingpixels.substance.api.SubstanceLookAndFeel;
10 | import org.pushingpixels.substance.internal.fonts.DefaultGnomeFontPolicy;
11 | import org.pushingpixels.substance.internal.fonts.DefaultKDEFontPolicy;
12 | import org.pushingpixels.substance.internal.fonts.DefaultMacFontPolicy;
13 |
14 | import com.ms509.util.Configuration;
15 | import com.ms509.util.InitConfig;
16 |
17 | public class Cknife {
18 | public static void main(String[] args) {
19 | // TODO Auto-generated method stub
20 | EventQueue.invokeLater(new Runnable() {
21 | @Override
22 | public void run() {
23 | new InitConfig();
24 | setLookFeel();
25 | new MainFrame();
26 |
27 | }
28 | });
29 | }
30 |
31 | public static void setLookFeel() {
32 | try {
33 | Configuration config = new Configuration();
34 | String skin = config.getValue("SKIN");
35 | JFrame.setDefaultLookAndFeelDecorated(true);
36 | JDialog.setDefaultLookAndFeelDecorated(true);
37 | if (!skin.equals("")) {
38 | UIManager.setLookAndFeel(skin);
39 | } else {
40 | // substance皮肤带LookAndFeel结尾的其实与不带的是一样的,只是实现方式不同而已。
41 | // 即SubstanceGraphiteLookAndFeel与GraphiteSkin是同一款皮肤
42 |
43 | // 带LookAndFeel结尾的皮肤使用UIManager.setLookAndFeel
44 | // UIManager.setLookAndFeel("org.pushingpixels.substance.api.skin.SubstanceGraphiteLookAndFeel");
45 |
46 | // 不带LookAndFeel结尾的皮肤使用SubstanceLookAndFeel.setSkin
47 | // SubstanceLookAndFeel.setSkin(new GraphiteSkin());
48 | SubstanceLookAndFeel.setSkin("org.pushingpixels.substance.api.skin.GraphiteSkin");
49 | String os = System.getProperty("os.name");
50 | if(os.startsWith("Mac"))
51 | {
52 | SubstanceLookAndFeel.setFontPolicy(new DefaultMacFontPolicy());
53 | } else if(os.startsWith("Linux"))
54 | {
55 | SubstanceLookAndFeel.setFontPolicy(new DefaultKDEFontPolicy());
56 | }
57 | }
58 | } catch (Exception e) {
59 | try {
60 | JFrame.setDefaultLookAndFeelDecorated(true);
61 | JDialog.setDefaultLookAndFeelDecorated(true);
62 | UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
63 | } catch (Exception e1) {
64 | }
65 | }
66 |
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/com/ms509/ui/ConfigDialog.java:
--------------------------------------------------------------------------------
1 | package com.ms509.ui;
2 |
3 | import java.awt.Dimension;
4 | import java.awt.Toolkit;
5 |
6 | import javax.swing.ImageIcon;
7 | import javax.swing.JDialog;
8 | import javax.swing.JTabbedPane;
9 |
10 | import com.ms509.ui.config.panel.RequestPanel;
11 | import com.ms509.ui.config.panel.ProxyPanel;
12 |
13 | public class ConfigDialog extends JDialog{
14 | public static ConfigDialog cdialog;
15 | public ConfigDialog() {
16 | super(MainFrame.main,"Cknife 设置",true);
17 | this.setComponent();
18 | cdialog = this;
19 | this.setVisible(true);
20 | }
21 | private void setComponent()
22 | {
23 | Toolkit t = Toolkit.getDefaultToolkit();
24 | Dimension d = t.getScreenSize();
25 | this.setResizable(false);
26 | this.setSize(450, 240);
27 | this.setLocation((d.width - this.getWidth()) / 2,
28 | (d.height - this.getHeight()) / 2);
29 | this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
30 | JTabbedPane pane = new JTabbedPane();
31 | pane.addTab("代理", new ProxyPanel());
32 | pane.addTab("请求头", new RequestPanel());
33 | this.getContentPane().add(pane);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/com/ms509/ui/MainFrame.java:
--------------------------------------------------------------------------------
1 | package com.ms509.ui;
2 |
3 | import javax.swing.*;
4 | import java.awt.*;
5 |
6 | public class MainFrame {
7 | public static TabFrame tab;
8 | public static JFrame main;
9 | public MainFrame() {
10 | // TODO Auto-generated constructor stub
11 | Toolkit t = Toolkit.getDefaultToolkit();
12 | Dimension d = t.getScreenSize();
13 | main = new JFrame("Cknife 1.0 Release");
14 | main.setIconImage(new ImageIcon(getClass().getResource("/com/ms509/images/main.png")).getImage());
15 | main.setSize(900, 480);
16 | main.setLocation((d.width - main.getWidth()) / 2,
17 | (d.height - main.getHeight()) / 2);
18 | main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
19 | main.getContentPane().setLayout(new BorderLayout(0, 0));
20 | tab = new TabFrame();
21 | tab.addPanel("list");
22 | main.add(tab);
23 | main.setVisible(true);
24 | }
25 | }
--------------------------------------------------------------------------------
/src/com/ms509/ui/MessageDialog.java:
--------------------------------------------------------------------------------
1 | package com.ms509.ui;
2 |
3 | import java.awt.BorderLayout;
4 | import java.awt.Dimension;
5 | import java.awt.Toolkit;
6 | import java.awt.event.ActionEvent;
7 | import java.awt.event.ActionListener;
8 | import java.util.TimerTask;
9 |
10 | import javax.swing.JDialog;
11 | import javax.swing.JPanel;
12 | import javax.swing.JScrollPane;
13 | import javax.swing.JTextPane;
14 | import javax.swing.SwingUtilities;
15 |
16 | import java.util.Timer;
17 |
18 | public class MessageDialog extends JDialog {
19 | private int i;
20 | private java.util.TimerTask task;
21 | private java.util.Timer timer;
22 |
23 | public MessageDialog(String message,int time) {
24 | super(MainFrame.main, time+"秒后自动关闭窗口", true);
25 | this.i = time;
26 | Toolkit t = Toolkit.getDefaultToolkit();
27 | Dimension d = t.getScreenSize();
28 | this.setResizable(false);
29 | this.setSize(450, 240);
30 | this.setLocation((d.width - this.getWidth()) / 2,
31 | (d.height - this.getHeight()) / 2);
32 | this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
33 | final JTextPane text = new JTextPane();
34 | text.setText(message);
35 | JScrollPane scroll = new JScrollPane(text);
36 | JPanel panel = new JPanel();
37 | panel.setLayout(new BorderLayout());
38 | panel.add(scroll, BorderLayout.CENTER);
39 | this.getContentPane().add(panel);
40 |
41 | // this.setModal(true); // 该方法可用于模态对话框,也可用于非模态对话框。
42 | timer = new Timer();
43 | task = new TimerTask() {
44 | @Override
45 | public void run() {
46 | setTitle(--i + "秒后自动关闭窗口");
47 | if (i == 0) {
48 | timer.cancel(); // 终止此计时器
49 | // task.cancel(); // 取消此计时器任务
50 | setVisible(false);
51 | }
52 | }
53 | };
54 | timer.schedule(task, 1000, 1000);
55 | setVisible(true);
56 |
57 | // this.setModal(false); // 该方法只能用于非模态对话框
58 | // final javax.swing.Timer timer = new javax.swing.Timer(1000,
59 | // new ActionListener() {
60 | // public void actionPerformed(ActionEvent e) {
61 | // setTitle(--i + "秒后自动关闭窗口");
62 | // }
63 | // });
64 | // timer.start();
65 | // setVisible(true);
66 | // Runnable run = new Runnable() {
67 | // public void run() {
68 | //// while (timer.isRunning()) {
69 | //// if (i == 0) {
70 | //// SwingUtilities.invokeLater(new Runnable() {
71 | //// @Override
72 | //// public void run() {
73 | //// timer.stop();
74 | //// setVisible(false);
75 | //// }
76 | //// });
77 | //// break;
78 | //// }
79 | //// }
80 | // // 在多线程编程中,主线程执行无线循环需要加入sleep或者yield让其他线程有机会执行,
81 | // // 不然其他线程没机会执行,则无线循环的条件也就满足不了,则会进入死循环。
82 | // while (true) {
83 | // try {
84 | // Thread.sleep(1);
85 | // } catch (InterruptedException e) {
86 | // }
87 | // Thread.yield();
88 | // if (i == 0) {
89 | // // 必须通过EDT刷新组件
90 | // SwingUtilities.invokeLater(new Runnable() {
91 | // @Override
92 | // public void run() {
93 | // timer.stop();
94 | // setVisible(false);
95 | // }
96 | // });
97 | // break;
98 | // }
99 | // }
100 | // }
101 | // };
102 | // // 不能在EDT中执行其他耗时操作,应该在一个独立的工作器线程中(即普通线程中)做这件事情
103 | // new Thread(run).start();
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/src/com/ms509/ui/SetDBDialog.java:
--------------------------------------------------------------------------------
1 | package com.ms509.ui;
2 | //数据库配置窗口
3 | import java.awt.BorderLayout;
4 | import java.awt.Choice;
5 | import java.awt.Dimension;
6 | import java.awt.FlowLayout;
7 | import java.awt.GridBagLayout;
8 | import java.awt.HeadlessException;
9 | import java.awt.Toolkit;
10 | import java.awt.event.ActionEvent;
11 | import java.awt.event.ActionListener;
12 | import java.awt.event.ItemEvent;
13 | import java.awt.event.ItemListener;
14 | import java.awt.event.MouseListener;
15 | import java.sql.ResultSet;
16 | import java.sql.SQLException;
17 | import java.sql.Statement;
18 | import java.util.Vector;
19 | import java.util.regex.Matcher;
20 | import java.util.regex.Pattern;
21 |
22 | import com.ms509.ui.MainFrame;
23 | import javax.swing.*;
24 |
25 | import com.ms509.ui.panel.DatabasePanel;
26 | import com.ms509.ui.panel.ListPanel;
27 | import com.ms509.util.DataBase;
28 | import com.ms509.util.DbDao;
29 | import com.ms509.util.GBC;
30 |
31 | public class SetDBDialog extends JDialog {
32 |
33 | private JDialog a;
34 | private JPanel north;
35 | private JPanel center;
36 | private JPanel south;
37 | private JLabel example;
38 | private JLabel setting;
39 | private JTextArea dbset;
40 | private JButton submit;
41 | private JScrollPane dbset_scroll;
42 | private JComboBox dbtype;
43 | private String id;
44 | private static String config;
45 | private Statement stmt = DbDao.getInstance().getStmt();;
46 | private String[] tmp;
47 | private String type;
48 |
49 | public SetDBDialog(String[] t) {
50 | // TODO Auto-generated constructor stub
51 | super(MainFrame.main, "数据库配置", true);
52 | // 初始化布局和控件
53 | id = t[0];
54 | type = t[4];
55 | this.setComponent();
56 |
57 | //从数据库中读取配置信息
58 | String getconfig_data = "select config from data where id=" + id;
59 | //System.out.println(getconfig_data);
60 | try {
61 | ResultSet rs = stmt.executeQuery(getconfig_data);
62 | while (rs.next()) {
63 | config = rs.getString(1);
64 | dbset.setText(config);
65 | }
66 | rs.close();
67 | } catch (SQLException e) {
68 | // TODO Auto-generated catch block
69 | e.printStackTrace();
70 | }
71 |
72 | //System.out.println(t[3]);
73 | this.setVisible(true);
74 | }
75 |
76 | //初始化界面
77 | private void setComponent() {
78 | south = new JPanel();
79 | center = new JPanel();
80 | north = new JPanel();
81 | a = this;
82 | Toolkit t = Toolkit.getDefaultToolkit();
83 | Dimension d = t.getScreenSize();
84 | this.setResizable(false);
85 | this.setSize(450, 240);
86 | this.setLocation((d.width - this.getWidth()) / 2, (d.height - this.getHeight()) / 2);
87 | this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
88 | // 初始化布局和控件
89 | this.setLayout(new GridBagLayout());
90 | GBC gbcnorth = new GBC(0, 0, 3, 1).setFill(GBC.BOTH).setInsets(0, 0, 0, 0);
91 | GBC gbccenter = new GBC(0, 1, 3, 2).setFill(GBC.BOTH).setInsets(0, 0, 0, 0);
92 | GBC gbcsouth = new GBC(0, 5, 3, 1).setFill(GBC.BOTH).setInsets(0, 0, 0, 0);
93 |
94 | GBC gbcnorth1 = new GBC(0, 0, 1, 1).setFill(GBC.BOTH).setInsets(0, 0, 0, 0);
95 | GBC gbcnorth2 = new GBC(1, 0, 2, 1).setFill(GBC.BOTH).setInsets(0, 0, 0, 0);
96 | GBC gbccenter1 = new GBC(0, 1, 1, 2).setFill(GBC.BOTH).setInsets(0, 0, 0, 0);
97 | GBC gbccenter2 = new GBC(1, 1, 2, 2).setFill(GBC.BOTH).setInsets(0, 0, 0, 0);
98 |
99 |
100 | example = new JLabel("示例");
101 | setting = new JLabel("配置");
102 | dbset = new JTextArea();
103 | submit = new JButton("提交");
104 | // submit action
105 | InitDB action = new InitDB();
106 | dbset_scroll = new JScrollPane(dbset);
107 | dbset_scroll.setPreferredSize(new Dimension(400, 100));
108 | dbset.setText(config);
109 |
110 | // 数据库类型配置示例
111 | String[] dbtypes = new String[] {};
112 | //System.out.println(type);
113 | switch (type) {
114 | case "JSP(Eval)":
115 | dbtypes = new String[] { "MYSQLlocalhostrootroot
utf8",
116 | "ORACLElocalhost:1521rootroot
databaseutf8",
117 | "MSSQLlocalhost:1433rootroot
databaseutf8" };
118 | break;
119 | case "PHP(Eval)":
120 | dbtypes = new String[] { "MYSQLlocalhostrootroot
utf8" };
121 | break;
122 | case "ASP(Eval)":
123 | dbtypes = new String[] {
124 | "MYSQLDriver=MySQL ODBC 5.3 Unicode Driver;Server=localhost;database=mysql;UID=root;PWD=root",
125 | "MSSQLProvider=SQLOLEDB.1;User ID=;Password=;Initial Catalog=master;Data Source=(local)",
126 | "MSSQLDriver={Sql Server};Server=(local);Database=master;Uid=sa;Pwd=",
127 | "MDBProvider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\111.mdb" };
128 | break;
129 | case "ASPX(Eval)":
130 | dbtypes = new String[] {
131 | "MYSQLDriver=MySQL ODBC 5.3 Unicode Driver;Server=localhost;database=mysql;UID=root;PWD=root",
132 | "MSSQLProvider=SQLOLEDB.1;User ID=;Password=;Initial Catalog=master;Data Source=(local)",
133 | "MSSQLDriver={Sql Server};Server=(local);Database=master;Uid=sa;Pwd=",
134 | "MDBProvider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\111.mdb" };
135 | break;
136 | }
137 | // dbtype
138 | dbtype = new JComboBox<>(dbtypes);
139 | dbtype.setPreferredSize(new Dimension(400, 30));
140 | SelectItem aListener = new SelectItem();
141 | dbtype.addActionListener(aListener);
142 |
143 | submit.addActionListener(action);
144 | dbtype.setSelectedIndex(0);
145 | // 布局
146 | north.add(example, gbcnorth1);
147 | north.add(dbtype, gbcnorth2);
148 | center.add(setting, gbccenter1);
149 | center.add(dbset_scroll, gbccenter2);
150 | south.add(submit);
151 |
152 | // 添加布局到panel
153 | this.getContentPane().add(north, gbcnorth);
154 | this.getContentPane().add(center, gbccenter);
155 | this.getContentPane().add(south, gbcsouth);
156 | }
157 |
158 | class InitDB implements ActionListener {
159 | @Override
160 | public void actionPerformed(ActionEvent e) {
161 | // TODO Auto-generated method stub
162 | config = dbset.getText().replaceAll("'", "''");
163 | String sql = "update data set config='" + config + "' where id=" + id;
164 | try {
165 | stmt.execute(sql);
166 | Vector vector = new Vector();
167 | tmp = MainFrame.tab.getUrl().split("\t");
168 | vector.add(tmp[0]);
169 | vector.add(tmp[1].replaceAll("''", "'"));
170 | vector.add(tmp[2].replaceAll("''", "'"));
171 | vector.add(config.replaceAll("''", "'"));
172 | vector.add(tmp[4]);
173 | vector.add(tmp[5]);
174 | vector.add(tmp[6]);
175 | vector.add(tmp[7]);
176 | // 实例化向上转型,只修改原列表中row的config参数
177 | ListPanel list = (ListPanel) MainFrame.tab.addPanel("list");
178 | list.getModel().update(id, vector);
179 | } catch (SQLException e1) {
180 | // TODO Auto-generated catch block
181 | e1.printStackTrace();
182 | }
183 | a.setVisible(false);
184 |
185 | }
186 |
187 | }
188 |
189 |
190 | //将示例添加至配置框中
191 | class SelectItem implements ActionListener {
192 |
193 | @Override
194 | public void actionPerformed(ActionEvent e) {
195 | // TODO Auto-generated method stub
196 | String tmp = dbtype.getSelectedItem().toString();
197 | tmp = tmp.replace("><", ">\r\n<");
198 | dbset.append(tmp + "\n");
199 | }
200 |
201 | }
202 |
203 | public static String getStr() {
204 | config = config.replace("''", "'");
205 | return config;
206 | }
207 | }
208 |
--------------------------------------------------------------------------------
/src/com/ms509/ui/TabFrame.java:
--------------------------------------------------------------------------------
1 | package com.ms509.ui;
2 |
3 |
4 |
5 |
6 | import javax.swing.*;
7 | import com.ms509.ui.panel.DatabasePanel;
8 | import com.ms509.ui.panel.FileManagerPanel;
9 | import com.ms509.ui.panel.HeadPanel;
10 | import com.ms509.ui.panel.ListPanel;
11 | import com.ms509.ui.panel.ShellPanel;
12 | import com.ms509.ui.panel.TextPanel;
13 |
14 | public class TabFrame extends JTabbedPane {
15 | private ListPanel list;
16 | private String url;
17 | public String getUrl() {
18 | return url;
19 | }
20 | public void setUrl(String url) {
21 | this.url = url;
22 | }
23 | public JPanel addPanel(String type) {
24 | switch (type) {
25 | case "list":
26 | if(list==null)
27 | {
28 | list = new ListPanel();
29 | this.addTab("列表", list);
30 | this.setSelectedIndex(this.indexOfComponent(list));
31 | }
32 | return list;
33 | case "database":
34 | DatabasePanel database = new DatabasePanel();
35 | this.addTab("数据库管理", database);
36 | this.setSelectedIndex(this.indexOfComponent(database));
37 | this.setTabComponentAt(this.getTabCount()-1, new HeadPanel(database));
38 | return database;
39 | case "filemanager":
40 | FileManagerPanel filemanager = new FileManagerPanel();
41 | this.addTab("文件管理", filemanager);
42 | this.setSelectedIndex(this.indexOfComponent(filemanager));
43 | this.setTabComponentAt(this.getTabCount()-1, new HeadPanel(filemanager));
44 | return filemanager;
45 | case "shell":
46 | ShellPanel shell = new ShellPanel();
47 | this.addTab("模拟终端", shell);
48 | this.setSelectedIndex(this.indexOfComponent(shell));
49 | this.setTabComponentAt(this.getTabCount()-1, new HeadPanel(shell));
50 | shell.setVisible(true);
51 | shell.requestFocus();
52 | return shell;
53 | case "text":
54 | TextPanel text = new TextPanel();
55 | this.addTab("文本文件", text);
56 | this.setSelectedIndex(this.indexOfComponent(text));
57 | this.setTabComponentAt(this.getTabCount()-1, new HeadPanel(text));
58 | return text;
59 | default:
60 | return null;
61 | }
62 |
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/src/com/ms509/ui/config/panel/ProxyPanel.java:
--------------------------------------------------------------------------------
1 | package com.ms509.ui.config.panel;
2 |
3 | import java.awt.Dimension;
4 | import java.awt.GridBagLayout;
5 | import java.awt.event.ActionEvent;
6 | import java.awt.event.ActionListener;
7 |
8 | import javax.swing.JButton;
9 | import javax.swing.JComboBox;
10 | import javax.swing.JLabel;
11 | import javax.swing.JOptionPane;
12 | import javax.swing.JPanel;
13 | import javax.swing.JTextField;
14 |
15 | import com.ms509.ui.ConfigDialog;
16 | import com.ms509.util.Common;
17 | import com.ms509.util.Configuration;
18 | import com.ms509.util.GBC;
19 | import com.ms509.util.Safe;
20 |
21 | public class ProxyPanel extends JPanel{
22 | private JTextField host;
23 | private JTextField port;
24 | private JTextField user;
25 | private JTextField pass;
26 | private JComboBox type;
27 | public ProxyPanel() {
28 | this.setLayout(new GridBagLayout());
29 | GBC gbclhost = new GBC(0, 0).setInsets(5, -40, 0, 0);
30 | GBC gbchost = new GBC(1,0,3,1).setInsets(5, 20, 0, 0);
31 | GBC gbclport = new GBC(0,1).setInsets(10, -40, 0, 0);
32 | GBC gbcport = new GBC(1,1,3,1).setInsets(10, 20, 0, 0);
33 | GBC gbcluser = new GBC(0,2).setInsets(10, -40, 0, 0);
34 | GBC gbcuser = new GBC(1,2,3,1).setInsets(10, 20, 0, 0);
35 | GBC gbclpass = new GBC(0,3).setInsets(10, -40, 0, 0);
36 | GBC gbcpass = new GBC(1,3,3,1).setInsets(10, 20, 0, 0);
37 | GBC gbcltype = new GBC(0,4).setInsets(10, -40, 0, 0);
38 | GBC gbctype = new GBC(1,4,1,1).setInsets(10, 20, 0, 0);
39 | GBC gbcok = new GBC(2,4,1,1).setInsets(10, 5, 0, 0);
40 | GBC gbccancle = new GBC(3,4,1,1).setInsets(10, 5, 0, 0);
41 | Dimension dim = new Dimension(200, 23);
42 | JLabel lhost = new JLabel("地址:");
43 | host = new JTextField();
44 | host.setPreferredSize(dim);
45 | JLabel lport = new JLabel("端口:");
46 | port = new JTextField();
47 | port.setPreferredSize(dim);
48 | JLabel luser = new JLabel("用户名:");
49 | user = new JTextField();
50 | user.setPreferredSize(dim);
51 | JLabel lpass = new JLabel("密码:");
52 | pass = new JTextField();
53 | pass.setPreferredSize(dim);
54 | JLabel ltype = new JLabel("类型:");
55 | type = new JComboBox();
56 | type.addItem("SOCKS");
57 | type.addItem("HTTP");
58 | type.addItem("DIRECT");
59 | JButton ok = new JButton("确定");
60 | JButton cancle = new JButton("取消");
61 | cancle.addActionListener(new ActionListener() {
62 | public void actionPerformed(ActionEvent e) {
63 | ConfigDialog.cdialog.hide();
64 | }
65 | });
66 | ok.addActionListener(new ButtonAction());
67 | this.add(lhost,gbclhost);
68 | this.add(host,gbchost);
69 | this.add(lport,gbclport);
70 | this.add(port,gbcport);
71 | this.add(luser,gbcluser);
72 | this.add(user,gbcuser);
73 | this.add(lpass,gbclpass);
74 | this.add(pass,gbcpass);
75 | this.add(ltype,gbcltype);
76 | this.add(type,gbctype);
77 | this.add(ok,gbcok);
78 | this.add(cancle,gbccancle);
79 | Configuration config = new Configuration();
80 | String ihost = config.getValue("PROXY_HOST");
81 | String iport = config.getValue("PROXY_PORT");
82 | String iuser = config.getValue("PROXY_USER");
83 | String ipass = config.getValue("PROXY_PASS");
84 | String itype = config.getValue("PROXY_TYPE");
85 | host.setText(ihost);
86 | port.setText(iport);
87 | user.setText(iuser);
88 | pass.setText(ipass);
89 | if(!itype.equals(""))
90 | {
91 | type.setSelectedItem(itype);
92 | }
93 | }
94 | class ButtonAction implements ActionListener
95 | {
96 | public void actionPerformed(ActionEvent e) {
97 | Configuration config = new Configuration();
98 | String shost = host.getText().trim();
99 | String sport = port.getText().trim();
100 | String suser = user.getText().trim();
101 | String spass = pass.getText().trim();
102 | String stype = type.getSelectedItem().toString();
103 | Safe.PROXY_HOST = shost;
104 | Safe.PROXY_PORT = sport;
105 | Safe.PROXY_USER = suser;
106 | Safe.PROXY_PASS = spass;
107 | Safe.PROXY_TYPE = stype;
108 | String sstatus = Common.getProxyStatus();
109 | Safe.PROXY_STATUS = sstatus;
110 | config.setValue("PROXY_HOST", shost);
111 | config.setValue("PROXY_PORT", sport);
112 | config.setValue("PROXY_USER", suser);
113 | config.setValue("PROXY_PASS", spass);
114 | config.setValue("PROXY_TYPE", stype);
115 | config.setValue("PROXY_STATUS", sstatus);
116 | JOptionPane.showMessageDialog(ConfigDialog.cdialog, "代理设置成功", "提示", JOptionPane.DEFAULT_OPTION);
117 | }
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/src/com/ms509/ui/config/panel/RequestPanel.java:
--------------------------------------------------------------------------------
1 | package com.ms509.ui.config.panel;
2 |
3 | import java.awt.BorderLayout;
4 | import java.awt.GridLayout;
5 | import java.awt.event.ActionEvent;
6 | import java.awt.event.ActionListener;
7 |
8 | import javax.swing.ButtonGroup;
9 | import javax.swing.JButton;
10 | import javax.swing.JOptionPane;
11 | import javax.swing.JPanel;
12 | import javax.swing.JRadioButton;
13 | import javax.swing.JScrollPane;
14 | import javax.swing.JTextPane;
15 |
16 | import com.ms509.ui.ConfigDialog;
17 | import com.ms509.ui.MainFrame;
18 | import com.ms509.util.Common;
19 | import com.ms509.util.Configuration;
20 | import com.ms509.util.Safe;
21 |
22 | public class RequestPanel extends JPanel{
23 | private JTextPane content;
24 | private JRadioButton open,close;
25 | public RequestPanel() {
26 | this.setLayout(new BorderLayout());
27 | JPanel contentPanel = new JPanel();
28 | contentPanel.setLayout(new BorderLayout());
29 | content = new JTextPane();
30 | JScrollPane scontent = new JScrollPane(content);
31 | contentPanel.add(scontent);
32 | JPanel buttonPanel = new JPanel();
33 | ButtonGroup group = new ButtonGroup();
34 | open = new JRadioButton("开启");
35 | close = new JRadioButton("关闭");
36 | group.add(open);
37 | group.add(close);
38 | Configuration config = new Configuration();
39 | String status = config.getValue("REQUEST_STATUS");
40 | String data = config.getValue("REQUEST_DATA");
41 | if(status.equals("1"))
42 | {
43 | open.setSelected(true);
44 | } else
45 | {
46 | close.setSelected(true);
47 | }
48 | content.setText(data);
49 | JButton ok = new JButton("确定");
50 | JButton cancle = new JButton("取消");
51 | buttonPanel.add(open);
52 | buttonPanel.add(close);
53 | buttonPanel.add(ok);
54 | buttonPanel.add(cancle);
55 | cancle.addActionListener(new ActionListener() {
56 | public void actionPerformed(ActionEvent e) {
57 | ConfigDialog.cdialog.hide();
58 | }
59 | });
60 | ok.addActionListener(new ButtonAction());
61 | this.add(contentPanel,BorderLayout.CENTER);
62 | this.add(buttonPanel,BorderLayout.SOUTH);
63 | }
64 | class ButtonAction implements ActionListener
65 | {
66 | public void actionPerformed(ActionEvent e) {
67 | Configuration config = new Configuration();
68 | String status;
69 | String data = content.getText().trim();
70 | if(close.isSelected() || data.equals(""))
71 | {
72 | status="0";
73 | } else
74 | {
75 | status="1";
76 | }
77 | Safe.REQUEST_DATA = data;
78 | Safe.REQUEST_STATUS = status;
79 | config.setValue("REQUEST_DATA", data);
80 | config.setValue("REQUEST_STATUS", status);
81 | Common.map.clear(); // 静态Map,如果不清空,则会一直往Map里注入数据。
82 | Common.getData();
83 | JOptionPane.showMessageDialog(ConfigDialog.cdialog, "请求头设置成功", "提示", JOptionPane.DEFAULT_OPTION);
84 | }
85 |
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/src/com/ms509/ui/menu/DBPopMenu.java:
--------------------------------------------------------------------------------
1 | package com.ms509.ui.menu;
2 | //数据库列表右键菜单
3 |
4 | import java.awt.Component;
5 | import java.awt.datatransfer.Clipboard;
6 | import java.awt.datatransfer.StringSelection;
7 | import java.awt.datatransfer.Transferable;
8 | import java.awt.event.ActionEvent;
9 | import java.awt.event.ActionListener;
10 | import java.awt.event.MouseAdapter;
11 | import java.awt.event.MouseEvent;
12 | import java.awt.event.MouseListener;
13 | import java.io.BufferedWriter;
14 | import java.io.File;
15 | import java.io.FileOutputStream;
16 | import java.io.FileWriter;
17 | import java.util.Arrays;
18 | import java.util.Enumeration;
19 | import java.util.Vector;
20 |
21 | import javax.swing.*;
22 | import javax.swing.table.DefaultTableCellRenderer;
23 | import javax.swing.table.DefaultTableModel;
24 | import javax.swing.table.JTableHeader;
25 | import javax.swing.table.TableCellRenderer;
26 | import javax.swing.table.TableColumn;
27 | import javax.swing.table.TableColumnModel;
28 | import javax.swing.table.TableModel;
29 | import javax.swing.tree.DefaultMutableTreeNode;
30 | import javax.swing.tree.DefaultTreeModel;
31 | import javax.swing.tree.MutableTreeNode;
32 | import javax.swing.tree.TreeNode;
33 | import javax.swing.tree.TreePath;
34 |
35 | import com.ms509.model.DatabaseTableModel;
36 | import com.ms509.ui.MainFrame;
37 | import com.ms509.ui.panel.DatabasePanel;
38 | import com.ms509.ui.panel.FileManagerPanel;
39 | import com.ms509.util.DataBase;
40 | import com.ms509.util.NodeData;
41 | import com.ms509.util.NodeData.DataType;
42 | import com.ms509.util.Safe;
43 | import com.ms509.util.TreeMethod;
44 |
45 | public class DBPopMenu extends JPopupMenu {
46 |
47 | private JPopupMenu dbmenu, dbmenu2, dbmenu3;
48 | private JMenuItem createtable, deltable, countnum, showtable, copysingle, copyline, outfile;
49 | private static JTree tree;
50 | private static JTable table;
51 | private static String url;
52 | private static String pass;
53 | private static String config;
54 | private static String code;
55 | private static int type;
56 | private boolean status;
57 | private JLabel jlabel_status;
58 |
59 |
60 | public DBPopMenu(JPanel j, JTree tr, JTable ta, JLabel st) {
61 | // TODO Auto-generated constructor stub
62 | jlabel_status = st;
63 | status = true;
64 |
65 | //数据库名右键菜单:显示表信息
66 | dbmenu = new JPopupMenu();
67 | showtable = new JMenuItem("查看表信息");
68 | dbmenu.add(showtable);
69 | tree = tr;
70 | DoAction action = new DoAction();
71 | showtable.addActionListener(action);
72 |
73 | //数据库表名右键菜单
74 | dbmenu2 = new JPopupMenu();
75 | countnum = new JMenuItem("获取表行数");
76 | countnum.addActionListener(action);
77 |
78 | dbmenu2.add(countnum);
79 |
80 | j.add(dbmenu);
81 | j.add(dbmenu2);
82 | DBMenu l = new DBMenu();
83 | tree.addMouseListener(l);
84 |
85 | //数据库结果列表右键菜单
86 | dbmenu3 = new JPopupMenu();
87 | // System.out.println("t2");
88 | copysingle = new JMenuItem("复制");
89 | copysingle.addActionListener(action);
90 | copyline = new JMenuItem("复制整行");
91 | copyline.addActionListener(action);
92 | outfile = new JMenuItem("导出");
93 | outfile.addActionListener(action);
94 |
95 | dbmenu3.add(copysingle);
96 | dbmenu3.add(copyline);
97 | dbmenu3.add(outfile);
98 | table = ta;
99 | j.add(dbmenu3);
100 | TBmenu l2 = new TBmenu();
101 | table.addMouseListener(l2);
102 |
103 | }
104 |
105 | //设置传递数据库相关配置参数
106 | public static void init_menu(String u, String p, String conf, int t, String c) {
107 | url = u;
108 | pass = p;
109 | config = conf;
110 | type = t;
111 | code = c;
112 | }
113 |
114 | // 数据库列表菜单
115 | class DBMenu extends MouseAdapter {
116 |
117 | @Override
118 | public void mouseClicked(MouseEvent e) {
119 | TreePath index = tree.getPathForLocation(e.getX(), e.getY());
120 | tree.setSelectionPath(index);
121 | int pathcount = 0;
122 | try {
123 | pathcount = index.getPathCount();
124 | } catch (Exception k) {
125 | pathcount = 0;
126 | }
127 | //判断jtree路径,分别显示两个菜单
128 | if (e.isMetaDown() && pathcount > 2) {
129 | tree.setSelectionPath(index);
130 | dbmenu2.show(tree, e.getX(), e.getY());
131 | } else if (e.isMetaDown() && pathcount == 2) {
132 | tree.setSelectionPath(index);
133 | dbmenu.show(tree, e.getX(), e.getY());
134 | }
135 | }
136 | }
137 |
138 | // 结果列表菜单
139 | class TBmenu extends MouseAdapter {
140 |
141 | @Override
142 | public void mouseClicked(MouseEvent e) {
143 | // TODO Auto-generated method stub
144 | int row = table.rowAtPoint(e.getPoint());
145 | table.setRowSelectionInterval(row, row);
146 | if (e.isMetaDown() && table.getSelectedRow() >= 0) {
147 | dbmenu3.show(table, e.getX(), e.getY());
148 | }
149 | }
150 | }
151 |
152 | // 菜单点击事件
153 | class DoAction implements ActionListener {
154 |
155 | @Override
156 | public void actionPerformed(ActionEvent e) {
157 | // TODO Auto-generated method stub
158 | if (status) { //状态锁
159 | if (e.getSource() == showtable) { //显示表信息
160 | status = false;
161 | Thread run = new Thread(new Runnable() {
162 | @Override
163 | public void run() {
164 | // TODO Auto-generated method stub
165 |
166 | showtable();
167 |
168 | SwingUtilities.invokeLater(new Runnable() {
169 | @Override
170 | public void run() {
171 | // TODO Auto-generated method stub
172 | tree.expandRow(tree.getLeadSelectionRow());
173 | }
174 | });
175 | jlabel_status.setText("执行完毕");
176 | status = true;
177 | }
178 | });
179 | try {
180 | run.start();
181 |
182 | } catch (Exception e1) {
183 | status = true;
184 | }
185 | } else if (e.getSource() == outfile) { //导出到文件
186 | status = false;
187 | Thread run = new Thread(new Runnable() {
188 | @Override
189 | public void run() {
190 | // TODO Auto-generated method stub
191 | SwingUtilities.invokeLater(new Runnable() {
192 | public void run() {
193 | String name = "test.txt";
194 | FileManagerPanel filemanagerpanel = null;
195 | JFileChooser downch = new JFileChooser(".");
196 | downch.setDialogTitle("导出内容");
197 | downch.setSelectedFile(new File(name));
198 | int select = downch.showSaveDialog(filemanagerpanel);
199 | if (select == JFileChooser.APPROVE_OPTION) {
200 | try {
201 |
202 | TableModel model = table.getModel();
203 | File fw = downch.getSelectedFile();
204 | BufferedWriter bw = new BufferedWriter(new FileWriter(fw));
205 | for (int i = 0; i < model.getColumnCount(); i++) {
206 | bw.write(model.getColumnName(i));
207 | bw.write("\t");
208 | }
209 | bw.newLine();
210 | for (int i = 0; i < model.getRowCount(); i++) {
211 | for (int j = 1; j < model.getColumnCount(); j++) { //从1开始,0为图标文件
212 | bw.write(model.getValueAt(i, j).toString());
213 | bw.write("\t");
214 | }
215 | bw.newLine();
216 | }
217 | bw.close();
218 | jlabel_status.setText("导出成功");
219 | status = true;
220 | } catch (Exception e1) {
221 | filemanagerpanel.getStatus().setText("导出失败");
222 | status = true;
223 | }
224 | }
225 | }
226 | });
227 |
228 | }
229 |
230 | });
231 | try {
232 | run.start();
233 |
234 | } catch (Exception e1) {
235 | status = true;
236 | }
237 | } else if (e.getSource() == copysingle) { //复制单个表格内容
238 | status = false;
239 | Thread run = new Thread(new Runnable() {
240 |
241 | @Override
242 | public void run() {
243 | // TODO Auto-generated method stub
244 | try {
245 | TableModel model = table.getModel();
246 | int x = table.getSelectedRow();
247 | int y = table.getSelectedColumn();
248 | String k = model.getValueAt(x, y).toString();
249 | Clipboard clipboard;// 获取系统剪贴板。
250 | clipboard = MainFrame.main.getToolkit().getSystemClipboard();
251 | Transferable tText = new StringSelection(k);
252 | clipboard.setContents(tText, null);
253 | jlabel_status.setText("复制完毕");
254 | status = true;
255 | } catch (Exception e1) {
256 | // System.out.println("copy failed");
257 | status = true;
258 | }
259 | }
260 |
261 | });
262 |
263 | try {
264 | run.start();
265 | } catch (Exception e1) {
266 | status = true;
267 | }
268 | } else if (e.getSource() == copyline) { //复制整行
269 | status = false;
270 | Thread run = new Thread(new Runnable() {
271 |
272 | @Override
273 | public void run() {
274 | // TODO Auto-generated method stub
275 | try {
276 | TableModel model = table.getModel();
277 | int y = table.getSelectedRow();
278 | int x = table.getColumnCount();
279 | String k = "";
280 | for (int lx = 1; lx < x; lx++) { //从1开始,0列为图标文件
281 |
282 | try {
283 | k = k + model.getValueAt(y, lx).toString() + "\t";
284 | } catch (Exception e1) {
285 | break;
286 | }
287 |
288 | }
289 | Clipboard clipboard;// 获取系统剪贴板。
290 | clipboard = MainFrame.main.getToolkit().getSystemClipboard();
291 | Transferable tText = new StringSelection(k);
292 | clipboard.setContents(tText, null);
293 | jlabel_status.setText("复制完毕");
294 | status = true;
295 | } catch (Exception e1) {
296 | status = true;
297 | }
298 | }
299 |
300 | });
301 | try {
302 | run.start();
303 | } catch (Exception e1) {
304 | status = true;
305 | }
306 | } else if (e.getSource() == countnum) { //统计count信息
307 | Thread run = new Thread(new Runnable() {
308 |
309 | @Override
310 | public void run() {
311 | // TODO Auto-generated method stub
312 | status = false;
313 | String sql = "select count(*) from ";
314 | TreePath test = tree.getLeadSelectionPath();
315 | String dbn = test.getPathComponent(1).toString().replace("\t", "");
316 | String table = tree.getLastSelectedPathComponent().toString();
317 | if (config.toLowerCase().indexOf("oracle") > 0) // oracle 由于cknife.jsp中未指定数据库名,所以查询需要带上数据库名
318 | {
319 | sql = sql + dbn + "." + table;
320 | } else {
321 | sql = sql + table;
322 | }
323 | final String re = DataBase.exec_sql(url, pass, config, type, code, sql, dbn);
324 | SwingUtilities.invokeLater(new Runnable() {
325 |
326 | @Override
327 | public void run() {
328 | // TODO Auto-generated method stub
329 | UpdateData(re);
330 | jlabel_status.setText("执行完毕");
331 | status = true;
332 | }
333 |
334 | });
335 | }
336 |
337 | });
338 |
339 | try {
340 | run.start();
341 | } catch (Exception e1) {
342 | e1.printStackTrace();
343 | status = true;
344 | }
345 |
346 | }
347 | } else {
348 | jlabel_status.setText("上一操作尚未执行完毕");
349 | }
350 | }
351 |
352 | }
353 |
354 | // 根据result结果更新table的显示内容
355 | private void UpdateData(String result) {
356 | DatabaseTableModel dtm = new DatabaseTableModel();
357 | Vector