├── .gitignore ├── LICENSE ├── README.md ├── examples ├── example-full │ ├── alien-stare.png │ ├── barbarian.png │ ├── blindfold.png │ ├── character-GENERATED.html │ ├── character.css │ ├── character.csv │ ├── character.html │ ├── cowled.png │ ├── dead-head.png │ ├── dwarf-face.png │ ├── gluttony.png │ ├── icon-heart.png │ ├── icon-move.png │ ├── icon-shield.png │ ├── icon-skull.png │ ├── icon-swords.png │ ├── idea.png │ ├── iron-mask.png │ ├── lizardman.png │ ├── ninja-mask.png │ ├── one-eyed.png │ ├── overlord-helm.png │ ├── police-officer-head.png │ ├── pumpkin-mask.png │ ├── silenced.png │ ├── snake-bite.png │ ├── tear-tracks.png │ ├── wolf-head.png │ └── woman-elf-face.png └── example-minimum │ ├── card-GENERATED.html │ ├── card.css │ ├── card.csv │ └── card.html ├── pom.xml └── src └── main ├── java ├── com │ └── jdotsoft │ │ └── jarloader │ │ └── JarClassLoader.java └── net │ └── vaemendis │ └── hccd │ ├── CardGenerator.java │ ├── ErrorDialog.java │ ├── FileDrop.java │ ├── FileWatcher.java │ ├── Hccd.java │ ├── Launcher.java │ ├── MainForm.java │ ├── Tools.java │ ├── UserConfiguration.java │ └── WatchedFiles.java └── resources ├── icon-128.png ├── icon-16.png ├── icon-256.png ├── icon-32.png ├── icon-48.png └── icon-64.png /.gitignore: -------------------------------------------------------------------------------- 1 | /extra 2 | /target 3 | /.idea 4 | hccd.iml -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HCCD - HTML+CSS Card Designer 2 | 3 | HCCD is a small tool designed to automate the creation of game cards from a CSV (Excel) file using a few lines of HTML and CSS. 4 | 5 | **[Download it here](https://github.com/vaemendis/hccd/releases)** 6 | 7 | ![](http://vaemendis.github.io/external/hccd/hccd-diagram.png) 8 | 9 | For other card game creation tools (there are a lot of them), check [this list](https://boardgamegeek.com/thread/991506/resources-card-game-makers) on BoardGameGeek. 10 | 11 | # 30 seconds example 12 | Here is how to use HCCD: 13 | - Download and unzip the [latest HCCD release ](https://github.com/vaemendis/hccd/releases) (the **hccd-binary.zip** file) 14 | - Double click on **Hccd.jar** to launch the application (you need to have installed [Java](https://java.com/en/download/) first) 15 | - Now, in HCCD, open the file `character.html` from `examples/example-full` (or just drag and drop it on the user interface). 16 | A new file (`character-GENERATED.html`, the cards contact sheet) has been generated. You just created your first set of cards. (here is an [online example](http://vaemendis.github.io/external/hccd/character-GENERATED.html)) 17 | - You can now edit the card layout and description files (the contact sheet is automatically updated): 18 | - `character.html` 19 | - `character.css` 20 | - `character.csv` 21 | 22 | # How it works 23 | 24 | To build the card contact sheet, HCCD uses three files and as many image as you need: 25 | - **the HTML file**: contains the layout for a single type card, with variables declared using mustaches (e.g. `{{myVariable}}`). The custom code has to be declared in the `div` with the `card` class (see the HTML file in `examples/example-minimum`) 26 | - **the CSS file**: contains the style to apply to the HTML layout. As your cards will be printed, be careful to use physical units (`mm`, `pt`...) instead of pixels to define dimensions. 27 | - **the CSV file**: contains all the data specific to each card. The first line of the CSV file is the header: it contains the name of the columns (same names as the variables you have defined in your HTML file). Starting from the second line, a new card will be generated for every line. 28 | - **images**: can be referenced from the HTML or CSS files 29 | 30 | **IMPORTANT**: the three files (HTML, CSS, CSV) must have the *same name* (with a different extensions) and be in the same directory as the images. 31 | 32 | When you open your HTML file, HCCD will monitor it, as well as the two other files (CSS and CSV), so that each time one of these three files is modified the card contact sheet is automatically regenerated. If the contact sheet is already opened in your browser, just refresh it ot see your modifications. 33 | 34 | So once your HTML file is opened, just forget about HCCD and work on your files ! 35 | 36 | ## Settings 37 | 38 | Settings are modified in the interface. 39 | 40 | ![](http://vaemendis.github.io/external/hccd/hccd-screenshot.png) 41 | 42 | #### Rows/Columns 43 | Dimensions of the grid of cards. You have to choose it depending on your card size and page size so that it fits in a single page (HCCD will create as many grids and pages as necessary). 44 | 45 | #### CSV format 46 | **RFC-4180** is standard CSV format. If you use Excel and have issues reading the CSV file, try changing the format to **Excel.** 47 | 48 | #### Delimiter 49 | Must obviously match the delimiter used in your CSV file 50 | 51 | #### Card filter 52 | Usefull when you want to reprint only a part of your cards. Choose the card to print using comma separated values (and a dash for ranges). 53 | 54 | #### Refresh button 55 | Only usefull to apply new settings, as file modifications are automatically detected anyway. 56 | 57 | 58 | # Useful tips 59 | 60 | - Don't forget to use `mm` and `pt` instead of `px` in your CSS. 61 | - You don't need to hit the "Refresh" button each time you modify one of your description files (html, css, csv), HCCD monitors them and the contact sheet will be regenerated automatically. 62 | - If you want to fully automate your workflow, you can use an add-on like [Tab Auto Reload](https://addons.mozilla.org/en-US/firefox/addon/tab-auto-reload/) for Firefox. 63 | - The CSV file has to be UTF-8 encoded if you are using non-ASCII characters (like accents) 64 | - When printing the contact sheet using your browser, don't forget to adapt settings so that the page is printed at 100% of its size, with background images but any without margin or header. 65 | - If you get `[NOT FOUND]` on your cards instead of the text you had put into your CSV file, check that the delimiter and the CSV file type are correctly set in the interface. 66 | 67 | ## License 68 | HCCD is licensed under GPL V3. 69 | 70 | HCCD uses icons from [game-icons.net](http://game-icons.net/) and the [JarClassLoader](http://www.jdotsoft.com/JarClassLoader.php) from JDotSoft. 71 | 72 | ## Disclaimer 73 | 74 | As you might have gathered from the ugly user interface, the ugly code and the lack of unit tests, HCCD is a small, quickly put together tool made to meet my specific needs. It is not meant to evolve, except for a few bug fixes if need be. 75 | 76 | ## Alternatives 77 | 78 | - A long list of resources for card game making is available on the **BoardGameGeek forum**: 79 | https://boardgamegeek.com/thread/991506/resources-card-game-makers/page/1 80 | 81 | - **PyCard**, Python card maker inspired by Hccd: 82 | https://github.com/ghostsquad/pycard 83 | 84 | - **CardPen** is a web oriented card maker, also in the same family (HTML+CSS) as Hccd and PyCard: 85 | http://cardpen.mcdemarco.net/doc/index.html 86 | 87 | 88 | -------------------------------------------------------------------------------- /examples/example-full/alien-stare.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaemendis/hccd/0e8cd6c3347e60e80789555f030aa05391790814/examples/example-full/alien-stare.png -------------------------------------------------------------------------------- /examples/example-full/barbarian.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaemendis/hccd/0e8cd6c3347e60e80789555f030aa05391790814/examples/example-full/barbarian.png -------------------------------------------------------------------------------- /examples/example-full/blindfold.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaemendis/hccd/0e8cd6c3347e60e80789555f030aa05391790814/examples/example-full/blindfold.png -------------------------------------------------------------------------------- /examples/example-full/character-GENERATED.html: -------------------------------------------------------------------------------- 1 | 18 |
19 | 20 | 21 |
22 | Alien 23 |
24 |
25 |
26 | 1 27 |
28 |
29 | 1 30 |
31 |
32 | 4 33 |
34 |
35 | 9 36 |
37 |
38 | 1 39 |
40 |
41 |
42 | Lorem ipsum dolor sit amet, consectetur adipiscing elit 43 |
44 | 45 |
46 | 47 | 48 |
49 | Barbarian 50 |
51 |
52 |
53 | 7 54 |
55 |
56 | 2 57 |
58 |
59 | 6 60 |
61 |
62 | 8 63 |
64 |
65 | 2 66 |
67 |
68 |
69 | sed do eiusmod tempor incididunt ut labore et dolore magna 70 |
71 | 72 |
73 | 74 | 75 |
76 | Blind Man 77 |
78 |
79 |
80 | 9 81 |
82 |
83 | 8 84 |
85 |
86 | 5 87 |
88 |
89 | 1 90 |
91 |
92 | 4 93 |
94 |
95 |
96 | aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex 97 |
98 | 99 |
100 | 101 | 102 |
103 | Pythia 104 |
105 |
106 |
107 | 2 108 |
109 |
110 | 6 111 |
112 |
113 | 3 114 |
115 |
116 | 2 117 |
118 |
119 | 2 120 |
121 |
122 |
123 | ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur 124 |
125 | 126 |
127 | 128 | 129 |
130 | Dead Man 131 |
132 |
133 |
134 | 1 135 |
136 |
137 | 3 138 |
139 |
140 | 6 141 |
142 |
143 | 6 144 |
145 |
146 | 1 147 |
148 |
149 |
150 | sint occaecat cupidatat 151 |
152 | 153 |
154 | 155 | 156 |
157 | Viking 158 |
159 |
160 |
161 | 5 162 |
163 |
164 | 5 165 |
166 |
167 | 5 168 |
169 |
170 | 9 171 |
172 |
173 | 3 174 |
175 |
176 |
177 | proident, sunt in culpa qui officia deserunt mollit anim id est laborum 178 |
179 | 180 |
181 | 182 | 183 |
184 | Hungry Blob 185 |
186 |
187 |
188 | 3 189 |
190 |
191 | 7 192 |
193 |
194 | 6 195 |
196 |
197 | 1 198 |
199 |
200 | 2 201 |
202 |
203 |
204 | Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium , totam explicabo. Nemo enim ipsam voluptatem voluptas sit 205 |
206 | 207 |
208 | 209 | 210 |
211 | Smartbot 212 |
213 |
214 |
215 | 6 216 |
217 |
218 | 8 219 |
220 |
221 | 3 222 |
223 |
224 | 3 225 |
226 |
227 | 6 228 |
229 |
230 |
231 | aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem quia dolor sit amet, consectetur, adipisci velit, sed quia non 232 |
233 | 234 |
235 | 236 | 237 |
238 | Masked Man 239 |
240 |
241 |
242 | 4 243 |
244 |
245 | 9 246 |
247 |
248 | 9 249 |
250 |
251 | 2 252 |
253 |
254 | 3 255 |
256 |
257 |
258 | ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur 259 |
260 | 261 |
262 | 263 | 264 |
265 | Angry Monster 266 |
267 |
268 |
269 | 8 270 |
271 |
272 | 1 273 |
274 |
275 | 8 276 |
277 |
278 | 1 279 |
280 |
281 | 2 282 |
283 |
284 |
285 | sint occaecat cupidatat 286 |
287 | 288 |
289 | 290 | 291 |
292 | Ninja 293 |
294 |
295 |
296 | 5 297 |
298 |
299 | 2 300 |
301 |
302 | 2 303 |
304 |
305 | 1 306 |
307 |
308 | 1 309 |
310 |
311 |
312 | proident, sunt in culpa qui officia deserunt mollit anim id est laborum 313 |
314 | 315 |
316 | 317 | 318 |
319 | One-Eye 320 |
321 |
322 |
323 | 7 324 |
325 |
326 | 3 327 |
328 |
329 | 1 330 |
331 |
332 | 1 333 |
334 |
335 | 6 336 |
337 |
338 |
339 | Lorem ipsum dolor sit amet, consectetur adipiscing elit 340 |
341 | 342 |
343 | 344 | 345 |
346 | Nazgul 347 |
348 |
349 |
350 | 2 351 |
352 |
353 | 6 354 |
355 |
356 | 3 357 |
358 |
359 | 3 360 |
361 |
362 | 8 363 |
364 |
365 |
366 | sed do eiusmod tempor incididunt ut labore et dolore magna 367 |
368 | 369 |
370 | 371 | 372 |
373 | Policeman 374 |
375 |
376 |
377 | 6 378 |
379 |
380 | 5 381 |
382 |
383 | 7 384 |
385 |
386 | 2 387 |
388 |
389 | 2 390 |
391 |
392 |
393 | aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex 394 |
395 | 396 |
397 | 398 | 399 |
400 | Halloween Pumpkin 401 |
402 |
403 |
404 | 5 405 |
406 |
407 | 7 408 |
409 |
410 | 3 411 |
412 |
413 | 3 414 |
415 |
416 | 1 417 |
418 |
419 |
420 | aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex 421 |
422 | 423 |
424 | 425 | 426 |
427 | Silent 428 |
429 |
430 |
431 | 9 432 |
433 |
434 | 9 435 |
436 |
437 | 6 438 |
439 |
440 | 3 441 |
442 |
443 | 4 444 |
445 |
446 |
447 | ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur 448 |
449 | 450 |
451 | 452 | 453 |
454 | Snake 455 |
456 |
457 |
458 | 8 459 |
460 |
461 | 1 462 |
463 |
464 | 1 465 |
466 |
467 | 2 468 |
469 |
470 | 5 471 |
472 |
473 |
474 | sint occaecat cupidatat 475 |
476 | 477 |
478 | 479 | 480 |
481 | Crying Man 482 |
483 |
484 |
485 | 7 486 |
487 |
488 | 2 489 |
490 |
491 | 2 492 |
493 |
494 | 1 495 |
496 |
497 | 2 498 |
499 |
500 |
501 | proident, sunt in culpa qui officia deserunt mollit anim id est laborum 502 |
503 | 504 |
505 | 506 | 507 |
508 | Wolf 509 |
510 |
511 |
512 | 1 513 |
514 |
515 | 7 516 |
517 |
518 | 9 519 |
520 |
521 | 3 522 |
523 |
524 | 3 525 |
526 |
527 |
528 | Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium , totam explicabo. Nemo enim ipsam voluptatem voluptas sit 529 |
530 | 531 |
532 | 533 | 534 |
535 | Elf 536 |
537 |
538 |
539 | 2 540 |
541 |
542 | 5 543 |
544 |
545 | 8 546 |
547 |
548 | 2 549 |
550 |
551 | 2 552 |
553 |
554 |
555 | sint occaecat cupidatat 556 |
557 | 558 |
-------------------------------------------------------------------------------- /examples/example-full/character.css: -------------------------------------------------------------------------------- 1 | .card { 2 | margin: 0.5mm; 3 | border-style: solid; 4 | border-width: 0.8mm; 5 | border-color: black; 6 | border-radius: 3mm; 7 | width: 63mm; 8 | height: 88mm; 9 | } 10 | 11 | .avatar { 12 | float: left; 13 | margin: 1.1mm; 14 | width: 24mm; 15 | height: 24mm; 16 | } 17 | 18 | .name { 19 | margin-top: 2mm; 20 | margin-right: 1mm; 21 | margin-left: 1mm; 22 | font-family: "Arial"; 23 | font-weight: bold; 24 | font-size: 16pt; 25 | height: 10mm; 26 | } 27 | 28 | .icon { 29 | width: 7mm; 30 | height: 7mm; 31 | vertical-align: text-bottom; 32 | margin: 1mm; 33 | } 34 | 35 | .iconcell { 36 | padding: 0.5mm; 37 | margin-right: 1mm; 38 | } 39 | 40 | .carac { 41 | float: right; 42 | margin: 3mm; 43 | font-family: "Arial"; 44 | font-weight: bold; 45 | font-size: 16pt; 46 | } 47 | 48 | .text { 49 | float:left; 50 | font-family: "Arial"; 51 | font-size: 11pt; 52 | margin-left: 1.5mm; 53 | margin-right: 1.5mm; 54 | margin-top: 5mm; 55 | padding: 2mm; 56 | background-color: #EEEEEE; 57 | border-radius: 3mm; 58 | height: 51mm; 59 | width: 34mm; 60 | } -------------------------------------------------------------------------------- /examples/example-full/character.csv: -------------------------------------------------------------------------------- 1 | avatar;name;defense;attack;health;insanity;move;text 2 | alien-stare.png;Alien;1;1;4;9;1;Lorem ipsum dolor sit amet, consectetur adipiscing elit 3 | barbarian.png;Barbarian;7;2;6;8;2;sed do eiusmod tempor incididunt ut labore et dolore magna 4 | blindfold.png;Blind Man;9;8;5;1;4;aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex 5 | cowled.png;Pythia;2;6;3;2;2;ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur 6 | dead-head.png;Dead Man;1;3;6;6;1;sint occaecat cupidatat 7 | dwarf-face.png;Viking;5;5;5;9;3;proident, sunt in culpa qui officia deserunt mollit anim id est laborum 8 | gluttony.png;Hungry Blob;3;7;6;1;2;Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium , totam explicabo. Nemo enim ipsam voluptatem voluptas sit 9 | idea.png;Smartbot;6;8;3;3;6;aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem quia dolor sit amet, consectetur, adipisci velit, sed quia non 10 | iron-mask.png;Masked Man;4;9;9;2;3;ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur 11 | lizardman.png;Angry Monster;8;1;8;1;2;sint occaecat cupidatat 12 | ninja-mask.png;Ninja;5;2;2;1;1;proident, sunt in culpa qui officia deserunt mollit anim id est laborum 13 | one-eyed.png;One-Eye;7;3;1;1;6;Lorem ipsum dolor sit amet, consectetur adipiscing elit 14 | overlord-helm.png;Nazgul;2;6;3;3;8;sed do eiusmod tempor incididunt ut labore et dolore magna 15 | police-officer-head.png;Policeman;6;5;7;2;2;aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex 16 | pumpkin-mask.png;Halloween Pumpkin;5;7;3;3;1;aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex 17 | silenced.png;Silent;9;9;6;3;4;ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur 18 | snake-bite.png;Snake;8;1;1;2;5;sint occaecat cupidatat 19 | tear-tracks.png;Crying Man;7;2;2;1;2;proident, sunt in culpa qui officia deserunt mollit anim id est laborum 20 | wolf-head.png;Wolf;1;7;9;3;3;Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium , totam explicabo. Nemo enim ipsam voluptatem voluptas sit 21 | woman-elf-face.png;Elf;2;5;8;2;2;sint occaecat cupidatat 22 | -------------------------------------------------------------------------------- /examples/example-full/character.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 |
{{name}}
15 |
16 |
17 | {{defense}} 18 |
19 |
20 | {{attack}} 21 |
22 |
23 | {{health}} 24 |
25 |
26 | {{insanity}} 27 |
28 |
29 | {{move}} 30 |
31 |
32 |
{{text}}
33 | 34 | 35 |
36 | 37 | 38 | -------------------------------------------------------------------------------- /examples/example-full/cowled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaemendis/hccd/0e8cd6c3347e60e80789555f030aa05391790814/examples/example-full/cowled.png -------------------------------------------------------------------------------- /examples/example-full/dead-head.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaemendis/hccd/0e8cd6c3347e60e80789555f030aa05391790814/examples/example-full/dead-head.png -------------------------------------------------------------------------------- /examples/example-full/dwarf-face.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaemendis/hccd/0e8cd6c3347e60e80789555f030aa05391790814/examples/example-full/dwarf-face.png -------------------------------------------------------------------------------- /examples/example-full/gluttony.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaemendis/hccd/0e8cd6c3347e60e80789555f030aa05391790814/examples/example-full/gluttony.png -------------------------------------------------------------------------------- /examples/example-full/icon-heart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaemendis/hccd/0e8cd6c3347e60e80789555f030aa05391790814/examples/example-full/icon-heart.png -------------------------------------------------------------------------------- /examples/example-full/icon-move.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaemendis/hccd/0e8cd6c3347e60e80789555f030aa05391790814/examples/example-full/icon-move.png -------------------------------------------------------------------------------- /examples/example-full/icon-shield.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaemendis/hccd/0e8cd6c3347e60e80789555f030aa05391790814/examples/example-full/icon-shield.png -------------------------------------------------------------------------------- /examples/example-full/icon-skull.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaemendis/hccd/0e8cd6c3347e60e80789555f030aa05391790814/examples/example-full/icon-skull.png -------------------------------------------------------------------------------- /examples/example-full/icon-swords.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaemendis/hccd/0e8cd6c3347e60e80789555f030aa05391790814/examples/example-full/icon-swords.png -------------------------------------------------------------------------------- /examples/example-full/idea.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaemendis/hccd/0e8cd6c3347e60e80789555f030aa05391790814/examples/example-full/idea.png -------------------------------------------------------------------------------- /examples/example-full/iron-mask.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaemendis/hccd/0e8cd6c3347e60e80789555f030aa05391790814/examples/example-full/iron-mask.png -------------------------------------------------------------------------------- /examples/example-full/lizardman.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaemendis/hccd/0e8cd6c3347e60e80789555f030aa05391790814/examples/example-full/lizardman.png -------------------------------------------------------------------------------- /examples/example-full/ninja-mask.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaemendis/hccd/0e8cd6c3347e60e80789555f030aa05391790814/examples/example-full/ninja-mask.png -------------------------------------------------------------------------------- /examples/example-full/one-eyed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaemendis/hccd/0e8cd6c3347e60e80789555f030aa05391790814/examples/example-full/one-eyed.png -------------------------------------------------------------------------------- /examples/example-full/overlord-helm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaemendis/hccd/0e8cd6c3347e60e80789555f030aa05391790814/examples/example-full/overlord-helm.png -------------------------------------------------------------------------------- /examples/example-full/police-officer-head.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaemendis/hccd/0e8cd6c3347e60e80789555f030aa05391790814/examples/example-full/police-officer-head.png -------------------------------------------------------------------------------- /examples/example-full/pumpkin-mask.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaemendis/hccd/0e8cd6c3347e60e80789555f030aa05391790814/examples/example-full/pumpkin-mask.png -------------------------------------------------------------------------------- /examples/example-full/silenced.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaemendis/hccd/0e8cd6c3347e60e80789555f030aa05391790814/examples/example-full/silenced.png -------------------------------------------------------------------------------- /examples/example-full/snake-bite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaemendis/hccd/0e8cd6c3347e60e80789555f030aa05391790814/examples/example-full/snake-bite.png -------------------------------------------------------------------------------- /examples/example-full/tear-tracks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaemendis/hccd/0e8cd6c3347e60e80789555f030aa05391790814/examples/example-full/tear-tracks.png -------------------------------------------------------------------------------- /examples/example-full/wolf-head.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaemendis/hccd/0e8cd6c3347e60e80789555f030aa05391790814/examples/example-full/wolf-head.png -------------------------------------------------------------------------------- /examples/example-full/woman-elf-face.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaemendis/hccd/0e8cd6c3347e60e80789555f030aa05391790814/examples/example-full/woman-elf-face.png -------------------------------------------------------------------------------- /examples/example-minimum/card-GENERATED.html: -------------------------------------------------------------------------------- 1 | 18 |
19 | 20 |
Write your card template here. 21 |
Variables are declared using mustaches: 22 |
Card one 23 | 24 |
25 | 26 |
Write your card template here. 27 |
Variables are declared using mustaches: 28 |
Card two 29 | 30 |
31 | 32 |
Write your card template here. 33 |
Variables are declared using mustaches: 34 |
Card three 35 | 36 |
-------------------------------------------------------------------------------- /examples/example-minimum/card.css: -------------------------------------------------------------------------------- 1 | .card { 2 | margin: 0.5mm; 3 | border-style: solid; 4 | border-width: 0.8mm; 5 | border-color: black; 6 | border-radius: 3mm; 7 | width: 63mm; 8 | height: 88mm; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /examples/example-minimum/card.csv: -------------------------------------------------------------------------------- 1 | cardnumber 2 | one 3 | two 4 | three -------------------------------------------------------------------------------- /examples/example-minimum/card.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 |
17 | Write your card template here. 18 |
19 | Variables are declared using mustaches: 20 |
21 | Card {{cardnumber}} 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | net.vaemendis.hccd 7 | hccd 8 | 1.1 9 | 10 | 11 | 12 | UTF-8 13 | Hccd 14 | 15 | 16 | 17 | 18 | 19 | org.apache.maven.plugins 20 | maven-compiler-plugin 21 | 3.5.1 22 | 23 | true 24 | 1.8 25 | 1.8 26 | 27 | 28 | 29 | org.apache.maven.plugins 30 | maven-dependency-plugin 31 | 2.10 32 | 33 | 34 | copy-dependencies 35 | prepare-package 36 | 37 | copy-dependencies 38 | 39 | 40 | ${project.build.directory}/classes 41 | false 42 | false 43 | true 44 | 45 | runtime 46 | provided 47 | 48 | 49 | 50 | 51 | 52 | org.apache.maven.plugins 53 | maven-jar-plugin 54 | 2.6 55 | 56 | ${jar.name} 57 | 58 | 59 | net.vaemendis.hccd.Launcher 60 | 61 | 62 | ${project.version} 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | com.samskivert 75 | jmustache 76 | 1.12 77 | 78 | 79 | * 80 | * 81 | 82 | 83 | 84 | 85 | commons-io 86 | commons-io 87 | 2.4 88 | 89 | 90 | * 91 | * 92 | 93 | 94 | 95 | 96 | org.jsoup 97 | jsoup 98 | 1.8.3 99 | 100 | 101 | * 102 | * 103 | 104 | 105 | 106 | 107 | org.apache.commons 108 | commons-csv 109 | 1.3 110 | 111 | 112 | * 113 | * 114 | 115 | 116 | 117 | 118 | 119 | 120 | junit 121 | junit 122 | 4.12 123 | test 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /src/main/java/com/jdotsoft/jarloader/JarClassLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * File: JarClassLoader.java 3 | * 4 | * Copyright (C) 2008-2013 JDotSoft. All Rights Reserved. 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License version 2 as 8 | * published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13 | * See the GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 18 | * MA 02110-1301 USA 19 | * 20 | * Visit jdotsoft.com for commercial license. 21 | * 22 | * $Id: JarClassLoader.java,v 1.39 2016/04/24 17:25:30 mg Exp $ 23 | */ 24 | package com.jdotsoft.jarloader; 25 | 26 | import java.applet.AppletContext; 27 | import java.applet.AppletStub; 28 | import java.io.BufferedOutputStream; 29 | import java.io.BufferedReader; 30 | import java.io.BufferedWriter; 31 | import java.io.DataInputStream; 32 | import java.io.File; 33 | import java.io.FileNotFoundException; 34 | import java.io.FileOutputStream; 35 | import java.io.FileReader; 36 | import java.io.FileWriter; 37 | import java.io.IOException; 38 | import java.io.InputStream; 39 | import java.io.PrintStream; 40 | import java.io.UnsupportedEncodingException; 41 | import java.lang.reflect.InvocationTargetException; 42 | import java.lang.reflect.Method; 43 | import java.lang.reflect.Modifier; 44 | import java.net.JarURLConnection; 45 | import java.net.MalformedURLException; 46 | import java.net.URL; 47 | import java.net.URLDecoder; 48 | import java.security.CodeSource; 49 | import java.security.ProtectionDomain; 50 | import java.security.cert.Certificate; 51 | import java.util.ArrayList; 52 | import java.util.Collections; 53 | import java.util.Enumeration; 54 | import java.util.HashMap; 55 | import java.util.HashSet; 56 | import java.util.List; 57 | import java.util.Map; 58 | import java.util.Set; 59 | import java.util.jar.Attributes; 60 | import java.util.jar.Attributes.Name; 61 | import java.util.jar.JarEntry; 62 | import java.util.jar.JarFile; 63 | import java.util.jar.Manifest; 64 | 65 | import javax.swing.JApplet; 66 | 67 | /** 68 | * This class loader loads classes, native libraries and resources from 69 | * the top JAR and from JARs inside top JAR. The loading process looks 70 | * through JARs hierarchy and allows their tree structure, i.e. nested JARs. 71 | *

72 | * The top JAR and nested JARs are included in the classpath and searched 73 | * for the class or resource to load. The nested JARs could be located 74 | * in any directories or subdirectories in a parent JAR. 75 | *

76 | * All directories or subdirectories in the top JAR and nested JARs are 77 | * included in the library path and searched for a native library. 78 | * For example, the library "Native.dll" could be in the JAR root directory 79 | * as "Native.dll" or in any directory as "lib/Native.dll" 80 | * or "abc/xyz/Native.dll". 81 | *

82 | * This class delegates class loading to the parent class loader and 83 | * successfully loads classes, native libraries and resources when it works 84 | * not in a JAR environment. 85 | *

86 | * Create a launcher class to start your class 87 | * com.mycompany.MyApp main() method to start your application 88 | * 89 |

  90 |  public class MyAppLauncher {
  91 | 
  92 |  public static void main(String[] args) {
  93 |  JarClassLoader jcl = new JarClassLoader();
  94 |  try {
  95 |  jcl.invokeMain("com.mycompany.MyApp", args);
  96 |  } catch (Throwable e) {
  97 |  e.printStackTrace();
  98 |  }
  99 |  } // main()
 100 | 
 101 |  } // class MyAppLauncher
 102 |  
103 | * 104 | *

105 | * An application could be started in two different environments: 106 | *
107 | * 1. Application is started from an exploded JAR with dependent resources 108 | * locations defined in a classpath. 109 | * Command line to start the application could point to the main class e.g. 110 | * MyApp.main() or to the MyAppLauncher.main() 111 | * class (see example above). The application behavior in both cases 112 | * is identical. Application started with MyApp.main() 113 | * uses system class loader and resources loaded from a file system. 114 | * Application started with MyAppLauncher.main() 115 | * uses JarClassLoader which transparently passes class 116 | * loading to the system class loader. 117 | * 118 | *
119 | * 2. Application is started from a JAR with dependent JARs and other 120 | * resources inside the main JAR. 121 | * Application must be started with MyAppLauncher.main() and 122 | * JarClassLoader will load MyApp.main() 123 | * and required resources from the main JAR. 124 | * 125 | *

The launcher class for the Java applet is very similar to application 126 | * launcher. 127 | * 128 |

 129 |  public class MyAppletLauncher extends JApplet {
 130 | 
 131 |  private JarClassLoader jcl;
 132 | 
 133 |  @Override
 134 |  public void init() {
 135 |  jcl = new JarClassLoader();
 136 |  try {
 137 |  jcl.initApplet("com.mycompany.MyApplet", this);
 138 |  } catch (Throwable e) {
 139 |  e.printStackTrace();
 140 |  }
 141 |  }
 142 | 
 143 |  @Override
 144 |  public void start() {
 145 |  jcl.startApplet();
 146 |  }
 147 | 
 148 |  @Override
 149 |  public void stop() {
 150 |  jcl.stopApplet();
 151 |  }
 152 | 
 153 |  @Override
 154 |  public void destroy() {
 155 |  jcl.destroyApplet();
 156 |  }
 157 | 
 158 |  } // class MyAppletLauncher
 159 |  
160 | * 161 | * The applet launcher class could have both main() and applet 162 | * related methods for UI class which could be started as an application or 163 | * an applet. This technique is very convenient to develop an applet and test 164 | * it as an application. 165 | * 166 | *

167 | * Use VM parameters in the command line for logging settings (examples): 168 | *

    169 | *
  • -DJarClassLoader.logger=[filename] for logging into the file. 170 | * The default is console.
  • 171 | *
  • -DJarClassLoader.logger.level=INFO for logging level. 172 | * The default level is ERROR. See also {@link LogLevel}.
  • 173 | *
  • -DJarClassLoader.logger.area=CLASS,RESOURCE for logging area. 174 | * The default area is ALL. See also {@link LogArea}. Multiple logging areas 175 | * could be specified with ',' delimiter.
  • 176 | *
177 | * 178 | *

179 | * Known issues: some temporary files created by class loader are not deleted 180 | * on application exit because JVM does not close handles to them. 181 | * See details in {@link #shutdown()}. 182 | *

183 | * See also discussion "How load library from jar file?" 184 | * http://discuss.develop.com/archives/wa.exe?A2=ind0302&L=advanced-java&D=0&P=4549 185 | * Unfortunately, the native method java.lang.ClassLoader$NativeLibrary.unload() 186 | * is package accessed in a package accessed inner class. 187 | * Moreover, it's called from finalizer. This does not allow releasing 188 | * the native library handle and delete the temporary library file. 189 | * Option to explore: use JNI function UnregisterNatives(). See also 190 | * native code in ...\jdk\src\share\native\java\lang\ClassLoader.class 191 | * 192 | * @version $Revision: 1.39 $ 193 | */ 194 | public class JarClassLoader extends ClassLoader { 195 | 196 | /** VM parameter key to turn on logging to file or console. */ 197 | public static final String KEY_LOGGER = "JarClassLoader.logger"; 198 | 199 | /** 200 | * VM parameter key to define log level. 201 | * Valid levels are defined in {@link LogLevel}. 202 | * Default value is {@link LogLevel#OFF}. 203 | */ 204 | public static final String KEY_LOGGER_LEVEL = "JarClassLoader.logger.level"; 205 | 206 | /** 207 | * VM parameter key to define log area. 208 | * Valid areas are defined in {@link LogArea}. 209 | * Default value is {@link LogArea#ALL}. Multiple areas could be specified 210 | * with ',' delimiter (no spaces!). 211 | */ 212 | public static final String KEY_LOGGER_AREA = "JarClassLoader.logger.area"; 213 | 214 | public enum LogLevel { ERROR, WARN, INFO, DEBUG } 215 | public enum LogArea { 216 | /** Enable all logging areas. */ 217 | ALL, 218 | /** Configuration related logging. Enabled always. */ 219 | CONFIG, 220 | /** Enable JAR related logging. */ 221 | JAR, 222 | /** Enable class loading related logging. */ 223 | CLASS, 224 | /** Enable resource loading related logging. */ 225 | RESOURCE, 226 | /** Enable native libraries loading related logging. */ 227 | NATIVE 228 | } 229 | 230 | /** 231 | * Sub directory name for temporary files. 232 | *

233 | * JarClassLoader extracts all JARs and native libraries into temporary files 234 | * and makes the best attempt to clean these files on exit. 235 | *

236 | * The sub directory is created in the directory defined in a system 237 | * property "java.io.tmpdir". Verify the content of this directory 238 | * periodically and empty it if required. Temporary files could accumulate 239 | * there if application was killed. 240 | */ 241 | public static final String TMP_SUB_DIRECTORY = "JarClassLoader"; 242 | 243 | private File dirTemp; 244 | private PrintStream logger; 245 | private List lstJarFile; 246 | private Set hsDeleteOnExit; 247 | private Map> hmClass; 248 | private LogLevel logLevel; 249 | private Set hsLogArea; 250 | private boolean bLogConsole; 251 | private JApplet applet; 252 | 253 | /** 254 | * Default constructor. 255 | * Defines system class loader as a parent class loader. 256 | */ 257 | public JarClassLoader() { 258 | this(ClassLoader.getSystemClassLoader()); 259 | } 260 | 261 | /** 262 | * Constructor. 263 | * 264 | * @param parent class loader parent. 265 | */ 266 | public JarClassLoader(ClassLoader parent) { 267 | super(parent); 268 | initLogger(); 269 | 270 | hmClass = new HashMap>(); 271 | lstJarFile = new ArrayList(); 272 | hsDeleteOnExit = new HashSet(); 273 | 274 | // Prepare common for all protocols 275 | String sUrlTopJar = null; 276 | ProtectionDomain pdTop = getClass().getProtectionDomain(); 277 | CodeSource cs = pdTop.getCodeSource(); 278 | URL urlTopJar = cs.getLocation(); 279 | String protocol = urlTopJar.getProtocol(); 280 | 281 | // Work with different cases: 282 | JarFileInfo jarFileInfo = null; 283 | if ("http".equals(protocol) || "https".equals(protocol)) { 284 | // Protocol 'http' or 'https' - application launched from WebStart / JNLP or as Java applet 285 | try { 286 | // Convert: 287 | // urlTopJar = "http://.../MyApp.jar" --> connection sun.net.www.protocol.http.HttpURLConnection 288 | // to 289 | // urlTopJar = "jar:http://.../MyApp.jar!/" --> connection java.net.JarURLConnection 290 | urlTopJar = new URL("jar:" + urlTopJar + "!/"); 291 | JarURLConnection jarCon = (JarURLConnection)urlTopJar.openConnection(); 292 | JarFile jarFile = jarCon.getJarFile(); 293 | jarFileInfo = new JarFileInfo(jarFile, jarFile.getName(), null, pdTop, null); 294 | logInfo(LogArea.JAR, "Loading from top JAR: '%s' PROTOCOL: '%s'", 295 | urlTopJar, protocol); 296 | } catch (Exception e) { 297 | // ClassCastException, IOException 298 | logError(LogArea.JAR, "Failure to load HTTP JAR: %s %s", urlTopJar, e.toString()); 299 | return; 300 | } 301 | } 302 | if ("file".equals(protocol)) { 303 | // Protocol 'file' - application launched from exploded dir or JAR 304 | // Decoding required for 'space char' in URL: 305 | // URL.getFile() returns "/C:/my%20dir/MyApp.jar" for "/C:/my dir/MyApp.jar" 306 | try { 307 | sUrlTopJar = URLDecoder.decode(urlTopJar.getFile(), "UTF-8"); 308 | } catch (UnsupportedEncodingException e) { 309 | logError(LogArea.JAR, "Failure to decode URL: %s %s", urlTopJar, e.toString()); 310 | return; 311 | } 312 | File fileJar = new File(sUrlTopJar); 313 | 314 | // Application is loaded from directory: 315 | if (fileJar.isDirectory()) { 316 | logInfo(LogArea.JAR, "Loading from exploded directory: %s", sUrlTopJar); 317 | return; // JarClassLoader completed its job 318 | } 319 | 320 | // Application is loaded from a JAR: 321 | try { 322 | jarFileInfo = new JarFileInfo(new JarFile(fileJar), fileJar.getName(), null, pdTop, null); 323 | logInfo(LogArea.JAR, "Loading from top JAR: '%s' PROTOCOL: '%s'", sUrlTopJar, protocol); 324 | } catch (IOException e) { 325 | logError(LogArea.JAR, "Not a JAR: %s %s", sUrlTopJar, e.toString()); 326 | return; 327 | } 328 | } 329 | 330 | // FINALLY LOAD TOP JAR: 331 | try { 332 | if (jarFileInfo == null) { 333 | throw new IOException(String.format( 334 | "Unknown protocol %s", protocol)); 335 | } 336 | loadJar(jarFileInfo); // start recursive JAR loading 337 | } catch (IOException e) { 338 | logError(LogArea.JAR, "Not valid URL: %s %s", urlTopJar, e.toString()); 339 | return; 340 | } 341 | 342 | checkShading(); 343 | Runtime.getRuntime().addShutdownHook(new Thread() { 344 | public void run() { 345 | shutdown(); 346 | } 347 | }); 348 | } // JarClassLoader() 349 | 350 | //--------------------------------separator-------------------------------- 351 | static int ______INIT; 352 | 353 | private void initLogger() { 354 | // Logger defaults: 355 | bLogConsole = true; 356 | this.logger = System.out; // default to console 357 | logLevel = LogLevel.ERROR; 358 | hsLogArea = new HashSet(); 359 | hsLogArea.add(LogArea.CONFIG); 360 | 361 | // Logger stream console or file: 362 | String sLogger = System.getProperty(KEY_LOGGER); 363 | if (sLogger != null) { 364 | try { 365 | this.logger = new PrintStream(sLogger); 366 | bLogConsole = false; 367 | } catch (FileNotFoundException e) { 368 | logError(LogArea.CONFIG, "Cannot create log file %s.", sLogger); 369 | } 370 | } 371 | 372 | // Logger level: 373 | String sLogLevel = System.getProperty(KEY_LOGGER_LEVEL); 374 | if (sLogLevel != null) { 375 | try { 376 | logLevel = LogLevel.valueOf(sLogLevel); 377 | } catch (Exception e) { 378 | logError(LogArea.CONFIG, "Not valid parameter in %s=%s", KEY_LOGGER_LEVEL, sLogLevel); 379 | } 380 | } 381 | 382 | // Logger area: 383 | String sLogArea = System.getProperty(KEY_LOGGER_AREA); 384 | if (sLogArea != null) { 385 | String[] tokenAll = sLogArea.split(","); 386 | try { 387 | for (String t : tokenAll) { 388 | hsLogArea.add(LogArea.valueOf(t)); 389 | } 390 | } catch (Exception e) { 391 | logError(LogArea.CONFIG, "Not valid parameter in %s=%s", KEY_LOGGER_AREA, sLogArea); 392 | } 393 | } 394 | if (hsLogArea.size() == 1 && hsLogArea.contains(LogArea.CONFIG)) { 395 | for (LogArea la : LogArea.values()) { 396 | hsLogArea.add(la); 397 | } 398 | } 399 | } // initLogger() 400 | 401 | /** 402 | * Using temp files (one per inner JAR/DLL) solves many issues: 403 | * 1. There are no ways to load JAR defined in a JarEntry directly 404 | * into the JarFile object (see also #6 below). 405 | * 2. Cannot use memory-mapped files because they are using 406 | * nio channels, which are not supported by JarFile ctor. 407 | * 3. JarFile object keeps opened JAR files handlers for fast access. 408 | * 4. Deep resource in a jar-in-jar does not have well defined URL. 409 | * Making temp file with JAR solves this problem. 410 | * 5. Similar issues with native libraries: 411 | * ClassLoader.findLibrary() accepts ONLY string with 412 | * absolute path to the file with native library. 413 | * 6. Option "java.protocol.handler.pkgs" does not allow access to nested JARs(?). 414 | * 415 | * @param inf JAR entry information. 416 | * @return temporary file object presenting JAR entry. 417 | * @throws JarClassLoaderException 418 | */ 419 | private File createTempFile(JarEntryInfo inf) 420 | throws JarClassLoaderException { 421 | // Temp files directory: 422 | // WinXP: C:/Documents and Settings/username/Local Settings/Temp/JarClassLoader 423 | // Unix: /var/tmp/JarClassLoader 424 | if (dirTemp == null) { 425 | File dir = new File(System.getProperty("java.io.tmpdir"), TMP_SUB_DIRECTORY); 426 | if (!dir.exists()) { 427 | dir.mkdir(); 428 | } 429 | chmod777(dir); // Unix - allow temp directory RW access to all users. 430 | if (!dir.exists() || !dir.isDirectory()) { 431 | throw new JarClassLoaderException( 432 | "Cannot create temp directory " + dir.getAbsolutePath()); 433 | } 434 | dirTemp = dir; 435 | } 436 | File fileTmp = null; 437 | try { 438 | fileTmp = File.createTempFile(inf.getName() + ".", null, dirTemp); 439 | fileTmp.deleteOnExit(); 440 | chmod777(fileTmp); // Unix - allow temp file deletion by any user 441 | byte[] a_by = inf.getJarBytes(); 442 | BufferedOutputStream os = new BufferedOutputStream( 443 | new FileOutputStream(fileTmp)); 444 | os.write(a_by); 445 | os.close(); 446 | return fileTmp; 447 | } catch (IOException e) { 448 | throw new JarClassLoaderException(String.format( 449 | "Cannot create temp file '%s' for %s", fileTmp, inf.jarEntry), e); 450 | } 451 | } // createTempFile() 452 | 453 | /** 454 | * Loads specified JAR. 455 | * 456 | * @param jarFileInfo 457 | * @throws IOException 458 | */ 459 | private void loadJar(JarFileInfo jarFileInfo) throws IOException { 460 | lstJarFile.add(jarFileInfo); 461 | try { 462 | Enumeration en = jarFileInfo.jarFile.entries(); 463 | final String EXT_JAR = ".jar"; 464 | while (en.hasMoreElements()) { 465 | JarEntry je = en.nextElement(); 466 | if (je.isDirectory()) { 467 | continue; 468 | } 469 | String s = je.getName().toLowerCase(); // JarEntry name 470 | if (s.lastIndexOf(EXT_JAR) == s.length() - EXT_JAR.length()) { 471 | JarEntryInfo inf = new JarEntryInfo(jarFileInfo, je); 472 | File fileTemp = createTempFile(inf); 473 | logInfo(LogArea.JAR, "Loading inner JAR %s from temp file %s", 474 | inf.jarEntry, getFilename4Log(fileTemp)); 475 | // Construct ProtectionDomain for this inner JAR: 476 | URL url = fileTemp.toURI().toURL(); 477 | ProtectionDomain pdParent = jarFileInfo.pd; 478 | // 'csParent' is never null: top JAR has it, JCL creates it for child JAR: 479 | CodeSource csParent = pdParent.getCodeSource(); 480 | Certificate[] certParent = csParent.getCertificates(); 481 | CodeSource csChild = (certParent == null ? new CodeSource(url, csParent.getCodeSigners()) 482 | : new CodeSource(url, certParent)); 483 | ProtectionDomain pdChild = new ProtectionDomain(csChild, 484 | pdParent.getPermissions(), pdParent.getClassLoader(), pdParent.getPrincipals()); 485 | loadJar(new JarFileInfo( 486 | new JarFile(fileTemp), inf.getName(), jarFileInfo, pdChild, fileTemp)); 487 | } 488 | } 489 | } catch (JarClassLoaderException e) { 490 | throw new RuntimeException( 491 | "ERROR on loading inner JAR: " + e.getMessageAll()); 492 | } 493 | } // loadJar() 494 | 495 | private JarEntryInfo findJarEntry(String sName) { 496 | for (JarFileInfo jarFileInfo : lstJarFile) { 497 | JarFile jarFile = jarFileInfo.jarFile; 498 | JarEntry jarEntry = jarFile.getJarEntry(sName); 499 | if (jarEntry != null) { 500 | return new JarEntryInfo(jarFileInfo, jarEntry); 501 | } 502 | } 503 | return null; 504 | } // findJarEntry() 505 | 506 | private List findJarEntries(String sName) { 507 | List lst = new ArrayList(); 508 | for (JarFileInfo jarFileInfo : lstJarFile) { 509 | JarFile jarFile = jarFileInfo.jarFile; 510 | JarEntry jarEntry = jarFile.getJarEntry(sName); 511 | if (jarEntry != null) { 512 | lst.add(new JarEntryInfo(jarFileInfo, jarEntry)); 513 | } 514 | } 515 | return lst; 516 | } // findJarEntries() 517 | 518 | /** 519 | * Finds native library entry. 520 | * 521 | * @param sLib Library name. For example for the library name "Native" 522 | * - Windows returns entry "Native.dll" 523 | * - Linux returns entry "libNative.so" 524 | * - Mac returns entry "libNative.jnilib" or "libNative.dylib" 525 | * (depending on Apple or Oracle JDK and/or JDK version) 526 | * @return Native library entry. 527 | */ 528 | private JarEntryInfo findJarNativeEntry(String sLib) { 529 | String sName = System.mapLibraryName(sLib); 530 | for (JarFileInfo jarFileInfo : lstJarFile) { 531 | JarFile jarFile = jarFileInfo.jarFile; 532 | Enumeration en = jarFile.entries(); 533 | while (en.hasMoreElements()) { 534 | JarEntry je = en.nextElement(); 535 | if (je.isDirectory()) { 536 | continue; 537 | } 538 | // Example: sName is "Native.dll" 539 | String sEntry = je.getName(); // "Native.dll" or "abc/xyz/Native.dll" 540 | // sName "Native.dll" could be found, for example 541 | // - in the path: abc/Native.dll/xyz/my.dll <-- do not load this one! 542 | // - in the partial name: abc/aNative.dll <-- do not load this one! 543 | String[] token = sEntry.split("/"); // the last token is library name 544 | if (token.length > 0 && token[token.length - 1].equals(sName)) { 545 | logInfo(LogArea.NATIVE, "Loading native library '%s' found as '%s' in JAR %s", 546 | sLib, sEntry, jarFileInfo.simpleName); 547 | return new JarEntryInfo(jarFileInfo, je); 548 | } 549 | } 550 | } 551 | return null; 552 | } // findJarNativeEntry() 553 | 554 | /** 555 | * Loads class from a JAR and searches for all jar-in-jar. 556 | * 557 | * @param sClassName class to load. 558 | * @return Loaded class. 559 | * @throws JarClassLoaderException. 560 | */ 561 | private Class findJarClass(String sClassName) throws JarClassLoaderException { 562 | Class c = hmClass.get(sClassName); 563 | if (c != null) { 564 | return c; 565 | } 566 | // Char '/' works for Win32 and Unix. 567 | String sName = sClassName.replace('.', '/') + ".class"; 568 | JarEntryInfo inf = findJarEntry(sName); 569 | String jarSimpleName = null; 570 | if (inf != null) { 571 | jarSimpleName = inf.jarFileInfo.simpleName; 572 | definePackage(sClassName, inf); 573 | byte[] a_by = inf.getJarBytes(); 574 | try { 575 | c = defineClass(sClassName, a_by, 0, a_by.length, inf.jarFileInfo.pd); 576 | } catch (ClassFormatError e) { 577 | throw new JarClassLoaderException(null, e); 578 | } 579 | } 580 | if (c == null) { 581 | throw new JarClassLoaderException(sClassName); 582 | } 583 | hmClass.put(sClassName, c); 584 | logInfo(LogArea.CLASS, "Loaded %s by %s from JAR %s", 585 | sClassName, getClass().getName(), jarSimpleName); 586 | return c; 587 | } // findJarClass() 588 | 589 | private void checkShading() { 590 | if (logLevel.ordinal() < LogLevel.WARN.ordinal()) { 591 | // Do not waste time if no logging. 592 | return; 593 | } 594 | Map hm = new HashMap(); 595 | for (JarFileInfo jarFileInfo : lstJarFile) { 596 | JarFile jarFile = jarFileInfo.jarFile; 597 | Enumeration en = jarFile.entries(); 598 | while (en.hasMoreElements()) { 599 | JarEntry je = en.nextElement(); 600 | if (je.isDirectory()) { 601 | continue; 602 | } 603 | String sEntry = je.getName(); // "Some.txt" or "abc/xyz/Some.txt" 604 | if ("META-INF/MANIFEST.MF".equals(sEntry)) { 605 | continue; 606 | } 607 | JarFileInfo jar = hm.get(sEntry); 608 | if (jar == null) { 609 | hm.put(sEntry, jarFileInfo); 610 | } else { 611 | logWarn(LogArea.JAR, "ENTRY %s IN %s SHADES %s", 612 | sEntry, jar.simpleName, jarFileInfo.simpleName); 613 | } 614 | } 615 | } 616 | } // checkShading() 617 | 618 | //--------------------------------separator-------------------------------- 619 | static int ______SHUTDOWN; 620 | 621 | /** 622 | * Called on shutdown to cleanup temporary files. 623 | *

624 | * JVM does not close handles to native libraries files or JARs with 625 | * resources loaded as getResourceAsStream(). Temp files are not deleted 626 | * even if they are marked deleteOnExit(). They also fail to delete explicitly. 627 | * Workaround is to preserve list with temp files in configuration file 628 | * "[user.home]/.JarClassLoader" and delete them on next application run. 629 | *

630 | * See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4171239 631 | * "This occurs only on Win32, which does not allow a file to be deleted 632 | * until all streams on it have been closed." 633 | */ 634 | private void shutdown() { 635 | for (JarFileInfo jarFileInfo : lstJarFile) { 636 | try { 637 | jarFileInfo.jarFile.close(); 638 | } catch (IOException e) { 639 | // Ignore. In the worst case temp files will accumulate. 640 | } 641 | File file = jarFileInfo.fileDeleteOnExit; 642 | if (file != null && !file.delete()) { 643 | hsDeleteOnExit.add(file); 644 | } 645 | } 646 | // Private configuration file with failed to delete temporary files: 647 | // WinXP: C:/Documents and Settings/username/.JarClassLoader 648 | // Unix: /export/home/username/.JarClassLoader 649 | // -or- /home/username/.JarClassLoader 650 | File fileCfg = new File(System.getProperty("user.home") 651 | + File.separator + ".JarClassLoader"); 652 | deleteOldTemp(fileCfg); 653 | persistNewTemp(fileCfg); 654 | } // shutdown() 655 | 656 | /** 657 | * Deletes temporary files listed in the file. 658 | * The method is called on shutdown(). 659 | * 660 | * @param fileCfg file with temporary files list. 661 | */ 662 | private void deleteOldTemp(File fileCfg) { 663 | BufferedReader reader = null; 664 | try { 665 | int count = 0; 666 | reader = new BufferedReader(new FileReader(fileCfg)); 667 | String sLine; 668 | while ((sLine = reader.readLine()) != null) { 669 | File file = new File(sLine); 670 | if (!file.exists()) { 671 | continue; // already deleted; from command line? 672 | } 673 | if (file.delete()) { 674 | count++; 675 | } else { 676 | // Cannot delete, will try next time. 677 | hsDeleteOnExit.add(file); 678 | } 679 | } 680 | logDebug(LogArea.CONFIG, "Deleted %d old temp files listed in %s", 681 | count, fileCfg.getAbsolutePath()); 682 | } catch (IOException e) { 683 | // Ignore. This file may not exist. 684 | } finally { 685 | if (reader != null) { 686 | try { reader.close(); } catch (IOException e) { } 687 | } 688 | } 689 | } // deleteOldTemp() 690 | 691 | /** 692 | * Creates file with temporary files list. This list will be used to 693 | * delete temporary files on the next application launch. 694 | * The method is called from shutdown(). 695 | * 696 | * @param fileCfg file with temporary files list. 697 | */ 698 | private void persistNewTemp(File fileCfg) { 699 | if (hsDeleteOnExit.size() == 0) { 700 | logDebug(LogArea.CONFIG, "No temp file names to persist on exit."); 701 | fileCfg.delete(); // do not pollute disk 702 | return; 703 | } 704 | logDebug(LogArea.CONFIG, "Persisting %d temp file names into %s", 705 | hsDeleteOnExit.size(), fileCfg.getAbsolutePath()); 706 | BufferedWriter writer = null; 707 | try { 708 | writer = new BufferedWriter(new FileWriter(fileCfg)); 709 | for (File file : hsDeleteOnExit) { 710 | if (!file.delete()) { 711 | String f = file.getCanonicalPath(); 712 | writer.write(f); 713 | writer.newLine(); 714 | logWarn(LogArea.JAR, "JVM failed to release %s", f); 715 | } 716 | } 717 | } catch (IOException e) { 718 | // Ignore. In the worst case temp files will accumulate. 719 | } finally { 720 | if (writer != null) { 721 | try { writer.close(); } catch (IOException e) { } 722 | } 723 | } 724 | } // persistNewTemp() 725 | 726 | //--------------------------------separator-------------------------------- 727 | static int ______ACCESS; 728 | 729 | /** 730 | * Checks how the application was loaded: from JAR or file system. 731 | * 732 | * @return true if application was started from JAR. 733 | */ 734 | public boolean isLaunchedFromJar() { 735 | return (lstJarFile.size() > 0); 736 | } // isLaunchedFromJar() 737 | 738 | /** 739 | * Returns the name of the jar file main class, or null if 740 | * no "Main-Class" manifest attributes was defined. 741 | * 742 | * @return Main class declared in JAR's manifest. 743 | */ 744 | public String getManifestMainClass() { 745 | Attributes attr = null; 746 | if (isLaunchedFromJar()) { 747 | try { 748 | // The first element in array is the top level JAR 749 | Manifest m = lstJarFile.get(0).jarFile.getManifest(); 750 | attr = m.getMainAttributes(); 751 | } catch (IOException e) { 752 | } 753 | } 754 | return (attr == null ? null : attr.getValue(Attributes.Name.MAIN_CLASS)); 755 | } // getManifestMainClass() 756 | 757 | /** 758 | * Invokes main() method on class with provided parameters. 759 | * 760 | * @param sClass class name in form "MyClass" for default package 761 | * or "com.abc.MyClass" for class in some package 762 | * 763 | * @param args arguments for the main() method or null. 764 | * 765 | * @throws Throwable wrapper for many exceptions thrown while 766 | *

(1) main() method lookup: 767 | * ClassNotFoundException, SecurityException, NoSuchMethodException 768 | *

(2) main() method launch: 769 | * IllegalArgumentException, IllegalAccessException (disabled) 770 | *

(3) Actual cause of InvocationTargetException 771 | * 772 | * See 773 | * {@link http://java.sun.com/developer/Books/javaprogramming/JAR/api/jarclassloader.html} 774 | * and 775 | * {@link http://java.sun.com/developer/Books/javaprogramming/JAR/api/example-1dot2/JarClassLoader.java} 776 | */ 777 | public void invokeMain(String sClass, String[] args) throws Throwable { 778 | Class clazz = loadClass(sClass); 779 | logInfo(LogArea.CONFIG, "Launch: %s.main(); Loader: %s", sClass, clazz.getClassLoader()); 780 | Method method = clazz.getMethod("main", new Class[] { String[].class }); 781 | 782 | boolean bValidModifiers = false; 783 | boolean bValidVoid = false; 784 | 785 | if (method != null) { 786 | method.setAccessible(true); // Disable IllegalAccessException 787 | int nModifiers = method.getModifiers(); // main() must be "public static" 788 | bValidModifiers = Modifier.isPublic(nModifiers) && 789 | Modifier.isStatic(nModifiers); 790 | Class clazzRet = method.getReturnType(); // main() must be "void" 791 | bValidVoid = (clazzRet == void.class); 792 | } 793 | if (method == null || !bValidModifiers || !bValidVoid) { 794 | throw new NoSuchMethodException( 795 | "The main() method in class \"" + sClass + "\" not found."); 796 | } 797 | 798 | // Invoke method. 799 | // Crazy cast "(Object)args" because param is: "Object... args" 800 | try { 801 | method.invoke(null, (Object)args); 802 | } catch (InvocationTargetException e) { 803 | throw e.getTargetException(); 804 | } 805 | } // invokeMain() 806 | 807 | /** 808 | * Call this method to initialize an applet from your launcher class 809 | * MyAppletLauncher.init() method. 810 | * 811 | * @param sClass class name in form "MyClass" for default package 812 | * or "com.abc.MyClass" for class in some package 813 | * 814 | * @param appletParent parent applet from a launcher. 815 | * 816 | * @throws Throwable wrapper for many exceptions thrown while applet 817 | * instantiation and calling init() method. 818 | */ 819 | public void initApplet(String sClass, final JApplet appletParent) throws Throwable { 820 | Class clazz = loadClass(sClass); 821 | logInfo(LogArea.CONFIG, "initApplet() --> %s.init(); Loader: %s", sClass, clazz.getClassLoader()); 822 | applet = (JApplet)clazz.newInstance(); 823 | applet.setStub(new AppletStub() { 824 | @Override 825 | public boolean isActive() { 826 | return appletParent.isActive(); 827 | } 828 | @Override 829 | public URL getDocumentBase() { 830 | return appletParent.getDocumentBase(); 831 | } 832 | @Override 833 | public URL getCodeBase() { 834 | return appletParent.getCodeBase(); 835 | } 836 | @Override 837 | public String getParameter(String name) { 838 | return appletParent.getParameter(name); 839 | } 840 | @Override 841 | public AppletContext getAppletContext() { 842 | return appletParent.getAppletContext(); 843 | } 844 | @Override 845 | public void appletResize(int width, int height) { 846 | appletParent.resize(width, height); 847 | } 848 | }); 849 | applet.init(); 850 | appletParent.setContentPane(applet.getContentPane()); 851 | } // initApplet() 852 | 853 | /** 854 | * Call this method to start the applet from your launcher class 855 | * MyAppletLauncher.start() method. 856 | */ 857 | public void startApplet() { 858 | checkApplet(); 859 | logInfo(LogArea.CONFIG, "startApplet() --> %s.start()", applet.getClass().getName()); 860 | applet.start(); 861 | } 862 | 863 | /** 864 | * Call this method to stop the applet from your launcher class 865 | * MyAppletLauncher.stop() method. 866 | */ 867 | public void stopApplet() { 868 | checkApplet(); 869 | logInfo(LogArea.CONFIG, "stopApplet() --> %s.stop()", applet.getClass().getName()); 870 | applet.stop(); 871 | } 872 | 873 | /** 874 | * Call this method to destroy the applet from your launcher class 875 | * MyAppletLauncher.destroy() method. 876 | */ 877 | public void destroyApplet() { 878 | checkApplet(); 879 | logInfo(LogArea.CONFIG, "destroyApplet() --> %s.destroy()", applet.getClass().getName()); 880 | applet.destroy(); 881 | } 882 | 883 | //--------------------------------separator-------------------------------- 884 | static int ______OVERRIDE; 885 | 886 | /** 887 | * Class loader JavaDoc encourages overriding findClass(String) in derived 888 | * class rather than overriding this method. This does not work for 889 | * loading classes from a JAR. Default implementation of loadClass() is 890 | * able to load a class from a JAR without calling findClass(). 891 | */ 892 | @Override 893 | protected synchronized Class loadClass(String sClassName, boolean bResolve) 894 | throws ClassNotFoundException 895 | { 896 | logDebug(LogArea.CLASS, "LOADING %s (resolve=%b)", sClassName, bResolve); 897 | // Each thread must have THIS class loader set as a context class loader. 898 | // This is required to prevent failure finding a class or resource from 899 | // external JAR requested by a common class loaded from rt.jar. 900 | // The best example is external LnF, explained in steps: 901 | // 1. Application requests 'javax.swing.JOptionPane'. 902 | // 2. THIS class loader passes request to system default class loader 903 | // to load the class from rt.jar. 904 | // 3. The class 'javax.swing.JOptionPane' is loaded by system default class 905 | // loader. 906 | // 4. The class 'javax.swing.JOptionPane' is requesting 'UIDefaults.getUI()' 907 | // for component, which resides in external LnF JAR. 908 | // 5. The class loader which is used to load the requested component is 909 | // current thread context class loader if it is set, otherwise the parent 910 | // thread context class loader, or the default system class loader 911 | // for the top level thread. 912 | // 6. The system class loader is used to load requested component if 913 | // thread context class loader is not set. The default system class loader is 914 | // - sun.misc.Launcher$AppClassLoader - run from file system or JAR 915 | // - com.sun.jnlp.JNLPClassLoader - run from JNLP 916 | // System class loaders cannot find requested component in external 917 | // JAR and throw exception. 918 | // 919 | // Setting thread context class loader for the top thread in invokeMain() 920 | // method is sufficient for most cases. It fails for new threads created 921 | // not from the main thread. 922 | // 923 | // Setting thread context class loader below must be reconsidered 924 | // for specific conditions. 925 | // 926 | // Essential reading: 927 | // - Thread.getContextClassLoader() JavaDoc. 928 | // - http://www.javaworld.com/javaworld/javaqa/2003-06/01-qa-0606-load.html 929 | Thread.currentThread().setContextClassLoader(this); 930 | 931 | Class c = null; 932 | try { 933 | // Step 0. This class is already loaded by system classloader. 934 | if (getClass().getName().equals(sClassName)) { 935 | return JarClassLoader.class; 936 | } 937 | // Step 1. Load from JAR. 938 | if (isLaunchedFromJar()) { 939 | try { 940 | c = findJarClass(sClassName); // Do not simplify! See "finally"! 941 | return c; 942 | } catch (JarClassLoaderException e) { 943 | if (e.getCause() == null) { 944 | logDebug(LogArea.CLASS, "Not found %s in JAR by %s: %s", 945 | sClassName, getClass().getName(), e.getMessage()); 946 | } else { 947 | logDebug(LogArea.CLASS, "Error loading %s in JAR by %s: %s", 948 | sClassName, getClass().getName(), e.getCause()); 949 | } 950 | // keep looking... 951 | } 952 | } 953 | // Step 2. Load by parent (usually system) class loader. 954 | // Call findSystemClass() AFTER attempt to find in a JAR. 955 | // If it called BEFORE it will load class-in-jar using 956 | // SystemClassLoader and "infect" it with SystemClassLoader. 957 | // The SystemClassLoader will be used to load all dependent 958 | // classes. SystemClassLoader will fail to load a class from 959 | // jar-in-jar and to load dll-in-jar. 960 | try { 961 | // No need to call findLoadedClass(sClassName) because it's called inside: 962 | ClassLoader cl = getParent(); 963 | c = cl.loadClass(sClassName); 964 | // System classloader does not define ProtectionDomain->CodeSource - null 965 | logInfo(LogArea.CLASS, "Loaded %s by %s", sClassName, cl.getClass().getName()); 966 | return c; 967 | } catch (ClassNotFoundException e) { 968 | } 969 | // What else? 970 | throw new ClassNotFoundException("Failure to load: " + sClassName); 971 | } finally { 972 | if (c != null && bResolve) { 973 | resolveClass(c); 974 | } 975 | } 976 | } // loadClass() 977 | 978 | /** 979 | * @see java.lang.ClassLoader#findResource(java.lang.String) 980 | * 981 | * @return A URL object for reading the resource, or null if the resource could not be found. 982 | * Example URL: jar:file:C:\...\some.jar!/resources/InnerText.txt 983 | */ 984 | @Override 985 | protected URL findResource(String sName) { 986 | logDebug(LogArea.RESOURCE, "findResource: %s", sName); 987 | if (isLaunchedFromJar()) { 988 | JarEntryInfo inf = findJarEntry(normalizeResourceName(sName)); 989 | if (inf != null) { 990 | URL url = inf.getURL(); 991 | logInfo(LogArea.RESOURCE, "found resource: %s", url); 992 | return url; 993 | } 994 | logInfo(LogArea.RESOURCE, "not found resource: %s", sName); 995 | return null; 996 | } 997 | return super.findResource(sName); 998 | } // findResource() 999 | 1000 | /** 1001 | * @see java.lang.ClassLoader#findResources(java.lang.String) 1002 | * 1003 | * @return An enumeration of {@link java.net.URL URL} objects for 1004 | * the resources 1005 | */ 1006 | @Override 1007 | public Enumeration findResources(String sName) throws IOException { 1008 | logDebug(LogArea.RESOURCE, "getResources: %s", sName); 1009 | if (isLaunchedFromJar()) { 1010 | List lstJarEntry = findJarEntries(normalizeResourceName(sName)); 1011 | List lstURL = new ArrayList(); 1012 | for (JarEntryInfo inf : lstJarEntry) { 1013 | URL url = inf.getURL(); 1014 | if (url != null) { 1015 | lstURL.add(url); 1016 | } 1017 | } 1018 | return Collections.enumeration(lstURL); 1019 | } 1020 | return super.findResources(sName); 1021 | } // findResources() 1022 | 1023 | /** 1024 | * @see java.lang.ClassLoader#findLibrary(java.lang.String) 1025 | * 1026 | * @return The absolute path of the native library. 1027 | */ 1028 | @Override 1029 | protected String findLibrary(String sLib) { 1030 | logDebug(LogArea.NATIVE, "findLibrary: %s", sLib); 1031 | if (isLaunchedFromJar()) { 1032 | JarEntryInfo inf = findJarNativeEntry(sLib); 1033 | if (inf != null) { 1034 | try { 1035 | File file = createTempFile(inf); 1036 | logDebug(LogArea.NATIVE, "Loading native library %s from temp file %s", 1037 | inf.jarEntry, getFilename4Log(file)); 1038 | hsDeleteOnExit.add(file); 1039 | return file.getAbsolutePath(); 1040 | } catch (JarClassLoaderException e) { 1041 | logError(LogArea.NATIVE, "Failure to load native library %s: %s", sLib, e.toString()); 1042 | } 1043 | } 1044 | return null; 1045 | } 1046 | return super.findLibrary(sLib); 1047 | } // findLibrary() 1048 | 1049 | //--------------------------------separator-------------------------------- 1050 | static int ______HELPERS; 1051 | 1052 | /** 1053 | * The default ClassLoader.defineClass() does not create package 1054 | * for the loaded class and leaves it null. Each package referenced by this 1055 | * class loader must be created only once before the 1056 | * ClassLoader.defineClass() call. 1057 | * The base class ClassLoader keeps cache with created packages 1058 | * for reuse. 1059 | * 1060 | * @param sClassName class to load. 1061 | * @throws IllegalArgumentException 1062 | * If package name duplicates an existing package either in this 1063 | * class loader or one of its ancestors. 1064 | */ 1065 | private void definePackage(String sClassName, JarEntryInfo inf) 1066 | throws IllegalArgumentException { 1067 | int pos = sClassName.lastIndexOf('.'); 1068 | String sPackageName = pos > 0 ? sClassName.substring(0, pos) : ""; 1069 | if (getPackage(sPackageName) == null) { 1070 | JarFileInfo jfi = inf.jarFileInfo; 1071 | definePackage(sPackageName, 1072 | jfi.getSpecificationTitle(), jfi.getSpecificationVersion(), 1073 | jfi.getSpecificationVendor(), jfi.getImplementationTitle(), 1074 | jfi.getImplementationVersion(), jfi.getImplementationVendor(), 1075 | jfi.getSealURL()); 1076 | } 1077 | } 1078 | 1079 | /** 1080 | * The system class loader could load resources defined as 1081 | * "com/abc/Foo.txt" or "com\abc\Foo.txt". 1082 | * This method converts path with '\' to default '/' JAR delimiter. 1083 | * 1084 | * @param sName resource name including path. 1085 | * @return normalized resource name. 1086 | */ 1087 | private String normalizeResourceName(String sName) { 1088 | return sName.replace('\\', '/'); 1089 | } 1090 | 1091 | private void chmod777(File file) { 1092 | file.setReadable(true, false); 1093 | file.setWritable(true, false); 1094 | file.setExecutable(true, false); // Unix: allow content for dir, redundant for file 1095 | } 1096 | 1097 | private String getFilename4Log(File file) { 1098 | if (logger != null) { 1099 | try { 1100 | // In form "C:\Documents and Settings\..." 1101 | return file.getCanonicalPath(); 1102 | } catch (IOException e) { 1103 | // In form "C:\DOCUME~1\..." 1104 | return file.getAbsolutePath(); 1105 | } 1106 | } 1107 | return null; 1108 | } 1109 | 1110 | private void checkApplet() { 1111 | if (applet == null) { 1112 | throw new IllegalStateException("Applet is not inited. " + 1113 | "Please call JarClassLoader.initApplet() first."); 1114 | } 1115 | } 1116 | private void logDebug(LogArea area, String sMsg, Object ... obj) { 1117 | log(LogLevel.DEBUG, area, sMsg, obj); 1118 | } 1119 | 1120 | private void logInfo(LogArea area, String sMsg, Object ... obj) { 1121 | log(LogLevel.INFO, area, sMsg, obj); 1122 | } 1123 | 1124 | private void logWarn(LogArea area, String sMsg, Object ... obj) { 1125 | log(LogLevel.WARN, area, sMsg, obj); 1126 | } 1127 | 1128 | private void logError(LogArea area, String sMsg, Object ... obj) { 1129 | log(LogLevel.ERROR, area, sMsg, obj); 1130 | } 1131 | 1132 | private void log(LogLevel level, LogArea area, String sMsg, Object ... obj) { 1133 | if (level.ordinal() <= logLevel.ordinal()) { 1134 | if (hsLogArea.contains(LogArea.ALL) || hsLogArea.contains(area)) { 1135 | logger.printf("JarClassLoader-" + level + ": " + sMsg + "\n", obj); 1136 | } 1137 | } 1138 | if (!bLogConsole && level == LogLevel.ERROR) { // repeat to console 1139 | System.out.printf("JarClassLoader-" + level + ": " + sMsg + "\n", obj); 1140 | } 1141 | } 1142 | 1143 | /** 1144 | * Inner class with JAR file information. 1145 | */ 1146 | private static class JarFileInfo { 1147 | JarFile jarFile; // this is the essence of JarFileInfo wrapper 1148 | String simpleName; // accumulated for logging like: "topJar!childJar!kidJar" 1149 | File fileDeleteOnExit; 1150 | Manifest mf; // required for package creation 1151 | ProtectionDomain pd; 1152 | 1153 | /** 1154 | * @param jarFile 1155 | * Never null. 1156 | * @param simpleName 1157 | * Used for logging. Never null. 1158 | * @param jarFileParent 1159 | * Used to make simpleName for logging. Null for top level JAR. 1160 | * @param fileDeleteOnExit 1161 | * Used only to delete temporary file on exit. 1162 | * Could be null if not required to delete on exit (top level JAR) 1163 | * @throws JarClassLoaderException 1164 | */ 1165 | JarFileInfo(JarFile jarFile, String simpleName, JarFileInfo jarFileParent, 1166 | ProtectionDomain pd, File fileDeleteOnExit) 1167 | { 1168 | this.simpleName = (jarFileParent == null ? "" : jarFileParent.simpleName + "!") + simpleName; 1169 | this.jarFile = jarFile; 1170 | this.pd = pd; 1171 | this.fileDeleteOnExit = fileDeleteOnExit; 1172 | try { 1173 | this.mf = jarFile.getManifest(); // 'null' if META-INF directory is missing 1174 | } catch (IOException e) { 1175 | // Ignore and create blank manifest 1176 | } 1177 | if (this.mf == null) { 1178 | this.mf = new Manifest(); 1179 | } 1180 | } 1181 | String getSpecificationTitle() { 1182 | return mf.getMainAttributes().getValue(Name.SPECIFICATION_TITLE); 1183 | } 1184 | String getSpecificationVersion() { 1185 | return mf.getMainAttributes().getValue(Name.SPECIFICATION_VERSION); 1186 | } 1187 | String getSpecificationVendor() { 1188 | return mf.getMainAttributes().getValue(Name.SPECIFICATION_VENDOR); 1189 | } 1190 | String getImplementationTitle() { 1191 | return mf.getMainAttributes().getValue(Name.IMPLEMENTATION_TITLE); 1192 | } 1193 | String getImplementationVersion() { 1194 | return mf.getMainAttributes().getValue(Name.IMPLEMENTATION_VERSION); 1195 | } 1196 | String getImplementationVendor() { 1197 | return mf.getMainAttributes().getValue(Name.IMPLEMENTATION_VENDOR); 1198 | } 1199 | URL getSealURL() { 1200 | String seal = mf.getMainAttributes().getValue(Name.SEALED); 1201 | if (seal != null) { 1202 | try { 1203 | return new URL(seal); 1204 | } catch (MalformedURLException e) { 1205 | // Ignore, will return null 1206 | } 1207 | } 1208 | return null; 1209 | } 1210 | } // inner class JarFileInfo 1211 | 1212 | /** 1213 | * Inner class with JAR entry information. Keeps JAR file and entry object. 1214 | */ 1215 | private static class JarEntryInfo { 1216 | JarFileInfo jarFileInfo; 1217 | JarEntry jarEntry; 1218 | JarEntryInfo(JarFileInfo jarFileInfo, JarEntry jarEntry) { 1219 | this.jarFileInfo = jarFileInfo; 1220 | this.jarEntry = jarEntry; 1221 | } 1222 | URL getURL() { // used in findResource() and findResources() 1223 | try { 1224 | return new URL("jar:file:" + jarFileInfo.jarFile.getName() + "!/" + jarEntry); 1225 | } catch (MalformedURLException e) { 1226 | return null; 1227 | } 1228 | } 1229 | String getName() { // used in createTempFile() and loadJar() 1230 | return jarEntry.getName().replace('/', '_'); 1231 | } 1232 | @Override 1233 | public String toString() { 1234 | return "JAR: " + jarFileInfo.jarFile.getName() + " ENTRY: " + jarEntry; 1235 | } 1236 | /** 1237 | * Read JAR entry and returns byte array of this JAR entry. This is 1238 | * a helper method to load JAR entry into temporary file. 1239 | * 1240 | * @param inf JAR entry information object 1241 | * @return byte array for the specified JAR entry 1242 | * @throws JarClassLoaderException 1243 | */ 1244 | byte[] getJarBytes() throws JarClassLoaderException { 1245 | DataInputStream dis = null; 1246 | byte[] a_by = null; 1247 | try { 1248 | long lSize = jarEntry.getSize(); 1249 | if (lSize <= 0 || lSize >= Integer.MAX_VALUE) { 1250 | throw new JarClassLoaderException( 1251 | "Invalid size " + lSize + " for entry " + jarEntry); 1252 | } 1253 | a_by = new byte[(int)lSize]; 1254 | InputStream is = jarFileInfo.jarFile.getInputStream(jarEntry); 1255 | dis = new DataInputStream(is); 1256 | dis.readFully(a_by); 1257 | } catch (IOException e) { 1258 | throw new JarClassLoaderException(null, e); 1259 | } finally { 1260 | if (dis != null) { 1261 | try { 1262 | dis.close(); 1263 | } catch (IOException e) { 1264 | } 1265 | } 1266 | } 1267 | return a_by; 1268 | } 1269 | } // inner class JarEntryInfo 1270 | 1271 | /** 1272 | * Inner class to handle JarClassLoader exceptions. 1273 | */ 1274 | @SuppressWarnings("serial") 1275 | private static class JarClassLoaderException extends Exception { 1276 | JarClassLoaderException(String sMsg) { 1277 | super(sMsg); 1278 | } 1279 | JarClassLoaderException(String sMsg, Throwable eCause) { 1280 | super(sMsg, eCause); 1281 | } 1282 | String getMessageAll() { 1283 | StringBuilder sb = new StringBuilder(); 1284 | for (Throwable e = this; e != null; e = e.getCause()) { 1285 | if (sb.length() > 0) { 1286 | sb.append(" / "); 1287 | } 1288 | String sMsg = e.getMessage(); 1289 | if (sMsg == null || sMsg.length() == 0) { 1290 | sMsg = e.getClass().getSimpleName(); 1291 | } 1292 | sb.append(sMsg); 1293 | } 1294 | return sb.toString(); 1295 | } 1296 | } // inner class JarClassLoaderException 1297 | 1298 | } // class JarClassLoader 1299 | -------------------------------------------------------------------------------- /src/main/java/net/vaemendis/hccd/CardGenerator.java: -------------------------------------------------------------------------------- 1 | package net.vaemendis.hccd; 2 | 3 | import com.samskivert.mustache.Mustache; 4 | import com.samskivert.mustache.Template; 5 | import org.apache.commons.csv.CSVFormat; 6 | import org.apache.commons.csv.CSVRecord; 7 | import org.apache.commons.io.FileUtils; 8 | import org.apache.commons.io.FilenameUtils; 9 | import org.apache.commons.io.input.BOMInputStream; 10 | import org.jsoup.Jsoup; 11 | import org.jsoup.nodes.Document; 12 | 13 | import java.io.*; 14 | import java.nio.charset.StandardCharsets; 15 | import java.util.ArrayList; 16 | import java.util.Iterator; 17 | import java.util.List; 18 | 19 | public class CardGenerator { 20 | 21 | private static final String GENERATED_SUFFIX = "-GENERATED"; 22 | 23 | public static void generateCards(WatchedFiles projectFiles, UserConfiguration config) throws IOException { 24 | Hccd.log("Generating card sheet file..."); 25 | if (!projectFiles.getCsvFile().isFile()) { 26 | Hccd.log("CSV file does not exist. Generation aborted."); 27 | } else { 28 | String root = FilenameUtils.getBaseName(projectFiles.getHtmlFile().getName()); 29 | File target = new File(projectFiles.getParentDir(), root + GENERATED_SUFFIX + ".html"); 30 | 31 | String html = FileUtils.readFileToString(projectFiles.getHtmlFile()); 32 | Document doc = Jsoup.parse(html); 33 | String card = doc.select(".card").first().outerHtml(); 34 | Template template = Mustache.compiler().escapeHTML(false).defaultValue("[NOT FOUND]").compile(card); 35 | Iterable records = getData(projectFiles.getCsvFile(), config); 36 | 37 | // filter cards 38 | List filter = config.getCardFilter(); 39 | List recordList = new ArrayList<>(); 40 | int index = 1; 41 | for (CSVRecord record : records) { 42 | if (filter.size() == 0 || filter.contains(index)) { 43 | recordList.add(record); 44 | } 45 | index++; 46 | } 47 | 48 | 49 | 50 | StringBuilder sb = new StringBuilder(); 51 | writeHeader(sb, projectFiles.getCssFile().getName()); 52 | 53 | Iterator recordIter = recordList.iterator(); 54 | int rows = config.getGridRowNumber(); 55 | int cols = config.getGridColNumber(); 56 | 57 | recordLoop: 58 | { 59 | while (recordIter.hasNext()) { 60 | sb.append(""); 61 | for (int i = 0; i < rows; i++) { 62 | sb.append(""); 63 | for (int j = 0; j < cols; j++) { 64 | if (recordIter.hasNext()) { 65 | sb.append(""); 68 | } else { 69 | sb.append("
"); 66 | sb.append(template.execute(recordIter.next().toMap())); 67 | sb.append("
"); 70 | break recordLoop; 71 | } 72 | } 73 | sb.append(""); 74 | } 75 | sb.append(""); 76 | } 77 | } 78 | writeFooter(sb); 79 | 80 | FileUtils.writeStringToFile(target, sb.toString()); 81 | Hccd.log("Card sheet file written to " + target.getPath()); 82 | } 83 | } 84 | 85 | private static void writeHeader(StringBuilder sb, String cssFilePath) { 86 | sb.append("" + 87 | "" + 88 | "" + 89 | "" + 90 | "" + 91 | "" + 92 | "" + 93 | "\n"); 113 | } 114 | 115 | private static void writeFooter(StringBuilder sb) { 116 | sb.append(""); 117 | 118 | } 119 | 120 | private static List getData(File csvFile, UserConfiguration config) throws IOException { 121 | List recordList = new ArrayList<>(); 122 | Iterable records; 123 | if (config.useExcelFormat()) { 124 | try(Reader reader = new InputStreamReader(new BOMInputStream(new FileInputStream(csvFile)), StandardCharsets.UTF_8)){ 125 | records = CSVFormat.EXCEL.withDelimiter(config.getDelimiter()).withFirstRecordAsHeader().parse(reader); 126 | for (CSVRecord record : records) { 127 | recordList.add(record); 128 | } 129 | } 130 | }else{ 131 | try (Reader in = new FileReader(csvFile)){ 132 | records = CSVFormat.RFC4180.withDelimiter(config.getDelimiter()).withFirstRecordAsHeader().parse(in); 133 | for (CSVRecord record : records) { 134 | recordList.add(record); 135 | } 136 | } 137 | } 138 | return recordList; 139 | } 140 | 141 | } 142 | -------------------------------------------------------------------------------- /src/main/java/net/vaemendis/hccd/ErrorDialog.java: -------------------------------------------------------------------------------- 1 | package net.vaemendis.hccd; 2 | 3 | import javax.swing.*; 4 | import javax.swing.border.BevelBorder; 5 | import javax.swing.border.EmptyBorder; 6 | import java.awt.*; 7 | import java.awt.event.*; 8 | import java.io.IOException; 9 | import java.io.PrintWriter; 10 | import java.io.StringWriter; 11 | 12 | public class ErrorDialog extends JDialog { 13 | 14 | private final JPanel contentPanel = new JPanel(); 15 | 16 | public ErrorDialog(Throwable throwable) { 17 | setModal(true); 18 | setTitle("An error occured"); 19 | setBounds(100, 100, 450, 300); 20 | getContentPane().setLayout(new BorderLayout()); 21 | contentPanel.setBorder(new EmptyBorder(10, 10, 10, 10)); 22 | getContentPane().add(contentPanel, BorderLayout.CENTER); 23 | contentPanel.setLayout(new BorderLayout(0, 0)); 24 | 25 | JPanel panel = new JPanel(); 26 | contentPanel.add(panel, BorderLayout.NORTH); 27 | panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); 28 | 29 | JLabel lblNewLabel = new JLabel("An unexpected error occured"); 30 | panel.add(lblNewLabel); 31 | 32 | Component verticalStrut1 = Box.createVerticalStrut(20); 33 | verticalStrut1.setMaximumSize(new Dimension(32767, 5)); 34 | verticalStrut1.setMinimumSize(new Dimension(0, 5)); 35 | verticalStrut1.setPreferredSize(new Dimension(0, 5)); 36 | panel.add(verticalStrut1); 37 | 38 | Component verticalStrut2 = Box.createVerticalStrut(20); 39 | verticalStrut2.setPreferredSize(new Dimension(0, 10)); 40 | verticalStrut2.setMinimumSize(new Dimension(0, 10)); 41 | verticalStrut2.setMaximumSize(new Dimension(32767, 10)); 42 | panel.add(verticalStrut2); 43 | 44 | JTextArea textArea = new JTextArea(); 45 | textArea.setEditable(false); 46 | textArea.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null)); 47 | textArea.setText(getStack(throwable)); 48 | textArea.setCaretPosition(0); 49 | contentPanel.add(new JScrollPane(textArea), BorderLayout.CENTER); 50 | 51 | JPanel buttonPane = new JPanel(); 52 | buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); 53 | getContentPane().add(buttonPane, BorderLayout.SOUTH); 54 | 55 | JButton okButton = new JButton("Close"); 56 | okButton.addActionListener(e -> System.exit(1)); 57 | okButton.setPreferredSize(new Dimension(70, 25)); 58 | okButton.setMinimumSize(new Dimension(70, 25)); 59 | okButton.setMaximumSize(new Dimension(70, 25)); 60 | okButton.setActionCommand("OK"); 61 | buttonPane.add(okButton); 62 | getRootPane().setDefaultButton(okButton); 63 | 64 | } 65 | 66 | public static void show(Component parent, Throwable t) { 67 | ErrorDialog dialog = new ErrorDialog(t); 68 | try { 69 | dialog.setIconImages(Tools.getApplicationIcons()); 70 | } catch (IOException e) { 71 | // don't really care if it fails 72 | e.printStackTrace(); 73 | } 74 | 75 | dialog.addWindowListener(new WindowAdapter() { 76 | @Override 77 | public void windowClosing(WindowEvent e) { 78 | System.exit(1); 79 | } 80 | }); 81 | dialog.setLocationRelativeTo(parent); 82 | dialog.setVisible(true); 83 | } 84 | 85 | private String getStack(Throwable throwable) { 86 | StringWriter sw = new StringWriter(); 87 | PrintWriter pw = new PrintWriter(sw); 88 | throwable.printStackTrace(pw); 89 | return sw.toString(); 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/net/vaemendis/hccd/FileDrop.java: -------------------------------------------------------------------------------- 1 | package net.vaemendis.hccd; 2 | 3 | import java.awt.datatransfer.DataFlavor; 4 | import java.io.*; 5 | 6 | /** 7 | * This class makes it easy to drag and drop files from the operating 8 | * system to a Java program. Any java.awt.Component can be 9 | * dropped onto, but only javax.swing.JComponents will indicate 10 | * the drop event with a changed border. 11 | *

12 | * To use this class, construct a new FileDrop by passing 13 | * it the target component and a Listener to receive notification 14 | * when file(s) have been dropped. Here is an example: 15 | *

16 | *

 17 |  *      JPanel myPanel = new JPanel();
 18 |  *      new FileDrop( myPanel, new FileDrop.Listener()
 19 |  *      {   public void filesDropped( java.io.File[] files )
 20 |  *          {
 21 |  *              // handle file drop
 22 |  *              ...
 23 |  *          }   // end filesDropped
 24 |  *      }); // end FileDrop.Listener
 25 |  * 
26 | *

27 | * You can specify the border that will appear when files are being dragged by 28 | * calling the constructor with a javax.swing.border.Border. Only 29 | * JComponents will show any indication with a border. 30 | *

31 | * You can turn on some debugging features by passing a PrintStream 32 | * object (such as System.out) into the full constructor. A null 33 | * value will result in no extra debugging information being output. 34 | *

35 | * 36 | *

I'm releasing this code into the Public Domain. Enjoy. 37 | *

38 | *

Original author: Robert Harder, rharder@usa.net

39 | *

2007-09-12 Nathan Blomquist -- Linux (KDE/Gnome) support added.

40 | * 41 | * @author Robert Harder 42 | * @author rharder@users.sf.net 43 | * @version 1.0.1 44 | */ 45 | 46 | @SuppressWarnings({"unused","rawtypes","unchecked"}) 47 | public class FileDrop 48 | { 49 | private transient javax.swing.border.Border normalBorder; 50 | private transient java.awt.dnd.DropTargetListener dropListener; 51 | 52 | 53 | /** Discover if the running JVM is modern enough to have drag and drop. */ 54 | private static Boolean supportsDnD; 55 | 56 | // Default border color 57 | private static java.awt.Color defaultBorderColor = new java.awt.Color( 0f, 0f, 1f, 0.25f ); 58 | 59 | /** 60 | * Constructs a {@link FileDrop} with a default light-blue border 61 | * and, if c is a {@link java.awt.Container}, recursively 62 | * sets all elements contained within as drop targets, though only 63 | * the top level container will change borders. 64 | * 65 | * @param c Component on which files will be dropped. 66 | * @param listener Listens for filesDropped. 67 | * @since 1.0 68 | */ 69 | public FileDrop( 70 | final java.awt.Component c, 71 | final Listener listener ) 72 | { this( null, // Logging stream 73 | c, // Drop target 74 | javax.swing.BorderFactory.createMatteBorder( 2, 2, 2, 2, defaultBorderColor ), // Drag border 75 | true, // Recursive 76 | listener ); 77 | } // end constructor 78 | 79 | 80 | 81 | 82 | /** 83 | * Constructor with a default border and the option to recursively set drop targets. 84 | * If your component is a java.awt.Container, then each of its children 85 | * components will also listen for drops, though only the parent will change borders. 86 | * 87 | * @param c Component on which files will be dropped. 88 | * @param recursive Recursively set children as drop targets. 89 | * @param listener Listens for filesDropped. 90 | * @since 1.0 91 | */ 92 | public FileDrop( 93 | final java.awt.Component c, 94 | final boolean recursive, 95 | final Listener listener ) 96 | { this( null, // Logging stream 97 | c, // Drop target 98 | javax.swing.BorderFactory.createMatteBorder( 2, 2, 2, 2, defaultBorderColor ), // Drag border 99 | recursive, // Recursive 100 | listener ); 101 | } // end constructor 102 | 103 | 104 | /** 105 | * Constructor with a default border and debugging optionally turned on. 106 | * With Debugging turned on, more status messages will be displayed to 107 | * out. A common way to use this constructor is with 108 | * System.out or System.err. A null value for 109 | * the parameter out will result in no debugging output. 110 | * 111 | * @param out PrintStream to record debugging info or null for no debugging. 112 | * @param c Component on which files will be dropped. 113 | * @param listener Listens for filesDropped. 114 | * @since 1.0 115 | */ 116 | public FileDrop( 117 | final PrintStream out, 118 | final java.awt.Component c, 119 | final Listener listener ) 120 | { this( out, // Logging stream 121 | c, // Drop target 122 | javax.swing.BorderFactory.createMatteBorder( 2, 2, 2, 2, defaultBorderColor ), 123 | false, // Recursive 124 | listener ); 125 | } // end constructor 126 | 127 | 128 | 129 | /** 130 | * Constructor with a default border, debugging optionally turned on 131 | * and the option to recursively set drop targets. 132 | * If your component is a java.awt.Container, then each of its children 133 | * components will also listen for drops, though only the parent will change borders. 134 | * With Debugging turned on, more status messages will be displayed to 135 | * out. A common way to use this constructor is with 136 | * System.out or System.err. A null value for 137 | * the parameter out will result in no debugging output. 138 | * 139 | * @param out PrintStream to record debugging info or null for no debugging. 140 | * @param c Component on which files will be dropped. 141 | * @param recursive Recursively set children as drop targets. 142 | * @param listener Listens for filesDropped. 143 | * @since 1.0 144 | */ 145 | public FileDrop( 146 | final PrintStream out, 147 | final java.awt.Component c, 148 | final boolean recursive, 149 | final Listener listener) 150 | { this( out, // Logging stream 151 | c, // Drop target 152 | javax.swing.BorderFactory.createMatteBorder( 2, 2, 2, 2, defaultBorderColor ), // Drag border 153 | recursive, // Recursive 154 | listener ); 155 | } // end constructor 156 | 157 | 158 | 159 | 160 | /** 161 | * Constructor with a specified border 162 | * 163 | * @param c Component on which files will be dropped. 164 | * @param dragBorder Border to use on JComponent when dragging occurs. 165 | * @param listener Listens for filesDropped. 166 | * @since 1.0 167 | */ 168 | public FileDrop( 169 | final java.awt.Component c, 170 | final javax.swing.border.Border dragBorder, 171 | final Listener listener) 172 | { this( 173 | null, // Logging stream 174 | c, // Drop target 175 | dragBorder, // Drag border 176 | false, // Recursive 177 | listener ); 178 | } // end constructor 179 | 180 | 181 | 182 | 183 | /** 184 | * Constructor with a specified border and the option to recursively set drop targets. 185 | * If your component is a java.awt.Container, then each of its children 186 | * components will also listen for drops, though only the parent will change borders. 187 | * 188 | * @param c Component on which files will be dropped. 189 | * @param dragBorder Border to use on JComponent when dragging occurs. 190 | * @param recursive Recursively set children as drop targets. 191 | * @param listener Listens for filesDropped. 192 | * @since 1.0 193 | */ 194 | public FileDrop( 195 | final java.awt.Component c, 196 | final javax.swing.border.Border dragBorder, 197 | final boolean recursive, 198 | final Listener listener) 199 | { this( 200 | null, 201 | c, 202 | dragBorder, 203 | recursive, 204 | listener ); 205 | } // end constructor 206 | 207 | 208 | 209 | /** 210 | * Constructor with a specified border and debugging optionally turned on. 211 | * With Debugging turned on, more status messages will be displayed to 212 | * out. A common way to use this constructor is with 213 | * System.out or System.err. A null value for 214 | * the parameter out will result in no debugging output. 215 | * 216 | * @param out PrintStream to record debugging info or null for no debugging. 217 | * @param c Component on which files will be dropped. 218 | * @param dragBorder Border to use on JComponent when dragging occurs. 219 | * @param listener Listens for filesDropped. 220 | * @since 1.0 221 | */ 222 | public FileDrop( 223 | final PrintStream out, 224 | final java.awt.Component c, 225 | final javax.swing.border.Border dragBorder, 226 | final Listener listener) 227 | { this( 228 | out, // Logging stream 229 | c, // Drop target 230 | dragBorder, // Drag border 231 | false, // Recursive 232 | listener ); 233 | } // end constructor 234 | 235 | 236 | 237 | 238 | 239 | /** 240 | * Full constructor with a specified border and debugging optionally turned on. 241 | * With Debugging turned on, more status messages will be displayed to 242 | * out. A common way to use this constructor is with 243 | * System.out or System.err. A null value for 244 | * the parameter out will result in no debugging output. 245 | * 246 | * @param out PrintStream to record debugging info or null for no debugging. 247 | * @param c Component on which files will be dropped. 248 | * @param dragBorder Border to use on JComponent when dragging occurs. 249 | * @param recursive Recursively set children as drop targets. 250 | * @param listener Listens for filesDropped. 251 | * @since 1.0 252 | */ 253 | public FileDrop( 254 | final PrintStream out, 255 | final java.awt.Component c, 256 | final javax.swing.border.Border dragBorder, 257 | final boolean recursive, 258 | final Listener listener) 259 | { 260 | 261 | if( supportsDnD() ) 262 | { // Make a drop listener 263 | dropListener = new java.awt.dnd.DropTargetListener() 264 | { public void dragEnter( java.awt.dnd.DropTargetDragEvent evt ) 265 | { log( out, "FileDrop: dragEnter event." ); 266 | 267 | // Is this an acceptable drag event? 268 | if( isDragOk( out, evt ) ) 269 | { 270 | // If it's a Swing component, set its border 271 | if( c instanceof javax.swing.JComponent ) 272 | { javax.swing.JComponent jc = (javax.swing.JComponent) c; 273 | normalBorder = jc.getBorder(); 274 | log( out, "FileDrop: normal border saved." ); 275 | jc.setBorder( dragBorder ); 276 | log( out, "FileDrop: drag border set." ); 277 | } // end if: JComponent 278 | 279 | // Acknowledge that it's okay to enter 280 | //evt.acceptDrag( java.awt.dnd.DnDConstants.ACTION_COPY_OR_MOVE ); 281 | evt.acceptDrag( java.awt.dnd.DnDConstants.ACTION_COPY ); 282 | log( out, "FileDrop: event accepted." ); 283 | } // end if: drag ok 284 | else 285 | { // Reject the drag event 286 | evt.rejectDrag(); 287 | log( out, "FileDrop: event rejected." ); 288 | } // end else: drag not ok 289 | } // end dragEnter 290 | 291 | public void dragOver( java.awt.dnd.DropTargetDragEvent evt ) 292 | { // This is called continually as long as the mouse is 293 | // over the drag target. 294 | } // end dragOver 295 | 296 | public void drop( java.awt.dnd.DropTargetDropEvent evt ) 297 | { log( out, "FileDrop: drop event." ); 298 | try 299 | { // Get whatever was dropped 300 | java.awt.datatransfer.Transferable tr = evt.getTransferable(); 301 | 302 | // Is it a file list? 303 | if (tr.isDataFlavorSupported (DataFlavor.javaFileListFlavor)) 304 | { 305 | // Say we'll take it. 306 | //evt.acceptDrop ( java.awt.dnd.DnDConstants.ACTION_COPY_OR_MOVE ); 307 | evt.acceptDrop ( java.awt.dnd.DnDConstants.ACTION_COPY ); 308 | log( out, "FileDrop: file list accepted." ); 309 | 310 | // Get a useful list 311 | java.util.List fileList = (java.util.List) 312 | tr.getTransferData(DataFlavor.javaFileListFlavor); 313 | java.util.Iterator iterator = fileList.iterator(); 314 | 315 | // Convert list to array 316 | File[] filesTemp = new File[ fileList.size() ]; 317 | fileList.toArray( filesTemp ); 318 | final File[] files = filesTemp; 319 | 320 | // Alert listener to drop. 321 | if( listener != null ) 322 | listener.filesDropped( files ); 323 | 324 | // Mark that drop is completed. 325 | evt.getDropTargetContext().dropComplete(true); 326 | log( out, "FileDrop: drop complete." ); 327 | } // end if: file list 328 | else // this section will check for a reader flavor. 329 | { 330 | // Thanks, Nathan! 331 | // BEGIN 2007-09-12 Nathan Blomquist -- Linux (KDE/Gnome) support added. 332 | DataFlavor[] flavors = tr.getTransferDataFlavors(); 333 | boolean handled = false; 334 | for (int zz = 0; zz < flavors.length; zz++) { 335 | if (flavors[zz].isRepresentationClassReader()) { 336 | // Say we'll take it. 337 | //evt.acceptDrop ( java.awt.dnd.DnDConstants.ACTION_COPY_OR_MOVE ); 338 | evt.acceptDrop(java.awt.dnd.DnDConstants.ACTION_COPY); 339 | log(out, "FileDrop: reader accepted."); 340 | 341 | Reader reader = flavors[zz].getReaderForText(tr); 342 | 343 | BufferedReader br = new BufferedReader(reader); 344 | 345 | if(listener != null) 346 | listener.filesDropped(createFileArray(br, out)); 347 | 348 | // Mark that drop is completed. 349 | evt.getDropTargetContext().dropComplete(true); 350 | log(out, "FileDrop: drop complete."); 351 | handled = true; 352 | break; 353 | } 354 | } 355 | if(!handled){ 356 | log( out, "FileDrop: not a file list or reader - abort." ); 357 | evt.rejectDrop(); 358 | } 359 | // END 2007-09-12 Nathan Blomquist -- Linux (KDE/Gnome) support added. 360 | } // end else: not a file list 361 | } // end try 362 | catch ( IOException io) 363 | { log( out, "FileDrop: IOException - abort:" ); 364 | io.printStackTrace( out ); 365 | evt.rejectDrop(); 366 | } // end catch IOException 367 | catch (java.awt.datatransfer.UnsupportedFlavorException ufe) 368 | { log( out, "FileDrop: UnsupportedFlavorException - abort:" ); 369 | ufe.printStackTrace( out ); 370 | evt.rejectDrop(); 371 | } // end catch: UnsupportedFlavorException 372 | finally 373 | { 374 | // If it's a Swing component, reset its border 375 | if( c instanceof javax.swing.JComponent ) 376 | { javax.swing.JComponent jc = (javax.swing.JComponent) c; 377 | jc.setBorder( normalBorder ); 378 | log( out, "FileDrop: normal border restored." ); 379 | } // end if: JComponent 380 | } // end finally 381 | } // end drop 382 | 383 | public void dragExit( java.awt.dnd.DropTargetEvent evt ) 384 | { log( out, "FileDrop: dragExit event." ); 385 | // If it's a Swing component, reset its border 386 | if( c instanceof javax.swing.JComponent ) 387 | { javax.swing.JComponent jc = (javax.swing.JComponent) c; 388 | jc.setBorder( normalBorder ); 389 | log( out, "FileDrop: normal border restored." ); 390 | } // end if: JComponent 391 | } // end dragExit 392 | 393 | public void dropActionChanged( java.awt.dnd.DropTargetDragEvent evt ) 394 | { log( out, "FileDrop: dropActionChanged event." ); 395 | // Is this an acceptable drag event? 396 | if( isDragOk( out, evt ) ) 397 | { //evt.acceptDrag( java.awt.dnd.DnDConstants.ACTION_COPY_OR_MOVE ); 398 | evt.acceptDrag( java.awt.dnd.DnDConstants.ACTION_COPY ); 399 | log( out, "FileDrop: event accepted." ); 400 | } // end if: drag ok 401 | else 402 | { evt.rejectDrag(); 403 | log( out, "FileDrop: event rejected." ); 404 | } // end else: drag not ok 405 | } // end dropActionChanged 406 | }; // end DropTargetListener 407 | 408 | // Make the component (and possibly children) drop targets 409 | makeDropTarget( out, c, recursive ); 410 | } // end if: supports dnd 411 | else 412 | { log( out, "FileDrop: Drag and drop is not supported with this JVM" ); 413 | } // end else: does not support DnD 414 | } // end constructor 415 | 416 | 417 | public static boolean supportsDnD() 418 | { // Static Boolean 419 | if( supportsDnD == null ) 420 | { 421 | boolean support = false; 422 | try 423 | { Class arbitraryDndClass = Class.forName( "java.awt.dnd.DnDConstants" ); 424 | support = true; 425 | } // end try 426 | catch( Exception e ) 427 | { support = false; 428 | } // end catch 429 | supportsDnD = new Boolean( support ); 430 | } // end if: first time through 431 | return supportsDnD.booleanValue(); 432 | } // end supportsDnD 433 | 434 | 435 | // BEGIN 2007-09-12 Nathan Blomquist -- Linux (KDE/Gnome) support added. 436 | private static String ZERO_CHAR_STRING = "" + (char)0; 437 | private static File[] createFileArray(BufferedReader bReader, PrintStream out) 438 | { 439 | try { 440 | java.util.List list = new java.util.ArrayList(); 441 | String line = null; 442 | while ((line = bReader.readLine()) != null) { 443 | try { 444 | // kde seems to append a 0 char to the end of the reader 445 | if(ZERO_CHAR_STRING.equals(line)) continue; 446 | 447 | File file = new File(new java.net.URI(line)); 448 | list.add(file); 449 | } catch (Exception ex) { 450 | log(out, "Error with " + line + ": " + ex.getMessage()); 451 | } 452 | } 453 | 454 | return (File[]) list.toArray(new File[list.size()]); 455 | } catch (IOException ex) { 456 | log(out, "FileDrop: IOException"); 457 | } 458 | return new File[0]; 459 | } 460 | // END 2007-09-12 Nathan Blomquist -- Linux (KDE/Gnome) support added. 461 | 462 | /** add a new drop target */ 463 | public void makeDropTarget(final java.awt.Component c) { 464 | makeDropTarget(null, c, true); 465 | } 466 | 467 | private void makeDropTarget( final PrintStream out, final java.awt.Component c, boolean recursive ) 468 | { 469 | // Make drop target 470 | final java.awt.dnd.DropTarget dt = new java.awt.dnd.DropTarget(); 471 | try 472 | { dt.addDropTargetListener( dropListener ); 473 | } // end try 474 | catch( java.util.TooManyListenersException e ) 475 | { e.printStackTrace(); 476 | log(out, "FileDrop: Drop will not work due to previous error. Do you have another listener attached?" ); 477 | } // end catch 478 | 479 | // Listen for hierarchy changes and remove the drop target when the parent gets cleared out. 480 | c.addHierarchyListener( new java.awt.event.HierarchyListener() 481 | { public void hierarchyChanged( java.awt.event.HierarchyEvent evt ) 482 | { log( out, "FileDrop: Hierarchy changed." ); 483 | java.awt.Component parent = c.getParent(); 484 | if( parent == null ) 485 | { c.setDropTarget( null ); 486 | log( out, "FileDrop: Drop target cleared from component." ); 487 | } // end if: null parent 488 | else 489 | { new java.awt.dnd.DropTarget(c, dropListener); 490 | log( out, "FileDrop: Drop target added to component." ); 491 | } // end else: parent not null 492 | } // end hierarchyChanged 493 | }); // end hierarchy listener 494 | if( c.getParent() != null ) 495 | new java.awt.dnd.DropTarget(c, dropListener); 496 | 497 | if( recursive && (c instanceof java.awt.Container ) ) 498 | { 499 | // Get the container 500 | java.awt.Container cont = (java.awt.Container) c; 501 | 502 | // Get it's components 503 | java.awt.Component[] comps = cont.getComponents(); 504 | 505 | // Set it's components as listeners also 506 | for( int i = 0; i < comps.length; i++ ) 507 | makeDropTarget( out, comps[i], recursive ); 508 | } // end if: recursively set components as listener 509 | } // end dropListener 510 | 511 | 512 | 513 | /** Determine if the dragged data is a file list. */ 514 | private boolean isDragOk( final PrintStream out, final java.awt.dnd.DropTargetDragEvent evt ) 515 | { boolean ok = false; 516 | 517 | // Get data flavors being dragged 518 | DataFlavor[] flavors = evt.getCurrentDataFlavors(); 519 | 520 | // See if any of the flavors are a file list 521 | int i = 0; 522 | while( !ok && i < flavors.length ) 523 | { 524 | // BEGIN 2007-09-12 Nathan Blomquist -- Linux (KDE/Gnome) support added. 525 | // Is the flavor a file list? 526 | final DataFlavor curFlavor = flavors[i]; 527 | if( curFlavor.equals( DataFlavor.javaFileListFlavor ) || 528 | curFlavor.isRepresentationClassReader()){ 529 | ok = true; 530 | } 531 | // END 2007-09-12 Nathan Blomquist -- Linux (KDE/Gnome) support added. 532 | i++; 533 | } // end while: through flavors 534 | 535 | // If logging is enabled, show data flavors 536 | if( out != null ) 537 | { if( flavors.length == 0 ) 538 | log( out, "FileDrop: no data flavors." ); 539 | for( i = 0; i < flavors.length; i++ ) 540 | log( out, flavors[i].toString() ); 541 | } // end if: logging enabled 542 | 543 | return ok; 544 | } // end isDragOk 545 | 546 | 547 | /** Outputs message to out if it's not null. */ 548 | private static void log( PrintStream out, String message ) 549 | { // Log message if requested 550 | if( out != null ) 551 | out.println( message ); 552 | } // end log 553 | 554 | 555 | 556 | 557 | /** 558 | * Removes the drag-and-drop hooks from the component and optionally 559 | * from the all children. You should call this if you add and remove 560 | * components after you've set up the drag-and-drop. 561 | * This will recursively unregister all components contained within 562 | * c if c is a {@link java.awt.Container}. 563 | * 564 | * @param c The component to unregister as a drop target 565 | * @since 1.0 566 | */ 567 | public static boolean remove( java.awt.Component c) 568 | { return remove( null, c, true ); 569 | } // end remove 570 | 571 | 572 | 573 | /** 574 | * Removes the drag-and-drop hooks from the component and optionally 575 | * from the all children. You should call this if you add and remove 576 | * components after you've set up the drag-and-drop. 577 | * 578 | * @param out Optional {@link PrintStream} for logging drag and drop messages 579 | * @param c The component to unregister 580 | * @param recursive Recursively unregister components within a container 581 | * @since 1.0 582 | */ 583 | public static boolean remove( PrintStream out, java.awt.Component c, boolean recursive ) 584 | { // Make sure we support dnd. 585 | if( supportsDnD() ) 586 | { log( out, "FileDrop: Removing drag-and-drop hooks." ); 587 | c.setDropTarget( null ); 588 | if( recursive && ( c instanceof java.awt.Container ) ) 589 | { java.awt.Component[] comps = ((java.awt.Container)c).getComponents(); 590 | for( int i = 0; i < comps.length; i++ ) 591 | remove( out, comps[i], recursive ); 592 | return true; 593 | } // end if: recursive 594 | else return false; 595 | } // end if: supports DnD 596 | else return false; 597 | } // end remove 598 | 599 | 600 | 601 | 602 | /* ******** I N N E R I N T E R F A C E L I S T E N E R ******** */ 603 | 604 | 605 | /** 606 | * Implement this inner interface to listen for when files are dropped. For example 607 | * your class declaration may begin like this: 608 | *
609 |      *      public class MyClass implements FileDrop.Listener
610 |      *      ...
611 |      *      public void filesDropped( java.io.File[] files )
612 |      *      {
613 |      *          ...
614 |      *      }   // end filesDropped
615 |      *      ...
616 |      * 
617 | * 618 | * @since 1.1 619 | */ 620 | public static interface Listener { 621 | 622 | /** 623 | * This method is called when files have been successfully dropped. 624 | * 625 | * @param files An array of Files that were dropped. 626 | * @since 1.0 627 | */ 628 | public abstract void filesDropped(File[] files); 629 | 630 | 631 | } // end inner-interface Listener 632 | 633 | 634 | /* ******** I N N E R C L A S S ******** */ 635 | 636 | 637 | /** 638 | * This is the event that is passed to the 639 | * FileDropListener#filesDropped filesDropped(...) method in 640 | * your FileDropListener when files are dropped onto 641 | * a registered drop target. 642 | * 643 | *

I'm releasing this code into the Public Domain. Enjoy.

644 | * 645 | * @author Robert Harder 646 | * @author rob@iharder.net 647 | * @version 1.2 648 | */ 649 | public static class Event extends java.util.EventObject { 650 | 651 | private File[] files; 652 | 653 | /** 654 | * Constructs an {@link Event} with the array 655 | * of files that were dropped and the 656 | * {@link FileDrop} that initiated the event. 657 | * 658 | * @param files The array of files that were dropped 659 | * @since 1.1 660 | */ 661 | public Event( File[] files, Object source ) { 662 | super( source ); 663 | this.files = files; 664 | } // end constructor 665 | 666 | /** 667 | * Returns an array of files that were dropped on a 668 | * registered drop target. 669 | * 670 | * @return array of files that were dropped 671 | * @since 1.1 672 | */ 673 | public File[] getFiles() { 674 | return files; 675 | } // end getFiles 676 | 677 | } // end inner class Event 678 | 679 | 680 | 681 | /* ******** I N N E R C L A S S ******** */ 682 | 683 | 684 | /** 685 | * At last an easy way to encapsulate your custom objects for dragging and dropping 686 | * in your Java programs! 687 | * When you need to create a {@link java.awt.datatransfer.Transferable} object, 688 | * use this class to wrap your object. 689 | * For example: 690 | *

691 |      *      ...
692 |      *      MyCoolClass myObj = new MyCoolClass();
693 |      *      Transferable xfer = new TransferableObject( myObj );
694 |      *      ...
695 |      * 
696 | * Or if you need to know when the data was actually dropped, like when you're 697 | * moving data out of a list, say, you can use the {@link TransferableObject.Fetcher} 698 | * inner class to return your object Just in Time. 699 | * For example: 700 | *

701 |      *      ...
702 |      *      final MyCoolClass myObj = new MyCoolClass();
703 |      *
704 |      *      TransferableObject.Fetcher fetcher = new TransferableObject.Fetcher()
705 |      *      {   public Object getObject(){ return myObj; }
706 |      *      }; // end fetcher
707 |      *
708 |      *      Transferable xfer = new TransferableObject( fetcher );
709 |      *      ...
710 |      * 
711 | * 712 | * The {@link DataFlavor} associated with 713 | * {@link TransferableObject} has the representation class 714 | * net.iharder.dnd.TransferableObject.class and MIME type 715 | * application/x-net.iharder.dnd.TransferableObject. 716 | * This data flavor is accessible via the static 717 | * {@link #DATA_FLAVOR} property. 718 | * 719 | * 720 | *

I'm releasing this code into the Public Domain. Enjoy.

721 | * 722 | * @author Robert Harder 723 | * @author rob@iharder.net 724 | * @version 1.2 725 | */ 726 | public static class TransferableObject implements java.awt.datatransfer.Transferable 727 | { 728 | /** 729 | * The MIME type for {@link #DATA_FLAVOR} is 730 | * application/x-net.iharder.dnd.TransferableObject. 731 | * 732 | * @since 1.1 733 | */ 734 | public final static String MIME_TYPE = "application/x-net.iharder.dnd.TransferableObject"; 735 | 736 | 737 | /** 738 | * The default {@link DataFlavor} for 739 | * {@link TransferableObject} has the representation class 740 | * net.iharder.dnd.TransferableObject.class 741 | * and the MIME type 742 | * application/x-net.iharder.dnd.TransferableObject. 743 | * 744 | * @since 1.1 745 | */ 746 | public final static DataFlavor DATA_FLAVOR = 747 | new DataFlavor( FileDrop.TransferableObject.class, MIME_TYPE ); 748 | 749 | 750 | private Fetcher fetcher; 751 | private Object data; 752 | 753 | private DataFlavor customFlavor; 754 | 755 | 756 | 757 | /** 758 | * Creates a new {@link TransferableObject} that wraps data. 759 | * Along with the {@link #DATA_FLAVOR} associated with this class, 760 | * this creates a custom data flavor with a representation class 761 | * determined from data.getClass() and the MIME type 762 | * application/x-net.iharder.dnd.TransferableObject. 763 | * 764 | * @param data The data to transfer 765 | * @since 1.1 766 | */ 767 | public TransferableObject( Object data ) 768 | { this.data = data; 769 | this.customFlavor = new DataFlavor( data.getClass(), MIME_TYPE ); 770 | } // end constructor 771 | 772 | 773 | 774 | /** 775 | * Creates a new {@link TransferableObject} that will return the 776 | * object that is returned by fetcher. 777 | * No custom data flavor is set other than the default 778 | * {@link #DATA_FLAVOR}. 779 | * 780 | * @see Fetcher 781 | * @param fetcher The {@link Fetcher} that will return the data object 782 | * @since 1.1 783 | */ 784 | public TransferableObject( Fetcher fetcher ) 785 | { this.fetcher = fetcher; 786 | } // end constructor 787 | 788 | 789 | 790 | /** 791 | * Creates a new {@link TransferableObject} that will return the 792 | * object that is returned by fetcher. 793 | * Along with the {@link #DATA_FLAVOR} associated with this class, 794 | * this creates a custom data flavor with a representation class dataClass 795 | * and the MIME type 796 | * application/x-net.iharder.dnd.TransferableObject. 797 | * 798 | * @see Fetcher 799 | * @param dataClass The {@link Class} to use in the custom data flavor 800 | * @param fetcher The {@link Fetcher} that will return the data object 801 | * @since 1.1 802 | */ 803 | public TransferableObject( Class dataClass, Fetcher fetcher ) 804 | { this.fetcher = fetcher; 805 | this.customFlavor = new DataFlavor( dataClass, MIME_TYPE ); 806 | } // end constructor 807 | 808 | /** 809 | * Returns the custom {@link DataFlavor} associated 810 | * with the encapsulated object or null if the {@link Fetcher} 811 | * constructor was used without passing a {@link Class}. 812 | * 813 | * @return The custom data flavor for the encapsulated object 814 | * @since 1.1 815 | */ 816 | public DataFlavor getCustomDataFlavor() 817 | { return customFlavor; 818 | } // end getCustomDataFlavor 819 | 820 | 821 | /* ******** T R A N S F E R A B L E M E T H O D S ******** */ 822 | 823 | 824 | /** 825 | * Returns a two- or three-element array containing first 826 | * the custom data flavor, if one was created in the constructors, 827 | * second the default {@link #DATA_FLAVOR} associated with 828 | * {@link TransferableObject}, and third the 829 | * java.awt.datatransfer.DataFlavor.stringFlavor. 830 | * 831 | * @return An array of supported data flavors 832 | * @since 1.1 833 | */ 834 | public DataFlavor[] getTransferDataFlavors() 835 | { 836 | if( customFlavor != null ) 837 | return new DataFlavor[] 838 | { customFlavor, 839 | DATA_FLAVOR, 840 | DataFlavor.stringFlavor 841 | }; // end flavors array 842 | else 843 | return new DataFlavor[] 844 | { DATA_FLAVOR, 845 | DataFlavor.stringFlavor 846 | }; // end flavors array 847 | } // end getTransferDataFlavors 848 | 849 | 850 | 851 | /** 852 | * Returns the data encapsulated in this {@link TransferableObject}. 853 | * If the {@link Fetcher} constructor was used, then this is when 854 | * the {@link Fetcher#getObject getObject()} method will be called. 855 | * If the requested data flavor is not supported, then the 856 | * {@link Fetcher#getObject getObject()} method will not be called. 857 | * 858 | * @param flavor The data flavor for the data to return 859 | * @return The dropped data 860 | * @since 1.1 861 | */ 862 | public Object getTransferData( DataFlavor flavor ) 863 | throws java.awt.datatransfer.UnsupportedFlavorException, IOException 864 | { 865 | // Native object 866 | if( flavor.equals( DATA_FLAVOR ) ) 867 | return fetcher == null ? data : fetcher.getObject(); 868 | 869 | // String 870 | if( flavor.equals( DataFlavor.stringFlavor ) ) 871 | return fetcher == null ? data.toString() : fetcher.getObject().toString(); 872 | 873 | // We can't do anything else 874 | throw new java.awt.datatransfer.UnsupportedFlavorException(flavor); 875 | } // end getTransferData 876 | 877 | 878 | 879 | 880 | /** 881 | * Returns true if flavor is one of the supported 882 | * flavors. Flavors are supported using the equals(...) method. 883 | * 884 | * @param flavor The data flavor to check 885 | * @return Whether or not the flavor is supported 886 | * @since 1.1 887 | */ 888 | public boolean isDataFlavorSupported( DataFlavor flavor ) 889 | { 890 | // Native object 891 | if( flavor.equals( DATA_FLAVOR ) ) 892 | return true; 893 | 894 | // String 895 | if( flavor.equals( DataFlavor.stringFlavor ) ) 896 | return true; 897 | 898 | // We can't do anything else 899 | return false; 900 | } // end isDataFlavorSupported 901 | 902 | 903 | /* ******** I N N E R I N T E R F A C E F E T C H E R ******** */ 904 | 905 | /** 906 | * Instead of passing your data directly to the {@link TransferableObject} 907 | * constructor, you may want to know exactly when your data was received 908 | * in case you need to remove it from its source (or do anyting else to it). 909 | * When the {@link #getTransferData getTransferData(...)} method is called 910 | * on the {@link TransferableObject}, the {@link Fetcher}'s 911 | * {@link #getObject getObject()} method will be called. 912 | * 913 | * @author Robert Harder 914 | * @version 1.1 915 | * @since 1.1 916 | */ 917 | public static interface Fetcher 918 | { 919 | /** 920 | * Return the object being encapsulated in the 921 | * {@link TransferableObject}. 922 | * 923 | * @return The dropped object 924 | * @since 1.1 925 | */ 926 | public abstract Object getObject(); 927 | } // end inner interface Fetcher 928 | 929 | 930 | 931 | } // end class TransferableObject 932 | 933 | 934 | 935 | 936 | 937 | } // end class FileDrop 938 | -------------------------------------------------------------------------------- /src/main/java/net/vaemendis/hccd/FileWatcher.java: -------------------------------------------------------------------------------- 1 | package net.vaemendis.hccd; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.nio.file.*; 6 | import java.util.Timer; 7 | import java.util.TimerTask; 8 | 9 | import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY; 10 | 11 | public class FileWatcher { 12 | 13 | private WatchService watchService; 14 | private Timer timer; 15 | private WatchedFiles watchedFiles; 16 | private UserConfiguration config; 17 | 18 | public FileWatcher() throws IOException { 19 | timer = new Timer(); 20 | timer.schedule(new TimerTask() { 21 | @Override 22 | public void run() { 23 | try { 24 | checkFiles(); 25 | } catch (Exception e) { 26 | ErrorDialog.show(null, e); 27 | } 28 | } 29 | }, 0, 500); 30 | } 31 | 32 | public void watch(File watched) throws IOException { 33 | resetWatchService(); 34 | 35 | watchedFiles = new WatchedFiles(watched); 36 | Path watchedDir = watchedFiles.getParentDir().toPath(); 37 | watchedDir.register(watchService, ENTRY_MODIFY); 38 | Hccd.log("Watching " + watchedFiles.toString()); 39 | CardGenerator.generateCards(watchedFiles, config); 40 | } 41 | 42 | private void resetWatchService() throws IOException { 43 | if (watchService != null) { 44 | watchService.close(); 45 | } 46 | watchService = FileSystems.getDefault().newWatchService(); 47 | } 48 | 49 | 50 | private void checkFiles() throws IOException { 51 | if (watchService != null) { 52 | WatchKey key = watchService.poll(); 53 | if (key != null) { 54 | for (WatchEvent watchEvent : key.pollEvents()) { 55 | final WatchEvent.Kind kind = watchEvent.kind(); 56 | if (StandardWatchEventKinds.ENTRY_MODIFY == kind && 57 | isWatched((Path)watchEvent.context())) { 58 | Path p = (Path) watchEvent.context(); 59 | Hccd.log("File modified: " + p.getFileName().toString()); 60 | CardGenerator.generateCards(watchedFiles, config); 61 | } 62 | } 63 | key.reset(); 64 | } 65 | } 66 | } 67 | 68 | private boolean isWatched(Path path) { 69 | String fileName = path.getFileName().toString(); 70 | return watchedFiles.getCsvFile().getName().equals(fileName) || 71 | watchedFiles.getCssFile().getName().equals(fileName) || 72 | watchedFiles.getHtmlFile().getName().equals(fileName); 73 | } 74 | 75 | public void setConfiguration(UserConfiguration config) { 76 | this.config = config; 77 | } 78 | 79 | public void generateCardSheet() throws IOException { 80 | if (watchedFiles != null) { 81 | CardGenerator.generateCards(watchedFiles, config); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/net/vaemendis/hccd/Hccd.java: -------------------------------------------------------------------------------- 1 | package net.vaemendis.hccd; 2 | 3 | 4 | import javax.swing.*; 5 | 6 | public class Hccd { 7 | 8 | private static MainForm frame; 9 | 10 | 11 | public static void main(String[] args) { 12 | try { 13 | frame = new MainForm(new FileWatcher()); 14 | frame.init(); 15 | SwingUtilities.invokeLater(() -> frame.setVisible(true)); 16 | } catch (Exception e) { 17 | ErrorDialog.show(frame, e); 18 | } 19 | } 20 | 21 | public static void log(String msg) { 22 | frame.log(msg); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/net/vaemendis/hccd/Launcher.java: -------------------------------------------------------------------------------- 1 | package net.vaemendis.hccd; 2 | 3 | import com.jdotsoft.jarloader.JarClassLoader; 4 | 5 | public class Launcher { 6 | 7 | public static void main(String[] args) { 8 | JarClassLoader jcl = new JarClassLoader(); 9 | try { 10 | jcl.invokeMain("net.vaemendis.hccd.Hccd", args); 11 | } catch (Throwable e) { 12 | e.printStackTrace(); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /src/main/java/net/vaemendis/hccd/MainForm.java: -------------------------------------------------------------------------------- 1 | package net.vaemendis.hccd; 2 | 3 | import javax.swing.*; 4 | import javax.swing.border.BevelBorder; 5 | import javax.swing.filechooser.FileFilter; 6 | import javax.swing.filechooser.FileSystemView; 7 | import java.awt.*; 8 | import java.awt.event.WindowAdapter; 9 | import java.awt.event.WindowEvent; 10 | import java.io.File; 11 | import java.io.IOException; 12 | import java.text.SimpleDateFormat; 13 | import java.util.ArrayList; 14 | import java.util.Date; 15 | import java.util.List; 16 | import java.util.prefs.Preferences; 17 | 18 | public class MainForm extends JFrame implements UserConfiguration { 19 | 20 | private static final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); 21 | private static final String PREF_NODE_NAME = "net.vaemendis.hccd.GUI_PREFERENCES"; 22 | private static final String PREF_ROWS = "rows"; 23 | private static final String PREF_COLS = "columns"; 24 | private static final String PREF_EXCEL_CSV = "csv_excel"; 25 | private static final String PREF_DELIMITER = "delimiter"; 26 | private static final String PREF_CARD_FILTER = "card_filter"; 27 | private static final String PREF_WATCHED_FILE = "watched_file"; 28 | 29 | 30 | private Preferences prefs; 31 | 32 | private JTextArea logPanel; 33 | private FileWatcher watcher; 34 | private final JRadioButton excelRadio; 35 | private final JSpinner rowSpinner; 36 | private final JSpinner colSpinner; 37 | private final String[] delimiters = {";", ","}; 38 | private final JComboBox delimiterBox; 39 | private final JTextField cardFilter; 40 | private String watchedFilePath; 41 | 42 | 43 | public MainForm(FileWatcher watcher) { 44 | this.watcher = watcher; 45 | this.watcher.setConfiguration(this); 46 | prefs = Preferences.userRoot().node(PREF_NODE_NAME); 47 | 48 | setResizable(false); 49 | getContentPane().setLayout(new BorderLayout()); 50 | setTitle("HTML+CSS Card Designer"); 51 | setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 52 | setMinimumSize(new Dimension(800, 600)); 53 | 54 | // TOP PANEL 55 | JButton openBtn = new JButton("Open..."); 56 | openBtn.addActionListener(e -> { 57 | try { 58 | openFile(); 59 | } catch (IOException e1) { 60 | ErrorDialog.show(MainForm.this, e1); 61 | } 62 | }); 63 | openBtn.setPreferredSize(new Dimension(120, 25)); 64 | openBtn.setMaximumSize(new Dimension(120, 25)); 65 | 66 | JLabel rowLbl = new JLabel("Rows: "); 67 | rowSpinner = new JSpinner(new SpinnerNumberModel(2, 1, 50, 1)); 68 | rowSpinner.setMaximumSize(new Dimension(40, 50)); 69 | JLabel colLbl = new JLabel("Columns: "); 70 | colSpinner = new JSpinner(new SpinnerNumberModel(4, 1, 50, 1)); 71 | colSpinner.setMaximumSize(new Dimension(40, 50)); 72 | 73 | JLabel formatLabel = new JLabel("CSV format: "); 74 | excelRadio = new JRadioButton("Excel"); 75 | JRadioButton rfcRadio = new JRadioButton("RFC-4180"); 76 | ButtonGroup group = new ButtonGroup(); 77 | group.add(rfcRadio); 78 | group.add(excelRadio); 79 | rfcRadio.setSelected(true); 80 | 81 | JLabel delimiterLbl = new JLabel("Delimiter: "); 82 | delimiterBox = new JComboBox<>(delimiters); 83 | delimiterBox.setSelectedIndex(0); 84 | delimiterBox.setMaximumSize(new Dimension(40, 50)); 85 | 86 | JButton refreshBtn = new JButton("Refresh"); 87 | refreshBtn.addActionListener(e -> { 88 | try { 89 | this.watcher.generateCardSheet(); 90 | } catch (IOException e1) { 91 | ErrorDialog.show(MainForm.this, e1); 92 | } 93 | }); 94 | refreshBtn.setPreferredSize(new Dimension(120, 25)); 95 | refreshBtn.setMaximumSize(new Dimension(120, 25)); 96 | 97 | 98 | JLabel filterLbl = new JLabel("Card filter (eg. 1,3,6-8)"); 99 | cardFilter = new JTextField(); 100 | cardFilter.setMaximumSize(new Dimension(120, 25)); 101 | 102 | JPanel rightPanel = new JPanel(); 103 | rightPanel.setLayout(new BoxLayout(rightPanel, BoxLayout.PAGE_AXIS)); 104 | rightPanel.add(openBtn); 105 | rightPanel.add(Box.createVerticalStrut(60)); 106 | rightPanel.add(filterLbl); 107 | rightPanel.add(Box.createVerticalStrut(10)); 108 | rightPanel.add(cardFilter); 109 | rightPanel.add(Box.createVerticalStrut(20)); 110 | rightPanel.add(refreshBtn); 111 | 112 | 113 | rightPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); 114 | getContentPane().add(rightPanel, BorderLayout.EAST); 115 | 116 | 117 | JPanel topPanel = new JPanel(); 118 | topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.LINE_AXIS)); 119 | topPanel.add(rowLbl); 120 | topPanel.add(rowSpinner); 121 | topPanel.add(Box.createHorizontalStrut(10)); 122 | topPanel.add(colLbl); 123 | topPanel.add(colSpinner); 124 | topPanel.add(Box.createHorizontalStrut(30)); 125 | topPanel.add(formatLabel); 126 | topPanel.add(rfcRadio); 127 | topPanel.add(excelRadio); 128 | topPanel.add(Box.createHorizontalStrut(30)); 129 | topPanel.add(delimiterLbl); 130 | topPanel.add(delimiterBox); 131 | 132 | 133 | topPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); 134 | getContentPane().add(topPanel, BorderLayout.NORTH); 135 | 136 | // CENTER PANEL 137 | logPanel = new JTextArea(); 138 | logPanel.setEditable(false); 139 | logPanel.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null)); 140 | JScrollPane scrollPane = new JScrollPane(logPanel); 141 | scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); 142 | getContentPane().add(scrollPane, BorderLayout.CENTER); 143 | 144 | // Add drag and drop support 145 | new FileDrop(null, logPanel, files -> { 146 | String errorMsg = null; 147 | if (files.length == 1) { 148 | File file = files[0]; 149 | if (file.isFile() && isHtml(file)) { 150 | try { 151 | watcher.watch(file); 152 | watchedFilePath = file.getPath(); 153 | } catch (Exception e) { 154 | ErrorDialog.show(MainForm.this, e); 155 | } 156 | } else { 157 | errorMsg = "Only HTML files are supported"; 158 | } 159 | } else { 160 | errorMsg = "Drop only one file at a time"; 161 | } 162 | if (errorMsg != null) { 163 | JOptionPane.showMessageDialog(MainForm.this, errorMsg, "File opening failed", JOptionPane.ERROR_MESSAGE); 164 | } 165 | }); 166 | 167 | // save preferences on exit 168 | addWindowListener(new WindowAdapter() { 169 | @Override 170 | public void windowClosing(WindowEvent e) { 171 | savePreferences(); 172 | } 173 | }); 174 | } 175 | 176 | public void init() throws IOException { 177 | setIconImages(Tools.getApplicationIcons()); 178 | 179 | // center frame 180 | Toolkit tk = Toolkit.getDefaultToolkit(); 181 | Dimension screenSize = tk.getScreenSize(); 182 | int screenHeight = screenSize.height; 183 | int screenWidth = screenSize.width; 184 | setLocation((screenWidth - getWidth()) / 2, (screenHeight - getHeight()) / 2); 185 | loadPreferences(); 186 | } 187 | 188 | public void openFile() throws IOException { 189 | JFileChooser chooser = new JFileChooser(FileSystemView.getFileSystemView().getHomeDirectory()); 190 | chooser.setFileFilter(new FileFilter() { 191 | @Override 192 | public boolean accept(File f) { 193 | return f.isDirectory() || isHtml(f); 194 | } 195 | 196 | @Override 197 | public String getDescription() { 198 | return "HTML files"; 199 | } 200 | }); 201 | int returnVal = chooser.showOpenDialog(this); 202 | 203 | if (returnVal == JFileChooser.APPROVE_OPTION) { 204 | File chosenFile = chooser.getSelectedFile(); 205 | watcher.watch(chosenFile); 206 | watchedFilePath = chosenFile.getPath(); 207 | } 208 | } 209 | 210 | public void log(String msg) { 211 | SwingUtilities.invokeLater(() -> logPanel.append(sdf.format(new Date()) + " - " + msg + "\n")); 212 | } 213 | 214 | private boolean isHtml(File f) { 215 | return f.getName().toLowerCase().endsWith("htm") || 216 | f.getName().toLowerCase().endsWith("html"); 217 | } 218 | 219 | @Override 220 | public int getGridColNumber() { 221 | return (int) colSpinner.getValue(); 222 | } 223 | 224 | @Override 225 | public int getGridRowNumber() { 226 | return (int) rowSpinner.getValue(); 227 | } 228 | 229 | @Override 230 | public boolean useExcelFormat() { 231 | return excelRadio.isSelected(); 232 | } 233 | 234 | @Override 235 | public char getDelimiter() { 236 | return ((String) delimiterBox.getSelectedItem()).charAt(0); 237 | } 238 | 239 | @Override 240 | public List getCardFilter() { 241 | List cardList = new ArrayList<>(); 242 | String filterString = cardFilter.getText(); 243 | try { 244 | if (filterString != null && filterString.length() > 0) { 245 | String[] commaSepValues = filterString.split(","); 246 | for (String s : commaSepValues) { 247 | if (s.contains("-")) { 248 | String[] dashSepValues = s.split("-"); 249 | int start = Integer.valueOf(dashSepValues[0]); 250 | int end = Integer.valueOf(dashSepValues[1]); 251 | for (int i = start; i < end + 1; i++) { 252 | cardList.add(i); 253 | } 254 | } else { 255 | cardList.add(Integer.valueOf(s)); 256 | } 257 | } 258 | } 259 | } catch (Exception e) { 260 | Hccd.log("Invalid filter: " + filterString); 261 | cardList.clear(); 262 | } 263 | 264 | return cardList; 265 | } 266 | 267 | private void savePreferences() { 268 | prefs.putInt(PREF_ROWS, getGridRowNumber()); 269 | prefs.putInt(PREF_COLS, getGridColNumber()); 270 | prefs.putBoolean(PREF_EXCEL_CSV, useExcelFormat()); 271 | prefs.put(PREF_DELIMITER, String.valueOf(getDelimiter())); 272 | prefs.put(PREF_CARD_FILTER, cardFilter.getText()); 273 | prefs.put(PREF_WATCHED_FILE, watchedFilePath); 274 | } 275 | 276 | private void loadPreferences() { 277 | rowSpinner.setValue(prefs.getInt(PREF_ROWS, 2)); 278 | colSpinner.setValue(prefs.getInt(PREF_COLS, 4)); 279 | if (prefs.getBoolean(PREF_EXCEL_CSV, false)) { 280 | excelRadio.setSelected(true); 281 | } else { 282 | excelRadio.setSelected(false); 283 | } 284 | delimiterBox.setSelectedItem(prefs.get(PREF_DELIMITER, ";")); 285 | cardFilter.setText(prefs.get(PREF_CARD_FILTER, "")); 286 | watchedFilePath = prefs.get(PREF_WATCHED_FILE, null); 287 | 288 | boolean restored = false; 289 | if (watchedFilePath != null) { 290 | File wf = new File(watchedFilePath); 291 | if (wf.isFile()) { 292 | try { 293 | watcher.watch(wf); 294 | restored = true; 295 | } catch (Exception e) { 296 | log("Error while trying to monitor file: " + wf.getPath()); 297 | } 298 | } 299 | } 300 | if(!restored){ 301 | log("Open your HTML file or drag and drop it here"); 302 | } 303 | } 304 | } 305 | 306 | -------------------------------------------------------------------------------- /src/main/java/net/vaemendis/hccd/Tools.java: -------------------------------------------------------------------------------- 1 | package net.vaemendis.hccd; 2 | 3 | import javax.imageio.ImageIO; 4 | import java.awt.*; 5 | import java.io.IOException; 6 | import java.util.ArrayList; 7 | 8 | public class Tools { 9 | 10 | public static java.util.List getApplicationIcons() throws IOException { 11 | Object o = new Tools(); 12 | java.util.List iconList = new ArrayList<>(); 13 | iconList.add(ImageIO.read(o.getClass().getResource("/icon-256.png"))); 14 | iconList.add(ImageIO.read(o.getClass().getResource("/icon-128.png"))); 15 | iconList.add(ImageIO.read(o.getClass().getResource("/icon-64.png"))); 16 | iconList.add(ImageIO.read(o.getClass().getResource("/icon-48.png"))); 17 | iconList.add(ImageIO.read(o.getClass().getResource("/icon-32.png"))); 18 | iconList.add(ImageIO.read(o.getClass().getResource("/icon-16.png"))); 19 | return iconList; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/net/vaemendis/hccd/UserConfiguration.java: -------------------------------------------------------------------------------- 1 | package net.vaemendis.hccd; 2 | 3 | import java.util.List; 4 | 5 | public interface UserConfiguration { 6 | 7 | int getGridColNumber(); 8 | 9 | int getGridRowNumber(); 10 | 11 | boolean useExcelFormat(); 12 | 13 | char getDelimiter(); 14 | 15 | List getCardFilter(); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/net/vaemendis/hccd/WatchedFiles.java: -------------------------------------------------------------------------------- 1 | package net.vaemendis.hccd; 2 | 3 | import org.apache.commons.io.FilenameUtils; 4 | 5 | import java.io.File; 6 | 7 | public class WatchedFiles { 8 | 9 | private File htmlFile; 10 | private File cssFile; 11 | private File csvFile; 12 | private File parentDir; 13 | 14 | public WatchedFiles(File htmlFile) { 15 | this.htmlFile = htmlFile; 16 | parentDir = htmlFile.getParentFile(); 17 | String root = FilenameUtils.getBaseName(htmlFile.getName()); 18 | cssFile = new File(parentDir, root + ".css"); 19 | csvFile = new File(parentDir, root + ".csv"); 20 | } 21 | 22 | public File getHtmlFile() { 23 | return htmlFile; 24 | } 25 | 26 | public File getCssFile() { 27 | return cssFile; 28 | } 29 | 30 | public File getCsvFile() { 31 | return csvFile; 32 | } 33 | 34 | public File getParentDir() { 35 | return parentDir; 36 | } 37 | 38 | @Override 39 | public String toString(){ 40 | return htmlFile.getName() + ", " + 41 | cssFile.getName() + ", " + 42 | csvFile.getName() + " in " + 43 | parentDir.getPath(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/resources/icon-128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaemendis/hccd/0e8cd6c3347e60e80789555f030aa05391790814/src/main/resources/icon-128.png -------------------------------------------------------------------------------- /src/main/resources/icon-16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaemendis/hccd/0e8cd6c3347e60e80789555f030aa05391790814/src/main/resources/icon-16.png -------------------------------------------------------------------------------- /src/main/resources/icon-256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaemendis/hccd/0e8cd6c3347e60e80789555f030aa05391790814/src/main/resources/icon-256.png -------------------------------------------------------------------------------- /src/main/resources/icon-32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaemendis/hccd/0e8cd6c3347e60e80789555f030aa05391790814/src/main/resources/icon-32.png -------------------------------------------------------------------------------- /src/main/resources/icon-48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaemendis/hccd/0e8cd6c3347e60e80789555f030aa05391790814/src/main/resources/icon-48.png -------------------------------------------------------------------------------- /src/main/resources/icon-64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vaemendis/hccd/0e8cd6c3347e60e80789555f030aa05391790814/src/main/resources/icon-64.png --------------------------------------------------------------------------------