This is an automated email from the git hooks/post-receive script. tille pushed a commit to branch master in repository orthanc-imagej.
commit 2afd8442272b089907cbdf0af2133aa0c277e6e2 Author: Andreas Tille <[email protected]> Date: Tue Apr 19 14:54:08 2016 +0200 Imported Upstream version 1.1+dfsg --- .hg_archival.txt | 5 + AUTHORS | 5 + CMakeLists.txt | 44 ++ COPYING | 674 ++++++++++++++++++++++ INSTALL | 36 ++ NEWS | 15 + README | 57 ++ com/orthancserver/DicomDecoder.java | 427 ++++++++++++++ com/orthancserver/GridLayout2.java | 167 ++++++ com/orthancserver/HttpsTrustModifier.java | 84 +++ com/orthancserver/Orthanc.java | 51 ++ com/orthancserver/OrthancConfigurationDialog.java | 170 ++++++ com/orthancserver/OrthancConnection.java | 242 ++++++++ com/orthancserver/PreviewPanel.java | 82 +++ com/orthancserver/SelectImageDialog.java | 580 +++++++++++++++++++ debian/README.Debian | 7 - debian/changelog | 12 - debian/compat | 1 - debian/control | 35 -- debian/copyright | 29 - debian/dirs | 1 - debian/install | 1 - debian/patches/json-simple | 38 -- debian/patches/series | 1 - debian/rules | 19 - debian/source/format | 1 - debian/upstream/metadata | 6 - debian/watch | 3 - plugins.config | 1 + 29 files changed, 2640 insertions(+), 154 deletions(-) diff --git a/.hg_archival.txt b/.hg_archival.txt new file mode 100644 index 0000000..58db48f --- /dev/null +++ b/.hg_archival.txt @@ -0,0 +1,5 @@ +repo: 1092b2dca366ed837f03d51f1a1b6002d52c4c12 +node: 4c6bba5f44e778f26f9bd45d0c3ce0167e921280 +branch: OrthancImageJ-1.1 +latesttag: null +latesttagdistance: 10 diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..8ae3946 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,5 @@ +Orthanc - A Lightweight, RESTful DICOM Server +============================================= + +* Sebastien Jodogne <[email protected]> + Department of Medical Physics, CHU of Liege, Belgium diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..54dc06f --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,44 @@ +cmake_minimum_required (VERSION 2.8) + +project(Orthanc_Import) + +find_package(Java REQUIRED) +include(UseJava) + +set(CMAKE_JAVA_COMPILE_FLAGS "-source" "1.6" "-target" "1.6") +set(CMAKE_JAVA_INCLUDE_PATH /usr/share/java/ij.jar) + +# The name of an ImageJ plugin must contain an underscore +# http://imagejdocu.tudor.lu/doku.php?id=howto:plugins:howto_create_an_imagej_plugin_jar_file +add_jar(Orthanc_Import + # Sources of the plugin + ${CMAKE_SOURCE_DIR}/com/orthancserver/DicomDecoder.java + ${CMAKE_SOURCE_DIR}/com/orthancserver/Orthanc.java + ${CMAKE_SOURCE_DIR}/com/orthancserver/OrthancConfigurationDialog.java + ${CMAKE_SOURCE_DIR}/com/orthancserver/OrthancConnection.java + ${CMAKE_SOURCE_DIR}/com/orthancserver/PreviewPanel.java + ${CMAKE_SOURCE_DIR}/com/orthancserver/SelectImageDialog.java + ${CMAKE_SOURCE_DIR}/com/orthancserver/HttpsTrustModifier.java + + # Sources of the "json-simple" toolkit + ${CMAKE_SOURCE_DIR}/org/json/simple/ItemList.java + ${CMAKE_SOURCE_DIR}/org/json/simple/JSONArray.java + ${CMAKE_SOURCE_DIR}/org/json/simple/JSONAware.java + ${CMAKE_SOURCE_DIR}/org/json/simple/JSONObject.java + ${CMAKE_SOURCE_DIR}/org/json/simple/JSONStreamAware.java + ${CMAKE_SOURCE_DIR}/org/json/simple/JSONValue.java + ${CMAKE_SOURCE_DIR}/org/json/simple/parser/ContainerFactory.java + ${CMAKE_SOURCE_DIR}/org/json/simple/parser/ContentHandler.java + ${CMAKE_SOURCE_DIR}/org/json/simple/parser/JSONParser.java + ${CMAKE_SOURCE_DIR}/org/json/simple/parser/ParseException.java + ${CMAKE_SOURCE_DIR}/org/json/simple/parser/Yylex.java + ${CMAKE_SOURCE_DIR}/org/json/simple/parser/Yytoken.java + ) + +# Add the "plugins.config" file that is expected by ImageJ in the JAR file +add_custom_command(TARGET Orthanc_Import + POST_BUILD + COMMAND jar uf ${CMAKE_CURRENT_BINARY_DIR}/Orthanc_Import.jar plugins.config + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + COMMENT "Packaging the configuration file" VERBATIM + ) diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..94a9ed0 --- /dev/null +++ b/COPYING @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + <program> Copyright (C) <year> <name of author> + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +<http://www.gnu.org/licenses/>. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +<http://www.gnu.org/philosophy/why-not-lgpl.html>. diff --git a/INSTALL b/INSTALL new file mode 100644 index 0000000..d8c13ae --- /dev/null +++ b/INSTALL @@ -0,0 +1,36 @@ +Installing pre-compiled binaries +================================ + +Pre-compiled binaries of this plugin are available at: +http://sourceforge.net/projects/orthancserver/files/ImageJ/ + + +Windows Installation +-------------------- + +Download the most recent ".jar" file, then put it into the "plugins" +folder of the ImageJ distribution. By default, this folder is: + +C:\Program Files\ImageJ\plugins\ + + +Linux Installation +------------------ + +Download the most recent ".jar" file, then put it into the following +folder: + +~/.imagej/plugins/ + + +Building from source +==================== + +You will first have to install CMake (http://www.cmake.org/) and, of +course, ImageJ. Here are the commands to build from source under +Linux: + +# mkdir Build +# cd Build +# cmake .. +# make diff --git a/NEWS b/NEWS new file mode 100644 index 0000000..748cb9a --- /dev/null +++ b/NEWS @@ -0,0 +1,15 @@ +Pending changes in the mainline +=============================== + + +Version 1.1 (2016/04/15) +======================== + +* Fix issue #9 ("Error while importing this image: null") +* Fix issue #10 ("Cannot access an Orthanc running with a self-signed HTTPS certificate") + + +Version 1.0.0 (2014/12/08) +========================== + +* Initial release diff --git a/README b/README new file mode 100644 index 0000000..3a282c4 --- /dev/null +++ b/README @@ -0,0 +1,57 @@ +Orthanc - A Lightweight, RESTful DICOM Server +============================================= + + +General Information +------------------- + +This repository contains an ImageJ plugin that allows to easily access +DICOM images that are stored in some Orthanc server. This plugin might +be useful to medical physicists for QA tasks, as well as for +pedagogical purpose. + +Demonstration: http://youtu.be/wsslVhE-R1Q + +The instructions for building/installing the plugin can be found in +the "INSTALL" file. + + +Licensing +--------- + +Orthanc and this plugin are licensed under the GPLv3 license. + +We also kindly ask scientific works and clinical studies that make use +of this plugin or of Orthanc, to cite Orthanc in their associated +publications. Similarly, we ask open-source and closed-source products +that make use of Orthanc to warn us about this use. You can cite our +work using the following BibTeX entry: + +@inproceedings{Jodogne:ISBI2013, + author = {Jodogne, S. and Bernard, C. and Devillers, M. and Lenaerts, E. and Coucke, P.}, + title = {Orthanc -- {A} Lightweight, {REST}ful {DICOM} Server for Healthcare and Medical Research}, + booktitle={Biomedical Imaging ({ISBI}), {IEEE} 10th International Symposium on}, + year={2013}, + pages={190-193}, + ISSN={1945-7928}, + month=apr, + url={http://ieeexplore.ieee.org/xpl/articleDetails.jsp?tp=&arnumber=6556444}, + address={San Francisco, {CA}, {USA}} +} + + +Disclaimer +---------- + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + +Dependencies +------------ + +* This plugin depends upon the "json-simple" toolkit + (http://code.google.com/p/json-simple/), version 1.1.1, that is + released under the Apache License 2.0. The source of this dependency + is located in the "org/" folder. diff --git a/com/orthancserver/DicomDecoder.java b/com/orthancserver/DicomDecoder.java new file mode 100644 index 0000000..36c3f5e --- /dev/null +++ b/com/orthancserver/DicomDecoder.java @@ -0,0 +1,427 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +package com.orthancserver; + +import ij.ImagePlus; +import ij.ImageStack; +import ij.process.ImageProcessor; +import ij.process.ShortProcessor; +import ij.process.ColorProcessor; +import ij.io.FileInfo; +import ij.measure.Calibration; +import org.json.simple.*; +import java.util.List; +import java.util.ArrayList; +import java.util.Collections; +import java.io.IOException; +import javax.swing.SwingWorker; +import java.util.concurrent.ExecutionException; + +import javax.swing.JFrame; +import javax.swing.JProgressBar; +import java.awt.BorderLayout; +import javax.swing.JPanel; +import javax.swing.JButton; +import java.awt.FlowLayout; +import javax.swing.border.EmptyBorder; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; + + +public class DicomDecoder +{ + private static class ProgressDialog extends JFrame + { + private JProgressBar bar_ = new JProgressBar(); + private boolean canceled_ = false; + + public ProgressDialog(int count) + { + getContentPane().setLayout(new BorderLayout()); + bar_.setBorder(new EmptyBorder(20, 20, 20, 20)); + getContentPane().add(bar_, BorderLayout.NORTH); + + JPanel buttonPane = new JPanel(); + buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); + getContentPane().add(buttonPane, BorderLayout.SOUTH); + + JButton cancelButton = new JButton("Cancel"); + cancelButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg) { + canceled_ = true; + } + }); + buttonPane.add(cancelButton); + + bar_.setMaximum(0); + bar_.setMaximum(count); + + setSize(500, 150); + setTitle("Importing series from Orthanc"); + setLocationRelativeTo(null); // Center dialog on screen + } + + public void SetProgress(int value) + { + bar_.setValue(value); + } + + public boolean IsCanceled() + { + return canceled_; + } + }; + + private static void ExtractCalibration(ImagePlus image, + JSONObject tags) + { + JSONObject rescaleIntercept = (JSONObject) tags.get("0028,1052"); + JSONObject rescaleSlope = (JSONObject) tags.get("0028,1053"); + if (rescaleIntercept != null && + rescaleSlope != null) + { + double[] coeff = { + Float.valueOf((String) rescaleIntercept.get("Value")), + Float.valueOf((String) rescaleSlope.get("Value")) + }; + image.getCalibration().setFunction(Calibration.STRAIGHT_LINE, coeff, "Gray Value"); + } + } + + private static void ExtractPixelSpacing(ImagePlus image, + JSONObject tags) + { + JSONObject pixelSpacing = (JSONObject) tags.get("0028,0030"); + if (pixelSpacing != null) + { + String[] tokens = ((String) pixelSpacing.get("Value")).split("\\\\"); + if (tokens.length == 2) + { + FileInfo fi = image.getFileInfo(); + fi.pixelWidth = Float.valueOf(tokens[0]); + fi.pixelHeight = Float.valueOf(tokens[1]); + fi.unit = "mm"; + + image.setFileInfo(fi); + image.getCalibration().pixelWidth = fi.pixelWidth; + image.getCalibration().pixelHeight = fi.pixelHeight; + image.getCalibration().setUnit(fi.unit); + } + } + } + + private static void ExtractDicomInfo(ImagePlus image, + JSONObject tags) + { + String info = new String(); + + ArrayList<String> tagsIndex = new ArrayList<String>(); + for (Object tag : tags.keySet()) + { + tagsIndex.add((String) tag); + } + + Collections.sort(tagsIndex); + for (String tag : tagsIndex) + { + JSONObject value = (JSONObject) tags.get(tag); + + if (((String) value.get("Type")).equals("String")) + { + info += (tag + " " + (String) value.get("Name") + + ": " + (String) value.get("Value") + "\n"); + } + } + + image.setProperty("Info", info); + } + + private static ImageProcessor DecodeInstance(OrthancConnection c, + String uuid) throws IOException + { + try + { + String uri = "/instances/" + uuid + "/image-uint16"; + ShortProcessor slice = new ShortProcessor(c.ReadImage(uri)); + return slice; + } + catch (IllegalArgumentException e) + { + // Color image + String uri = "/instances/" + uuid + "/preview"; + ColorProcessor slice = new ColorProcessor(c.ReadImage(uri)); + return slice; + } + } + + private static ImageStack AddSlice(ImageStack stack, + OrthancConnection c, + String uuid) throws IOException + { + ImageProcessor slice = DecodeInstance(c, uuid); + + if (stack == null) + { + stack = new ImageStack(slice.getWidth(), slice.getHeight()); + } + + stack.addSlice("", slice); + return stack; + } + + + static private class Slice implements Comparable + { + private Float index_; + private String uuid_; + + Slice(float index, + String uuid) + { + index_ = index; + uuid_ = uuid; + } + + @Override + public int compareTo(Object other) + { + return index_.compareTo(((Slice) other).index_); + } + + public String GetUuid() + { + return uuid_; + } + } + + + + private String[] SortSlices(List<Slice> slices) + { + Collections.sort(slices); + + String[] result = new String[slices.size()]; + + for (int i = 0; i < slices.size(); i++) + { + result[i] = slices.get(i).GetUuid(); + } + + return result; + } + + + + private String[] SortSlicesBy3D(OrthancConnection c, + JSONArray instances) throws IOException + { + ArrayList<Slice> slices = new ArrayList<Slice>(); + float normal[] = null; + + float minDistance = Float.POSITIVE_INFINITY; + float maxDistance = Float.NEGATIVE_INFINITY; + + for (int i = 0; i < instances.size(); i++) + { + String uuid = (String) instances.get(i); + JSONObject instance = (JSONObject) c.ReadJson("/instances/" + uuid + "/tags?simplify"); + if (!instance.containsKey("ImageOrientationPatient") || + !instance.containsKey("ImagePositionPatient")) + { + return null; + } + + if (i == 0) + { + String[] tokens = ((String) instance.get("ImageOrientationPatient")).split("\\\\"); + if (tokens.length != 6) + { + return null; + } + + float cosines[] = new float[6]; + for (int j = 0; j < 6; j++) + { + cosines[j] = Float.parseFloat(tokens[j]); + } + + normal = new float[] { + cosines[1] * cosines[5] - cosines[2] * cosines[4], + cosines[2] * cosines[3] - cosines[0] * cosines[5], + cosines[0] * cosines[4] - cosines[1] * cosines[3] + }; + } + + String[] tokens = ((String) instance.get("ImagePositionPatient")).split("\\\\"); + if (tokens.length != 3) + { + return null; + } + + float distance = 0; + for (int j = 0; j < 3; j++) + { + distance += normal[j] * Float.parseFloat(tokens[j]); + } + + minDistance = Math.min(minDistance, distance); + maxDistance = Math.max(minDistance, distance); + slices.add(new Slice(distance, uuid)); + } + + if (maxDistance - minDistance < 0.001) + { + return null; + } + + return SortSlices(slices); + } + + + private String[] SortSlicesByNumber(OrthancConnection c, + JSONArray instances) throws IOException + { + ArrayList<Slice> slices = new ArrayList<Slice>(); + + for (int i = 0; i < instances.size(); i++) + { + String uuid = (String) instances.get(i); + JSONObject instance = (JSONObject) c.ReadJson("/instances/" + uuid); + Long index = (Long) instance.get("IndexInSeries"); + slices.add(new Slice((float) index, uuid)); + } + + return SortSlices(slices); + } + + + + private String[] GetSlices(OrthancConnection c, + JSONArray instances) throws IOException + { + String[] result; + + result = SortSlicesBy3D(c, instances); + if (result != null && result.length == instances.size()) + { + return result; + } + + result = SortSlicesByNumber(c, instances); + if (result != null && result.length == instances.size()) + { + return result; + } + + throw new IOException("Not a 3D image"); + } + + + + + private ImagePlus image_; + + public DicomDecoder(final OrthancConnection c, + boolean isInstance, + String uuid) throws IOException, InterruptedException, ExecutionException + { + ImageStack stack = null; + JSONObject tags = null; + String tagsUri, name; + + if (isInstance) + { + name = "Instance " + uuid; + tags = (JSONObject) c.ReadJson("/instances/" + uuid + "/tags"); + stack = AddSlice(stack, c, uuid); + } + else + { + name = "Series " + uuid; + + JSONObject series = (JSONObject) c.ReadJson("/series/" + uuid); + JSONArray instances = (JSONArray) series.get("Instances"); + + try + { + tags = (JSONObject) c.ReadJson("/series/" + uuid + "/shared-tags"); + } + catch (Exception e) + { + // Fallback for old versions of Orthanc, without "shared-tags" + tags = (JSONObject) c.ReadJson("/instances/" + (String) instances.get(0) + "/tags"); + } + + final String[] slices = GetSlices(c, instances); + final ProgressDialog progress = new ProgressDialog(slices.length); + + try + { + progress.setVisible(true); + SwingWorker<ImageStack, Float> worker = new SwingWorker<ImageStack, Float>() { + @Override + protected ImageStack doInBackground() + { + try + { + ImageStack stack = null; + + for (int i = 0; i < slices.length; i++) + { + if (progress.IsCanceled()) + { + return null; + } + + progress.SetProgress(i); + stack = AddSlice(stack, c, slices[i]); + } + + return stack; + } + catch (IOException e) + { + return null; + } + } + }; + + worker.execute(); + stack = worker.get(); + } + finally + { + progress.setVisible(false); + } + } + + image_ = new ImagePlus(name, stack); + + ExtractCalibration(image_, tags); + ExtractPixelSpacing(image_, tags); + ExtractDicomInfo(image_, tags); + } + + public ImagePlus GetImage() + { + return image_; + } +} diff --git a/com/orthancserver/GridLayout2.java b/com/orthancserver/GridLayout2.java new file mode 100644 index 0000000..86beedb --- /dev/null +++ b/com/orthancserver/GridLayout2.java @@ -0,0 +1,167 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +package com.orthancserver; + +import java.awt.*; + +public class GridLayout2 extends GridLayout +{ + public GridLayout2() { + this(1, 0, 0, 0); + } + + public GridLayout2(int rows, int cols) { + this(rows, cols, 0, 0); + } + + public GridLayout2(int rows, int cols, int hgap, int vgap) { + super(rows, cols, hgap, vgap); + } + + public Dimension preferredLayoutSize(Container parent) { + synchronized (parent.getTreeLock()) { + Insets insets = parent.getInsets(); + int ncomponents = parent.getComponentCount(); + int nrows = getRows(); + int ncols = getColumns(); + if (nrows > 0) { + ncols = (ncomponents + nrows - 1) / nrows; + } + else { + nrows = (ncomponents + ncols - 1) / ncols; + } + int[] w = new int[ncols]; + int[] h = new int[nrows]; + for (int i = 0; i < ncomponents; i ++) { + int r = i / ncols; + int c = i % ncols; + Component comp = parent.getComponent(i); + Dimension d = comp.getPreferredSize(); + if (w[c] < d.width) { + w[c] = d.width; + } + if (h[r] < d.height) { + h[r] = d.height; + } + } + int nw = 0; + for (int j = 0; j < ncols; j ++) { + nw += w[j]; + } + int nh = 0; + for (int i = 0; i < nrows; i ++) { + nh += h[i]; + } + return new Dimension(insets.left + insets.right + nw + (ncols-1)*getHgap(), + insets.top + insets.bottom + nh + (nrows-1)*getVgap()); + } + } + + public Dimension minimumLayoutSize(Container parent) { + synchronized (parent.getTreeLock()) { + Insets insets = parent.getInsets(); + int ncomponents = parent.getComponentCount(); + int nrows = getRows(); + int ncols = getColumns(); + if (nrows > 0) { + ncols = (ncomponents + nrows - 1) / nrows; + } + else { + nrows = (ncomponents + ncols - 1) / ncols; + } + int[] w = new int[ncols]; + int[] h = new int[nrows]; + for (int i = 0; i < ncomponents; i ++) { + int r = i / ncols; + int c = i % ncols; + Component comp = parent.getComponent(i); + Dimension d = comp.getMinimumSize(); + if (w[c] < d.width) { + w[c] = d.width; + } + if (h[r] < d.height) { + h[r] = d.height; + } + } + int nw = 0; + for (int j = 0; j < ncols; j ++) { + nw += w[j]; + } + int nh = 0; + for (int i = 0; i < nrows; i ++) { + nh += h[i]; + } + return new Dimension(insets.left + insets.right + nw + (ncols-1)*getHgap(), + insets.top + insets.bottom + nh + (nrows-1)*getVgap()); + } + } + + public void layoutContainer(Container parent) { + synchronized (parent.getTreeLock()) { + Insets insets = parent.getInsets(); + int ncomponents = parent.getComponentCount(); + int nrows = getRows(); + int ncols = getColumns(); + if (ncomponents == 0) { + return; + } + if (nrows > 0) { + ncols = (ncomponents + nrows - 1) / nrows; + } + else { + nrows = (ncomponents + ncols - 1) / ncols; + } + int hgap = getHgap(); + int vgap = getVgap(); + // scaling factors + Dimension pd = preferredLayoutSize(parent); + double sw = (1.0 * parent.getWidth()) / pd.width; + double sh = (1.0 * parent.getHeight()) / pd.height; + // scale + int[] w = new int[ncols]; + int[] h = new int[nrows]; + for (int i = 0; i < ncomponents; i ++) { + int r = i / ncols; + int c = i % ncols; + Component comp = parent.getComponent(i); + Dimension d = comp.getPreferredSize(); + d.width = (int) (sw * d.width); + d.height = (int) (sh * d.height); + if (w[c] < d.width) { + w[c] = d.width; + } + if (h[r] < d.height) { + h[r] = d.height; + } + } + for (int c = 0, x = insets.left; c < ncols; c ++) { + for (int r = 0, y = insets.top; r < nrows; r ++) { + int i = r * ncols + c; + if (i < ncomponents) { + parent.getComponent(i).setBounds(x, y, w[c], h[r]); + } + y += h[r] + vgap; + } + x += w[c] + hgap; + } + } + } +} diff --git a/com/orthancserver/HttpsTrustModifier.java b/com/orthancserver/HttpsTrustModifier.java new file mode 100644 index 0000000..0295063 --- /dev/null +++ b/com/orthancserver/HttpsTrustModifier.java @@ -0,0 +1,84 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +package com.orthancserver; + +import java.net.*; +import javax.net.ssl.*; +import java.security.*; +import java.security.cert.*; + +public class HttpsTrustModifier +{ + private static final AlwaysTrustHostname trustHostname_ = new AlwaysTrustHostname(); + private static SSLSocketFactory trustSocket_; + + private static synchronized SSLSocketFactory GetAlwaysTrustSocket(HttpsURLConnection httpsConnection) + throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException + { + // Singleton pattern to create one single trust manager + if (trustSocket_ == null) + { + SSLContext ctx = SSLContext.getInstance("TLS"); + ctx.init(null, new TrustManager[] { new AlwaysTrustManager() }, null); + trustSocket_ = ctx.getSocketFactory(); + } + + return trustSocket_; + } + + + private static final class AlwaysTrustHostname implements HostnameVerifier + { + public boolean verify(String hostname, SSLSession session) + { + return true; + } + } + + + private static class AlwaysTrustManager implements X509TrustManager + { + public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException + { + } + + public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException + { + } + + public X509Certificate[] getAcceptedIssuers() + { + return null; + } + } + + + public static void Trust(URLConnection conn) + throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException + { + if (conn instanceof HttpsURLConnection) + { + HttpsURLConnection httpsConnection = (HttpsURLConnection) conn; + httpsConnection.setSSLSocketFactory(GetAlwaysTrustSocket(httpsConnection)); + httpsConnection.setHostnameVerifier(trustHostname_); + } + } +} diff --git a/com/orthancserver/Orthanc.java b/com/orthancserver/Orthanc.java new file mode 100644 index 0000000..abe2d47 --- /dev/null +++ b/com/orthancserver/Orthanc.java @@ -0,0 +1,51 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +package com.orthancserver; + +import ij.plugin.PlugIn; +import ij.Prefs; +import javax.swing.JOptionPane; + +public class Orthanc implements PlugIn +{ + public void run(String arg) + { + SelectImageDialog d = new SelectImageDialog(); + d.Unserialize(Prefs.get("orthanc.servers", "")); + + boolean success = d.ShowModal(); + Prefs.set("orthanc.servers", d.Serialize()); + + if (success) + { + try + { + DicomDecoder decoder = new DicomDecoder(d.GetSelectedConnection(), d.IsInstanceSelected(), d.GetSelectedUuid()); + decoder.GetImage().show(); + } + catch (Exception e) + { + JOptionPane.showMessageDialog(null, "Error while importing this image: " + e.getMessage()); + //e.printStackTrace(System.out); + } + } + } +} diff --git a/com/orthancserver/OrthancConfigurationDialog.java b/com/orthancserver/OrthancConfigurationDialog.java new file mode 100644 index 0000000..35ddfd1 --- /dev/null +++ b/com/orthancserver/OrthancConfigurationDialog.java @@ -0,0 +1,170 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +package com.orthancserver; + +import java.awt.BorderLayout; +import java.awt.Canvas; +import java.awt.FlowLayout; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.io.IOException; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JPasswordField; +import javax.swing.JScrollPane; +import javax.swing.JSplitPane; +import javax.swing.JTextField; +import javax.swing.JTree; +import javax.swing.SwingWorker; +import javax.swing.border.EmptyBorder; + +import org.json.simple.JSONObject; + + +public class OrthancConfigurationDialog extends JDialog +{ + private JTextField name_ = new JTextField("Orthanc"); + private JTextField url_ = new JTextField("http://localhost:8042/"); + private JTextField username_ = new JTextField(""); + private JTextField password_ = new JPasswordField(""); + private boolean isSuccess_; + + private OrthancConnection CreateConnection() + { + OrthancConnection orthanc = new OrthancConnection(); + orthanc.SetInsecure(true); // Fix issue 9 (cannot connect to self-signed certificates) + orthanc.SetName(name_.getText()); + orthanc.SetBaseUrl(url_.getText()); + + if (username_.getText().length() != 0) + { + orthanc.SetCredentials(username_.getText(), password_.getText()); + } + + return orthanc; + } + + public OrthancConfigurationDialog() + { + final JPanel contentPanel = new JPanel(); + contentPanel.setBorder(new EmptyBorder(20, 5, 5, 5)); + contentPanel.setLayout(new GridLayout2(0, 2, 20, 5)); + + JLabel label = new JLabel("Name:"); + label.setHorizontalAlignment(JLabel.RIGHT); + contentPanel.add(label); + contentPanel.add(name_); + + label = new JLabel("URL:"); + label.setHorizontalAlignment(JLabel.RIGHT); + contentPanel.add(label); + contentPanel.add(url_); + + label = new JLabel("Username:"); + label.setHorizontalAlignment(JLabel.RIGHT); + contentPanel.add(label); + contentPanel.add(username_); + + label = new JLabel("Password:"); + label.setHorizontalAlignment(JLabel.RIGHT); + contentPanel.add(label); + contentPanel.add(password_); + + getContentPane().setLayout(new BorderLayout()); + getContentPane().add(contentPanel, BorderLayout.NORTH); + + JPanel buttonPane = new JPanel(); + buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); + getContentPane().add(buttonPane, BorderLayout.SOUTH); + { + { + JButton test = new JButton("Test connection"); + test.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg) { + OrthancConnection orthanc = CreateConnection(); + try + { + JSONObject system = (JSONObject) orthanc.ReadJson("system"); + JOptionPane.showMessageDialog(null, "Successfully connected to this Orthanc server " + + "(version: " + (String) system.get("Version") + ")!", + "Success", JOptionPane.INFORMATION_MESSAGE); + } + catch (IOException e) + { + JOptionPane.showMessageDialog(null, "Cannot connect to this Orthanc server!", + "Error", JOptionPane.ERROR_MESSAGE); + } + } + }); + buttonPane.add(test); + } + { + JButton okButton = new JButton("Add"); + okButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg) { + isSuccess_ = true; + setVisible(false); + } + }); + buttonPane.add(okButton); + getRootPane().setDefaultButton(okButton); + } + { + JButton cancelButton = new JButton("Cancel"); + cancelButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg) { + setVisible(false); + } + }); + buttonPane.add(cancelButton); + } + } + + setUndecorated(false); + setSize(500,500); + setTitle("Add new server"); + setModal(true); + } + + + + public OrthancConnection ShowModal() + { + isSuccess_ = false; + setVisible(true); + if (isSuccess_) + { + return CreateConnection(); + } + else + { + return null; + } + } + +} diff --git a/com/orthancserver/OrthancConnection.java b/com/orthancserver/OrthancConnection.java new file mode 100644 index 0000000..c7f622a --- /dev/null +++ b/com/orthancserver/OrthancConnection.java @@ -0,0 +1,242 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +package com.orthancserver; + +import java.awt.image.BufferedImage; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.ConnectException; +import java.net.URL; +import java.net.URLConnection; +import javax.imageio.ImageIO; +import javax.xml.bind.DatatypeConverter; +import org.json.simple.JSONObject; +import org.json.simple.JSONValue; + +public class OrthancConnection +{ + private String baseUrl_; + private String authentication_; + private String name_; + private boolean insecure_; + + OrthancConnection() + { + baseUrl_ = "http://localhost:8042/"; + authentication_ = null; + name_ = "Default Orthanc server"; + insecure_ = false; + } + + + private static InputStream OpenUrl(String urlString, + boolean isInsecure, + String authentication, + String accept) throws IOException + { + URL url = new URL(urlString); + + URLConnection uc = url.openConnection(); + + if (isInsecure) + { + try + { + HttpsTrustModifier.Trust(uc); + } + catch (Exception e) + { + throw new IOException("Cannot allow self-signed certificates"); + } + } + + if (authentication != null) + { + // http://blogs.deepal.org/2008/01/sending-basic-authentication-using-url.html + uc.setRequestProperty("Authorization", "Basic " + authentication); + } + + if (accept != null) + { + uc.setRequestProperty("Accept", accept); + } + + try + { + return uc.getInputStream(); + } + catch (ConnectException e) + { + throw new IOException("Cannot read URL: " + urlString); + } + } + + + private static String ComputeAuthentication(String username, + String password) + { + String auth = (new StringBuffer(username).append(":").append(password)).toString(); + // http://stackoverflow.com/a/14413290/881731 + return DatatypeConverter.printBase64Binary(auth.getBytes()); + } + + + public InputStream OpenStream(String uri, + String acceptHeader) throws IOException + { + String url = baseUrl_ + uri; + return OpenUrl(url, insecure_, authentication_, acceptHeader); + } + + + public void SetCredentials(String username, + String password) + { + authentication_ = ComputeAuthentication(username, password); + } + + public void SetBaseUrl(String url) + { + if (url.endsWith("/")) + { + baseUrl_ = url; + } + else + { + baseUrl_ = url + "/"; + } + } + + public String GetBaseUrl() + { + return baseUrl_; + } + + public void SetInsecure(boolean insecure) + { + insecure_ = true; + } + + public boolean IsInsecure() + { + return insecure_; + } + + public String ReadString(String uri) throws IOException + { + InputStream stream = OpenStream(uri, null); + + BufferedReader reader = null; + try + { + reader = new BufferedReader(new InputStreamReader(stream)); + + StringBuffer buffer = new StringBuffer(); + int read; + char[] chars = new char[1024 * 16]; + while ((read = reader.read(chars)) != -1) + { + buffer.append(chars, 0, read); + } + + return buffer.toString(); + } + finally + { + try + { + if (reader != null) + { + reader.close(); + } + } + catch (IOException e) + { + } + } + } + + public Object ReadJson(String uri) throws IOException + { + String content = ReadString(uri); + Object json = JSONValue.parse(content); + + if (json == null) + { + throw new IOException(); + } + else + { + return json; + } + } + + public BufferedImage ReadImage(String uri) throws IOException + { + // Ask the download of "image/png", otherwise an "image/jpeg" is negociated + return ImageIO.read(OpenStream(uri, "image/png")); + } + + public String GetName() + { + return name_; + } + + public void SetName(String name) + { + name_ = name; + } + + public JSONObject Serialize() + { + JSONObject json = new JSONObject(); + json.put("Name", name_); + json.put("Url", baseUrl_); + + if (authentication_ != null) + { + json.put("Authentication", authentication_); + } + + return json; + } + + public static OrthancConnection Unserialize(JSONObject json) + { + OrthancConnection c = new OrthancConnection(); + c.SetInsecure(true); // Fix issue 9 (cannot connect to self-signed certificates) + c.SetName((String) json.get("Name")); + c.SetBaseUrl((String) json.get("Url")); + + if (json.containsKey("Authentication")) + { + c.authentication_ = (String) json.get("Authentication"); + } + else + { + c.authentication_ = null; + } + + return c; + } +} diff --git a/com/orthancserver/PreviewPanel.java b/com/orthancserver/PreviewPanel.java new file mode 100644 index 0000000..f56315d --- /dev/null +++ b/com/orthancserver/PreviewPanel.java @@ -0,0 +1,82 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +package com.orthancserver; + +import java.awt.Graphics; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.ByteArrayInputStream; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.JPanel; + +public class PreviewPanel extends JPanel +{ + private BufferedImage image_ = null; + + public void Reset() + { + image_ = null; + repaint(); + } + + public void Load(OrthancConnection orthanc, + String uri) + { + try + { + image_ = orthanc.ReadImage(uri); + repaint(); + } + catch (IOException e) + { + Reset(); + } + } + + @Override + protected void paintComponent(Graphics g) + { + super.paintComponent(g); + + if (image_ != null) + { + float scaleX = (float) getWidth() / (float) image_.getWidth(); + float scaleY = (float) getHeight() / (float) image_.getHeight(); + float scale = Math.min(scaleX, scaleY); + if (scale > 1) + { + // Do not upscale the image + scale = 1; + } + + int width = Math.round((float) image_.getWidth() * scale); + int height = Math.round((float) image_.getHeight() * scale); + + int dx = (getWidth() - width) / 2; + int dy = (getHeight() - height) / 2; + g.drawImage(image_, dx, dy, dx + width, dy + height, + 0, 0, image_.getWidth(), image_.getHeight(), null); + } + } +} diff --git a/com/orthancserver/SelectImageDialog.java b/com/orthancserver/SelectImageDialog.java new file mode 100644 index 0000000..9fc96a5 --- /dev/null +++ b/com/orthancserver/SelectImageDialog.java @@ -0,0 +1,580 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +package com.orthancserver; + +import org.json.simple.JSONValue; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Collections; +import java.util.Enumeration; + + +import java.awt.Canvas; +import java.awt.GridLayout; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JSplitPane; +import javax.swing.JScrollPane; +import javax.swing.JTree; +import javax.swing.SwingWorker; +import javax.swing.border.EmptyBorder; +import java.awt.BorderLayout; +import java.awt.FlowLayout; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; + +import javax.xml.bind.DatatypeConverter; +import javax.swing.event.TreeExpansionEvent; +import javax.swing.event.TreeWillExpandListener; +import javax.swing.event.TreeSelectionEvent; +import javax.swing.event.TreeSelectionListener; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.ExpandVetoException; +import javax.swing.tree.MutableTreeNode; +import javax.swing.tree.TreePath; + + +public class SelectImageDialog extends JDialog +{ + private enum ResourceType { + ROOT, + SERVER, + PATIENT, + STUDY, + SERIES, + INSTANCE, + INFO; + } + + + private static class MyTreeNode extends DefaultMutableTreeNode implements Comparable + { + private OrthancConnection orthanc_; + private boolean loaded_ = false; + private ResourceType type_; + private String uuid_; + + + public String GetUuid() + { + return uuid_; + } + + public ResourceType GetResourceType() + { + return type_; + } + + public OrthancConnection GetConnection() + { + return orthanc_; + } + + public boolean UpdatePreview(PreviewPanel preview) + { + if (type_ == ResourceType.INSTANCE) + { + preview.Load(orthanc_, "/instances/" + uuid_ + "/preview"); + return true; + } + else if (type_ == ResourceType.SERIES) + { + try + { + JSONObject series = (JSONObject) orthanc_.ReadJson("series/" + uuid_); + JSONArray instances = (JSONArray) series.get("Instances"); + if (instances.size() > 0) + { + preview.Load(orthanc_, "/instances/" + instances.get(0) + "/preview"); + return true; + } + } + catch (IOException e) + { + } + } + + preview.Reset(); + return false; + } + + + private String AddComponent(String source, String component) + { + if (component == null || + component.length() == 0) + { + return source; + } + + if (source.length() == 0) + { + return component; + } + else + { + return source + " - " + component; + } + } + + + private List<MyTreeNode> LoadPatients() throws IOException + { + List<MyTreeNode> children = new ArrayList<MyTreeNode>(); + + JSONArray patients = (JSONArray) orthanc_.ReadJson("patients"); + for (int i = 0; i < patients.size(); i++) + { + String uuid = (String) patients.get(i); + JSONObject patient = (JSONObject) orthanc_.ReadJson("patients/" + uuid); + JSONObject main = (JSONObject) patient.get("MainDicomTags"); + + String s = new String(); + s = AddComponent(s, (String) main.get("PatientID")); + s = AddComponent(s, (String) main.get("PatientName")); + children.add(new MyTreeNode(orthanc_, ResourceType.PATIENT, uuid, s)); + } + + return children; + } + + + private List<MyTreeNode> LoadStudies() throws IOException + { + List<MyTreeNode> children = new ArrayList<MyTreeNode>(); + + JSONObject patient = (JSONObject) orthanc_.ReadJson("patients/" + uuid_); + JSONArray studies = (JSONArray) patient.get("Studies"); + for (int i = 0; i < studies.size(); i++) + { + String uuid = (String) studies.get(i); + JSONObject study = (JSONObject) orthanc_.ReadJson("studies/" + uuid); + JSONObject main = (JSONObject) study.get("MainDicomTags"); + + String s = new String(); + s = AddComponent(s, (String) main.get("StudyDescription")); + s = AddComponent(s, (String) main.get("StudyDate")); + children.add(new MyTreeNode(orthanc_, ResourceType.STUDY, uuid, s)); + } + + return children; + } + + + private List<MyTreeNode> LoadSeries() throws IOException + { + List<MyTreeNode> children = new ArrayList<MyTreeNode>(); + + JSONObject study = (JSONObject) orthanc_.ReadJson("studies/" + uuid_); + JSONArray seriesSet = (JSONArray) study.get("Series"); + for (int i = 0; i < seriesSet.size(); i++) + { + String uuid = (String) seriesSet.get(i); + JSONObject series = (JSONObject) orthanc_.ReadJson("series/" + uuid); + JSONObject main = (JSONObject) series.get("MainDicomTags"); + + String s = new String(); + s = AddComponent(s, (String) main.get("Modality")); + s = AddComponent(s, (String) main.get("SeriesDescription")); + children.add(new MyTreeNode(orthanc_, ResourceType.SERIES, uuid, s)); + } + + return children; + } + + + private List<MyTreeNode> LoadInstances() throws IOException + { + List<MyTreeNode> children = new ArrayList<MyTreeNode>(); + + JSONObject series = (JSONObject) orthanc_.ReadJson("series/" + uuid_); + JSONArray instances = (JSONArray) series.get("Instances"); + for (int i = 0; i < instances.size(); i++) + { + String uuid = (String) instances.get(i); + JSONObject instance = (JSONObject) orthanc_.ReadJson("instances/" + uuid); + Long index = (Long) instance.get("IndexInSeries"); + String s; + if (index == null) + { + s = uuid; + } + else + { + s = String.valueOf(index); + } + + children.add(new MyTreeNode(orthanc_, ResourceType.INSTANCE, uuid, s)); + } + + return children; + } + + + public MyTreeNode() // Create root node + { + loaded_ = true; + orthanc_ = null; + type_ = ResourceType.ROOT; + uuid_ = ""; + setAllowsChildren(true); + } + + public MyTreeNode(OrthancConnection orthanc, + ResourceType type, + String id, + String name) + { + orthanc_ = orthanc; + type_ = type; + uuid_ = id; + add(new DefaultMutableTreeNode("Loading...", false)); + setAllowsChildren(true); + setUserObject(name); + } + + @Override + public int compareTo(Object other) + { + String a = (String) getUserObject(); + String b = (String) ((MyTreeNode) other).getUserObject(); + return a.compareTo(b); + } + + private void SetChildren(List<MyTreeNode> children) + { + Collections.sort(children); + + removeAllChildren(); + setAllowsChildren(children.size() > 0); + for (MutableTreeNode node : children) + { + add(node); + } + loaded_ = true; + } + + @Override + public boolean isLeaf() + { + return type_ == ResourceType.INSTANCE || type_ == ResourceType.INFO; + } + + public void LoadChildren(final DefaultTreeModel model) + { + if (loaded_) + { + return; + } + + SwingWorker<List<MyTreeNode>, Void> worker = new SwingWorker<List<MyTreeNode>, Void>() { + @Override + protected List<MyTreeNode> doInBackground() + { + List<MyTreeNode> children = null; + + try + { + switch (type_) + { + case SERVER: children = LoadPatients(); break; + case PATIENT: children = LoadStudies(); break; + case STUDY: children = LoadSeries(); break; + case SERIES: children = LoadInstances(); break; + default: + break; + } + } + catch (IOException e) + { + children = null; + } + + if (children == null) + { + children = new ArrayList<MyTreeNode>(); + children.add(new MyTreeNode(orthanc_, ResourceType.INFO, "", "Orthanc is not running, or bad credentials")); + } + + return children; + } + + @Override + protected void done() + { + try + { + SetChildren(get()); + model.nodeStructureChanged(MyTreeNode.this); + } + catch (Exception e) + { + } + + super.done(); + } + }; + + worker.execute(); + } + + } + + + private MyTreeNode root_ = new MyTreeNode(); + private JTree tree_ = null; + private boolean isSuccess_; + private String selectedUuid_; + private ResourceType selectedType_; + private OrthancConnection selectedConnection_; + private JButton okButton_ = new JButton("Open"); + private JButton removeServer_ = new JButton("Remove server"); + private PreviewPanel preview_ = new PreviewPanel(); + + public SelectImageDialog() + { + tree_ = new JTree(); + + tree_.addTreeWillExpandListener(new TreeWillExpandListener() + { + @Override + public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException { + TreePath path = event.getPath(); + if (path.getLastPathComponent() instanceof MyTreeNode) { + MyTreeNode node = (MyTreeNode) path.getLastPathComponent(); + node.LoadChildren((DefaultTreeModel) tree_.getModel()); + } + } + + @Override + public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException { + } + }); + + + tree_.addTreeSelectionListener(new TreeSelectionListener() + { + @Override + public void valueChanged(TreeSelectionEvent e) { + TreePath path = e.getNewLeadSelectionPath(); + if (path != null) + { + MyTreeNode node = (MyTreeNode) path.getLastPathComponent(); + if (node.UpdatePreview(preview_)) + { + selectedType_ = node.GetResourceType(); + selectedUuid_ = node.GetUuid(); + selectedConnection_ = node.GetConnection(); + okButton_.setEnabled(true); + } + + removeServer_.setEnabled(node.GetResourceType() == ResourceType.SERVER); + } + } + }); + + + tree_.addMouseListener(new MouseAdapter() + { + public void mousePressed(MouseEvent e) { + TreePath path = tree_.getPathForLocation(e.getX(), e.getY()); + if (path != null) { + MyTreeNode node = (MyTreeNode) path.getLastPathComponent(); + if (e.getClickCount() == 2 && + node.GetResourceType() == ResourceType.INSTANCE) { + // Double click on an instance, close the dialog + isSuccess_ = true; + setVisible(false); + } + } + } + }); + + + final JPanel contentPanel = new JPanel(); + getContentPane().setLayout(new BorderLayout()); + contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); + getContentPane().add(contentPanel, BorderLayout.CENTER); + contentPanel.setLayout(new BorderLayout(0, 0)); + { + JSplitPane splitPane = new JSplitPane(); + splitPane.setResizeWeight(0.6); + contentPanel.add(splitPane); + + splitPane.setLeftComponent(new JScrollPane(tree_)); + splitPane.setRightComponent(preview_); + } + { + JPanel buttonPane = new JPanel(); + buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); + getContentPane().add(buttonPane, BorderLayout.SOUTH); + { + JButton btnAddServer = new JButton("Add server"); + btnAddServer.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg) { + OrthancConfigurationDialog dd = new OrthancConfigurationDialog(); + dd.setLocationRelativeTo(null); // Center dialog on screen + + OrthancConnection orthanc = dd.ShowModal(); + if (orthanc != null) { + AddOrthancServer(orthanc); + ((DefaultTreeModel) tree_.getModel()).reload(); + } + } + }); + buttonPane.add(btnAddServer); + } + + { + buttonPane.add(removeServer_); + removeServer_.setEnabled(false); + + removeServer_.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg) { + MyTreeNode selected = (MyTreeNode) tree_.getLastSelectedPathComponent(); + if (selected.GetResourceType() == ResourceType.SERVER && + JOptionPane.showConfirmDialog(null, "Remove server \"" + selected.getUserObject() + "\"?", + "WARNING", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) + { + ((DefaultTreeModel) tree_.getModel()).removeNodeFromParent(selected); + } + } + }); + } + + { + okButton_.setEnabled(false); + okButton_.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg) { + isSuccess_ = true; + setVisible(false); + } + }); + buttonPane.add(okButton_); + getRootPane().setDefaultButton(okButton_); + } + { + JButton cancelButton = new JButton("Cancel"); + cancelButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg) { + setVisible(false); + } + }); + buttonPane.add(cancelButton); + } + } + + setUndecorated(false); + setSize(500,500); + setTitle("Select some series or some instance in Orthanc"); + setModal(true); + } + + + public void AddOrthancServer(OrthancConnection orthanc) + { + root_.add(new MyTreeNode(orthanc, ResourceType.SERVER, "", orthanc.GetName())); + } + + public boolean ShowModal() + { + final DefaultTreeModel model = new DefaultTreeModel(root_); + root_.LoadChildren(model); + tree_.setRootVisible(false); + tree_.setShowsRootHandles(true); + tree_.setModel(model); + + isSuccess_ = false; + setVisible(true); + return isSuccess_; + } + + public String GetSelectedUuid() + { + return selectedUuid_; + } + + public boolean IsSeriesSelected() + { + return selectedType_ == ResourceType.SERIES; + } + + public boolean IsInstanceSelected() + { + return selectedType_ == ResourceType.INSTANCE; + } + + public OrthancConnection GetSelectedConnection() + { + return selectedConnection_; + } + + public void Select(OrthancConnection c, boolean isInstance, String uuid) // For test + { + selectedConnection_ = c; + selectedType_ = (isInstance ? ResourceType.INSTANCE : ResourceType.SERIES); + selectedUuid_ = uuid; + } + + public void Unserialize(String s) + { + if (s.length() == 0) + { + // Add default Orthanc server + AddOrthancServer(new OrthancConnection()); + } + else + { + String decoded = new String(DatatypeConverter.parseBase64Binary(s)); + JSONArray config = (JSONArray) JSONValue.parse(decoded); + if (config != null) + { + for (int i = 0; i < config.size(); i++) + { + AddOrthancServer(OrthancConnection.Unserialize((JSONObject) config.get(i))); + } + } + } + } + + public String Serialize() + { + JSONArray servers = new JSONArray(); + + for (int i = 0; i < root_.getChildCount(); i++) + { + MyTreeNode node = (MyTreeNode) root_.getChildAt(i); + servers.add(node.GetConnection().Serialize()); + } + + String config = servers.toJSONString(); + return DatatypeConverter.printBase64Binary(config.getBytes()); + } +} diff --git a/debian/README.Debian b/debian/README.Debian deleted file mode 100644 index b4751bc..0000000 --- a/debian/README.Debian +++ /dev/null @@ -1,7 +0,0 @@ -This is a plugin for ImageJ to browse and download the content of an -Orthanc server. - -Homepage: http://www.orthanc-server.com/static.php?page=imagej - -The plugin is accessible from the "File" -> "Import" -> "Orthanc" menu -entry in ImageJ. diff --git a/debian/changelog b/debian/changelog deleted file mode 100644 index c88d212..0000000 --- a/debian/changelog +++ /dev/null @@ -1,12 +0,0 @@ -orthanc-imagej (1.1+dfsg-1) unstable; urgency=medium - - * New upstream version. - * Updated URLs to the project, the code repository and the downloads. - - -- Sebastien Jodogne <[email protected]> Fri, 15 Apr 2016 11:44:54 +0200 - -orthanc-imagej (1.0.0+dfsg-1) unstable; urgency=low - - * Initial release. (Closes: #772561) - - -- Sebastien Jodogne <[email protected]> Mon, 15 Dec 2014 15:55:43 +0100 diff --git a/debian/compat b/debian/compat deleted file mode 100644 index ec63514..0000000 --- a/debian/compat +++ /dev/null @@ -1 +0,0 @@ -9 diff --git a/debian/control b/debian/control deleted file mode 100644 index 4b62b52..0000000 --- a/debian/control +++ /dev/null @@ -1,35 +0,0 @@ -Source: orthanc-imagej -Maintainer: Debian Med Packaging Team <[email protected]> -Uploaders: Sebastien Jodogne <[email protected]>, - Andreas Tille <[email protected]> -Section: science -Priority: optional -Standards-Version: 3.9.7 -Build-Depends: cmake (>= 2.8), - default-jdk | openjdk-8-jdk, - debhelper (>= 9), - imagej, - libjson-simple-java -Vcs-Browser: https://anonscm.debian.org/viewvc/debian-med/trunk/packages/orthanc-imagej/trunk/ -Vcs-Svn: svn://anonscm.debian.org/debian-med/trunk/packages/orthanc-imagej/trunk/ -Homepage: http://www.orthanc-server.com/static.php?page=imagej - -Package: orthanc-imagej -Architecture: all -Depends: ${misc:Depends}, - default-jre | openjdk-8-jre, - imagej, - libjson-simple-java -Recommends: orthanc -Description: ImageJ plugin to import images from Orthanc - This ImageJ plugin allows ImageJ to browse the content of an Orthanc - server, then import 2D/3D DICOM images from Orthanc into ImageJ. - Orthanc is a lightweight, RESTful DICOM server for healthcare and - medical research. - . - This plugin simplifies the indexation of DICOM images if using - ImageJ (e.g. for quality control of DICOM modalities, or for - pedagogical use). There is also no need to carry on any complex - network configuration, since the plugin directly uses the REST - API of Orthanc. This makes its installation and its use - quite straightforward. diff --git a/debian/copyright b/debian/copyright deleted file mode 100644 index 5a11a28..0000000 --- a/debian/copyright +++ /dev/null @@ -1,29 +0,0 @@ -Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ -Upstream-Name: OrthancImageJ -Upstream-Contact: Sebastien Jodogne <[email protected]> -Source: https://bitbucket.org/sjodogne/orthanc-imagej/ -Files-Excluded: org/* - -Files: * -Copyright: 2012-2016 CHU of Liege (Belgium), and Sebastien Jodogne <[email protected]> -License: GPL-3 - - -License: GPL-3 - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or (at - your option) any later version. - . - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - . - You should have received a copy of the GNU General Public License along - with this package; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - . - On Debian systems, the full text of the GNU General Public License - version 3 can be found in the file - `/usr/share/common-licenses/GPL-3'. diff --git a/debian/dirs b/debian/dirs deleted file mode 100644 index db0cbfb..0000000 --- a/debian/dirs +++ /dev/null @@ -1 +0,0 @@ -usr/share/imagej/plugins diff --git a/debian/install b/debian/install deleted file mode 100644 index 6a8750a..0000000 --- a/debian/install +++ /dev/null @@ -1 +0,0 @@ -Build/Orthanc_Import.jar usr/share/imagej/plugins/ diff --git a/debian/patches/json-simple b/debian/patches/json-simple deleted file mode 100644 index 097d359..0000000 --- a/debian/patches/json-simple +++ /dev/null @@ -1,38 +0,0 @@ -Description: Patch to link against Debian's libjson-simple-java package -Author: Sebastien Jodogne <[email protected]> ---- -This patch header follows DEP-3: http://dep.debian.net/deps/dep3/ -Index: OrthancImageJ-1.1/CMakeLists.txt -=================================================================== ---- OrthancImageJ-1.1.orig/CMakeLists.txt -+++ OrthancImageJ-1.1/CMakeLists.txt -@@ -6,7 +6,7 @@ find_package(Java REQUIRED) - include(UseJava) - - set(CMAKE_JAVA_COMPILE_FLAGS "-source" "1.6" "-target" "1.6") --set(CMAKE_JAVA_INCLUDE_PATH /usr/share/java/ij.jar) -+set(CMAKE_JAVA_INCLUDE_PATH /usr/share/java/ij.jar:/usr/share/java/json-simple.jar) - - # The name of an ImageJ plugin must contain an underscore - # http://imagejdocu.tudor.lu/doku.php?id=howto:plugins:howto_create_an_imagej_plugin_jar_file -@@ -19,20 +19,6 @@ add_jar(Orthanc_Import - ${CMAKE_SOURCE_DIR}/com/orthancserver/PreviewPanel.java - ${CMAKE_SOURCE_DIR}/com/orthancserver/SelectImageDialog.java - ${CMAKE_SOURCE_DIR}/com/orthancserver/HttpsTrustModifier.java -- -- # Sources of the "json-simple" toolkit -- ${CMAKE_SOURCE_DIR}/org/json/simple/ItemList.java -- ${CMAKE_SOURCE_DIR}/org/json/simple/JSONArray.java -- ${CMAKE_SOURCE_DIR}/org/json/simple/JSONAware.java -- ${CMAKE_SOURCE_DIR}/org/json/simple/JSONObject.java -- ${CMAKE_SOURCE_DIR}/org/json/simple/JSONStreamAware.java -- ${CMAKE_SOURCE_DIR}/org/json/simple/JSONValue.java -- ${CMAKE_SOURCE_DIR}/org/json/simple/parser/ContainerFactory.java -- ${CMAKE_SOURCE_DIR}/org/json/simple/parser/ContentHandler.java -- ${CMAKE_SOURCE_DIR}/org/json/simple/parser/JSONParser.java -- ${CMAKE_SOURCE_DIR}/org/json/simple/parser/ParseException.java -- ${CMAKE_SOURCE_DIR}/org/json/simple/parser/Yylex.java -- ${CMAKE_SOURCE_DIR}/org/json/simple/parser/Yytoken.java - ) - - # Add the "plugins.config" file that is expected by ImageJ in the JAR file diff --git a/debian/patches/series b/debian/patches/series deleted file mode 100644 index 33ce5e2..0000000 --- a/debian/patches/series +++ /dev/null @@ -1 +0,0 @@ -json-simple diff --git a/debian/rules b/debian/rules deleted file mode 100755 index 36e6248..0000000 --- a/debian/rules +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/make -f - -JSON_SIMPLE_JAR = /usr/share/java/json-simple.jar - -%: - dh $@ --parallel --builddirectory=Build - -override_dh_auto_configure: - dh_auto_configure -- -DCMAKE_JAVA_INCLUDE_PATH=${JSON_SIMPLE_JAR} - -override_dh_auto_install: - dh_auto_install - dh_link ${JSON_SIMPLE_JAR} usr/share/imagej/plugins/Orthanc_Import_json-simple.jar - -override_dh_installchangelogs: - dh_installchangelogs -k NEWS - -get-orig-source: - uscan --verbose --force-download --repack --compression xz diff --git a/debian/source/format b/debian/source/format deleted file mode 100644 index 163aaf8..0000000 --- a/debian/source/format +++ /dev/null @@ -1 +0,0 @@ -3.0 (quilt) diff --git a/debian/upstream/metadata b/debian/upstream/metadata deleted file mode 100644 index 7cf8c15..0000000 --- a/debian/upstream/metadata +++ /dev/null @@ -1,6 +0,0 @@ -Reference: - Author: S. Jodogne and C. Bernard and M. Devillers and E. Lenaerts and P. Coucke - Title: "Orthanc -- A Lightweight, RESTful DICOM Server for Healthcare and Medical Research" - Type: book - Booktitle: Proc. of the International Symposium on Biomedical Imaging - Year: 2013 diff --git a/debian/watch b/debian/watch deleted file mode 100644 index 1407b5b..0000000 --- a/debian/watch +++ /dev/null @@ -1,3 +0,0 @@ -version=3 -opts="repacksuffix=+dfsg,dversionmangle=s/\+dfsg//g,downloadurlmangle=s/\/browse\.php\?path=//g,repack,compression=xz" \ -http://www.orthanc-server.com/browse.php?path=/imagej downloads/get\.php\?path=/imagej/OrthancImageJ-(\d\S*)\.tar\.gz diff --git a/plugins.config b/plugins.config new file mode 100644 index 0000000..cebd549 --- /dev/null +++ b/plugins.config @@ -0,0 +1 @@ +File>Import, "Orthanc", com.orthancserver.Orthanc -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/orthanc-imagej.git _______________________________________________ debian-med-commit mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/debian-med-commit
