1 | !7 |
2 | |
3 | lib 1006627 lib 1006628 // jcterm |
4 | |
5 | import com.jcraft.jsch.*; |
6 | import com.jcraft.jsch.Proxy; |
7 | import com.jcraft.jcterm.*; |
8 | import java.util.Random; |
9 | //import static com.jcraft.jcterm.Frame.*; |
10 | |
11 | // modelled after JCTermSwingFrame |
12 | sclass JCTermModule extends DynModule |
13 | implements /*Frame,*/ ActionListener, Runnable { |
14 | static S COPYRIGHT = "JCTerm 0.0.11\nCopyright (C) 2002,2012 ymnk<ymnk@jcraft.com>, JCraft,Inc.\n" |
15 | +"Official Homepage: http://www.jcraft.com/jcterm/\n" |
16 | +"This software is licensed under GNU LGPL."; |
17 | |
18 | final static int SHELL=0, SFTP=1, EXEC=2; |
19 | |
20 | transient Thread thread=null; |
21 | |
22 | int mode=SHELL; |
23 | |
24 | String xhost="127.0.0.1"; |
25 | int xport=0; |
26 | boolean xforwarding=false; |
27 | String user=""; |
28 | String host="127.0.0.1"; |
29 | |
30 | String proxy_http_host=null; |
31 | int proxy_http_port=0; |
32 | |
33 | String proxy_socks5_host=null; |
34 | int proxy_socks5_port=0; |
35 | |
36 | transient JSchSession jschsession=null; |
37 | transient Proxy proxy=null; |
38 | |
39 | int compression=0; |
40 | |
41 | transient Splash splash=null; |
42 | |
43 | transient JCTermSwing term=null; |
44 | transient Connection connection=null; |
45 | |
46 | transient Channel channel=null; |
47 | |
48 | String configName = "default"; |
49 | |
50 | JComponent visualize() { |
51 | ret term = swingNu(JCTermSwing.class); |
52 | } |
53 | |
54 | void enhanceFrame(final JInternalFrame f) { |
55 | JMenuBar mb = getJMenuBar(); |
56 | f.setJMenuBar(mb); |
57 | |
58 | ComponentAdapter l = new ComponentAdapter(){ |
59 | public void componentResized(ComponentEvent e){ |
60 | Container cp = f.getContentPane(); |
61 | int cw=f.getWidth(); |
62 | int ch=f.getHeight(); |
63 | int cwm=f.getWidth()-cp.getWidth(); |
64 | int chm=f.getHeight()-cp.getHeight(); |
65 | cw-=cwm; |
66 | ch-=chm; |
67 | term.setSize(cw, ch); |
68 | } |
69 | }; |
70 | f.addComponentListener(l); |
71 | |
72 | applyConfig(configName); |
73 | |
74 | openSession(); |
75 | } |
76 | |
77 | public void kick(){ |
78 | this.thread=new Thread(this); |
79 | this.thread.start(); |
80 | } |
81 | |
82 | public void run(){ |
83 | String destination = null; |
84 | while(thread!=null){ |
85 | try{ |
86 | int port=22; |
87 | try{ |
88 | String[] destinations = JCTermSwing.getCR().load(configName).destinations; |
89 | String _host = promptDestination(term, destinations); |
90 | destination = _host; |
91 | if(_host==null){ |
92 | break; |
93 | } |
94 | String _user=_host.substring(0, _host.indexOf('@')); |
95 | _host=_host.substring(_host.indexOf('@')+1); |
96 | if(_host==null||_host.length()==0){ |
97 | continue; |
98 | } |
99 | if(_host.indexOf(':')!=-1){ |
100 | try{ |
101 | port=Integer.parseInt(_host.substring(_host.indexOf(':')+1)); |
102 | } |
103 | catch(Exception eee){ |
104 | } |
105 | _host=_host.substring(0, _host.indexOf(':')); |
106 | } |
107 | user=_user; |
108 | host=_host; |
109 | } |
110 | catch(Exception ee){ |
111 | continue; |
112 | } |
113 | |
114 | try{ |
115 | UserInfo ui=new MyUserInfo(); |
116 | |
117 | jschsession=JSchSession.getSession(user, null, host, port, ui, proxy); |
118 | setCompression(compression); |
119 | |
120 | Configuration conf = JCTermSwing.getCR().load(configName); |
121 | conf.addDestination(destination); |
122 | JCTermSwing.getCR().save(conf); |
123 | } |
124 | catch(Exception e){ |
125 | //System.out.println(e); |
126 | break; |
127 | } |
128 | |
129 | Channel channel=null; |
130 | OutputStream out=null; |
131 | InputStream in=null; |
132 | |
133 | if(mode==SHELL){ |
134 | channel=jschsession.getSession().openChannel("shell"); |
135 | if(xforwarding){ |
136 | jschsession.getSession().setX11Host(xhost); |
137 | jschsession.getSession().setX11Port(xport+6000); |
138 | channel.setXForwarding(true); |
139 | } |
140 | |
141 | out=channel.getOutputStream(); |
142 | in=channel.getInputStream(); |
143 | |
144 | channel.connect(); |
145 | } |
146 | else if(mode==SFTP){ |
147 | |
148 | out=new PipedOutputStream(); |
149 | in=new PipedInputStream(); |
150 | |
151 | channel=jschsession.getSession().openChannel("sftp"); |
152 | |
153 | channel.connect(); |
154 | |
155 | (new Sftp((ChannelSftp)channel, (InputStream)(new PipedInputStream( |
156 | (PipedOutputStream)out)), new PipedOutputStream( |
157 | (PipedInputStream)in))).kick(); |
158 | } |
159 | |
160 | final OutputStream fout=out; |
161 | final InputStream fin=in; |
162 | final Channel fchannel=channel; |
163 | |
164 | connection=new Connection(){ |
165 | public InputStream getInputStream(){ |
166 | return fin; |
167 | } |
168 | |
169 | public OutputStream getOutputStream(){ |
170 | return fout; |
171 | } |
172 | |
173 | public void requestResize(Term term){ |
174 | if(fchannel instanceof ChannelShell){ |
175 | int c=term.getColumnCount(); |
176 | int r=term.getRowCount(); |
177 | ((ChannelShell)fchannel).setPtySize(c, r, c*term.getCharWidth(), |
178 | r*term.getCharHeight()); |
179 | } |
180 | } |
181 | |
182 | public void close(){ |
183 | fchannel.disconnect(); |
184 | } |
185 | }; |
186 | setModuleName(user+"@"+host+(port!=22 ? (":"+port) : "")); |
187 | term.requestFocus(); |
188 | term.start(connection); |
189 | } |
190 | catch(Exception e){ |
191 | _handleException(e); |
192 | } |
193 | break; |
194 | } |
195 | thread=null; |
196 | |
197 | dispose_connection(); |
198 | } |
199 | |
200 | void dispose_connection(){ |
201 | synchronized(this){ |
202 | if(channel!=null){ |
203 | channel.disconnect(); |
204 | channel=null; |
205 | } |
206 | } |
207 | } |
208 | |
209 | public class MyUserInfo implements UserInfo, UIKeyboardInteractive{ |
210 | |
211 | public void showMessage(S s) { |
212 | infoBox(s); |
213 | } |
214 | |
215 | public boolean promptYesNo(S str){ |
216 | ret confirmYesNo(str); |
217 | } |
218 | |
219 | String passwd=null; |
220 | String passphrase=null; |
221 | JTextField pword=swingNu(JPasswordField.class, 20); |
222 | |
223 | public String getPassword(){ |
224 | return passwd; |
225 | } |
226 | |
227 | public String getPassphrase(){ |
228 | return passphrase; |
229 | } |
230 | |
231 | public boolean promptPassword(String message){ |
232 | if (!showTitledForm_blocking("Give Password", "Password", pword)) false; |
233 | ret true with passwd=pword.getText(); |
234 | } |
235 | |
236 | public boolean promptPassphrase(String message){ |
237 | return true; |
238 | } |
239 | |
240 | final GridBagConstraints gbc=new GridBagConstraints(0, 0, 1, 1, 1, 1, |
241 | GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, |
242 | 0, 0), 0, 0); |
243 | Container panel; |
244 | |
245 | public String[] promptKeyboardInteractive(String destination, String name, |
246 | String instruction, String[] prompt, boolean[] echo){ |
247 | panel=new JPanel(); |
248 | panel.setLayout(new GridBagLayout()); |
249 | |
250 | gbc.weightx=1.0; |
251 | gbc.gridwidth=GridBagConstraints.REMAINDER; |
252 | gbc.gridx=0; |
253 | panel.add(new JLabel(instruction), gbc); |
254 | gbc.gridy++; |
255 | |
256 | gbc.gridwidth=GridBagConstraints.RELATIVE; |
257 | |
258 | JTextField[] texts=new JTextField[prompt.length]; |
259 | for(int i=0; i<prompt.length; i++){ |
260 | gbc.fill=GridBagConstraints.NONE; |
261 | gbc.gridx=0; |
262 | gbc.weightx=1; |
263 | panel.add(new JLabel(prompt[i]), gbc); |
264 | |
265 | gbc.gridx=1; |
266 | gbc.fill=GridBagConstraints.HORIZONTAL; |
267 | gbc.weighty=1; |
268 | if(echo[i]){ |
269 | texts[i]=new JTextField(20); |
270 | } |
271 | else{ |
272 | texts[i]=new JPasswordField(20); |
273 | texts[i].requestFocusInWindow(); |
274 | } |
275 | panel.add(texts[i], gbc); |
276 | gbc.gridy++; |
277 | } |
278 | for(int i=prompt.length-1; i>0; i--){ |
279 | texts[i].requestFocusInWindow(); |
280 | } |
281 | JOptionPane pane = new JOptionPane(panel, |
282 | JOptionPane.QUESTION_MESSAGE, |
283 | JOptionPane.OK_CANCEL_OPTION){ |
284 | public void selectInitialValue() { |
285 | } |
286 | }; |
287 | JDialog dialog = pane.createDialog(term, |
288 | destination+": "+name); |
289 | dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); |
290 | dialog.setVisible(true); |
291 | Object o = pane.getValue(); |
292 | if(o != null && ((Integer)o).intValue()==JOptionPane.OK_OPTION){ |
293 | String[] response=new String[prompt.length]; |
294 | for(int i=0; i<prompt.length; i++){ |
295 | response[i]=texts[i].getText(); |
296 | } |
297 | return response; |
298 | } |
299 | else{ |
300 | return null; // cancel |
301 | } |
302 | } |
303 | } |
304 | |
305 | public void setProxyHttp(String host, int port){ |
306 | proxy_http_host=host; |
307 | proxy_http_port=port; |
308 | if(proxy_http_host!=null&&proxy_http_port!=0){ |
309 | proxy=new ProxyHTTP(proxy_http_host, proxy_http_port); |
310 | } |
311 | else{ |
312 | proxy=null; |
313 | } |
314 | } |
315 | |
316 | public String getProxyHttpHost(){ |
317 | return proxy_http_host; |
318 | } |
319 | |
320 | public int getProxyHttpPort(){ |
321 | return proxy_http_port; |
322 | } |
323 | |
324 | public void setProxySOCKS5(String host, int port){ |
325 | proxy_socks5_host=host; |
326 | proxy_socks5_port=port; |
327 | if(proxy_socks5_host!=null&&proxy_socks5_port!=0){ |
328 | proxy=new ProxySOCKS5(proxy_socks5_host, proxy_socks5_port); |
329 | } |
330 | else{ |
331 | proxy=null; |
332 | } |
333 | } |
334 | |
335 | public String getProxySOCKS5Host(){ |
336 | return proxy_socks5_host; |
337 | } |
338 | |
339 | public int getProxySOCKS5Port(){ |
340 | return proxy_socks5_port; |
341 | } |
342 | |
343 | public void setXHost(String xhost){ |
344 | this.xhost=xhost; |
345 | } |
346 | |
347 | public void setXPort(int xport){ |
348 | this.xport=xport; |
349 | } |
350 | |
351 | public void setXForwarding(boolean foo){ |
352 | this.xforwarding=foo; |
353 | } |
354 | |
355 | public void setCompression(int compression){ |
356 | if(compression<0||9<compression) |
357 | return; |
358 | this.compression=compression; |
359 | if(jschsession!=null){ |
360 | if(compression==0){ |
361 | jschsession.getSession().setConfig("compression.s2c", "none"); |
362 | jschsession.getSession().setConfig("compression.c2s", "none"); |
363 | jschsession.getSession().setConfig("compression_level", "0"); |
364 | } |
365 | else{ |
366 | jschsession.getSession().setConfig("compression.s2c", "zlib@openssh.com,zlib,none"); |
367 | jschsession.getSession().setConfig("compression.c2s", "zlib@openssh.com,zlib,none"); |
368 | jschsession.getSession().setConfig("compression_level", |
369 | new Integer(compression).toString()); |
370 | } |
371 | try{ |
372 | jschsession.getSession().rekey(); |
373 | } |
374 | catch(Exception e){ |
375 | System.out.println(e); |
376 | } |
377 | } |
378 | } |
379 | |
380 | public void setFontSize(int size){ |
381 | Configuration conf = JCTermSwing.getCR().load(configName); |
382 | conf.font_size = size; |
383 | JCTermSwing.getCR().save(conf); |
384 | _setFontSize(size); |
385 | } |
386 | |
387 | JInternalFrame frame() { ret getInternalFrame(term); } |
388 | |
389 | void _setFontSize(int size){ |
390 | int mwidth = frame().getWidth()-term.getTermWidth(); |
391 | int mheight = frame().getHeight()-term.getTermHeight(); |
392 | call(term, 'setFont, "Monospaced-"+size); |
393 | frame().setSize(mwidth+term.getTermWidth(), mheight+term.getTermHeight()); |
394 | term.clear(); |
395 | term.redraw(0, 0, term.getWidth(), term.getHeight()); |
396 | } |
397 | |
398 | public int getCompression(){ |
399 | return this.compression; |
400 | } |
401 | |
402 | public void setLineSpace(int foo){ |
403 | term.setLineSpace(foo); |
404 | } |
405 | |
406 | public void setSplash(Splash foo){ |
407 | this.splash=foo; |
408 | } |
409 | |
410 | public boolean getAntiAliasing(){ |
411 | return term.getAntiAliasing(); |
412 | } |
413 | |
414 | public void setAntiAliasing(boolean foo){ |
415 | term.setAntiAliasing(foo); |
416 | } |
417 | |
418 | public void setUserHost(String userhost){ |
419 | try{ |
420 | String _user=userhost.substring(0, userhost.indexOf('@')); |
421 | String _host=userhost.substring(userhost.indexOf('@')+1); |
422 | this.user=_user; |
423 | this.host=_host; |
424 | } |
425 | catch(Exception e){ |
426 | } |
427 | } |
428 | |
429 | public void openSession(){ |
430 | kick(); |
431 | } |
432 | |
433 | public void setPortForwardingL(int port1, String host, int port2){ |
434 | if(jschsession==null) |
435 | return; |
436 | try{ |
437 | jschsession.getSession().setPortForwardingL(port1, host, port2); |
438 | } |
439 | catch(JSchException e){ |
440 | } |
441 | } |
442 | |
443 | public void setPortForwardingR(int port1, String host, int port2){ |
444 | if(jschsession==null) |
445 | return; |
446 | try{ |
447 | jschsession.getSession().setPortForwardingR(port1, host, port2); |
448 | } |
449 | catch(JSchException e){ |
450 | } |
451 | } |
452 | |
453 | public void actionPerformed(ActionEvent e){ |
454 | String action=e.getActionCommand(); |
455 | |
456 | int _mode = SHELL; |
457 | if(action.equals("Open SHELL Session...")){ |
458 | _mode=SHELL; |
459 | } |
460 | else if(action.equals("Open SFTP Session...")){ |
461 | _mode=SFTP; |
462 | } |
463 | |
464 | if(action.equals("Open SHELL Session...") |
465 | ||action.equals("Open SFTP Session...")){ |
466 | if(thread==null){ |
467 | mode=_mode; |
468 | openSession(); |
469 | } |
470 | else { |
471 | infoBox("TODO"); |
472 | //frame.openFrame(_mode, configName); |
473 | } |
474 | } |
475 | else if(action.equals("HTTP...")){ |
476 | String foo=getProxyHttpHost(); |
477 | int bar=getProxyHttpPort(); |
478 | String proxy=JOptionPane.showInputDialog(null, |
479 | "HTTP proxy server (hostname:port)", ((foo!=null&&bar!=0) ? foo+":" |
480 | +bar : "")); |
481 | if(proxy==null) |
482 | return; |
483 | if(proxy.length()==0){ |
484 | setProxyHttp(null, 0); |
485 | return; |
486 | } |
487 | |
488 | try{ |
489 | foo=proxy.substring(0, proxy.indexOf(':')); |
490 | bar=Integer.parseInt(proxy.substring(proxy.indexOf(':')+1)); |
491 | if(foo!=null){ |
492 | setProxyHttp(foo, bar); |
493 | } |
494 | } |
495 | catch(Exception ee){ |
496 | } |
497 | } |
498 | else if(action.equals("SOCKS5...")){ |
499 | String foo=getProxySOCKS5Host(); |
500 | int bar=getProxySOCKS5Port(); |
501 | String proxy=JOptionPane.showInputDialog(null, |
502 | "SOCKS5 server (hostname:1080)", ((foo!=null&&bar!=0) ? foo+":"+bar |
503 | : "")); |
504 | if(proxy==null) |
505 | return; |
506 | if(proxy.length()==0){ |
507 | setProxySOCKS5(null, 0); |
508 | return; |
509 | } |
510 | |
511 | try{ |
512 | foo=proxy.substring(0, proxy.indexOf(':')); |
513 | bar=Integer.parseInt(proxy.substring(proxy.indexOf(':')+1)); |
514 | if(foo!=null){ |
515 | setProxySOCKS5(foo, bar); |
516 | } |
517 | } |
518 | catch(Exception ee){ |
519 | } |
520 | } |
521 | else if(action.equals("X11 Forwarding...")){ |
522 | String display=JOptionPane.showInputDialog(null, |
523 | "XDisplay name (hostname:0)", (xhost==null) ? "" : (xhost+":"+xport)); |
524 | try{ |
525 | if(display!=null){ |
526 | xhost=display.substring(0, display.indexOf(':')); |
527 | xport=Integer.parseInt(display.substring(display.indexOf(':')+1)); |
528 | xforwarding=true; |
529 | } |
530 | } |
531 | catch(Exception ee){ |
532 | xforwarding=false; |
533 | xhost=null; |
534 | } |
535 | } |
536 | else if((action.equals("AntiAliasing"))){ |
537 | setAntiAliasing(!getAntiAliasing()); |
538 | } |
539 | else if(action.equals("Compression...")){ |
540 | String foo=JOptionPane |
541 | .showInputDialog( |
542 | null, |
543 | "Compression level(0-9)\n0 means no compression.\n1 means fast.\n9 means slow, but best.", |
544 | new Integer(compression).toString()); |
545 | try{ |
546 | if(foo!=null){ |
547 | compression=Integer.parseInt(foo); |
548 | setCompression(compression); |
549 | } |
550 | } |
551 | catch(Exception ee){ |
552 | } |
553 | } |
554 | else if(action.equals("About...")) |
555 | ret with JOptionPane.showMessageDialog(null, COPYRIGHT); |
556 | else if((action.equals("Local Port..."))||(action.equals("Remote Port..."))){ |
557 | if(jschsession==null){ |
558 | JOptionPane.showMessageDialog(null, |
559 | "Establish the connection before this setting."); |
560 | return; |
561 | } |
562 | |
563 | try{ |
564 | String title=""; |
565 | if(action.equals("Local Port...")){ |
566 | title+="Local port forwarding"; |
567 | } |
568 | else{ |
569 | title+="remote port forwarding"; |
570 | } |
571 | title+="(port:host:hostport)"; |
572 | |
573 | String foo=JOptionPane.showInputDialog(null, title, ""); |
574 | if(foo==null) |
575 | return; |
576 | int port1=Integer.parseInt(foo.substring(0, foo.indexOf(':'))); |
577 | foo=foo.substring(foo.indexOf(':')+1); |
578 | String host=foo.substring(0, foo.indexOf(':')); |
579 | int port2=Integer.parseInt(foo.substring(foo.indexOf(':')+1)); |
580 | |
581 | if(action.equals("Local Port...")){ |
582 | setPortForwardingL(port1, host, port2); |
583 | } |
584 | else{ |
585 | setPortForwardingR(port1, host, port2); |
586 | } |
587 | } |
588 | catch(Exception ee){ |
589 | } |
590 | } |
591 | else if(action.equals("Quit")){ |
592 | quit(); |
593 | } |
594 | } |
595 | |
596 | public JMenuBar getJMenuBar(){ |
597 | JMenuBar mb=new JMenuBar(); |
598 | JMenu m; |
599 | JMenuItem mi; |
600 | |
601 | m=new JMenu("File"); |
602 | mi=new JMenuItem("Open SHELL Session..."); |
603 | mi.addActionListener(this); |
604 | mi.setActionCommand("Open SHELL Session..."); |
605 | m.add(mi); |
606 | mi=new JMenuItem("Open SFTP Session..."); |
607 | mi.addActionListener(this); |
608 | mi.setActionCommand("Open SFTP Session..."); |
609 | m.add(mi); |
610 | mi=new JMenuItem("Quit"); |
611 | mi.addActionListener(this); |
612 | mi.setActionCommand("Quit"); |
613 | m.add(mi); |
614 | mb.add(m); |
615 | |
616 | m=new JMenu("Proxy"); |
617 | mi=new JMenuItem("HTTP..."); |
618 | mi.addActionListener(this); |
619 | mi.setActionCommand("HTTP..."); |
620 | m.add(mi); |
621 | mi=new JMenuItem("SOCKS5..."); |
622 | mi.addActionListener(this); |
623 | mi.setActionCommand("SOCKS5..."); |
624 | m.add(mi); |
625 | mb.add(m); |
626 | |
627 | m=new JMenu("PortForwarding"); |
628 | mi=new JMenuItem("Local Port..."); |
629 | mi.addActionListener(this); |
630 | mi.setActionCommand("Local Port..."); |
631 | m.add(mi); |
632 | mi=new JMenuItem("Remote Port..."); |
633 | mi.addActionListener(this); |
634 | mi.setActionCommand("Remote Port..."); |
635 | m.add(mi); |
636 | mi=new JMenuItem("X11 Forwarding..."); |
637 | mi.addActionListener(this); |
638 | mi.setActionCommand("X11 Forwarding..."); |
639 | m.add(mi); |
640 | mb.add(m); |
641 | |
642 | m=new JMenu("Etc"); |
643 | |
644 | mi=new JMenuItem("AntiAliasing"); |
645 | mi.addActionListener(this); |
646 | mi.setActionCommand("AntiAliasing"); |
647 | m.add(mi); |
648 | |
649 | mi=new JMenuItem("Compression..."); |
650 | mi.addActionListener(this); |
651 | mi.setActionCommand("Compression..."); |
652 | m.add(mi); |
653 | |
654 | JMenu mcolor=new JMenu("Color"); |
655 | final ActionListener mcolor_action = new ActionListener(){ |
656 | public void actionPerformed(ActionEvent e){ |
657 | setFgBg(e.getActionCommand()); |
658 | } |
659 | }; |
660 | mcolor.addMenuListener(new MenuListener(){ |
661 | public void menuSelected(MenuEvent me){ |
662 | JMenu jm = (JMenu)me.getSource(); |
663 | String[] fg_bg = JCTermSwing.getCR().load(configName).fg_bg; |
664 | for(int i=0; i < fg_bg.length; i++){ |
665 | String[] tmp = fg_bg[i].split(":"); |
666 | JMenuItem mi = new JMenuItem("ABC"); |
667 | mi.setForeground(toColor(tmp[0])); |
668 | mi.setBackground(toColor(tmp[1])); |
669 | mi.setActionCommand(fg_bg[i]); |
670 | mi.addActionListener(mcolor_action); |
671 | jm.add(mi); |
672 | } |
673 | } |
674 | public void menuDeselected(MenuEvent me){ |
675 | JMenu jm = (JMenu)me.getSource(); |
676 | jm.removeAll(); |
677 | } |
678 | public void menuCanceled(MenuEvent arg){ } |
679 | }); |
680 | m.add(mcolor); |
681 | |
682 | JMenu mfsize=new JMenu("Font size"); |
683 | final ActionListener mfsize_action = new ActionListener(){ |
684 | public void actionPerformed(ActionEvent e){ |
685 | String _font_size=e.getActionCommand(); |
686 | try { |
687 | setFontSize(Integer.parseInt(_font_size)); |
688 | } |
689 | catch(NumberFormatException nfe){ |
690 | } |
691 | } |
692 | }; |
693 | mfsize.addMenuListener(new MenuListener(){ |
694 | public void menuSelected(MenuEvent me){ |
695 | JMenuItem mi; |
696 | JMenu jm = (JMenu)me.getSource(); |
697 | int font_size = JCTermSwing.getCR().load(configName).font_size; |
698 | mi = new JMenuItem("Smaller ("+(font_size-1)+")");; |
699 | mi.setActionCommand(""+(font_size-1)); |
700 | mi.addActionListener(mfsize_action); |
701 | jm.add(mi); |
702 | mi = new JMenuItem("Larger ("+(font_size+1)+")"); |
703 | mi.setActionCommand(""+(font_size+1)); |
704 | mi.addActionListener(mfsize_action); |
705 | jm.add(mi); |
706 | } |
707 | public void menuDeselected(MenuEvent me){ |
708 | JMenu jm = (JMenu)me.getSource(); |
709 | jm.removeAll(); |
710 | } |
711 | public void menuCanceled(MenuEvent arg){ } |
712 | }); |
713 | m.add(mfsize); |
714 | |
715 | mb.add(m); |
716 | |
717 | m=new JMenu("Help"); |
718 | mi=new JMenuItem("About..."); |
719 | mi.addActionListener(this); |
720 | mi.setActionCommand("About..."); |
721 | m.add(mi); |
722 | mb.add(m); |
723 | |
724 | return mb; |
725 | } |
726 | |
727 | public void quit(){ |
728 | thread=null; |
729 | if(connection!=null){ |
730 | connection.close(); |
731 | connection=null; |
732 | } |
733 | /* |
734 | if(jschsession!=null){ |
735 | jschsession.dispose(); |
736 | jschsession=null; |
737 | } |
738 | */ |
739 | } |
740 | |
741 | public void setTerm(JCTermSwing term){ |
742 | this.term=term; |
743 | } |
744 | |
745 | public Term getTerm(){ |
746 | return term; |
747 | } |
748 | |
749 | void setFgBg(String fg_bg){ |
750 | Configuration conf = JCTermSwing.getCR().load(configName); |
751 | conf.addFgBg(fg_bg); |
752 | JCTermSwing.getCR().save(conf); |
753 | _setFgBg(fg_bg); |
754 | } |
755 | |
756 | void _setFgBg(String fg_bg){ |
757 | String[] tmp = fg_bg.split(":"); |
758 | Color fg = toColor(tmp[0]); |
759 | Color bg = toColor(tmp[1]); |
760 | term.setForeGround(fg); |
761 | term.setDefaultForeGround(fg); |
762 | term.setBackGround(bg); |
763 | term.setDefaultBackGround(bg); |
764 | call(term, 'resetCursorGraphics); |
765 | term.clear(); |
766 | term.redraw(0, 0, term.getWidth(), term.getHeight()); |
767 | } |
768 | |
769 | String promptDestination(JComponent term, String[] destinations){ |
770 | JTextField tf = jTextField("kiosk@gemini.circumlunar.space"); |
771 | ret showTitledForm_blocking("Enter destination", |
772 | "Username@Hostname", tf) ? getTextTrim(tf) : null; |
773 | } |
774 | |
775 | void applyConfig(String configName){ |
776 | this.configName = configName; |
777 | Configuration conf = JCTermSwing.getCR().load(configName); |
778 | _setFontSize(conf.font_size); |
779 | _setFgBg(conf.fg_bg[0]); |
780 | } |
781 | |
782 | /*public static void main(String[] arg){ |
783 | JCTermSwing.setCR(new ConfigurationRepositoryFS()); |
784 | |
785 | String s = System.getProperty("jcterm.config.use_ssh_agent"); |
786 | if(s != null && s.equals("true")) |
787 | JSchSession.useSSHAgent(true); |
788 | }*/ |
789 | |
790 | static java.awt.Color toColor(Object o){ |
791 | if(o instanceof String){ |
792 | try{ |
793 | return java.awt.Color.decode(((String)o).trim()); |
794 | } |
795 | catch(java.lang.NumberFormatException e){ } |
796 | return java.awt.Color.getColor(((String)o).trim()); |
797 | } |
798 | if(o instanceof java.awt.Color){ |
799 | return (java.awt.Color)o; |
800 | } |
801 | return Color.white; |
802 | } |
803 | } |
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, iveijnkanddl, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1035224 |
Snippet name: | JCTerm (SSH Client as Dyn Module, dev.){Gemini Protocol} |
Eternal ID of this version: | #1035224/1 |
Text MD5: | f88278459ca94d90b29d9f73de79a7e0 |
Author: | someone |
Category: | |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-04-17 03:40:41 |
Source code size: | 22421 bytes / 803 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 120 / 157 |
Referenced in: | [show references] |