├── COPYING ├── ChangeLog ├── README ├── build.xml └── src └── main └── java └── com └── jcraft └── jcterm ├── Configuration.java ├── ConfigurationRepository.java ├── ConfigurationRepositoryFS.java ├── Connection.java ├── Emulator.java ├── EmulatorVT100.java ├── Frame.java ├── JCTermAWT.java ├── JCTermAWTFrame.java ├── JCTermApplet.java ├── JCTermIdentityRepository.java ├── JCTermJ2MECDC.java ├── JCTermMIDP.java ├── JCTermPanelG2D.java ├── JCTermSWT.java ├── JCTermSwing.java ├── JCTermSwingFrame.java ├── JSchSession.java ├── Sftp.java ├── Splash.java └── Term.java /COPYING: -------------------------------------------------------------------------------- 1 | GNU LIBRARY GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1991 Free Software Foundation, Inc. 5 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the library GPL. It is 10 | numbered 2 because it goes with version 2 of the ordinary GPL.] 11 | 12 | Preamble 13 | 14 | The licenses for most software are designed to take away your 15 | freedom to share and change it. By contrast, the GNU General Public 16 | Licenses are intended to guarantee your freedom to share and change 17 | free software--to make sure the software is free for all its users. 18 | 19 | This license, the Library General Public License, applies to some 20 | specially designated Free Software Foundation software, and to any 21 | other libraries whose authors decide to use it. You can use it for 22 | your libraries, too. 23 | 24 | When we speak of free software, we are referring to freedom, not 25 | price. Our General Public Licenses are designed to make sure that you 26 | have the freedom to distribute copies of free software (and charge for 27 | this service if you wish), that you receive source code or can get it 28 | if you want it, that you can change the software or use pieces of it 29 | in new free programs; and that you know you can do these things. 30 | 31 | To protect your rights, we need to make restrictions that forbid 32 | anyone to deny you these rights or to ask you to surrender the rights. 33 | These restrictions translate to certain responsibilities for you if 34 | you distribute copies of the library, or if you modify it. 35 | 36 | For example, if you distribute copies of the library, whether gratis 37 | or for a fee, you must give the recipients all the rights that we gave 38 | you. You must make sure that they, too, receive or can get the source 39 | code. If you link a program with the library, you must provide 40 | complete object files to the recipients so that they can relink them 41 | with the library, after making changes to the library and recompiling 42 | it. And you must show them these terms so they know their rights. 43 | 44 | Our method of protecting your rights has two steps: (1) copyright 45 | the library, and (2) offer you this license which gives you legal 46 | permission to copy, distribute and/or modify the library. 47 | 48 | Also, for each distributor's protection, we want to make certain 49 | that everyone understands that there is no warranty for this free 50 | library. If the library is modified by someone else and passed on, we 51 | want its recipients to know that what they have is not the original 52 | version, so that any problems introduced by others will not reflect on 53 | the original authors' reputations. 54 | 55 | Finally, any free program is threatened constantly by software 56 | patents. We wish to avoid the danger that companies distributing free 57 | software will individually obtain patent licenses, thus in effect 58 | transforming the program into proprietary software. To prevent this, 59 | we have made it clear that any patent must be licensed for everyone's 60 | free use or not licensed at all. 61 | 62 | Most GNU software, including some libraries, is covered by the ordinary 63 | GNU General Public License, which was designed for utility programs. This 64 | license, the GNU Library General Public License, applies to certain 65 | designated libraries. This license is quite different from the ordinary 66 | one; be sure to read it in full, and don't assume that anything in it is 67 | the same as in the ordinary license. 68 | 69 | The reason we have a separate public license for some libraries is that 70 | they blur the distinction we usually make between modifying or adding to a 71 | program and simply using it. Linking a program with a library, without 72 | changing the library, is in some sense simply using the library, and is 73 | analogous to running a utility program or application program. However, in 74 | a textual and legal sense, the linked executable is a combined work, a 75 | derivative of the original library, and the ordinary General Public License 76 | treats it as such. 77 | 78 | Because of this blurred distinction, using the ordinary General 79 | Public License for libraries did not effectively promote software 80 | sharing, because most developers did not use the libraries. We 81 | concluded that weaker conditions might promote sharing better. 82 | 83 | However, unrestricted linking of non-free programs would deprive the 84 | users of those programs of all benefit from the free status of the 85 | libraries themselves. This Library General Public License is intended to 86 | permit developers of non-free programs to use free libraries, while 87 | preserving your freedom as a user of such programs to change the free 88 | libraries that are incorporated in them. (We have not seen how to achieve 89 | this as regards changes in header files, but we have achieved it as regards 90 | changes in the actual functions of the Library.) The hope is that this 91 | will lead to faster development of free libraries. 92 | 93 | The precise terms and conditions for copying, distribution and 94 | modification follow. Pay close attention to the difference between a 95 | "work based on the library" and a "work that uses the library". The 96 | former contains code derived from the library, while the latter only 97 | works together with the library. 98 | 99 | Note that it is possible for a library to be covered by the ordinary 100 | General Public License rather than by this special one. 101 | 102 | GNU LIBRARY GENERAL PUBLIC LICENSE 103 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 104 | 105 | 0. This License Agreement applies to any software library which 106 | contains a notice placed by the copyright holder or other authorized 107 | party saying it may be distributed under the terms of this Library 108 | General Public License (also called "this License"). Each licensee is 109 | addressed as "you". 110 | 111 | A "library" means a collection of software functions and/or data 112 | prepared so as to be conveniently linked with application programs 113 | (which use some of those functions and data) to form executables. 114 | 115 | The "Library", below, refers to any such software library or work 116 | which has been distributed under these terms. A "work based on the 117 | Library" means either the Library or any derivative work under 118 | copyright law: that is to say, a work containing the Library or a 119 | portion of it, either verbatim or with modifications and/or translated 120 | straightforwardly into another language. (Hereinafter, translation is 121 | included without limitation in the term "modification".) 122 | 123 | "Source code" for a work means the preferred form of the work for 124 | making modifications to it. For a library, complete source code means 125 | all the source code for all modules it contains, plus any associated 126 | interface definition files, plus the scripts used to control compilation 127 | and installation of the library. 128 | 129 | Activities other than copying, distribution and modification are not 130 | covered by this License; they are outside its scope. The act of 131 | running a program using the Library is not restricted, and output from 132 | such a program is covered only if its contents constitute a work based 133 | on the Library (independent of the use of the Library in a tool for 134 | writing it). Whether that is true depends on what the Library does 135 | and what the program that uses the Library does. 136 | 137 | 1. You may copy and distribute verbatim copies of the Library's 138 | complete source code as you receive it, in any medium, provided that 139 | you conspicuously and appropriately publish on each copy an 140 | appropriate copyright notice and disclaimer of warranty; keep intact 141 | all the notices that refer to this License and to the absence of any 142 | warranty; and distribute a copy of this License along with the 143 | Library. 144 | 145 | You may charge a fee for the physical act of transferring a copy, 146 | and you may at your option offer warranty protection in exchange for a 147 | fee. 148 | 149 | 2. You may modify your copy or copies of the Library or any portion 150 | of it, thus forming a work based on the Library, and copy and 151 | distribute such modifications or work under the terms of Section 1 152 | above, provided that you also meet all of these conditions: 153 | 154 | a) The modified work must itself be a software library. 155 | 156 | b) You must cause the files modified to carry prominent notices 157 | stating that you changed the files and the date of any change. 158 | 159 | c) You must cause the whole of the work to be licensed at no 160 | charge to all third parties under the terms of this License. 161 | 162 | d) If a facility in the modified Library refers to a function or a 163 | table of data to be supplied by an application program that uses 164 | the facility, other than as an argument passed when the facility 165 | is invoked, then you must make a good faith effort to ensure that, 166 | in the event an application does not supply such function or 167 | table, the facility still operates, and performs whatever part of 168 | its purpose remains meaningful. 169 | 170 | (For example, a function in a library to compute square roots has 171 | a purpose that is entirely well-defined independent of the 172 | application. Therefore, Subsection 2d requires that any 173 | application-supplied function or table used by this function must 174 | be optional: if the application does not supply it, the square 175 | root function must still compute square roots.) 176 | 177 | These requirements apply to the modified work as a whole. If 178 | identifiable sections of that work are not derived from the Library, 179 | and can be reasonably considered independent and separate works in 180 | themselves, then this License, and its terms, do not apply to those 181 | sections when you distribute them as separate works. But when you 182 | distribute the same sections as part of a whole which is a work based 183 | on the Library, the distribution of the whole must be on the terms of 184 | this License, whose permissions for other licensees extend to the 185 | entire whole, and thus to each and every part regardless of who wrote 186 | it. 187 | 188 | Thus, it is not the intent of this section to claim rights or contest 189 | your rights to work written entirely by you; rather, the intent is to 190 | exercise the right to control the distribution of derivative or 191 | collective works based on the Library. 192 | 193 | In addition, mere aggregation of another work not based on the Library 194 | with the Library (or with a work based on the Library) on a volume of 195 | a storage or distribution medium does not bring the other work under 196 | the scope of this License. 197 | 198 | 3. You may opt to apply the terms of the ordinary GNU General Public 199 | License instead of this License to a given copy of the Library. To do 200 | this, you must alter all the notices that refer to this License, so 201 | that they refer to the ordinary GNU General Public License, version 2, 202 | instead of to this License. (If a newer version than version 2 of the 203 | ordinary GNU General Public License has appeared, then you can specify 204 | that version instead if you wish.) Do not make any other change in 205 | these notices. 206 | 207 | Once this change is made in a given copy, it is irreversible for 208 | that copy, so the ordinary GNU General Public License applies to all 209 | subsequent copies and derivative works made from that copy. 210 | 211 | This option is useful when you wish to copy part of the code of 212 | the Library into a program that is not a library. 213 | 214 | 4. You may copy and distribute the Library (or a portion or 215 | derivative of it, under Section 2) in object code or executable form 216 | under the terms of Sections 1 and 2 above provided that you accompany 217 | it with the complete corresponding machine-readable source code, which 218 | must be distributed under the terms of Sections 1 and 2 above on a 219 | medium customarily used for software interchange. 220 | 221 | If distribution of object code is made by offering access to copy 222 | from a designated place, then offering equivalent access to copy the 223 | source code from the same place satisfies the requirement to 224 | distribute the source code, even though third parties are not 225 | compelled to copy the source along with the object code. 226 | 227 | 5. A program that contains no derivative of any portion of the 228 | Library, but is designed to work with the Library by being compiled or 229 | linked with it, is called a "work that uses the Library". Such a 230 | work, in isolation, is not a derivative work of the Library, and 231 | therefore falls outside the scope of this License. 232 | 233 | However, linking a "work that uses the Library" with the Library 234 | creates an executable that is a derivative of the Library (because it 235 | contains portions of the Library), rather than a "work that uses the 236 | library". The executable is therefore covered by this License. 237 | Section 6 states terms for distribution of such executables. 238 | 239 | When a "work that uses the Library" uses material from a header file 240 | that is part of the Library, the object code for the work may be a 241 | derivative work of the Library even though the source code is not. 242 | Whether this is true is especially significant if the work can be 243 | linked without the Library, or if the work is itself a library. The 244 | threshold for this to be true is not precisely defined by law. 245 | 246 | If such an object file uses only numerical parameters, data 247 | structure layouts and accessors, and small macros and small inline 248 | functions (ten lines or less in length), then the use of the object 249 | file is unrestricted, regardless of whether it is legally a derivative 250 | work. (Executables containing this object code plus portions of the 251 | Library will still fall under Section 6.) 252 | 253 | Otherwise, if the work is a derivative of the Library, you may 254 | distribute the object code for the work under the terms of Section 6. 255 | Any executables containing that work also fall under Section 6, 256 | whether or not they are linked directly with the Library itself. 257 | 258 | 6. As an exception to the Sections above, you may also compile or 259 | link a "work that uses the Library" with the Library to produce a 260 | work containing portions of the Library, and distribute that work 261 | under terms of your choice, provided that the terms permit 262 | modification of the work for the customer's own use and reverse 263 | engineering for debugging such modifications. 264 | 265 | You must give prominent notice with each copy of the work that the 266 | Library is used in it and that the Library and its use are covered by 267 | this License. You must supply a copy of this License. If the work 268 | during execution displays copyright notices, you must include the 269 | copyright notice for the Library among them, as well as a reference 270 | directing the user to the copy of this License. Also, you must do one 271 | of these things: 272 | 273 | a) Accompany the work with the complete corresponding 274 | machine-readable source code for the Library including whatever 275 | changes were used in the work (which must be distributed under 276 | Sections 1 and 2 above); and, if the work is an executable linked 277 | with the Library, with the complete machine-readable "work that 278 | uses the Library", as object code and/or source code, so that the 279 | user can modify the Library and then relink to produce a modified 280 | executable containing the modified Library. (It is understood 281 | that the user who changes the contents of definitions files in the 282 | Library will not necessarily be able to recompile the application 283 | to use the modified definitions.) 284 | 285 | b) Accompany the work with a written offer, valid for at 286 | least three years, to give the same user the materials 287 | specified in Subsection 6a, above, for a charge no more 288 | than the cost of performing this distribution. 289 | 290 | c) If distribution of the work is made by offering access to copy 291 | from a designated place, offer equivalent access to copy the above 292 | specified materials from the same place. 293 | 294 | d) Verify that the user has already received a copy of these 295 | materials or that you have already sent this user a copy. 296 | 297 | For an executable, the required form of the "work that uses the 298 | Library" must include any data and utility programs needed for 299 | reproducing the executable from it. However, as a special exception, 300 | the source code distributed need not include anything that is normally 301 | distributed (in either source or binary form) with the major 302 | components (compiler, kernel, and so on) of the operating system on 303 | which the executable runs, unless that component itself accompanies 304 | the executable. 305 | 306 | It may happen that this requirement contradicts the license 307 | restrictions of other proprietary libraries that do not normally 308 | accompany the operating system. Such a contradiction means you cannot 309 | use both them and the Library together in an executable that you 310 | distribute. 311 | 312 | 7. You may place library facilities that are a work based on the 313 | Library side-by-side in a single library together with other library 314 | facilities not covered by this License, and distribute such a combined 315 | library, provided that the separate distribution of the work based on 316 | the Library and of the other library facilities is otherwise 317 | permitted, and provided that you do these two things: 318 | 319 | a) Accompany the combined library with a copy of the same work 320 | based on the Library, uncombined with any other library 321 | facilities. This must be distributed under the terms of the 322 | Sections above. 323 | 324 | b) Give prominent notice with the combined library of the fact 325 | that part of it is a work based on the Library, and explaining 326 | where to find the accompanying uncombined form of the same work. 327 | 328 | 8. You may not copy, modify, sublicense, link with, or distribute 329 | the Library except as expressly provided under this License. Any 330 | attempt otherwise to copy, modify, sublicense, link with, or 331 | distribute the Library is void, and will automatically terminate your 332 | rights under this License. However, parties who have received copies, 333 | or rights, from you under this License will not have their licenses 334 | terminated so long as such parties remain in full compliance. 335 | 336 | 9. You are not required to accept this License, since you have not 337 | signed it. However, nothing else grants you permission to modify or 338 | distribute the Library or its derivative works. These actions are 339 | prohibited by law if you do not accept this License. Therefore, by 340 | modifying or distributing the Library (or any work based on the 341 | Library), you indicate your acceptance of this License to do so, and 342 | all its terms and conditions for copying, distributing or modifying 343 | the Library or works based on it. 344 | 345 | 10. Each time you redistribute the Library (or any work based on the 346 | Library), the recipient automatically receives a license from the 347 | original licensor to copy, distribute, link with or modify the Library 348 | subject to these terms and conditions. You may not impose any further 349 | restrictions on the recipients' exercise of the rights granted herein. 350 | You are not responsible for enforcing compliance by third parties to 351 | this License. 352 | 353 | 11. If, as a consequence of a court judgment or allegation of patent 354 | infringement or for any other reason (not limited to patent issues), 355 | conditions are imposed on you (whether by court order, agreement or 356 | otherwise) that contradict the conditions of this License, they do not 357 | excuse you from the conditions of this License. If you cannot 358 | distribute so as to satisfy simultaneously your obligations under this 359 | License and any other pertinent obligations, then as a consequence you 360 | may not distribute the Library at all. For example, if a patent 361 | license would not permit royalty-free redistribution of the Library by 362 | all those who receive copies directly or indirectly through you, then 363 | the only way you could satisfy both it and this License would be to 364 | refrain entirely from distribution of the Library. 365 | 366 | If any portion of this section is held invalid or unenforceable under any 367 | particular circumstance, the balance of the section is intended to apply, 368 | and the section as a whole is intended to apply in other circumstances. 369 | 370 | It is not the purpose of this section to induce you to infringe any 371 | patents or other property right claims or to contest validity of any 372 | such claims; this section has the sole purpose of protecting the 373 | integrity of the free software distribution system which is 374 | implemented by public license practices. Many people have made 375 | generous contributions to the wide range of software distributed 376 | through that system in reliance on consistent application of that 377 | system; it is up to the author/donor to decide if he or she is willing 378 | to distribute software through any other system and a licensee cannot 379 | impose that choice. 380 | 381 | This section is intended to make thoroughly clear what is believed to 382 | be a consequence of the rest of this License. 383 | 384 | 12. If the distribution and/or use of the Library is restricted in 385 | certain countries either by patents or by copyrighted interfaces, the 386 | original copyright holder who places the Library under this License may add 387 | an explicit geographical distribution limitation excluding those countries, 388 | so that distribution is permitted only in or among countries not thus 389 | excluded. In such case, this License incorporates the limitation as if 390 | written in the body of this License. 391 | 392 | 13. The Free Software Foundation may publish revised and/or new 393 | versions of the Library General Public License from time to time. 394 | Such new versions will be similar in spirit to the present version, 395 | but may differ in detail to address new problems or concerns. 396 | 397 | Each version is given a distinguishing version number. If the Library 398 | specifies a version number of this License which applies to it and 399 | "any later version", you have the option of following the terms and 400 | conditions either of that version or of any later version published by 401 | the Free Software Foundation. If the Library does not specify a 402 | license version number, you may choose any version ever published by 403 | the Free Software Foundation. 404 | 405 | 14. If you wish to incorporate parts of the Library into other free 406 | programs whose distribution conditions are incompatible with these, 407 | write to the author to ask for permission. For software which is 408 | copyrighted by the Free Software Foundation, write to the Free 409 | Software Foundation; we sometimes make exceptions for this. Our 410 | decision will be guided by the two goals of preserving the free status 411 | of all derivatives of our free software and of promoting the sharing 412 | and reuse of software generally. 413 | 414 | NO WARRANTY 415 | 416 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 417 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 418 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 419 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 420 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 421 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 422 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 423 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 424 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 425 | 426 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 427 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 428 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 429 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 430 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 431 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 432 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 433 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 434 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 435 | DAMAGES. 436 | 437 | END OF TERMS AND CONDITIONS 438 | 439 | How to Apply These Terms to Your New Libraries 440 | 441 | If you develop a new library, and you want it to be of the greatest 442 | possible use to the public, we recommend making it free software that 443 | everyone can redistribute and change. You can do so by permitting 444 | redistribution under these terms (or, alternatively, under the terms of the 445 | ordinary General Public License). 446 | 447 | To apply these terms, attach the following notices to the library. It is 448 | safest to attach them to the start of each source file to most effectively 449 | convey the exclusion of warranty; and each file should have at least the 450 | "copyright" line and a pointer to where the full notice is found. 451 | 452 | 453 | Copyright (C) 454 | 455 | This library is free software; you can redistribute it and/or 456 | modify it under the terms of the GNU Library General Public 457 | License as published by the Free Software Foundation; either 458 | version 2 of the License, or (at your option) any later version. 459 | 460 | This library is distributed in the hope that it will be useful, 461 | but WITHOUT ANY WARRANTY; without even the implied warranty of 462 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 463 | Library General Public License for more details. 464 | 465 | You should have received a copy of the GNU Library General Public 466 | License along with this library; if not, write to the 467 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, 468 | Boston, MA 02111-1307 USA. 469 | 470 | Also add information on how to contact you by electronic and paper mail. 471 | 472 | You should also get your employer (if you work as a programmer) or your 473 | school, if any, to sign a "copyright disclaimer" for the library, if 474 | necessary. Here is a sample; alter the names: 475 | 476 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 477 | library `Frob' (a library for tweaking knobs) written by James Random Hacker. 478 | 479 | , 1 April 1990 480 | Ty Coon, President of Vice 481 | 482 | That's all there is to it! 483 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | ChangeLog of JCTerm 2 | ==================================================================== 3 | Last modified: Wed Apr 11 09:55:50 UTC 2012 4 | 5 | 6 | Changes since version 0.0.9: 7 | - changing foreground and background colors dynamically. 8 | - changing the font size dynamically. 9 | - the prompt for the destination will list previous inputs. 10 | - settings will be saved in ~/.ssh/jcterm.properties 11 | if the configuration repository using file-system is chosen; 12 | JCTermSwing.setCR(new ConfigurationRepositoryFS()); 13 | - added build.xml 14 | - introduced properties for applet 15 | jcterm.font_size 16 | jcterm.fg_bg 17 | jcterm.destinations 18 | jcterm.config.repository 19 | jcterm.config.name 20 | 21 | 22 | Changes since version 0.0.8: 23 | - added color, bold, underline support. 24 | - added an implemetation by SWT. 25 | 26 | 27 | Changes since version 0.0.7: 28 | - JCTermMIDP supports public-key authentication. 29 | - JCTermMIDP can install remote private-keys by using remote exec on ssh2. 30 | - JCTermMIDP allow you to choose TCP port for the remote sshd; 31 | user@host[:port] 32 | 33 | 34 | Changes since version 0.0.6: 35 | - added JCTermMIDP, which is for J2ME/CLDC/MIDP2.0 platform. 36 | 37 | 38 | Changes since version 0.0.5: 39 | - allowed to choose ssh port; user@host:port 40 | - added JCTermJ2MECDC, which is for J2ME CDC platform. 41 | 42 | 43 | Changes since version 0.0.4: 44 | - improved vt100 terminal emulation. 45 | - added timeout in opening the socket. 46 | - added 'About...' to menu-bar. 47 | - implemented JCTerm in AWT widgets(com.jcraft.jcterm.JCTermAWT). 48 | 49 | 50 | Changes since version 0.0.3: 51 | - fixed a crash bug at the end of ssh session. 52 | - add the progress monitor on sftp session. 53 | 54 | 55 | Changes since version 0.0.2: 56 | - added the packet compression support. 57 | 58 | 59 | Changes since version 0.0.1: 60 | - function keys from F1 to F10. 61 | - arrow keys. 62 | - sftp support. 63 | - a switch to enable and disable anti-aliasing text. 64 | - some escape sequences support for vt100 emulation. 65 | - rendering speed is improved. 66 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | 2 | JCTerm 3 | 4 | JCraft's Term 5 | by ymnk@jcraft.com, JCraft,Inc. 6 | 7 | http://www.jcraft.com/jcterm/ 8 | 9 | Last modified: Thu Apr 26 14:01:53 UTC 2012 10 | 11 | Description 12 | =========== 13 | JCTerm(JCraft's Term) is a pure Java VT100 terminal emulator for 14 | SSH2 sessions. This terminal emulator also allows you to enjoy 15 | port forwarding, X11 forwarding, etc,. 16 | JCTerm is licensed under GNU LGPL and easily integrated into you programs. 17 | 18 | 19 | Documentation 20 | ============= 21 | * README files all over the source tree have info related to the stuff 22 | in the directories. 23 | 24 | 25 | Directories & Files in the Source Tree 26 | ====================================== 27 | * src/com/jcraft/jcterm has source trees of JCTerm 28 | 29 | 30 | Features 31 | ======== 32 | * JCTerm requires jsch(http://www.jcraft.com/jsch/) 0.1.48. 33 | * JCTerm requires J2SE 1.4. 34 | * JCTermMIDP runs on J2ME/CLDC/MIDP2.0 35 | * JCTermJ2MECDC runs on J2ME/CDC/PP 1.0 36 | * VT100 emulation 37 | * SSH2 protocol support. 38 | * X11 forwarding. 39 | * connection through HTTP proxy. 40 | * connection through SOCKS5 proxy. 41 | * local/remote port forwarding. 42 | * anti-aliasing text. 43 | * sftp support. 44 | * packet compression support. 45 | * OpenSSH's ssh-agent and Putty's pageant support. 46 | * JCTerm is licensed under GNU LGPL. 47 | 48 | 49 | How To Try 50 | ========== 51 | This archive does not include java byte code, so please compile 52 | the source code by your self. Suppose you have jsch-?.?.?.zip. 53 | 54 | $ unzip jcterm-?.?.?.zip 55 | $ cd jcterm-?.?.?/ 56 | $ mkdir lib/ 57 | $ (cd lib; \ 58 | wget \ 59 | http://sourceforge.net/projects/jsch/files/jsch.jar/0.1.48/jsch-0.1.48.jar) 60 | $ ant 61 | $ java -cp './lib/*.jar:./dist/lib/*.jar' \ 62 | com.jcraft.jcterm.JCTermSwingFrame 63 | 64 | If you need the packet compression support, you have to put the jar file of 65 | jzlib(http://www.jcraft.com/jzlib) into lib/ . 66 | 67 | 68 | Using ssh-agent 69 | =============== 70 | JCTerm supports OpenSSH's ssh-agent and Putty's pageant by 71 | using jsch-agent-proxy. Here are steps to enable it, 72 | 73 | $ pushd /tmp 74 | $ git clone git://github.com/ymnk/jsch-agent-proxy.git 75 | $ cd jsch-agent-proxy 76 | $ mkdir lib 77 | $ (cd lib; \ 78 | wget --no-check-certificate \ 79 | https://github.com/downloads/twall/jna/jna.jar) 80 | $ (cd lib; \ 81 | wget --no-check-certificate \ 82 | https://github.com/downloads/twall/jna/platform.jar) 83 | $ (cd lib; \ 84 | wget \ 85 | http://sourceforge.net/projects/jsch/files/jsch.jar/0.1.48/jsch-0.1.48.jar) 86 | $ ant 87 | $ popd 88 | $ mkdir lib/ 89 | $ cp /tmp/jsch-agent-proxy/lib/*.jar lib/ 90 | $ cp /tmp/jsch-agent-proxy/jsch-agent-proxy/dist/lib/*.jar lib/ 91 | $ ant 92 | $ java -cp './lib/*.jar:./dist/lib/*.jar' \ 93 | -Djcterm.config.use_ssh_agent=true \ 94 | com.jcraft.jcterm.JCTermSwingFrame 95 | 96 | 97 | On-Line Demo 98 | ============ 99 | On-Line demo is available at http://wiredx.net/jcterm/ . 100 | On this page, the digitally signed JCterm applet is provided and 101 | you can try JCterm on the web browser. In starting this applet, 102 | you will receive a Java Security prompt asking to deny/grant to run it. 103 | 104 | 105 | JCTerm for J2ME/CDC platform 106 | ============================ 107 | JCTermJ2MECDC is the port of JCTerm to J2ME/CDC platform. 108 | 109 | How to Compile 110 | ============== 111 | To compile this program, you need BouncyCastle Crypto API 112 | (http://www.bouncycastle.org/) 1.26 or later and JSch for 113 | J2ME/CDC, which is available at http://j2me.jsch.org/ . 114 | 115 | Confirmed Devices 116 | ================= 117 | We have heard that this program is running on the following device. 118 | * SHARP Zaurus SL-C700 119 | The binary for this device is available at http://j2me.jsch.org/ . 120 | * SHARP Zaurus SL-C760 121 | 122 | 123 | JCTerm for J2ME/CLDC/MIDP2.0 124 | ============================ 125 | JCTermMIDP is the port of JCTerm to J2ME/CLDC/MIDP2.0 platform. 126 | 127 | How to Compile 128 | ============== 129 | To compile this midlet, you need BouncyCastle Crypto API 130 | (http://www.bouncycastle.org/) 1.26 or later and JSch for 131 | J2ME/CLDC/MIDP2.0, which is available at http://j2me.jsch.org/ . 132 | We have confirmed that this midlet is compilable on Sun's Wireless 133 | Toolkit 2.2. You have to delete following files before compilation process, 134 | * src/com/jcraft/jcterm/JCTerm.java 135 | * src/com/jcraft/jcterm/JCTermAWT.java 136 | * src/com/jcraft/jcterm/JCTermApplet.java 137 | * src/com/jcraft/jcterm/JCTermJ2MECDC.java 138 | * src/com/jcraft/jcterm/Sftp.java 139 | * src/com/jcraft/jcterm/Splash.java 140 | The jar and jad files are available at http://j2me.jsch.org/ . 141 | 142 | Public-key Authentication 143 | ========================= 144 | Current version supports password authentication and public-key 145 | authentication. This midlet will allow you to install private keys 146 | into MIDP's RecordStore. After staring this midlet, you will find 147 | the checkbox 'Install private key', If you select this checkbox and 148 | connect to the remote host with password authentication , following commands 149 | 'cat ~/.ssh/id_rsa' and 'cat ~/.ssh/id_dsa' 150 | will be remotely execed and outputs will be stored locally. 151 | In the next time, public-key authentication will be tried. 152 | Of course, we strongly recommend to encrypt id_rsa' and 'id_dsa'. 153 | 154 | Confirmed Devices 155 | ================= 156 | We have heard that this midlet is running on the following device. 157 | * Motorola c650 158 | 159 | 160 | TODO 161 | ==== 162 | * VT100 emulation is incomplete. 163 | 164 | 165 | Copyrights & Disclaimers 166 | ======================== 167 | JCterm is copyrighted by JCraft,Inc. and is licensed through the 168 | GNU Library General Public License. 169 | Read the COPYING file for the complete license. 170 | 171 | 172 | If you have any comments, suggestions and questions, write us 173 | at ymnk@jcraft.com 174 | 175 | 176 | ``SSH is a registered trademark and Secure Shell is a trademark of 177 | SSH Communications Security Corp (www.ssh.com)''. 178 | -------------------------------------------------------------------------------- /build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 28 | 30 | 31 | 32 | 37 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 47 | 48 | 49 | 50 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jcterm/Configuration.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; -*- */ 2 | /* JCTerm 3 | * Copyright (C) 20012 ymnk, JCraft,Inc. 4 | * 5 | * Written by: ymnk 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Library General Public License 10 | * as published by the Free Software Foundation; either version 2 of 11 | * the License, or (at your option) any later version. 12 | 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Library General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Library General Public 19 | * License along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | */ 22 | 23 | package com.jcraft.jcterm; 24 | 25 | import java.awt.Color; 26 | import java.util.Vector; 27 | 28 | /** 29 | * This class abstracts settings from JCTerm. 30 | * - font size 31 | * - pairs of foreground and background color 32 | * - list of destinations for the prompt. 33 | * 34 | * @see com.jcraft.jcterm.ConfigurationRepository 35 | */ 36 | public class Configuration { 37 | public static int FONT_SIZE = 14; 38 | public static String[] FG_BG = {"#000000:#ffffff", "#ffffff:#000000"}; 39 | public static String[] DESTINATIONS = new String[0]; 40 | 41 | public String name = "default"; 42 | public int font_size = FONT_SIZE; 43 | public String[] fg_bg = FG_BG.clone(); 44 | public String[] destinations = DESTINATIONS; 45 | 46 | public synchronized void addDestination(String d){ 47 | destinations = add(d, destinations); 48 | } 49 | 50 | public synchronized void addFgBg(String d){ 51 | fg_bg = add(d, fg_bg); 52 | } 53 | 54 | private String[] add(String d, String[]array){ 55 | int i=0; 56 | while(i0){ 68 | System.arraycopy(array, 0, foo, 1, array.length); 69 | } 70 | foo[0]=d; 71 | array=foo; 72 | return array; 73 | } 74 | 75 | static String[] parseDestinations(String d){ 76 | String[] tmp = d.split(","); 77 | if(tmp.length==1 && tmp[0].length()==0) 78 | tmp = new String[0]; 79 | return tmp; 80 | } 81 | 82 | static String[] parseFgBg(String fg_bg){ 83 | Vector v = new Vector(); 84 | String[] _fg_bg = fg_bg.split(","); 85 | for(int i=0; i < _fg_bg.length; i++){ 86 | String[] tmp = _fg_bg[i].split(":"); 87 | if(tmp.length!=2) 88 | continue; 89 | Color fg = JCTermSwing.toColor(tmp[0]); 90 | Color bg = JCTermSwing.toColor(tmp[1]); 91 | if(fg!=null && bg!=null){ 92 | v.addElement(_fg_bg[i]); 93 | } 94 | } 95 | if(v.size()==0) return null; 96 | return v.toArray(new String[0]); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jcterm/ConfigurationRepository.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; -*- */ 2 | /* JCTerm 3 | * Copyright (C) 20012 ymnk, JCraft,Inc. 4 | * 5 | * Written by: ymnk 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Library General Public License 10 | * as published by the Free Software Foundation; either version 2 of 11 | * the License, or (at your option) any later version. 12 | 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Library General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Library General Public 19 | * License along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | */ 22 | 23 | package com.jcraft.jcterm; 24 | 25 | /** 26 | * This interface abstracts where the configuration is stored to and 27 | * retrived from. 28 | * 29 | * @see com.jcraft.jcterm.Configuration 30 | * @see com.jcraft.jcterm.ConfigurationRepositoryFS 31 | */ 32 | public interface ConfigurationRepository { 33 | Configuration load(String name); 34 | void save(Configuration conf); 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jcterm/ConfigurationRepositoryFS.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */ 2 | /* JCTerm 3 | * Copyright (C) 2002,2007 ymnk, JCraft,Inc. 4 | * 5 | * Written by: ymnk 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Library General Public License 10 | * as published by the Free Software Foundation; either version 2 of 11 | * the License, or (at your option) any later version. 12 | 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Library General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Library General Public 19 | * License along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | */ 22 | 23 | package com.jcraft.jcterm; 24 | import java.io.*; 25 | import java.util.Vector; 26 | 27 | /** 28 | * This class will save the configuration into ~/.ssh/jcterm.properties 29 | * file in property file format. 30 | * 31 | * @see com.jcraft.jcterm.Configuration 32 | * @see com.jcraft.jcterm.ConfigurationRepository 33 | */ 34 | public class ConfigurationRepositoryFS implements ConfigurationRepository { 35 | 36 | private File ssh_home = new File(System.getProperty("user.home"), ".ssh"); 37 | private File jcterm_prop = new File(ssh_home, "jcterm.properties"); 38 | 39 | public Configuration load(String name){ 40 | Configuration conf = new Configuration(); 41 | conf.name = name; 42 | 43 | java.util.Properties prop = new java.util.Properties(); 44 | InputStream in = null; 45 | 46 | try{ 47 | in = new FileInputStream(jcterm_prop); 48 | prop.load(in); 49 | 50 | String key="jcterm."+name+".font_size"; 51 | if(prop.get(key)!=null){ 52 | try{ 53 | conf.font_size = Integer.parseInt((String)prop.get(key)); 54 | } 55 | catch(Exception ee){ 56 | // ignore it because of loading incompatible data. 57 | } 58 | } 59 | 60 | try{ 61 | key = "jcterm."+name+".fg_bg"; 62 | if(prop.get(key) != null) 63 | conf.fg_bg = ((String)prop.get(key)).split(","); 64 | } 65 | catch(Exception ee){ 66 | // ignore it because of loading incompatible data. 67 | } 68 | 69 | try{ 70 | key = "jcterm."+name+".destination"; 71 | if(prop.get(key) != null) 72 | conf.destinations = ((String)prop.get(key)).split(","); 73 | } 74 | catch(Exception ee){ 75 | // ignore it because of loading incompatible data. 76 | } 77 | 78 | in.close(); 79 | } 80 | catch(Exception e){ 81 | // the file does not exist. 82 | } 83 | 84 | return conf; 85 | } 86 | 87 | public void save(Configuration conf){ 88 | java.util.Properties prop = new java.util.Properties(); 89 | InputStream in = null; 90 | try{ 91 | in = new FileInputStream(jcterm_prop); 92 | prop.load(in); 93 | in.close(); 94 | } 95 | catch(IOException e){ 96 | // the file does not exist. 97 | } 98 | 99 | String name = conf.name; 100 | 101 | prop.setProperty("jcterm."+name+".destination", join(conf.destinations)); 102 | 103 | prop.setProperty("jcterm."+name+".font_size", 104 | new Integer(conf.font_size).toString()); 105 | 106 | prop.setProperty("jcterm."+name+".fg_bg", join(conf.fg_bg)); 107 | 108 | try{ 109 | OutputStream out = new FileOutputStream(jcterm_prop); 110 | prop.store(out, ""); 111 | out.close(); 112 | } 113 | catch(IOException e){ 114 | // failed to save file. 115 | } 116 | } 117 | 118 | String join(String[] array){ 119 | StringBuilder builder = new StringBuilder(); 120 | for (int i = 0; i < array.length; i++) { 121 | builder.append(array[i]); 122 | if(i+1 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Library General Public License 10 | * as published by the Free Software Foundation; either version 2 of 11 | * the License, or (at your option) any later version. 12 | 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Library General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Library General Public 19 | * License along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | */ 22 | 23 | package com.jcraft.jcterm; 24 | 25 | import java.io.InputStream; 26 | import java.io.OutputStream; 27 | 28 | public interface Connection{ 29 | 30 | InputStream getInputStream(); 31 | 32 | OutputStream getOutputStream(); 33 | 34 | void requestResize(Term term); 35 | 36 | void close(); 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jcterm/Emulator.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; -*- */ 2 | /* JCTerm 3 | * Copyright (C) 2002,2007 ymnk, JCraft,Inc. 4 | * 5 | * Written by: ymnk 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Library General Public License 10 | * as published by the Free Software Foundation; either version 2 of 11 | * the License, or (at your option) any later version. 12 | 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Library General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Library General Public 19 | * License along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | */ 22 | 23 | package com.jcraft.jcterm; 24 | 25 | import java.io.InputStream; 26 | import java.io.IOException; 27 | 28 | public abstract class Emulator{ 29 | Term term=null; 30 | InputStream in=null; 31 | 32 | public Emulator(Term term, InputStream in){ 33 | this.term=term; 34 | this.in=in; 35 | } 36 | 37 | public abstract void start(); 38 | 39 | public abstract byte[] getCodeENTER(); 40 | 41 | public abstract byte[] getCodeUP(); 42 | 43 | public abstract byte[] getCodeDOWN(); 44 | 45 | public abstract byte[] getCodeRIGHT(); 46 | 47 | public abstract byte[] getCodeLEFT(); 48 | 49 | public abstract byte[] getCodeF1(); 50 | 51 | public abstract byte[] getCodeF2(); 52 | 53 | public abstract byte[] getCodeF3(); 54 | 55 | public abstract byte[] getCodeF4(); 56 | 57 | public abstract byte[] getCodeF5(); 58 | 59 | public abstract byte[] getCodeF6(); 60 | 61 | public abstract byte[] getCodeF7(); 62 | 63 | public abstract byte[] getCodeF8(); 64 | 65 | public abstract byte[] getCodeF9(); 66 | 67 | public abstract byte[] getCodeF10(); 68 | 69 | public abstract byte[] getCodeTAB(); 70 | 71 | public void reset(){ 72 | term_width=term.getColumnCount(); 73 | term_height=term.getRowCount(); 74 | char_width=term.getCharWidth(); 75 | char_height=term.getCharHeight(); 76 | region_y1=1; 77 | region_y2=term_height; 78 | } 79 | 80 | byte[] buf=new byte[1024]; 81 | int bufs=0; 82 | int buflen=0; 83 | 84 | byte getChar() throws java.io.IOException{ 85 | if(buflen==0){ 86 | fillBuf(); 87 | } 88 | buflen--; 89 | 90 | // System.out.println("getChar: "+new Character((char)buf[bufs])+"["+Integer.toHexString(buf[bufs]&0xff)+"]"); 91 | 92 | return buf[bufs++]; 93 | } 94 | 95 | void fillBuf() throws java.io.IOException{ 96 | buflen=bufs=0; 97 | buflen=in.read(buf, bufs, buf.length-bufs); 98 | /* 99 | System.out.println("fillBuf: "); 100 | for(int i=0; i=term_width*char_width){ 308 | x=0; 309 | y+=char_height; 310 | } 311 | term.setCursor(x, y); 312 | term.draw_cursor(); 313 | } 314 | 315 | protected void carriage_return(){ 316 | term.draw_cursor(); 317 | x=0; 318 | term.setCursor(x, y); 319 | term.draw_cursor(); 320 | } 321 | 322 | protected void cursor_left(){ 323 | term.draw_cursor(); 324 | x-=char_width; 325 | if(x<0){ 326 | y-=char_height; 327 | x=term_width*char_width-char_width; 328 | } 329 | term.setCursor(x, y); 330 | term.draw_cursor(); 331 | } 332 | 333 | protected void cursor_down(){ 334 | term.draw_cursor(); 335 | y+=char_height; 336 | term.setCursor(x, y); 337 | term.draw_cursor(); 338 | 339 | check_region(); 340 | } 341 | 342 | private byte[] b2=new byte[2]; 343 | private byte[] b1=new byte[1]; 344 | 345 | protected void draw_text() throws java.io.IOException{ 346 | 347 | int rx; 348 | int ry; 349 | int w; 350 | int h; 351 | 352 | check_region(); 353 | 354 | rx=x; 355 | ry=y; 356 | 357 | byte b=getChar(); 358 | term.draw_cursor(); 359 | //System.out.print(new Character((char)b)+"["+Integer.toHexString(b&0xff)+"]"); 360 | if((b&0x80)!=0){ 361 | term.clear_area(x, y-char_height, x+char_width*2, y); 362 | b2[0]=b; 363 | b2[1]=getChar(); 364 | term.drawString(new String(b2, 0, 2, "EUC-JP"), x, y); 365 | x+=char_width; 366 | x+=char_width; 367 | w=char_width*2; 368 | h=char_height; 369 | } 370 | else{ 371 | pushChar(b); 372 | int foo=getASCII(term_width-(x/char_width)); 373 | if(foo!=0){ 374 | //System.out.println("foo="+foo+" "+x+", "+(y-char_height)+" "+(x+foo*char_width)+" "+y+" "+buf+" "+bufs+" "+b+" "+buf[bufs-foo]); 375 | //System.out.println("foo="+foo+" ["+new String(buf, bufs-foo, foo)); 376 | term.clear_area(x, y-char_height, x+foo*char_width, y); 377 | term.drawBytes(buf, bufs-foo, foo, x, y); 378 | } 379 | else{ 380 | foo=1; 381 | term.clear_area(x, y-char_height, x+foo*char_width, y); 382 | b1[0]=getChar(); 383 | term.drawBytes(b1, 0, foo, x, y); 384 | //System.out.print("["+Integer.toHexString(bar[0]&0xff)+"]"); 385 | } 386 | x+=(char_width*foo); 387 | w=char_width*foo; 388 | h=char_height; 389 | } 390 | term.redraw(rx, ry-char_height, w, h); 391 | term.setCursor(x, y); 392 | term.draw_cursor(); 393 | } 394 | 395 | private void check_region(){ 396 | if(x>=term_width*char_width){ 397 | //System.out.println("!! "+new Character((char)b)+"["+Integer.toHexString(b&0xff)+"]"); 398 | x=0; 399 | y+=char_height; 400 | //System.out.println("@1: ry="+ry); 401 | } 402 | 403 | if(y>region_y2*char_height){ 404 | while(y>region_y2*char_height){ 405 | y-=char_height; 406 | } 407 | term.draw_cursor(); 408 | term.scroll_area(0, region_y1*char_height, term_width*char_width, 409 | (region_y2-region_y1)*char_height, 0, -char_height); 410 | term.clear_area(0, y-char_height, term_width*char_width, y); 411 | term.redraw(0, 0, term_width*char_width, region_y2*char_height); 412 | term.setCursor(x, y); 413 | term.draw_cursor(); 414 | } 415 | } 416 | } 417 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jcterm/EmulatorVT100.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; -*- */ 2 | /* JCTerm 3 | * Copyright (C) 2002,2007 ymnk, JCraft,Inc. 4 | * 5 | * Written by: ymnk 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Library General Public License 10 | * as published by the Free Software Foundation; either version 2 of 11 | * the License, or (at your option) any later version. 12 | 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Library General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Library General Public 19 | * License along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | */ 22 | 23 | package com.jcraft.jcterm; 24 | 25 | import java.io.InputStream; 26 | 27 | public class EmulatorVT100 extends Emulator{ 28 | 29 | public EmulatorVT100(Term term, InputStream in){ 30 | super(term, in); 31 | } 32 | 33 | public void setInputStream(InputStream in){ 34 | this.in=in; 35 | } 36 | 37 | public void setTerm(Term term){ 38 | this.term=term; 39 | } 40 | 41 | public void start(){ 42 | reset(); 43 | 44 | int[] intarg=new int[10]; 45 | int intargi=0; 46 | 47 | x=0; 48 | y=char_height; 49 | 50 | byte b; 51 | 52 | try{ 53 | while(true){ 54 | 55 | b=getChar(); 56 | 57 | //System.out.println("@0: "+ new Character((char)b)+"["+Integer.toHexString(b&0xff)+"]"); 58 | 59 | //System.out.println("@0: ry="+ry); 60 | 61 | /* 62 | outputs from infocmp on RedHat8.0 63 | # Reconstructed via infocmp from file: /usr/share/terminfo/v/vt100 64 | vt100|vt100-am|dec vt100 (w/advanced video), 65 | am, msgr, xenl, xon, 66 | cols#80, it#8, lines#24, vt#3, 67 | acsc=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~, 68 | bel=^G, blink=\E[5m$<2>, bold=\E[1m$<2>, 69 | clear=\E[H\E[J$<50>, cr=^M, csr=\E[%i%p1%d;%p2%dr, 70 | cub=\E[%p1%dD, cub1=^H, cud=\E[%p1%dB, cud1=^J, 71 | cuf=\E[%p1%dC, cuf1=\E[C$<2>, 72 | cup=\E[%i%p1%d;%p2%dH$<5>, cuu=\E[%p1%dA, 73 | cuu1=\E[A$<2>, ed=\E[J$<50>, el=\E[K$<3>, el1=\E[1K$<3>, 74 | enacs=\E(B\E)0, home=\E[H, ht=^I, hts=\EH, ind=^J, ka1=\EOq, 75 | ka3=\EOs, kb2=\EOr, kbs=^H, kc1=\EOp, kc3=\EOn, kcub1=\EOD, 76 | kcud1=\EOB, kcuf1=\EOC, kcuu1=\EOA, kent=\EOM, kf0=\EOy, 77 | kf1=\EOP, kf10=\EOx, kf2=\EOQ, kf3=\EOR, kf4=\EOS, kf5=\EOt, 78 | kf6=\EOu, kf7=\EOv, kf8=\EOl, kf9=\EOw, rc=\E8, 79 | rev=\E[7m$<2>, ri=\EM$<5>, rmacs=^O, rmam=\E[?7l, 80 | rmkx=\E[?1l\E>, rmso=\E[m$<2>, rmul=\E[m$<2>, 81 | rs2=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h, sc=\E7, 82 | sgr=\E[0%?%p1%p6%|%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;m%?%p9%t\016%e\017%;$<2>, 83 | sgr0=\E[m\017$<2>, smacs=^N, smam=\E[?7h, smkx=\E[?1h\E=, 84 | smso=\E[7m$<2>, smul=\E[4m$<2>, tbc=\E[3g, 85 | */ 86 | /* 87 | am terminal has automatic margnins 88 | msgr safe to move while in standout mode 89 | xenl newline ignored after 80 cols (concept) 90 | xon terminal uses xon/xoff handshake 91 | cols number of columns in a line 92 | it tabs initially every # spaces 93 | lines number of lines on screen of page 94 | vt virstual terminal number(CB/unix) 95 | acsc graphics charset pairs, based on vt100 96 | bel bell 97 | blink turn on blinking 98 | bold turn on bold(extra bright) mode 99 | clear clear screen and home cursor(P*) 100 | cr carriage return (P)(P*) 101 | csr change region to line #1 to line #2(P) 102 | cub move #1 characters to the left (P) 103 | cub1 move left one space 104 | cud down #1 lines (P*) 105 | cud1 down one line 106 | cuf move to #1 characters to the right. 107 | cuf1 non-destructive space (move right one space) 108 | cup move to row #1 columns #2 109 | cuu up #1 lines (P*) 110 | cuu1 up one line 111 | ed clear to end of screen (P*) 112 | el clear to end of line (P) 113 | el1 Clear to begining of line 114 | enacs enable alterate char set 115 | home home cursor (if no cup) 116 | ht tab to next 8-space hardware tab stop 117 | hts set a tab in every row, current columns 118 | ind scroll text up 119 | ka1 upper left of keypad 120 | ka3 upper right of keypad 121 | kb2 center of keypad 122 | kbs backspace key 123 | kc1 lower left of keypad 124 | kc3 lower right of keypad 125 | kcub1 left-arrow key 126 | kcud1 down-arrow key 127 | kcuf1 right-arrow key 128 | kcuu1 up-arrow key 129 | kent enter/sekd key 130 | kf0 F0 function key 131 | kf1 F1 function key 132 | kf10 F10 function key 133 | kf2 F2 function key 134 | kf3 F3 function key 135 | kf4 F4 function key 136 | kf5 F5 function key 137 | kf6 F6 function key 138 | kf7 F7 function key 139 | kf8 F8 function key 140 | kf9 F9 function key 141 | rc restore cursor to position of last save_cursor 142 | rev turn on reverse video mode 143 | ri scroll text down (P) 144 | rmacs end alternate character set 145 | rmam turn off automatic margins 146 | rmkx leave 'keybroad_transmit' mode 147 | rmso exit standout mode 148 | rmul exit underline mode 149 | rs2 reset string 150 | sc save current cursor position (P) 151 | sgr define video attribute #1-#9(PG9) 152 | sgr0 turn off all attributes 153 | smacs start alternate character set (P) 154 | smam turn on automatic margins 155 | smkx enter 'keyborad_transmit' mode 156 | smso begin standout mode 157 | smul begin underline mode 158 | tbc clear all tab stops(P) 159 | */ 160 | if(b==0){ 161 | continue; 162 | } 163 | 164 | if(b==0x1b){ 165 | b=getChar(); 166 | 167 | //System.out.println("@1: "+ new Character((char)b)+"["+Integer.toHexString(b&0xff)+"]"); 168 | 169 | if(b=='M'){ // sr \EM sr scroll text down (P) 170 | scroll_reverse(); 171 | continue; 172 | } 173 | 174 | if(b=='D'){ // sf 175 | scroll_forward(); 176 | continue; 177 | } 178 | 179 | if(b=='7'){ 180 | save_cursor(); 181 | continue; 182 | } 183 | 184 | if(b=='('){ 185 | b=getChar(); 186 | if(b=='B'){ 187 | b=getChar(); 188 | if(b==0x1b){ 189 | b=getChar(); 190 | if(b==')'){ 191 | b=getChar(); 192 | if(b=='0'){ // enacs 193 | ena_acs(); 194 | continue; 195 | } 196 | else{ 197 | pushChar((byte)'0'); 198 | } 199 | } 200 | else{ 201 | pushChar((byte)')'); 202 | } 203 | } 204 | else{ 205 | pushChar((byte)0x1b); 206 | } 207 | } 208 | else{ 209 | pushChar((byte)'B'); 210 | } 211 | } 212 | 213 | if(b=='>'){ 214 | b=getChar(); // 0x1b 215 | b=getChar(); // '[' 216 | b=getChar(); // '?' 217 | b=getChar(); // '3' 218 | b=getChar(); // 'l' 219 | b=getChar(); // 0x1b 220 | b=getChar(); // '[' 221 | b=getChar(); // '?' 222 | b=getChar(); // '4' 223 | b=getChar(); // 'l' 224 | b=getChar(); // 0x1b 225 | b=getChar(); // '[' 226 | b=getChar(); // '?' 227 | b=getChar(); // '5' 228 | b=getChar(); // 'l' 229 | b=getChar(); // 0x1b 230 | b=getChar(); // '[' 231 | b=getChar(); // '?' 232 | b=getChar(); // '7' 233 | b=getChar(); // 'h' 234 | b=getChar(); // 0x1b 235 | b=getChar(); // '[' 236 | b=getChar(); // '?' 237 | b=getChar(); // '8' 238 | b=getChar(); // 'h' 239 | 240 | reset_2string(); 241 | continue; 242 | } 243 | 244 | if(b!='['){ 245 | System.out.print("@11: "+new Character((char)b)+"[" 246 | +Integer.toHexString(b&0xff)+"]"); 247 | pushChar(b); 248 | continue; 249 | } 250 | 251 | //System.out.print("@2: "+ new Character((char)b)+"["+Integer.toHexString(b&0xff)+"]"); 252 | 253 | intargi=0; 254 | intarg[intargi]=0; 255 | int digit=0; 256 | 257 | while(true){ 258 | b=getChar(); 259 | //System.out.print("#"+new Character((char)b)+"["+Integer.toHexString(b&0xff)+"]"); 260 | if(b==';'){ 261 | if(digit>0){ 262 | intargi++; 263 | intarg[intargi]=0; 264 | digit=0; 265 | } 266 | continue; 267 | } 268 | 269 | if('0'<=b&&b<='9'){ 270 | intarg[intargi]=intarg[intargi]*10+(b-'0'); 271 | digit++; 272 | continue; 273 | } 274 | 275 | pushChar(b); 276 | break; 277 | } 278 | 279 | b=getChar(); 280 | 281 | //System.out.print("@4: "+ new Character((char)b)+"["+Integer.toHexString(b&0xff)+"]"); 282 | 283 | if(b=='m'){ 284 | /* 285 | b=getChar(); 286 | if(b=='$'){ 287 | b=getChar(); // < 288 | b=getChar(); // 2 289 | b=getChar(); // > 290 | } 291 | else{ 292 | pushChar(b); 293 | } 294 | */ 295 | 296 | if(digit==0&&intargi==0){ 297 | b=getChar(); 298 | if(b==0x0f){ // sgr0 299 | exit_attribute_mode(); 300 | continue; 301 | } 302 | else{ // rmso, rmul 303 | exit_underline_mode(); 304 | exit_standout_mode(); 305 | pushChar(b); 306 | continue; 307 | } 308 | } 309 | 310 | for(int i=0; i<=intargi; i++){ 311 | Object fg=null; 312 | Object bg=null; 313 | Object tmp=null; 314 | 315 | switch(intarg[i]){ 316 | case 0: // Reset all attributes 317 | exit_standout_mode(); 318 | continue; 319 | case 1: // Bright // bold 320 | enter_bold_mode(); 321 | continue; 322 | case 2: // Dim 323 | break; 324 | case 4: // Underline 325 | enter_underline_mode(); 326 | continue; 327 | case 5: // Blink 328 | case 8: // Hidden 329 | break; 330 | case 7: // reverse 331 | enter_reverse_mode(); 332 | continue; 333 | case 30: 334 | case 31: 335 | case 32: 336 | case 33: 337 | case 34: 338 | case 35: 339 | case 36: 340 | case 37: 341 | tmp=term.getColor(intarg[i]-30); 342 | if(tmp!=null) 343 | fg=tmp; 344 | break; 345 | case 40: 346 | case 41: 347 | case 42: 348 | case 43: 349 | case 44: 350 | case 45: 351 | case 46: 352 | case 47: 353 | tmp=term.getColor(intarg[i]-40); 354 | if(tmp!=null) 355 | bg=tmp; 356 | break; 357 | default: 358 | break; 359 | } 360 | if(fg!=null) 361 | term.setForeGround(fg); 362 | if(bg!=null) 363 | term.setBackGround(bg); 364 | } 365 | //System.out.println("fg: "+fg+" bg: "+bg); 366 | continue; 367 | } 368 | 369 | if(b=='r'){ // csr 370 | change_scroll_region(intarg[0], intarg[1]); 371 | //System.out.println("r: "+region_y1+", "+region_y2+", intargi="+intargi); 372 | continue; 373 | } 374 | 375 | if(b=='H'){ // cup 376 | /* 377 | b=getChar(); 378 | if(b!='$'){ // home 379 | pushChar(b); 380 | } 381 | else{ 382 | b=getChar(); // < 383 | b=getChar(); // 5 384 | b=getChar(); // > 385 | } 386 | */ 387 | 388 | if(digit==0&&intargi==0){ 389 | intarg[0]=intarg[1]=1; 390 | } 391 | 392 | //System.out.println("H: "+region_y1+", "+region_y2+", intargi="+intargi); 393 | cursor_address(intarg[0], intarg[1]); 394 | continue; 395 | } 396 | 397 | if(b=='B'){ // cud 398 | parm_down_cursor(intarg[0]); 399 | continue; 400 | } 401 | 402 | if(b=='D'){ // cub 403 | parm_left_cursor(intarg[0]); 404 | continue; 405 | } 406 | 407 | if(b=='C'){ // cuf 408 | if(digit==0&&intargi==0){ 409 | intarg[0]=1; 410 | } 411 | parm_right_cursor(intarg[0]); 412 | continue; 413 | } 414 | 415 | if(b=='K'){ // el 416 | /* 417 | b=getChar(); // 418 | if(b=='$'){ 419 | b=getChar(); // < 420 | b=getChar(); // 3 421 | b=getChar(); // > 422 | } 423 | else{ 424 | pushChar(b); 425 | } 426 | */ 427 | 428 | if(digit==0&&intargi==0){ // el 429 | clr_eol(); 430 | } 431 | else{ // el1 432 | clr_bol(); 433 | } 434 | continue; 435 | } 436 | 437 | if(b=='J'){ 438 | //for(int i=0; i, JCraft,Inc.\n"+ 36 | "Official Homepage: http://www.jcraft.com/jcterm/\n"+ 37 | "This software is licensed under GNU LGPL."; 38 | 39 | private OutputStream out; 40 | private InputStream in; 41 | Emulator emulator=null; 42 | 43 | Connection connection=null; 44 | 45 | private Image img; 46 | //private Image background; 47 | private Graphics cursor_graphics; 48 | private Graphics graphics; 49 | private java.awt.Color defaultbground=Color.black; 50 | private java.awt.Color defaultfground=Color.white; 51 | private java.awt.Color bground=Color.black; 52 | private java.awt.Color fground=Color.white; 53 | private java.awt.Component term_area=null; 54 | private java.awt.Font font; 55 | 56 | private boolean bold=false; 57 | private boolean underline=false; 58 | private boolean reverse=false; 59 | 60 | private int term_width=80; 61 | private int term_height=24; 62 | 63 | private int x=0; 64 | private int y=0; 65 | private int descent=0; 66 | 67 | private int char_width; 68 | private int char_height; 69 | 70 | /* 71 | private String xhost="127.0.0.1"; 72 | private int xport=0; 73 | private boolean xforwarding=false; 74 | private String user=System.getProperty("user.name"); 75 | private String host="127.0.0.1"; 76 | 77 | private String proxy_http_host=null; 78 | private int proxy_http_port=0; 79 | 80 | private String proxy_socks5_host=null; 81 | private int proxy_socks5_port=0; 82 | */ 83 | 84 | private boolean antialiasing=true; 85 | // private int line_space=0; 86 | private int line_space=-2; 87 | private int compression=0; 88 | 89 | private Splash splash=null; 90 | 91 | private final Object[] colors={Color.black, Color.red, Color.green, 92 | Color.yellow,Color.blue, 93 | Color.magenta, Color.cyan, Color.white}; 94 | 95 | public JCTermAWT(){ 96 | enableEvents(AWTEvent.KEY_EVENT_MASK); 97 | /* 98 | initGraphics(); 99 | */ 100 | } 101 | 102 | private void setFont(String fname){ 103 | font=java.awt.Font.decode(fname); 104 | Image img=createImage(1, 1); 105 | Graphics graphics=img.getGraphics(); 106 | graphics.setFont(font); 107 | { 108 | FontMetrics fo = graphics.getFontMetrics(); 109 | descent=fo.getDescent(); 110 | //System.out.println(fo.getDescent()); 111 | //System.out.println(fo.getAscent()); 112 | //System.out.println(fo.getLeading()); 113 | //System.out.println(fo.getHeight()); 114 | //System.out.println(fo.getMaxAscent()); 115 | //System.out.println(fo.getMaxDescent()); 116 | //System.out.println(fo.getMaxDecent()); 117 | //System.out.println(fo.getMaxAdvance()); 118 | char_width=(int)(fo.charWidth((char)'@')); 119 | char_height=(int)(fo.getHeight())+(line_space*2); 120 | // descent+=line_space; 121 | } 122 | img.flush(); 123 | graphics.dispose(); 124 | } 125 | 126 | void initGraphics(){ 127 | setFont("Monospaced-14"); 128 | /* 129 | background=createImage(char_width, char_height); 130 | { 131 | Graphics foog=background.getGraphics(); 132 | foog.setColor(getBackGround()); 133 | foog.fillRect(0, 0, char_width, char_height); 134 | foog.dispose(); 135 | } 136 | */ 137 | 138 | img=createImage(getTermWidth(), getTermHeight()); 139 | graphics=img.getGraphics(); 140 | graphics.setFont(font); 141 | if(splash!=null) splash.draw(img, getTermWidth(), getTermHeight()); 142 | else clear(); 143 | cursor_graphics=(img.getGraphics()); 144 | cursor_graphics.setColor(getForeGround()); 145 | cursor_graphics.setXORMode(getBackGround()); 146 | 147 | term_area=this; 148 | 149 | Panel panel=this; 150 | panel.setSize(getTermWidth(), getTermHeight()); 151 | panel.setFocusable(true); 152 | } 153 | 154 | public void setFrame(java.awt.Component term_area){ 155 | this.term_area=term_area; 156 | } 157 | 158 | private Thread thread=null; 159 | 160 | public void start(Connection connection){ 161 | this.connection=connection; 162 | in=connection.getInputStream(); 163 | out=connection.getOutputStream(); 164 | emulator=new EmulatorVT100(this, in); 165 | emulator.reset(); 166 | emulator.start(); 167 | 168 | if(splash!=null) 169 | splash.draw(img, getTermWidth(), getTermHeight()); 170 | else 171 | clear(); 172 | redraw(0, 0, getTermWidth(), getTermHeight()); 173 | } 174 | 175 | /* 176 | MyUserInfo ui=null; 177 | 178 | public void run(){ 179 | while(thread!=null){ 180 | try{ 181 | try{ 182 | } 183 | catch(Exception e){ 184 | //System.out.println(e); 185 | break; 186 | } 187 | requestFocus(); 188 | emulator=new EmulatorVT100(this, in); 189 | emulator.reset(); 190 | emulator.start(); 191 | } 192 | catch(Exception e){ 193 | //e.printStackTrace(); 194 | } 195 | break; 196 | } 197 | 198 | thread=null; 199 | 200 | if(splash!=null) 201 | splash.draw(img, getTermWidth(), getTermHeight()); 202 | else 203 | clear(); 204 | 205 | redraw(0, 0, getTermWidth(), getTermHeight()); 206 | } 207 | */ 208 | 209 | public void update(Graphics g){ 210 | //System.out.println("update"); 211 | if(img==null){ 212 | initGraphics(); 213 | } 214 | g.drawImage(img, 0, 0, term_area); 215 | //super.update(g); 216 | } 217 | public void paint(Graphics g){ 218 | //System.out.println("paint"); 219 | if(img==null){ 220 | initGraphics(); 221 | } 222 | g.drawImage(img, 0, 0, term_area); 223 | //super.paint(g); 224 | } 225 | 226 | public void processKeyEvent(KeyEvent e){ 227 | //System.out.println(e); 228 | int id=e.getID(); 229 | if(id == KeyEvent.KEY_PRESSED) { keyPressed(e); } 230 | else if(id == KeyEvent.KEY_RELEASED) { /*keyReleased(e);*/ } 231 | else if(id == KeyEvent.KEY_TYPED) { keyTyped(e);/*keyTyped(e);*/ } 232 | e.consume(); // ?? 233 | } 234 | 235 | byte[] obuffer=new byte[3]; 236 | public void keyPressed(KeyEvent e){ 237 | int keycode=e.getKeyCode(); 238 | byte[] code=null; 239 | switch(keycode){ 240 | case KeyEvent.VK_CONTROL: 241 | case KeyEvent.VK_SHIFT: 242 | case KeyEvent.VK_ALT: 243 | case KeyEvent.VK_CAPS_LOCK: 244 | return; 245 | case KeyEvent.VK_ENTER: 246 | code=emulator.getCodeENTER(); 247 | break; 248 | case KeyEvent.VK_UP: 249 | code=emulator.getCodeUP(); 250 | break; 251 | case KeyEvent.VK_DOWN: 252 | code=emulator.getCodeDOWN(); 253 | break; 254 | case KeyEvent.VK_RIGHT: 255 | code=emulator.getCodeRIGHT(); 256 | break; 257 | case KeyEvent.VK_LEFT: 258 | code=emulator.getCodeLEFT(); 259 | break; 260 | case KeyEvent.VK_F1: 261 | code=emulator.getCodeF1(); 262 | break; 263 | case KeyEvent.VK_F2: 264 | code=emulator.getCodeF2(); 265 | break; 266 | case KeyEvent.VK_F3: 267 | code=emulator.getCodeF3(); 268 | break; 269 | case KeyEvent.VK_F4: 270 | code=emulator.getCodeF4(); 271 | break; 272 | case KeyEvent.VK_F5: 273 | code=emulator.getCodeF5(); 274 | break; 275 | case KeyEvent.VK_F6: 276 | code=emulator.getCodeF6(); 277 | break; 278 | case KeyEvent.VK_F7: 279 | code=emulator.getCodeF7(); 280 | break; 281 | case KeyEvent.VK_F8: 282 | code=emulator.getCodeF8(); 283 | break; 284 | case KeyEvent.VK_F9: 285 | code=emulator.getCodeF9(); 286 | break; 287 | case KeyEvent.VK_F10: 288 | code=emulator.getCodeF10(); 289 | break; 290 | case KeyEvent.VK_TAB: 291 | code=emulator.getCodeTAB(); 292 | break; 293 | } 294 | if(code!=null){ 295 | try{ 296 | out.write(code, 0, code.length); 297 | out.flush(); 298 | } 299 | catch(Exception ee){ 300 | } 301 | return; 302 | } 303 | 304 | char keychar=e.getKeyChar(); 305 | if((keychar&0xff00)==0){ 306 | obuffer[0]=(byte)(e.getKeyChar()); 307 | try{ 308 | out.write(obuffer, 0, 1); 309 | out.flush(); 310 | } 311 | catch(Exception ee){ 312 | } 313 | } 314 | } 315 | 316 | public void keyTyped(KeyEvent e){ 317 | char keychar=e.getKeyChar(); 318 | if((keychar&0xff00)!=0){ 319 | char[] foo=new char[1]; 320 | foo[0]=keychar; 321 | try{ 322 | byte[] goo=new String(foo).getBytes("EUC-JP"); 323 | out.write(goo, 0, goo.length); 324 | out.flush(); 325 | } 326 | catch(Exception eee){ } 327 | } 328 | } 329 | 330 | public int getTermWidth(){ return char_width*term_width; } 331 | public int getTermHeight(){ return char_height*term_height; } 332 | public int getCharWidth(){ return char_width; } 333 | public int getCharHeight(){ return char_height; } 334 | public int getColumnCount(){ return term_width; } 335 | public int getRowCount(){ return term_height; } 336 | 337 | public void clear(){ 338 | graphics.setColor(getBackGround()); 339 | graphics.fillRect(0, 0, char_width*term_width, char_height*term_height); 340 | graphics.setColor(getForeGround()); 341 | } 342 | public void setCursor(int x, int y){ 343 | this.x=x; 344 | this.y=y; 345 | } 346 | public void draw_cursor(){ 347 | cursor_graphics.fillRect(x, y-char_height, char_width, char_height); 348 | // term_area.repaint(x, y-char_height, char_width, char_height); 349 | repaint(x, y-char_height, char_width, char_height); 350 | } 351 | public void redraw(int x, int y, int width, int height){ 352 | // term_area.repaint(x, y, width, height); 353 | repaint(x, y, width, height); 354 | } 355 | public void clear_area(int x1, int y1, int x2, int y2){ 356 | /* 357 | for(int i=y1; i 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Library General Public License 10 | * as published by the Free Software Foundation; either version 2 of 11 | * the License, or (at your option) any later version. 12 | 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Library General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Library General Public 19 | * License along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | */ 22 | 23 | package com.jcraft.jcterm; 24 | 25 | import com.jcraft.jsch.*; 26 | import java.awt.*; 27 | import java.awt.event.*; 28 | import java.io.*; 29 | import java.awt.font.*; 30 | import java.awt.geom.*; 31 | import java.awt.image.*; 32 | 33 | public class JCTermAWTFrame extends java.awt.Frame implements ActionListener, Runnable{ 34 | 35 | private static final int SHELL=0; 36 | private static final int SFTP=1; 37 | private static final int EXEC=2; 38 | 39 | private int mode=SHELL; 40 | int port=22; 41 | 42 | private String xhost="127.0.0.1"; 43 | private int xport=0; 44 | private boolean xforwarding=false; 45 | private String user=System.getProperty("user.name"); 46 | private String host="127.0.0.1"; 47 | 48 | private String proxy_http_host=null; 49 | private int proxy_http_port=0; 50 | 51 | private String proxy_socks5_host=null; 52 | private int proxy_socks5_port=0; 53 | 54 | private JSchSession jschsession=null; 55 | private Proxy proxy=null; 56 | 57 | private int line_space=-2; 58 | private int compression=0; 59 | 60 | private Splash splash=null; 61 | 62 | private JCTermAWT term=null; 63 | 64 | private Connection connection=null; 65 | 66 | public JCTermAWTFrame(String name){ 67 | super(name); 68 | 69 | enableEvents(AWTEvent.KEY_EVENT_MASK); 70 | addWindowListener(new WindowAdapter(){ 71 | public void windowClosing(WindowEvent e){System.exit(0);} 72 | }); 73 | 74 | MenuBar mb=getMenuBar(); 75 | setMenuBar(mb); 76 | 77 | term=new JCTermAWT(); 78 | 79 | setSize(term.getTermWidth(), term.getTermHeight()); 80 | add("Center", term); 81 | 82 | pack(); 83 | term.setVisible(true); 84 | setVisible(true); 85 | 86 | term.initGraphics(); 87 | 88 | setResizable(true); 89 | { 90 | Insets insets=getInsets(); 91 | int foo=term.getTermWidth(); 92 | int bar=term.getTermHeight(); 93 | foo+=(insets.left+insets.right); 94 | bar+=(insets.top+insets.bottom); 95 | setSize(foo, bar); 96 | } 97 | setResizable(false); 98 | } 99 | 100 | private Thread thread=null; 101 | 102 | public void kick(){ 103 | this.thread=new Thread(this); 104 | this.thread.start(); 105 | } 106 | 107 | public void run(){ 108 | while(thread!=null){ 109 | try{ 110 | 111 | try{ 112 | UserInfo ui=new MyUserInfo(); 113 | jschsession=JSchSession.getSession(user, null, host, port, ui, proxy); 114 | java.util.Properties config=new java.util.Properties(); 115 | if(compression==0){ 116 | config.put("compression.s2c", "none"); 117 | config.put("compression.c2s", "none"); 118 | } 119 | else{ 120 | config.put("compression.s2c", "zlib,none"); 121 | config.put("compression.c2s", "zlib,none"); 122 | } 123 | jschsession.getSession().setConfig(config); 124 | jschsession.getSession().rekey(); 125 | } 126 | catch(Exception e){ 127 | //System.out.println(e); 128 | break; 129 | } 130 | 131 | Channel channel=null; 132 | OutputStream out=null; 133 | InputStream in=null; 134 | 135 | if(mode==SHELL){ 136 | channel=jschsession.getSession().openChannel("shell"); 137 | if(xforwarding){ 138 | jschsession.getSession().setX11Host(xhost); 139 | jschsession.getSession().setX11Port(xport+6000); 140 | channel.setXForwarding(true); 141 | } 142 | 143 | out=channel.getOutputStream(); 144 | in=channel.getInputStream(); 145 | channel.connect(); 146 | } 147 | else if(mode==SFTP){ 148 | 149 | out=new PipedOutputStream(); 150 | in=new PipedInputStream(); 151 | 152 | channel=jschsession.getSession().openChannel("sftp"); 153 | 154 | channel.connect(); 155 | 156 | (new Sftp((ChannelSftp)channel, 157 | (InputStream)(new PipedInputStream((PipedOutputStream)out)), 158 | new PipedOutputStream((PipedInputStream)in))).kick(); 159 | } 160 | 161 | final OutputStream fout=out; 162 | final InputStream fin=in; 163 | final Channel fchannel=channel; 164 | 165 | connection=new Connection(){ 166 | public InputStream getInputStream(){return fin;} 167 | public OutputStream getOutputStream(){return fout;} 168 | public void requestResize(Term term){ 169 | if(fchannel instanceof ChannelShell){ 170 | int c=term.getColumnCount(); 171 | int r=term.getRowCount(); 172 | ((ChannelShell)fchannel).setPtySize(c, r, 173 | c*term.getCharWidth(), 174 | r*term.getCharHeight()); 175 | } 176 | } 177 | public void close(){ 178 | fchannel.disconnect(); 179 | } 180 | }; 181 | 182 | setTitle(user+"@"+host+(port!=22 ? new Integer(port).toString() : "")); 183 | term.requestFocus(); 184 | term.start(connection); 185 | } 186 | catch(Exception e){ 187 | //e.printStackTrace(); 188 | } 189 | break; 190 | } 191 | 192 | setTitle("JCTerm"); 193 | thread=null; 194 | } 195 | 196 | public class MyUserInfo implements UserInfo{ 197 | public boolean promptYesNo(String str){ 198 | // System.out.println(str); 199 | PromptDialog dialog=new PromptDialog("Warning",str); 200 | while(true){ 201 | try{Thread.sleep(1000);}catch(Exception e){} 202 | if(!dialog.isVisible()){ 203 | break; 204 | } 205 | } 206 | return dialog.result; 207 | } 208 | 209 | String passwd=null; 210 | String passphrase=null; 211 | 212 | public String getPassword(){ return passwd; } 213 | public String getPassphrase(){ return passphrase; } 214 | 215 | public boolean promptPassword(String message){ 216 | InputDialog dialog=new InputDialog(message, "", true); 217 | passwd=dialog.getText(); 218 | return passwd!=null; 219 | } 220 | public boolean promptPassphrase(String message){ 221 | InputDialog dialog=new InputDialog(message, "", true); 222 | passphrase=dialog.getText(); 223 | return passphrase!=null; 224 | } 225 | public void showMessage(String message){ 226 | MessageDialog msg=new MessageDialog("", message); 227 | } 228 | } 229 | 230 | /** Ignores key released events. */ 231 | public void keyReleased(KeyEvent event){} 232 | // public void keyPressed(KeyEvent event){} 233 | 234 | public void setProxyHttp(String host, int port){ 235 | proxy_http_host=host; 236 | proxy_http_port=port; 237 | if(proxy_http_host!=null && proxy_http_port!=0){ 238 | proxy=new ProxyHTTP(proxy_http_host, proxy_http_port); 239 | } 240 | else{ 241 | proxy=null; 242 | } 243 | } 244 | public String getProxyHttpHost(){return proxy_http_host;} 245 | public int getProxyHttpPort(){return proxy_http_port;} 246 | 247 | public void setProxySOCKS5(String host, int port){ 248 | proxy_socks5_host=host; 249 | proxy_socks5_port=port; 250 | if(proxy_socks5_host!=null && proxy_socks5_port!=0){ 251 | proxy=new ProxySOCKS5(proxy_socks5_host, proxy_socks5_port); 252 | } 253 | else{ 254 | proxy=null; 255 | } 256 | } 257 | public String getProxySOCKS5Host(){return proxy_socks5_host;} 258 | public int getProxySOCKS5Port(){return proxy_socks5_port;} 259 | public void setSplash(Splash foo){this.splash=foo;} 260 | public void setXHost(String xhost){this.xhost=xhost;} 261 | public void setXPort(int xport){this.xport=xport;} 262 | public void setXForwarding(boolean foo){this.xforwarding=foo;} 263 | public void setLineSpace(int foo){this.line_space=foo;} 264 | public void setCompression(int compression){ 265 | if(compression<0 || 9 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Library General Public License 10 | * as published by the Free Software Foundation; either version 2 of 11 | * the License, or (at your option) any later version. 12 | 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Library General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Library General Public 19 | * License along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | */ 22 | 23 | package com.jcraft.jcterm; 24 | 25 | import java.awt.*; 26 | import java.awt.event.*; 27 | import javax.swing.*; 28 | import javax.swing.event.InternalFrameAdapter; 29 | import javax.swing.event.InternalFrameEvent; 30 | 31 | public class JCTermApplet extends JApplet { 32 | JDesktopPane desktop=new JDesktopPane(); 33 | 34 | private String configName = "default"; 35 | 36 | public void init(){ 37 | JCTermSwingFrame.resetCounter(); 38 | String s; 39 | 40 | s = getParameter("jcterm.config.repository"); 41 | if(s!=null){ 42 | try{ 43 | Class c = Class.forName(s); 44 | ConfigurationRepository cr = 45 | (ConfigurationRepository)(c.newInstance()); 46 | JCTermSwing.setCR(cr); 47 | } 48 | catch(Exception e){ 49 | System.err.println("invalid jcterm.config.repository: "+s); 50 | } 51 | } 52 | 53 | s = getParameter("jcterm.config.use_ssh_agent"); 54 | if(s!=null&& s.equals("true")) 55 | JSchSession.useSSHAgent(true); 56 | 57 | s = getParameter("jcterm.config.name"); 58 | if(s!=null){ 59 | configName = s; 60 | } 61 | 62 | Configuration conf = JCTermSwing.getCR().load(configName); 63 | boolean conf_update = false; 64 | 65 | s = getParameter("jcterm.font_size"); 66 | if(s!=null){ 67 | try{ 68 | int font_size = Integer.parseInt(s); 69 | if(conf.font_size == conf.FONT_SIZE){ 70 | conf.font_size = font_size; 71 | conf_update = true; 72 | } 73 | } 74 | catch(NumberFormatException e){ 75 | System.err.println("invalid jcterm.font_size: "+s); 76 | } 77 | } 78 | 79 | s = getParameter("jcterm.destinations"); 80 | if(s!=null){ 81 | String[] tmp = Configuration.parseDestinations(s); 82 | tmp = difference(tmp, conf.destinations); 83 | if(tmp.length>0){ 84 | conf_update = true; 85 | for(int i=tmp.length-1; i>=0; i--){ 86 | conf.addDestination(tmp[i]); 87 | } 88 | } 89 | } 90 | 91 | s = getParameter("jcterm.fg_bg"); 92 | if(s!=null){ 93 | String[]tmp = Configuration.parseFgBg(s); 94 | if(tmp!=null){ 95 | tmp = difference(tmp, conf.fg_bg); 96 | if(tmp.length>0){ 97 | conf_update = true; 98 | for(int i=tmp.length-1; i>=0; i--){ 99 | conf.addFgBg(tmp[i]); 100 | } 101 | } 102 | } 103 | else 104 | System.err.println("invalid jcterm.fg_bg: "+s); 105 | } 106 | 107 | if(conf_update) 108 | JCTermSwing.getCR().save(conf); 109 | 110 | setVisible(true); 111 | 112 | if(Toolkit.getDefaultToolkit() 113 | .getDesktopProperty("win.mdi.backgroundColor")!=null) 114 | desktop.setBackground((Color)Toolkit.getDefaultToolkit() 115 | .getDesktopProperty("win.mdi.backgroundColor")); 116 | 117 | Container content=getContentPane(); 118 | content.add(desktop, BorderLayout.CENTER); 119 | desktop.setVisible(true); 120 | 121 | JButton addButton = new JButton("New window"); 122 | addButton.addActionListener(new ActionListener() { 123 | public void actionPerformed(ActionEvent e) { 124 | openFrame(Frame.SHELL, configName); 125 | } 126 | }); 127 | content.add(addButton, BorderLayout.NORTH); 128 | addButton.setLocation(0, 0); 129 | addButton.setVisible(true); 130 | 131 | setFocusable(true); 132 | } 133 | 134 | public void start(){ 135 | requestFocus(); 136 | setFocusable(true); 137 | openFrame(Frame.SHELL, configName); 138 | } 139 | 140 | public void openFrame(int mode, String configNname){ 141 | final JCTermSwing term = new JCTermSwing(); 142 | JCTermSwingFrame jctermsf=new JCTermSwingFrame(); 143 | final MyFrame frame = new MyFrame(jctermsf); 144 | 145 | frame.setTitle("JCTerm"); 146 | frame.setIconifiable(true); 147 | 148 | frame.getContentPane().add("Center", term); 149 | 150 | jctermsf.setCloseOnExit(true); 151 | jctermsf.setTerm(term); 152 | jctermsf.setFrame(frame); 153 | 154 | frame.setJMenuBar(jctermsf.getJMenuBar()); 155 | 156 | frame.pack(); 157 | 158 | desktop.add(frame); 159 | 160 | ComponentAdapter l = new ComponentAdapter(){ 161 | public void componentResized(ComponentEvent e){ 162 | Component c = e.getComponent(); 163 | Container cp = ((JInternalFrame)c).getContentPane(); 164 | int cw=c.getWidth(); 165 | int ch=c.getHeight(); 166 | int cwm=c.getWidth()-cp.getWidth(); 167 | int chm=c.getHeight()-cp.getHeight(); 168 | cw-=cwm; 169 | ch-=chm; 170 | term.setSize(cw, ch); 171 | } 172 | }; 173 | frame.addComponentListener(l); 174 | addKeyListener(term); 175 | 176 | term.setVisible(true); 177 | frame.setVisible(true); 178 | 179 | frame.setResizable(true); 180 | frame.setMaximizable(true); 181 | 182 | jctermsf.applyConfig(configName); 183 | 184 | frame.setLocation((getWidth()-frame.getWidth())/2, 185 | (getHeight()-frame.getHeight())/2); 186 | 187 | jctermsf.openSession(); 188 | } 189 | 190 | class MyFrame extends JInternalFrame implements Frame { 191 | JCTermSwingFrame jctermsf; 192 | InternalFrameAdapter l = new InternalFrameAdapter(){ 193 | public void internalFrameClosing(InternalFrameEvent e){ 194 | jctermsf.dispose_connection(); 195 | } 196 | }; 197 | MyFrame(JCTermSwingFrame jctermsf){ 198 | this.jctermsf = jctermsf; 199 | setClosable(true); 200 | addInternalFrameListener(l); 201 | } 202 | public void openFrame(int mode, String configName){ 203 | JCTermApplet.this.openFrame(mode, configName); 204 | } 205 | } 206 | 207 | private String[] difference(String[] a, String[] b){ 208 | java.util.Vector v = new java.util.Vector(); 209 | for(int i=0; i 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Library General Public License 10 | * as published by the Free Software Foundation; either version 2 of 11 | * the License, or (at your option) any later version. 12 | 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Library General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Library General Public 19 | * License along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | */ 22 | 23 | package com.jcraft.jcterm; 24 | 25 | import com.jcraft.jsch.*; 26 | import com.jcraft.jsch.agentproxy.*; 27 | import com.jcraft.jsch.agentproxy.usocket.*; 28 | import com.jcraft.jsch.agentproxy.connector.*; 29 | import java.util.Vector; 30 | 31 | public class JCTermIdentityRepository extends RemoteIdentityRepository { 32 | private static Connector con; 33 | 34 | static { 35 | try { 36 | if(System.getenv("SSH_AUTH_SOCK")!=null){ 37 | USocketFactory usf = new JNAUSocketFactory(); 38 | con = new SSHAgentConnector(usf); 39 | } 40 | } 41 | catch(AgentProxyException e){ System.err.println(e); } 42 | 43 | try { 44 | if(System.getProperty("os.name").startsWith("Windows")) 45 | con = new PageantConnector(); 46 | } 47 | catch(AgentProxyException e){ System.err.println(e); } 48 | } 49 | 50 | public JCTermIdentityRepository() { 51 | super(con); 52 | } 53 | 54 | public int getStatus() { 55 | if(con == null) 56 | return NOTRUNNING; 57 | return super.getStatus(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jcterm/JCTermMIDP.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; -*- */ 2 | /* JCTermMIDP 3 | * Copyright (C) 2005,2007 ymnk, JCraft,Inc. 4 | * 5 | * Written by: ymnk 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Library General Public License 10 | * as published by the Free Software Foundation; either version 2 of 11 | * the License, or (at your option) any later version. 12 | 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Library General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Library General Public 19 | * License along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | */ 22 | 23 | package com.jcraft.jcterm; 24 | 25 | import com.jcraft.jsch.*; 26 | import java.io.*; 27 | 28 | import javax.microedition.midlet.*; 29 | import javax.microedition.io.*; 30 | import javax.microedition.lcdui.*; 31 | import javax.microedition.rms.*; 32 | import java.io.*; 33 | import java.util.Vector; 34 | 35 | public class JCTermMIDP extends MIDlet implements Runnable, CommandListener{ 36 | static String COPYRIGHT= 37 | "JCTerm 0.0.11\nCopyright (C) 2002,2007 ymnk, JCraft,Inc.\n"+ 38 | "Official Homepage: http://www.jcraft.com/jcterm/\n"+ 39 | "This software is licensed under GNU LGPL.\n"+ 40 | "This software is using JSch for J2ME(http://j2me.jsch.org/) and\n"+ 41 | "BouncyCastle Crypto API(http://www.bouncycastle.org/)."; 42 | 43 | private static Display display; 44 | private Form f; 45 | private StringItem si; 46 | private TextField tf; 47 | 48 | private Command exitCommand=new Command("Exit", Command.EXIT, 0); 49 | private Command connectCommand=new Command("Connect", Command.ITEM, 1); 50 | private Command clearKeyCommand=new Command("Clear private key", Command.ITEM, 2); 51 | private Command cancelCommand=new Command("Cancel", Command.SCREEN, 0); 52 | private Command okCommand=new Command("Ok", Command.SCREEN, 1); 53 | private Command inputCommand=new Command("Input", Command.SCREEN, 1); 54 | private TextBox resultBox=new TextBox("Result", "", 2048, 0); 55 | private TextBox tb=new TextBox("Input", "", 64, 0); 56 | private ChoiceGroup choice=new ChoiceGroup("", Choice.MULTIPLE); 57 | 58 | private Displayable nextScreen=null; 59 | 60 | private String host=null; 61 | private String user=null; 62 | private int port=22; 63 | 64 | private boolean isPaused; 65 | 66 | private final String UH=""; 67 | 68 | private OutputStream out; 69 | private InputStream in; 70 | 71 | //private Image background; 72 | //private Graphics cursor_graphics; 73 | //private int compression=0; 74 | 75 | public JCTermMIDP(){ 76 | display=Display.getDisplay(this); 77 | f=new Form("JCTerm"); 78 | si=new StringItem("Status", "No connection"); 79 | tf=new TextField("user@hostname", UH, 30, TextField.ANY); 80 | 81 | f.append(tf); 82 | f.append(choice); 83 | f.append(""); 84 | f.append(COPYRIGHT); 85 | 86 | choice.append("Install private key", null); 87 | 88 | f.addCommand(exitCommand); 89 | f.addCommand(connectCommand); 90 | f.addCommand(clearKeyCommand); 91 | f.setCommandListener(this); 92 | display.setCurrent(f); 93 | 94 | tb.addCommand(okCommand); 95 | tb.setCommandListener(this); 96 | 97 | resultBox.addCommand(okCommand); 98 | resultBox.setCommandListener(this); 99 | 100 | initGraphics(); 101 | 102 | } 103 | 104 | private Thread thread=null; 105 | public void start() { 106 | thread=new Thread(this); 107 | thread.start(); 108 | } 109 | 110 | public void run() { 111 | try{ 112 | if(host!=null && user!=null){ 113 | connect(); 114 | } 115 | if(session==null){ 116 | si.setText("No connection"); 117 | } 118 | } 119 | catch (Exception e) { 120 | //e.printStackTrace(); 121 | } 122 | } 123 | 124 | private void connect(){ 125 | si.setText("Connecting to "+user+"@"+host+"..."); 126 | nextScreen=display.getCurrent(); 127 | 128 | try{ 129 | Session session=null; 130 | try{ session=getSession(user, host); } 131 | catch(JSchException ee){ 132 | //System.out.println(ee); 133 | si.setText("No connection"); 134 | f.addCommand(connectCommand); 135 | f.addCommand(clearKeyCommand); 136 | display.setCurrent(f); 137 | return; 138 | } 139 | si.setText("Connected to "+user+"@"+host); 140 | 141 | f.addCommand(connectCommand); 142 | f.addCommand(clearKeyCommand); 143 | display.setCurrent(f); 144 | 145 | if(choice.isSelected(0)){ 146 | installPKey(session); 147 | } 148 | else{ 149 | canvas.setTitle("JCTerm: "+user+"@"+host); 150 | display.setCurrent(canvas); 151 | canvas.initGraphics(); 152 | 153 | channel=session.openChannel("shell"); 154 | out=channel.getOutputStream(); 155 | in=channel.getInputStream(); 156 | channel.connect(); 157 | 158 | ((ChannelShell)channel).setPtySize(canvas.getColumnCount(), 159 | canvas.getRowCount()-1, 160 | canvas.getWidth(), 161 | canvas.getHeight()); 162 | 163 | emulator=new EmulatorVT100(canvas, in); 164 | emulator.reset(); 165 | canvas.setOutputStream(out); 166 | emulator.start(); 167 | channel.disconnect(); 168 | f.addCommand(connectCommand); 169 | f.addCommand(clearKeyCommand); 170 | display.setCurrent(f); 171 | } 172 | } 173 | catch(Exception e){ 174 | //System.err.println(e); 175 | } 176 | } 177 | 178 | private void clearKey(){ 179 | try{ RecordStore.deleteRecordStore(".ssh"); } 180 | catch(RecordStoreException e){ } 181 | } 182 | private void installPKey(Session session) throws Exception { 183 | resultBox.setTitle("Install private key"); 184 | resultBox.delete(0, resultBox.size()); 185 | display.setCurrent(resultBox); 186 | 187 | String[] pkey={"id_dsa", "id_rsa"}; 188 | for(int j=0; j0){ 291 | try{port=Integer.parseInt(_host.substring(_host.indexOf(':')+1));} 292 | catch(Exception e){} 293 | _host=_host.substring(0, _host.indexOf(':')); 294 | } 295 | if(_host==null || _host.length()==0 || 296 | _user==null || _user.length()==0){ 297 | return; 298 | } 299 | host=_host; 300 | user=_user; 301 | thread=new Thread(this); 302 | thread.start(); 303 | f.removeCommand(connectCommand); 304 | f.removeCommand(clearKeyCommand); 305 | } 306 | 307 | if((c==Alert.DISMISS_COMMAND) || (c==exitCommand)){ 308 | stop(); 309 | notifyDestroyed(); 310 | destroyApp(true); 311 | } 312 | } 313 | 314 | private JSch jsch=null; 315 | private Session session=null; 316 | Channel channel=null; 317 | 318 | private MyCanvas canvas; 319 | 320 | private void initGraphics(){ 321 | canvas=new MyCanvas(); 322 | canvas.addCommand(exitCommand); 323 | canvas.addCommand(inputCommand); 324 | canvas.setCommandListener(this); 325 | 326 | // cursor_graphics=(img.getGraphics()); 327 | // cursor_graphics.setColor(getForeGround()); 328 | // cursor_graphics.setXORMode(getBackGround()); 329 | } 330 | 331 | public void kick(){ 332 | this.thread=new Thread(this); 333 | this.thread.start(); 334 | } 335 | 336 | MyUserInfo ui=null; 337 | private Emulator emulator=null; 338 | 339 | // public void setLineSpace(int foo){this.line_space=foo;} 340 | // public void setCompression(int compression){ 341 | // if(compression<0 || 9 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Library General Public License 10 | * as published by the Free Software Foundation; either version 2 of 11 | * the License, or (at your option) any later version. 12 | 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Library General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Library General Public 19 | * License along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | */ 22 | 23 | package com.jcraft.jcterm; 24 | 25 | import java.awt.*; 26 | import java.awt.event.*; 27 | import java.io.*; 28 | import java.awt.image.*; 29 | 30 | public class JCTermPanelG2D extends Panel implements KeyListener, Term{ 31 | 32 | static String COPYRIGHT="JCTerm 0.0.11\nCopyright (C) 2002,2007 ymnk, JCraft,Inc.\n" 33 | +"Official Homepage: http://www.jcraft.com/jcterm/\n" 34 | +"This software is licensed under GNU LGPL."; 35 | 36 | private OutputStream out; 37 | private InputStream in; 38 | Emulator emulator=null; 39 | 40 | Connection connection=null; 41 | 42 | private BufferedImage img; 43 | private Graphics2D cursor_graphics; 44 | private Graphics2D graphics; 45 | private java.awt.Color defaultbground=Color.black; 46 | private java.awt.Color defaultfground=Color.white; 47 | private java.awt.Color bground=Color.black; 48 | private java.awt.Color fground=Color.white; 49 | private java.awt.Component term_area=null; 50 | private java.awt.Font font; 51 | 52 | private boolean bold=false; 53 | private boolean underline=false; 54 | private boolean reverse=false; 55 | 56 | private int term_width=80; 57 | private int term_height=24; 58 | 59 | private int x=0; 60 | private int y=0; 61 | private int descent=0; 62 | 63 | private int char_width; 64 | private int char_height; 65 | 66 | private boolean antialiasing=true; 67 | // private int line_space=0; 68 | private int line_space=-2; 69 | private int compression=0; 70 | 71 | private Splash splash=null; 72 | 73 | private final Object[] colors= {Color.black, Color.red, Color.green, 74 | Color.yellow, Color.blue, Color.magenta, Color.cyan, Color.white}; 75 | 76 | public JCTermPanelG2D(){ 77 | enableEvents(AWTEvent.KEY_EVENT_MASK); 78 | 79 | setFocusable(true); 80 | setFocusTraversalKeysEnabled(false); 81 | } 82 | 83 | private void setFont(String fname){ 84 | font=java.awt.Font.decode(fname); 85 | Image img=createImage(1, 1); 86 | Graphics graphics=img.getGraphics(); 87 | graphics.setFont(font); 88 | { 89 | FontMetrics fo=graphics.getFontMetrics(); 90 | descent=fo.getDescent(); 91 | //System.out.println(fo.getDescent()); 92 | //System.out.println(fo.getAscent()); 93 | //System.out.println(fo.getLeading()); 94 | //System.out.println(fo.getHeight()); 95 | //System.out.println(fo.getMaxAscent()); 96 | //System.out.println(fo.getMaxDescent()); 97 | //System.out.println(fo.getMaxDecent()); 98 | //System.out.println(fo.getMaxAdvance()); 99 | char_width=(int)(fo.charWidth((char)'@')); 100 | char_height=(int)(fo.getHeight())+(line_space*2); 101 | // descent+=line_space; 102 | } 103 | img.flush(); 104 | graphics.dispose(); 105 | } 106 | 107 | void initGraphics(){ 108 | setFont("Monospaced-14"); 109 | 110 | img=new BufferedImage(getTermWidth(), getTermHeight(), 111 | BufferedImage.TYPE_INT_RGB); 112 | graphics=(Graphics2D)(img.getGraphics()); 113 | graphics.setFont(font); 114 | if(splash!=null) 115 | splash.draw(img, getTermWidth(), getTermHeight()); 116 | else 117 | clear(); 118 | cursor_graphics=(Graphics2D)(img.getGraphics()); 119 | cursor_graphics.setColor(getForeGround()); 120 | cursor_graphics.setXORMode(getBackGround()); 121 | 122 | term_area=this; 123 | 124 | Panel panel=this; 125 | panel.setSize(getTermWidth(), getTermHeight()); 126 | panel.setFocusable(true); 127 | } 128 | 129 | public void setSize(int w, int h){ 130 | 131 | super.setSize(w, h); 132 | 133 | if(img==null){ 134 | initGraphics(); 135 | } 136 | 137 | Image imgOrg=img; 138 | if(graphics!=null) 139 | graphics.dispose(); 140 | 141 | int column=w/getCharWidth(); 142 | int row=h/getCharHeight(); 143 | 144 | term_width=column; 145 | term_height=row; 146 | 147 | if(emulator!=null) 148 | emulator.reset(); 149 | 150 | img=new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); 151 | graphics=(Graphics2D)(img.getGraphics()); 152 | graphics.setFont(font); 153 | 154 | clear_area(0, 0, w, h); 155 | 156 | if(imgOrg!=null){ 157 | Shape clip=graphics.getClip(); 158 | graphics.setClip(0, 0, getTermWidth(), getTermHeight()); 159 | graphics.drawImage(imgOrg, 0, 0, term_area); 160 | graphics.setClip(clip); 161 | } 162 | 163 | if(cursor_graphics!=null) 164 | cursor_graphics.dispose(); 165 | 166 | cursor_graphics=(Graphics2D)(img.getGraphics()); 167 | cursor_graphics.setColor(getForeGround()); 168 | cursor_graphics.setXORMode(getBackGround()); 169 | 170 | setAntiAliasing(antialiasing); 171 | 172 | if(connection!=null){ 173 | connection.requestResize(this); 174 | } 175 | 176 | if(imgOrg!=null){ 177 | imgOrg.flush(); 178 | imgOrg=null; 179 | } 180 | 181 | } 182 | 183 | public void setFrame(java.awt.Component term_area){ 184 | this.term_area=term_area; 185 | } 186 | 187 | public void start(Connection connection){ 188 | this.connection=connection; 189 | in=connection.getInputStream(); 190 | out=connection.getOutputStream(); 191 | emulator=new EmulatorVT100(this, in); 192 | emulator.reset(); 193 | emulator.start(); 194 | 195 | if(splash!=null) 196 | splash.draw(img, getTermWidth(), getTermHeight()); 197 | else 198 | clear(); 199 | redraw(0, 0, getTermWidth(), getTermHeight()); 200 | 201 | requestFocus(); 202 | } 203 | 204 | public void update(Graphics g){ 205 | if(img==null){ 206 | initGraphics(); 207 | } 208 | g.drawImage(img, 0, 0, term_area); 209 | } 210 | 211 | public void paint(Graphics g){ 212 | if(img==null){ 213 | initGraphics(); 214 | } 215 | g.drawImage(img, 0, 0, term_area); 216 | } 217 | 218 | public void processKeyEvent(KeyEvent e){ 219 | //System.out.println(e); 220 | int id=e.getID(); 221 | if(id==KeyEvent.KEY_PRESSED){ 222 | /*keyPressed(e);*/ 223 | } 224 | else if(id==KeyEvent.KEY_RELEASED){ 225 | /*keyReleased(e);*/ 226 | } 227 | else if(id==KeyEvent.KEY_TYPED){ 228 | keyTyped(e); 229 | } 230 | e.consume(); // ?? 231 | } 232 | 233 | byte[] obuffer=new byte[3]; 234 | 235 | public boolean keyTypedCode(int keycode){ 236 | byte[] code=null; 237 | switch(keycode){ 238 | case KeyEvent.VK_CONTROL: 239 | case KeyEvent.VK_SHIFT: 240 | case KeyEvent.VK_ALT: 241 | case KeyEvent.VK_CAPS_LOCK: 242 | return true; 243 | case KeyEvent.VK_ENTER: 244 | code=emulator.getCodeENTER(); 245 | break; 246 | case KeyEvent.VK_UP: 247 | code=emulator.getCodeUP(); 248 | break; 249 | case KeyEvent.VK_DOWN: 250 | code=emulator.getCodeDOWN(); 251 | break; 252 | case KeyEvent.VK_RIGHT: 253 | code=emulator.getCodeRIGHT(); 254 | break; 255 | case KeyEvent.VK_LEFT: 256 | code=emulator.getCodeLEFT(); 257 | break; 258 | case KeyEvent.VK_F1: 259 | code=emulator.getCodeF1(); 260 | break; 261 | case KeyEvent.VK_F2: 262 | code=emulator.getCodeF2(); 263 | break; 264 | case KeyEvent.VK_F3: 265 | code=emulator.getCodeF3(); 266 | break; 267 | case KeyEvent.VK_F4: 268 | code=emulator.getCodeF4(); 269 | break; 270 | case KeyEvent.VK_F5: 271 | code=emulator.getCodeF5(); 272 | break; 273 | case KeyEvent.VK_F6: 274 | code=emulator.getCodeF6(); 275 | break; 276 | case KeyEvent.VK_F7: 277 | code=emulator.getCodeF7(); 278 | break; 279 | case KeyEvent.VK_F8: 280 | code=emulator.getCodeF8(); 281 | break; 282 | case KeyEvent.VK_F9: 283 | code=emulator.getCodeF9(); 284 | break; 285 | case KeyEvent.VK_F10: 286 | code=emulator.getCodeF10(); 287 | break; 288 | case KeyEvent.VK_TAB: 289 | code=emulator.getCodeTAB(); 290 | break; 291 | } 292 | if(code!=null){ 293 | try{ 294 | out.write(code, 0, code.length); 295 | out.flush(); 296 | } 297 | catch(Exception ee){ 298 | } 299 | return true; 300 | } 301 | return false; 302 | } 303 | 304 | public void keyTyped(KeyEvent e){ 305 | int keycode=e.getKeyCode(); 306 | //System.out.println(e); 307 | 308 | if(keyTypedCode(keycode)) 309 | return; 310 | 311 | char keychar=e.getKeyChar(); 312 | if((keychar&0xff00)==0){ 313 | obuffer[0]=(byte)(e.getKeyChar()); 314 | //System.out.println(Integer.toHexString(obuffer[0])); 315 | try{ 316 | out.write(obuffer, 0, 1); 317 | out.flush(); 318 | } 319 | catch(Exception ee){ 320 | } 321 | } 322 | 323 | // char keychar=e.getKeyChar(); 324 | if((keychar&0xff00)!=0){ 325 | char[] foo=new char[1]; 326 | foo[0]=keychar; 327 | try{ 328 | byte[] goo=new String(foo).getBytes("EUC-JP"); 329 | out.write(goo, 0, goo.length); 330 | out.flush(); 331 | } 332 | catch(Exception eee){ 333 | } 334 | } 335 | } 336 | 337 | public int getTermWidth(){ 338 | return char_width*term_width; 339 | } 340 | 341 | public int getTermHeight(){ 342 | return char_height*term_height; 343 | } 344 | 345 | public int getCharWidth(){ 346 | return char_width; 347 | } 348 | 349 | public int getCharHeight(){ 350 | return char_height; 351 | } 352 | 353 | public int getColumnCount(){ 354 | return term_width; 355 | } 356 | 357 | public int getRowCount(){ 358 | return term_height; 359 | } 360 | 361 | public void clear(){ 362 | graphics.setColor(getBackGround()); 363 | graphics.fillRect(0, 0, char_width*term_width, char_height*term_height); 364 | graphics.setColor(getForeGround()); 365 | } 366 | 367 | public void setCursor(int x, int y){ 368 | this.x=x; 369 | this.y=y; 370 | } 371 | 372 | public void draw_cursor(){ 373 | cursor_graphics.fillRect(x, y-char_height, char_width, char_height); 374 | repaint(x, y-char_height, char_width, char_height); 375 | } 376 | 377 | public void redraw(int x, int y, int width, int height){ 378 | repaint(x, y, width, height); 379 | } 380 | 381 | public void clear_area(int x1, int y1, int x2, int y2){ 382 | graphics.setColor(getBackGround()); 383 | graphics.fillRect(x1, y1, x2-x1, y2-y1); 384 | graphics.setColor(getForeGround()); 385 | } 386 | 387 | public void scroll_area(int x, int y, int w, int h, int dx, int dy){ 388 | graphics.copyArea(x, y, w, h, dx, dy); 389 | } 390 | 391 | public void drawBytes(byte[] buf, int s, int len, int x, int y){ 392 | //System.out.println("drawBytes: "+new String(buf, s, len)+" "+graphics); 393 | graphics.drawBytes(buf, s, len, x, y-(descent+line_space)); 394 | if(bold) 395 | graphics.drawBytes(buf, s, len, x+1, y-(descent+line_space)); 396 | if(underline){ 397 | graphics.drawLine(x, y-1, x+len*char_width, y-1); 398 | } 399 | } 400 | 401 | public void drawString(String str, int x, int y){ 402 | //System.out.println("drawString: "+str); 403 | graphics.drawString(str, x, y-(descent+line_space)); 404 | if(bold) 405 | graphics.drawString(str, x+1, y-(descent+line_space)); 406 | if(underline){ 407 | graphics.drawLine(x, y-1, x+str.getBytes().length*char_width, y-1); 408 | } 409 | } 410 | 411 | public void beep(){ 412 | Toolkit.getDefaultToolkit().beep(); 413 | } 414 | 415 | public void keyPressed(KeyEvent e){ 416 | } 417 | 418 | public void keyReleased(KeyEvent e){ 419 | } 420 | 421 | public void setSplash(Splash foo){ 422 | this.splash=foo; 423 | } 424 | 425 | public void setLineSpace(int foo){ 426 | this.line_space=foo; 427 | } 428 | 429 | public void setAntiAliasing(boolean foo){ 430 | antialiasing=foo; 431 | if(graphics==null) 432 | return; 433 | java.lang.Object mode=foo ? RenderingHints.VALUE_TEXT_ANTIALIAS_ON 434 | : RenderingHints.VALUE_TEXT_ANTIALIAS_OFF; 435 | RenderingHints hints=new RenderingHints( 436 | RenderingHints.KEY_TEXT_ANTIALIASING, mode); 437 | graphics.setRenderingHints(hints); 438 | } 439 | 440 | public void setCompression(int compression){ 441 | if(compression<0||9 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Library General Public License 10 | * as published by the Free Software Foundation; either version 2 of 11 | * the License, or (at your option) any later version. 12 | 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Library General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Library General Public 19 | * License along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | */ 22 | 23 | package com.jcraft.jcterm; 24 | 25 | import java.io.InputStream; 26 | import java.io.OutputStream; 27 | 28 | import org.eclipse.swt.SWT; 29 | import org.eclipse.swt.events.ControlEvent; 30 | import org.eclipse.swt.events.ControlListener; 31 | import org.eclipse.swt.events.DisposeEvent; 32 | import org.eclipse.swt.events.DisposeListener; 33 | import org.eclipse.swt.events.KeyEvent; 34 | import org.eclipse.swt.events.KeyListener; 35 | import org.eclipse.swt.events.PaintEvent; 36 | import org.eclipse.swt.events.PaintListener; 37 | import org.eclipse.swt.graphics.Color; 38 | import org.eclipse.swt.graphics.Font; 39 | import org.eclipse.swt.graphics.FontMetrics; 40 | import org.eclipse.swt.graphics.GC; 41 | import org.eclipse.swt.graphics.Image; 42 | import org.eclipse.swt.graphics.Rectangle; 43 | import org.eclipse.swt.widgets.Canvas; 44 | import org.eclipse.swt.widgets.Composite; 45 | import org.eclipse.swt.widgets.Display; 46 | 47 | public class JCTermSWT extends Canvas implements PaintListener, 48 | ControlListener, DisposeListener, KeyListener, Term{ 49 | 50 | private static boolean xor_not_supported=SWT.getPlatform().equals("carbon"); 51 | 52 | private OutputStream out; 53 | private InputStream in; 54 | private Emulator emulator=null; 55 | 56 | private Connection connection=null; 57 | 58 | private Image img; 59 | private GC graphics; 60 | 61 | private Image backgroundImg; 62 | 63 | private Color black=new Color(null, 0, 0, 0); 64 | private Color red=new Color(null, 255, 0, 0); 65 | private Color green=new Color(null, 0, 255, 0); 66 | private Color blue=new Color(null, 0, 0, 255); 67 | private Color yellow=new Color(null, 255, 255, 0); 68 | private Color magenta=new Color(null, 255, 0, 255); 69 | private Color cyan=new Color(null, 0, 255, 255); 70 | private Color white=new Color(null, 255, 255, 255); 71 | private final Object[] colors= {black, red, green, yellow, blue, magenta, 72 | cyan, white}; 73 | 74 | private Color defaultbground=black; 75 | private Color defaultfground=white; 76 | private Color bground=black; 77 | private Color fground=white; 78 | private Font font; 79 | 80 | private boolean bold=false; 81 | private boolean underline=false; 82 | private boolean reverse=false; 83 | 84 | private int column=80; 85 | private int row=24; 86 | 87 | private int x=0; 88 | private int y=0; 89 | private int descent=0; 90 | 91 | private int char_width; 92 | private int char_height; 93 | private int term_width; 94 | private int term_height; 95 | 96 | private int leading; 97 | 98 | private int font_size=16; 99 | 100 | //private boolean antialiasing=true; 101 | //private int line_space=0; 102 | private int line_space=-2; 103 | private int compression=0; 104 | 105 | private Splash splash=null; 106 | 107 | public JCTermSWT(Composite parent){ 108 | super(parent, SWT.NO_BACKGROUND); 109 | addPaintListener(this); 110 | addControlListener(this); 111 | addDisposeListener(this); 112 | addKeyListener(this); 113 | } 114 | 115 | public void paintControl(PaintEvent e){ 116 | 117 | Display display=Display.getDefault(); 118 | if(display==null){ 119 | return; 120 | } 121 | 122 | if(img==null){ 123 | Rectangle bounds=getBounds(); 124 | setSize(display, bounds.width, bounds.height); 125 | } 126 | 127 | synchronized(this){ 128 | e.gc.drawImage(img, 0, 0); 129 | } 130 | } 131 | 132 | public void controlMoved(ControlEvent e){ 133 | } 134 | 135 | public void controlResized(ControlEvent e){ 136 | //System.out.println("contorlResized"); 137 | 138 | Display display=Display.getDefault(); 139 | if(display==null){ 140 | return; 141 | } 142 | 143 | Rectangle bounds=getBounds(); 144 | 145 | if(bounds.width==0||bounds.height==0) 146 | return; 147 | 148 | setSize(display, bounds.width, bounds.height); 149 | } 150 | 151 | public void setFont(int size){ 152 | Display display=Display.getDefault(); 153 | if(display==null){ 154 | return; 155 | } 156 | 157 | if(font!=null){ 158 | font.dispose(); 159 | } 160 | 161 | font=new Font(display, "Terminal", size, SWT.NORMAL); 162 | //font = new Font(display,"Fixed Width",size,SWT.NORMAL); 163 | graphics.setFont(font); 164 | FontMetrics fm=graphics.getFontMetrics(); 165 | char_width=fm.getAverageCharWidth(); 166 | char_height=fm.getHeight(); 167 | leading=fm.getLeading(); 168 | term_width=char_width*column; 169 | term_height=char_height*row; 170 | draw_cursor(); 171 | font_size=size; 172 | 173 | } 174 | 175 | private void setSize(Display display, int w, int h){ 176 | Image oimg=img; 177 | synchronized(this){ 178 | if(graphics!=null){ 179 | graphics.dispose(); 180 | } 181 | 182 | ; 183 | img=new Image(display, w, h); 184 | graphics=new GC(img); 185 | graphics.setBackground(getBackGround()); 186 | graphics.setForeground(getForeGround()); 187 | graphics.fillRectangle(0, 0, w, h); 188 | if(backgroundImg!=null){ 189 | graphics.drawImage(backgroundImg, 0, 0); 190 | } 191 | /* 192 | if(xor_not_supported){ 193 | if(graphics.getTextAntialias()!=SWT.OFF) 194 | graphics.setTextAntialias(SWT.OFF); 195 | } 196 | */ 197 | if(font==null){ 198 | setFont(font_size); 199 | } 200 | else{ 201 | graphics.setFont(font); 202 | } 203 | } 204 | column=w/getCharWidth(); 205 | row=h/getCharHeight(); 206 | 207 | term_width=char_width*column; 208 | term_height=char_height*row; 209 | 210 | if(emulator!=null) 211 | emulator.reset(); 212 | 213 | clear_area(0, 0, w, h); 214 | 215 | if(oimg!=null){ 216 | synchronized(this){ 217 | Rectangle clip=graphics.getClipping(); 218 | graphics.setClipping(0, 0, getTermWidth(), getTermHeight()); 219 | graphics.drawImage(oimg, 0, 0); 220 | graphics.setClipping(clip); 221 | } 222 | } 223 | 224 | if(connection!=null){ 225 | connection.requestResize(this); 226 | } 227 | 228 | if(oimg!=null){ 229 | oimg.dispose(); 230 | } 231 | 232 | } 233 | 234 | public void widgetDisposed(DisposeEvent e){ 235 | for(int i=0; i 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Library General Public License 10 | * as published by the Free Software Foundation; either version 2 of 11 | * the License, or (at your option) any later version. 12 | 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Library General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Library General Public 19 | * License along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | */ 22 | 23 | package com.jcraft.jcterm; 24 | 25 | import java.awt.*; 26 | import java.awt.event.*; 27 | import javax.swing.*; 28 | import java.io.*; 29 | import java.awt.image.*; 30 | 31 | public class JCTermSwing extends JPanel implements KeyListener, /*Runnable,*/ 32 | Term{ 33 | OutputStream out; 34 | InputStream in; 35 | Emulator emulator=null; 36 | 37 | Connection connection=null; 38 | 39 | private BufferedImage img; 40 | private BufferedImage background; 41 | private Graphics2D cursor_graphics; 42 | private Graphics2D graphics; 43 | private java.awt.Color defaultbground=Color.black; 44 | private java.awt.Color defaultfground=Color.white; 45 | private java.awt.Color bground=Color.black; 46 | private java.awt.Color fground=Color.white; 47 | private java.awt.Component term_area=null; 48 | private java.awt.Font font; 49 | 50 | private boolean bold=false; 51 | private boolean underline=false; 52 | private boolean reverse=false; 53 | 54 | private int term_width=80; 55 | private int term_height=24; 56 | 57 | private int descent=0; 58 | 59 | private int x=0; 60 | private int y=0; 61 | 62 | private int char_width; 63 | private int char_height; 64 | 65 | //private int line_space=0; 66 | private int line_space=-2; 67 | private int compression=0; 68 | 69 | private boolean antialiasing=true; 70 | 71 | private Splash splash=null; 72 | 73 | private final Object[] colors= {Color.black, Color.red, Color.green, 74 | Color.yellow, Color.blue, Color.magenta, Color.cyan, Color.white}; 75 | 76 | public JCTermSwing(){ 77 | 78 | enableEvents(AWTEvent.KEY_EVENT_MASK); 79 | addKeyListener(this); 80 | 81 | setFont("Monospaced-14"); 82 | 83 | setSize(getTermWidth(), getTermHeight()); 84 | 85 | if(splash!=null) 86 | splash.draw(img, getTermWidth(), getTermHeight()); 87 | else 88 | clear(); 89 | 90 | term_area=this; 91 | 92 | setPreferredSize(new Dimension(getTermWidth(), getTermHeight())); 93 | 94 | setSize(getTermWidth(), getTermHeight()); 95 | setFocusable(true); 96 | enableInputMethods(true); 97 | 98 | setFocusTraversalKeysEnabled(false); 99 | // setOpaque(true); 100 | } 101 | 102 | void setFont(String fname){ 103 | font=java.awt.Font.decode(fname); 104 | BufferedImage img=new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB); 105 | Graphics2D graphics=(Graphics2D)(img.getGraphics()); 106 | graphics.setFont(font); 107 | { 108 | FontMetrics fo=graphics.getFontMetrics(); 109 | descent=fo.getDescent(); 110 | /* 111 | System.out.println(fo.getDescent()); 112 | System.out.println(fo.getAscent()); 113 | System.out.println(fo.getLeading()); 114 | System.out.println(fo.getHeight()); 115 | System.out.println(fo.getMaxAscent()); 116 | System.out.println(fo.getMaxDescent()); 117 | System.out.println(fo.getMaxDecent()); 118 | System.out.println(fo.getMaxAdvance()); 119 | */ 120 | char_width=(int)(fo.charWidth((char)'@')); 121 | char_height=(int)(fo.getHeight())+(line_space*2); 122 | descent+=line_space; 123 | } 124 | 125 | img.flush(); 126 | graphics.dispose(); 127 | 128 | background=new BufferedImage(char_width, char_height, 129 | BufferedImage.TYPE_INT_RGB); 130 | { 131 | Graphics2D foog=(Graphics2D)(background.getGraphics()); 132 | foog.setColor(getBackGround()); 133 | foog.fillRect(0, 0, char_width, char_height); 134 | foog.dispose(); 135 | } 136 | } 137 | 138 | public void setSize(int w, int h){ 139 | 140 | super.setSize(w, h); 141 | BufferedImage imgOrg=img; 142 | if(graphics!=null) 143 | graphics.dispose(); 144 | 145 | int column=w/getCharWidth(); 146 | int row=h/getCharHeight(); 147 | term_width=column; 148 | term_height=row; 149 | 150 | if(emulator!=null) 151 | emulator.reset(); 152 | 153 | img=new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); 154 | graphics=(Graphics2D)(img.getGraphics()); 155 | graphics.setFont(font); 156 | 157 | clear_area(0, 0, w, h); 158 | redraw(0, 0, w, h); 159 | 160 | if(imgOrg!=null){ 161 | Shape clip=graphics.getClip(); 162 | graphics.setClip(0, 0, getTermWidth(), getTermHeight()); 163 | graphics.drawImage(imgOrg, 0, 0, term_area); 164 | graphics.setClip(clip); 165 | } 166 | 167 | resetCursorGraphics(); 168 | 169 | setAntiAliasing(antialiasing); 170 | 171 | if(connection!=null){ 172 | connection.requestResize(this); 173 | } 174 | 175 | if(imgOrg!=null){ 176 | imgOrg.flush(); 177 | imgOrg=null; 178 | } 179 | } 180 | 181 | public void start(Connection connection){ 182 | this.connection=connection; 183 | in=connection.getInputStream(); 184 | out=connection.getOutputStream(); 185 | emulator=new EmulatorVT100(this, in); 186 | emulator.reset(); 187 | emulator.start(); 188 | 189 | if(splash!=null) 190 | splash.draw(img, getTermWidth(), getTermHeight()); 191 | else 192 | clear(); 193 | redraw(0, 0, getTermWidth(), getTermHeight()); 194 | } 195 | 196 | public void paintComponent(Graphics g){ 197 | super.paintComponent(g); 198 | if(img!=null){ 199 | g.drawImage(img, 0, 0, term_area); 200 | } 201 | } 202 | 203 | public void paint(Graphics g){ 204 | super.paint(g); 205 | } 206 | 207 | public void processKeyEvent(KeyEvent e){ 208 | //System.out.println(e); 209 | int id=e.getID(); 210 | if(id==KeyEvent.KEY_PRESSED){ 211 | keyPressed(e); 212 | } 213 | else if(id==KeyEvent.KEY_RELEASED){ 214 | /*keyReleased(e);*/ 215 | } 216 | else if(id==KeyEvent.KEY_TYPED){ 217 | keyTyped(e);/*keyTyped(e);*/ 218 | } 219 | e.consume(); // ?? 220 | } 221 | 222 | byte[] obuffer=new byte[3]; 223 | 224 | public void keyPressed(KeyEvent e){ 225 | int keycode=e.getKeyCode(); 226 | byte[] code=null; 227 | switch(keycode){ 228 | case KeyEvent.VK_CONTROL: 229 | case KeyEvent.VK_SHIFT: 230 | case KeyEvent.VK_ALT: 231 | case KeyEvent.VK_CAPS_LOCK: 232 | return; 233 | case KeyEvent.VK_ENTER: 234 | code=emulator.getCodeENTER(); 235 | break; 236 | case KeyEvent.VK_UP: 237 | code=emulator.getCodeUP(); 238 | break; 239 | case KeyEvent.VK_DOWN: 240 | code=emulator.getCodeDOWN(); 241 | break; 242 | case KeyEvent.VK_RIGHT: 243 | code=emulator.getCodeRIGHT(); 244 | break; 245 | case KeyEvent.VK_LEFT: 246 | code=emulator.getCodeLEFT(); 247 | break; 248 | case KeyEvent.VK_F1: 249 | code=emulator.getCodeF1(); 250 | break; 251 | case KeyEvent.VK_F2: 252 | code=emulator.getCodeF2(); 253 | break; 254 | case KeyEvent.VK_F3: 255 | code=emulator.getCodeF3(); 256 | break; 257 | case KeyEvent.VK_F4: 258 | code=emulator.getCodeF4(); 259 | break; 260 | case KeyEvent.VK_F5: 261 | code=emulator.getCodeF5(); 262 | break; 263 | case KeyEvent.VK_F6: 264 | code=emulator.getCodeF6(); 265 | break; 266 | case KeyEvent.VK_F7: 267 | code=emulator.getCodeF7(); 268 | break; 269 | case KeyEvent.VK_F8: 270 | code=emulator.getCodeF8(); 271 | break; 272 | case KeyEvent.VK_F9: 273 | code=emulator.getCodeF9(); 274 | break; 275 | case KeyEvent.VK_F10: 276 | code=emulator.getCodeF10(); 277 | break; 278 | case KeyEvent.VK_TAB: 279 | code=emulator.getCodeTAB(); 280 | break; 281 | } 282 | if(code!=null){ 283 | try{ 284 | out.write(code, 0, code.length); 285 | out.flush(); 286 | } 287 | catch(Exception ee){ 288 | } 289 | return; 290 | } 291 | 292 | char keychar=e.getKeyChar(); 293 | if((keychar&0xff00)==0){ 294 | obuffer[0]=(byte)(e.getKeyChar()); 295 | try{ 296 | out.write(obuffer, 0, 1); 297 | out.flush(); 298 | } 299 | catch(Exception ee){ 300 | } 301 | } 302 | } 303 | 304 | public void keyTyped(KeyEvent e){ 305 | char keychar=e.getKeyChar(); 306 | if((keychar&0xff00)!=0){ 307 | char[] foo=new char[1]; 308 | foo[0]=keychar; 309 | try{ 310 | byte[] goo=new String(foo).getBytes("EUC-JP"); 311 | out.write(goo, 0, goo.length); 312 | out.flush(); 313 | } 314 | catch(Exception eee){ 315 | } 316 | } 317 | } 318 | 319 | public int getTermWidth(){ 320 | return char_width*term_width; 321 | } 322 | 323 | public int getTermHeight(){ 324 | return char_height*term_height; 325 | } 326 | 327 | public int getCharWidth(){ 328 | return char_width; 329 | } 330 | 331 | public int getCharHeight(){ 332 | return char_height; 333 | } 334 | 335 | public int getColumnCount(){ 336 | return term_width; 337 | } 338 | 339 | public int getRowCount(){ 340 | return term_height; 341 | } 342 | 343 | public void clear(){ 344 | graphics.setColor(getBackGround()); 345 | graphics.fillRect(0, 0, char_width*term_width, char_height*term_height); 346 | graphics.setColor(getForeGround()); 347 | } 348 | 349 | public void setCursor(int x, int y){ 350 | //System.out.println("setCursor: "+x+","+y); 351 | this.x=x; 352 | this.y=y; 353 | } 354 | 355 | public void draw_cursor(){ 356 | cursor_graphics.fillRect(x, y-char_height, char_width, char_height); 357 | repaint(x, y-char_height, char_width, char_height); 358 | } 359 | 360 | public void redraw(int x, int y, int width, int height){ 361 | repaint(x, y, width, height); 362 | } 363 | 364 | public void clear_area(int x1, int y1, int x2, int y2){ 365 | //System.out.println("clear_area: "+x1+" "+y1+" "+x2+" "+y2); 366 | graphics.setColor(getBackGround()); 367 | graphics.fillRect(x1, y1, x2-x1, y2-y1); 368 | graphics.setColor(getForeGround()); 369 | } 370 | 371 | public void scroll_area(int x, int y, int w, int h, int dx, int dy){ 372 | //System.out.println("scroll_area: "+x+" "+y+" "+w+" "+h+" "+dx+" "+dy); 373 | graphics.copyArea(x, y, w, h, dx, dy); 374 | repaint(x+dx, y+dy, w, h); 375 | } 376 | 377 | public void drawBytes(byte[] buf, int s, int len, int x, int y){ 378 | // clear_area(x, y, x+len*char_width, y+char_height); 379 | // graphics.setColor(getForeGround()); 380 | 381 | //System.out.println("drawString: "+x+","+y+" "+len+" "+new String(buf, s, len)); 382 | 383 | graphics.drawBytes(buf, s, len, x, y-descent); 384 | if(bold) 385 | graphics.drawBytes(buf, s, len, x+1, y-descent); 386 | 387 | if(underline){ 388 | graphics.drawLine(x, y-1, x+len*char_width, y-1); 389 | } 390 | 391 | } 392 | 393 | public void drawString(String str, int x, int y){ 394 | // clear_area(x, y, x+str.length()*char_width, y+char_height); 395 | // graphics.setColor(getForeGround()); 396 | graphics.drawString(str, x, y-descent); 397 | if(bold) 398 | graphics.drawString(str, x+1, y-descent); 399 | 400 | if(underline){ 401 | graphics.drawLine(x, y-1, x+str.length()*char_width, y-1); 402 | } 403 | 404 | } 405 | 406 | public void beep(){ 407 | Toolkit.getDefaultToolkit().beep(); 408 | } 409 | 410 | /** Ignores key released events. */ 411 | public void keyReleased(KeyEvent event){ 412 | } 413 | 414 | // public void keyPressed(KeyEvent event){} 415 | 416 | public void setSplash(Splash foo){ 417 | this.splash=foo; 418 | } 419 | 420 | public void setLineSpace(int foo){ 421 | this.line_space=foo; 422 | } 423 | 424 | public boolean getAntiAliasing(){ 425 | return antialiasing; 426 | } 427 | 428 | public void setAntiAliasing(boolean foo){ 429 | if(graphics==null) 430 | return; 431 | antialiasing=foo; 432 | java.lang.Object mode=foo ? RenderingHints.VALUE_TEXT_ANTIALIAS_ON 433 | : RenderingHints.VALUE_TEXT_ANTIALIAS_OFF; 434 | RenderingHints hints=new RenderingHints( 435 | RenderingHints.KEY_TEXT_ANTIALIASING, mode); 436 | graphics.setRenderingHints(hints); 437 | } 438 | 439 | public void setCompression(int compression){ 440 | if(compression<0||9 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Library General Public License 10 | * as published by the Free Software Foundation; either version 2 of 11 | * the License, or (at your option) any later version. 12 | 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Library General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Library General Public 19 | * License along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | */ 22 | 23 | package com.jcraft.jcterm; 24 | 25 | import com.jcraft.jsch.*; 26 | 27 | public class JSchSession{ 28 | private static JSch jsch=null; 29 | private static SessionFactory sessionFactory=null; 30 | 31 | private static java.util.Hashtable pool=new java.util.Hashtable(); 32 | 33 | private String key=null; 34 | private Session session=null; 35 | 36 | public static JSchSession getSession(String username, String password, 37 | String hostname, int port, UserInfo userinfo, Proxy proxy) 38 | throws JSchException{ 39 | String key=getPoolKey(username, hostname, port); 40 | try{ 41 | JSchSession jschSession=(JSchSession)pool.get(key); 42 | if(jschSession!=null&&!jschSession.getSession().isConnected()){ 43 | pool.remove(key); 44 | jschSession=null; 45 | } 46 | if(jschSession==null){ 47 | Session session=null; 48 | try{ 49 | session=createSession(username, password, hostname, port, userinfo, 50 | proxy); 51 | } 52 | catch(JSchException e){ 53 | if(isAuthenticationFailure(e)){ 54 | session=createSession(username, password, hostname, port, userinfo, 55 | proxy); 56 | } 57 | else{ 58 | throw e; 59 | } 60 | } 61 | 62 | if(session==null) 63 | throw new JSchException("The JSch service is not available"); 64 | 65 | JSchSession schSession=new JSchSession(session, key); 66 | pool.put(key, schSession); 67 | 68 | return schSession; 69 | } 70 | return jschSession; 71 | } 72 | catch(JSchException e){ 73 | pool.remove(key); 74 | throw e; 75 | } 76 | } 77 | 78 | private static synchronized JSch getJSch(){ 79 | if(jsch==null){ 80 | jsch=new JSch(); 81 | } 82 | return jsch; 83 | } 84 | 85 | private static Session createSession(String username, String password, 86 | String hostname, int port, UserInfo userinfo, Proxy proxy) 87 | throws JSchException{ 88 | Session session=null; 89 | if(sessionFactory==null){ 90 | session=getJSch().getSession(username, hostname, port); 91 | } 92 | else{ 93 | session=sessionFactory.getSession(username, hostname, port); 94 | } 95 | session.setTimeout(60000); 96 | if(password!=null) 97 | session.setPassword(password); 98 | session.setUserInfo(userinfo); 99 | if(proxy!=null) 100 | session.setProxy(proxy); 101 | session.connect(60000); 102 | session.setServerAliveInterval(60000); 103 | return session; 104 | } 105 | 106 | private static String getPoolKey(String username, String hostname, int port){ 107 | return username+"@"+hostname+":"+port; 108 | } 109 | 110 | private JSchSession(Session session, String key){ 111 | this.session=session; 112 | this.key=key; 113 | } 114 | 115 | public Session getSession(){ 116 | return session; 117 | } 118 | 119 | public void dispose(){ 120 | if(session.isConnected()){ 121 | session.disconnect(); 122 | } 123 | pool.remove(key); 124 | } 125 | 126 | public static boolean isAuthenticationFailure(JSchException ee){ 127 | return ee.getMessage().equals("Auth fail"); 128 | } 129 | 130 | public static interface SessionFactory{ 131 | Session getSession(String username, String hostname, int port) 132 | throws JSchException; 133 | } 134 | 135 | public static void setSessionFactory(SessionFactory sf){ 136 | sessionFactory=sf; 137 | } 138 | 139 | static void useSSHAgent(boolean use){ 140 | IdentityRepository ir = null; 141 | if(use){ 142 | try{ 143 | Class c = Class.forName("com.jcraft.jcterm.JCTermIdentityRepository"); 144 | ir = (IdentityRepository)(c.newInstance()); 145 | } 146 | catch(java.lang.NoClassDefFoundError e){ 147 | System.err.println(e); 148 | } 149 | catch(Exception e){ 150 | System.err.println(e); 151 | } 152 | if(ir==null){ 153 | System.err.println("JCTermIdentityRepository is not available."); 154 | } 155 | } 156 | if(ir!=null) 157 | getJSch().setIdentityRepository(ir); 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jcterm/Sftp.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; -*- */ 2 | /* JCTerm 3 | * Copyright (C) 2002,2007 ymnk, JCraft,Inc. 4 | * 5 | * Written by: ymnk 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Library General Public License 10 | * as published by the Free Software Foundation; either version 2 of 11 | * the License, or (at your option) any later version. 12 | 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Library General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Library General Public 19 | * License along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | */ 22 | 23 | package com.jcraft.jcterm; 24 | 25 | import com.jcraft.jsch.*; 26 | import java.io.*; 27 | 28 | public class Sftp implements Runnable{ 29 | InputStream in; 30 | OutputStream out; 31 | ChannelSftp c; 32 | 33 | private byte[] lf= {0x0a, 0x0d}; 34 | private byte[] del= {0x08, 0x20, 0x08}; 35 | 36 | public Sftp(ChannelSftp c, InputStream in, OutputStream out){ 37 | this.c=c; 38 | this.in=in; 39 | this.out=out; 40 | } 41 | 42 | public void run(){ 43 | try{ 44 | java.util.Vector cmds=new java.util.Vector(); 45 | byte[] buf=new byte[1024]; 46 | int i; 47 | String str; 48 | String lhome=c.lpwd(); 49 | 50 | StringBuffer sb=new StringBuffer(); 51 | while(true){ 52 | //out.print("sftp> "); 53 | out.write("sftp> ".getBytes()); 54 | cmds.removeAllElements(); 55 | 56 | sb.setLength(0); 57 | 58 | loop: while(true){ 59 | i=in.read(buf, 0, 1024); 60 | if(i<=0) 61 | break; 62 | if(i!=1) 63 | continue; 64 | //System.out.println(Integer.toHexString(i)+" "+Integer.toHexString(buf[0]&0xff)); 65 | if(buf[0]==0x08){ 66 | if(sb.length()>0){ 67 | sb.setLength(sb.length()-1); 68 | out.write(del, 0, del.length); 69 | out.flush(); 70 | } 71 | continue; 72 | } 73 | 74 | if(buf[0]==0x0d){ 75 | out.write(lf, 0, lf.length); 76 | } 77 | else if(buf[0]==0x0a){ 78 | out.write(lf, 0, lf.length); 79 | } 80 | else if(buf[0]<0x20||(buf[0]&0x80)!=0){ 81 | continue; 82 | } 83 | else{ 84 | out.write(buf, 0, i); 85 | } 86 | out.flush(); 87 | 88 | for(int j=0; j0&&buf[i-1]==0x0d) 109 | i--; 110 | if(i>0&&buf[i-1]==0x0a) 111 | i--; 112 | //str=new String(buf, 0, i); 113 | //System.out.println("|"+str+"|"); 114 | int s=0; 115 | for(int ii=0; ii0){ 118 | cmds.addElement(new String(buf, s, ii-s)); 119 | } 120 | while(ii'7'){ 215 | foo=-1; 216 | break; 217 | } 218 | foo<<=3; 219 | foo|=(k-'0'); 220 | } 221 | if(foo==-1) 222 | continue; 223 | } 224 | else{ 225 | try{ 226 | foo=Integer.parseInt((String)cmds.elementAt(1)); 227 | } 228 | catch(Exception e){ 229 | continue; 230 | } 231 | } 232 | try{ 233 | if(cmd.equals("chgrp")){ 234 | c.chgrp(foo, path); 235 | } 236 | else if(cmd.equals("chown")){ 237 | c.chown(foo, path); 238 | } 239 | else if(cmd.equals("chmod")){ 240 | c.chmod(foo, path); 241 | } 242 | } 243 | catch(SftpException e){ 244 | //System.out.println(e.getMessage()); 245 | out.write(e.getMessage().getBytes()); 246 | out.write(lf); 247 | out.flush(); 248 | } 249 | continue; 250 | } 251 | if(cmd.equals("pwd")||cmd.equals("lpwd")){ 252 | str=(cmd.equals("pwd") ? "Remote" : "Local"); 253 | str+=" working directory: "; 254 | if(cmd.equals("pwd")) 255 | str+=c.pwd(); 256 | else 257 | str+=c.lpwd(); 258 | //out.print(str+"\n"); 259 | out.write(str.getBytes()); 260 | out.write(lf); 261 | out.flush(); 262 | continue; 263 | } 264 | if(cmd.equals("ls")||cmd.equals("dir")){ 265 | String path="."; 266 | if(cmds.size()==2) 267 | path=(String)cmds.elementAt(1); 268 | try{ 269 | java.util.Vector vv=c.ls(path); 270 | if(vv!=null){ 271 | for(int ii=0; ii 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Library General Public License 10 | * as published by the Free Software Foundation; either version 2 of 11 | * the License, or (at your option) any later version. 12 | 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Library General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Library General Public 19 | * License along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | */ 22 | 23 | package com.jcraft.jcterm; 24 | 25 | public interface Splash{ 26 | void draw(Object image, int width, int height); 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/jcraft/jcterm/Term.java: -------------------------------------------------------------------------------- 1 | /* -*-mode:java; c-basic-offset:2; -*- */ 2 | /* JCTerm 3 | * Copyright (C) 2002,2007 ymnk, JCraft,Inc. 4 | * 5 | * Written by: ymnk 6 | * 7 | * 8 | * This program is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Library General Public License 10 | * as published by the Free Software Foundation; either version 2 of 11 | * the License, or (at your option) any later version. 12 | 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Library General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Library General Public 19 | * License along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | */ 22 | 23 | package com.jcraft.jcterm; 24 | 25 | public interface Term{ 26 | 27 | void start(Connection connection); 28 | 29 | int getRowCount(); 30 | 31 | int getColumnCount(); 32 | 33 | int getCharWidth(); 34 | 35 | int getCharHeight(); 36 | 37 | void setCursor(int x, int y); 38 | 39 | void clear(); 40 | 41 | void draw_cursor(); 42 | 43 | void redraw(int x, int y, int width, int height); 44 | 45 | //void redraw(); 46 | void clear_area(int x1, int y1, int x2, int y2); 47 | 48 | void scroll_area(int x, int y, int w, int h, int dx, int dy); 49 | 50 | void drawBytes(byte[] buf, int s, int len, int x, int y); 51 | 52 | void drawString(String str, int x, int y); 53 | 54 | void beep(); 55 | 56 | void setDefaultForeGround(Object foreground); 57 | 58 | void setDefaultBackGround(Object background); 59 | 60 | void setForeGround(Object foreground); 61 | 62 | void setBackGround(Object background); 63 | 64 | void setBold(); 65 | 66 | void setUnderline(); 67 | 68 | void setReverse(); 69 | 70 | void resetAllAttributes(); 71 | 72 | int getTermWidth(); 73 | 74 | int getTermHeight(); 75 | 76 | Object getColor(int index); 77 | } 78 | --------------------------------------------------------------------------------