diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index f4b2559d..00000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,11 +0,0 @@ -version: 2 -updates: - - package-ecosystem: "github-actions" - directory: "/" - schedule: - interval: "weekly" - - package-ecosystem: maven - directory: "/rococoa" - schedule: - interval: "daily" - open-pull-requests-limit: 99 diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml deleted file mode 100644 index 55e52e36..00000000 --- a/.github/workflows/snapshot.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Publish Snapshot Artifacts -on: - push: - branches: [ master ] -jobs: - snapshot: - runs-on: macos-latest - steps: - - uses: actions/checkout@v4 - - name: Set up JDK - uses: actions/setup-java@v4 - with: - distribution: 'temurin' - java-version: 21 - cache: maven - - name: Build with Maven - run: mvn --file rococoa/pom.xml --batch-mode deploy - env: - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 89731079..00000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Java CI with Maven -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] -jobs: - build: - runs-on: macos-latest - steps: - - uses: actions/checkout@v4 - - name: Set up JDK - uses: actions/setup-java@v4 - with: - distribution: 'temurin' - java-version: 21 - cache: maven - - name: Build with Maven - run: mvn -B verify --file rococoa/pom.xml \ No newline at end of file diff --git a/Acknowledgements.md b/Acknowledgements.md index 7878424f..078836c8 100644 --- a/Acknowledgements.md +++ b/Acknowledgements.md @@ -1,6 +1,6 @@ # Rococoa Acknowledgements # Rococoa owes much to the following people and organisations - * [JNA](https://github.com/java-native-access/jna) does all the heavy lifting of calling into Cocoa and marshaling parameters. Timothy Wall also added pass struct by value and other extension points to make our life simpler. + * [JNA](http://jna.dev.java.net) does all the heavy lifting of calling into Cocoa and marshaling parameters. Timothy Wall also added pass struct by value and other extension points to make our life simpler. * [Paul Loy](http://www.keteracel.com) was the alpha guinea-pig. * Simon Taylor, Gareth Sylvester-Bradley and Dion Crannitch for Objective-C help. * Richard Care, Matt Bowers, Andy Collins and Morgan David let it go. diff --git a/COPYING b/COPYING deleted file mode 100644 index 94a9ed02..00000000 --- a/COPYING +++ /dev/null @@ -1,674 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - 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. - - - Copyright (C) - - 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 . - -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: - - Copyright (C) - 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 -. - - 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 -. diff --git a/COPYING.LESSER b/COPYING.LESSER deleted file mode 100644 index fc8a5de7..00000000 --- a/COPYING.LESSER +++ /dev/null @@ -1,165 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser 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 -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. diff --git a/ObjcMsgSend.md b/ObjcMsgSend.md index 6841993d..bdd1a7f6 100644 --- a/ObjcMsgSend.md +++ b/ObjcMsgSend.md @@ -38,7 +38,7 @@ What I think this means is that despite the prototype saying that the function r In C the way to make this happen is to cast the function pointer to a pointer to a function that does return the correct struct by value, thus tricking the compiler into generating the correct cleanup code. If you don't have a C compiler handy to do this for you, this is going to be tricky. -Luckily Rococoa uses [JNA](https://github.com/java-native-access/jna), which in turns uses [libffi](http://sourceware.org/libffi/), which is very close to having a C compiler to hand at runtime. +Luckily Rococoa uses [JNA](http://jna.dev.java.net), which in turns uses [libffi](http://sourceware.org/libffi/), which is very close to having a C compiler to hand at runtime. Armed with a description of the structure being returned, libffi sorts out the call stack after the call. It turns out that libffi doesn't only help with objc\_msgSend\_stret. diff --git a/ProjectHome.md b/ProjectHome.md new file mode 100644 index 00000000..53fac0e5 --- /dev/null +++ b/ProjectHome.md @@ -0,0 +1,27 @@ +Rococoa allows you to call Objective-C code through Java classes and interfaces that you define. + +# Welcome to Rococoa # + +Rococoa is a generic Java binding to the Mac Objective-C object system. It +allows the creation and use of Objective-C objects in Java, and the +implementation of Objective-C interfaces in Java. + +_Fair Warning_ + +Rococoa is very much work in progress. Much is subject to change. A lot isn't +good enough not to change. But given the recent deprecation of the Java-Cocoa +bridge, it's the best I've got. Just mind your head. And please give feedback in the +[mailing list](https://rococoa.dev.java.net/servlets/ProjectMailingListList). + +Oh, one big warning. Rococoa on PPC passes all but one of its tests, but that +shows that it has an [issue](http://code.google.com/p/rococoa/issues/detail?id=3) returning longs from Objective-C methods. Please do +try it on PPC, and report any other problems to the project [mailing list](https://rococoa.dev.java.net/servlets/ProjectMailingListList). + + * Take the [Whistlestop Tour](WhistlestopTour.md) + * [How To](HowTo.md) + * [Quicktime](Quicktime.md) + * [Limitations](Limitations.md) + * [Help Wanted](HelpWanted.md) + * [Acknowledgements](Acknowledgements.md) + +Useful information can be found in the archives of both the [users](http://markmail.org/browse/net.java.dev.rococoa.users) and [developers](http://markmail.org/browse/net.java.dev.rococoa.dev) mailing lists. \ No newline at end of file diff --git a/ProjectsUsingRococoa.md b/ProjectsUsingRococoa.md index e69de29b..58d71474 100644 --- a/ProjectsUsingRococoa.md +++ b/ProjectsUsingRococoa.md @@ -0,0 +1,9 @@ +# Projects using Rococoa # + +_Make sure you comply with the GNU Lesser General Public License when releasing an application that uses Rococoa._ + + * [Cyberduck](http://cyberduck.ch) - a FTP, SFTP, WebDAV, Cloud Files & Amazon S3 Browser. + * [Stor](http://www.theescapers.com/stor) - a MySQL editor. + * [Kalexo](http://www.kalexo.com/) - a communication, filing & work co-ordination system. + * [FarFinder](http://flyingmac.com/farfinder) - remote access to your Mac's files by web browser and iPhone. + * [Webjimbo](http://flyingmac.com/webjimbo) - remote access to Yojimbo by web browser and iPhone. \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index 74efd939..00000000 --- a/README.md +++ /dev/null @@ -1,112 +0,0 @@ -#  Welcome to Rococoa - -Rococoa is a generic Java binding to the Mac Objective-C object system. It -allows the creation and use of Objective-C objects in Java, and the -implementation of Objective-C interfaces in Java. - -[![Java CI with Maven](https://github.com/iterate-ch/rococoa/actions/workflows/test.yml/badge.svg)](https://github.com/iterate-ch/rococoa/actions/workflows/test.yml) - -## Rococoa Acknowledgements -Rococoa owes much to the following people and organisations - * [JNA](https://github.com/java-native-access/jna) does all the heavy lifting of calling into Cocoa and marshaling parameters. Timothy Wall also added pass struct by value and other extension points to make our life simpler. - * [Paul Loy](http://www.keteracel.com) was the alpha guinea-pig. - * Simon Taylor, Gareth Sylvester-Bradley and Dion Crannitch for Objective-C help. - * Richard Care, Matt Bowers, Andy Collins and Morgan David let it go. - * [Apple Inc](http://www.apple.com) produced Quicktime, Java on Mac OS, the Cocoa-Java Bridge and Quicktime for Java, then killed at least 2 of them. -If you know Java and Cocoa your name could be on this list! [Get involved!](HelpWanted.md). This project is now maintained by [iterate GmbH](https://iterate.ch/). - -## Projects using Rococoa - -_Make sure you comply with the GNU Lesser General Public License when releasing an application that uses Rococoa._ - - * [Cyberduck](https://github.com/iterate-ch/cyberduck) - Libre file transfer client for macOS and Windows. Command line interface (CLI) for Linux, macOS and Windows. - -## Usage -### Maven Artifacts (LGPL) -Maven artifacts are available in a repository hosted on Amazon S3. - -1. Use the following Maven configuration in your project POM to reference artifacts - ```xml - - - maven.cyberduck.io-release - https://s3.eu-west-1.amazonaws.com/repo.maven.cyberduck.io/releases - default - - true - - - false - - - - ``` - -2. Add the dependencies as follows - ``` - - org.rococoa - rococoa-core - 0.9.1 - - - org.rococoa - librococoa - 0.9.1 - dylib - runtime - - ``` - -## Documentation - * [Building](Building.md) - * [How To](HowTo.md) - * [Take the Whistlestop Tour](WhistlestopTour.md) - * [Limitations](Limitations.md) - * [Memory](Memory.md) - * [NIBLoading](NIBLoading.md) - * [ObjcMsgSend](ObjcMsgSend.md) - * [Quicktime](Quicktime.md) - * [Help Wanted](HelpWanted.md) - * [How To](HowTo.md) - -## Change History -### 0.9.1 -* Support for Apple silicon -### 0.8.0 -* Rewrite implementation of cstringPtrForSelector to be failsave using `CFStringGetMaximumSizeForEncoding` -### 0.7.0 -### 0.5.0 -### 0.3.0 -* Functioning 64-bit (and hence Java 6) support - thanks to Paul Loy for fixes and discussions, and Andy Thompson for NSInteger et al -* We should now correctly l small structs as return values, not just NSSize! -* Improved NSDictionary -* Support for JNA-3.0.4 -### 0.2.0 -* Much more rigorous memory management. -* Selectors are now cached on the Java side. -* Fixed problem #9 where we could only have one delegate or notification - thanks to Adrian Ross for diagnosis and fix. -* Much expanded set of parameter and return types for delegates and notifications - thanks to Andy Thompson for suggestions and help. -* Fix defect #10 where delegates and notifications failed after the autorelease - pool is released. Now use Rococoa.proxy rather than wrap. -* Now use JNA-3.0.3 (NB slightly patched, please make sure that Rococoa precedes - JNA in the classpath - -### 0.1.4 -* Reworked CFString handling to use UTF-8 and hence support extended characters. -* Now support delegates and notifications, using Rococoa.wrap(Object) - -### 0.1.3 -* Now ship a Universal Binary dylib - -### 0.1.2 -* Added LGPL licence files and these release notes. - -### 0.1.1 -* Changes to allow the checked-out code to build. - -### 0.1.0 -* First published to dev.java.net. \ No newline at end of file diff --git a/rococoa/pom.xml b/rococoa/pom.xml deleted file mode 100644 index 83d17ca5..00000000 --- a/rococoa/pom.xml +++ /dev/null @@ -1,343 +0,0 @@ - - - 4.0.0 - org.rococoa - rococoa-parent - pom - 0.10.1-SNAPSHOT - Rococoa Parent Project - https://github.com/iterate-ch/rococoa - - - org.sonatype.oss - oss-parent - 9 - - - - 1.8 - 1.8 - - - - - rococoa-auto - rococoa-cocoa - rococoa-contrib - rococoa-core - rococoa-core/dylib - rococoa-functionaltest - - - - - oneeyedmen - Duncan McGregor - duncan@oneeyedmen.com - - Owner - - - - lordpixel - Andrew Thompson - lordpixel@mac.com - - Owner - - - - dkocher - David Kocher - post@iterate.ch - iterate GmbH - - Committer - - - - keteracel - Paul Loy - keteracel@gmail.com - - Committer - - - - ochafik - Olivier Chafik - olivier.chafik@gmail.com - - Committer - - - - - - https://github.com/iterate-ch/rococoa - scm:git:git@github.com:iterate-ch/rococoa.git - scm:git:git@github.com:iterate-ch/rococoa.git - HEAD - - - - - maven.cyberduck.io-release - s3://repo.maven.cyberduck.io/releases/ - default - - - maven.cyberduck.io-snapshot - s3://repo.maven.cyberduck.io/snapshots/ - - - - - - LGPL 3 - http://www.gnu.org/licenses/lgpl-3.0.txt - repo - - - - - - - org.rococoa - rococoa-core - ${project.version} - - - org.rococoa - librococoa - dylib - ${project.version} - - - org.rococoa - librococoa - test - dylib - ${project.version} - - - org.rococoa - rococoa-cocoa - ${project.version} - - - org.rococoa - rococoa-core - test-jar - ${project.version} - - - org.rococoa - rococoa-contrib - ${project.version} - - - org.rococoa - rococoa-functionaltest - ${project.version} - - - net.java.dev.jna - jna - 5.17.0 - - - net.bytebuddy - byte-buddy - 1.17.5 - - - - - - - - org.springframework.build - aws-maven - 5.0.0.RELEASE - - - - - org.apache.maven.plugins - maven-source-plugin - 3.3.1 - - - attach-sources - - jar - - - - - - maven-resources-plugin - 3.3.1 - true - - UTF-8 - - - - maven-dependency-plugin - - - copy-dependencies-dylib-target - generate-sources - - copy-dependencies - - - ${project.build.directory} - dylib - false - true - - - - - - maven-surefire-plugin - - @{argLine}-Djava.library.path=${project.build.directory} - - ${project.build.directory} - - - ${project.build.directory} - - false - - - - - - - - maven-jar-plugin - 3.4.2 - - - maven-javadoc-plugin - 3.11.2 - - - maven-antrun-plugin - 3.1.0 - - - maven-surefire-plugin - 3.5.3 - - - maven-install-plugin - 3.1.4 - - - maven-deploy-plugin - 3.1.4 - - - maven-release-plugin - 3.1.1 - - -DskipTests - - - - maven-shade-plugin - 3.6.0 - - - package - - shade - - - - - *:*:dylib: - - - - - - - - maven-assembly-plugin - 3.7.1 - - - src/main/assembly/dist.xml - - - - - - single - - package - - - - - maven-dependency-plugin - 3.8.1 - - - org.codehaus.mojo - build-helper-maven-plugin - 3.6.1 - - - - - - - - junit - junit - 4.13.2 - test - - - - - - release-sign-artifacts - - - performRelease - true - - - - rococoa-core - - - - - org.apache.maven.plugins - maven-gpg-plugin - 3.2.7 - - - sign-artifacts - verify - - sign - - - - - - - - - \ No newline at end of file diff --git a/rococoa/rococoa-auto/pom.xml b/rococoa/rococoa-auto/pom.xml deleted file mode 100644 index b1b1a1a0..00000000 --- a/rococoa/rococoa-auto/pom.xml +++ /dev/null @@ -1,101 +0,0 @@ - - - 4.0.0 - rococoa-auto - jar - Rococoa Autogenerated Cocoa Package - https://github.com/iterate-ch/rococoa - - - org.rococoa - rococoa-parent - 0.10.1-SNAPSHOT - - - - 0.12 - - - - - com.nativelibs4java - jnaerator-runtime - ${jnaerator.version} - - - org.rococoa - rococoa-core - - - - - - - com.nativelibs4java - maven-jnaerator-plugin - ${jnaerator.version} - - src/main/java - - - - maven-shade-plugin - - - org.apache.maven.plugins - maven-deploy-plugin - - true - - - - - - - - - maven-javadoc-plugin - - 128m - 512 - true - true - 1.8 - false - public - - http://java.sun.com/javase/6/docs/api/ - https://javadoc.io/doc/net.java.dev.jna/jna - http://jnaerator.sourceforge.net/sites/jnaerator/apidocs - http://jnaerator.sourceforge.net/sites/jnaerator-runtime/apidocs - - - - - - - - - sonatype-oss-public - https://oss.sonatype.org/content/groups/public - - true - - - true - - - - - - sonatype-oss-public - https://oss.sonatype.org/content/groups/public - - true - - - true - - - - \ No newline at end of file diff --git a/rococoa/rococoa-auto/regenerate b/rococoa/rococoa-auto/regenerate deleted file mode 100755 index 37947e87..00000000 --- a/rococoa/rococoa-auto/regenerate +++ /dev/null @@ -1 +0,0 @@ -MAVEN_OPTS=-Xmx4g mvn com.nativelibs4java:maven-jnaerator-plugin:generate && MAVEN_OPTS=-Xmx2g mvn package diff --git a/rococoa/rococoa-auto/src/main/jnaerator/config.jnaerator b/rococoa/rococoa-auto/src/main/jnaerator/config.jnaerator deleted file mode 100644 index 7771f323..00000000 --- a/rococoa/rococoa-auto/src/main/jnaerator/config.jnaerator +++ /dev/null @@ -1,13 +0,0 @@ --framework Foundation --framework AppKit -//-framework CoreFoundation -//-framework CoreGraphics - --root org.rococoa.cocoa -//-parseInOneChunk --runtime JNAerator - -//-o "$(DIR)/../java" // overwrite versioned files instead of writing to target/generated-sources/java - -//-v -//-choicesOut "$(DIR)/rococoa.choices" diff --git a/rococoa/rococoa-cocoa/pom.xml b/rococoa/rococoa-cocoa/pom.xml deleted file mode 100644 index 1f25ea02..00000000 --- a/rococoa/rococoa-cocoa/pom.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - 4.0.0 - rococoa-cocoa - jar - Rococoa Cocoa Mappings - https://github.com/iterate-ch/rococoa - - - org.rococoa - rococoa-parent - 0.10.1-SNAPSHOT - - - - - org.rococoa - rococoa-core - - - org.rococoa - rococoa-core - test-jar - test - - - org.rococoa - librococoa - test - dylib - test - - - - - - - src/test/resources - - - - - - maven-assembly-plugin - - - maven-dependency-plugin - - - org.apache.maven.plugins - maven-deploy-plugin - - true - - - - - diff --git a/rococoa/rococoa-cocoa/src/main/assembly/dist.xml b/rococoa/rococoa-cocoa/src/main/assembly/dist.xml deleted file mode 100644 index 458471c3..00000000 --- a/rococoa/rococoa-cocoa/src/main/assembly/dist.xml +++ /dev/null @@ -1,40 +0,0 @@ - - src - - tar.gz - zip - - - - target - dist - - *.jar - - - - target - lib - - *.jar - - - - src - - - src/main/doc - / - - * - - - - - - lib - false - runtime - - - \ No newline at end of file diff --git a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/carbon/FSRef.java b/rococoa/rococoa-cocoa/src/main/java/org/rococoa/carbon/FSRef.java deleted file mode 100644 index f50581d1..00000000 --- a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/carbon/FSRef.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.carbon; - -import com.sun.jna.PointerType; - -public class FSRef extends PointerType { -} diff --git a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/carbon/FSSpec.java b/rococoa/rococoa-cocoa/src/main/java/org/rococoa/carbon/FSSpec.java deleted file mode 100644 index b9d03ce8..00000000 --- a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/carbon/FSSpec.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.carbon; - -import com.sun.jna.PointerType; - -public class FSSpec extends PointerType { -} diff --git a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/appkit/AppKitLibrary.java b/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/appkit/AppKitLibrary.java deleted file mode 100644 index e0df2d82..00000000 --- a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/appkit/AppKitLibrary.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.appkit; - -import org.rococoa.cocoa.foundation.NSRect; - -import com.sun.jna.Library; -import com.sun.jna.Native; - -/** - * @author paulloy - */ -public interface AppKitLibrary extends Library { - - AppKitLibrary INSTANCE = Native.load("AppKit", AppKitLibrary.class); - - void NSRectFill (NSRect aRect); - -} diff --git a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/appkit/NSColor.java b/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/appkit/NSColor.java deleted file mode 100644 index b3bbeb74..00000000 --- a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/appkit/NSColor.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.appkit; - - -import org.rococoa.cocoa.foundation.NSObject; -import org.rococoa.Rococoa; - -/** - * @author paulloy - */ -public abstract class NSColor extends NSObject { - public static final _Class CLASS = Rococoa.createClass("NSColor", _Class.class); //$NON-NLS-1$ - public abstract class _Class extends NSObject._class_ { - public abstract NSColor clearColor(); - } - - public abstract void set(); -} diff --git a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/appkit/NSOpenPanel.java b/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/appkit/NSOpenPanel.java deleted file mode 100644 index ff278d14..00000000 --- a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/appkit/NSOpenPanel.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.appkit; - -import org.rococoa.ID; - -import org.rococoa.cocoa.foundation.NSObject; -import org.rococoa.Rococoa; -import org.rococoa.RunOnMainThread; -import org.rococoa.cocoa.foundation.NSArray; -import org.rococoa.cocoa.foundation.NSString; - -public @RunOnMainThread abstract class NSOpenPanel extends NSObject { - - public static final int NSOKButton = 1; - public static final int NSCancelButton = 0; - - public static final _Class CLASS = Rococoa.createClass("NSOpenPanel", _Class.class); //$NON-NLS-1$ - public @RunOnMainThread abstract class _Class extends NSObject._class_ { - public abstract NSOpenPanel openPanel(); - } - - public abstract int runModalForTypes(NSArray arrayOfTypeStrings); - - public abstract NSString filename(); - public abstract NSArray filenames(); - - public abstract void setDelegate(ID ocProxy); -} diff --git a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/foundation/NSCoder.java b/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/foundation/NSCoder.java deleted file mode 100644 index 9a5ca97f..00000000 --- a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/foundation/NSCoder.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.foundation; - -import org.rococoa.cocoa.foundation.NSObject; - -/** - * @author paulloy - */ -public abstract class NSCoder extends NSObject { - - public abstract void encodeObject_forKey (NSObject objv, NSString key); - public abstract NSObject decodeObjectForKey(NSString mountainNameString); - -} diff --git a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/foundation/NSDateFormatter.java b/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/foundation/NSDateFormatter.java deleted file mode 100644 index c0108dc1..00000000 --- a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/foundation/NSDateFormatter.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.foundation; - -import org.rococoa.cocoa.foundation.NSObject; -import org.rococoa.Rococoa; - -public abstract class NSDateFormatter extends NSFormatter { - public static final _Class CLASS = Rococoa.createClass("NSDateFormatter", _Class.class); //$NON-NLS-1$ - public abstract class _Class extends NSObject._class_ { - } - - public static final int NSDateFormatterNoStyle = 0; - public static final int NSDateFormatterShortStyle = 1; - public static final int NSDateFormatterMediumStyle = 2; - public static final int NSDateFormatterLongStyle = 3; - public static final int NSDateFormatterFullStyle = 4; - - public abstract void setDateStyle(int nsDateFormatterStyle); - public abstract void setTimeStyle(int nsDateFormatterStyle); - public abstract void setLocale(NSLocale locale); - public abstract NSString stringFromDate(NSDate date); - -} diff --git a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/foundation/NSFormatter.java b/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/foundation/NSFormatter.java deleted file mode 100644 index da72bbf8..00000000 --- a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/foundation/NSFormatter.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.foundation; - -import org.rococoa.cocoa.foundation.NSObject; - -public abstract class NSFormatter extends NSObject { - -} diff --git a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/foundation/NSLocale.java b/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/foundation/NSLocale.java deleted file mode 100644 index 87ce0af7..00000000 --- a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/foundation/NSLocale.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.foundation; - - -import org.rococoa.cocoa.foundation.NSObject; -import org.rococoa.Rococoa; - -public abstract class NSLocale extends NSObject { - public static final _Class CLASS = Rococoa.createClass("NSLocale", _Class.class); //$NON-NLS-1$ - public abstract class _Class extends NSObject._class_ { - public abstract NSLocale autoupdatingCurrentLocale(); - } -} diff --git a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/foundation/NSTimer.java b/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/foundation/NSTimer.java deleted file mode 100644 index 00c25e84..00000000 --- a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/foundation/NSTimer.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.foundation; - -import org.rococoa.cocoa.foundation.NSObject; - -public abstract class NSTimer extends NSObject { - -} diff --git a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/qtkit/QTKit.java b/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/qtkit/QTKit.java deleted file mode 100644 index c864cc9c..00000000 --- a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/qtkit/QTKit.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.qtkit; - -import com.sun.jna.Library; -import com.sun.jna.Native; - -public interface QTKit extends Library { - - QTKit instance = Native.load("QTKit", QTKit.class); - -} diff --git a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/qtkit/QTMedia.java b/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/qtkit/QTMedia.java deleted file mode 100755 index b148d633..00000000 --- a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/qtkit/QTMedia.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.qtkit; - -import org.rococoa.ID; -import org.rococoa.cocoa.foundation.NSObject; -import org.rococoa.RunOnMainThread; -import org.rococoa.cocoa.foundation.NSDictionary; - -import com.sun.jna.Pointer; - -public @RunOnMainThread abstract class QTMedia extends NSObject { - - public static final String QTMediaDurationAttribute = "QTMediaDurationAttribute"; - public static final String QTMediaTimeScaleAttribute = "QTMediaTimeScaleAttribute"; - public static final String QTMediaSampleCountAttribute = "QTMediaSampleCountAttribute"; - - public static final String QTMediaTypeAttribute = "QTMediaTypeAttribute"; - public static final String QTMediaTypeVideo = "vide"; - public static final String QTMediaTypeSound = "soun"; - public static final String QTMediaTypeText = "text"; - public static final String QTMediaTypeBase = "gnrc"; - public static final String QTMediaTypeMPEG = "MPEG"; - public static final String QTMediaTypeMusic = "musi"; - public static final String QTMediaTypeTimeCode = "tmcd"; - //etc... - - public abstract QTTrack track(); - - public abstract boolean hasCharacteristic(String characteristic); - public abstract boolean hasCharacteristic(ID characteristic); - - public abstract NSObject attributeForKey(String key); - public abstract NSObject attributeForKey(ID key); - public abstract void setAttribute_forKey(NSObject attribute, String key); - public abstract void setAttribute_forKey(NSObject attribute, ID key); - - public abstract NSDictionary mediaAttributes(); - public abstract void setMediaAttributes(NSDictionary attributes); - - public abstract Pointer quickTimeMedia(); -} diff --git a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/qtkit/QTMovie.java b/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/qtkit/QTMovie.java deleted file mode 100755 index 3083ce8c..00000000 --- a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/qtkit/QTMovie.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.qtkit; - -import java.io.File; -import java.util.concurrent.Callable; - -import org.rococoa.Foundation; -import org.rococoa.ID; - -import org.rococoa.cocoa.foundation.NSObject; -import org.rococoa.ObjCObjectByReference; -import org.rococoa.Rococoa; -import org.rococoa.RunOnMainThread; -import org.rococoa.cocoa.foundation.NSArray; -import org.rococoa.cocoa.foundation.NSDictionary; -import org.rococoa.cocoa.foundation.NSImage; -import org.rococoa.cocoa.foundation.NSString; - -import com.sun.jna.Pointer; - -/** - * Wrapper for QTKit QTMovie. - * - * For a discussion on threading and QT see - * TN2125 - * - * @author duncan - * - */ -public @RunOnMainThread abstract class QTMovie extends NSObject { - - // Loading the QTMovie class has to happen on the main thread - private static final _Class CLASS = - Foundation.callOnMainThread(new Callable<_Class>() { - public _Class call() throws Exception { - return Rococoa.wrap(Foundation.getClass("QTMovie"), _Class.class); //$NON-NLS-1$ - } - }); - - // Creating instances has to happen on the main thread - public static @RunOnMainThread abstract class _Class implements org.rococoa.ObjCClass {//extends NSObject._class_ { - public abstract QTMovie movie(); - public abstract QTMovie movieWithFile_error(String fileName, ObjCObjectByReference errorReference); - public abstract QTMovie movieWithAttributes_error(NSDictionary attributes, ObjCObjectByReference errorReference); - public abstract QTMovie movieWithQuickTimeMovie_disposeWhenDone_error(Pointer movie, boolean b, ObjCObjectByReference errorReference); - } - - public static final String QTMovieTimeScaleAttribute = "QTMovieTimeScaleAttribute"; //$NON-NLS-1$ - public static final String QTMovieFileNameAttribute = "QTMovieFileNameAttribute"; //$NON-NLS-1$ - public static final String QTMovieOpenAsyncOKAttribute = "QTMovieOpenAsyncOKAttribute"; //$NON-NLS-1$ - public static final String QTMoviePlaysSelectionOnlyAttribute = "QTMoviePlaysSelectionOnlyAttribute"; //$NON-NLS-1$ - public static final String QTMovieLoadStateAttribute = "QTMovieLoadStateAttribute"; //$NON-NLS-1$ - public static final long QTMovieLoadStateError = -1L; - public static final long QTMovieLoadStateLoading = 1000L; - public static final long QTMovieLoadStateComplete = 100000L; - - public static final String QTMovieFlatten = "QTMovieFlatten"; //$NON-NLS-1$ - public static final String QTMovieExport = "QTMovieExport"; //$NON-NLS-1$ - public static final String QTMovieExportType = "QTMovieExportType"; //$NON-NLS-1$ - public static final String QTMovieEditableAttribute = "QTMovieEditableAttribute"; //$NON-NLS-1$ - - public static QTMovie movie() { - return CLASS.movie(); - } - - public static QTMovie movieWithFile_error(File file, ObjCObjectByReference errorReference) { - return movieWithFile_error(file.getAbsolutePath(), errorReference); - } - public static QTMovie movieWithFile_error(String fileName, ObjCObjectByReference errorReference) { - return CLASS.movieWithFile_error(fileName, errorReference); - } - public static QTMovie movieWithAttributes_error(NSDictionary attributes, ObjCObjectByReference errorReference) { - return CLASS.movieWithAttributes_error(attributes, errorReference); - } - public static QTMovie movieWithQuickTimeMovie_disposeWhenDone_error(Pointer movie, boolean b, ObjCObjectByReference errorReference) { - return CLASS.movieWithQuickTimeMovie_disposeWhenDone_error(movie, b, errorReference); - } - - public abstract QTTime duration(); - - public abstract void gotoBeginning(); - - public abstract void gotoEnd(); - - public abstract void play(); - - public abstract void stop(); - - public abstract void stepBackward(); - - public abstract void stepForward(); - - public abstract void setCurrentTime(QTTime time); - - public abstract QTTime currentTime(); - - public abstract void setRate(float speed); - - public abstract float rate(); - - public abstract NSImage frameImageAtTime(QTTime time); - - public abstract NSObject attributeForKey(NSString key); - public abstract NSObject attributeForKey(String key); - public abstract NSObject attributeForKey(ID keyId); - - public abstract void setAttribute_forKey(NSObject attribute, NSString key); - public abstract void setAttribute_forKey(NSObject attribute, String key); - public abstract void setAttribute_forKey(NSObject attribute, ID key); - - public abstract void insertSegmentOfMovie_timeRange_atTime(QTMovie movie, QTTimeRange range, QTTime time); - public abstract void insertSegmentOfMovie_fromRange_scaledToRange(QTMovie movie, QTTimeRange srcRange, QTTimeRange dstRange); - public abstract void insertEmptySegmentAt(QTTimeRange range); - - public abstract NSArray tracksOfMediaType(String mediaTypeVideo); - public abstract NSArray tracksOfMediaType(ID mediaTypeVideo); - public abstract NSArray tracks(); - - public abstract void setSelection(QTTimeRange timeRange); - - public abstract QTTime selectionStart(); - - public abstract QTTime selectionDuration(); - - public abstract QTTime selectionEnd(); - - public abstract void writeToFile_withAttributes(String filename, NSDictionary attributes); - - public abstract Pointer quickTimeMovie(); - -} diff --git a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/qtkit/QTMovieView.java b/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/qtkit/QTMovieView.java deleted file mode 100644 index 8eac4858..00000000 --- a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/qtkit/QTMovieView.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.qtkit; - -import java.util.concurrent.Callable; - -import org.rococoa.Foundation; -import org.rococoa.cocoa.foundation.NSObject; -import org.rococoa.Rococoa; -import org.rococoa.RunOnMainThread; - - -public @RunOnMainThread abstract class QTMovieView extends NSObject { - - public static final _Class CLASS = new _Class(); - - public static class _Class { - public QTMovieView create() { - return Foundation.callOnMainThread(new Callable() { - public QTMovieView call() throws Exception { - return Rococoa.create("QTMovieView", QTMovieView.class); //$NON-NLS-1$ - }}); - } - } - - public abstract void setMovie(QTMovie movie); - - public abstract void setControllerVisible(boolean isVisible); - - public abstract void setPreservesAspectRatio(boolean b); - - public abstract void play(NSObject sender); - - public abstract QTMovie movie(); - -} diff --git a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/qtkit/QTTime.java b/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/qtkit/QTTime.java deleted file mode 100644 index 4f4f4b0d..00000000 --- a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/qtkit/QTTime.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.qtkit; - -import com.sun.jna.Structure; - -//long long timeValue; long timeScale; long flags; -public class QTTime extends QTTimeByReference implements Structure.ByValue { - - public QTTime() { - super(); - } - - public QTTime(long timeValue, int timeScale, int flags) { - super(timeValue, timeScale, flags); - } - - public QTTime(long timeValue, int timeScale) { - super(timeValue, timeScale); - } - -} diff --git a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/qtkit/QTTimeByReference.java b/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/qtkit/QTTimeByReference.java deleted file mode 100644 index bc453f45..00000000 --- a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/qtkit/QTTimeByReference.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.qtkit; - -import java.util.Arrays; -import java.util.List; - -import com.sun.jna.NativeLong; -import com.sun.jna.Structure; - -public class QTTimeByReference extends Structure { - - public long timeValue; - public NativeLong timeScale; - public NativeLong flags; - - public QTTimeByReference() { - } - - public QTTimeByReference(long timeValue, int timeScale) { - this(timeValue, timeScale, 0); - } - - public QTTimeByReference(long timeValue, int timeScale, int flags) { - this.timeValue = timeValue; - this.timeScale = new NativeLong(timeScale); - this.flags = new NativeLong(); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + flags.intValue(); - result = prime * result + timeScale.intValue(); - result = prime * result + (int) (timeValue ^ (timeValue >>> 32)); - return result; - } - - @Override - public boolean equals(Object obj) { - if(this == obj) { - return true; - } - if(obj == null) { - return false; - } - if(getClass() != obj.getClass()) { - return false; - } - final QTTime other = (QTTime) obj; - if(!flags.equals(other.flags)) { - return false; - } - if(!timeScale.equals(other.timeScale)) { - return false; - } - if(timeValue != other.timeValue) { - return false; - } - return true; - } - - @Override - protected List getFieldOrder() { - return Arrays.asList("timeValue", "timeScale", "flags"); - } -} diff --git a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/qtkit/QTTimeRange.java b/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/qtkit/QTTimeRange.java deleted file mode 100644 index a8a8281a..00000000 --- a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/qtkit/QTTimeRange.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.qtkit; - -import java.util.Arrays; -import java.util.List; - -import com.sun.jna.Structure; - -public class QTTimeRange extends Structure implements Structure.ByValue { - - public QTTime time; - public QTTime duration; - - public QTTimeRange() { - } - - public QTTimeRange(QTTime time, QTTime duration) { - this.time = time; - this.duration = duration; - } - - @Override - protected List getFieldOrder() { - return Arrays.asList("time", "duration"); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result - + ((duration == null) ? 0 : duration.hashCode()); - result = prime * result + ((time == null) ? 0 : time.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if(this == obj) { - return true; - } - if(!super.equals(obj)) { - return false; - } - if(getClass() != obj.getClass()) { - return false; - } - final QTTimeRange other = (QTTimeRange) obj; - if(duration == null) { - if(other.duration != null) { - return false; - } - } - else if(!duration.equals(other.duration)) { - return false; - } - if(time == null) { - if(other.time != null) { - return false; - } - } - else if(!time.equals(other.time)) { - return false; - } - return true; - } - -} diff --git a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/qtkit/QTTrack.java b/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/qtkit/QTTrack.java deleted file mode 100755 index e829a29e..00000000 --- a/rococoa/rococoa-cocoa/src/main/java/org/rococoa/cocoa/qtkit/QTTrack.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.qtkit; - -import org.rococoa.ID; -import org.rococoa.cocoa.foundation.NSObject; -import org.rococoa.RunOnMainThread; -import org.rococoa.cocoa.foundation.NSDictionary; - -import com.sun.jna.Pointer; - -public @RunOnMainThread abstract class QTTrack extends NSObject { - - public static final String QTTrackTimeScaleAttribute = "QTTrackTimeScaleAttribute"; - public static final String QTTrackBoundsAttribute = "QTTrackBoundsAttribute"; - public static final String QTTrackDimensionsAttribute = "QTTrackDimensionsAttribute"; - - public abstract QTMovie movie(); - - public abstract QTMedia media(); - - public abstract boolean isEnabled(); - public abstract void setEnabled(boolean enabled); - - public abstract float volume(); - public abstract void setVolume(float level); - public abstract NSObject attributeForKey(String key); - public abstract NSObject attributeForKey(ID key); - public abstract void setAttribute_forKey(NSObject attribute, String key); - public abstract NSDictionary trackAttributes(); - public abstract void setTrackAttributes(NSDictionary trackAttributes); - public abstract Pointer quickTimeTrack(); - -} diff --git a/rococoa/rococoa-cocoa/src/test/java/org/rococoa/cocoa/NSOpenPanelTest.java b/rococoa/rococoa-cocoa/src/test/java/org/rococoa/cocoa/NSOpenPanelTest.java deleted file mode 100644 index 5479cd93..00000000 --- a/rococoa/rococoa-cocoa/src/test/java/org/rococoa/cocoa/NSOpenPanelTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa; - -import java.io.File; - -import javax.swing.JFrame; - -import static org.junit.Assert .*; -import org.junit.Ignore; -import org.junit.Test; -import org.rococoa.ID; -import org.rococoa.cocoa.foundation.NSObject; -import org.rococoa.Rococoa; -import org.rococoa.ObjCObject; -import org.rococoa.cocoa.appkit.NSOpenPanel; -import org.rococoa.cocoa.foundation.NSString; -import org.rococoa.test.RococoaTestCase; - -public class NSOpenPanelTest extends RococoaTestCase { - - // Requires user to select a text file somewhere downtree from ~ - @Test - @Ignore - public void testShow() { - new JFrame().setVisible(true); // otherwise no panel - NSOpenPanel panel = NSOpenPanel.CLASS.openPanel(); - - // Keep this reference! - ObjCObject ocProxy = Rococoa.proxy(new Object() { - @SuppressWarnings("unused") - public boolean panel_shouldShowFilename(ID panel, String filename) { - char initialChar = new File(filename).getName().toLowerCase().charAt(0); - return initialChar % 2 == 0; - } - }); - - panel.setDelegate(ocProxy.id()); - int button = panel.runModalForTypes(null); -// or, eg -// NSArray.CLASS.arrayWithObjects( -// NSString.stringWithString("txt"), null)); - NSString filenameAsNSString = panel.filename(); - if (button == NSOpenPanel.NSOKButton) { - assertTrue(filenameAsNSString.toString().startsWith("/Users")); - } else { - assertEquals(NSOpenPanel.NSCancelButton, button); - assertNull(filenameAsNSString); - } - } -} diff --git a/rococoa/rococoa-cocoa/src/test/java/org/rococoa/cocoa/qtkit/QTMovieTest.java b/rococoa/rococoa-cocoa/src/test/java/org/rococoa/cocoa/qtkit/QTMovieTest.java deleted file mode 100644 index 963d2a3f..00000000 --- a/rococoa/rococoa-cocoa/src/test/java/org/rococoa/cocoa/qtkit/QTMovieTest.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.qtkit; - -import com.sun.jna.Platform; -import org.junit.Ignore; -import org.junit.Test; -import org.rococoa.ObjCClass; -import org.rococoa.ObjCObjectByReference; -import org.rococoa.Rococoa; -import org.rococoa.cocoa.foundation.*; -import org.rococoa.test.RococoaTestCase; - -import java.io.File; - -import static org.junit.Assert.*; - - -@Ignore -public class QTMovieTest extends RococoaTestCase { - - static String testMovieFile = "src/test/resources/test.mov"; - static int testMovieTimeScale = 1000; - - static { - @SuppressWarnings("unused") - QTKit instance = QTKit.instance; - } - - @Test - public void test() { - File file = new File(testMovieFile); - ObjCObjectByReference errorReference = new ObjCObjectByReference(); - QTMovie movie = QTMovie.movieWithFile_error(file, errorReference); - - assertNotNull(movie); - assertNull(errorReference.getValueAs(NSError.class));//.id().isNull()); - QTTime time3 = movie.currentTime(); - assertEquals(testMovieTimeScale, time3.timeScale.intValue()); - - movie.setSelection(new QTTimeRange(new QTTime(50, testMovieTimeScale), new QTTime(100, testMovieTimeScale))); - assertEquals(new QTTime(50, testMovieTimeScale), movie.selectionStart()); - assertEquals(new QTTime(100, testMovieTimeScale), movie.selectionDuration()); - assertEquals(new QTTime(150, testMovieTimeScale), movie.selectionEnd()); - } - - @Test - public void testError() { - File file = new File("NOSUCH"); - ObjCObjectByReference errorReference = new ObjCObjectByReference(); - QTMovie movie = QTMovie.movieWithFile_error(file, errorReference); - assertNull(movie); - NSError error = errorReference.getValueAs(NSError.class); - assertEquals(-2000, error.code().intValue()); - } - - @Test - public void testAttributeForKey() throws Exception { - QTMovie movie = loadMovie(testMovieFile); - NSObject attribute = movie.attributeForKey(QTMovie.QTMovieTimeScaleAttribute); - - assertTrue(attribute.isKindOfClass(ObjCClass.CLASS.classWithName("NSNumber"))); - assertFalse(attribute.isKindOfClass(ObjCClass.CLASS.classWithName("NSString"))); - - //need to cast 'rococoa style' - assertEquals(testMovieTimeScale, Rococoa.cast(attribute, NSNumber.class).intValue()); - } - - private QTMovie loadMovie(String filename) throws Exception { -// NSDictionary attributes = NSDictionary.CLASS.dictionaryWithObjectsAndKeys( -// NSString.CLASS.stringWithString(filename), -// NSString.CLASS.stringWithString(QTMovie.QTMovieFileNameAttribute), -// -// NSNumber.CLASS.numberWithBool(false), -// NSString.CLASS.stringWithString(QTMovie.QTMovieOpenAsyncOKAttribute), -// -// null); - - NSMutableDictionary attributes = NSMutableDictionary.CLASS.dictionaryWithCapacity(2); - attributes.setValue_forKey(NSString.CLASS.stringWithString(new File(filename).getCanonicalPath()), - QTMovie.QTMovieFileNameAttribute); - attributes.setValue_forKey(NSNumber.CLASS.numberWithBool(false), - QTMovie.QTMovieOpenAsyncOKAttribute); - - QTMovie movie = QTMovie.movieWithAttributes_error(attributes, null); - - assertNotNull(movie); - assertNotNull(movie.id()); - return movie; - } - - @Test - public void testGetTracks() throws Exception { - QTMovie movie = loadMovie(testMovieFile); - NSArray tracks = movie.tracks(); - assertEquals(2, tracks.count()); - - NSArray pictureTracks = movie.tracksOfMediaType(QTMedia.QTMediaTypeVideo); - assertEquals(1, pictureTracks.count()); - - NSArray soundTracks = movie.tracksOfMediaType(QTMedia.QTMediaTypeSound); - assertEquals(1, soundTracks.count()); - - NSArray mpegTracks = movie.tracksOfMediaType(QTMedia.QTMediaTypeMPEG); - assertEquals(0, mpegTracks.count()); - } - - @Test - public void testGetQTMedia() throws Exception { - QTMovie movie = loadMovie(testMovieFile); - QTTrack track = Rococoa.cast(movie.tracksOfMediaType(QTMedia.QTMediaTypeVideo).objectAtIndex(0), QTTrack.class); - QTMedia media = track.media(); - if (!Platform.is64Bit()) // quickTimeMedia is in a "#if !__LP64__" block - media.quickTimeMedia(); - } -} diff --git a/rococoa/rococoa-cocoa/src/test/resources/test.mov b/rococoa/rococoa-cocoa/src/test/resources/test.mov deleted file mode 100644 index b6ce6171..00000000 Binary files a/rococoa/rococoa-cocoa/src/test/resources/test.mov and /dev/null differ diff --git a/rococoa/rococoa-contrib/pom.xml b/rococoa/rococoa-contrib/pom.xml deleted file mode 100644 index 93ed4ce3..00000000 --- a/rococoa/rococoa-contrib/pom.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - 4.0.0 - rococoa-contrib - jar - Rococoa Contrib - https://github.com/iterate-ch/rococoa - - - org.rococoa - rococoa-parent - 0.10.1-SNAPSHOT - - - - - org.rococoa - rococoa-core - - - org.rococoa - rococoa-cocoa - - - org.rococoa - rococoa-core - test-jar - test - - - org.rococoa - librococoa - test - dylib - test - - - - - - - maven-assembly-plugin - - - maven-dependency-plugin - - - org.apache.maven.plugins - maven-deploy-plugin - - true - - - - - diff --git a/rococoa/rococoa-contrib/src/main/assembly/dist.xml b/rococoa/rococoa-contrib/src/main/assembly/dist.xml deleted file mode 100644 index 458471c3..00000000 --- a/rococoa/rococoa-contrib/src/main/assembly/dist.xml +++ /dev/null @@ -1,40 +0,0 @@ - - src - - tar.gz - zip - - - - target - dist - - *.jar - - - - target - lib - - *.jar - - - - src - - - src/main/doc - / - - * - - - - - - lib - false - runtime - - - \ No newline at end of file diff --git a/rococoa/rococoa-contrib/src/main/java/org/rococoa/cocoa/NSApplication.java b/rococoa/rococoa-contrib/src/main/java/org/rococoa/cocoa/NSApplication.java deleted file mode 100644 index b13a6753..00000000 --- a/rococoa/rococoa-contrib/src/main/java/org/rococoa/cocoa/NSApplication.java +++ /dev/null @@ -1,320 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa; - -import org.rococoa.ID; -import org.rococoa.ObjCClass; -import org.rococoa.Rococoa; -import org.rococoa.RunOnMainThread; -import org.rococoa.cocoa.foundation.NSImage; -import org.rococoa.cocoa.foundation.NSInteger; -import org.rococoa.cocoa.foundation.NSObject; - -/** - * NSApplication - * - * @author Harald Kuhr - * @author last modified by $Author: haraldk$ - * @version $Id: NSApplication.java,v 1.0 Mar 21, 2008 11:12:34 PM haraldk Exp$ - */ -@RunOnMainThread -public abstract class NSApplication extends NSObject { - - private static final _Class CLASS = Rococoa.createClass("NSApplication", _Class.class); //$NON-NLS-1$ - - // NOTE: This class should not run on main thread (deadlocks?) - private interface _Class extends ObjCClass { - NSApplication sharedApplication(); - } - - static public final NSApplication NSApp = NSApplication.CLASS.sharedApplication(); - - /* - Tasks -Getting the Application - - * + sharedApplication -*/ - static public NSApplication sharedApplication() { - return NSApp; - } - - public abstract void run(); - - public abstract void stop(ID sender); - - /* - -Configuring Applications - - * ? applicationIconImage - * ? setApplicationIconImage: - * ? delegate - * ? setDelegate: - * */ - - public abstract NSImage applicationIconImage(); - - public abstract void setApplicationIconImage(NSImage image); - - public abstract NSDockTile dockTile(); - - - public abstract ID delegate(); - - public abstract void setDelegate(ID delegate); - - public abstract NSWindow mainWindow(); - - /* - typedef enum { - NSCriticalRequest = 0, - NSInformationalRequest = 10 - } NSRequestUserAttentionType; - */ - - public static final int NSCriticalRequest = 0; - public static final int NSInformationalRequest = 10; - - /** - * Activating the application cancels the user attention request. - * A spoken notification will occur if spoken notifications are enabled. - * Sending requestUserAttention: to an application that is already active has no effect. - * - * If the inactive application presents a modal panel, this method will be invoked with - * NSCriticalRequest automatically. The modal panel is not brought to the front for an - * inactive application. - * - * @param requestType {@link #NSCriticalRequest} or {@link #NSInformationalRequest} - * @return The identifier for the request. - * You can use this value to cancel the request later using the {@link #cancelUserAttentionRequest} method. - */ - public abstract NSInteger requestUserAttention(int requestType); - - public abstract void cancelUserAttentionRequest(NSInteger request); - /* - -Launching Applications - - * ? finishLaunching - * ? applicationWillFinishLaunching: delegate method - * ? applicationDidFinishLaunching: delegate method - -Terminating Applications - - * ? terminate: - * ? applicationShouldTerminate: delegate method - * ? applicationShouldTerminateAfterLastWindowClosed: delegate method - * ? replyToApplicationShouldTerminate: - * ? applicationWillTerminate: delegate method - -Managing Active Status - - * ? isActive - * ? activateIgnoringOtherApps: - * ? applicationWillBecomeActive: delegate method - * ? applicationDidBecomeActive: delegate method - * ? deactivate - * ? applicationWillResignActive: delegate method - * ? applicationDidResignActive: delegate method - -Hiding Applications - - * ? hideOtherApplications: - * ? unhideAllApplications: - * ? applicationWillHide: delegate method - * ? applicationDidHide: delegate method - * ? applicationWillUnhide: delegate method - * ? applicationDidUnhide: delegate method - -Managing the Event Loop - - * ? isRunning - * ? run - * ? stop: - * ? runModalForWindow: - */ - public abstract int runModalForWindow(NSWindow window); - /* - * ? stopModal - * ? stopModalWithCode: - * ? abortModal - * ? beginModalSessionForWindow: - * ? runModalSession: - * ? modalWindow - * ? endModalSession: - * ? sendEvent: - -Handling Events - - * ? currentEvent - * ? nextEventMatchingMask:untilDate:inMode:dequeue: - * ? discardEventsMatchingMask:beforeEvent: - -Posting Events - - * ? postEvent:atStart: - -Managing Sheets - - * ? beginSheet:modalForWindow:modalDelegate:didEndSelector:contextInfo: - * ? endSheet: - * ? endSheet:returnCode: - -Managing Windows - - * ? keyWindow - * ? mainWindow - * ? windowWithWindowNumber: - * ? windows - * ? makeWindowsPerform:inOrder: - * ? applicationWillUpdate: delegate method - * ? applicationDidUpdate: delegate method - * ? applicationShouldHandleReopen:hasVisibleWindows: delegate method - -Minimizing Windows - - * ? miniaturizeAll: - -Hiding Windows - - * ? isHidden - * ? hide: - * ? unhide: - * ? unhideWithoutActivation - -Updating Windows - - * ? updateWindows - * ? setWindowsNeedUpdate: - -Managing Window Layers - - * ? preventWindowOrdering - * ? arrangeInFront: - -Accessing the Main Menu - - * ? mainMenu - * */ - - public abstract NSMenu mainMenu(); - - /* - * ? setMainMenu: - -Managing the Window Menu - - * ? windowsMenu - * ? setWindowsMenu: - * ? addWindowsItem:title:filename: - * ? changeWindowsItem:title:filename: - * ? removeWindowsItem: - * ? updateWindowsItem: - -Managing the Dock Menu - - * ? applicationDockMenu: delegate method - -Managing the Services Menu - - * ? registerServicesMenuSendTypes:returnTypes: - * ? servicesMenu - * ? setServicesMenu: - -Providing Services - - * ? validRequestorForSendType:returnType: - * ? servicesProvider - * ? setServicesProvider: - -Managing Panels - - * ? orderFrontColorPanel: - * ? orderFrontStandardAboutPanel: - * ? orderFrontStandardAboutPanelWithOptions: - * ? orderFrontCharacterPalette: - * ? runPageLayout: - -Displaying Help - - * ? showHelp: - * ? activateContextHelpMode: - -Displaying Errors - - * ? application:willPresentError: delegate method - -Managing Threads - - * + detachDrawingThread:toTarget:withObject: - -Posting Actions - - * ? tryToPerform:with: - * ? sendAction:to:from: - * ? targetForAction: - * ? targetForAction:to:from: - -Drawing Windows - - * ? context - -Logging Exceptions - - * ? reportException: - -Scripting - - * ? orderedDocuments - * ? orderedWindows - * ? application:delegateHandlesKey: delegate method - -Managing User Attention Requests - - * ? requestUserAttention: - * ? cancelUserAttentionRequest: - * ? replyToOpenOrPrint: - -Managing the Screen - - * ? applicationDidChangeScreenParameters: delegate method - -Opening Files - - * ? application:openFile: delegate method - * ? application:openFileWithoutUI: delegate method - * ? application:openTempFile: delegate method - * ? application:openFiles: delegate method - * ? applicationOpenUntitledFile: delegate method - * ? applicationShouldOpenUntitledFile: delegate method - -Printing - - * ? application:printFile: delegate method - * ? application:printFiles:withSettings:showPrintPanels: delegate method - -Deprecated - - * ? runModalForWindow:relativeToWindow: - * ? beginModalSessionForWindow:relativeToWindow: - * ? application:printFiles: delegate method Deprecated in Mac OS X v10.4 - */ -} diff --git a/rococoa/rococoa-contrib/src/main/java/org/rococoa/cocoa/NSDistributedNotificationCenter.java b/rococoa/rococoa-contrib/src/main/java/org/rococoa/cocoa/NSDistributedNotificationCenter.java deleted file mode 100644 index 62276d8a..00000000 --- a/rococoa/rococoa-contrib/src/main/java/org/rococoa/cocoa/NSDistributedNotificationCenter.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa; - -import org.rococoa.ObjCClass; -import org.rococoa.Rococoa; -import org.rococoa.cocoa.foundation.NSDictionary; -import org.rococoa.cocoa.foundation.NSObject; - -/** - * NSDistributedNotificationCenter - * - * @author Harald Kuhr - * @author last modified by $Author: haraldk$ - * @version $Id: NSDistributedNotificationCenter.java,v 1.0 Mar 26, 2009 5:47:51 PM haraldk Exp$ - */ -public abstract class NSDistributedNotificationCenter extends NSObject { - public static final _Class CLASS = Rococoa.createClass("NSDistributedNotificationCenter", _Class.class); //$NON-NLS-1$ - - public interface _Class extends ObjCClass { - NSDistributedNotificationCenter defaultCenter(); - } - - public static NSDistributedNotificationCenter defaultCenter() { - return CLASS.defaultCenter(); - } - - abstract void postNotificationName_object_userInfo_deliverImmediately(String notificationName, String notificationSender, NSDictionary userInfo, boolean deliverImmediately); - - public final void postNotification(String notificationName, String notificationSender, NSDictionary userInfo, boolean deliverImmediately) { - postNotificationName_object_userInfo_deliverImmediately(notificationName, notificationSender, userInfo, deliverImmediately); - } -} - diff --git a/rococoa/rococoa-contrib/src/main/java/org/rococoa/cocoa/NSDockTile.java b/rococoa/rococoa-contrib/src/main/java/org/rococoa/cocoa/NSDockTile.java deleted file mode 100644 index 45f9f770..00000000 --- a/rococoa/rococoa-contrib/src/main/java/org/rococoa/cocoa/NSDockTile.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa; - -import org.rococoa.cocoa.foundation.NSObject; - -/** - * @author Paul Loy - */ -//TODO: flesh this out -public abstract class NSDockTile extends NSObject { -} diff --git a/rococoa/rococoa-contrib/src/main/java/org/rococoa/cocoa/NSMenu.java b/rococoa/rococoa-contrib/src/main/java/org/rococoa/cocoa/NSMenu.java deleted file mode 100644 index 1280d1f1..00000000 --- a/rococoa/rococoa-contrib/src/main/java/org/rococoa/cocoa/NSMenu.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa; - -import org.rococoa.cocoa.foundation.NSObject; - -/** - * @author Paul Loy - */ -//TODO: flesh this out -public abstract class NSMenu extends NSObject { -} diff --git a/rococoa/rococoa-contrib/src/main/java/org/rococoa/cocoa/NSWindow.java b/rococoa/rococoa-contrib/src/main/java/org/rococoa/cocoa/NSWindow.java deleted file mode 100644 index 55e7f666..00000000 --- a/rococoa/rococoa-contrib/src/main/java/org/rococoa/cocoa/NSWindow.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa; - -import org.rococoa.cocoa.foundation.NSObject; - -/** - * @author Paul Loy - */ -//TODO: flesh this out -public abstract class NSWindow extends NSObject { -} diff --git a/rococoa/rococoa-contrib/src/main/java/org/rococoa/contrib/AbstractPropertyDictionary.java b/rococoa/rococoa-contrib/src/main/java/org/rococoa/contrib/AbstractPropertyDictionary.java deleted file mode 100755 index 78f4c645..00000000 --- a/rococoa/rococoa-contrib/src/main/java/org/rococoa/contrib/AbstractPropertyDictionary.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.contrib; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; - -import org.rococoa.Rococoa; -import org.rococoa.cocoa.foundation.NSDictionary; -import org.rococoa.cocoa.foundation.NSMutableDictionary; -import org.rococoa.cocoa.foundation.NSNumber; -import org.rococoa.cocoa.foundation.NSObject; -import org.rococoa.cocoa.foundation.NSString; - -/** Wraps an NSMutableDictionary with a set of keys defined by - * a Java enumeration. Also provides convenience methods for converting between - * Java and Cocoa types for the values. - * @param the enumerated type of the keys used with this dictionary - */ -public abstract class AbstractPropertyDictionary & NativeEnum> { - /**Used to convert dates between Cocoa and Java*/ - private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS Z"; - /** The data dictionary we are providing convenient access to*/ - private final NSMutableDictionary data; - - /** Construct a new empty dictionary with the given initial capacity. - * @param initialCapacity the initial capacity to use - */ - protected AbstractPropertyDictionary(int initialCapacity) { - this.data = NSMutableDictionary.dictionaryWithCapacity(initialCapacity); - } - /** Construct a new dictionary with the given dictionary. - * The dictionary is not copied. - * @param data the dictionary to use - */ - protected AbstractPropertyDictionary(final NSMutableDictionary data) { - this.data = data; - } - /** Construct a new dictionary with the given dictionary. - * The dictionary is copied into a mutable dictionary. - * @param data the dictionary to use - */ - protected AbstractPropertyDictionary(final NSDictionary data) { - this.data = NSMutableDictionary.dictionaryWithDictionary(data); - } - /** Get the underlying dictionary - * @return the dictionary being wrapped - */ - public NSMutableDictionary getData() { - return data; - } - - /** Get the value associated with the given key as a String - * @param key the key whose associated value will be returned - * @return the value associated with the key as a Java String - */ - public String getString(E key) { - return data.objectForKey(key.getNativeValue()).toString(); - } - - /** Set the value associated with the given key. - * @param key the key whose value will be set - * @param value the value to set - */ - public void setString(E key, String value) { - data.setValue_forKey(NSString.stringWithString(value), key.getNativeValue()); - } - - /** Get the value associated with the given key as an int - * @param key the key whose associated value will be returned - * @return the value associated with the key as a Java int - */ - public int getInt(E key) { - return getValueAsType(key, NSNumber.class).intValue(); - } - - /** Get the value associated with the given key as a short - * @param key the key whose associated value will be returned - * @return the value associated with the key as a Java short - */ - public short getShort(E key) { - return getValueAsType(key, NSNumber.class).shortValue(); - } - - /** Get the value associated with the given key as a boolean - * @param key the key whose associated value will be returned - * @return the value associated with the key as a Java boolean - */ - public boolean getBoolean(E key) { - return getInt(key) != 0; - } - - /** Get the value associated with the given key as a Date - * @param key the key whose associated value will be returned - * @return the value associated with the key as a Java Date - */ - public Date getDate(E key) { - String date = getString(key); - try { - return new SimpleDateFormat(DATE_FORMAT).parse(date); - } catch (ParseException ex) { - throw new IllegalStateException("Bad date found in property dictionary: " + date, ex); - } - } - - /** Set the value associated with the given key. - * @param key the key whose value will be set - * @param date the value to set - */ - public void setDate(E key, Date date) { - setString(key, new SimpleDateFormat(DATE_FORMAT).format(date)); - } - - /** Get the value associated with the given key as an enum - * @param key the key whose associated value will be returned - * @param nativeEnum the class of the enum, used to resolve native values to the corresponding Java enum values - * @return the value associated with the key as a Java Enum - * @param the type of enum to return - */ - public & NativeEnum> EN getEnum(Class nativeEnum, E key) { - return NativeEnum.Resolver.fromNative(nativeEnum, data.objectForKey(key.getNativeValue())); - } - - - /** Get the value associated with the given key as coercing it to the given type. - * @param key the key whose associated value will be returned - * @param type the subclass of NSObject that the value associated with key will be coerced to - * @return the value associated with the key coerced as into type - * @param the type to return - */ - public R getValueAsType(E key, Class type) { - NSObject result = data.objectForKey(key.getNativeValue()); - return result == null ? null : Rococoa.cast(result, type); - } - - - /** Set the value associated with the given key. - * @param key the key whose value will be set - * @param value the value to set - */ - public void setValue(E key, NSObject value) { - data.setValue_forKey(value, key.getNativeValue()); - } - - @Override - public String toString() { - StringBuilder result = new StringBuilder('[' + getClass().getSimpleName()); - result.append(": ").append(data).append(']'); - return result.toString(); - } -} diff --git a/rococoa/rococoa-contrib/src/main/java/org/rococoa/contrib/NativeEnum.java b/rococoa/rococoa-contrib/src/main/java/org/rococoa/contrib/NativeEnum.java deleted file mode 100755 index b0dd9d85..00000000 --- a/rococoa/rococoa-contrib/src/main/java/org/rococoa/contrib/NativeEnum.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ -package org.rococoa.contrib; - -import org.rococoa.cocoa.foundation.NSObject; - -/** An interface for Enumerations that derive their actual values from native code. - * e.g. many header files contain groups of related String or Integer - * constants that have may be passed into the APIs defined in the header. - * @param the type of native values associated with the enum - */ -public interface NativeEnum { - /** Get the native value associated with this enum value - * @return the native value associated with this enum value - */ - public N getNativeValue(); - - /** Given a native value, resolve the corresponding enum entry. - */ - public static final class Resolver { - private Resolver() {} - /** Given an enum class that implements NativeEnum, resolve the Java enum - * value that corresponds to the native value value - * @param the type of the Java enum - * @param nativeEnum the class of the Java enum - * @param value the native value to resolve - * @return the corresponding Java enum value - * @throws IllegalArgumentException if value does not correspond to any - * value in the Java enum - */ - public static & NativeEnum> E fromNative(Class nativeEnum, NSObject value) { - try { - @SuppressWarnings("unchecked") - E[] enumValues = (E[]) nativeEnum.getDeclaredMethod("values").invoke(null); - for (E e : enumValues) { - if ( e.getNativeValue().equals(value) ) { - return e; - } - } - } catch (Exception ex) { - throw new IllegalArgumentException("Unknown value " + value + " for " + nativeEnum.getSimpleName(), ex); - } - throw new IllegalArgumentException("Unknown value " + value + " for " + nativeEnum.getSimpleName()); - } - }; -} - diff --git a/rococoa/rococoa-contrib/src/main/java/org/rococoa/contrib/appkit/NSInvocationOperation.java b/rococoa/rococoa-contrib/src/main/java/org/rococoa/contrib/appkit/NSInvocationOperation.java deleted file mode 100644 index 3d8e9147..00000000 --- a/rococoa/rococoa-contrib/src/main/java/org/rococoa/contrib/appkit/NSInvocationOperation.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.contrib.appkit; - -import org.rococoa.ID; -import org.rococoa.ObjCClass; -import org.rococoa.Rococoa; -import org.rococoa.Selector; - -/** NSInvocationOperation from Cocoa. - * - */ -public abstract class NSInvocationOperation extends NSOperation { - public static final _Class CLASS = Rococoa.createClass(NSInvocationOperation.class.getSimpleName(), _Class.class); //$NON-NLS-1$ - public interface _Class extends ObjCClass { - public NSInvocationOperation alloc(); - } - - public abstract NSInvocationOperation initWithTarget_selector_object(ID target, Selector sel, ID arg); - - public abstract ID result(); -} \ No newline at end of file diff --git a/rococoa/rococoa-contrib/src/main/java/org/rococoa/contrib/appkit/NSOperation.java b/rococoa/rococoa-contrib/src/main/java/org/rococoa/contrib/appkit/NSOperation.java deleted file mode 100644 index fe2e5991..00000000 --- a/rococoa/rococoa-contrib/src/main/java/org/rococoa/contrib/appkit/NSOperation.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.contrib.appkit; - -import org.rococoa.ObjCClass; -import org.rococoa.Rococoa; -import org.rococoa.cocoa.foundation.NSObject; - -/** NSOperation from Cocoa. - * - */ -public abstract class NSOperation extends NSObject { - public static final _Class CLASS = Rococoa.createClass(NSOperation.class.getSimpleName(), _Class.class); //$NON-NLS-1$ - public interface _Class extends ObjCClass { - public NSOperation alloc(); - } - - public abstract NSOperation init(); - public abstract void start(); - public abstract void main(); - - public abstract void cancel(); - public abstract void waitUntilFinished(); - - public abstract boolean isCancelled(); - public abstract boolean isExecuting(); - public abstract boolean isFinished(); - public abstract boolean isConcurrent(); - public abstract boolean isReady(); -} diff --git a/rococoa/rococoa-contrib/src/main/java/org/rococoa/contrib/appkit/NSOperationQueue.java b/rococoa/rococoa-contrib/src/main/java/org/rococoa/contrib/appkit/NSOperationQueue.java deleted file mode 100644 index cf3d3c1d..00000000 --- a/rococoa/rococoa-contrib/src/main/java/org/rococoa/contrib/appkit/NSOperationQueue.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ -package org.rococoa.contrib.appkit; - -import org.rococoa.ObjCClass; -import org.rococoa.Rococoa; -import org.rococoa.cocoa.foundation.NSArray; -import org.rococoa.cocoa.foundation.NSInteger; -import org.rococoa.cocoa.foundation.NSObject; -import org.rococoa.cocoa.foundation.NSUInteger; - -/** NSOperationQueue from Cocoa; - * - */ -public abstract class NSOperationQueue extends NSObject { - public static final _Class CLASS = Rococoa.createClass(NSOperationQueue.class.getSimpleName(), _Class.class); //$NON-NLS-1$ - public static final int NSOperationQueueDefaultMaxConcurrentOperationCount = -1; - public interface _Class extends ObjCClass { - public NSOperationQueue alloc(); - public NSOperationQueue currentQueue(); - public NSOperationQueue mainQueue(); - } - - public abstract NSOperationQueue init(); - public abstract void addOperation(NSOperation operation); - public abstract void addOperations_waitUntilFinished(NSArray ops, boolean wait); - public abstract void cancelAllOperations(); - public abstract boolean isSuspended(); - public abstract NSInteger maxConcurrentOperationCount(); - public abstract String name(); - public abstract NSUInteger operationCount(); - public abstract NSArray operations(); - public abstract void setMaxConcurrentOperationCount(NSInteger count); - public abstract void setName(String name); - public abstract void setSuspended(boolean suspend); - public abstract void waitUntilAllOperationsAreFinished(); -} diff --git a/rococoa/rococoa-contrib/src/main/java/org/rococoa/contrib/appkit/NSSpeechDictionary.java b/rococoa/rococoa-contrib/src/main/java/org/rococoa/contrib/appkit/NSSpeechDictionary.java deleted file mode 100755 index 5acfb1ff..00000000 --- a/rococoa/rococoa-contrib/src/main/java/org/rococoa/contrib/appkit/NSSpeechDictionary.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.contrib.appkit; - -import org.rococoa.contrib.AbstractPropertyDictionary; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Locale; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import org.rococoa.contrib.NativeEnum; -import org.rococoa.Rococoa; - -import org.rococoa.cocoa.foundation.NSMutableArray; -import org.rococoa.cocoa.foundation.NSMutableDictionary; -import org.rococoa.cocoa.foundation.NSString; -import static org.rococoa.contrib.appkit.NSSpeechDictionary.SpeechDictionaryProperty.*; - -/** NSVoice encapsulates the properties of a speech synthesis dictionary, and can be - * used with NSSpeechSynthesizer to change the way words are pronounced. - * Dictionaries contain lists of entries that define how a given word or abbreviation - * should be pronounced. - * This class is a Rococoa enhancment designed to make it easier to work with - * speech dictionaries, there is no actual class with this name in Cocoa. - */ -public class NSSpeechDictionary extends AbstractPropertyDictionary { - /** Used to parse Locale strings, to convert Locales between Cocoa and Java*/ - private static final Pattern LOCALE_SPLITTER = Pattern.compile("([a-z]{2})_([A-Z]{2})_?([a-zA-Z1-9]*)"); - /** Defines the properties of a speech dictionary*/ - public enum SpeechDictionaryProperty implements NativeEnum { - LocaleIdentifier, - ModificationDate, - Pronunciations, - Abbreviations; - private final NSString value = NSString.getGlobalString(NSSpeechDictionary.class.getSimpleName() + name()); - public NSString getNativeValue() { - return value; - } - } - - /** Construct a new empty speech dictionary*/ - public NSSpeechDictionary() { - super(SpeechDictionaryProperty.values().length); - } - - /** Construct a new SpecchDictionary from existing data - * @param data used to initialize the speech dictionary, must contain valid keys and values for a speech dictionary - */ - public NSSpeechDictionary(final NSMutableDictionary data) { - super(data); - } - - /** Get the Locale associated with this dictionary - * @return the dictionary's Locale - */ - public Locale getLocaleIdentifier() { - String locale = getString(LocaleIdentifier); - Matcher m = LOCALE_SPLITTER.matcher(locale); - if ( m.matches() ) { - if ( m.group(2) == null ) { - throw new IllegalStateException("Could not parse locale: " + locale + " not enough fields."); - } - return m.group(3) != null ? new Locale(m.group(1), m.group(2), m.group(3)) : new Locale(m.group(1), m.group(2)); - } else { - throw new IllegalStateException("Could not parse locale, does not follow expected format: " + locale); - } - } - - public void setLocaleIdentifier(Locale localeIdentifier) { - setString(LocaleIdentifier, localeIdentifier.toString()); - } - - public Date getModificationDate() { - return getDate(ModificationDate); - } - - public void setModificationDate(Date modificationDate) { - setDate(ModificationDate, modificationDate); - } - - public List getPronunciations() { - NSMutableArray pronounciations = getValueAsType(Pronunciations, NSMutableArray.class); - List result = new ArrayList(pronounciations.count()); - for (int i=0; i < pronounciations.count(); i++) { - result.add(new Entry(Rococoa.cast(pronounciations.objectAtIndex(i), NSMutableDictionary.class))); - } - return Collections.unmodifiableList(result); - } - - public void setPronunciations(List pronounciations) { - NSMutableArray pronounciationDicts = NSMutableArray.CLASS.arrayWithCapacity(pronounciations.size()); - for (Entry e : pronounciations) { - pronounciationDicts.addObject(e.getData()); - } - setValue(Pronunciations, pronounciationDicts); - } - - public void addPronounciation(Entry pronounciation) { - NSMutableArray pronounciations = getValueAsType(Pronunciations, NSMutableArray.class); - if ( pronounciations == null ) { - pronounciations = NSMutableArray.CLASS.arrayWithCapacity(1); - } - pronounciations.addObject(pronounciation.getData()); - setValue(Pronunciations, pronounciations); - } - - public List getAbbreviations() { - NSMutableArray abbreviations = getValueAsType(Abbreviations, NSMutableArray.class); - List result = new ArrayList(abbreviations.count()); - for (int i=0; i < abbreviations.count(); i++) { - result.add(new Entry(Rococoa.cast(abbreviations.objectAtIndex(i), NSMutableDictionary.class))); - } - return Collections.unmodifiableList(result); - } - - public void setAbbreviations(List abbreviations) { - NSMutableArray abbreviationDicts = NSMutableArray.CLASS.arrayWithCapacity(abbreviations.size()); - for (Entry e : abbreviations) { - abbreviationDicts.addObject(e.getData()); - } - setValue(Abbreviations, abbreviationDicts); - } - - public void addAbbreviation(Entry abbreviation) { - NSMutableArray abbreviations = getValueAsType(Abbreviations, NSMutableArray.class); - if ( abbreviations == null ) { - abbreviations = NSMutableArray.CLASS.arrayWithCapacity(1); - } - abbreviations.addObject(abbreviation.getData()); - setValue(Abbreviations, abbreviations); - } - - @Override - public String toString() { - return "[NSSpeechDictionary: " + getData() + ']'; - } - - /** Represents a dictionary entry. - * Maps a spelling of a word to the associated phonemes that should be used to pronounce it. - */ - public static class Entry extends AbstractPropertyDictionary { - /**The properties associated with a dictionary entry*/ - public enum DictionaryEntryProperty implements NativeEnum{ - Spelling, - Phonemes; - private final NSString value = NSString.getGlobalString(NSSpeechDictionary.class.getSimpleName() + "Entry" + name()); - public NSString getNativeValue() { - return value; - } - } - public Entry() { - super(DictionaryEntryProperty.values().length); - } - public Entry(final NSMutableDictionary data) { - super(data); - } - public Entry(final String spelling, final String phonemes) { - this(NSMutableDictionary.dictionaryWithObjectsAndKeys( - NSString.stringWithString(phonemes), DictionaryEntryProperty.Phonemes.getNativeValue(), - NSString.stringWithString(spelling), DictionaryEntryProperty.Spelling.getNativeValue(), - null) - ); - } - public String getSpelling() { - return getString(DictionaryEntryProperty.Spelling); - } - - public void setSpelling(String entrySpelling) { - setString(DictionaryEntryProperty.Spelling, entrySpelling); - } - - public String getPhonemes() { - return getString(DictionaryEntryProperty.Phonemes); - } - - public void setPhonemes(String entryPhonemes) { - setString(DictionaryEntryProperty.Phonemes, entryPhonemes); - } - } -} diff --git a/rococoa/rococoa-contrib/src/main/java/org/rococoa/contrib/appkit/NSSpeechSynthesizer.java b/rococoa/rococoa-contrib/src/main/java/org/rococoa/contrib/appkit/NSSpeechSynthesizer.java deleted file mode 100755 index f5b164c4..00000000 --- a/rococoa/rococoa-contrib/src/main/java/org/rococoa/contrib/appkit/NSSpeechSynthesizer.java +++ /dev/null @@ -1,690 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.contrib.appkit; - -import java.net.URI; -import java.util.ArrayList; -import java.util.List; - - -import org.rococoa.contrib.AbstractPropertyDictionary; -import org.rococoa.ID; -import org.rococoa.ObjCClass; -import org.rococoa.ObjCObject; -import org.rococoa.ObjCObjectByReference; -import org.rococoa.contrib.NativeEnum; -import org.rococoa.Rococoa; -import org.rococoa.cocoa.foundation.NSArray; -import org.rococoa.cocoa.foundation.NSDictionary; -import org.rococoa.cocoa.foundation.NSError; -import org.rococoa.cocoa.foundation.NSMutableDictionary; -import org.rococoa.cocoa.foundation.NSNumber; -import org.rococoa.cocoa.foundation.NSObject; -import org.rococoa.cocoa.foundation.NSRange; -import org.rococoa.cocoa.foundation.NSString; -import org.rococoa.cocoa.foundation.NSUInteger; -import org.rococoa.cocoa.foundation.NSURL; -//import org.rococoa.RunOnMainThread; - -/** Provides access to Cocoa NSSpeechSynthesizer. - * Methods have been wrapped to take and return natural Java types. - * Convenience methods and wrapper classes have been implemented for property and NSDictionary based datastructures. - */ -//@RunOnMainThread -public abstract class NSSpeechSynthesizer extends NSObject { - /** Defines the properties associated with a speech synthesizer. Getters and setters have been provided for most of these, - * so using the properties directly will not usually be necessary. - * @see NSSpeechSynthesizer#getProperty(org.rococoa.contrib.appkit.NSSpeechSynthesizer.SpeechProperty) - * @see NSSpeechSynthesizer#setProperty(org.rococoa.contrib.appkit.NSSpeechSynthesizer.SpeechProperty, org.rococoa.NSObject) - */ - public enum SpeechProperty implements NativeEnum { - StatusProperty, - ErrorsProperty, - InputModeProperty, - CharacterModeProperty, - NumberModeProperty, - RateProperty, - PitchBaseProperty, - PitchModProperty, - VolumeProperty, - SynthesizerInfoProperty, - RecentSyncProperty, - PhonemeSymbolsProperty, - CurrentVoiceProperty, - CommandDelimiterProperty, - ResetProperty, - OutputToFileURLProperty; - private final NSString value = NSString.getGlobalString("NSSpeech" + name()); - public NSString getNativeValue() { - return value; - } - - @Override - public String toString() { - return super.toString() + " (" + getNativeValue() + ')'; - } - - } - /**Represents the Objective C class for NSSpeechSynthesizer*/ - public static final _Class CLASS = Rococoa.createClass("NSSpeechSynthesizer", _Class.class); - /** Synthesizers have an associated delegate. This is the Objective C delegate object acting as the delegate*/ - private ObjCObject delegateProxy = null; - /** Synthesizers have an associated delegate. This is the Java object provided by the user of this class - that allows Java code to receive delegate related callbacks.*/ - private NSSpeechSynthesizerDelegate delegate = null; - - /** Represents the Objective C class of the speech synthesizer*/ - public static abstract class _Class implements ObjCClass { - public _Class() {} - public abstract NSSpeechSynthesizer alloc(); - public abstract NSDictionary attributesForVoice(String voiceIdentifier); - - public abstract NSArray availableVoices(); - public abstract String defaultVoice(); - public abstract boolean isAnyApplicationSpeaking(); - } - - /** Interface to be implemented by Java objects that want to be informed about events reported to the speech syntheszier's delegate*/ - public interface NSSpeechSynthesizerDelegate { - public void speechSynthesizer_didEncounterErrorAtIndex_ofString_message(NSSpeechSynthesizer sender, Integer characterIndex, String text, String errorMessage); - public void speechSynthesizer_didEncounterSyncMessage(NSSpeechSynthesizer sender, String syncFlag); - public void speechSynthesizer_didFinishSpeaking(NSSpeechSynthesizer sender, boolean success); - public void speechSynthesizer_willSpeakPhoneme(NSSpeechSynthesizer sender, short phonemeOpcode); - public void speechSynthesizer_willSpeakWord_ofString(NSSpeechSynthesizer sender, NSRange wordToSpeak, String text); - } - - /** Construct a new synthesizer that speaks with a specified voice. - * @param voiceIdentifer the identifier of the voice to use - * @return the newly created synthesizer - * @throws IllegalArgumentException if the identifier is invalid or the voice indicated is not installed - */ - public static NSSpeechSynthesizer synthesizerWithVoiceIdentifier(String voiceIdentifer) throws IllegalArgumentException { - return CLASS.alloc().initWithVoice(voiceIdentifer); - } - - /** Construct a new synthesizer that speaks with a specified voice. - * @param voice the voice to use, or null to use the defalt voice - * @return the newly created synthesizer - * @throws IllegalArgumentException if the voice is invalid or not installed - */ - public static NSSpeechSynthesizer synthesizerWithVoice(NSVoice voice) { - return synthesizerWithVoiceIdentifier(voice == null ? null : voice.getIdentifier()); - } - - /** Determine the default voice for this computer, set in system preferences - * @return the system default voice - */ - public static NSVoice defaultVoice() { - return new NSVoice(CLASS.attributesForVoice(CLASS.defaultVoice())); - } - - /** Get a list of all available voices - * @return a list of available voices - */ - public static List availableVoices() { - NSArray availableVoices = CLASS.availableVoices(); - List result = new ArrayList(availableVoices.count()); - for (int i=0; i < availableVoices.count(); i++) { - result.add(new NSVoice(CLASS.attributesForVoice(availableVoices.objectAtIndex(i).toString()))); - } - return result; - } - - /** Determine whether any application is currently generating speech through - * the default output channel at present. - * @return true if the default speech output channel is in use - */ - public static boolean isAnyApplicationSpeaking() { - return CLASS.isAnyApplicationSpeaking(); - } - - /** Set the delegate that will receive events when speech is generated. - * @param delegate the delegate to set, replacing any existing one - */ - public synchronized void setDelegate(final NSSpeechSynthesizerDelegate delegate) { - if ( delegate != null ) { - this.delegate = delegate; - delegateProxy = Rococoa.proxy(delegate); - setDelegate(this.delegateProxy.id()); - } - } - - /** Get the current delegate - * @return the delegate - */ - public synchronized NSSpeechSynthesizerDelegate getDelegate() { - return delegate; - } - - /** Convert a phoneme opcode to human readable form - * @param opcode the phoneme code to convert - * @return the corresponding readable string - */ - public String opcodeToPhoneme(short opcode) { - for(NSSpeechPhonemeInfo info : getPhonemeInfo()) { - if (info.getOpcode() == opcode) { - return info.getSymbol(); - } - } - return "?"; - } - - /** Create a sync point that can be embeded in speech, to trigger a - * synchronization callback. - * @param marker the marker number for the sync point - * @return a sync point marker that can be embeded in a string to be spoken - */ - public static String createSyncPoint(int marker) { - return String.format("[[sync 0x%h]]", marker); - } - - /** Get the value of a synthesizer property. - * @param property the property whose value should be retrieved - * @return the value asociated with the property - * @throws IllegalArgumentException if an error occurs while reading the property - */ - public NSObject getProperty(SpeechProperty property) throws IllegalArgumentException { - ObjCObjectByReference errorPtr = new ObjCObjectByReference(); - NSObject result = objectForProperty_error(property.getNativeValue(), errorPtr); - NSError error = errorPtr.getValueAs(NSError.class); - //objectForProperty:error isn't well documented, so be very conservative - if ( result != null && !result.id().isNull() && (error == null || error.id().isNull() || error.code().intValue() == 0) ) { - return result; - } else { - throw new IllegalArgumentException("Could not get property: " + property + ", error: " + error.localizedDescription()); - } - } - - /** Set the value of a synthesizer property. - * @param property the property whose value will be set - * @param value the value to set - * @throws IllegalArgumentException if an error occurs while setting the property - */ - public void setProperty(SpeechProperty property, NSObject value) throws IllegalArgumentException { - ObjCObjectByReference errorPtr = new ObjCObjectByReference(); - if ( !setObject_forProperty_error(value, property.getNativeValue(), errorPtr) ) { - NSError error = errorPtr.getValueAs(NSError.class); - throw new IllegalArgumentException("Could not set property: " + property + " to value " + value + ", error: " + error.localizedDescription()); - } - } - - /** Add a speech dictionary to those in use with this synthesizer - * @param dictionary the dictionary to add - */ - public void addSpeechDictionary(NSSpeechDictionary dictionary) { - addSpeechDictionary(dictionary.getData()); - } - - - /** Describes boundaries between speech units*/ - public static final class NSSpeechBoundary extends NSUInteger { - private static final long serialVersionUID = 0; - public static final NSSpeechBoundary ImmediateBoundary = new NSSpeechBoundary(0); - public static final NSSpeechBoundary WordBoundary = new NSSpeechBoundary(1); - public static final NSSpeechBoundary SentenceBoundary = new NSSpeechBoundary(2); - public NSSpeechBoundary() {} //required by the plumbing - private NSSpeechBoundary(int ordinal) { - super(ordinal); - } - } - - /** Get the status of the synthesizer - * @return the current status of the synthesizer - */ - public NSSpeechStatus getStatus() { - return new NSSpeechStatus(Rococoa.cast(getProperty(SpeechProperty.StatusProperty), NSMutableDictionary.class)); - } - - //read-only - /** Describes the current status of the synthesizer*/ - public static class NSSpeechStatus extends AbstractPropertyDictionary { - public enum StatusProperty implements NativeEnum { - OutputBusy, - OutputPaused, - NumberOfCharactersLeft, - PhonemeCode; - private final NSString value = NSString.getGlobalString(NSSpeechStatus.class.getSimpleName() + name()); - public NSString getNativeValue() { - return value; - } - } - - public NSSpeechStatus() { - super(StatusProperty.values().length); - } - - public NSSpeechStatus(final NSMutableDictionary data) { - super(data); - } - - public boolean isOutputBusy() { - return getBoolean(StatusProperty.OutputBusy); - } - - public boolean isOutputPaused() { - return getBoolean(StatusProperty.OutputPaused); - } - - public int getNumberOfCharactersLeft() { - return getInt(StatusProperty.NumberOfCharactersLeft); - } - - public short getPhonemeCode() { - return getShort(StatusProperty.PhonemeCode); - } - } - - /** Get the latest error that occurred in the synthesizer - * @return the latest error to occur - */ - public NSSpeechError getError() { - return new NSSpeechError(Rococoa.cast(getProperty(SpeechProperty.ErrorsProperty), NSMutableDictionary.class)); - } - - //read-only - /** Describes an error that occurred*/ - public static class NSSpeechError extends AbstractPropertyDictionary { - public enum ErrorProperty implements NativeEnum { - Count, - OldestCode, - OldestCharacterOffset, - NewestCode, - NewestCharacterOffset; - private final NSString value = NSString.getGlobalString(NSSpeechError.class.getSimpleName() + name()); - public NSString getNativeValue() { - return value; - } - } - - public NSSpeechError() { - super(ErrorProperty.values().length); - } - - public NSSpeechError(final NSMutableDictionary data) { - super(data); - } - - public int getErrorCount() { - return getInt(ErrorProperty.Count); - } - - public int getOldestCode() { - return getInt(ErrorProperty.OldestCode); - } - public int getOldestCharacterOffset() { - return getInt(ErrorProperty.OldestCharacterOffset); - } - public int getNewestCode() { - return getInt(ErrorProperty.NewestCode); - } - public int getNewestCharacterOffset() { - return getInt(ErrorProperty.NewestCharacterOffset); - } - - } - - /** Describes the modes a synthesizer can operate in.*/ - public enum NSSpeechMode implements NativeEnum { - Text, - Phoneme, - Normal, - Literal; - private final NSString value = NSString.getGlobalString(this.getClass().getSimpleName() + name()); - public NSString getNativeValue() { - return value; - } - } - - /** Get the current input mode, whether the synthesizer is currently expecting regular text input or raw phonemes. - * @return either NSSpeechMode.Text or NSSpeechMode.Phoneme depending on the current mode - */ - public NSSpeechMode getInputMode() { - return NativeEnum.Resolver.fromNative(NSSpeechMode.class, getProperty(SpeechProperty.InputModeProperty)); - } - - /** Set the current input mode, whether the synthesizer is currently expecting regular text input or raw phonemes. - * @param mode either NSSpeechMode.Text or NSSpeechMode.Phoneme depending on the desired mode - */ - public void setInputMode(NSSpeechMode mode) { - setProperty(SpeechProperty.InputModeProperty, mode.getNativeValue()); - } - - /** Get the current character mode, whether the synthesizer is currently speaking strings normally or speaking each character literally. - * @return either NSSpeechMode.Normal or NSSpeechMode.Literal depending on the current mode - */ - public NSSpeechMode getCharacterMode() { - return NativeEnum.Resolver.fromNative(NSSpeechMode.class, getProperty(SpeechProperty.CharacterModeProperty)); - } - - /** Set the current character mode, whether the synthesizer is currently speaking strings normally or speaking each character literally. - * @param mode either NSSpeechMode.Normal or NSSpeechMode.Literal depending on the desired mode - */ - public void setCharacterMode(NSSpeechMode mode) { - setProperty(SpeechProperty.CharacterModeProperty, mode.getNativeValue()); - } - - /** Get the current number mode, whether the synthesizer is currently speaking numbers normally or speaking each digit literally. - * @return either NSSpeechMode.Normal or NSSpeechMode.Literal depending on the current mode - */ - public NSSpeechMode getNumberMode() { - return NativeEnum.Resolver.fromNative(NSSpeechMode.class, getProperty(SpeechProperty.NumberModeProperty)); - } - - /** Set the current number mode, whether the synthesizer is currently speaking numbers normally or speaking each digit literally. - * @param mode either NSSpeechMode.Normal or NSSpeechMode.Literal depending on the desired mode - */ - public void setNumberMode(NSSpeechMode mode) { - setProperty(SpeechProperty.NumberModeProperty, mode.getNativeValue()); - } - - /** Get identifying information about this synthesizer - * @return information that identifies this synthesizer - */ - public NSSpeechSynthesizerInfo getSynthesizerInfo() { - return new NSSpeechSynthesizerInfo(Rococoa.cast(getProperty(SpeechProperty.SynthesizerInfoProperty), NSMutableDictionary.class)); - } - - //read-only - /** Describes identifying information about the synthesizer*/ - public static class NSSpeechSynthesizerInfo extends AbstractPropertyDictionary { - public enum SpeechSynthesizerInfoProperty implements NativeEnum { - Identifier, - Version; - private final NSString value = NSString.getGlobalString(NSSpeechSynthesizerInfo.class.getSimpleName() + name()); - public NSString getNativeValue() { - return value; - } - } - public NSSpeechSynthesizerInfo() { - super(SpeechSynthesizerInfoProperty.values().length); - } - public NSSpeechSynthesizerInfo(final NSMutableDictionary data) { - super(data); - } - public String getSynthesizerIdentifier() { - return getString(SpeechSynthesizerInfoProperty.Identifier); - } - public String getSynthesizerVersion() { - return getString(SpeechSynthesizerInfoProperty.Version); - } - } - - /** Get the baseline pitch for the synthesizer - * @return the baseline pitch - */ - public float getPitchBase() { - return Rococoa.cast(getProperty(SpeechProperty.PitchBaseProperty), NSNumber.class).floatValue(); - } - - /** Set the baseline pitch for the synthesizer - * @param baselinePitch the baseline pitch to use - */ - public void setPitchBase(float baselinePitch) { - setProperty(SpeechProperty.PitchBaseProperty, NSNumber.CLASS.numberWithFloat(baselinePitch)); - } - - /** Get the pitch modulation for the synthesizer - * @return the pitch modulation - */ - public float getPitchMod() { - return Rococoa.cast(getProperty(SpeechProperty.PitchModProperty), NSNumber.class).floatValue(); - } - - /** Set the pitch modulation for the synthesizer - * @param modulation the pitch modulation to use - */ - public void setPitchMod(float modulation) { - if ( modulation < 0.0f || modulation > 127.0f) { - throw new IllegalArgumentException("Pitch modulation must be in the range 0.0 - 127.0"); - } - setProperty(SpeechProperty.PitchModProperty, NSNumber.CLASS.numberWithFloat(modulation)); - } - - /** Get a list of phonemes the synthesizer uses - * @return information about the phonemes the synthesizer uses - */ - public List getPhonemeInfo() { - NSArray infos = Rococoa.cast(getProperty(SpeechProperty.PhonemeSymbolsProperty), NSArray.class); - List result = new ArrayList(infos.count()); - for(int i=0; i < infos.count(); i++) { - NSDictionary phonemeInfo = Rococoa.cast(infos.objectAtIndex(i), NSDictionary.class); - result.add(new NSSpeechPhonemeInfo(NSMutableDictionary.dictionaryWithDictionary(phonemeInfo))); - } - return result; - } - - //read-only - /** Describes information about phonemes the synthesizer uses*/ - public static class NSSpeechPhonemeInfo extends AbstractPropertyDictionary { - public enum PhonemeInfoProperty implements NativeEnum { - Opcode, - Symbol, - Example, - HiliteStart, - HiliteEnd; - private final NSString value = NSString.getGlobalString(NSSpeechPhonemeInfo.class.getSimpleName() + name()); - public NSString getNativeValue() { - return value; - } - } - - public NSSpeechPhonemeInfo() { - super(PhonemeInfoProperty.values().length); - } - - public NSSpeechPhonemeInfo(final NSMutableDictionary data) { - super(data); - } - - public short getOpcode() { - return getShort(PhonemeInfoProperty.Opcode); - } - - public String getSymbol() { - return getString(PhonemeInfoProperty.Symbol); - } - - public String getExample() { - return getString(PhonemeInfoProperty.Example); - } - - public int getHiliteStart() { - return getInt(PhonemeInfoProperty.HiliteStart); - } - - public int getHiliteEnd() { - return getInt(PhonemeInfoProperty.HiliteEnd); - } - - @Override - public String toString() { - return getData().toString(); - } - } - - /** Get the most recent sync point encountered when speaking - * @return the identifying number of the most recent sync point - */ - public int getRecentSync() { - return Rococoa.cast(getProperty(SpeechProperty.RecentSyncProperty), NSNumber.class).intValue(); - } - - /** Set the voice to use - * @param voice the new voice to use - * @return true if the voice change was successful - */ - public boolean setVoice(NSVoice voice) { - //CurrentVocieProperty basically takes a map with 2 keys, creator and id like an old school VoiceSpec spec (see SpeechSynthesis.h) - //setProperty(SpeechProperty.CurrentVoiceProperty, dictionary of creator and id would go here ); - //this is much less painful - we'd have to call the C API, and why do it the hard way? If someone needs to, they can always - //call setProperty() for themselves. - return setVoice(voice.getIdentifier()); - } - - /** Get the current voice in use - * @return the voice in use - */ - public NSVoice getVoice() { - return new NSVoice(CLASS.attributesForVoice(voice())); - } - - /** Set the command delimiter to use - * @param delimiters the delimiters to use when embedding commands in speech - */ - public void setCommandDelimiter(NSSpeechCommand delimiters) { - setProperty(SpeechProperty.CommandDelimiterProperty, delimiters.getData()); - } - - //write-only - /** Desribes how to set the delimiters used to embed commands in text to be spoken*/ - public static class NSSpeechCommand extends AbstractPropertyDictionary { - public enum CommandDelimiterProperty implements NativeEnum{ - Prefix, - Suffix; - private final NSString value = NSString.getGlobalString(NSSpeechCommand.class.getSimpleName() + name()); - public NSString getNativeValue() { - return value; - } - } - - public NSSpeechCommand() { - super(CommandDelimiterProperty.values().length); - } - - public NSSpeechCommand(final NSMutableDictionary data) { - super(data); - } - - public NSSpeechCommand(String prefix, String suffix) { - this(); - setCommandPrefix(prefix); - setCommandSuffix(suffix); - } - - public String getCommandPrefix() { - return getString(CommandDelimiterProperty.Prefix); - } - public void setCommandPrefix(String prefix) { - setString(CommandDelimiterProperty.Prefix, prefix); - } - - public String getCommandSuffix() { - return getString(CommandDelimiterProperty.Suffix); - } - public void setCommandSuffix(String suffix) { - setString(CommandDelimiterProperty.Suffix, suffix); - } - } - - /** Reset the synthesizer to the default settings*/ - public void reset() { - setProperty(SpeechProperty.ResetProperty, null); - } - //pass null for computer speakers - /** Set the synthesizer to send output to a file instead of the default output channel - * @param uri a file URI to send output to, pass null to switch back to the computer speakers - */ - public void setOutputToFileURL(URI uri) { - setProperty(SpeechProperty.OutputToFileURLProperty, uri != null ? NSURL.CLASS.URLWithString(uri.toString()) : null); - } - - /** Speak the given string to a file - * @param text the text to speak - * @param uri a file URI indicating where to send output to - * @return true if the synthesis began successfully - */ - public boolean startSpeakingStringToURL(String text, URI uri) { - return startSpeakingString_toURL(NSString.stringWithString(text), NSURL.CLASS.URLWithString(uri.toString())); - } - - //Those methods that will simply be called directly are public, the rest are 'package' - wrapper methods can be found above. - abstract void addSpeechDictionary(NSDictionary speechDictionary); - /** Resume speaking if output was paused*/ - public abstract void continueSpeaking(); - abstract ID delegate(); - abstract NSSpeechSynthesizer initWithVoice(String voiceIdentifier); - /** Determine whether the current application is speaking using the default output channel - * @return true if the current application is speaking - */ - public abstract boolean isSpeaking(); - abstract NSObject objectForProperty_error(NSString speechProperty, ObjCObjectByReference out_error); - abstract boolean setObject_forProperty_error(NSObject object, NSString speechProperty, ObjCObjectByReference out_error); - /** Pause speech at the indicated boundary - * @param boundary the place to stop speech - */ - public abstract void pauseSpeakingAtBoundary(NSSpeechBoundary boundary); - /** Convert text to phonemes. - * @param text the text to convert - * @return the corresponding phonemes - */ - public abstract String phonemesFromText(String text); - /** Get the current rate of speech - * @return the current rate of speech - */ - public abstract float rate(); - abstract void setDelegate(ID delegate); - /** Set the current rate of speech - * @param rate the rate to use - */ - public abstract void setRate(float rate); - /** Set whether the feedback window should be used - * @param useFeedbackWindow pass true to enable the feedback window - */ - public abstract void setUsesFeedbackWindow(boolean useFeedbackWindow); - /** Set the voice to use, should be called when the synthesizer is not currently speaking - * @param voiceIdentifier the identifier of the voice to use - * @return true if the voice change was successful - */ - public abstract boolean setVoice(String voiceIdentifier); - /** Set the volume - * @param volume the volume to use - */ - public abstract void setVolume(float volume); - /** Start speaking the given string through the default system speech channel - * @param text the text to speak - * @return true if synthesis starts successfully - */ - public abstract boolean startSpeakingString(String text); - abstract boolean startSpeakingString_toURL(NSString text, NSURL url); - /** Stop this synthesizer from speaking*/ - public abstract void stopSpeaking(); - /** Stop this synthesizer from speaking when it reaches the indicated place. - * @param boundary the place to stop speaking - */ - public abstract void stopSpeakingAtBoundary(NSSpeechBoundary boundary); - /** Get whether the feedback window is enabled - * @return true if the feedback window is enabled - */ - public abstract boolean usesFeedbackWindow(); - abstract String voice(); - /** Get the identifier of the current voice - * @return the identifier of the current voice - */ - public String getVoiceIdentifier() { - return voice(); - } - abstract float volume(); - /** Get the current volume - * @return the current volume - */ - public float getVolume() { - return volume(); - } -} diff --git a/rococoa/rococoa-contrib/src/main/java/org/rococoa/contrib/appkit/NSVoice.java b/rococoa/rococoa-contrib/src/main/java/org/rococoa/contrib/appkit/NSVoice.java deleted file mode 100755 index e88b2097..00000000 --- a/rococoa/rococoa-contrib/src/main/java/org/rococoa/contrib/appkit/NSVoice.java +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.contrib.appkit; - -import org.rococoa.cocoa.foundation.NSArray; -import org.rococoa.cocoa.foundation.NSDictionary; -import org.rococoa.cocoa.foundation.NSMutableDictionary; -import org.rococoa.cocoa.foundation.NSString; -import org.rococoa.contrib.AbstractPropertyDictionary; -import org.rococoa.contrib.NativeEnum; - -import static org.rococoa.contrib.appkit.NSVoice.VoiceProperty.Age; -import static org.rococoa.contrib.appkit.NSVoice.VoiceProperty.DemoText; -import static org.rococoa.contrib.appkit.NSVoice.VoiceProperty.Gender; -import static org.rococoa.contrib.appkit.NSVoice.VoiceProperty.Identifier; -import static org.rococoa.contrib.appkit.NSVoice.VoiceProperty.IndividuallySpokenCharacters; -import static org.rococoa.contrib.appkit.NSVoice.VoiceProperty.Language; -import static org.rococoa.contrib.appkit.NSVoice.VoiceProperty.LocaleIdentifier; -import static org.rococoa.contrib.appkit.NSVoice.VoiceProperty.Name; -import static org.rococoa.contrib.appkit.NSVoice.VoiceProperty.SupportedCharacters; - -/** NSVoice encapsulates the properties of a speech synthesis voice, and can be - * used with NSSpeechSynthesizer to change the voice used to spreak. - * This class is a Rococoa enhancment designed to make it easier to work with - * voices, there is no actual class with this name in Cocoa. - */ -public class NSVoice extends AbstractPropertyDictionary { - //No way of knowing which voices a user has installed, so just expose the known ids - public static final String ALEX = "com.apple.speech.synthesis.voice.Alex"; - public static final String ALICE = "com.apple.speech.synthesis.voice.alice"; - public static final String ALVA = "com.apple.speech.synthesis.voice.alva"; - public static final String AMELIE = "com.apple.speech.synthesis.voice.amelie"; - public static final String ANNA = "com.apple.speech.synthesis.voice.anna"; - public static final String CARMIT = "com.apple.speech.synthesis.voice.carmit"; - public static final String DAMAYANTI = "com.apple.speech.synthesis.voice.damayanti"; - public static final String DANIEL = "com.apple.speech.synthesis.voice.daniel"; - public static final String DIEGO = "com.apple.speech.synthesis.voice.diego"; - public static final String ELLEN = "com.apple.speech.synthesis.voice.ellen"; - public static final String FIONA = "com.apple.speech.synthesis.voice.fiona"; - public static final String FRED = "com.apple.speech.synthesis.voice.Fred"; - public static final String IOANA = "com.apple.speech.synthesis.voice.ioana"; - public static final String JOANA = "com.apple.speech.synthesis.voice.joana"; - public static final String JORGE = "com.apple.speech.synthesis.voice.jorge"; - public static final String JUAN = "com.apple.speech.synthesis.voice.juan"; - public static final String KANYA = "com.apple.speech.synthesis.voice.kanya"; - public static final String KAREN = "com.apple.speech.synthesis.voice.karen"; - public static final String KYOKO = "com.apple.speech.synthesis.voice.kyoko.premium"; - public static final String LAURA = "com.apple.speech.synthesis.voice.laura"; - public static final String LEKHA = "com.apple.speech.synthesis.voice.lekha"; - public static final String LUCA = "com.apple.speech.synthesis.voice.luca"; - public static final String LUCIANA = "com.apple.speech.synthesis.voice.luciana"; - public static final String MAGED = "com.apple.speech.synthesis.voice.maged"; - public static final String MARISKA = "com.apple.speech.synthesis.voice.mariska"; - public static final String MEI_JIA = "com.apple.speech.synthesis.voice.mei-jia"; - public static final String MELINA = "com.apple.speech.synthesis.voice.melina"; - public static final String MILENA = "com.apple.speech.synthesis.voice.milena"; - public static final String MOIRA = "com.apple.speech.synthesis.voice.moira"; - public static final String MONICA = "com.apple.speech.synthesis.voice.monica"; - public static final String NORA = "com.apple.speech.synthesis.voice.nora"; - public static final String PAULINA = "com.apple.speech.synthesis.voice.paulina"; - public static final String RISHI = "com.apple.speech.synthesis.voice.rishi"; - public static final String SAMANTHA = "com.apple.speech.synthesis.voice.samantha"; - public static final String SARA = "com.apple.speech.synthesis.voice.sara"; - public static final String SATU = "com.apple.speech.synthesis.voice.satu"; - public static final String SIN_JI = "com.apple.speech.synthesis.voice.sin-ji"; - public static final String TESSA = "com.apple.speech.synthesis.voice.tessa"; - public static final String THOMAS = "com.apple.speech.synthesis.voice.thomas"; - public static final String TING_TING = "com.apple.speech.synthesis.voice.ting-ting"; - public static final String VEENA = "com.apple.speech.synthesis.voice.veena"; - public static final String VICTORIA = "com.apple.speech.synthesis.voice.Victoria"; - public static final String XANDER = "com.apple.speech.synthesis.voice.xander"; - public static final String YELDA = "com.apple.speech.synthesis.voice.yelda"; - public static final String YUNA = "com.apple.speech.synthesis.voice.yuna"; - public static final String YURI = "com.apple.speech.synthesis.voice.yuri"; - public static final String ZOSIA = "com.apple.speech.synthesis.voice.zosia"; - public static final String ZUZANA = "com.apple.speech.synthesis.voice.zuzana"; - - /** Defines the properties of a voice*/ - public enum VoiceProperty implements NativeEnum { - Name, - Identifier, - Age, - Gender, - DemoText, - LocaleIdentifier, - SupportedCharacters, - IndividuallySpokenCharacters, - Language; - private final NSString value = NSString.getGlobalString(NSVoice.class.getSimpleName() + name()); - public NSString getNativeValue() { - return value; - } - } - - /** Construct a new voice using the given identifier - * @param voiceIdentifier the voice to lookup - * @throws IllegalArgumentException if the voice identified by voiceIdentifier is not installed - */ - public NSVoice (String voiceIdentifier) throws IllegalArgumentException { - super(NSMutableDictionary.dictionaryWithDictionary( - checkData(voiceIdentifier, NSSpeechSynthesizer.CLASS.attributesForVoice(voiceIdentifier)))); - } - - NSVoice() { - super(VoiceProperty.values().length); - } - - NSVoice(final NSMutableDictionary data) { - super(checkData(null, data)); - } - - NSVoice(NSDictionary data) { - super(checkData(null, data)); - } - - private static NSDictionary checkData(String identifier, NSDictionary data) { - if (data == null || data.count() == 0) { - throw new IllegalArgumentException("Invalid voice data" + - identifier == null ? "." : ", unknown identifier: " + identifier ); - } else { - return data; - } - } - - public String getName() { - return getString(Name); - } - - public String getIdentifier() { - return getString(Identifier); - } - - public int getAge() { - return getInt(Age); - } - - public VoiceGender getGender() { - return getEnum(VoiceGender.class, Gender); - } - - public String getDemoText() { - return getString(DemoText); - } - - public String getLocaleIdentifier() { - return getString(LocaleIdentifier); - } - - public NSArray getSupportedCharacters() { - return getValueAsType(SupportedCharacters, NSArray.class); - } - - public NSArray getIndividuallySpokenCharacters() { - return getValueAsType(IndividuallySpokenCharacters, NSArray.class); - } - - @Deprecated - public String getLanguage() { - return getString(Language); - } - - @Override - public String toString() { - return "[NSVoice: " + getData() + ']'; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof NSVoice) { - return getIdentifier().equals(((NSVoice) obj).getIdentifier()); - } - return false; - } - - @Override - public int hashCode() { - return getIdentifier().hashCode(); - } - - /** An enumeration representing possible genders for voices*/ - public enum VoiceGender implements NativeEnum { - Neuter, - Male, - Female; - private final NSString value = NSString.getGlobalString("NS" + getClass().getSimpleName() + name()); - public NSString getNativeValue() { - return value; - } - } - -} diff --git a/rococoa/rococoa-contrib/src/main/java/org/rococoa/contrib/dispatch/GCDExecutorService.java b/rococoa/rococoa-contrib/src/main/java/org/rococoa/contrib/dispatch/GCDExecutorService.java deleted file mode 100644 index f446c377..00000000 --- a/rococoa/rococoa-contrib/src/main/java/org/rococoa/contrib/dispatch/GCDExecutorService.java +++ /dev/null @@ -1,289 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.contrib.dispatch; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.concurrent.AbstractExecutorService; -import java.util.concurrent.Callable; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.FutureTask; -import java.util.concurrent.RejectedExecutionException; -import java.util.concurrent.RunnableFuture; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.locks.Condition; -import java.util.concurrent.locks.ReentrantLock; - -import org.rococoa.Foundation; -import org.rococoa.ID; -import org.rococoa.ObjCObject; -import org.rococoa.Rococoa; -import org.rococoa.Selector; -import org.rococoa.cocoa.foundation.NSArray; -import org.rococoa.cocoa.foundation.NSAutoreleasePool; -import org.rococoa.contrib.appkit.NSInvocationOperation; -import org.rococoa.contrib.appkit.NSOperation; -import org.rococoa.contrib.appkit.NSOperationQueue; - -/** GCDExecutorService runs tasks by passing them to Grand Central Dispatch. - * Presently, every GCDExecutorService creates its own - * NSOperationQueue underneath. - * @author Andrew Thompson (lordpixel@mac.com) - */ -public class GCDExecutorService extends AbstractExecutorService { - /**An Object-C selector representing a run() method*/ - private static final Selector RUN_SELECTOR = Foundation.selector("run"); - /**A permission meaning one thread can modify another*/ - private static final RuntimePermission shutdownPerm = new RuntimePermission("modifyThread"); - /**Represents the states this ExecutorService can be in*/ - private enum State { RUNNING, SHUTDOWN, TERMINATED } - /**The underlying operation queue used to schedule tasks*/ - private final NSOperationQueue queue; - /**The current state of this ExecutorService*/ - private volatile State state = State.RUNNING; - /**A lock used to manage the state of the ExecutorService during the shutdown process*/ - private final ReentrantLock shutdownLock = new ReentrantLock(); - /**A signal condition used during the shutdown process*/ - private final Condition shutdownCondition = shutdownLock.newCondition(); - /**A Map used both to retain proxies for running tasks - so they are not collected - and to - * support the shutdownNow() method*/ - private final Map> tasks = new ConcurrentHashMap>(); - - /** Construct a new instance of the code ExecutorService, with its own underlying NSOperationQueue*/ - public GCDExecutorService() { - queue = NSOperationQueue.CLASS.alloc().init(); - } - - public void shutdown() { - SecurityManager sm = System.getSecurityManager(); - if ( sm != null ) { - sm.checkPermission(shutdownPerm); - } - try { - shutdownLock.lock(); - state = State.SHUTDOWN; - terminateIfDone(queue.operationCount().intValue() == 0); - } finally { - shutdownLock.unlock(); - } - } - - public List shutdownNow() { - SecurityManager sm = System.getSecurityManager(); - if ( sm != null ) { - sm.checkPermission(shutdownPerm); - } - return doWithAutoreleasePool(new Callable>() { - public List call() { - try { - shutdownLock.lock(); - state = State.SHUTDOWN; - NSArray queuedTasks = queue.operations(); - List result = new ArrayList(queuedTasks.count()); - for (int i = 0; i < queuedTasks.count(); i++) { - NSOperation o = Rococoa.cast(queuedTasks.objectAtIndex(i), NSOperation.class); - InvocationFutureTask task = tasks.get(o.id()); - if ( task != null && !(o.isFinished() || o.isCancelled()) ) { - result.add(task.getOriginalRunnable()); - } - } - queue.cancelAllOperations(); - tasks.clear(); - terminateIfDone(queue.operationCount().intValue() == 0); - return result; - } finally { - shutdownLock.unlock(); - } - } - }); - } - - public boolean isShutdown() { - return state != State.RUNNING; - } - - public boolean isTerminated() { - return state == State.TERMINATED; - } - - public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { - long wait = unit.toNanos(timeout); - shutdownLock.lock(); - try { - while ( !isTerminated() ) { - if ( wait <= 0) { - return false; - } - wait = shutdownCondition.awaitNanos(wait); - terminateIfDone(queue.operationCount().intValue() == 0); - } - return true; - } finally { - shutdownLock.unlock(); - } - } - - public void execute(Runnable command) { - if ( command == null ) { - throw new NullPointerException("Tasks may not be null"); - } - try { - shutdownLock.lock(); - if ( state != State.RUNNING ) { - throw new RejectedExecutionException("Executor is not running"); - } else { - InvocationFutureTask task = command instanceof InvocationFutureTask ? - (InvocationFutureTask) command : - (InvocationFutureTask) newTaskFor(command, null); - queue.addOperation(task.getInvocationOperation()); - } - } finally { - shutdownLock.unlock(); - } - } - - @Override - protected RunnableFuture newTaskFor(Runnable runnable, T value) { - return new InvocationFutureTask(runnable, value); - } - - @Override - protected RunnableFuture newTaskFor(Callable callable) { - return super.newTaskFor(callable); - } - - /** A future task that creates an NSInvocationOperation to run the Runnable - * or Callable it is created with. - * @param the type of the result of the task - */ - private class InvocationFutureTask extends FutureTask { - /** The NSInvocationOperation that will be enqueued and executed*/ - private final NSInvocationOperation invocation; - /** A reference to the Java proxy object created to allow Objective C - * to callback methods on this class. It must be held because a crash - * will occur if the Java proxy is collected and Objective-C attempts - * to use it. - */ - private final ObjCObject proxy; - /**The original runnable submitted by the caller of the ExecutorService, when a method - * that takes a Runnable is used. Conversely, if a Callable is submitted for execution - * then this is simply set to this. - * This is ultimately for the shutdownNow() method - we try to return the original - * submitted objects whenever possible. - */ - private final Runnable originalRunnable; - - /** Create an new invocation based future task to run the given Runnable - * @param r the Runnable to run - * @param result the result to return when the Runnable completes - */ - public InvocationFutureTask(Runnable r, V result) { - super(r, result); - originalRunnable = r; - proxy = Rococoa.proxy(this); - invocation = createInvocation(proxy); - tasks.put(invocation.id(), this); - } - - /** Create an new invocation based future task to run the given Callable - * @param callable the Callable to run - */ - public InvocationFutureTask(Callable callable){ - super(callable); - originalRunnable = this; - proxy = Rococoa.proxy(this); - invocation = createInvocation(proxy); - tasks.put(invocation.id(), this); - } - private NSInvocationOperation createInvocation(final ObjCObject toInvoke) { - return doWithAutoreleasePool(new Callable () { - public NSInvocationOperation call() { - NSInvocationOperation result = NSInvocationOperation.CLASS.alloc(); - //when the NSOperationQueue executes the NSInvocationOperation, run() is - //called on this object. - result = result.initWithTarget_selector_object(toInvoke.id(), RUN_SELECTOR, null); - return result; - } - }); - } - /** Get the NSInvocationOperation created to run this task. - * @return the invocation operation that will be used to run this tak - */ - public NSInvocationOperation getInvocationOperation() { - return invocation; - } - /** Get the original Runnable used to create this task, - * will simply return this if the task was creaed with a - * Callable instead. - * @return the original Runnable - */ - public Runnable getOriginalRunnable () { - return originalRunnable; - } - @Override - public void run() { - try { - super.run(); - } finally { - tasks.remove(invocation.id()); - if ( state == GCDExecutorService.State.SHUTDOWN ) { - //i.e. this is the last item on the queue - terminateIfDone(queue.operationCount().intValue() <= 1); - } - } - } - } - - /** If the ExecutorService has been shutdown and the work queue is empty, - * transition to the TERMINATED state. - * @param queueEmpty pass true if the queue is currently empty. - */ - private void terminateIfDone(boolean queueEmpty) { - try { - shutdownLock.lock(); - if ( state == State.SHUTDOWN && queueEmpty ) { - shutdownCondition.signalAll(); - queue.setSuspended(true); - state = State.TERMINATED; - } - } finally { - shutdownLock.unlock(); - } - } - - /** Perform some code with an autorelease pool in place. - * - * @param the type returned when callable is run - * @param callable the Callable code to run with a pool in place - * @return the result of running the Callable - */ - private static R doWithAutoreleasePool(Callable callable) { - NSAutoreleasePool pool = null; - try { - pool = NSAutoreleasePool.new_(); - return callable.call(); - } catch (Exception e) { - throw e instanceof RuntimeException ? ((RuntimeException)e) : new RuntimeException(e); - } finally { - if ( pool != null ) pool.drain(); - } - } -} diff --git a/rococoa/rococoa-contrib/src/main/java/org/rococoa/contrib/growl/Growl.java b/rococoa/rococoa-contrib/src/main/java/org/rococoa/contrib/growl/Growl.java deleted file mode 100644 index d7ae5ae4..00000000 --- a/rococoa/rococoa-contrib/src/main/java/org/rococoa/contrib/growl/Growl.java +++ /dev/null @@ -1,444 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.contrib.growl; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import org.rococoa.cocoa.NSApplication; -import org.rococoa.cocoa.NSDistributedNotificationCenter; -import org.rococoa.cocoa.foundation.NSArray; -import org.rococoa.cocoa.foundation.NSDictionary; -import org.rococoa.cocoa.foundation.NSImage; -import org.rococoa.cocoa.foundation.NSMutableDictionary; -import org.rococoa.cocoa.foundation.NSNumber; -import org.rococoa.cocoa.foundation.NSObject; -import org.rococoa.cocoa.foundation.NSString; - -/** - * A class that encapsulates the work of talking to Growl. - * - * @author Karl Adam (original code using CocoaJavaBridge) - * @author Harald Kuhr (port to Rococoa). - * @author last modified by $Author: haraldk$ - * @version $Id: Growl.java,v 1.0 Mar 26, 2009 12:24:28 PM haraldk Exp$ - */ -public final class Growl { - // TODO: Consider allowing Icon/(Buffered)Image to be passed instead of NSImage - // TODO: Consider using Map instead of NSDictionary - - // defines - /** The name of the growl registration notification for DNC. */ - public static final String GROWL_APP_REGISTRATION = "GrowlApplicationRegistrationNotification"; - - // Ticket Defines - /** Ticket key for the application name. */ - public static final String GROWL_APP_NAME = "ApplicationName"; - /** Ticket key for the application icon. */ - public static final String GROWL_APP_ICON = "ApplicationIcon"; - /** Ticket key for the default notifactions. */ - public static final String GROWL_NOTIFICATIONS_DEFAULT = "DefaultNotifications"; - /** Ticket key for all notifactions. */ - public static final String GROWL_NOTIFICATIONS_ALL = "AllNotifications"; - - // Notification Defines - /** The name of the growl notification for DNC. */ - public static final String GROWL_NOTIFICATION = "GrowlNotification"; - /** Notification key for the name. */ - public static final String GROWL_NOTIFICATION_NAME = "NotificationName"; - /** Notification key for the title. */ - public static final String GROWL_NOTIFICATION_TITLE = "NotificationTitle"; - /** Notification key for the description. */ - public static final String GROWL_NOTIFICATION_DESCRIPTION = "NotificationDescription"; - /** Notification key for the icon. */ - public static final String GROWL_NOTIFICATION_ICON = "NotificationIcon"; - /** Notification key for the application icon. */ - public static final String GROWL_NOTIFICATION_APP_ICON = "NotificationAppIcon"; - /** Notification key for the sticky flag. */ - public static final String GROWL_NOTIFICATION_STICKY = "NotificationSticky"; - /** Notification key for the identifier. */ - public static final String GROWL_NOTIFICATION_IDENTIFIER = "GrowlNotificationIdentifier"; - - // Actual instance data - // We should only register once - private boolean registered; - // "Application" Name - private String appName; - // "application" Icon - private NSImage appImage; - // All notifications - private List allNotes; - // Default enabled notifications - private List defNotes; - - // The notification center - private final NSDistributedNotificationCenter theCenter; - - private static NSArray toNSArray(final List strings) { - if (strings == null) { - return null; - } - - return toNSArray(strings.toArray(new String[strings.size()])); - } - - private static NSArray toNSArray(final String... strings) { - if (strings == null) { - return null; - } - - NSObject[] types = new NSObject[strings.length]; - for (int i = 0; i < strings.length; i++) { - types[i] = NSString.stringWithString(strings[i]); - - } - - return NSArray.CLASS.arrayWithObjects(types); - } - -// private static NSDictionary toNSDictionary(final Map map) { -// NSDictionary dictionary = NSDictionary.dictionaryWithObjects_forKeys(objects, keys); -// return dictionary; -// } -// -// private static NSImage toNSImage(final Image image) { -// return null; -// } - - //************ Constructors **************// - /** - * Convenience method to contruct a growl instance, defers to Growl(String - * inAppName, NSData inImageData, NSArray inAllNotes, NSArray inDefNotes, - * boolean registerNow) with empty arrays for your notifications. - * - * @param inAppName The Name of your "application" - * @param inImage The NSImage Icon for your Application - */ - public Growl(String inAppName, NSImage inImage) { - this(inAppName, inImage, null, null, false); - } - - /** - * Convenience method to contruct a growl instance, defers to Growl(String - * inAppName, NSData inImageData, NSArray inAllNotes, NSArray inDefNotes, - * boolean registerNow) with the arrays passed here and empty Data for the icon. - * - * @param inAppName The Name of your "Application" - * @param inAllNotes A String Array with the name of all your notifications - * @param inDefNotes A String Array with the na,es of the Notifications on - * by default - */ - public Growl(String inAppName, List inAllNotes, List inDefNotes) { - this(inAppName, null, inAllNotes, inDefNotes, false); - } - - /** - * Convenience method to contruct a growl instance, defers to Growl(String - * inAppName, NSData inImageData, NSArray inAllNotes, NSArray inDefNotes, - * boolean registerNow) with empty arrays for your notifications. - * - * @param inAppName The Name of your "Application" - * @param inImage Your "Application"'s icon, or {@code null} to use your application's default application icon. - * @param inAllNotes The NSArray of Strings of all your Notifications - * @param inDefNotes The NSArray of Strings of your default Notifications - * @param registerNow Since we have all the necessary info we can go ahead - * and register - */ - public Growl(String inAppName, NSImage inImage, List inAllNotes, List inDefNotes, boolean registerNow) { - if (inAppName == null) { - throw new IllegalArgumentException("Application name may not be null"); - } - - appName = inAppName; - appImage = inImage != null ? inImage : NSApplication.NSApp.applicationIconImage(); - - setAllowedNotifications(inAllNotes); - setDefaultNotifications(inDefNotes); - - theCenter = NSDistributedNotificationCenter.defaultCenter(); - - if (registerNow) { - register(); - } - } - - //************ Commonly Used Methods **************// - - // TODO: What's the point of this return value? It's always true... - - /** - * Register all our notifications with Growl, this should only be called once. - * - * @return true. - */ - public final boolean register() { - if (!registered) { - // Construct our dictionary - // Make the arrays of objects then keys - NSArray objects = NSArray.CLASS.arrayWithObjects( - NSString.stringWithString(appName), - toNSArray(allNotes), - toNSArray(defNotes), - appImage != null ? appImage.TIFFRepresentation() : null - ); - - NSArray keys = NSArray.CLASS.arrayWithObjects( - NSString.stringWithString(GROWL_APP_NAME), - NSString.stringWithString(GROWL_NOTIFICATIONS_ALL), - NSString.stringWithString(GROWL_NOTIFICATIONS_DEFAULT), - appImage != null ? NSString.stringWithString(GROWL_APP_ICON) : null - ); - - // Make the Dictionary - NSDictionary regDict = NSDictionary.dictionaryWithObjects_forKeys(objects, keys); - - theCenter.postNotification( - GROWL_APP_REGISTRATION, // notificationName - null, // anObject - regDict, // userInfoDictionary - true // deliverImmediately - ); - - registered = true; - } - - return true; - } - - /** - * The fun part is actually sending those notifications we worked so hard for - * so here we let growl know about things we think the user would like, and growl - * decides if that is the case. - * - * @param inNotificationName The name of one of the notifications we told growl - * about. - * @param inIcon The NSImage for the icon for this notification, can be null - * @param inTitle The Title of our Notification as Growl will show it - * @param inDescription The Description of our Notification as Growl will - * display it - * @param inExtraInfo Growl is flexible and allows Display Plugins to do as they - * please with thier own special keys and values, you may use - * them here. These may be ignored by either the user's - * preferences or the current Display Plugin. This can be null - * @param inSticky Whether the Growl notification should be sticky - * @param inIdentifier Notification identifier for coalescing. This can be null. - * @throws IllegalArgumentException When a notification is not known - */ - public void postNotification(String inNotificationName, NSImage inIcon, String inTitle, String inDescription, - NSDictionary inExtraInfo, boolean inSticky, String inIdentifier) { - NSMutableDictionary noteDict = NSMutableDictionary.dictionaryWithCapacity(0); - - if (!allNotes.contains(inNotificationName)) { - throw new IllegalArgumentException("Undefined Notification attempted: " + inNotificationName); - } - - noteDict.setValue_forKey(NSString.stringWithString(inNotificationName), GROWL_NOTIFICATION_NAME); - noteDict.setValue_forKey(inTitle != null ? NSString.stringWithString(inTitle) : null, GROWL_NOTIFICATION_TITLE); - noteDict.setValue_forKey(inDescription != null ? NSString.stringWithString(inDescription) : null, GROWL_NOTIFICATION_DESCRIPTION); - noteDict.setValue_forKey(NSString.stringWithString(appName), GROWL_APP_NAME); - if (inIcon != null) { - noteDict.setValue_forKey(inIcon.TIFFRepresentation(), GROWL_NOTIFICATION_ICON); - } - - if (inSticky) { - noteDict.setValue_forKey(NSNumber.CLASS.numberWithInt(1), GROWL_NOTIFICATION_STICKY); - } - - if (inIdentifier != null) { - noteDict.setValue_forKey(NSString.stringWithString(inIdentifier), GROWL_NOTIFICATION_IDENTIFIER); - } - - if (inExtraInfo != null) { - noteDict.addEntriesFromDictionary(inExtraInfo); - } - - theCenter.postNotification(GROWL_NOTIFICATION, null, noteDict, true); - } - - /** - * Convenience method that defers to postNotificationGrowlOf(String inNotificationName, - * NSData inIconData, String inTitle, String inDescription, - * NSDictionary inExtraInfo, boolean inSticky, String inIdentifier). - * This is primarily for compatibility with older code - * - * @param inNotificationName The name of one of the notifications we told growl - * about. - * @param inIcon The NSData for the icon for this notification, can be null - * @param inTitle The Title of our Notification as Growl will show it - * @param inDescription The Description of our Notification as Growl will - * display it - * @param inExtraInfo Growl is flexible and allows Display Plugins to do as - * they please with their own special keys and values, you - * may use them here. These may be ignored by either the - * user's preferences or the current Display Plugin. This - * can be null. - * @param inSticky Whether the Growl notification should be sticky. - * @throws IllegalArgumentException When a notification is not known - */ - public void postNotification(String inNotificationName, NSImage inIcon, String inTitle, String inDescription, - NSDictionary inExtraInfo, boolean inSticky) { - postNotification(inNotificationName, inIcon, inTitle, inDescription, inExtraInfo, inSticky, null); - } - - - /** - * Convenience method that defers to postNotificationGrowlOf(String inNotificationName, - * NSData inIconData, String inTitle, String inDescription, - * NSDictionary inExtraInfo, boolean inSticky, String inIdentifier). - * This is primarily for compatibility with older code - * - * @param inNotificationName The name of one of the notifications we told growl - * about. - * @param inIcon The NSData for the icon for this notification, can be null - * @param inTitle The Title of our Notification as Growl will show it - * @param inDescription The Description of our Notification as Growl will - * display it - * @param inExtraInfo Growl is flexible and allows Display Plugins to do as - * they please with their own special keys and values, you - * may use them here. These may be ignored by either the - * user's preferences or the current Display Plugin. This - * can be null. - * @throws IllegalArgumentException When a notification is not known - */ - public void postNotification(String inNotificationName, NSImage inIcon, String inTitle, String inDescription, - NSDictionary inExtraInfo) { - postNotification(inNotificationName, inIcon, inTitle, inDescription, inExtraInfo, false, null); - } - - /** - * Convenienve method that defers to postNotificationGrowlOf(String inNotificationName, - * NSData inIconData, String inTitle, String inDescription, - * NSDictionary inExtraInfo, boolean inSticky, String inIdentifier) with - * null passed for icon, extraInfo and identifier arguments - * - * @param inNotificationName The name of one of the notifications we told growl - * about. - * @param inTitle The Title of our Notification as Growl will show it - * @param inDescription The Description of our Notification as Growl will - * display it - * @throws IllegalArgumentException When a notification is not known - */ - public void postNotification(String inNotificationName, String inTitle, String inDescription) { - postNotification(inNotificationName, null, inTitle, inDescription, null, false, null); - } - - /** - * Convenience method that defers to postNotificationGrowlOf(String inNotificationName, - * NSData inIconData, String inTitle, String inDescription, - * NSDictionary inExtraInfo, boolean inSticky) - * with null passed for icon and extraInfo arguments. - * - * @param inNotificationName The name of one of the notifications we told growl - * about. - * @param inTitle The Title of our Notification as Growl will show it - * @param inDescription The Description of our Notification as Growl will - * display it - * @param inSticky Whether our notification should be sticky - * @throws IllegalArgumentException When a notification is not known - */ - public void postNotification(String inNotificationName, String inTitle, String inDescription, boolean inSticky) { - postNotification(inNotificationName, null, inTitle, inDescription, null, inSticky, null); - } - - - //************ Accessors **************// - - /** - * Accessor for The currently set "Application" Name - * - * @return String Application Name - */ - public String applicationName() { - return appName; - } - - /** - * Accessor for the Array of allowed Notifications returned an NSArray - * - * @return the array of allowed notifications. - */ - public List allowedNotifications() { - return allNotes; - } - - /** - * Accessor for the Array of default Notifications returned as an NSArray - * - * @return the array of default notifications. - */ - public List defaultNotifications() { - return defNotes; - } - - //************ Mutators **************// - - /** - * Sets The name of the Application talking to growl - * - * @param inAppName The Application Name - * @throws IllegalStateException if already registered - */ - public void setApplicationName(final String inAppName) { - if (registered) { - throw new IllegalStateException("Already registered"); - } - - appName = inAppName; - } - - /** - * Set the list of allowed Notifications - * - * @param inAllNotes The array of allowed Notifications - * @throws IllegalStateException if already registered - */ - public void setAllowedNotifications(final List inAllNotes) { - if (registered) { - throw new IllegalStateException("Already registered"); - } - - allNotes = Collections.unmodifiableList(new ArrayList(inAllNotes)); - } - - - /** - * Set the list of Default Notfiications - * - * @param inDefNotes The default Notifications - * @throws IllegalArgumentException when an element of the array is not in the - * allowedNotifications - * @throws IllegalStateException if already registered - */ - public void setDefaultNotifications(final List inDefNotes) { - if (registered) { - throw new IllegalStateException("Already registered"); - } - - for (String inDefNote : inDefNotes) { - if (!allNotes.contains(inDefNote)) { - // TODO: This check is not done in the constructor - throw new IllegalArgumentException("Array Element not in Allowed Notifications"); - } - } - - defNotes = Collections.unmodifiableList(new ArrayList(inDefNotes)); - } -} diff --git a/rococoa/rococoa-contrib/src/test/java/org/rococoa/contrib/appkit/NSOperationQueueTest.java b/rococoa/rococoa-contrib/src/test/java/org/rococoa/contrib/appkit/NSOperationQueueTest.java deleted file mode 100644 index b881dc03..00000000 --- a/rococoa/rococoa-contrib/src/test/java/org/rococoa/contrib/appkit/NSOperationQueueTest.java +++ /dev/null @@ -1,200 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.contrib.appkit; - -import java.util.ArrayList; -import java.util.List; -import org.junit.Before; -import org.junit.Test; -import org.rococoa.Foundation; -import org.rococoa.ObjCObject; -import static org.junit.Assert.*; -import org.rococoa.Rococoa; -import org.rococoa.cocoa.foundation.NSArray; -import org.rococoa.cocoa.foundation.NSInteger; -import org.rococoa.test.RococoaTestCase; - -/** Test case for mapping of NSOperationQueue. - * - */ -public class NSOperationQueueTest extends RococoaTestCase { - NSOperationQueue fixture; - - public NSOperationQueueTest() { - } - - - @Before - public void setUp() { - fixture = NSOperationQueue.CLASS.alloc().init(); - } - - private static class RunnableHolder { - final boolean[] results; - final ObjCObject[] runnables; - final NSInvocationOperation[] ops; - public RunnableHolder(int numItems) { - this.results = new boolean[numItems]; - runnables = new ObjCObject[numItems]; - ops = new NSInvocationOperation[numItems]; - for(int i=0; i < ops.length; i++) { - final int j = i; - Runnable r = new Runnable() { - public void run() { - synchronized(results) { - results[j] = true; - } - } - }; - ops[i] = NSInvocationOperation.CLASS.alloc(); - runnables[i] = Rococoa.proxy(r); - ops[i].initWithTarget_selector_object(runnables[i].id(), Foundation.selector("run"), null); - } - } - public void addOperations(NSOperationQueue queue) { - for(NSOperation op : ops) { - queue.addOperation(op); - } - } - public void addOperationsAndWait(NSOperationQueue queue, boolean wait) { - queue.addOperations_waitUntilFinished(NSArray.CLASS.arrayWithObjects(ops), wait); - } - public void checkResults() { - List incomplete = new ArrayList(results.length); - synchronized(results) { - for(int i=0; i < results.length; i++) { - if (!results[i]) incomplete.add(i); - } - } - assertEquals("Failed for items: " + incomplete, 0, incomplete.size()); - } - public int firstFailure() { - synchronized(results) { - for(int i=0; i < results.length; i++) { - if (!results[i]) return i; - } - return results.length -1; - } - } - } - - /** - * Test of addOperation method, of class NSOperationQueue. - */ - @Test - public void testAddOperation() throws InterruptedException { - RunnableHolder runnables = new RunnableHolder(250); - runnables.addOperations(fixture); - fixture.waitUntilAllOperationsAreFinished(); - assertEquals(0, fixture.operationCount().intValue()); - runnables.checkResults(); - } - - /** - * Test of addOperations_waitUntilFinished method, of class NSOperationQueue. - */ - @Test - public void testAddOperations_waitUntilFinished() { - RunnableHolder runnables = new RunnableHolder(250); - runnables.addOperationsAndWait(fixture, true); - assertEquals(0, fixture.operationCount().intValue()); - runnables.checkResults(); - - //without waiting - runnables = new RunnableHolder(250); - runnables.addOperationsAndWait(fixture, false); - fixture.waitUntilAllOperationsAreFinished(); - assertEquals(0, fixture.operationCount().intValue()); - runnables.checkResults(); - } - /** - * Test of cancelAllOperations method, of class NSOperationQueue. - */ - @Test - public void testCancelAllOperations() { - int numItems = 250; - RunnableHolder runnables = new RunnableHolder(numItems); - runnables.addOperations(fixture); - fixture.cancelAllOperations(); - fixture.waitUntilAllOperationsAreFinished(); - assertEquals(0, fixture.operationCount().intValue()); - int firstFailure = runnables.firstFailure(); - assertTrue("Not all should pass: " + firstFailure, 0 < firstFailure && firstFailure < numItems ); - assertTrue(runnables.ops[firstFailure].isCancelled()||runnables.ops[firstFailure].isReady()); - } - - /** - * Test of isSuspended method, of class NSOperationQueue. - */ - @Test - public void testIsSuspended() { - assertFalse(fixture.isSuspended()); - fixture.setSuspended(true); - assertTrue(fixture.isSuspended()); - fixture.setSuspended(false); - assertFalse(fixture.isSuspended()); - } - - /** - * Test of maxConcurrentOperationCount method, of class NSOperationQueue. - */ - @Test - public void testMaxConcurrentOperationCount() { - assertEquals(NSOperationQueue.NSOperationQueueDefaultMaxConcurrentOperationCount, fixture.maxConcurrentOperationCount().intValue()); - fixture.setMaxConcurrentOperationCount(new NSInteger(5)); - assertEquals(new NSInteger(5), fixture.maxConcurrentOperationCount()); - } - - /** - * Test of name method, of class NSOperationQueue. - */ - @Test - public void testName() { - assertNotSame("foo", fixture.name()); - fixture.setName("foo"); - assertEquals("foo", fixture.name()); - } - - /** - * Test of operationCount method, of class NSOperationQueue. - */ - @Test - public void testOperationCount() { - int numItems = 250; - RunnableHolder runnables = new RunnableHolder(numItems); - runnables.addOperations(fixture); - assertTrue(fixture.operationCount().intValue() > 0); - fixture.waitUntilAllOperationsAreFinished(); - assertEquals(0, fixture.operationCount().intValue()); - } - - /** - * Test of operations method, of class NSOperationQueue. - */ - @Test - public void testOperations() { - int numItems = 250; - RunnableHolder runnables = new RunnableHolder(numItems); - runnables.addOperations(fixture); - assertTrue("Should have some operations", fixture.operations().count() > 0); - fixture.waitUntilAllOperationsAreFinished(); - assertTrue("Should have completed all operations", fixture.operations().count() == 0); - } -} \ No newline at end of file diff --git a/rococoa/rococoa-contrib/src/test/java/org/rococoa/contrib/appkit/NSSpeechSynthesizerTest.java b/rococoa/rococoa-contrib/src/test/java/org/rococoa/contrib/appkit/NSSpeechSynthesizerTest.java deleted file mode 100644 index b23090ee..00000000 --- a/rococoa/rococoa-contrib/src/test/java/org/rococoa/contrib/appkit/NSSpeechSynthesizerTest.java +++ /dev/null @@ -1,583 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.contrib.appkit; - -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.rococoa.cocoa.foundation.NSAutoreleasePool; -import org.rococoa.cocoa.foundation.NSRange; -import org.rococoa.contrib.appkit.NSSpeechSynthesizer.NSSpeechStatus; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.*; - -import static org.junit.Assert.*; -/** - * Exercise the speech synthesizer. - */ -@Ignore -public class NSSpeechSynthesizerTest { - private static final int TIME_TO_WAIT = 5000; - private NSAutoreleasePool pool; - - @Before - public void preSetup() { - pool = NSAutoreleasePool.new_(); - } - - @After - public void postTeardown() { - pool.drain(); - } - - @Test - public void testDefaultVoice() { - assertNotNull(NSSpeechSynthesizer.CLASS.defaultVoice()); //System preference, so no way of knowing actual value - assertNotNull(NSSpeechSynthesizer.defaultVoice().getName()); - assertNotNull(NSSpeechSynthesizer.synthesizerWithVoice(null)); - assertEquals(NSSpeechSynthesizer.defaultVoice(), NSSpeechSynthesizer.synthesizerWithVoice(null).getVoice()); - } - - @Test - public void testAvailableVoices() { - assertEquals(NSSpeechSynthesizer.CLASS.availableVoices().count(), NSSpeechSynthesizer.availableVoices().size()); - assertTrue(NSSpeechSynthesizer.availableVoices().size() > 0); - assertNotNull(NSSpeechSynthesizer.availableVoices().get(0).getName()); - assertTrue(NSSpeechSynthesizer.availableVoices().get(0).getName().length() > 0); - } - - @Test - public void testAddGetSpeechDictionary() { - //first, let's teach the synth to talk like its from Newcastle (sort of) - NSSpeechDictionary dict = new NSSpeechDictionary(); - dict.setLocaleIdentifier(Locale.US); - Date now = new Date(); - dict.setModificationDate(now); - assertEquals(Locale.US, dict.getLocaleIdentifier()); - assertEquals(now, dict.getModificationDate()); - dict.addPronounciation(new NSSpeechDictionary.Entry("about", "AXbUWt")); //en_GB_geordie! - NSSpeechSynthesizer ss = NSSpeechSynthesizer.synthesizerWithVoice(null); - SynthesizerDelegate sd = new SynthesizerDelegate(ss); - ss.setDelegate(sd); - ss.addSpeechDictionary(dict); - ss.startSpeakingString("about"); - sd.waitForSpeechDone(TIME_TO_WAIT, true); - String[] expected = new String[]{"%", "AX", "b", "UW", "t", "%"}; - assertEquals(Arrays.asList(expected), sd.getPhonemesSpoken()); - - //Normally the synth falls into the SQL = 'S' 'Q' 'L' camp - sd.reset(); - ss.startSpeakingString("SQL"); - sd.waitForSpeechDone(TIME_TO_WAIT, true); - expected = new String[]{"%", "EH", "s", "k", "y", "UW", "EH", "l", "%"}; - assertEquals(Arrays.asList(expected), sd.getPhonemesSpoken()); - - //but we can make it say 'sequel' instead... - dict.setModificationDate(new Date()); - dict.addAbbreviation(new NSSpeechDictionary.Entry("SQL", "sIYkwAXl")); - ss.addSpeechDictionary(dict); - - sd.reset(); - ss.startSpeakingString("SQL"); - sd.waitForSpeechDone(TIME_TO_WAIT, true); - expected = new String[]{"%", "s", "IY", "k", "w", "AX", "l", "%"}; - assertEquals(Arrays.asList(expected), sd.getPhonemesSpoken()); - } - - @Test - public void testStartSpeakingString() throws InterruptedException { - NSSpeechSynthesizer ss = NSSpeechSynthesizer.synthesizerWithVoice(null); - SynthesizerDelegate sd = new SynthesizerDelegate(ss); - ss.startSpeakingString("Hello world"); - sd.waitForSpeechDone(TIME_TO_WAIT, true); - } - - @Test - public void testIsSpeaking() throws InterruptedException { - NSSpeechSynthesizer ss = NSSpeechSynthesizer.synthesizerWithVoice(null); - SynthesizerDelegate sd = new SynthesizerDelegate(ss); - assertTrue(!ss.isSpeaking()); - ss.startSpeakingString("Hello world"); - assertTrue(ss.isSpeaking()); - sd.waitForSpeechDone(TIME_TO_WAIT, true); - } - - @Test - public void testIsAnyApplicationSpeaking() throws InterruptedException { - NSSpeechSynthesizer ss = NSSpeechSynthesizer.synthesizerWithVoice(null); - SynthesizerDelegate sd = new SynthesizerDelegate(ss); - ss.setDelegate(sd); - assertTrue(!NSSpeechSynthesizer.isAnyApplicationSpeaking()); - ss.startSpeakingString("Hello world"); - assertTrue(NSSpeechSynthesizer.isAnyApplicationSpeaking()); - sd.waitForSpeechDone(TIME_TO_WAIT, true); - } - - @Test - public void testDidFinishSpeaking() { - NSSpeechSynthesizer ss = NSSpeechSynthesizer.synthesizerWithVoice(null); - SynthesizerDelegate sd = new SynthesizerDelegate(ss); - ss.setDelegate(sd); - ss.startSpeakingString("hello doctor"); - sd.waitForSpeechDone(TIME_TO_WAIT, true); - } - - @Test - public void testWillSpeakWord() { - NSSpeechSynthesizer ss = NSSpeechSynthesizer.synthesizerWithVoice(null); - SynthesizerDelegate sd = new SynthesizerDelegate(ss); - ss.setDelegate(sd); - String toSpeak = "hello doctor name"; - ss.startSpeakingString(toSpeak); - sd.waitForSpeechDone(5000, true); - assertEquals(Arrays.asList(toSpeak.split(" ")), sd.getWordsSpoken()); - } - - @Test - public void testWillSpeakPhoneme() { - NSSpeechSynthesizer ss = NSSpeechSynthesizer.synthesizerWithVoice(null); - SynthesizerDelegate sd = new SynthesizerDelegate(ss); - ss.setDelegate(sd); - String toSpeak = "blue daisy"; - ss.startSpeakingString(toSpeak); - sd.waitForSpeechDone(TIME_TO_WAIT, true); - //every so often some of the phonemes get flipped around, which isn't important to this test - List expected = new ArrayList(Arrays.asList(new String[]{"%", "b", "l", "UW", "d", "EY", "z", "IY", "%"})); - Collections.sort(expected); - List actual = new ArrayList(sd.getPhonemesSpoken()); - Collections.sort(actual); - assertEquals(expected, actual); - } - - @Test - public void testStopSpeakingAtBoundary() throws InterruptedException { - NSSpeechSynthesizer ss = NSSpeechSynthesizer.synthesizerWithVoice(null); - SynthesizerDelegate sd = new SynthesizerDelegate(ss); - ss.setDelegate(sd); - String toSpeak = "Hello are you receiving me now? I really hope someone is!"; - ss.startSpeakingString(toSpeak); - Thread.sleep(50); - ss.stopSpeakingAtBoundary(NSSpeechSynthesizer.NSSpeechBoundary.WordBoundary); - sd.waitForSpeechDone(TIME_TO_WAIT, false); - //don't want test case to be too timing dependent - assertTrue("Expected less than 3 words but got: " + sd.getWordsSpoken(), sd.getWordsSpoken().size() < 3); - assertTrue("Expected at least one word but got: " + sd.getWordsSpoken(), sd.getWordsSpoken().size() >= 1); - - //near as I can tell, SentenceBoundary just doesn't work! - sd.reset(); - ss.startSpeakingString(toSpeak); - sd.waitForNextWord(TIME_TO_WAIT); - ss.stopSpeakingAtBoundary(NSSpeechSynthesizer.NSSpeechBoundary.SentenceBoundary); - sd.waitForWord(TIME_TO_WAIT, "now"); - sd.waitForSpeechDone(TIME_TO_WAIT, false); - assertTrue("Expected 6 word sentence but got: " + sd.getWordsSpoken(), sd.getWordsSpoken().size() == 6); - - sd.reset(); - ss.startSpeakingString(toSpeak); - sd.waitForWord(TIME_TO_WAIT, "are"); - ss.stopSpeakingAtBoundary(NSSpeechSynthesizer.NSSpeechBoundary.ImmediateBoundary); - sd.waitForSpeechDone(TIME_TO_WAIT, false); - assertTrue("Expected less than 3 words but got: " + sd.getWordsSpoken(), sd.getWordsSpoken().size() < 3); - assertTrue("Expected at least one word but got: " + sd.getWordsSpoken(), sd.getWordsSpoken().size() >= 0); - } - - @Test - public void testGetStatus() { - NSSpeechSynthesizer ss = NSSpeechSynthesizer.synthesizerWithVoice(null); - SynthesizerDelegate sd = new SynthesizerDelegate(ss); - NSSpeechStatus status = ss.getStatus(); - assertEquals(status.isOutputBusy(), ss.isSpeaking()); - assertFalse(status.isOutputPaused()); - assertEquals("Should have no characters left", 0, status.getNumberOfCharactersLeft()); - assertEquals(0, status.getPhonemeCode()); - - ss.startSpeakingString("Status check"); - status = ss.getStatus(); - assertEquals(status.isOutputBusy(), ss.isSpeaking()); - assertFalse(status.isOutputPaused()); - assertTrue("Should have characters left", status.getNumberOfCharactersLeft() > 0); - //assertTrue("Opcode should not be zero", status.getPhonemeCode() != 0); always zero... seems to have word granularity - sd.waitForSpeechDone(TIME_TO_WAIT, true); - } - - @Test - public void testPauseSpeakingAtBoundary() throws InterruptedException { - NSSpeechSynthesizer ss = NSSpeechSynthesizer.synthesizerWithVoice(null); - SynthesizerDelegate sd = new SynthesizerDelegate(ss); - ss.startSpeakingString("Status check number two"); - sd.waitForNextWord(1000); - ss.pauseSpeakingAtBoundary(NSSpeechSynthesizer.NSSpeechBoundary.WordBoundary); - Thread.sleep(1000); //this API is very asynchronous ... need to sleep before polling status - NSSpeechStatus status = ss.getStatus(); - assertFalse("Output should not be busy", status.isOutputBusy()); - assertTrue("Output should be paused", status.isOutputPaused()); - assertEquals("Check number of characters left failed", 16, status.getNumberOfCharactersLeft()); - ss.continueSpeaking(); - sd.waitForNextWord(2500); - ss.pauseSpeakingAtBoundary(NSSpeechSynthesizer.NSSpeechBoundary.ImmediateBoundary); - Thread.sleep(TIME_TO_WAIT); - status = ss.getStatus(); - assertFalse("Output should not be busy", status.isOutputBusy()); - assertTrue("Output should be paused", status.isOutputPaused()); - assertEquals("Check number of characters left failed", 10, status.getNumberOfCharactersLeft()); - ss.continueSpeaking(); - sd.waitForSpeechDone(TIME_TO_WAIT, true); - } - - @Test - public void testPauseSpeakingAtSentenceBoundary() throws InterruptedException { - NSSpeechSynthesizer ss = NSSpeechSynthesizer.synthesizerWithVoice(null); - SynthesizerDelegate sd = new SynthesizerDelegate(ss); - ss.startSpeakingString("This is the way the world ends. Not with a bang."); - sd.waitForNextWord(1000); - ss.pauseSpeakingAtBoundary(NSSpeechSynthesizer.NSSpeechBoundary.SentenceBoundary); - sd.waitForWord(10000, "ends"); //this tells you the word is _about_ to be spoken - Thread.sleep(750); //so we need to wait a bit more - NSSpeechStatus status = ss.getStatus(); - assertFalse("Output should not be busy", status.isOutputBusy()); - assertTrue("Output should be paused", status.isOutputPaused()); - //often returns 22, which is just before 'ends'. There's a heck of a lag, basically, in the getStatus interface - assertTrue("Check number of characters left failed", status.getNumberOfCharactersLeft() >= 16); - ss.continueSpeaking(); - sd.waitForSpeechDone(5000, true); - } - - @Test - public void testGetError() throws InterruptedException { - NSSpeechSynthesizer ss = NSSpeechSynthesizer.synthesizerWithVoice(null); - SynthesizerDelegate sd = new SynthesizerDelegate(ss); - ss.startSpeakingString("Try this one [[pbas foobar]] two three"); - sd.waitForWord(1000, "three"); - assertTrue("Should have error position", sd.position > 0); - assertTrue("Should have error message", sd.errorMessage != null); - - NSSpeechSynthesizer.NSSpeechError error = ss.getError(); - assertTrue("Should find error", error.getErrorCount() > 0); - assertTrue("Should have error position", error.getNewestCharacterOffset() > 0); - assertTrue("Should have error code", error.getNewestCode() != 0); - sd.waitForSpeechDone(5000, true); - } - - @Test - public void testInputMode() { - NSSpeechSynthesizer ss = NSSpeechSynthesizer.synthesizerWithVoice(null); - assertEquals(NSSpeechSynthesizer.NSSpeechMode.Text, ss.getInputMode()); - ss.setInputMode(NSSpeechSynthesizer.NSSpeechMode.Text); - assertEquals("Should be text in, phonemes out", "_d1AOg.", ss.phonemesFromText("dog")); - ss.setInputMode(NSSpeechSynthesizer.NSSpeechMode.Phoneme); - assertEquals(NSSpeechSynthesizer.NSSpeechMode.Phoneme, ss.getInputMode()); - assertEquals("Should be phonemes in, phonemes out", "_d1AOg.", ss.phonemesFromText("_d1AOg.")); - } - - @Test - public void testCharacterMode() { - NSSpeechSynthesizer ss = NSSpeechSynthesizer.synthesizerWithVoice(null); - assertEquals(NSSpeechSynthesizer.NSSpeechMode.Normal, ss.getCharacterMode()); - ss.setCharacterMode(NSSpeechSynthesizer.NSSpeechMode.Normal); - assertEquals("Should say dog", "_d1AOg.", ss.phonemesFromText("dog")); - ss.setCharacterMode(NSSpeechSynthesizer.NSSpeechMode.Literal); - assertEquals(NSSpeechSynthesizer.NSSpeechMode.Literal, ss.getCharacterMode()); - assertEquals("Should say d o g", "_d1IY ~2OW _J1IY.", ss.phonemesFromText("dog")); - } - - @Test - public void testNumberMode() { - NSSpeechSynthesizer ss = NSSpeechSynthesizer.synthesizerWithVoice(null); - assertEquals(NSSpeechSynthesizer.NSSpeechMode.Normal, ss.getNumberMode()); - ss.setNumberMode(NSSpeechSynthesizer.NSSpeechMode.Normal); - assertEquals("Should say twelve", "_tw1EHlv.", ss.phonemesFromText("12")); - ss.setNumberMode(NSSpeechSynthesizer.NSSpeechMode.Literal); - assertEquals(NSSpeechSynthesizer.NSSpeechMode.Literal, ss.getNumberMode()); - assertEquals("Should say one two", "_w1UXn _t1UW.", ss.phonemesFromText("12")); - } - - @Test - public void testSynthesizerInfo() { - NSSpeechSynthesizer ss = NSSpeechSynthesizer.synthesizerWithVoice(null); - NSSpeechSynthesizer.NSSpeechSynthesizerInfo ssi = ss.getSynthesizerInfo(); - assertTrue(ssi.getSynthesizerIdentifier() != null); - assertTrue(ssi.getSynthesizerVersion() != null); - } - - @Test - public void testPitchBase() { - NSSpeechSynthesizer ss = NSSpeechSynthesizer.synthesizerWithVoice(null); - float pitchBase = ss.getPitchBase(); - assertTrue(pitchBase > 0.0f); - ss.setPitchBase(pitchBase * 1.5f); - assertEquals(pitchBase * 1.5f, ss.getPitchBase(), 0.001); - } - - @Test - public void testPitchMod() { - NSSpeechSynthesizer ss = NSSpeechSynthesizer.synthesizerWithVoice(null); - float pitchMod = ss.getPitchMod(); - assertTrue(pitchMod > 0.0f); - ss.setPitchMod(pitchMod * 0.9f); - assertEquals(pitchMod * 0.9f, ss.getPitchMod(), 0.001); - try { - ss.setPitchMod(-1.0f); - fail("Should have thrown IllegalArgumentException"); - } catch (IllegalArgumentException iae) { - } - try { - ss.setPitchMod(127.1f); - fail("Should have thrown IllegalArgumentException"); - } catch (IllegalArgumentException iae) { - } - } - - @Test - public void testPhonemeInfo() { - NSSpeechSynthesizer ss = NSSpeechSynthesizer.synthesizerWithVoice(null); - List spis = ss.getPhonemeInfo(); - assertTrue(spis.size() > 5); - NSSpeechSynthesizer.NSSpeechPhonemeInfo spi = spis.get(4); - assertTrue(spi.getExample() != null); - assertTrue(spi.getSymbol() != null); - assertTrue(spi.getHiliteEnd() >= 0); - assertTrue(spi.getHiliteStart() >= 0); - assertTrue(spi.getOpcode() != 0); - - } - - @Test - public void testRecentSyncAndCallback() throws InterruptedException { - NSSpeechSynthesizer ss = NSSpeechSynthesizer.synthesizerWithVoice(null); - SynthesizerDelegate sd = new SynthesizerDelegate(ss); - ss.startSpeakingString("I see no " + NSSpeechSynthesizer.createSyncPoint('A') + " ships sailing"); - sd.waitForWord(2500, "sailing"); - assertEquals("Should have synch with A", "A", sd.synchMark); - sd.waitForSpeechDone(3000, true); - assertEquals("Should be able to get recent sync", 'A', ss.getRecentSync()); - } - - @Test - public void testVoice() { - NSSpeechSynthesizer ss = NSSpeechSynthesizer.synthesizerWithVoice(null); - NSVoice defaultVoice = NSSpeechSynthesizer.defaultVoice(); - assertEquals(defaultVoice, ss.getVoice()); - assertEquals(defaultVoice.getIdentifier(), ss.voice()); - ss.setVoice(NSVoice.SAMANTHA); - assertEquals(NSVoice.SAMANTHA, ss.voice()); - assertEquals(new NSVoice(NSVoice.SAMANTHA), ss.getVoice()); - ss.setVoice(NSVoice.ALEX); - assertEquals(new NSVoice(NSVoice.ALEX), ss.getVoice()); - ss = NSSpeechSynthesizer.synthesizerWithVoice(new NSVoice(NSVoice.FRED)); - assertEquals(new NSVoice(NSVoice.FRED), ss.getVoice()); - } - - - @Test - public void testCommandDelimiter() { - NSSpeechSynthesizer ss = NSSpeechSynthesizer.synthesizerWithVoice(null); - SynthesizerDelegate sd = new SynthesizerDelegate(ss); - - // this raises a question - NSSpeechCommand - should it encapsulate the available commands and - //offer factory methods? e.g. NSSpeechCommand.createSyncPoint above has a bug, in the sense that it doesn't know what the - //current delimiters actually are... actually, since there's no API to GET the current delimiters, in the general case it can't - //work - the caller would always have to pass them in - still could maybe work as a factory still, just more complex - //something like NSSpeechCommand.createSync(String prefix, String suffix, String syncPoint) ? - - ss.setCommandDelimiter(new NSSpeechSynthesizer.NSSpeechCommand("{", "}")); - ss.startSpeakingString("I see no {sync 0x42} ships sailing"); - sd.waitForWord(2500, "sailing"); - assertEquals("Should have synch with B", "B", sd.synchMark); - sd.waitForSpeechDone(3000, true); - - } - - @Test - public void testReset() { - NSSpeechSynthesizer ss = NSSpeechSynthesizer.synthesizerWithVoice(null); - float pitchBase = ss.getPitchBase(); - assertTrue(pitchBase > 0.0f); - ss.setPitchBase(pitchBase + 1.0f); - assertEquals(pitchBase + 1.0f, ss.getPitchBase(), 0.001); - ss.reset(); - assertEquals(pitchBase, ss.getPitchBase(), 0.001); - } - - //pass null for computer speakers - @Test - public void testSetOutputToFileURL() throws IOException { - File helloWorld = null; - FileInputStream fis = null; - try { - helloWorld = File.createTempFile("helloworld", ".aiff"); - helloWorld.deleteOnExit(); - NSSpeechSynthesizer ss = NSSpeechSynthesizer.synthesizerWithVoice(null); - SynthesizerDelegate sd = new SynthesizerDelegate(ss); - ss.setOutputToFileURL(helloWorld.toURI()); - ss.startSpeakingString("Hello World"); - sd.waitForSpeechDone(5000, true); - assertTrue(helloWorld.exists()); - fis = new FileInputStream(helloWorld); - assertTrue("Should have some bytes", fis.available() > 0); - } finally { - if (fis != null) { - fis.close(); - } - if (helloWorld != null) { - helloWorld.delete(); - } - } - } - - @Test - public void testStartSpeakingStringToURL() throws IOException { - File helloWorld = null; - FileInputStream fis = null; - try { - helloWorld = File.createTempFile("helloworld", ".aiff"); - helloWorld.deleteOnExit(); - NSSpeechSynthesizer ss = NSSpeechSynthesizer.synthesizerWithVoice(null); - SynthesizerDelegate sd = new SynthesizerDelegate(ss); - ss.startSpeakingStringToURL("Hello World", helloWorld.toURI()); - sd.waitForSpeechDone(5000, true); - assertTrue(helloWorld.exists()); - fis = new FileInputStream(helloWorld); - assertTrue("Should have some bytes", fis.available() > 0); - } finally { - if (fis != null) { - fis.close(); - } - if (helloWorld != null) { - helloWorld.delete(); - } - } - } - - private static class SynthesizerDelegate implements NSSpeechSynthesizer.NSSpeechSynthesizerDelegate { - - private volatile boolean success = false; - private List wordsSpoken = new ArrayList(); - private List phonemesSpoken = new ArrayList(); - private String wordWaitingFor; - private int position = -1; - private String synchMark; - private String errorMessage; - private static final Object speechDoneMonitor = new Object(); - private static final Object waitForSpeechWordMonitor = new Object(); - - SynthesizerDelegate(NSSpeechSynthesizer ss) { - ss.setDelegate(this); - } - - public void reset() { - success = false; - wordsSpoken.clear(); - phonemesSpoken.clear(); - wordWaitingFor = null; - position = -1; - errorMessage = null; - synchMark = null; - } - - public boolean isSuccess() { - return success; - } - - public List getWordsSpoken() { - return wordsSpoken; - } - - public List getPhonemesSpoken() { - return phonemesSpoken; - } - - public void speechSynthesizer_didFinishSpeaking(NSSpeechSynthesizer sender, final boolean success) { - this.success = success; - synchronized (speechDoneMonitor) { - speechDoneMonitor.notify(); - } - } - - public void waitForSpeechDone(long interval, boolean stoppedNormally) { - synchronized (speechDoneMonitor) { - try { - speechDoneMonitor.wait(interval); - assertEquals("Success flag check failed", stoppedNormally, isSuccess()); - } catch (InterruptedException ex) { - fail("Should have been notified in " + getCallerName() + " but interrupted out: " + ex); - } - } - } - - public void waitForNextWord(long interval) { - synchronized (waitForSpeechWordMonitor) { - try { - waitForSpeechWordMonitor.wait(interval); - } catch (InterruptedException ex) { - fail("Should have been notified in " + getCallerName() + " but interrupted out: " + ex); - } - } - } - - public void waitForWord(long interval, final String word) { - synchronized (waitForSpeechWordMonitor) { - wordWaitingFor = word; - try { - waitForSpeechWordMonitor.wait(interval); - } catch (InterruptedException ex) { - fail("Should have been notified in " + getCallerName() + " but interrupted out: " + ex); - } - } - } - - private String getCallerName() { - for (StackTraceElement ste : Thread.currentThread().getStackTrace()) { - if (ste.getMethodName().startsWith("test")) { - return ste.getMethodName(); - } - } - return "Unknown method"; - } - - public void speechSynthesizer_didEncounterErrorAtIndex_ofString_message(NSSpeechSynthesizer sender, Integer characterIndex, String text, String errorMessage) { - position = characterIndex; - this.errorMessage = errorMessage; - //System.out.println(errorMessage); - //System.out.println("In callback: " + sender.getError()); - } - - public void speechSynthesizer_didEncounterSyncMessage(NSSpeechSynthesizer sender, String synchMark) { - this.synchMark = synchMark; - // System.out.println("In callback, sync: " + sender.getRecentSync()); - } - - public synchronized void speechSynthesizer_willSpeakPhoneme(NSSpeechSynthesizer sender, short phonemeOpcode) { - phonemesSpoken.add(sender.opcodeToPhoneme(phonemeOpcode)); - } - - public void speechSynthesizer_willSpeakWord_ofString(NSSpeechSynthesizer sender, NSRange wordToSpeak, String text) { - wordsSpoken.add(text.substring((int) wordToSpeak.getLocation(), (int) wordToSpeak.getEndLocation())); - if (wordWaitingFor == null || wordsSpoken.get(wordsSpoken.size() - 1).equals(wordWaitingFor)) { - synchronized (waitForSpeechWordMonitor) { - waitForSpeechWordMonitor.notify(); - } - } - } - } -} diff --git a/rococoa/rococoa-contrib/src/test/java/org/rococoa/contrib/appkit/NSVoiceTest.java b/rococoa/rococoa-contrib/src/test/java/org/rococoa/contrib/appkit/NSVoiceTest.java deleted file mode 100644 index db721086..00000000 --- a/rococoa/rococoa-contrib/src/test/java/org/rococoa/contrib/appkit/NSVoiceTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ -package org.rococoa.contrib.appkit; - -import java.util.Locale; - -import org.junit.Ignore; -import org.junit.Test; -import org.rococoa.cocoa.foundation.NSArray; -import org.rococoa.contrib.appkit.NSVoice.VoiceGender; -import org.rococoa.test.RococoaTestCase; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -/** - * Simple tests for functionality of the voice class - */ -public class NSVoiceTest extends RococoaTestCase { - - @Test - @Ignore - @SuppressWarnings("deprecation") - public void testAttributesForVoice() { - NSVoice voice = new NSVoice(NSVoice.VICTORIA); - assertEquals(35, voice.getAge()); - assertEquals("Isn't it nice to have a computer that will talk to you?", voice.getDemoText()); - assertEquals(VoiceGender.Female, voice.getGender()); - assertEquals(NSVoice.VICTORIA, voice.getIdentifier()); - assertEquals(Locale.US.toString(), voice.getLocaleIdentifier()); - assertEquals("en-US", voice.getLanguage()); //deprecated method, but we test it anyway - assertEquals("Victoria", voice.getName()); - NSArray supportedChars = voice.getSupportedCharacters(); - assertNotNull(supportedChars); - assertTrue(supportedChars.count() > 0); - NSArray individuallySpokenChars = voice.getIndividuallySpokenCharacters(); - assertNotNull(individuallySpokenChars); - assertTrue(individuallySpokenChars.count() > 0); - } - - @Test(expected=IllegalArgumentException.class) - @Ignore - public void testBadIdentifier() { - String badId = "This voice does not exist"; - try { - new NSVoice(badId); - } catch (IllegalArgumentException e) { - assertTrue(e.getMessage().indexOf(badId) > 0); - throw e; - } - } -} diff --git a/rococoa/rococoa-contrib/src/test/java/org/rococoa/contrib/dispatch/GCDExecutorServiceTest.java b/rococoa/rococoa-contrib/src/test/java/org/rococoa/contrib/dispatch/GCDExecutorServiceTest.java deleted file mode 100644 index 94450dc5..00000000 --- a/rococoa/rococoa-contrib/src/test/java/org/rococoa/contrib/dispatch/GCDExecutorServiceTest.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.contrib.dispatch; - -import java.util.List; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Future; -import java.util.concurrent.RejectedExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import static org.junit.Assert.*; - -/** Test the API of the GCDExecutorService. - * @author Andrew Thompson (lordpixel@mac.com) - */ -public class GCDExecutorServiceTest { - /**The GCD Executor to test*/ - ExecutorService fixture; - public GCDExecutorServiceTest() { - } - - @BeforeClass - public static void setupLogging() { - } - - @Before - public void setUp() { - fixture = new GCDExecutorService(); - } - - /** - * Test of shutdown method, of class GCDExecutorService. - */ - @Test(expected=RejectedExecutionException.class) - public void testShutdown() { - fixture.shutdown(); - assertTrue(fixture.isShutdown()); - assertTrue(fixture.isTerminated()); - fixture.execute(new Runnable() { - public void run() {} - }); - } - - @Test - public void testShutdown_TasksFinish() throws InterruptedException { - final boolean[] finished = { false }; - fixture.execute(new Runnable() { - public void run() { - finished[0] = true; - } - }); - fixture.shutdown(); - assertTrue(fixture.isShutdown()); - Thread.sleep(100); - List unrun = fixture.shutdownNow(); - assertTrue( finished[0] + ", " + unrun, finished[0] && unrun.size() == 0 ); - } - - /** - * Test of shutdownNow method, of class GCDExecutorService. - */ - @Test - public void testShutdownNow() throws InterruptedException { - Object lock = new Object(); - int count = 100; - queueUpSomeTasks(lock, count); - List outstandingTasks = fixture.shutdownNow(); - assertEquals(count, outstandingTasks.size()); - assertTrue(fixture.isShutdown()); - synchronized(lock) { - lock.notifyAll(); - } - assertTrue(fixture.awaitTermination(10, TimeUnit.SECONDS)); - } - - private void queueUpSomeTasks(final Object lock, int count) { - for (int i=0; i < count; i++) { - fixture.execute(new Runnable() { - public void run() { - try { - synchronized(lock) { - lock.wait(); - } - } catch (InterruptedException ie) { - - } - } - }); - } - } - - /** - * Test of isShutdown method, of class GCDExecutorService. - */ - @Test - public void testIsShutdown() { - fixture.shutdown(); - assertTrue(fixture.isShutdown()); - } - - /** - * Test of awaitTermination method, of class GCDExecutorService. - */ - @Test - public void testAwaitTermination() throws Exception { - int count=100; - Object lock = new Object(); - queueUpSomeTasks(lock, count); - List outstandingTasks = fixture.shutdownNow(); - assertEquals(count, outstandingTasks.size()); - assertTrue(fixture.isShutdown()); - synchronized(lock) { - lock.notifyAll(); - } - assertTrue(fixture.awaitTermination(5, TimeUnit.SECONDS)); - assertTrue(fixture.isTerminated()); - } - - /** - * Test of execute method, of class GCDExecutorService. - */ - @Test - public void testExecute() throws InterruptedException { - final boolean[] done = { false }; - fixture.execute(new Runnable() { - public void run() { - done[0]=true; - } - }); - Thread.sleep(1000); - assertTrue(done[0]); - } - - @Test - public void testSubmit_Callable() throws InterruptedException, ExecutionException { - Future result = fixture.submit(new Callable () { - public Boolean call() { - return true; - } - }); - assertTrue(result.get()); - } - @Test - public void testSubmit_Runnable() throws InterruptedException, ExecutionException, TimeoutException { - final boolean[] runCheck = { false }; - Future result = fixture.submit(new Runnable () { - public void run() { - runCheck[0] = true; - } - }); - assertEquals(null, result.get()); - assertTrue(runCheck[0]); - } - @Test - public void testSubmit_Runnable_WithResult() throws InterruptedException, ExecutionException, TimeoutException { - final boolean[] runCheck = { false }; - Future result = fixture.submit(new Runnable () { - public void run() { - runCheck[0] = true; - } - }, 42); - assertEquals(Integer.valueOf(42), result.get()); - assertTrue(runCheck[0]); - } -} diff --git a/rococoa/rococoa-core/dylib/pom.xml b/rococoa/rococoa-core/dylib/pom.xml deleted file mode 100644 index 17baeac1..00000000 --- a/rococoa/rococoa-core/dylib/pom.xml +++ /dev/null @@ -1,86 +0,0 @@ - - - 4.0.0 - librococoa - Rococoa Core Native Library - https://github.com/iterate-ch/rococoa - - org.rococoa - rococoa-parent - ../../pom.xml - 0.10.1-SNAPSHOT - - - - - maven-antrun-plugin - - - build-native - compile - - run - - - - - - - - - - - - - - - - build-native-clean - clean - - run - - - - - - - - - - - - - - - - - - - org.codehaus.mojo - build-helper-maven-plugin - - - test-compile - - attach-artifact - - - - - dylib - ${project.basedir}/../build/Release/librococoa.dylib - - - dylib - test - ${project.basedir}/../build/Release/librococoa-test.dylib - - - - - - - - - diff --git a/rococoa/rococoa-core/pom.xml b/rococoa/rococoa-core/pom.xml deleted file mode 100644 index f87744b0..00000000 --- a/rococoa/rococoa-core/pom.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - 4.0.0 - rococoa-core - jar - Rococoa Core - https://github.com/iterate-ch/rococoa - - org.rococoa - rococoa-parent - 0.10.1-SNAPSHOT - - - - net.java.dev.jna - jna - - - net.bytebuddy - byte-buddy - - - org.rococoa - librococoa - dylib - - - org.rococoa - librococoa - test - dylib - test - - - - - - maven-jar-plugin - - - - test-jar - - - - - - maven-surefire-plugin - - once - - - - maven-assembly-plugin - - - - diff --git a/rococoa/rococoa-core/rococoa.xcodeproj/project.pbxproj b/rococoa/rococoa-core/rococoa.xcodeproj/project.pbxproj deleted file mode 100644 index 0bf36a3d..00000000 --- a/rococoa/rococoa-core/rococoa.xcodeproj/project.pbxproj +++ /dev/null @@ -1,476 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 55; - objects = { - -/* Begin PBXBuildFile section */ - 47E7801E2555A8E400D21DBB /* test.h in Headers */ = {isa = PBXBuildFile; fileRef = AECF4DC90D042C5F00B44D6E /* test.h */; }; - 47E780212555A8E400D21DBB /* test.m in Sources */ = {isa = PBXBuildFile; fileRef = AECF4DCA0D042C5F00B44D6E /* test.m */; }; - 47E780252555A8E400D21DBB /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 08FB779EFE84155DC02AAC07 /* Foundation.framework */; }; - 47E7803A2555A90D00D21DBB /* librococoa-test.dylib in CopyFiles */ = {isa = PBXBuildFile; fileRef = 47E7802B2555A8E400D21DBB /* librococoa-test.dylib */; }; - 47E7803E2555A95C00D21DBB /* librococoa.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = AED079210CEC69DC00542DAC /* librococoa.dylib */; }; - AE1E31B20CFB1D1900508B04 /* ProxyForJava.h in Headers */ = {isa = PBXBuildFile; fileRef = AE1E31AE0CFB1D1900508B04 /* ProxyForJava.h */; }; - AE1E31B30CFB1D1900508B04 /* ProxyForJava.m in Sources */ = {isa = PBXBuildFile; fileRef = AE1E31AF0CFB1D1900508B04 /* ProxyForJava.m */; }; - AEA357FC0CEDFBDF00AE7D09 /* Rococoa.m in Sources */ = {isa = PBXBuildFile; fileRef = AEA357790CECA01400AE7D09 /* Rococoa.m */; }; - AEAEF7770D0EAEE700DA270B /* librococoa.dylib in CopyFiles */ = {isa = PBXBuildFile; fileRef = AED079210CEC69DC00542DAC /* librococoa.dylib */; }; - AED079230CEC6A0A00542DAC /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 08FB779EFE84155DC02AAC07 /* Foundation.framework */; }; -/* End PBXBuildFile section */ - -/* Begin PBXContainerItemProxy section */ - 47E780382555A8FB00D21DBB /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 08FB7793FE84155DC02AAC07 /* Project object */; - proxyType = 1; - remoteGlobalIDString = AED079200CEC69DC00542DAC; - remoteInfo = librococoa; - }; -/* End PBXContainerItemProxy section */ - -/* Begin PBXCopyFilesBuildPhase section */ - 47E780262555A8E400D21DBB /* CopyFiles */ = { - isa = PBXCopyFilesBuildPhase; - buildActionMask = 2147483647; - dstPath = ../..; - dstSubfolderSpec = 16; - files = ( - 47E7803A2555A90D00D21DBB /* librococoa-test.dylib in CopyFiles */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - AEAEF7750D0EAED000DA270B /* CopyFiles */ = { - isa = PBXCopyFilesBuildPhase; - buildActionMask = 2147483647; - dstPath = ../..; - dstSubfolderSpec = 16; - files = ( - AEAEF7770D0EAEE700DA270B /* librococoa.dylib in CopyFiles */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXCopyFilesBuildPhase section */ - -/* Begin PBXFileReference section */ - 08FB779EFE84155DC02AAC07 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = ""; }; - 47E7802B2555A8E400D21DBB /* librococoa-test.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = "librococoa-test.dylib"; sourceTree = BUILT_PRODUCTS_DIR; }; - AE1E31AE0CFB1D1900508B04 /* ProxyForJava.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProxyForJava.h; sourceTree = ""; }; - AE1E31AF0CFB1D1900508B04 /* ProxyForJava.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ProxyForJava.m; sourceTree = ""; }; - AEA357770CECA01400AE7D09 /* scratch.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = scratch.m; sourceTree = ""; }; - AEA357780CECA01400AE7D09 /* Rococoa.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = Rococoa.h; sourceTree = ""; }; - AEA357790CECA01400AE7D09 /* Rococoa.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = Rococoa.m; sourceTree = ""; }; - AECF4DC90D042C5F00B44D6E /* test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = test.h; sourceTree = ""; }; - AECF4DCA0D042C5F00B44D6E /* test.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = test.m; sourceTree = ""; }; - AED079210CEC69DC00542DAC /* librococoa.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = librococoa.dylib; sourceTree = BUILT_PRODUCTS_DIR; }; - C6859EA3029092ED04C91782 /* rococoa.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = rococoa.1; sourceTree = ""; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - 47E780242555A8E400D21DBB /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 47E7803E2555A95C00D21DBB /* librococoa.dylib in Frameworks */, - 47E780252555A8E400D21DBB /* Foundation.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - AED0791F0CEC69DC00542DAC /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - AED079230CEC6A0A00542DAC /* Foundation.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 08FB7794FE84155DC02AAC07 /* rococoa */ = { - isa = PBXGroup; - children = ( - 08FB7795FE84155DC02AAC07 /* Source */, - C6859EA2029092E104C91782 /* Documentation */, - 08FB779DFE84155DC02AAC07 /* External Frameworks and Libraries */, - 1AB674ADFE9D54B511CA2CBB /* Products */, - 47E7803D2555A95C00D21DBB /* Frameworks */, - ); - name = rococoa; - sourceTree = ""; - }; - 08FB7795FE84155DC02AAC07 /* Source */ = { - isa = PBXGroup; - children = ( - AEA357760CECA01400AE7D09 /* native */, - ); - name = Source; - sourceTree = ""; - }; - 08FB779DFE84155DC02AAC07 /* External Frameworks and Libraries */ = { - isa = PBXGroup; - children = ( - 08FB779EFE84155DC02AAC07 /* Foundation.framework */, - ); - name = "External Frameworks and Libraries"; - sourceTree = ""; - }; - 1AB674ADFE9D54B511CA2CBB /* Products */ = { - isa = PBXGroup; - children = ( - AED079210CEC69DC00542DAC /* librococoa.dylib */, - 47E7802B2555A8E400D21DBB /* librococoa-test.dylib */, - ); - name = Products; - sourceTree = ""; - }; - 47E7803D2555A95C00D21DBB /* Frameworks */ = { - isa = PBXGroup; - children = ( - ); - name = Frameworks; - sourceTree = ""; - }; - AEA357760CECA01400AE7D09 /* native */ = { - isa = PBXGroup; - children = ( - AE1E31AE0CFB1D1900508B04 /* ProxyForJava.h */, - AE1E31AF0CFB1D1900508B04 /* ProxyForJava.m */, - AECF4DC90D042C5F00B44D6E /* test.h */, - AECF4DCA0D042C5F00B44D6E /* test.m */, - AEA357770CECA01400AE7D09 /* scratch.m */, - AEA357780CECA01400AE7D09 /* Rococoa.h */, - AEA357790CECA01400AE7D09 /* Rococoa.m */, - ); - name = native; - path = src/main/native; - sourceTree = ""; - }; - C6859EA2029092E104C91782 /* Documentation */ = { - isa = PBXGroup; - children = ( - C6859EA3029092ED04C91782 /* rococoa.1 */, - ); - name = Documentation; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXHeadersBuildPhase section */ - 47E7801D2555A8E400D21DBB /* Headers */ = { - isa = PBXHeadersBuildPhase; - buildActionMask = 2147483647; - files = ( - 47E7801E2555A8E400D21DBB /* test.h in Headers */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - AED0791D0CEC69DC00542DAC /* Headers */ = { - isa = PBXHeadersBuildPhase; - buildActionMask = 2147483647; - files = ( - AE1E31B20CFB1D1900508B04 /* ProxyForJava.h in Headers */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXHeadersBuildPhase section */ - -/* Begin PBXNativeTarget section */ - 47E7801C2555A8E400D21DBB /* librococoa-test */ = { - isa = PBXNativeTarget; - buildConfigurationList = 47E780282555A8E400D21DBB /* Build configuration list for PBXNativeTarget "librococoa-test" */; - buildPhases = ( - 47E7801D2555A8E400D21DBB /* Headers */, - 47E780202555A8E400D21DBB /* Sources */, - 47E780242555A8E400D21DBB /* Frameworks */, - 47E780262555A8E400D21DBB /* CopyFiles */, - ); - buildRules = ( - ); - dependencies = ( - 47E780392555A8FB00D21DBB /* PBXTargetDependency */, - ); - name = "librococoa-test"; - productName = rococoalib; - productReference = 47E7802B2555A8E400D21DBB /* librococoa-test.dylib */; - productType = "com.apple.product-type.library.dynamic"; - }; - AED079200CEC69DC00542DAC /* librococoa */ = { - isa = PBXNativeTarget; - buildConfigurationList = AED079A10CEC6A3800542DAC /* Build configuration list for PBXNativeTarget "librococoa" */; - buildPhases = ( - AED0791D0CEC69DC00542DAC /* Headers */, - AED0791E0CEC69DC00542DAC /* Sources */, - AED0791F0CEC69DC00542DAC /* Frameworks */, - AEAEF7750D0EAED000DA270B /* CopyFiles */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = librococoa; - productName = rococoalib; - productReference = AED079210CEC69DC00542DAC /* librococoa.dylib */; - productType = "com.apple.product-type.library.dynamic"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - 08FB7793FE84155DC02AAC07 /* Project object */ = { - isa = PBXProject; - attributes = { - LastUpgradeCheck = 1210; - }; - buildConfigurationList = 1DEB927808733DD40010E9CD /* Build configuration list for PBXProject "rococoa" */; - compatibilityVersion = "Xcode 13.0"; - developmentRegion = en; - hasScannedForEncodings = 1; - knownRegions = ( - en, - Base, - ); - mainGroup = 08FB7794FE84155DC02AAC07 /* rococoa */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - AED079200CEC69DC00542DAC /* librococoa */, - 47E7801C2555A8E400D21DBB /* librococoa-test */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXSourcesBuildPhase section */ - 47E780202555A8E400D21DBB /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 47E780212555A8E400D21DBB /* test.m in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - AED0791E0CEC69DC00542DAC /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - AEA357FC0CEDFBDF00AE7D09 /* Rococoa.m in Sources */, - AE1E31B30CFB1D1900508B04 /* ProxyForJava.m in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin PBXTargetDependency section */ - 47E780392555A8FB00D21DBB /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = AED079200CEC69DC00542DAC /* librococoa */; - targetProxy = 47E780382555A8FB00D21DBB /* PBXContainerItemProxy */; - }; -/* End PBXTargetDependency section */ - -/* Begin XCBuildConfiguration section */ - 1DEB927908733DD40010E9CD /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_TESTABILITY = YES; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.13; - ONLY_ACTIVE_ARCH = YES; - }; - name = Debug; - }; - 1DEB927A08733DD40010E9CD /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.13; - }; - name = Release; - }; - 47E780292555A8E400D21DBB /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_ENABLE_OBJC_WEAK = YES; - COPY_PHASE_STRIP = NO; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - GCC_DYNAMIC_NO_PIC = NO; - GCC_GENERATE_DEBUGGING_SYMBOLS = YES; - GCC_MODEL_TUNING = G5; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h"; - INSTALL_PATH = /usr/local/lib; - OTHER_LDFLAGS = ( - "-framework", - Foundation, - "-framework", - AppKit, - ); - PRODUCT_NAME = "$(TARGET_NAME)"; - ZERO_LINK = YES; - }; - name = Debug; - }; - 47E7802A2555A8E400D21DBB /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_ENABLE_OBJC_WEAK = YES; - COPY_PHASE_STRIP = YES; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - GCC_DYNAMIC_NO_PIC = NO; - GCC_GENERATE_DEBUGGING_SYMBOLS = NO; - GCC_MODEL_TUNING = G5; - GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h"; - INSTALL_PATH = /usr/local/lib; - OTHER_LDFLAGS = ( - "-framework", - Foundation, - "-framework", - AppKit, - ); - PRODUCT_NAME = "$(TARGET_NAME)"; - ZERO_LINK = NO; - }; - name = Release; - }; - AED079A20CEC6A3800542DAC /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ENABLE_OBJC_WEAK = YES; - COPY_PHASE_STRIP = NO; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - GCC_DYNAMIC_NO_PIC = NO; - GCC_GENERATE_DEBUGGING_SYMBOLS = YES; - GCC_MODEL_TUNING = G5; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h"; - INSTALL_PATH = "@loader_path"; - OTHER_LDFLAGS = ( - "-framework", - Foundation, - "-framework", - AppKit, - ); - PRODUCT_NAME = librococoa; - ZERO_LINK = YES; - }; - name = Debug; - }; - AED079A30CEC6A3800542DAC /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ENABLE_OBJC_WEAK = YES; - COPY_PHASE_STRIP = YES; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - GCC_DYNAMIC_NO_PIC = NO; - GCC_GENERATE_DEBUGGING_SYMBOLS = NO; - GCC_MODEL_TUNING = G5; - GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h"; - INSTALL_PATH = "@loader_path"; - OTHER_LDFLAGS = ( - "-framework", - Foundation, - "-framework", - AppKit, - ); - PRODUCT_NAME = librococoa; - ZERO_LINK = NO; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 1DEB927808733DD40010E9CD /* Build configuration list for PBXProject "rococoa" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 1DEB927908733DD40010E9CD /* Debug */, - 1DEB927A08733DD40010E9CD /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 47E780282555A8E400D21DBB /* Build configuration list for PBXNativeTarget "librococoa-test" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 47E780292555A8E400D21DBB /* Debug */, - 47E7802A2555A8E400D21DBB /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - AED079A10CEC6A3800542DAC /* Build configuration list for PBXNativeTarget "librococoa" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - AED079A20CEC6A3800542DAC /* Debug */, - AED079A30CEC6A3800542DAC /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = 08FB7793FE84155DC02AAC07 /* Project object */; -} diff --git a/rococoa/rococoa-core/src/main/assembly/dist.xml b/rococoa/rococoa-core/src/main/assembly/dist.xml deleted file mode 100644 index 2e4b10c0..00000000 --- a/rococoa/rococoa-core/src/main/assembly/dist.xml +++ /dev/null @@ -1,46 +0,0 @@ - - src - - tar.gz - zip - - - - bin - - *.dylib - - - - target - dist - - *.jar - - - - target - lib - - *.jar - - - - src - - - src/main/doc - / - - * - - - - - - lib - false - runtime - - - \ No newline at end of file diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/AlreadyRetained.java b/rococoa/rococoa-core/src/main/java/org/rococoa/AlreadyRetained.java deleted file mode 100644 index a9829661..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/AlreadyRetained.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface AlreadyRetained { -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/Foundation.java b/rococoa/rococoa-core/src/main/java/org/rococoa/Foundation.java deleted file mode 100644 index 5d373854..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/Foundation.java +++ /dev/null @@ -1,284 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa; - -import com.sun.jna.Library; -import com.sun.jna.Native; -import org.rococoa.cocoa.CFIndex; -import org.rococoa.internal.*; - -import java.lang.reflect.Method; -import java.nio.charset.StandardCharsets; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.Callable; -import java.util.logging.Level; -import java.util.logging.Logger; - - -/** - * The core of Rococoa - statics to handle selectors and messaging at a function call level. - *

- * Marshalling of Java types to C types is handled by JNA. Marshalling of Java - * type to Objective-C types is handled by RococoaTypeMapper. - *

- * Not to be confused with the Mac Foundation or Core Foundation frameworks, most - * users shouldn't need to access this class directly. - * - * @author duncan - */ -public abstract class Foundation { - - private static final Logger logging = Logger.getLogger("org.rococoa.foundation"); - - private static final FoundationLibrary foundationLibrary; - private static final MsgSendLibrary messageSendLibrary; - private static final RococoaLibrary rococoaLibrary; - - private static final Map selectorCache = new HashMap<>(); - - static { - logging.finest("Initializing Foundation"); - - // Set JNA to convert java.lang.String to char* using UTF-8, and match that with - // the way we tell CF to interpret our char* - // May be removed if we use toStringViaUTF16 - System.setProperty("jna.encoding", "UTF8"); - - Map messageSendLibraryOptions = new HashMap<>(1); - messageSendLibraryOptions.put(Library.OPTION_INVOCATION_MAPPER, new MsgSendInvocationMapper()); - messageSendLibrary = Native.load("Foundation", MsgSendLibrary.class, messageSendLibraryOptions); - - foundationLibrary = Native.load("Foundation", FoundationLibrary.class); - rococoaLibrary = Native.load("rococoa", RococoaLibrary.class); - logging.finest("exit initializing Foundation"); - } - - private Foundation() { - // - } - - public static void nsLog(String format, Object thing) { - ID formatAsCFString = cfString(format); - try { - foundationLibrary.NSLog(formatAsCFString, thing); - } finally { - cfRelease(formatAsCFString); - } - } - - /** - * Return a CFString as an ID, toll-free bridged to NSString. - *

- * Note that the returned string must be freed with {@link #cfRelease(ID)}. - */ - public static ID cfString(String s) { - // Use a byte[] rather than letting jna do the String -> char* marshalling itself. - // Turns out about 10% quicker for long strings. - byte[] utf16Bytes = s.getBytes(StandardCharsets.UTF_16LE); - return foundationLibrary.CFStringCreateWithBytes(null, utf16Bytes, - utf16Bytes.length, - StringEncoding.kCFStringEncodingUTF16LE.value, (byte) 0); - } - - /** - * Retain the NSObject with id - */ - public static ID cfRetain(ID id) { - if (logging.isLoggable(Level.FINEST)) { - logging.finest(String.format("calling cfRetain(%s)", id)); - } - return foundationLibrary.CFRetain(id); - } - - /** - * Release the NSObject with id - */ - public static void cfRelease(ID id) { - if (logging.isLoggable(Level.FINEST)) { - logging.finest(String.format("calling cfRelease(%s)", id)); - } - foundationLibrary.CFRelease(id); - } - - public static CFIndex cfGetRetainCount(ID cfTypeRef) { - return foundationLibrary.CFGetRetainCount(cfTypeRef); - } - - public static String toString(ID cfString) { - return toStringViaUTF8(cfString); - } - - /* Experimental */ - static String toStringViaUTF16(ID cfString) { - int lengthInChars = foundationLibrary.CFStringGetLength(cfString); - int potentialLengthInBytes = 3 * lengthInChars + 1; // UTF16 fully escaped 16 bit chars, plus nul - - byte[] buffer = new byte[potentialLengthInBytes]; - byte ok = foundationLibrary.CFStringGetCString(cfString, buffer, buffer.length, StringEncoding.kCFStringEncodingUTF16LE.value); - if (ok == 0) { - throw new RococoaException("Could not convert string"); - } - return new String(buffer, StandardCharsets.UTF_16LE).substring(0, lengthInChars); - } - - static String toStringViaUTF8(ID cfString) { - int lengthInChars = foundationLibrary.CFStringGetLength(cfString); - int potentialLengthInBytes = 3 * lengthInChars + 1; // UTF8 fully escaped 16 bit chars, plus nul - - byte[] buffer = new byte[potentialLengthInBytes]; - byte ok = foundationLibrary.CFStringGetCString(cfString, buffer, buffer.length, StringEncoding.kCFStringEncodingUTF8.value); - if (ok == 0) { - throw new RococoaException("Could not convert string"); - } - return Native.toString(buffer); - } - - /** - * Get the ID of the NSClass with className - */ - public static ID getClass(String className) { - if (logging.isLoggable(Level.FINEST)) { - logging.finest(String.format("calling objc_getClass(%s)", className)); - } - ID classID = foundationLibrary.objc_getClass(className); - if (classID.isNull()) { - throw new RococoaException(new ClassNotFoundException(className)); - } - return classID; - } - - public static Selector selector(String selectorName) { - Selector cached = selectorCache.get(selectorName); - if (cached != null) { - return cached; - } - Selector result = foundationLibrary.sel_registerName(selectorName).initName(selectorName); - selectorCache.put(selectorName, result); - return result; - } - - @SuppressWarnings("unchecked") - public static T send(ID receiver, String selectorName, Class returnType, Object... args) { - return send(receiver, selectorName, returnType, null, args); - } - - @SuppressWarnings("unchecked") - public static T send(ID receiver, String selectorName, Class returnType, Method method, Object... args) { - return send(receiver, selector(selectorName), returnType, method, args); - } - - @SuppressWarnings("unchecked") - public static T send(ID receiver, Selector selector, Class returnType, Object... args) { - return send(receiver, selector, returnType, null, args); - } - - /** - * Send message with selector to receiver, passing args, expecting returnType. - *

- * Note that you are responsible for memory management if returnType is ID. - * - * @param returnType Expected return type mapping - * @param method Used to determine if variadic function call is required - * @param args Arguments including ID and selector - */ - @SuppressWarnings("unchecked") - public static T send(ID receiver, Selector selector, Class returnType, Method method, Object... args) { - if (logging.isLoggable(Level.FINEST)) { - logging.finest(String.format("sending (%s) %s.%s(%s)", - returnType.getSimpleName(), receiver, selector.getName(), new VarArgsUnpacker(args))); - } - if (method != null && method.isVarArgs()) { - return (T) messageSendLibrary.syntheticSendVarArgsMessage(returnType, receiver, selector, args); - } - return (T) messageSendLibrary.syntheticSendMessage(returnType, receiver, selector, args); - } - - /** - * Convenience as this happens a lot in tests. - *

- * Note that you are responsible for memory management for the returned ID - */ - public static ID sendReturnsID(ID receiver, String selectorName, Object... args) { - return send(receiver, selector(selectorName), ID.class, args); - } - - /** - * Convenience as this happens a lot in tests. - */ - public static void sendReturnsVoid(ID receiver, String selectorName, Object... args) { - send(receiver, selector(selectorName), void.class, args); - } - - public static boolean isMainThread() { - return MainThreadUtils.isMainThread(); - } - - /** - * Return the result of calling callable on the main Cococoa thread. - */ - public static T callOnMainThread(final Callable callable) { - return MainThreadUtils.callOnMainThread(rococoaLibrary, callable); - } - - /** - * Run runnable on the main Cococoa thread, waiting for completion. - */ - public static void runOnMainThread(final Runnable runnable) { - MainThreadUtils.runOnMainThread(rococoaLibrary, runnable, true); - } - - /** - * Run runnable on the main Cococoa thread, optionally waiting for completion. - */ - public static void runOnMainThread(Runnable runnable, boolean waitUntilDone) { - MainThreadUtils.runOnMainThread(rococoaLibrary, runnable, waitUntilDone); - } - - /** - * Create an Objective-C object which delegates to callbacks when methods - * are invoked on it. - *

- * Object is created with alloc, so is owned by the caller. - */ - public static ID newOCProxy(OCInvocationCallbacks callbacks) { - return rococoaLibrary.proxyForJavaObject( - callbacks.selectorInvokedCallback, - callbacks.methodSignatureCallback); - } - - public static boolean selectorNameMeansWeOwnReturnedObject(String selectorName) { - // From Memory Management Programming Guide for Cocoa - // This is the fundamental rule: - // You take ownership of an object if you create it using a method whose - // name begins with 'alloc' or 'new' or contains 'copy' (for example, - // alloc, newObject, or mutableCopy), or if you send it a retain - // message. You are responsible for relinquishing ownership of objects - // you own using release or autorelease. Any other time you receive an - // object, you must not release it. - - // Note that this does not appear to be an infallible rule - see - // https://rococoa.dev.java.net/servlets/ReadMsg?list=dev&msgNo=71 - return selectorName.startsWith("alloc") || - selectorName.startsWith("new") || - selectorName.toLowerCase().contains("copy"); - } - -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/ID.java b/rococoa/rococoa-core/src/main/java/org/rococoa/ID.java deleted file mode 100644 index 611bcd03..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/ID.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa; - -import com.sun.jna.Native; -import com.sun.jna.NativeLibrary; -import com.sun.jna.NativeLong; - - -/** - * Represents an Objective-C ID. - * - * This extends NativeLong for efficiency, but you should really think of it - * as opaque. - * - * Technically, this should be {@link Native#POINTER_SIZE} not {@link Native#LONG_SIZE}, - * but as they are both 32 on 32-bit and 64 on 64-bit we'll gloss over that. Ideally - * it would be Pointer, but they have no protected constructors. - * - */ -public class ID extends NativeLong { - - public static ID fromLong(long value) { - return new ID(value); - } - - // Public for JNA - public ID() { - super(); - }; - - protected ID(long value) { - super(value); - } - - protected ID(ID anotherID) { - this(anotherID.longValue()); - } - - @Override - public String toString() { - return String.format("[ID 0x%x]", longValue()); //$NON-NLS-1$ - } - - public boolean isNull() { - return longValue() == 0; - } - - public static ID getGlobal(String libraryName, String globalVarName) { - return new ID(NativeLibrary.getInstance(libraryName).getGlobalVariableAddress(globalVarName).getNativeLong(0).longValue()); - } -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/IDByReference.java b/rococoa/rococoa-core/src/main/java/org/rococoa/IDByReference.java deleted file mode 100644 index 01ce82a0..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/IDByReference.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa; - -import com.sun.jna.NativeLong; -import com.sun.jna.ptr.ByReference; - -/** - * Used when we need to pass an ID to be filled in by called code. - * - */ -public class IDByReference extends ByReference { - - public IDByReference() { - this(ID.fromLong(0)); - } - - public IDByReference(ID value) { - super(NativeLong.SIZE); - setValue(value); - } - - public void setValue(ID value) { - getPointer().setNativeLong(0, value); - } - - public ID getValue() { - return ID.fromLong(getPointer().getNativeLong(0).longValue()); - } -} - diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/ObjCClass.java b/rococoa/rococoa-core/src/main/java/org/rococoa/ObjCClass.java deleted file mode 100644 index 137bcb04..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/ObjCClass.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa; - - - -/** - * Marker interface that an OCObject represents a Class. - * - * Note that in Objective-C Class is a struct, so there are no methods to call. - * - * @author duncan - * - */ -public interface ObjCClass extends ObjCObject { - - public static final _Class CLASS = new _Class(); - - public static class _Class { - public ObjCClass classWithName(String className) { - return Rococoa.createClass(className, ObjCClass.class); - } - } - -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/ObjCObject.java b/rococoa/rococoa-core/src/main/java/org/rococoa/ObjCObject.java deleted file mode 100644 index 6c61bf8a..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/ObjCObject.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa; - -public interface ObjCObject { - - ID id(); - -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/ObjCObjectByReference.java b/rococoa/rococoa-core/src/main/java/org/rococoa/ObjCObjectByReference.java deleted file mode 100644 index dd50cc78..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/ObjCObjectByReference.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa; - -import com.sun.jna.NativeLong; -import com.sun.jna.ptr.ByReference; - -/** - * Used to retrieve an NSObject as an out param. - * - * @author duncan - * - */ -public class ObjCObjectByReference extends ByReference { - - private ObjCObject object; - - public ObjCObjectByReference() { - super(NativeLong.SIZE); - } - - public T getValueAs(Class javaClass) { - return Rococoa.cast(object, javaClass); - } - - public void setObject(ObjCObject object) { - this.object = object; - } -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/ReleaseInFinalize.java b/rococoa/rococoa-core/src/main/java/org/rococoa/ReleaseInFinalize.java deleted file mode 100644 index 8fc06e10..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/ReleaseInFinalize.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Marker to allow us to disable CFRelease'ing an id when its Java proxy is finalized. - *

- * Only NSAutoreleasePool applies at the time of writing. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface ReleaseInFinalize { - boolean value(); -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/ReturnType.java b/rococoa/rococoa-core/src/main/java/org/rococoa/ReturnType.java deleted file mode 100644 index c168df7b..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/ReturnType.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotation to specify or disambiguate the return type of a method. - * - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface ReturnType { - - Class value(); - -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/Rococoa.java b/rococoa/rococoa-core/src/main/java/org/rococoa/Rococoa.java deleted file mode 100644 index e7281b96..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/Rococoa.java +++ /dev/null @@ -1,250 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa; - -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; - -import net.bytebuddy.ByteBuddy; -import net.bytebuddy.TypeCache; -import net.bytebuddy.description.modifier.Visibility; -import net.bytebuddy.dynamic.scaffold.subclass.ConstructorStrategy; -import net.bytebuddy.implementation.InvocationHandlerAdapter; -import org.rococoa.cocoa.CFIndex; -import org.rococoa.internal.*; - -import java.util.logging.Level; -import java.util.logging.Logger; - -import static net.bytebuddy.implementation.FieldAccessor.*; -import static net.bytebuddy.implementation.MethodCall.*; -import static net.bytebuddy.matcher.ElementMatchers.*; - -/** - * Static factory for creating Java wrappers for Objective-C instances, and Objective-C - * wrappers for Java instances. START HERE. - * - * @author duncan - * - */ -public abstract class Rococoa { - - private static final Logger logging = Logger.getLogger("org.rococoa.proxy"); - - /** - * Create a Java NSClass representing the Objective-C class with ocClassName - */ - public static T createClass(String ocClassName, Class type) { - return wrap(Foundation.getClass(ocClassName), type, false); - } - - /** - * Create a Java NSObject representing an instance of the Objective-C class - * ocClassName. The Objective-C instance is created by calling the static - * factory method named ocMethodName, passing args. - */ - public static T create(String ocClassName, Class javaClass, String ocMethodName, Object... args) { - return create(ocClassName, javaClass, null, ocMethodName, args); - } - - public static T create(String ocClassName, Class javaClass, Method method, String ocMethodName, Object... args) { - boolean weOwnObject = Foundation.selectorNameMeansWeOwnReturnedObject(ocMethodName); - - // If we don't own the object we know that it has been autorelease'd - // But we need to own these objects, so that they are not dealloc'd when - // the pool is release'd. So we retain them. - // Objects that we own (because they were created with 'alloc' or 'new') - // have not been autorelease'd, so we don't retain them. - boolean retain = !weOwnObject; - return create(ocClassName, javaClass, method, ocMethodName, retain, args); - } - - /** - * Create a Java NSObject representing an instance of the Objective-C class - * ocClassName, created with the class method +new. - */ - public static T create(String ocClassName, Class javaClass) { - return create(ocClassName, javaClass, "new"); - } - - private static T create(String ocClassName, Class javaClass, Method method, - String ocFactoryName, - boolean retain, - Object... args) { - if (logging.isLoggable(Level.FINEST)) { - logging.finest(String.format("creating [%s (%s)].%s(%s)", - ocClassName, javaClass.getName(), ocFactoryName, new VarArgsUnpacker(args))); - } - ID ocClass = Foundation.getClass(ocClassName); - ID ocInstance = Foundation.send(ocClass, ocFactoryName, ID.class, method, args); - CFIndex initialRetainCount = Foundation.cfGetRetainCount(ocInstance); - T result = wrap(ocInstance, javaClass, retain); - checkRetainCount(ocInstance, retain ? initialRetainCount.intValue() + 1 : initialRetainCount.intValue()); - return result; - } - - /** - * Create a Java NSObject wrapping an existing Objective-C instance, represented - * by id. - * - * The NSObject is retained, and released when the object is GC'd. - */ - public static T wrap(ID id, Class javaClass) { - return wrap(id, javaClass, true); - } - - /** - * Create a Java NSObject down-casting an existing NSObject to a more derived - * type. - */ - public static T cast(ObjCObject object, Class desiredType) { - if (object == null) { - return null; - } - return wrap(object.id(), desiredType, true); - } - - public static T wrap(ID id, Class javaClass, boolean retain) { - if (id == null || id.isNull()) { - return null; - } - // Why would we not want to retain? Well if we are wrapping a Core Foundation - // created object, or one created with new (alloc init), it will not - // have been autorelease'd. - ObjCObjectInvocationHandler invocationHandler = new ObjCObjectInvocationHandler(id, javaClass, retain); - return createProxy(javaClass, invocationHandler); - } - - /** - * Return the ID of a new Objective-C object that will forward messages to - * javaObject. - * - * Keep hold of the ID all the time that methods may be invoked on the Obj-C - * object, otherwise the callbacks may be GC'd, with amusing consequences. - * - * @deprecated because the OC proxy object is never released. - * Use {@link Rococoa#proxy} instead. - */ - @Deprecated - public static ID wrap(Object javaObject) { - OCInvocationCallbacks callbacks = new OCInvocationCallbacks(javaObject); - ID idOfOCProxy = Foundation.newOCProxy(callbacks); - // idOfOCProxy is owned by us, and we have to release it at some stage - return new ProxyID(idOfOCProxy, callbacks); - } - - /** - * Return a new Objective-C object that will forward messages to javaObject, - * for use in delegates, notifications etc. - * - * You need to keep a reference to the returned value for as long as it is - * active. When it is GC'd, it will release the Objective-C proxy. - */ - public static ObjCObject proxy(Object javaObject) { - return proxy(javaObject, ObjCObject.class); - } - - public static T proxy(Object javaObject, Class javaType) { - ID proxyID = wrap(javaObject); - // we own the proxyID, so by wrapping it as NSObject, we can arrange for - // it to be release'd when the NSObject is finalized - return wrap(proxyID, javaType, false); - } - - private static final TypeCache> typeCache = new TypeCache<>(); - private static final String i15r = "invocationHandler"; - - /** - * Create a java.lang.reflect.Proxy or cglib proxy of type, which forwards - * invocations to invocationHandler. - */ - @SuppressWarnings("unchecked") - private static T createProxy(final Class type, ObjCObjectInvocationHandler invocationHandler) { - if (type.isInterface()) { - return (T) Proxy.newProxyInstance( - invocationHandler.getClass().getClassLoader(), - new Class[] {type}, invocationHandler); - } else { - ClassLoader classLoader = type.getClassLoader(); - - Class proxyClass = - typeCache.findOrInsert(classLoader, type, () -> - new ByteBuddy() - .subclass(type, ConstructorStrategy.Default.NO_CONSTRUCTORS) - .name(type.getName() + "$$ByRococoa") - .defineField(i15r, ObjCObjectInvocationHandler.class) - .defineConstructor(Visibility.PUBLIC) - .withParameter(ObjCObjectInvocationHandler.class, i15r) - .intercept( - // Invoke superclass default constructor explicitly - invoke(type.getConstructor()) - .andThen(ofField(i15r).setsArgumentAt(0)) - ) - .method( - isAbstract() - .or(is(ObjCObjectInvocationHandler.OBJECT_EQUALS)) - .or(is(ObjCObjectInvocationHandler.OBJECT_TOSTRING)) - .or(is(ObjCObjectInvocationHandler.OCOBJECT_ID)) - ) - .intercept(InvocationHandlerAdapter.toField(i15r)) - .make() - .load(classLoader) - .getLoaded() - ); - - try { - return ((Class) proxyClass) - .getConstructor(ObjCObjectInvocationHandler.class) - .newInstance(invocationHandler); - } catch (ReflectiveOperationException e) { - throw new RococoaException(e); - } - } - } - - // Public only because JNA doesn't call setAccessible to access ctor. - public static class ProxyID extends ID { - // used to prevent callbacks being GC'd as long as we hang onto this ID - @SuppressWarnings("unused") - private OCInvocationCallbacks callbacks; - - public ProxyID() { - // required by jna - } - - public ProxyID(ID anotherID, OCInvocationCallbacks callbacks) { - super(anotherID); - this.callbacks = callbacks; - } - } - - private static void checkRetainCount(ID ocInstance, int expected) { - CFIndex retainCount = Foundation.cfGetRetainCount(ocInstance); - if (retainCount.intValue() != expected) { - logging.warning("Created an object which had a retain count of " + retainCount + " not " + expected); - } - } - - /** - * Enforce static factory-ness. - */ - private Rococoa() { - } -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/RococoaException.java b/rococoa/rococoa-core/src/main/java/org/rococoa/RococoaException.java deleted file mode 100644 index 6e817d6c..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/RococoaException.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa; - -@SuppressWarnings("serial") -public class RococoaException extends RuntimeException { - - public RococoaException() { - } - - public RococoaException(String message) { - super(message); - } - - public RococoaException(Throwable cause) { - super(cause); - } - - public RococoaException(String message, Throwable cause) { - super(message, cause); - } - -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/RunOnMainThread.java b/rococoa/rococoa-core/src/main/java/org/rococoa/RunOnMainThread.java deleted file mode 100644 index 89c2fa1e..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/RunOnMainThread.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Marker that the methods of an NSObject should be invoked on the main Cocoa thread. - * - * @author duncan - * - */ -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE, ElementType.METHOD}) -public @interface RunOnMainThread { - -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/Selector.java b/rococoa/rococoa-core/src/main/java/org/rococoa/Selector.java deleted file mode 100644 index 22e42658..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/Selector.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa; - -import com.sun.jna.NativeLong; - -public class Selector extends NativeLong { - - private String name; - - public Selector() { - this("undefined selector", 0); - }; - - public Selector(String name, long value) { - super(value); - this.name = name; - } - - // used for setting name once we have got one from OC - Selector initName(String name) { - this.name = name; - return this; - } - - public String getName() { - return name; - } - - @Override - public String toString() { - return String.format("[Selector %s]", name); - } - -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/StringEncoding.java b/rococoa/rococoa-core/src/main/java/org/rococoa/StringEncoding.java deleted file mode 100644 index c8c19e14..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/StringEncoding.java +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa; - -public enum StringEncoding { - - // This set is CFStringBuiltInEncodings - kCFStringEncodingMacRoman(0), - kCFStringEncodingWindowsLatin1(0x0500), /* ANSI codepage 1252 */ - kCFStringEncodingISOLatin1(0x0201), /* ISO 8859-1 */ - kCFStringEncodingNextStepLatin(0x0B01), /* NextStep encoding*/ - kCFStringEncodingASCII(0x0600), /* 0..127 (in creating CFString, values greater than 0x7F are treated as corresponding Unicode value) */ - kCFStringEncodingUnicode(0x0100), /* kTextEncodingUnicodeDefault + kTextEncodingDefaultFormat (aka kUnicode16BitFormat) */ - kCFStringEncodingUTF8(0x08000100), /* kTextEncodingUnicodeDefault + kUnicodeUTF8Format */ - kCFStringEncodingNonLossyASCII(0x0BFF), /* 7bit Unicode variants used by Cocoa & Java */ - kCFStringEncodingUTF16(0x0100), /* kTextEncodingUnicodeDefault + kUnicodeUTF16Format (alias of kCFStringEncodingUnicode) */ - kCFStringEncodingUTF16BE(0x10000100), /* kTextEncodingUnicodeDefault + kUnicodeUTF16BEFormat */ - kCFStringEncodingUTF16LE(0x14000100), /* kTextEncodingUnicodeDefault + kUnicodeUTF16LEFormat */ - kCFStringEncodingUTF32(0x0c000100), /* kTextEncodingUnicodeDefault + kUnicodeUTF32Format */ - kCFStringEncodingUTF32BE(0x18000100), /* kTextEncodingUnicodeDefault + kUnicodeUTF32BEFormat */ - kCFStringEncodingUTF32LE(0x1c000100), /* kTextEncodingUnicodeDefault + kUnicodeUTF32LEFormat */ - - // Others are from CFStringEncodingExt.h - kCFStringEncodingMacJapanese(1), - kCFStringEncodingMacChineseTrad(2), - kCFStringEncodingMacKorean(3), - kCFStringEncodingMacArabic(4), - kCFStringEncodingMacHebrew(5), - kCFStringEncodingMacGreek(6), - kCFStringEncodingMacCyrillic(7), - kCFStringEncodingMacDevanagari(9), - kCFStringEncodingMacGurmukhi(10), - kCFStringEncodingMacGujarati(11), - kCFStringEncodingMacOriya(12), - kCFStringEncodingMacBengali(13), - kCFStringEncodingMacTamil(14), - kCFStringEncodingMacTelugu(15), - kCFStringEncodingMacKannada(16), - kCFStringEncodingMacMalayalam(17), - kCFStringEncodingMacSinhalese(18), - kCFStringEncodingMacBurmese(19), - kCFStringEncodingMacKhmer(20), - kCFStringEncodingMacThai(21), - kCFStringEncodingMacLaotian(22), - kCFStringEncodingMacGeorgian(23), - kCFStringEncodingMacArmenian(24), - kCFStringEncodingMacChineseSimp(25), - kCFStringEncodingMacTibetan(26), - kCFStringEncodingMacMongolian(27), - kCFStringEncodingMacEthiopic(28), - kCFStringEncodingMacCentralEurRoman(29), - kCFStringEncodingMacVietnamese(30), - kCFStringEncodingMacExtArabic(31), - kCFStringEncodingMacSymbol(33), - kCFStringEncodingMacDingbats(34), - kCFStringEncodingMacTurkish(35), - kCFStringEncodingMacCroatian(36), - kCFStringEncodingMacIcelandic(37), - kCFStringEncodingMacRomanian(38), - kCFStringEncodingMacCeltic(39), - kCFStringEncodingMacGaelic(40), - kCFStringEncodingMacFarsi(0x8C), - kCFStringEncodingMacUkrainian(0x98), - kCFStringEncodingMacInuit(0xEC), - kCFStringEncodingMacVT100(0xFC), - kCFStringEncodingMacHFS(0xFF), - kCFStringEncodingISOLatin2(0x0202), - kCFStringEncodingISOLatin3(0x0203), - kCFStringEncodingISOLatin4(0x0204), - kCFStringEncodingISOLatinCyrillic(0x0205), - kCFStringEncodingISOLatinArabic(0x0206), - kCFStringEncodingISOLatinGreek(0x0207), - kCFStringEncodingISOLatinHebrew(0x0208), - kCFStringEncodingISOLatin5(0x0209), - kCFStringEncodingISOLatin6(0x020A), - kCFStringEncodingISOLatinThai(0x020B), - kCFStringEncodingISOLatin7(0x020D), - kCFStringEncodingISOLatin8(0x020E), - kCFStringEncodingISOLatin9(0x020F), - kCFStringEncodingISOLatin10(0x0210), - kCFStringEncodingDOSLatinUS(0x0400), - kCFStringEncodingDOSGreek(0x0405), - kCFStringEncodingDOSBalticRim(0x0406), - kCFStringEncodingDOSLatin1(0x0410), - kCFStringEncodingDOSGreek1(0x0411), - kCFStringEncodingDOSLatin2(0x0412), - kCFStringEncodingDOSCyrillic(0x0413), - kCFStringEncodingDOSTurkish(0x0414), - kCFStringEncodingDOSPortuguese(0x0415), - kCFStringEncodingDOSIcelandic(0x0416), - kCFStringEncodingDOSHebrew(0x0417), - kCFStringEncodingDOSCanadianFrench(0x0418), - kCFStringEncodingDOSArabic(0x0419), - kCFStringEncodingDOSNordic(0x041A), - kCFStringEncodingDOSRussian(0x041B), - kCFStringEncodingDOSGreek2(0x041C), - kCFStringEncodingDOSThai(0x041D), - kCFStringEncodingDOSJapanese(0x0420), - kCFStringEncodingDOSChineseSimplif(0x0421), - kCFStringEncodingDOSKorean(0x0422), - kCFStringEncodingDOSChineseTrad(0x0423), - kCFStringEncodingWindowsLatin2(0x0501), - kCFStringEncodingWindowsCyrillic(0x0502), - kCFStringEncodingWindowsGreek(0x0503), - kCFStringEncodingWindowsLatin5(0x0504), - kCFStringEncodingWindowsHebrew(0x0505), - kCFStringEncodingWindowsArabic(0x0506), - kCFStringEncodingWindowsBalticRim(0x0507), - kCFStringEncodingWindowsVietnamese(0x0508), - kCFStringEncodingWindowsKoreanJohab(0x0510), - kCFStringEncodingANSEL(0x0601), - kCFStringEncodingJIS_X0201_76(0x0620), - kCFStringEncodingJIS_X0208_83(0x0621), - kCFStringEncodingJIS_X0208_90(0x0622), - kCFStringEncodingJIS_X0212_90(0x0623), - kCFStringEncodingJIS_C6226_78(0x0624), - kCFStringEncodingShiftJIS_X0213_00(0x0628), - kCFStringEncodingShiftJIS_X0213_MenKuTen(0x0629), - kCFStringEncodingGB_2312_80(0x0630), - kCFStringEncodingGBK_95(0x0631), - kCFStringEncodingGB_18030_2000(0x0632), - kCFStringEncodingKSC_5601_87(0x0640), - kCFStringEncodingKSC_5601_92_Johab(0x0641), - kCFStringEncodingCNS_11643_92_P1(0x0651), - kCFStringEncodingCNS_11643_92_P2(0x0652), - kCFStringEncodingCNS_11643_92_P3(0x0653), - kCFStringEncodingISO_2022_JP(0x0820), - kCFStringEncodingISO_2022_JP_2(0x0821), - kCFStringEncodingISO_2022_JP_1(0x0822), - kCFStringEncodingISO_2022_JP_3(0x0823), - kCFStringEncodingISO_2022_CN(0x0830), - kCFStringEncodingISO_2022_CN_EXT(0x0831), - kCFStringEncodingISO_2022_KR(0x0840), - kCFStringEncodingEUC_JP(0x0920), - kCFStringEncodingEUC_CN(0x0930), - kCFStringEncodingEUC_TW(0x0931), - kCFStringEncodingEUC_KR(0x0940), - kCFStringEncodingShiftJIS(0x0A01), - kCFStringEncodingKOI8_R(0x0A02), - kCFStringEncodingBig5(0x0A03), - kCFStringEncodingMacRomanLatin1(0x0A04), - kCFStringEncodingHZ_GB_2312(0x0A05), - kCFStringEncodingBig5_HKSCS_1999(0x0A06), - kCFStringEncodingVISCII(0x0A07), - kCFStringEncodingKOI8_U(0x0A08), - kCFStringEncodingBig5_E(0x0A09), - kCFStringEncodingNextStepJapanese(0x0B02), - kCFStringEncodingEBCDIC_US(0x0C01), - kCFStringEncodingEBCDIC_CP037(0x0C0); - - public final int value; - - private StringEncoding(int value) { - this.value = value; - } - -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/CFIndex.java b/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/CFIndex.java deleted file mode 100644 index f8d16ac6..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/CFIndex.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa; - -import com.sun.jna.NativeLong; - -/** - * - * @author pixel - */ -public class CFIndex extends NativeLong { - private static final long serialVersionUID = 0; -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/CFRange.java b/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/CFRange.java deleted file mode 100644 index b2021102..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/CFRange.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa; - -import java.util.Arrays; -import java.util.List; - -import com.sun.jna.Structure; - -/** - * @author pixel - */ -public class CFRange extends Structure implements Structure.ByValue { - public CFIndex location; - public CFIndex length; - - public CFRange() { - } - - public CFRange(final CFIndex location, final CFIndex length) { - this.location = location; - this.length = length; - } - - public long getLength() { - return length.longValue(); - } - - public long getLocation() { - return location.longValue(); - } - - public long getEndLocation() { - return getLocation() + getLength(); - } - - @Override - protected List getFieldOrder() { - return Arrays.asList("location", "length"); - } -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/CGFloat.java b/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/CGFloat.java deleted file mode 100644 index cd2ba863..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/CGFloat.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa; - -import com.sun.jna.FromNativeContext; -import com.sun.jna.Native; -import com.sun.jna.NativeMapped; - -/** - * CGFloat - * - * @author Harald Kuhr - * @author duncan - */ -public class CGFloat extends Number implements NativeMapped { - // Inspired by JNA NativeLong and IntegerType - public static final int SIZE = Native.LONG_SIZE; - - private final double value; - - public CGFloat() { - value = 0; - } - - public CGFloat(double d) { - value = d; - } - - @Override - public int intValue() { - return (int) value; - } - - @Override - public long longValue() { - return (long) value; - } - - @Override - public float floatValue() { - return (float) value; - } - - @Override - public double doubleValue() { - return value; - } - - @Override - public int hashCode() { - // From Double.hashCode - long bits = Double.doubleToLongBits(value); - return (int)(bits ^ (bits >>> 32)); - } - - @Override - public boolean equals(Object other) { - // Modified Double.equals - return (other instanceof CGFloat) && (Double.doubleToLongBits(((CGFloat) other).value) == Double.doubleToLongBits(value)); - } - - @Override - public String toString() { - return String.valueOf(value); - } - - // Native mapping - public Object fromNative(Object o, FromNativeContext fromNativeContext) { - switch (SIZE) { - case 4: - return new CGFloat((Float) o); - case 8: - return new CGFloat((Double) o); - default: - throw new Error("Unknown Native.LONG_SIZE: " + SIZE); - } - } - - public Object toNative() { - switch (SIZE) { - case 4: - return floatValue(); - case 8: - return doubleValue(); - default: - throw new Error("Unknown Native.LONG_SIZE: " + SIZE); - } - } - - public Class nativeType() { - switch (SIZE) { - case 4: - return Float.class; - case 8: - return Double.class; - default: - throw new Error("Unknown Native.LONG_SIZE: " + SIZE); - } - } -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSArray.java b/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSArray.java deleted file mode 100755 index d58f80a4..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSArray.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.foundation; - -import org.rococoa.ObjCClass; -import org.rococoa.Rococoa; - -public abstract class NSArray extends NSObject { - - public static final _Class CLASS = Rococoa.createClass("NSArray", _Class.class); //$NON-NLS-1$ - public interface _Class extends ObjCClass { - NSArray arrayWithObject(NSObject anObject); - /** - * @param objects Contents and then a trailing null - */ - NSArray arrayWithObjects(NSObject...objects); - } - - public abstract int count(); - - public abstract NSObject lastObject(); - public abstract NSObject objectAtIndex(int zeroOffsetIndex); - -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSAutoreleasePool.java b/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSAutoreleasePool.java deleted file mode 100644 index 5d3f50f0..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSAutoreleasePool.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.foundation; - -import org.rococoa.ReleaseInFinalize; -import org.rococoa.Rococoa; - -public @ReleaseInFinalize(false) abstract class NSAutoreleasePool extends NSObject { - - public static NSAutoreleasePool new_() { - return Rococoa.create("NSAutoreleasePool", NSAutoreleasePool.class); - } - - public abstract void addObject(NSObject object); - - public abstract void drain(); - -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSData.java b/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSData.java deleted file mode 100644 index 1609909e..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSData.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.foundation; - -import org.rococoa.ObjCClass; -import org.rococoa.Rococoa; - -public abstract class NSData extends NSObject { - public static final _Class CLASS = Rococoa.createClass("NSData", _Class.class); //$NON-NLS-1$ - public interface _Class extends ObjCClass { - NSData dataWithBytes_length(byte[] bytes, int length); - } - - public abstract int length(); - public abstract void getBytes(byte[] bytes); - public abstract void getBytes_length(byte[] bytes, int length); - -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSDate.java b/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSDate.java deleted file mode 100644 index 59152e99..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSDate.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.foundation; - -import org.rococoa.ObjCClass; -import org.rococoa.Rococoa; - - -public abstract class NSDate extends NSObject { - public static final _Class CLASS = Rococoa.createClass("NSDate", _Class.class); //$NON-NLS-1$ - public interface _Class extends ObjCClass { - NSDate dateWithTimeIntervalSince1970(double d); - } - - public abstract double timeIntervalSince1970(); - - public abstract String description(); -} \ No newline at end of file diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSDictionary.java b/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSDictionary.java deleted file mode 100755 index acce2780..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSDictionary.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.foundation; - -import org.rococoa.ID; -import org.rococoa.ObjCClass; -import org.rococoa.Rococoa; - -public abstract class NSDictionary extends NSObject { - public static final _Class CLASS = Rococoa.createClass("NSDictionary", _Class.class); //$NON-NLS-1$ - - public interface _Class extends ObjCClass { - NSDictionary dictionaryWithObjects_forKeys(NSArray objects, NSArray keys); - NSDictionary dictionaryWithObjectsAndKeys(NSObject...objects); - } - - public static NSDictionary dictionaryWithObjects_forKeys(NSArray objects, NSArray keys) { - return CLASS.dictionaryWithObjects_forKeys(objects, keys); - } - - public static NSDictionary dictionaryWithObjectsAndKeys(NSObject...objects) { - return CLASS.dictionaryWithObjectsAndKeys(objects); - } - - public abstract ID objectForKey(ID key); - public abstract NSObject objectForKey(NSObject key); - public abstract NSObject objectForKey(String key); - public abstract int count(); -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSError.java b/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSError.java deleted file mode 100644 index 1f25c0a3..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSError.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.foundation; - -import org.rococoa.ObjCClass; -import org.rococoa.Rococoa; - -public abstract class NSError extends NSObject { - - public static final _Class CLASS = Rococoa.createClass("NSError", _Class.class); //$NON-NLS-1$ - - public interface _Class extends ObjCClass { - NSError alloc(); - NSError errorWithDomain_code_userInfo(String domain, NSInteger code, NSDictionary userInfo); - } - - public abstract NSError initWithDomain_code_userInfo(String domain, NSInteger code, NSDictionary userInfo); - - public abstract NSInteger code(); - - public abstract String domain(); - - public abstract String localizedDescription(); - public abstract String localizedRecoverySuggestion(); - public abstract NSArray localizedRecoveryOptions(); - public abstract String localizedFailureReason(); - - public abstract NSObject recoveryAttempter(); - - public abstract NSDictionary userInfo(); -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSImage.java b/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSImage.java deleted file mode 100644 index 17d3c3e6..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSImage.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.foundation; - - - -public abstract class NSImage extends NSObject { - - public abstract void setScalesWhenResized(boolean scaleWhenResizing); - - public abstract void setSize(NSSize size); - - public abstract NSData TIFFRepresentation(); - -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSIndexSet.java b/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSIndexSet.java deleted file mode 100644 index 6b405f47..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSIndexSet.java +++ /dev/null @@ -1,187 +0,0 @@ -package org.rococoa.cocoa.foundation; - -/** - * This file was autogenerated by JNAerator,
- * a tool written by Olivier Chafik that uses a few opensource projects..
- * For help, please visit NativeLibs4Java, Rococoa, or JNA. - */ -public abstract class NSIndexSet extends org.rococoa.cocoa.foundation.NSObject implements org.rococoa.ObjCObject { - /** - * Original signature : +(id)indexSet
- * native declaration : NSIndexSet.h:51 - */ - public static org.rococoa.cocoa.foundation.NSIndexSet indexSet() { - return getNSClass().indexSet(); - } - - /** - * Original signature : +(id)indexSetWithIndex:(NSUInteger)
- * native declaration : NSIndexSet.h:52 - */ - public static org.rococoa.cocoa.foundation.NSIndexSet indexSetWithIndex(org.rococoa.cocoa.foundation.NSUInteger value) { - return getNSClass().indexSetWithIndex(value); - } - - /** - * Original signature : -(id)init
- * native declaration : NSIndexSet.h:55 - */ - public abstract org.rococoa.cocoa.foundation.NSIndexSet init(); - - /** - * Factory method
- * - * @see #init() - */ - public static org.rococoa.cocoa.foundation.NSIndexSet create() { - return getNSClass().alloc().init(); - } - - /** - * Original signature : -(id)initWithIndex:(NSUInteger)
- * native declaration : NSIndexSet.h:56 - */ - public abstract org.rococoa.cocoa.foundation.NSIndexSet initWithIndex(org.rococoa.cocoa.foundation.NSUInteger value); - - /** - * Factory method
- * - * @see #initWithIndex(org.rococoa.cocoa.foundation.NSUInteger) - */ - public static org.rococoa.cocoa.foundation.NSIndexSet createWithIndex(org.rococoa.cocoa.foundation.NSUInteger value) { - return getNSClass().alloc().initWithIndex(value); - } - /** - * native declaration : NSIndexSet.h:57
- * Conversion Error : /**
- * * designated initializer
- * * Original signature : -(id)initWithIndexesInRange:()
- * * /
- * - (id)initWithIndexesInRange:(null)range; (Argument range cannot be converted) - */ - /** - * designated initializer
- * Original signature : -(id)initWithIndexSet:(NSIndexSet*)
- * native declaration : NSIndexSet.h:58 - */ - public abstract org.rococoa.cocoa.foundation.NSIndexSet initWithIndexSet(org.rococoa.cocoa.foundation.NSIndexSet indexSet); - - /** - * Factory method
- * - * @see #initWithIndexSet(org.rococoa.cocoa.foundation.NSIndexSet) - */ - public static org.rococoa.cocoa.foundation.NSIndexSet createWithIndexSet(org.rococoa.cocoa.foundation.NSIndexSet indexSet) { - return getNSClass().alloc().initWithIndexSet(indexSet); - } - - /** - * Original signature : -(BOOL)isEqualToIndexSet:(NSIndexSet*)
- * native declaration : NSIndexSet.h:60 - */ - public abstract boolean isEqualToIndexSet(org.rococoa.cocoa.foundation.NSIndexSet indexSet); - - /** - * Original signature : -(NSUInteger)count
- * native declaration : NSIndexSet.h:62 - */ - public abstract org.rococoa.cocoa.foundation.NSUInteger count(); - - /** - * The following six methods will return NSNotFound if there is no index in the set satisfying the query.
- * Original signature : -(NSUInteger)firstIndex
- * native declaration : NSIndexSet.h:66 - */ - public abstract org.rococoa.cocoa.foundation.NSUInteger firstIndex(); - - /** - * Original signature : -(NSUInteger)lastIndex
- * native declaration : NSIndexSet.h:67 - */ - public abstract org.rococoa.cocoa.foundation.NSUInteger lastIndex(); - - /** - * Original signature : -(NSUInteger)indexGreaterThanIndex:(NSUInteger)
- * native declaration : NSIndexSet.h:68 - */ - public abstract org.rococoa.cocoa.foundation.NSUInteger indexGreaterThanIndex(org.rococoa.cocoa.foundation.NSUInteger value); - - /** - * Original signature : -(NSUInteger)indexLessThanIndex:(NSUInteger)
- * native declaration : NSIndexSet.h:69 - */ - public abstract org.rococoa.cocoa.foundation.NSUInteger indexLessThanIndex(org.rococoa.cocoa.foundation.NSUInteger value); - - /** - * Original signature : -(NSUInteger)indexGreaterThanOrEqualToIndex:(NSUInteger)
- * native declaration : NSIndexSet.h:70 - */ - public abstract org.rococoa.cocoa.foundation.NSUInteger indexGreaterThanOrEqualToIndex(org.rococoa.cocoa.foundation.NSUInteger value); - - /** - * Original signature : -(NSUInteger)indexLessThanOrEqualToIndex:(NSUInteger)
- * native declaration : NSIndexSet.h:71 - */ - public abstract org.rococoa.cocoa.foundation.NSUInteger indexLessThanOrEqualToIndex(org.rococoa.cocoa.foundation.NSUInteger value); - /** - * native declaration : NSIndexSet.h:75
- * Conversion Error : /**
- * * Fills up to bufferSize indexes in the specified range into the buffer and returns the number of indexes actually placed in the buffer; also modifies the optional range passed in by pointer to be "positioned" after the last index filled into the buffer.Example: if the index set contains the indexes 0, 2, 4, ..., 98, 100, for a buffer of size 10 and the range (20, 80) the buffer would contain 20, 22, ..., 38 and the range would be modified to (40, 60).
- * * Original signature : -(NSUInteger)getIndexes:(NSUInteger*) maxCount:(NSUInteger) inIndexRange:()
- * * /
- * - (NSUInteger)getIndexes:(NSUInteger*)indexBuffer maxCount:(NSUInteger)bufferSize inIndexRange:(null)range; (Argument range cannot be converted) - */ - /** - * native declaration : NSIndexSet.h:78
- * Conversion Error : /// Original signature : -(NSUInteger)countOfIndexesInRange:()
- * - (NSUInteger)countOfIndexesInRange:(null)range; (Argument range cannot be converted) - */ - /** - * Original signature : -(BOOL)containsIndex:(NSUInteger)
- * native declaration : NSIndexSet.h:81 - */ - public abstract boolean containsIndex(org.rococoa.cocoa.foundation.NSUInteger value); - /** - * native declaration : NSIndexSet.h:82
- * Conversion Error : /// Original signature : -(BOOL)containsIndexesInRange:()
- * - (BOOL)containsIndexesInRange:(null)range; (Argument range cannot be converted) - */ - /** - * Original signature : -(BOOL)containsIndexes:(NSIndexSet*)
- * native declaration : NSIndexSet.h:83 - */ - public abstract boolean containsIndexes(org.rococoa.cocoa.foundation.NSIndexSet indexSet); - - public static abstract class _class_ extends org.rococoa.cocoa.foundation.NSObject._class_ { - /** - * Original signature : +(id)indexSet
- * native declaration : NSIndexSet.h:51 - */ - public abstract org.rococoa.cocoa.foundation.NSIndexSet indexSet(); - - /** - * Original signature : +(id)indexSetWithIndex:(NSUInteger)
- * native declaration : NSIndexSet.h:52 - */ - public abstract org.rococoa.cocoa.foundation.NSIndexSet indexSetWithIndex(org.rococoa.cocoa.foundation.NSUInteger value); - - /** - * native declaration : NSIndexSet.h:53
- * Conversion Error : /// Original signature : +(id)indexSetWithIndexesInRange:()
- * + (id)indexSetWithIndexesInRange:(null)range; (Argument range cannot be converted) - */ - /// native declaration : NSIndexSet.h - public abstract org.rococoa.cocoa.foundation.NSIndexSet alloc(); - - /// native declaration : NSIndexSet.h - public abstract org.rococoa.cocoa.foundation.NSIndexSet new_(); - } - - public static _class_ getNSClass() { - if (_NSCLASS_ == null) - _NSCLASS_ = org.rococoa.Rococoa.createClass("NSIndexSet", _class_.class); - return _NSCLASS_; - } - - private static _class_ _NSCLASS_; -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSInteger.java b/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSInteger.java deleted file mode 100644 index f93f0c90..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSInteger.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.foundation; - -import com.sun.jna.NativeLong; - -/** - * - * @author pixel - */ -public class NSInteger extends NativeLong { - private static final long serialVersionUID = 0; - - public NSInteger() { - } - public NSInteger(long value) { - super(value); - } - public NSInteger(NativeLong nativeLong) { - super(nativeLong.longValue()); - } -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSIntegerByReference.java b/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSIntegerByReference.java deleted file mode 100644 index 5aa5ede4..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSIntegerByReference.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.foundation; - -import com.sun.jna.ptr.NativeLongByReference; - -public class NSIntegerByReference extends NativeLongByReference { - - public NSIntegerByReference() { - this(new NSInteger(0L)); - } - - public NSIntegerByReference(NSInteger value) { - super(value); - } - - public void setValue(NSInteger value) { - getPointer().setNativeLong(0, value); - } - - public NSInteger getValue() { - return new NSInteger(getPointer().getNativeLong(0)); - } - -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSInvocation.java b/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSInvocation.java deleted file mode 100644 index c88928d9..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSInvocation.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.foundation; - - -import com.sun.jna.Memory; -import com.sun.jna.Pointer; - -public abstract class NSInvocation extends NSObject { - - public abstract NSMethodSignature methodSignature(); - public abstract void getArgument_atIndex(Pointer receiver, int index); - public abstract void setReturnValue(Memory buffer); -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSMethodSignature.java b/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSMethodSignature.java deleted file mode 100644 index 1ce2a1d9..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSMethodSignature.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.foundation; - -import org.rococoa.ReturnType; - -import com.sun.jna.Pointer; - -public abstract class NSMethodSignature extends NSObject { - - public abstract int numberOfArguments(); - - public abstract @ReturnType(Pointer.class) String getArgumentTypeAtIndex(int index); - public abstract @ReturnType(Pointer.class) String methodReturnType(); - -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSMutableArray.java b/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSMutableArray.java deleted file mode 100644 index 0425549a..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSMutableArray.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.foundation; - -import org.rococoa.ObjCClass; -import org.rococoa.Rococoa; - -public abstract class NSMutableArray extends NSObject { - - public static final _Class CLASS = Rococoa.createClass("NSMutableArray", _Class.class); //$NON-NLS-1$ - public interface _Class extends ObjCClass { - NSMutableArray arrayWithCapacity(int numItems); - } - - public abstract int count(); - public abstract void addObject(NSObject anObject); - public abstract void addObject(String string); - - public abstract NSObject objectAtIndex(int index); -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSMutableDictionary.java b/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSMutableDictionary.java deleted file mode 100755 index 4d29ec9c..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSMutableDictionary.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.foundation; - -import org.rococoa.ObjCClass; -import org.rococoa.Rococoa; - -/** - * @author Duncan McGregor - * @author Paul Loy (added addEntriesFromDictionary for Growl contrib) - * - */ -public abstract class NSMutableDictionary extends NSDictionary { - - public static final _Class CLASS = Rococoa.createClass("NSMutableDictionary", _Class.class); //$NON-NLS-1$ - - public interface _Class extends ObjCClass { - NSMutableDictionary dictionaryWithCapacity(int numItems); - NSMutableDictionary dictionaryWithObjects_forKeys(NSArray objects, NSArray keys); - NSMutableDictionary dictionaryWithObjectsAndKeys(NSObject...objects); - NSMutableDictionary dictionaryWithDictionary(NSDictionary dict); - } - - public static NSMutableDictionary dictionaryWithCapacity(int numItems) { - return CLASS.dictionaryWithCapacity(numItems); - } - - public static NSMutableDictionary dictionaryWithObjects_forKeys(NSArray objects, NSArray keys) { - return CLASS.dictionaryWithObjects_forKeys(objects, keys); - } - - public static NSMutableDictionary dictionaryWithObjectsAndKeys(NSObject...objects) { - return CLASS.dictionaryWithObjectsAndKeys(objects); - } - - public static NSMutableDictionary dictionaryWithDictionary(NSDictionary dictionary) { - return CLASS.dictionaryWithDictionary(dictionary); - } - - public abstract void setValue_forKey(NSObject object, NSObject key); - - public abstract void setValue_forKey(NSObject object, String key); - - public abstract void addEntriesFromDictionary(NSDictionary dictionary); - -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSMutableIndexSet.java b/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSMutableIndexSet.java deleted file mode 100644 index ea84d83a..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSMutableIndexSet.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.rococoa.cocoa.foundation; - -/** - * This file was autogenerated by JNAerator,
- * a tool written by Olivier Chafik that uses a few opensource projects..
- * For help, please visit NativeLibs4Java, Rococoa, or JNA. - */ -public abstract class NSMutableIndexSet extends org.rococoa.cocoa.foundation.NSIndexSet { - /** - * Original signature : -(void)addIndexes:(NSIndexSet*)
- * native declaration : NSIndexSet.h:109 - */ - public abstract void addIndexes(org.rococoa.cocoa.foundation.NSIndexSet indexSet); - - /** - * Original signature : -(void)removeIndexes:(NSIndexSet*)
- * native declaration : NSIndexSet.h:110 - */ - public abstract void removeIndexes(org.rococoa.cocoa.foundation.NSIndexSet indexSet); - - /** - * Original signature : -(void)removeAllIndexes
- * native declaration : NSIndexSet.h:111 - */ - public abstract void removeAllIndexes(); - - /** - * Original signature : -(void)addIndex:(NSUInteger)
- * native declaration : NSIndexSet.h:112 - */ - public abstract void addIndex(org.rococoa.cocoa.foundation.NSUInteger value); - - /** - * Original signature : -(void)removeIndex:(NSUInteger)
- * native declaration : NSIndexSet.h:113 - */ - public abstract void removeIndex(org.rococoa.cocoa.foundation.NSUInteger value); - /** - * native declaration : NSIndexSet.h:114
- * Conversion Error : /// Original signature : -(void)addIndexesInRange:()
- * - (void)addIndexesInRange:(null)range; (Argument range cannot be converted) - */ - /** - * native declaration : NSIndexSet.h:115
- * Conversion Error : /// Original signature : -(void)removeIndexesInRange:()
- * - (void)removeIndexesInRange:(null)range; (Argument range cannot be converted) - */ - /** - * For a positive delta, shifts the indexes in [index, INT_MAX] to the right, thereby inserting an "empty space" [index, delta], for a negative delta, shifts the indexes in [index, INT_MAX] to the left, thereby deleting the indexes in the range [index - delta, delta].
- * Original signature : -(void)shiftIndexesStartingAtIndex:(NSUInteger) by:(NSInteger)
- * native declaration : NSIndexSet.h:119 - */ - public abstract void shiftIndexesStartingAtIndex_by(org.rococoa.cocoa.foundation.NSUInteger index, org.rococoa.cocoa.foundation.NSInteger delta); - - /// native declaration : NSIndexSet.h - public static org.rococoa.cocoa.foundation.NSMutableIndexSet alloc() { - return getNSClass().alloc(); - } - - /// native declaration : NSIndexSet.h - public static org.rococoa.cocoa.foundation.NSMutableIndexSet new_() { - return getNSClass().new_(); - } - - public static abstract class _class_ extends org.rococoa.cocoa.foundation.NSIndexSet._class_ { - /// native declaration : NSIndexSet.h - public abstract org.rococoa.cocoa.foundation.NSMutableIndexSet alloc(); - - /// native declaration : NSIndexSet.h - public abstract org.rococoa.cocoa.foundation.NSMutableIndexSet new_(); - } - - public static _class_ getNSClass() { - if (_NSCLASS_ == null) - _NSCLASS_ = org.rococoa.Rococoa.createClass("NSMutableIndexSet", _class_.class); - return _NSCLASS_; - } - - private static _class_ _NSCLASS_; -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSNotification.java b/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSNotification.java deleted file mode 100644 index 85f60ec6..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSNotification.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.foundation; - -import org.rococoa.ObjCClass; -import org.rococoa.Rococoa; - - -public abstract class NSNotification extends NSObject { - public static final _Class CLASS = Rococoa.createClass("NSNotification", _Class.class); //$NON-NLS-1$ - public interface _Class extends ObjCClass { - NSNotification notificationWithName_object(String notificationName, NSObject object); - } - -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSNotificationCenter.java b/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSNotificationCenter.java deleted file mode 100644 index f33fd57a..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSNotificationCenter.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.foundation; - -import org.rococoa.ID; -import org.rococoa.ObjCClass; -import org.rococoa.Rococoa; -import org.rococoa.Selector; - - -public abstract class NSNotificationCenter extends NSObject { - public static final _Class CLASS = Rococoa.createClass("NSNotificationCenter", _Class.class); //$NON-NLS-1$ - public interface _Class extends ObjCClass { - NSNotificationCenter defaultCenter(); - } - - public abstract void addObserver_selector_name_object(ID notificationObserver, - Selector notificationSelector, - String notificationName, - NSObject notificationSender); - - public abstract void removeObserver(ID notificationObserver); - - public abstract void postNotification(NSNotification notification); - -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSNumber.java b/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSNumber.java deleted file mode 100644 index 8b7edf6a..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSNumber.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.foundation; - -import org.rococoa.ObjCClass; -import org.rococoa.Rococoa; - - -public abstract class NSNumber extends NSObject { - public static final _Class CLASS = Rococoa.createClass("NSNumber", _Class.class); //$NON-NLS-1$ - public interface _Class extends ObjCClass { - NSNumber numberWithBool(boolean value); - NSNumber numberWithInt(int value); - NSNumber numberWithDouble(double e); - NSNumber numberWithLong(long value); - NSNumber numberWithFloat(float value); - } - - public abstract short shortValue(); - public abstract int intValue(); - public abstract long longValue(); - public abstract float floatValue(); - public abstract double doubleValue(); - public abstract int compare(NSNumber another); -} \ No newline at end of file diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSObject.java b/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSObject.java deleted file mode 100644 index e563d4eb..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSObject.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.foundation; - -import org.rococoa.ID; -import org.rococoa.ObjCClass; -import org.rococoa.ObjCObject; -import org.rococoa.Rococoa; - -public abstract class NSObject implements ObjCObject { - public static _class_ CLASS = Rococoa.createClass("NSObject", _class_.class); - - public static abstract class _class_ implements ObjCClass { - public abstract NSObject alloc(); - } - - public abstract NSObject retain(); - public abstract void release(); - public abstract NSUInteger retainCount(); - - public abstract boolean isKindOfClass(ObjCClass nsClass); - public abstract boolean isKindOfClass(ID nsClass); - - public abstract String description(); - -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSPoint.java b/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSPoint.java deleted file mode 100644 index 9b86a49b..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSPoint.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.foundation; - -import org.rococoa.cocoa.CGFloat; - -import java.awt.geom.Point2D; -import java.util.Arrays; -import java.util.List; - -import com.sun.jna.Structure; - -/** - * @author Harald Kuhr - */ -public class NSPoint extends Structure implements Structure.ByValue { - public CGFloat x; - public CGFloat y; - - public NSPoint() { - this(0, 0); - } - - public NSPoint(double x, double y) { - this.x = new CGFloat(x); - this.y = new CGFloat(y); - } - - public NSPoint(Point2D point) { - this(point.getX(), point.getY()); - } - - public Point2D getPoint() { - return new Point2D.Double(x.doubleValue(), y.doubleValue()); - } - - protected List getFieldOrder() { - return Arrays.asList("x", "y"); - } -} \ No newline at end of file diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSRange.java b/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSRange.java deleted file mode 100644 index 11848a05..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSRange.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.foundation; - -import org.rococoa.cocoa.CFIndex; -import org.rococoa.cocoa.CFRange; - - -/** - * - * @author pixel - */ -public class NSRange extends CFRange { - public NSRange() {} - public NSRange(final CFIndex location, final CFIndex length) { - super(location, length); - } -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSRect.java b/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSRect.java deleted file mode 100644 index 510533fb..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSRect.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.foundation; - -import java.awt.geom.Dimension2D; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; -import java.util.Arrays; -import java.util.List; - -import com.sun.jna.Structure; - -/** - * @author Harald Kuhr - */ -public class NSRect extends Structure implements Structure.ByValue { - public NSPoint origin; - public NSSize size; - - public NSRect() { - this(new NSPoint(0, 0), new NSSize()); - } - - public NSRect(NSPoint origin, NSSize size) { - this.origin = origin; - this.size = size; - } - - public NSRect(Point2D origin, Dimension2D size) { - this.origin = new NSPoint(origin); - this.size = new NSSize(size); - } - - public NSRect(Rectangle2D rect) { - this.origin = new NSPoint(rect.getX(), rect.getY()); - this.size = new NSSize(rect.getWidth(), rect.getHeight()); - } - - public NSRect(double w, double h) { - this.origin = new NSPoint(0, 0); - this.size = new NSSize(w, h); - } - - public Rectangle2D getBounds() { - return new Rectangle2D.Double(origin.x.doubleValue(), origin.y.doubleValue(), size.width.doubleValue(), size.height.doubleValue()); - } - - @Override - protected List getFieldOrder() { - return Arrays.asList("origin", "size"); - } -} \ No newline at end of file diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSSize.java b/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSSize.java deleted file mode 100644 index 55b5937b..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSSize.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.foundation; - -import org.rococoa.cocoa.CGFloat; - -import java.awt.geom.Dimension2D; -import java.util.Arrays; -import java.util.List; - -import com.sun.jna.Structure; - -public class NSSize extends Structure implements Structure.ByValue { - public CGFloat width; - public CGFloat height; - - public NSSize() { - this(0, 0); - } - - public NSSize(double width, double height) { - this.width = new CGFloat(width); - this.height = new CGFloat(height); - } - - public NSSize(Dimension2D pSize) { - this(pSize.getWidth(), pSize.getHeight()); - } - - @Override - protected List getFieldOrder() { - return Arrays.asList("width", "height"); - } -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSString.java b/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSString.java deleted file mode 100644 index 1dac0134..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSString.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.foundation; - -import org.rococoa.Foundation; -import org.rococoa.ID; -import org.rococoa.ObjCClass; -import org.rococoa.Rococoa; - -public abstract class NSString extends NSObject { - - public static _Class CLASS = Rococoa.createClass("NSString", _Class.class); //$NON-NLS-1$ - - public interface _Class extends ObjCClass { - NSString stringWithString(String string); - NSString stringWithFormat(String string, NSObject...objects); - } - - public static NSString stringWithString(String string) { - return CLASS.stringWithString(string); - } - - public abstract boolean isEqualToString(String string); - - public abstract NSString substringFromIndex(int anIndex); - - public abstract NSString lowercaseString(); - - @Override - public String toString() { - return Foundation.toString(id()); - } - - // TODO - move to Rococoa - public static NSString getGlobalString(String libraryName, String globalVarName) { - return Rococoa.wrap(ID.getGlobal(libraryName, globalVarName), NSString.class); - } - - // TODO - move to Rococoa - public static NSString getGlobalString(String globalVarName) { - return getGlobalString("AppKit", globalVarName); - } -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSUInteger.java b/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSUInteger.java deleted file mode 100644 index b1771734..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSUInteger.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.foundation; - -import com.sun.jna.NativeLong; - -/** - * - * @author pixel - */ -public class NSUInteger extends NativeLong { - private static final long serialVersionUID = 0; - - public NSUInteger() { - - } - public NSUInteger(long value) { - super(value); - } - public NSUInteger(NativeLong nativeLong) { - super(nativeLong.longValue()); - } -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSUIntegerByReference.java b/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSUIntegerByReference.java deleted file mode 100644 index f41785d6..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSUIntegerByReference.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.foundation; - -import com.sun.jna.ptr.NativeLongByReference; - -public class NSUIntegerByReference extends NativeLongByReference { - - public NSUIntegerByReference() { - this(new NSUInteger(0L)); - } - - public NSUIntegerByReference(NSUInteger value) { - super(value); - } - - public void setValue(NSUInteger value) { - getPointer().setNativeLong(0, value); - } - - public NSUInteger getValue() { - return new NSUInteger(getPointer().getNativeLong(0)); - } - -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSURL.java b/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSURL.java deleted file mode 100644 index 9a31c71b..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSURL.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.foundation; - -import org.rococoa.ObjCClass; -import org.rococoa.Rococoa; - -public abstract class NSURL extends NSObject { - public static final _Class CLASS = Rococoa.createClass("NSURL", _Class.class); //$NON-NLS-1$ - public interface _Class extends ObjCClass { - NSURL URLWithString(String value); - NSURL fileURLWithPath(String path); - } - public abstract NSURL absoluteURL(); - public abstract String path(); -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSValue.java b/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSValue.java deleted file mode 100755 index 8960b36e..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSValue.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa.foundation; - -import org.rococoa.ObjCClass; -import org.rococoa.Rococoa; - -import com.sun.jna.Structure; - -public abstract class NSValue extends NSObject { - - public static final _Class CLASS = Rococoa.createClass("NSValue", _Class.class); //$NON-NLS-1$ - public interface _Class extends ObjCClass { - NSValue valueWithSize(NSSize size); - } - - public static NSValue valueWithSize(NSSize size) { - return CLASS.valueWithSize(size); - } - - public abstract NSSize sizeValue(); - public abstract void getValue(Structure p); - -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/AutoreleaseBatcher.java b/rococoa/rococoa-core/src/main/java/org/rococoa/internal/AutoreleaseBatcher.java deleted file mode 100644 index 1f65127f..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/AutoreleaseBatcher.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.internal; -import org.rococoa.cocoa.foundation.NSAutoreleasePool; - -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Used by NSObjectInvocationHandler to make sure that there is an NSAutoreleasePool - * available when NSObject's are finalized, but not pay the price of creating one - * per call. - * - * Take care, this is tested but unproven code (2009/08). - * - * @author duncan - * - */ -public class AutoreleaseBatcher extends OperationBatcher { - - private static final Logger logging = Logger.getLogger("org.rococoa"); - - private static final ThreadLocal threadLocal = new ThreadLocal(); - - private NSAutoreleasePool pool; - - public static AutoreleaseBatcher forThread(int batchSize) { - if (threadLocal.get() == null) { - threadLocal.set(new AutoreleaseBatcher(batchSize)); - } - return threadLocal.get(); - } - - public AutoreleaseBatcher(int batchSize) { - super(batchSize); - } - - @Override - protected void operation() { - if (logging.isLoggable(Level.FINE)) { - logging.fine("Draining autorelease pool"); - } - pool.drain(); - } - - @Override - protected void reset() { - pool = NSAutoreleasePool.new_(); - } - -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/BoolConverter.java b/rococoa/rococoa-core/src/main/java/org/rococoa/internal/BoolConverter.java deleted file mode 100644 index e8c73d4e..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/BoolConverter.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2007-2010 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.internal; - -import com.sun.jna.FromNativeContext; -import com.sun.jna.FromNativeConverter; -import com.sun.jna.ToNativeContext; -import com.sun.jna.ToNativeConverter; - -/** - * Converts {@code java.lang.Boolean} to native by mapping to {@code java.lang.Integer} as defined by: - * - * #define YES (BOOL) 1 - * #define NO (BOOL) 0 - * - * - * @author Harald Kuhr - * @author last modified by $Author: haraldk$ - * @version $Id: BoolConverter.java,v 1.0 Feb 19, 2010 8:44:39 PM haraldk Exp$ - */ -public class BoolConverter implements ToNativeConverter, FromNativeConverter { - - public Object toNative(final Object value, final ToNativeContext context) { - return ((Boolean) value) ? 1 : 0; - } - - public Object fromNative(final Object value, final FromNativeContext context) { - return ((Byte) value).intValue() == 1; - } - - public Class nativeType() { - return byte.class; - } -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/FoundationLibrary.java b/rococoa/rococoa-core/src/main/java/org/rococoa/internal/FoundationLibrary.java deleted file mode 100644 index f2bfcebb..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/FoundationLibrary.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.internal; - - -import org.rococoa.ID; -import org.rococoa.Selector; - -import com.sun.jna.Library; -import org.rococoa.cocoa.CFIndex; - -/** - * JNA Library for plain C calls, standard JNA marshalling applies to these - */ -public interface FoundationLibrary extends Library { - - void NSLog(ID pString, Object thing); - - ID CFStringCreateWithCString(ID allocator, String string, int encoding); - ID CFStringCreateWithBytes(ID allocator, byte[] bytes, int byteCount, int encoding, byte isExternalRepresentation); - String CFStringGetCStringPtr(ID string, int encoding); - byte CFStringGetCString(ID theString, byte[] buffer, int bufferSize, int encoding); - int CFStringGetLength(ID theString); - - ID CFRetain(ID cfTypeRef); - void CFRelease(ID cfTypeRef); - CFIndex CFGetRetainCount(ID cfTypeRef); - - ID objc_getClass(String className); - ID class_createInstance(ID pClass, int extraBytes); - Selector sel_registerName(String selectorName); -} \ No newline at end of file diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/MainThreadUtils.java b/rococoa/rococoa-core/src/main/java/org/rococoa/internal/MainThreadUtils.java deleted file mode 100644 index b3d57c3a..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/MainThreadUtils.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.internal; - -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.Callable; - -import org.rococoa.Foundation; -import org.rococoa.ID; -import org.rococoa.RococoaException; -import org.rococoa.Selector; - -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Exists just to tidy up Foundation. - * - * @author duncan - * - */ -public abstract class MainThreadUtils { - private static final Logger logging = Logger.getLogger("org.rococoa.foundation"); - - private static final ID idNSThreadClass = Foundation.getClass("NSThread"); - private static final Selector isMainThreadSelector = Foundation.selector("isMainThread"); - - private static final ThreadLocal isMainThreadThreadLocal = new ThreadLocal() { - @Override - protected Boolean initialValue() { - return nsThreadSaysIsMainThread(); - } - }; - - private MainThreadUtils() { - // - } - - // References to callbacks that must live longer than the method invocation because they are called asynchronously - private static final Set asynchronousCallbacks = new HashSet(); - - /** - * Return the result of calling callable on the main Cococoa thread. - */ - @SuppressWarnings("unchecked") - public static T callOnMainThread(RococoaLibrary rococoaLibrary, final Callable callable) { - final Object[] result = new Object[1]; - final Throwable[] thrown = new Throwable[1]; - RococoaLibrary.VoidCallback callback = new RococoaLibrary.VoidCallback() { - public void callback() { - try { - result[0] = callable.call(); - } catch (Throwable t) { - thrown[0] = t; - } - }}; - - rococoaLibrary.callOnMainThread(callback, true); - rethrow(thrown[0]); - return (T) result[0]; - } - - /** - * @param runnable Run runnable on the main Cocoa thread. - * @param waitUntilDone A Boolean that specifies whether the current thread blocks until after - * the specified selector is performed on the receiver on the main thread. - */ - public static void runOnMainThread(RococoaLibrary rococoaLibrary, final Runnable runnable, final boolean waitUntilDone) { - final Throwable[] thrown = new Throwable[1]; - RococoaLibrary.VoidCallback callback = new RococoaLibrary.VoidCallback() { - public void callback() { - try { - runnable.run(); - } catch (Throwable t) { - if (waitUntilDone) { - thrown[0] = t; - } - else { - logging.log(Level.SEVERE, "Lost exception on main thread", t); - } - } finally { - if (!waitUntilDone) { - asynchronousCallbacks.remove(this); - } - } - }}; - - if (!waitUntilDone) { - asynchronousCallbacks.add(callback); - } - rococoaLibrary.callOnMainThread(callback, waitUntilDone); - rethrow(thrown[0]); - } - - public static boolean isMainThread() { - return isMainThreadThreadLocal.get(); - } - - private static boolean nsThreadSaysIsMainThread() { - return Foundation.send(idNSThreadClass, isMainThreadSelector, boolean.class); - } - - private static void rethrow(Throwable t) { - if (t == null) { - return; - } - if (t instanceof Error) { - throw (Error) t; - } - if (t instanceof RuntimeException) { - throw (RuntimeException) t; - } - throw new RococoaException(t); - } -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/MethodFunctionPair.java b/rococoa/rococoa-core/src/main/java/org/rococoa/internal/MethodFunctionPair.java deleted file mode 100644 index a2d594fd..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/MethodFunctionPair.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.internal; - -import com.sun.jna.Function; - -import java.lang.reflect.Method; - -public class MethodFunctionPair { - - public final Method method; - public final Function function; - - public MethodFunctionPair(Method method, Function function) { - this.method = method; - this.function = function; - } -} \ No newline at end of file diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/MsgSendHandler.java b/rococoa/rococoa-core/src/main/java/org/rococoa/internal/MsgSendHandler.java deleted file mode 100644 index b92521a1..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/MsgSendHandler.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.internal; - -import com.sun.jna.Library; -import com.sun.jna.NativeLibrary; -import com.sun.jna.NativeLong; -import com.sun.jna.Structure; -import org.rococoa.ID; -import org.rococoa.RococoaException; -import org.rococoa.Selector; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -/** - * Very special case InvocationHandler that invokes the correct message dispatch - * function for different return types. - *

- * Either objc_msgSend or objc_msgSend_stret should be called, depending on the - * return type. The latter is usually for struct by value, but the former is - * used for small structs on Intel! Oh and the call has to be mangled in all - * cases as the result is returned on the stack, but is different sizes - * depending on its type. Luckily jna and libffi take care of the details - - * provided they know what the return type is. - *

- * This InvocationHandler is passed the return type as the first arg to the method call that it - * intercepts, it uses it to determine which function to call, and removes it before - * calling invoking. - * - * @author duncan - * @see "http://www.cocoabuilder.com/archive/message/cocoa/2006/6/25/166236" - * @see "http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/LowLevelABI/Mac_OS_X_ABI_Function_Calls.pdf" - * @see "http://www.sealiesoftware.com/blog/archive/2008/10/30/objc_explain_objc_msgSend_stret.html" - *

- * Note also that there is a objc_msgSend_fret that is used supposed to be for - * floating point return types, but that I haven't (yet) had to use. - * @see "http://www.sealiesoftware.com/blog/archive/2008/11/16/objc_explain_objc_msgSend_fpret.html" - */ -class MsgSendHandler implements InvocationHandler { - - /** - * @see com.sun.jna.Function#OPTION_INVOKING_METHOD - */ - private final String OPTION_INVOKING_METHOD = "invoking-method"; - - private final static int I386_STRET_CUTOFF = 9; - private final static int IA64_STRET_CUTOFF = 17; - - private final static int STRET_CUTOFF = NativeLong.SIZE == 8 ? IA64_STRET_CUTOFF : I386_STRET_CUTOFF; - - public final static boolean AARCH64 = System.getProperty("os.arch").trim().equalsIgnoreCase("aarch64"); - public final static boolean PPC = System.getProperty("os.arch").trim().equalsIgnoreCase("ppc"); - - private final static Method OBJC_MSGSEND; - private final static Method OBJC_MSGSEND_VAR_ARGS; - private final static Method OBJC_MSGSEND_STRET; - - static { - try { - OBJC_MSGSEND = MsgSendLibrary.class.getDeclaredMethod("objc_msgSend", - ID.class, Selector.class, Object[].class); - OBJC_MSGSEND_VAR_ARGS = MsgSendLibrary.class.getDeclaredMethod("objc_msgSend", - ID.class, Selector.class, Object.class, Object[].class); - OBJC_MSGSEND_STRET = MsgSendLibrary.class.getDeclaredMethod("objc_msgSend_stret", - ID.class, Selector.class, Object[].class); - } catch (NoSuchMethodException x) { - throw new RococoaException(x); - } - } - - private final MethodFunctionPair objc_msgSend_stret_Pair; - private final MethodFunctionPair objc_msgSend_varArgs_Pair; - private final MethodFunctionPair objc_msgSend_Pair; - - private final RococoaTypeMapper rococoaTypeMapper = new RococoaTypeMapper(); - - public MsgSendHandler(final NativeLibrary lib) { - this.objc_msgSend_Pair = new MethodFunctionPair(AARCH64 ? null : OBJC_MSGSEND, - lib.getFunction("objc_msgSend")); - this.objc_msgSend_varArgs_Pair = new MethodFunctionPair(OBJC_MSGSEND_VAR_ARGS, - lib.getFunction("objc_msgSend")); - this.objc_msgSend_stret_Pair = new MethodFunctionPair(OBJC_MSGSEND_STRET, - AARCH64 ? null : lib.getFunction("objc_msgSend_stret")); - } - - public Object invoke(final Object proxy, final Method method, final Object[] args) { - Class returnTypeForThisCall = (Class) args[0]; - MethodFunctionPair invocation = this.invocationFor(returnTypeForThisCall, MsgSendInvocationMapper.SYNTHETIC_SEND_VARARGS_MSG.equals(method)); - Map options = new HashMap<>(Collections.singletonMap(Library.OPTION_TYPE_MAPPER, rococoaTypeMapper)); - options.put(OPTION_INVOKING_METHOD, invocation.method); - return invocation.function.invoke(returnTypeForThisCall, Arrays.copyOfRange(args, 1, args.length), options); - } - - private MethodFunctionPair invocationFor(Class returnTypeForThisCall, boolean varArgs) { - if (AARCH64) { - if (varArgs) { - return objc_msgSend_varArgs_Pair; - } - return objc_msgSend_Pair; - } - boolean isStruct = Structure.class.isAssignableFrom(returnTypeForThisCall); - boolean isStructByValue = isStruct && Structure.ByValue.class.isAssignableFrom(returnTypeForThisCall); - if (!isStructByValue) { - return objc_msgSend_Pair; - } - try { - if (PPC) { - // on ppc32 structs never return in registers - return objc_msgSend_stret_Pair; - } - // on i386 structs with sizeof exactly equal to 1, 2, 4, or 8 return in registers - Structure prototype = (Structure) returnTypeForThisCall.getDeclaredConstructor().newInstance(); - return prototype.size() < STRET_CUTOFF ? objc_msgSend_Pair : objc_msgSend_stret_Pair; - } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { - throw new RococoaException(e); - } - } -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/MsgSendInvocationMapper.java b/rococoa/rococoa-core/src/main/java/org/rococoa/internal/MsgSendInvocationMapper.java deleted file mode 100644 index c330537f..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/MsgSendInvocationMapper.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.internal; - -import com.sun.jna.InvocationMapper; -import com.sun.jna.NativeLibrary; -import org.rococoa.ID; -import org.rococoa.RococoaException; -import org.rococoa.Selector; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; - -/** - * A JNA InvocationMapper that maps calls to syntheticSendMessage to a MsgSendHandler. - *

- * This allows us to dispatch all calls to syntheticSendMessage and have MsgSendHandler - * call objc_msgSend or objc_msgSend_stret as appropriate, casting the return - * type appropriately. - * - * @author duncan - */ -public class MsgSendInvocationMapper implements InvocationMapper { - - public final static Method SYNTHETIC_SEND_MSG; - public final static Method SYNTHETIC_SEND_VARARGS_MSG; - - static { - try { - SYNTHETIC_SEND_MSG = MsgSendLibrary.class.getDeclaredMethod("syntheticSendMessage", - Class.class, ID.class, Selector.class, Object[].class); - } catch (Exception e) { - throw new RococoaException("Error retrieving method"); - } - try { - SYNTHETIC_SEND_VARARGS_MSG = MsgSendLibrary.class.getDeclaredMethod("syntheticSendVarArgsMessage", - Class.class, ID.class, Selector.class, Object[].class); - } catch (Exception e) { - throw new RococoaException("Error retrieving method"); - } - } - - public InvocationHandler getInvocationHandler(NativeLibrary lib, Method m) { - if (m.equals(SYNTHETIC_SEND_MSG) || m.equals(SYNTHETIC_SEND_VARARGS_MSG)) { - // Have to late bind this, as it's the only time we get to see lib. - // Not too bad as the results are cached. - return new MsgSendHandler(lib); - } - return null; // default handler - } -} \ No newline at end of file diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/MsgSendLibrary.java b/rococoa/rococoa-core/src/main/java/org/rococoa/internal/MsgSendLibrary.java deleted file mode 100644 index 16ee497b..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/MsgSendLibrary.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.internal; - - -import org.rococoa.ID; -import org.rococoa.Selector; - -import com.sun.jna.Library; -import com.sun.jna.Structure; - -/** - * JNA Library for special message send calls, called and marshalled specially. - */ -public interface MsgSendLibrary extends Library { - // This doesn't exist in the library, but is synthesised by msgSendHandler - Object syntheticSendMessage(Class returnType, ID receiver, Selector selector, Object... args); - Object syntheticSendVarArgsMessage(Class returnType, ID receiver, Selector selector, Object... args); - - // We don't call these directly, but through syntheticSendMessage - Object objc_msgSend(ID receiver, Selector selector, Object... args); - Object objc_msgSend(ID receiver, Selector selector, Object arg, Object... args); - Structure objc_msgSend_stret(ID receiver, Selector selector, Object... args); -} \ No newline at end of file diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/NSInvocationMapper.java b/rococoa/rococoa-core/src/main/java/org/rococoa/internal/NSInvocationMapper.java deleted file mode 100644 index 72f06e49..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/NSInvocationMapper.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.internal; - - -import com.sun.jna.Native; -import org.rococoa.cocoa.foundation.NSInvocation; - -import com.sun.jna.Memory; - -/** - * Maps to and from bytes in an NSInvocation to Java types. - * - * @author duncan - * - */ -public abstract class NSInvocationMapper { - - protected final Class type; - protected final String typeString; - - protected NSInvocationMapper(String typeString, Class type) { - this.type = type; - this.typeString = typeString; - } - - public String typeString() { - return typeString; - } - - public Object readArgumentFrom(NSInvocation invocation, int index, Class type) { - Memory buffer = new Memory(Native.LONG_SIZE); // big enough for long or double - invocation.getArgument_atIndex(buffer, index); - return readFrom(buffer, type); - } - - protected Object readFrom(Memory buffer, Class type) { - throw new Error("Should be overridden or bypassed"); - } - - public abstract Memory bufferForResult(Object methodCallResult); - -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/NSInvocationMapperLookup.java b/rococoa/rococoa-core/src/main/java/org/rococoa/internal/NSInvocationMapperLookup.java deleted file mode 100644 index fa23a09e..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/NSInvocationMapperLookup.java +++ /dev/null @@ -1,364 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.internal; - -import com.sun.jna.Memory; -import com.sun.jna.Native; -import com.sun.jna.NativeLong; -import com.sun.jna.Structure; -import org.rococoa.Foundation; -import org.rococoa.ID; -import org.rococoa.ObjCObject; -import org.rococoa.Rococoa; -import org.rococoa.cocoa.CGFloat; -import org.rococoa.cocoa.foundation.NSInteger; -import org.rococoa.cocoa.foundation.NSUInteger; - -import java.util.HashMap; -import java.util.Map; - -/** - * Look up how to map from and from NSInvocation and Java objects. - * - * @author duncan - */ -public final class NSInvocationMapperLookup { - private static final int NATIVE_POINTER_SIZE = Native.POINTER_SIZE; - private static final int NATIVE_LONG_SIZE = Native.LONG_SIZE; - - private static final String NATIVE_LONG_ENCODING = NATIVE_LONG_SIZE == 4 ? "l" : "q"; - private static final String NSINTEGER_ENCODING = NATIVE_LONG_SIZE == 4 ? "i" : "q"; - private static final String NSUINTEGER_ENCODING = NATIVE_LONG_SIZE == 4 ? "I" : "Q"; - private static final String CGFLOAT_ENCODING = NATIVE_LONG_SIZE == 4 ? "f" : "d"; - - private static final Map, NSInvocationMapper> classToMapperLookup = new HashMap, NSInvocationMapper>(); - - private NSInvocationMapperLookup() { - // - } - - public static NSInvocationMapper mapperForType(Class type) { - // first check if we have a direct hit in the classToMapperLookup - NSInvocationMapper directMatch = classToMapperLookup.get(type); - if (directMatch != null) { - return directMatch; - } - // Now if it is any subclass of NSObject, then the generic mapper will do - if (OCOBJECT.type.isAssignableFrom(type)) { - return OCOBJECT; - } - // Now if it is any subclass of NSObject, then the generic mapper will do - if (NATIVE_LONG.type.isAssignableFrom(type)) { - return NATIVE_LONG; - } - // finally if it's a structure (that wasn't found in classToMapperLookup) - // create a mapper for the actual type and add it for next time - if (Structure.class.isAssignableFrom(type)) { - NSInvocationStructureMapper result = new NSInvocationStructureMapper(type); - addToLookup(result); - return result; - } - return null; - } - - public static String stringForType(Class type) { - return mapperForType(type).typeString(); - } - - static { - addToLookup(new NSInvocationMapper("v", void.class) { - @Override - public Object readFrom(Memory buffer, Class type) { - throw new IllegalStateException("Should not have to read void"); - } - - @Override - public Memory bufferForResult(Object methodCallResult) { - return new Memory(0); - } - }); - addToLookup(new NSInvocationMapper("c", boolean.class) { - // Cocoa BOOL is defined as signed char - @Override - public Object readFrom(Memory buffer, Class type) { - byte character = buffer.getByte(0); - return character == 0 ? java.lang.Boolean.FALSE : java.lang.Boolean.TRUE; - } - - @Override - public Memory bufferForResult(Object methodCallResult) { - Memory result = new Memory(1); - result.setByte(0, ((Boolean) methodCallResult) ? (byte) 1 : (byte) 0); - return result; - } - }); - addToLookup(new NSInvocationMapper("c", byte.class) { - @Override - public Object readFrom(Memory buffer, Class type) { - return buffer.getByte(0); - } - - @Override - public Memory bufferForResult(Object methodCallResult) { - Memory result = new Memory(1); - result.setByte(0, ((Byte) methodCallResult).byteValue()); - return result; - } - }); - addToLookup(new NSInvocationMapper("s", char.class) { - @Override - public Object readFrom(Memory buffer, Class type) { - throw new UnsupportedOperationException("Don't yet support char, while I think what to do"); - // TODO - think what to do - } - - @Override - public Memory bufferForResult(Object methodCallResult) { - throw new UnsupportedOperationException("Don't yet support char, while I think what to do"); - // TODO - think what to do - } - }); - addToLookup(new NSInvocationMapper("s", short.class) { - @Override - public Object readFrom(Memory buffer, Class type) { - return buffer.getShort(0); - } - - @Override - public Memory bufferForResult(Object methodCallResult) { - Memory result = new Memory(2); - result.setShort(0, ((Short) methodCallResult)); - return result; - } - }); - addToLookup(new NSInvocationMapper("i", int.class) { - @Override - public Object readFrom(Memory buffer, Class type) { - return buffer.getInt(0); - } - - @Override - public Memory bufferForResult(Object methodCallResult) { - Memory result = new Memory(4); - result.setInt(0, ((Integer) methodCallResult)); - return result; - } - }); - addToLookup(new NSInvocationMapper("q", long.class) { - @Override - public Object readFrom(Memory buffer, Class type) { - return buffer.getLong(0); - } - - @Override - public Memory bufferForResult(Object methodCallResult) { - Memory result = new Memory(8); - result.setLong(0, (Long) methodCallResult); - return result; - } - - ; - }); - addToLookup(new NSInvocationMapper("f", float.class) { - @Override - public Object readFrom(Memory buffer, Class type) { - return buffer.getFloat(0); - } - - @Override - public Memory bufferForResult(Object methodCallResult) { - Memory result = new Memory(4); - result.setFloat(0, ((Float) methodCallResult)); - return result; - } - }); - addToLookup(new NSInvocationMapper("d", double.class) { - @Override - public Object readFrom(Memory buffer, Class type) { - return buffer.getDouble(0); - } - - @Override - public Memory bufferForResult(Object methodCallResult) { - Memory result = new Memory(8); - result.setDouble(0, ((Double) methodCallResult)); - return result; - } - }); - addToLookup(new NSInvocationMapper("@", ID.class) { - @Override - public Object readFrom(Memory buffer, Class type) { - ID id = ID.fromLong(buffer.getNativeLong(0).longValue()); - if (id.isNull()) { - return null; - } - return id; - } - - @Override - public Memory bufferForResult(Object methodCallResult) { - Memory result = new Memory(NATIVE_POINTER_SIZE); - result.setNativeLong(0, ((ID) methodCallResult)); - return result; - } - }); - addToLookup(new NSInvocationMapper("@", String.class) { - @Override - public Object readFrom(Memory buffer, Class type) { - ID id = ID.fromLong(buffer.getNativeLong(0).longValue()); - if (id.isNull()) { - return null; - } - return Foundation.toString(id); - } - - @Override - public Memory bufferForResult(Object methodCallResult) { - Memory buffer = new Memory(NATIVE_POINTER_SIZE); - ID idString = Foundation.cfString((String) methodCallResult); - Foundation.sendReturnsID(idString, "autorelease"); - buffer.setNativeLong(0, idString); - return buffer; - } - }); - addToLookup(new NSInvocationMapper(NSINTEGER_ENCODING, NSInteger.class) { - @Override - public Object readFrom(Memory buffer, Class type) { - return new NSInteger(buffer.getNativeLong(0)); - } - - @Override - public Memory bufferForResult(Object methodCallResult) { - Memory result = new Memory(NATIVE_LONG_SIZE); - result.setNativeLong(0, ((NativeLong) methodCallResult)); - return result; - } - }); - addToLookup(new NSInvocationMapper(NSUINTEGER_ENCODING, NSUInteger.class) { - @Override - public Object readFrom(Memory buffer, Class type) { - return new NSUInteger(buffer.getNativeLong(0)); - } - - @Override - public Memory bufferForResult(Object methodCallResult) { - Memory result = new Memory(NATIVE_LONG_SIZE); - result.setNativeLong(0, ((NativeLong) methodCallResult)); - return result; - } - }); - addToLookup(new NSInvocationMapper(CGFLOAT_ENCODING, CGFloat.class) { - @Override - public Object readFrom(Memory buffer, Class type) { - if (NATIVE_LONG_SIZE == 4) { - return new CGFloat(buffer.getFloat(0)); - } - if (NATIVE_LONG_SIZE == 8) { - return new CGFloat(buffer.getDouble(0)); - } - throw new IllegalStateException(); - } - - @Override - public Memory bufferForResult(Object methodCallResult) { - Memory result = new Memory(NATIVE_LONG_SIZE); - if (NATIVE_LONG_SIZE == 4) { - result.setFloat(0, ((CGFloat) methodCallResult).floatValue()); - } - if (NATIVE_LONG_SIZE == 8) { - result.setDouble(0, ((CGFloat) methodCallResult).doubleValue()); - } - return result; - } - }); - } - - static final NSInvocationMapper OCOBJECT = new NSInvocationMapper("@", ObjCObject.class) { - @SuppressWarnings("unchecked") - @Override - public Object readFrom(Memory buffer, Class type) { - ID id = ID.fromLong(buffer.getNativeLong(0).longValue()); - if (id.isNull()) { - return null; - } - return Rococoa.wrap(id, (Class) type); - } - - @Override - public Memory bufferForResult(Object methodCallResult) { - Memory buffer = new Memory(NATIVE_POINTER_SIZE); - buffer.setNativeLong(0, ((ObjCObject) methodCallResult).id()); - return buffer; - } - }; - - static final NSInvocationMapper NATIVE_LONG = new NSInvocationMapper(NATIVE_LONG_ENCODING, NativeLong.class) { - @Override - public Object readFrom(Memory buffer, Class type) { - return buffer.getNativeLong(0); - } - - @Override - public Memory bufferForResult(Object methodCallResult) { - Memory result = new Memory(NATIVE_LONG_SIZE); - result.setNativeLong(0, ((NativeLong) methodCallResult)); - return result; - } - }; - - private static void addToLookup(NSInvocationMapper mapper) { - Class type = mapper.type; - classToMapperLookup.put(type, mapper); - if (type.isPrimitive()) { - classToMapperLookup.put(boxTypeFor(type), mapper); - } - } - - private static Class boxTypeFor(Class type) { - if (type == void.class) { - return null; - } - if (type == boolean.class) { - return Boolean.class; - } - if (type == byte.class) { - return Byte.class; - } - if (type == short.class) { - return Short.class; - } - if (type == char.class) { - return Character.class; - } - if (type == int.class) { - return Integer.class; - } - if (type == long.class) { - return Long.class; - } - if (type == float.class) { - return Float.class; - } - if (type == double.class) { - return Double.class; - } - throw new IllegalArgumentException("Not a primitive class " + type); - } -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/NSInvocationStructureMapper.java b/rococoa/rococoa-core/src/main/java/org/rococoa/internal/NSInvocationStructureMapper.java deleted file mode 100644 index 8cd765c5..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/NSInvocationStructureMapper.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.internal; - -import com.sun.jna.Memory; -import com.sun.jna.Native; -import com.sun.jna.Pointer; -import com.sun.jna.Structure; -import org.rococoa.RococoaException; -import org.rococoa.cocoa.foundation.NSInvocation; - -import java.lang.reflect.Field; -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -class NSInvocationStructureMapper extends NSInvocationMapper { - - @SuppressWarnings("unchecked") - public NSInvocationStructureMapper(Class type) { - super(encodeStruct((Class) type), type); - } - - private static String encodeStruct(Class clas) { - StringBuilder result = new StringBuilder(); - if (!(Structure.ByValue.class.isAssignableFrom(clas))) { - result.append('^'); // pointer to - } - result.append('{').append(clas.getSimpleName()).append('='); - for (Field f : collectStructFields(clas, new ArrayList<>())) { - result.append(NSInvocationMapperLookup.stringForType(f.getType())); - } - return result.append('}').toString(); - } - - @SuppressWarnings("unchecked") - private static List collectStructFields(Class clas, List list) { - if (clas == Structure.class) { - return list; - } - Collections.addAll(list, clas.getDeclaredFields()); - return collectStructFields((Class) clas.getSuperclass(), list); - } - - @SuppressWarnings("unchecked") - @Override - public Object readArgumentFrom(NSInvocation invocation, int index, Class type) { - if (Structure.ByValue.class.isAssignableFrom(type)) { - return readStructureByValue(invocation, index, (Class) type); - } else { - return readStructureByReference(invocation, index, (Class) type); - } - } - - @Override - public Memory bufferForResult(Object methodCallResult) { - if (methodCallResult instanceof Structure.ByValue) { - return bufferForStructureByValue((Structure) methodCallResult); - } else { - return bufferForStructureByReference((Structure) methodCallResult); - } - } - - private Structure readStructureByValue(NSInvocation invocation, int index, - Class type) { - Structure result = newInstance(type); - Memory buffer = new Memory(result.size()); - invocation.getArgument_atIndex(buffer, index); - return copyBufferToStructure(buffer, result); - } - - private Structure readStructureByReference(NSInvocation invocation, int index, - Class type) { - Memory buffer = new Memory(Native.POINTER_SIZE); - invocation.getArgument_atIndex(buffer, index); - Pointer pointerToResult = buffer.getPointer(0); - Structure result = newInstance(type); - return copyBufferToStructure(pointerToResult, result); - } - - @SuppressWarnings("unchecked") - private T newInstance(Class clas) { - try { - return (T) clas.newInstance(); - } catch (Exception e) { - throw new RococoaException("Could not instantiate " + clas, e); - } - } - - private Structure copyBufferToStructure(Pointer buffer, Structure structure) { - int byteCount = structure.size(); - memcpy(structure.getPointer(), buffer, byteCount); - structure.read(); - return structure; - } - - private Memory bufferForStructureByValue(Structure methodCallResult) { - methodCallResult.write(); - int byteCount = methodCallResult.size(); - Memory buffer = new Memory(byteCount); - memcpy(buffer, methodCallResult.getPointer(), byteCount); - return buffer; - } - - private Memory bufferForStructureByReference(Structure methodCallResult) { - methodCallResult.write(); - Memory buffer = new Memory(Native.POINTER_SIZE); - buffer.setPointer(0, methodCallResult.getPointer()); - return buffer; - } - - private void memcpy(Pointer dest, Pointer src, int byteCount) { - memcpyViaByteBuffer(dest, src, byteCount); - } - - @SuppressWarnings("unused") // kept as naive implementation - private void memcpyViaArray(Pointer dest, Pointer src, int byteCount) { - byte[] structBytes = new byte[byteCount]; - src.read(0, structBytes, 0, byteCount); - dest.write(0, structBytes, 0, byteCount); - } - - private void memcpyViaByteBuffer(Pointer dest, Pointer src, int byteCount) { - ByteBuffer destBuffer = dest.getByteBuffer(0, byteCount); - ByteBuffer srcBuffer = src.getByteBuffer(0, byteCount); - destBuffer.put(srcBuffer); - } -} \ No newline at end of file diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/OCInvocationCallbacks.java b/rococoa/rococoa-core/src/main/java/org/rococoa/internal/OCInvocationCallbacks.java deleted file mode 100644 index 67c6bcdf..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/OCInvocationCallbacks.java +++ /dev/null @@ -1,274 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.internal; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import org.rococoa.ID; -import org.rococoa.Rococoa; -import org.rococoa.RococoaException; -import org.rococoa.cocoa.foundation.NSInvocation; -import org.rococoa.cocoa.foundation.NSMethodSignature; - -import java.util.logging.Level; -import java.util.logging.Logger; - -import com.sun.jna.Memory; - -/** - * Holds the callbacks called when a method is invoked on an Objective-C proxy - * for a Java object. - * - * When a message is sent to an OC object first it is sent - * methodSignatureForSelector: Our Obj-C proxy forwards this to - * methodSignatureCallback; we build a method signature string in Java - * corresponding to the Java method and return it. - * - * The object is then sent forwardInvocation: passing an NSInvocation. It - * forwards this to selectorInvokedCallback, which we use to invoke the method - * on the Java Object. - * - * @author duncan - * - */ -public class OCInvocationCallbacks { - - private static final Logger logging = Logger.getLogger("org.rococoa.callback"); - - private final Object javaObject; - - /** - * Called when method is about to be invoked on OC proxy and needs a method signature as String - * - * @see "http://www.cocoadev.com/index.pl?NSMethodSignature" - */ - public final RococoaLibrary.MethodSignatureCallback methodSignatureCallback = - new RococoaLibrary.MethodSignatureCallback() { - public String callback(String selectorName) { - if (logging.isLoggable(Level.FINEST)) { - logging.finest(String.format("callback wanting methodSignature for selector %s", selectorName)); - } - return methodSignatureForSelector(selectorName); - } - }; - - /** - * Called when method has been invoked on OC proxy and needs to be forwarded to javaObject - */ - public final RococoaLibrary.SelectorInvokedCallback selectorInvokedCallback = - new RococoaLibrary.SelectorInvokedCallback() { - public void callback(String selectorName, ID nsInvocation) { - if (logging.isLoggable(Level.FINEST)) { - logging.finest(String.format("callback invoking %s on %s", selectorName, javaObject)); - } - callMethod(javaObject, selectorName, Rococoa.wrap(nsInvocation, NSInvocation.class)); - } - }; - - public OCInvocationCallbacks(Object javaObject) { - this.javaObject = javaObject; - } - - protected String methodSignatureForSelector(String selectorName) { - Method method = methodForSelector(selectorName); - return method == null ? - null : - ocMethodSignatureAsString(method); - } - - protected Method methodForSelector(String selectorName) { - if (null == selectorName) { - logging.severe("methodForSelector called with null selectorName"); - return null; - } - int parameterCount = countColons(selectorName); - String methodName = methodNameForSelector(selectorName); - try { - Method[] methods = javaObject.getClass().getMethods(); - for (Method method : methods) { - if (method.getName().equals(methodName) && method.getParameterTypes().length == parameterCount) { - boolean match = true; - if(null == stringForType(method.getReturnType())) { - match = false; - } - if(match) { - for (Class parameterType : method.getParameterTypes()) { - if(null == stringForType(parameterType)) { - match = false; - break; - } - } - } - if(match) { - return method; - } - } - } - logging.fine("No method " + methodName + " for selector:" + selectorName); - return null; - } catch (Exception e) { - logging.log(Level.SEVERE, "Exception finding methodForSelector", e); - return null; - } - } - - /** - * @see "http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_13_section_9.html" - */ - protected String ocMethodSignatureAsString(Method method) { - StringBuilder result = new StringBuilder(); - result.append(stringForType(method.getReturnType())); - result.append("@:"); // self and cmd - id and selector - for (Class parameterType : method.getParameterTypes()) { - result.append(stringForType(parameterType)); - } - return result.toString(); - } - - private void callMethod(Object o, String selectorName, NSInvocation invocation) { - try { - Method method = methodForSelector(selectorName); - - NSMethodSignature nsMethodSignature = invocation.methodSignature(); - String typeToReturnToObjC = nsMethodSignature.methodReturnType(); - - if (nsMethodSignature.numberOfArguments() - method.getParameterTypes().length != 2) { // self, _cmd - throw new NoSuchMethodException(String.format( - "Number of arguments mismatch for invocation of selector %s (%s arguments supplied), method %s expects %s", - selectorName, nsMethodSignature.numberOfArguments(), method.getName(), method.getParameterTypes().length)); - } - if (typeToReturnToObjC.equals("v") && method.getReturnType() != void.class) { - throw new NoSuchMethodException(String.format( - "Selector %s expects void return, but method %s returns %s", - selectorName, method.getName(), method.getReturnType())); - } - if (method.getReturnType() == void.class && !(typeToReturnToObjC.equals("v"))) { - throw new NoSuchMethodException(String.format( - "Method %s returns void, but selector %s expects %s", - method.getName(), selectorName, typeToReturnToObjC)); - } - Object[] marshalledArgs = argsForFrom(method, invocation, nsMethodSignature); - method.setAccessible(true); // needed if implementation is an anonymous subclass of Object - Object result = method.invoke(o, marshalledArgs); - putResultIntoInvocation(invocation, typeToReturnToObjC, result); - } catch (InvocationTargetException e) { - logging.log(Level.SEVERE, "Exception calling method for selector " + selectorName, e); - throw new RococoaException("Exception calling method for selector " + selectorName, e.getCause()); - } catch (Exception e) { - logging.log(Level.SEVERE, "Exception calling method for selector " + selectorName, e); - throw new RococoaException("Exception calling method for selector " + selectorName, e); - } - } - - private String methodNameForSelector(String selectorName) { - String candidate = selectorName.replaceAll(":", "_"); - return candidate.endsWith("_") ? - candidate.substring(0, candidate.length() - 1) : - candidate; - } - - private Object[] argsForFrom(Method method, NSInvocation invocation, NSMethodSignature nsMethodSignature) { - Class[] parameterTypes = method.getParameterTypes(); - Object[] result = new Object[parameterTypes.length]; - for (int i = 0; i < result.length; i++) { - int indexAccountingForSelfAndCmd = 2 + i; - result[i] = javaObjectForOCArgument(invocation, - indexAccountingForSelfAndCmd, - nsMethodSignature.getArgumentTypeAtIndex(indexAccountingForSelfAndCmd), - parameterTypes[i]); - } - return result; - } - - /** - * At this point we have an NSInvocation, which has the arguments to the - * call in it. We know the type of the argument, and the type of the - * parameter expected by the Java method. [1] - * Our mission is to get the value of the argument from the NSInvocation - * and return a Java object of the desired type. - */ - private Object javaObjectForOCArgument(NSInvocation invocation, - int indexInInvocation, String objCArgumentTypeAsString, Class javaParameterType) { - NSInvocationMapper mapper = NSInvocationMapperLookup.mapperForType(javaParameterType); - if (mapper == null) { - throw new IllegalStateException( - String.format("Don't (yet) know how to marshall argument Objective-C type %s as %s", - objCArgumentTypeAsString, javaParameterType)); - } - return mapper.readArgumentFrom(invocation, indexInInvocation, javaParameterType); - } - - private void putResultIntoInvocation(NSInvocation invocation, String typeToReturnToObjC, Object result) { - if (typeToReturnToObjC.equals("v")) { - if (result != null) { - throw new IllegalStateException("Java method returned a result, but expected void");// void - } - return; - } - if (null == result) { - return; - } - Memory buffer = bufferForReturn(result); - if (buffer == null) { - throw new IllegalStateException( - String.format("Don't (yet) know how to marshall result %s as Objective-C type %s", result, typeToReturnToObjC)); - } - invocation.setReturnValue(buffer); - } - - private Memory bufferForReturn(Object methodCallResult) { - NSInvocationMapper mapper = NSInvocationMapperLookup.mapperForType(methodCallResult.getClass()); - return mapper == null ? null : mapper.bufferForResult(methodCallResult); - } - - private int countColons(String selectorName) { - int result = 0; - for (int i = 0; i < selectorName.length(); i++) { - if (selectorName.charAt(i) == ':') { - result++; - } - } - return result; - } - - private String stringForType(Class clas) { - NSInvocationMapper result = NSInvocationMapperLookup.mapperForType(clas); - if (result == null) { - logging.warning("Unable to give Objective-C type string for Java type " + clas); - return null; - } - return result.typeString(); - } - - /* - * [1] - http://en.wikipedia.org/wiki/Parameter_(computer_science) - * Although parameters are also commonly referred to as arguments, - * arguments are more properly thought of as the actual values or references - * assigned to the parameter variables when the subroutine is called at - * runtime. When discussing code that is calling into a subroutine, any - * values or references passed into the subroutine are the arguments, and - * the place in the code where these values or references are given is the - * parameter list. When discussing the code inside the subroutine - * definition, the variables in the subroutine's parameter list are the - * parameters, while the values of the parameters at runtime are the - * arguments. - */ -} \ No newline at end of file diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/ObjCObjectByReferenceTypeConverter.java b/rococoa/rococoa-core/src/main/java/org/rococoa/internal/ObjCObjectByReferenceTypeConverter.java deleted file mode 100644 index 8a1355b4..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/ObjCObjectByReferenceTypeConverter.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -/** - * - */ -package org.rococoa.internal; - -import org.rococoa.IDByReference; -import org.rococoa.ObjCObject; - -import com.sun.jna.FromNativeContext; -import com.sun.jna.ToNativeContext; -import com.sun.jna.TypeConverter; - -/** - * Work in progress. I think that this needs a bit of JNA help to get off the ground. - */ -class ObjCObjectByReferenceTypeConverter implements TypeConverter { - - public Object fromNative(Object nativeValue, FromNativeContext context) { - throw new UnsupportedOperationException(); - } - - public Class nativeType() { - return IDByReference.class; - } - - public Object toNative(Object value, ToNativeContext context) { - if (value == null) { - return null; - } - return new IDByReference(); - } - - -// // x'd until ObjectByReferenceConverter installed -// public void xtestPassNSObjectByReference() { -// // currently only out, not in-out -// NSObjectByReference reference = new NSObjectByReference(); -// ToNativeConverter toNative = typeMapper.getToNativeConverter(reference.getClass()); -// // argument passing is based on actual type -// -// assertEquals(IDByReference.class, toNative.nativeType()); -// -// IDByReference nativeValue = (IDByReference) toNative.toNative(reference, null); -// assertEquals(0, nativeValue.getValue().intValue()); -// -// // called code will set id -// //NSNumber number = NSNumber.CLASS.numberWithInt(42); -// -// // TODO - can't make this work without jna support -// nativeValue.getPointer().setInt(number.id().intValue(), 0); -// -// // which our reference should see -// -// -// assertEquals(null, toNative.toNative(null, null)); -// -// } - -} \ No newline at end of file diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/ObjCObjectInvocationHandler.java b/rococoa/rococoa-core/src/main/java/org/rococoa/internal/ObjCObjectInvocationHandler.java deleted file mode 100644 index 22e164fb..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/ObjCObjectInvocationHandler.java +++ /dev/null @@ -1,323 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.internal; - -import com.sun.jna.Pointer; -import org.rococoa.*; -import org.rococoa.cocoa.CFIndex; - -import java.lang.reflect.AnnotatedElement; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.Callable; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Listens to invocations of methods on a Java NSObject, and forwards them to - * its Objective-C counterpart. - * - * @author duncan - */ -public class ObjCObjectInvocationHandler implements InvocationHandler { - - private static final int FINALIZE_AUTORELEASE_BATCH_SIZE = 1000; - - private static final Logger logging = Logger.getLogger("org.rococoa.proxy"); - - public static final Method OBJECT_TOSTRING; - public static final Method OBJECT_HASHCODE; - public static final Method OBJECT_EQUALS; - public static final Method OCOBJECT_ID; - - static { - try { - OBJECT_TOSTRING = Object.class.getMethod("toString"); - OBJECT_HASHCODE = Object.class.getMethod("hashCode"); - OBJECT_EQUALS = Object.class.getMethod("equals", Object.class); - OCOBJECT_ID = ObjCObject.class.getMethod("id"); - } catch (NoSuchMethodException x) { - throw new RococoaException("Error retrieving method", x); - } - } - - private ID ocInstance; - private final String javaClassName; - private final boolean invokeAllMethodsOnMainThread; - private final boolean releaseOnFinalize; - private volatile boolean finalized; - - public ObjCObjectInvocationHandler(final ID ocInstance, Class javaClass, boolean retain) { - this.ocInstance = ocInstance; - javaClassName = javaClass.getSimpleName(); - invokeAllMethodsOnMainThread = shouldInvokeMethodsOnMainThread(javaClass); - releaseOnFinalize = shouldReleaseInFinalize(javaClass); - - if (logging.isLoggable(Level.FINEST)) { - CFIndex retainCount = Foundation.cfGetRetainCount(ocInstance); - logging.finest(String.format("Creating ObjCObjectInvocationHandler for id %s, javaclass %s. retain = %s, retainCount = %s", - ocInstance, javaClass, retain, retainCount.intValue())); - } - - if (ocInstance.isNull()) { - throw new NullPointerException(); - } - - if (retain) { - if (callAcrossToMainThread()) { - Foundation.runOnMainThread(() -> Foundation.cfRetain(ocInstance)); - } else { - Foundation.cfRetain(ocInstance); - } - } - } - - private boolean shouldReleaseInFinalize(Class javaClass) { - // Almost everything should be released in finalize, except wrappers for - // NSAutoreleasePool. - ReleaseInFinalize annotation = javaClass.getAnnotation(ReleaseInFinalize.class); - if (annotation == null) { - return true; - } - return annotation.value(); - } - - @Override - protected void finalize() throws Throwable { - if (finalized || !releaseOnFinalize) { - return; - } - try { - if (callAcrossToMainThread()) { - Foundation.runOnMainThread(() -> release()); - } else { - AutoreleaseBatcher autoreleaseBatcher = AutoreleaseBatcher.forThread(FINALIZE_AUTORELEASE_BATCH_SIZE); - release(); - autoreleaseBatcher.operate(); - } - super.finalize(); - } finally { - finalized = true; - } - super.finalize(); - } - - // must be run on appropriate thread - private void release() { - if (ocInstance.isNull()) { - return; - } - if (logging.isLoggable(Level.FINEST)) { - CFIndex retainCount = Foundation.cfGetRetainCount(ocInstance); - logging.finest(String.format("finalizing [%s %s], releasing with retain count = %s", - javaClassName, ocInstance, retainCount.intValue())); - } - Foundation.cfRelease(ocInstance); - } - - /** - * Callback from java.lang.reflect proxy - */ - public Object invoke(Object proxy, Method method, Object[] args) throws Exception { - if (logging.isLoggable(Level.FINEST)) { - logging.finest(String.format("invoking [%s %s].%s(%s)", - javaClassName, ocInstance, method.getName(), new VarArgsUnpacker(args))); - } - if (isSpecialMethod(method)) { - return invokeSpecialMethod(method, args); - } - return invokeCocoa(method, args); - } - - private boolean isSpecialMethod(Method method) { - return (OBJECT_TOSTRING.equals(method) || - OBJECT_EQUALS.equals(method) || - OCOBJECT_ID.equals(method)); - } - - private Object invokeSpecialMethod(final Method method, final Object[] args) { - if (OBJECT_TOSTRING.equals(method)) { - return invokeDescription(); - } - if (OBJECT_EQUALS.equals(method)) { - if (args[0] == null) { - return false; - } - if (args[0] instanceof ObjCObject) { - return invokeIsEqual(((ObjCObject) args[0]).id()); - } - return false; - } - if (OCOBJECT_ID.equals(method)) { - return ocInstance; - } - throw new IllegalArgumentException("Not a special method " + method); - } - - private Object invokeDescription() { - return sendOnThisOrMainThread(null, ocInstance, "description", String.class); - } - - private Object invokeIsEqual(final ID another) { - return sendOnThisOrMainThread(null, ocInstance, "isEqual:", Boolean.class, another); - } - - protected Object invokeCocoa(final Method method, Object[] args) { - String selectorName = selectorNameFor(method); - Class returnType = returnTypeFor(method); - Object[] marshalledArgs = marshallArgsFor(args); - - Object result = sendOnThisOrMainThread(method, ocInstance, selectorName, returnType, marshalledArgs); - if (method.getName().startsWith("init")) { - handleInitMethod(result); - } - fillInReferences(args, marshalledArgs); - - if (result instanceof Pointer && method.getReturnType().equals(String.class)) { - // special case for return char* - return ((Pointer) result).getString(0); - } - if (result instanceof ID) { - if (((ID) result).isNull()) { - return null; - } - } - return result; - } - - private void handleInitMethod(Object result) { - // Normally init methods return self, but on error they may return nil. - // In this case the ObjC object for which this is the handler is considered - // freed and should not be released when we are finalized. - if (result != null) { - return; - } - ocInstance = ID.fromLong(0); - } - - private Object sendOnThisOrMainThread(Method method, final ID id, final String selectorName, final Class returnType, final Object... args) { - if (callAcrossToMainThreadFor(method)) { - return Foundation.callOnMainThread( - (Callable) () -> Foundation.send(id, selectorName, returnType, method, args)); - } else { - return Foundation.send(id, selectorName, returnType, method, args); - } - } - - /** - * We need to make sure that we have filled in all NSObjectByReferences - * so that they are retained. - */ - private void fillInReferences(Object[] args, Object[] marshalledArgs) { - if (args == null) { - return; - } - for (int i = 0; i < args.length; i++) { - Object original = args[i]; - Object marshalled = marshalledArgs[i]; - if (marshalled instanceof IDByReference) { - if (!(original instanceof ObjCObjectByReference)) { - logging.severe("Bad marshalling"); - continue; - } - ((ObjCObjectByReference) original).setObject( - Rococoa.wrap(((IDByReference) marshalled).getValue(), ObjCObject.class)); - } - } - } - - private Class returnTypeFor(final Method method) { - ReturnType annotation = method.getAnnotation(ReturnType.class); - if (annotation == null) { - return method.getReturnType(); - } else { - return annotation.value(); - } - } - - private Object[] marshallArgsFor(Object[] args) { - if (args == null) { - return null; - } - List result = new ArrayList<>(args.length); - for (Object arg : args) { - final Object marshalled = marshall(arg); - if (marshalled instanceof Object[]) { - // flatten varags, it would never(?) make sense to pass Object[] to Cococoa - result.addAll(Arrays.asList((Object[]) marshalled)); - } else { - result.add(marshalled); - } - } - return result.toArray(new Object[result.size()]); - } - - private Object marshall(Object arg) { - // Note that this is not the only marshalling that is done. - // RococoaTypeMapper also gets involved. - if (arg == null) { - return null; - } - if (arg instanceof ObjCObjectByReference) { - // Forward conversion (another backwards conversion will take place in fillInReferences) - IDByReference idref = new IDByReference(); - ObjCObject ob = ((ObjCObjectByReference) arg).getValueAs(ObjCObject.class); - if (ob != null) { - idref.setValue(ob.id()); - } - return idref; - } - return arg; - } - - private String selectorNameFor(Method method) { - StringBuilder selector = new StringBuilder(method.getName()); - if (selector.charAt(selector.length()-1) == '_') { - // lets us append _ to allow Java keywords as method names - selector.setLength(selector.length()-1); - } - if (method.getParameterTypes().length > 0) { - for (int i = 0; i < selector.length(); i++) { - if (selector.charAt(i) == '_') { - selector.setCharAt(i, ':'); - } - } - selector.append(':'); - } - return selector.toString(); - } - - - private boolean shouldInvokeMethodsOnMainThread(AnnotatedElement element) { - return element != null && element.getAnnotation(RunOnMainThread.class) != null; - } - - private boolean callAcrossToMainThread() { - return callAcrossToMainThreadFor(null); - } - - private boolean callAcrossToMainThreadFor(Method m) { - return (invokeAllMethodsOnMainThread || shouldInvokeMethodsOnMainThread(m)) && !Foundation.isMainThread(); - } -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/ObjCObjectTypeConverter.java b/rococoa/rococoa-core/src/main/java/org/rococoa/internal/ObjCObjectTypeConverter.java deleted file mode 100644 index 529f732d..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/ObjCObjectTypeConverter.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -/** - * - */ -package org.rococoa.internal; - -import org.rococoa.Foundation; -import org.rococoa.ID; -import org.rococoa.ObjCObject; -import org.rococoa.Rococoa; -import org.rococoa.Selector; - -import com.sun.jna.FromNativeContext; -import com.sun.jna.FunctionResultContext; -import com.sun.jna.NativeMapped; -import com.sun.jna.ToNativeContext; -import com.sun.jna.TypeConverter; - -/** - * A JNA TypeConverter that gets the ID from an NSObject when passing it into - * native code, and creates an instance of subclass of NSObject to wrap an id - * when receiving one from native code. - */ -class ObjCObjectTypeConverter implements TypeConverter { - - private static final NativeMapped nativeLongConverter = new ID(); - - private final Class javaType; - - public ObjCObjectTypeConverter(Class javaType) { - this.javaType = javaType; - } - - public Class nativeType() { - // we can't return NativeLong here - has to be a primitive type, so - // delegate so that we are 32/64 correct - return nativeLongConverter.nativeType(); - } - - // Takes an Integer or Long representing id (32 or 64 bit respectively) - // and returns an NSObject of javaType with that id. - public T fromNative(Object nativeValue, FromNativeContext context) { - Number nativeValueAsNumber = (Number) nativeValue; - if (nativeValueAsNumber == null) { - return null; - } - ID id = ID.fromLong(nativeValueAsNumber.longValue()); - if (id.isNull()) { - return null; - } - boolean shouldRetain = shouldRetainFor(context); - return Rococoa.wrap(id, javaType, shouldRetain); - } - - // Takes an NSObject and returns its id as Integer or Long - public Object toNative(Object value, ToNativeContext context) { - if (value == null) { - return null; - } - ObjCObject valueAsNSObject = (ObjCObject) value; - ID idToReturn = valueAsNSObject.id(); - return idToReturn.toNative(); - } - - // For tests only - boolean convertsJavaType(Class javaType) { - return this.javaType == javaType; - } - - private boolean shouldRetainFor(FromNativeContext context) { - // Generally we should default to retaining, as by default NSObjects that - // are returned from methods are owned by the current autorelease pool and - // unless we retain will be dealloc'ed when is is drained. - if (!(context instanceof FunctionResultContext)) { - return true; - } - // The exception is if this conversion is for an object that we own, because - // the selector name matches those - FunctionResultContext resultContext = (FunctionResultContext) context; - Object[] arguments = resultContext.getArguments(); - if (arguments.length < 2) { - return true; - } - if (!(arguments[1] instanceof Selector)) { - return true; - } - boolean dontRetain = Foundation.selectorNameMeansWeOwnReturnedObject(((Selector) arguments[1]).getName()); - return !dontRetain; // OK Smartarse, you express it better. - } -} \ No newline at end of file diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/OperationBatcher.java b/rococoa/rococoa-core/src/main/java/org/rococoa/internal/OperationBatcher.java deleted file mode 100644 index cce57bea..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/OperationBatcher.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.internal; - -/** - * Batches calls to operate(), calling operation() once per batchsize. - * - * @author duncan - */ -public abstract class OperationBatcher { - private final int batchSize; - private int count; - private boolean closed; - - public OperationBatcher(int batchSize) { - this.batchSize = batchSize; - reset(); - } - - public void operate() { - if (closed) { - throw new IllegalStateException("Batcher closed"); - } - if (++count < batchSize) { - return; - } - operation(); - reset(); - count = 0; - } - - public void close() { - if (closed) { - throw new IllegalStateException("Batcher closed"); - } - operation(); - closed = true; - } - - protected abstract void operation(); - - protected abstract void reset(); -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/RococoaLibrary.java b/rococoa/rococoa-core/src/main/java/org/rococoa/internal/RococoaLibrary.java deleted file mode 100644 index a4353205..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/RococoaLibrary.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.internal; - - -import org.rococoa.ID; - -import com.sun.jna.Callback; -import com.sun.jna.Library; - -/** - * JNA Library for special operations provided by our own native code - */ -public interface RococoaLibrary extends Library { - - /** - * Callback from Obj-C to get method signature string for Java method matching selectorName - */ - interface MethodSignatureCallback extends Callback { - String callback(String selectorName); - } - - /** - * Callback from Obj-C to invoke method on Java object - */ - interface SelectorInvokedCallback extends Callback { - void callback(String selectorName, ID nsInvocation); - } - - /** - * Return an Obj-C object that will callback on methodSignature required and - * selector invoked, so that we can use a Java object to implement. - */ - ID proxyForJavaObject(SelectorInvokedCallback selectorInvokedCallback, - MethodSignatureCallback methodSignatureCallback); - - /** - * Generic callback from Obj-C - */ - interface VoidCallback extends Callback { - void callback(); - } - - /** - * Call callback on the main Cococa event thread - */ - void callOnMainThread(RococoaLibrary.VoidCallback callback, boolean waitUntilDone); -} \ No newline at end of file diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/RococoaTypeMapper.java b/rococoa/rococoa-core/src/main/java/org/rococoa/internal/RococoaTypeMapper.java deleted file mode 100644 index feb82230..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/RococoaTypeMapper.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.internal; - -import org.rococoa.ObjCObject; -import org.rococoa.cocoa.foundation.NSObject; - -import com.sun.jna.DefaultTypeMapper; -import com.sun.jna.FromNativeConverter; - -/** - * A JNA TypeMapper that knows how to convert : - *
    - *
  • {@link NSObject} to and from an integer type with the right size to be an id.
  • - *
  • {@link String} to and from an integer type with the right size to be an id.
  • - *
  • {@link boolean} to a byte with the right values for Mac.
  • - *
- * - * Note that nativeType is never NativeLong, but the appropriate Java primitive - * with the right size of NativeLong. - * - * TypeMappers are consulted by JNA to know how to convert between Java values - * and objects and native values. - * - * @author duncan - * - */ -public class RococoaTypeMapper extends DefaultTypeMapper { - - public RococoaTypeMapper() { - addToNativeConverter(ObjCObject.class, new ObjCObjectTypeConverter(ObjCObject.class)); - addToNativeConverter(Boolean.class, new BoolConverter()); - addFromNativeConverter(Boolean.class, new BoolConverter()); - addTypeConverter(String.class, new StringTypeConverter()); - // addToNativeConverter(NSObjectByReference.class, new ObjectByReferenceConverter()); - // not actually used at present because NSObjectInvocationHandler does marshalling - } - - @SuppressWarnings("unchecked") - @Override public FromNativeConverter getFromNativeConverter(Class javaType) { - if (ObjCObject.class.isAssignableFrom(javaType)) { - // return a new converter that knows the subtype it is going to create - return new ObjCObjectTypeConverter((Class)javaType); - } - return super.getFromNativeConverter(javaType); - } - -} diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/StringTypeConverter.java b/rococoa/rococoa-core/src/main/java/org/rococoa/internal/StringTypeConverter.java deleted file mode 100644 index d6d42775..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/StringTypeConverter.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.internal; - -import org.rococoa.Foundation; -import org.rococoa.ID; - -import com.sun.jna.FromNativeContext; -import com.sun.jna.NativeMapped; -import com.sun.jna.ToNativeContext; -import com.sun.jna.TypeConverter; - -/** - * Converts between java.lang.String and Cocooa id, which it needs to return - * as Integer or Long depending on platform - */ -class StringTypeConverter implements TypeConverter { - private static final NativeMapped nativeLongConverter = new ID(); - - public Class nativeType() { - // see NSObjectTypeConverter.nativeType - return nativeLongConverter.nativeType(); - } - - // Takes an Integer or Long representing id (32 or 64 bit respectively) - // and returns a java.lang.String - public String fromNative(Object nativeValue, FromNativeContext context) { - Number nativeValueAsNumber = (Number) nativeValue; - if (nativeValueAsNumber == null) { - return null; - } - ID id = ID.fromLong(nativeValueAsNumber.longValue()); - if (id.isNull()) { - return null; - } - return Foundation.toString(id); - } - - // Takes java.lang.String and returns value of an id as Integer or Long - public Object toNative(Object value, ToNativeContext context) { - if (value == null) { - return null; - } - String valueAsString = (String) value; - ID valueAsID = Foundation.cfString(valueAsString); - Foundation.sendReturnsID(valueAsID, "autorelease"); - return valueAsID.toNative(); - } -} \ No newline at end of file diff --git a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/VarArgsUnpacker.java b/rococoa/rococoa-core/src/main/java/org/rococoa/internal/VarArgsUnpacker.java deleted file mode 100644 index 975348e5..00000000 --- a/rococoa/rococoa-core/src/main/java/org/rococoa/internal/VarArgsUnpacker.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.internal; - -public class VarArgsUnpacker { - - private static final String SEPERATOR = ", "; - private static final Object[] NULLARGS = new Object[0]; - - private final Object[] args; - - public VarArgsUnpacker(Object... args) { - this.args = args != null ? args : NULLARGS; - } - - @Override - public String toString() { - StringBuilder result = new StringBuilder(); - for (Object arg : args) { - result.append(arg).append(SEPERATOR); - } - if (result.length() > 0) { - result.setLength(result.length() - SEPERATOR.length()); - } - return result.toString(); - } - -} diff --git a/rococoa/rococoa-core/src/main/native/ProxyForJava.h b/rococoa/rococoa-core/src/main/native/ProxyForJava.h deleted file mode 100644 index 1436d315..00000000 --- a/rococoa/rococoa-core/src/main/native/ProxyForJava.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -#import - -id proxyForJavaObject(void* methodInvokedCallback, void* methodSignatureCallback); - -@interface ProxyForJava : NSObject { - -void (*methodInvokedCallback)(const char*, id); -char* (*methodSignatureCallback)(const char*); - -} - -- (id) initWithMethodInvokedCallback: (void*) theMethodInvokedCallback methodSignatureCallback: (void*) theMethodSignatureCallback; - -- (void)forwardInvocation:(NSInvocation *) anInvocation; - -- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector; - -@end diff --git a/rococoa/rococoa-core/src/main/native/ProxyForJava.m b/rococoa/rococoa-core/src/main/native/ProxyForJava.m deleted file mode 100644 index d5200d85..00000000 --- a/rococoa/rococoa-core/src/main/native/ProxyForJava.m +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -#import "ProxyForJava.h" - -id proxyForJavaObject(void* methodInvokedCallback, void* methodSignatureCallback) { - return [[ProxyForJava alloc] initWithMethodInvokedCallback: methodInvokedCallback methodSignatureCallback: methodSignatureCallback]; -} - -@interface ProxyForJava (Private) -+ (const char *)cstringPtrForSelector:(CFStringRef) cfstring; -@end - -@implementation ProxyForJava - -- (id) initWithMethodInvokedCallback: (void*) theMethodInvokedCallback methodSignatureCallback: (void*) theMethodSignatureCallback { - self = [super init]; - if (self != nil) { - methodInvokedCallback = theMethodInvokedCallback; - methodSignatureCallback = theMethodSignatureCallback; - } - return self; -} - -// Passes a given invocation to the real object the proxy represents. -- (void)forwardInvocation:(NSInvocation *) anInvocation { - // calls back to Java on methodInvokedCallback, - SEL selector = [anInvocation selector]; - NSString* selectorName = NSStringFromSelector(selector); - // NSLog(@"forwardInvocation for %@", selectorName); - methodInvokedCallback([ProxyForJava cstringPtrForSelector:(CFStringRef) selectorName], anInvocation); -} - -- (BOOL)respondsToSelector:(SEL)aSelector { - // NSString* selectorName = NSStringFromSelector(aSelector); - // NSLog(@"respondsToSelector %@", selectorName); - NSMethodSignature* signature = [self methodSignatureForSelector:aSelector]; - return signature != nil; -} - -// Override this method in your concrete subclass to return a proper NSMethodSignature object for the -// given selector and the class your proxy objects stand in for. -- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector { - NSString* selectorName = NSStringFromSelector(aSelector); - // NSLog(@"methodSignatureForSelector %@", selectorName); - if (aSelector == @selector(hash) || aSelector == @selector(isEqual:)) { - return [super methodSignatureForSelector: aSelector]; - } - const char* methodSignature = methodSignatureCallback([ProxyForJava cstringPtrForSelector:(CFStringRef) selectorName]); - if (NULL == methodSignature) { - // No method with signature of selector implemented - // NSLog(@"No method with signature of selector implemented: %@", selectorName); - return nil; - } - NSMethodSignature* result = [NSMethodSignature signatureWithObjCTypes: methodSignature]; - return result; -} - -+ (const char *)cstringPtrForSelector:(CFStringRef) selectorName { - static CFStringEncoding encoding = kCFStringEncodingUTF8; - const char* selectorNameChar = CFStringGetCStringPtr(selectorName, encoding); - if (NULL == selectorNameChar) { - // NSLog(@"CFStringGetCStringPtr failed for selector %@ with encoding %u", selectorName, encoding); - // May return NULL at any time. NULL if the internal storage of theString does not allow this to be returned efficiently. - CFIndex maxSize = CFStringGetMaximumSizeForEncoding(CFStringGetLength(selectorName), encoding); - char *buffer = (char *)malloc(maxSize); - if(CFStringGetCString(selectorName, buffer, maxSize, encoding)) { - return buffer; - } - NSLog(@"CFStringGetCString failed for selector %@ with encoding %u", selectorName, encoding); - } - return selectorNameChar; -} - -@end diff --git a/rococoa/rococoa-core/src/main/native/Rococoa.h b/rococoa/rococoa-core/src/main/native/Rococoa.h deleted file mode 100644 index c47b12a8..00000000 --- a/rococoa/rococoa-core/src/main/native/Rococoa.h +++ /dev/null @@ -1,10 +0,0 @@ -#import -#include - -void callOnMainThread(void (*fn)(void), BOOL waitUntilDone); - -@interface RococoaHelper : NSObject -+ (void) callback: (NSValue*) fn; -@end - - diff --git a/rococoa/rococoa-core/src/main/native/Rococoa.m b/rococoa/rococoa-core/src/main/native/Rococoa.m deleted file mode 100644 index 48481d89..00000000 --- a/rococoa/rococoa-core/src/main/native/Rococoa.m +++ /dev/null @@ -1,20 +0,0 @@ -#include "Rococoa.h" - -void callOnMainThread(void (*fn)(void), BOOL waitUntilDone) { - // NSLog(@"callOnMainThread function at address %p", fn); - // Pool is required as we're being called from Java, which probably doesn't have a pool to - // allocate the NSValue from. - NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; - [RococoaHelper performSelectorOnMainThread: @selector(callback:) - withObject: [NSValue valueWithPointer: fn] waitUntilDone: waitUntilDone]; - [pool release]; -} - -@implementation RococoaHelper : NSObject - -+ (void) callback: (NSValue*) fnAsValue { - void (*fn)(void) = [fnAsValue pointerValue]; - (*fn)(); -} - -@end diff --git a/rococoa/rococoa-core/src/main/native/test.h b/rococoa/rococoa-core/src/main/native/test.h deleted file mode 100644 index 2361d9cf..00000000 --- a/rococoa/rococoa-core/src/main/native/test.h +++ /dev/null @@ -1,65 +0,0 @@ -// -// test.h -// rococoa -// -// Created by Duncan McGregor on 03/12/2007. -// Copyright 2007 __MyCompanyName__. All rights reserved. -// - -#import - -typedef struct TestIntDoubleStruct { - int anInt; - double aDouble; -} TestIntDoubleStruct; - -typedef struct TestStructOfStruct { - double aDouble; - TestIntDoubleStruct aStruct; -} TestStructOfStruct; - -typedef struct TestFloatFloatStruct { - float a; - float b; -} TestFloatFloatStruct; - -typedef struct TestIntFloatStruct { - int a; - float b; -} TestIntFloatStruct; - -typedef struct TestIntIntStruct { - int a; - int b; -} TestIntIntStruct; - -typedef struct TestIntLongStruct { - int a; - int64_t b; -} TestIntLongStruct; - -TestIntDoubleStruct createIntDoubleStruct(int a, double b); - -double addFieldsOfStructByValue(TestIntDoubleStruct s); - -@interface TestShunt : NSObject - -- (TestIntDoubleStruct) testReturnStructByValue: (int) a and: (double) b; - -- (double) testAddFieldsOfStructByValue: (TestIntDoubleStruct) s; - -- (TestStructOfStruct) testReturnStructOfStructByValue: (int) a and: (double) b; - -- (double) testPassStructOfStructByValue: (TestStructOfStruct) s; - -- (void) testNSNumberByReference: (NSNumber**) fillMeIn with: (int) aValue; - -- (BOOL) valueIsYES:(BOOL) a; - -- (BOOL) valueIsNO:(BOOL) a; - -- (bool) isMainThread; - - - -@end diff --git a/rococoa/rococoa-core/src/main/native/test.m b/rococoa/rococoa-core/src/main/native/test.m deleted file mode 100644 index 4cab5a8c..00000000 --- a/rococoa/rococoa-core/src/main/native/test.m +++ /dev/null @@ -1,103 +0,0 @@ -// -// test.m -// rococoa -// -// Created by Duncan McGregor on 03/12/2007. -// Copyright 2007 __MyCompanyName__. All rights reserved. -// - -#import "test.h" -#import -#include - -TestIntDoubleStruct createIntDoubleStruct(int a, double b) { - TestIntDoubleStruct result = {a, b}; - return result; -} - -double addFieldsOfStructByValue(TestIntDoubleStruct s) { - return s.anInt + s.aDouble; -} - -// JNA got broken for this case -double addFieldsOfStructByValueVARARGS(size_t count, ...) { - va_list vl; - va_start(vl, count); - TestIntDoubleStruct s = va_arg(vl, TestIntDoubleStruct); - double result = addFieldsOfStructByValue(s); - va_end(vl); - return result; -} - -TestFloatFloatStruct createFloatFloatStruct(float a, float b) { - TestFloatFloatStruct result = {a, b}; - return result; -} - -TestIntFloatStruct createIntFloatStruct(int a, float b) { - TestIntFloatStruct result = {a, b}; - return result; -} - -TestIntLongStruct createIntLongStruct(int a, int64_t b) { - TestIntLongStruct result = {a, b}; - return result; -} - -TestIntIntStruct createIntIntStruct(int a, int b) { - TestIntIntStruct result = {a, b}; - return result; -} - -@implementation TestShunt - -- (TestIntDoubleStruct) testReturnStructByValue: (int) a and: (double) b { - return createIntDoubleStruct(a, b); -} - -- (double) testAddFieldsOfStructByValue: (TestIntDoubleStruct) s { - return addFieldsOfStructByValue(s); -} - -- (TestStructOfStruct) testReturnStructOfStructByValue: (int) a and: (double) b { - TestIntDoubleStruct inside = createIntDoubleStruct(a, b); - TestStructOfStruct result = {b, inside}; - return result; -} - -- (double) testPassStructOfStructByValue: (TestStructOfStruct) s { - return s.aStruct.aDouble; -} - -- (NSNumber*) testNumberFromInt: (int) aValue { - NSLog(@"Received number %i", aValue); - NSNumber* number = [NSNumber numberWithInt: aValue]; - return number; -} - -- (void) testNSNumberByReference: (NSNumber**) fillMeIn with: (int) aValue { - NSNumber* number = [NSNumber numberWithInt: aValue]; - *fillMeIn = number; -} - -- (void) testCallbackWithReference:(id)delegate { - if ([delegate respondsToSelector:@selector(callback:)]) { - NSError* error = nil; - [delegate callback:&error]; - } -} - -- (BOOL) valueIsYES:(BOOL) a { - return a == YES; -} - -- (BOOL) valueIsNO:(BOOL) a { - return a == NO; -} - -- (bool) isMainThread { - return pthread_main_np(); -} - - -@end diff --git a/rococoa/rococoa-core/src/test/java/org/rococoa/FoundationMainThreadTest.java b/rococoa/rococoa-core/src/test/java/org/rococoa/FoundationMainThreadTest.java deleted file mode 100644 index f5c9b8e2..00000000 --- a/rococoa/rococoa-core/src/test/java/org/rococoa/FoundationMainThreadTest.java +++ /dev/null @@ -1,254 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa; - -import java.util.concurrent.Callable; -import java.util.concurrent.CyclicBarrier; - -import org.junit.Test; -import org.rococoa.test.RococoaTestCase; - -import static org.junit.Assert.*; - -public class FoundationMainThreadTest extends RococoaTestCase { - - private final ID idNSThreadClass = Foundation.getClass("NSThread"); - private final Selector isMainThreadSelector = Foundation.selector("isMainThread"); - - private boolean nsThreadSaysIsMainThread() { - return Foundation.send(idNSThreadClass, isMainThreadSelector, boolean.class); - } - - @Test - public void mainThreadChanges() { - // Not sure that I understand this result - assertFalse(nsThreadSaysIsMainThread()); - Thread t1 = Foundation.callOnMainThread(() -> { - assertTrue(nsThreadSaysIsMainThread()); - return Thread.currentThread(); - }); - Thread t2 = Foundation.callOnMainThread(() -> { - assertTrue(nsThreadSaysIsMainThread()); - return Thread.currentThread(); - }); - assertNotSame(t1, Thread.currentThread()); - assertNotSame(t1, t2); - assertNotEquals(t1, t2); - assertSame(t1.getThreadGroup(), t2.getThreadGroup()); - assertNotSame(Thread.currentThread().getThreadGroup(), t1.getThreadGroup()); - } - - @Test - public void testCallOnMainThreadFromMainThread() { - // Weird - Thread mainThread = Foundation.callOnMainThread(() -> { - assertTrue(nsThreadSaysIsMainThread()); - - Thread insideThread = Foundation.callOnMainThread(() -> { - assertTrue(nsThreadSaysIsMainThread()); - return Thread.currentThread(); - }); - - assertSame(Thread.currentThread(), insideThread); - return insideThread; - }); - assertNotSame(mainThread, Thread.currentThread()); - } - - @Test - public void isMainThread() { - assertFalse(Foundation.isMainThread()); - assertTrue(Foundation.callOnMainThread(() -> Foundation.isMainThread())); - } - - @Test - public void testCallOnMainThread() { - Callable callable = () -> { - assertTrue(nsThreadSaysIsMainThread()); - ID clas = Foundation.getClass("NSNumber"); - ID aDouble = Foundation.sendReturnsID(clas, "numberWithDouble:", Math.E); - Object[] args = {}; - return Foundation.send(aDouble, Foundation.selector("doubleValue"), double.class, args); - }; - - assertEquals(Math.E, Foundation.callOnMainThread(callable), 0.001); - } - - @Test - public void callOnMainThreadPropagatesError() { - Throwable thrown = new Error("deliberate"); - try { - throwOnMainThreadViaCallable(thrown); - fail(); - } catch (Error e) { - assertSame(thrown, e); - } - } - - @Test - public void callOnMainThreadPropagatesRuntimeException() { - Throwable thrown = new RuntimeException("deliberate"); - try { - throwOnMainThreadViaCallable(thrown); - fail(); - } catch (RuntimeException e) { - assertSame(thrown, e); - } - } - - @Test - public void callOnMainThreadWrapsException() { - Throwable thrown = new Exception("deliberate"); - try { - throwOnMainThreadViaCallable(thrown); - fail(); - } catch (Exception e) { - assertSame(thrown, e.getCause()); - } - } - - @Test - public void runOnMainThread() { - final double[] result = new double[1]; - Runnable runnable = () -> { - assertTrue(nsThreadSaysIsMainThread()); - ID clas = Foundation.getClass("NSNumber"); - ID aDouble = Foundation.sendReturnsID(clas, "numberWithDouble:", Math.E); - Object[] args = {}; - result[0] = Foundation.send(aDouble, Foundation.selector("doubleValue"), double.class, args); - }; - Foundation.runOnMainThread(runnable); - assertEquals(Math.E, result[0], 0.001); - } - - @Test - public void runOnMainThreadPropagatesError() { - Throwable thrown = new Error("deliberate"); - try { - throwOnMainThreadViaRunnable(thrown); - fail(); - } catch (Error e) { - assertSame(thrown, e); - } - } - - @Test - public void runOnMainThreadPropagatesRuntimeException() { - Throwable thrown = new RuntimeException("deliberate"); - try { - throwOnMainThreadViaRunnable(thrown); - fail(); - } catch (RuntimeException e) { - assertSame(thrown, e); - } - } - - @Test - public void runOnMainThreadNoWait() throws Exception { - final Throwable[] throwable = new Throwable[1]; - final CyclicBarrier barrier = new CyclicBarrier(2); - Runnable runnable = () -> { - try { - assertTrue(nsThreadSaysIsMainThread()); - barrier.await(); - } catch (Throwable t) { - throwable[0] = t; - } - }; - Foundation.runOnMainThread(runnable, false); - barrier.await(); - assertNull(throwable[0]); - } - - @Test - public void runOnMainThreadNoWaitThrows() throws Exception { - final Throwable[] throwable = new Throwable[1]; - final CyclicBarrier barrier = new CyclicBarrier(2); - Runnable runnable = () -> { - try { - barrier.await(); - } catch (Throwable t) { - throwable[0] = t; - } - throw new Error("deliberate"); - }; - Foundation.runOnMainThread(runnable, false); // Exception is just logged - barrier.await(); - } - - @Test - public void runOnMainThreadNoWaitWithGC() throws Exception { - // We had a problem where the callback that JNA uses to invoke Java code - // could be gc'd before the call had happened, if waitUntilDone == false - - // First block the Cocoa main thread - final CyclicBarrier barrier1 = new CyclicBarrier(2); - final CyclicBarrier barrier2 = new CyclicBarrier(2); - Runnable mainThreadBlocker = () -> { - try { - barrier1.await(); - barrier2.await(); - } catch (Throwable t) { - System.out.println(t); - } - }; - Foundation.runOnMainThread(mainThreadBlocker, false); - barrier1.await(); - // Now we know the main thread is stalled inside run - - // now set up another runnable - final CyclicBarrier barrier3 = new CyclicBarrier(2); - Runnable actualRunnable = () -> { - try { - barrier3.await(); - } catch (Throwable t) { - System.out.println(t); - } - }; - Foundation.runOnMainThread(actualRunnable, false); - - // Give the internal callback a chance to be gc'd - gc(); - - // release the main thread, so that the callback can happen - barrier2.await(); - - // and wait for it to happen - if the internal callback has been gc'd - // it won't be invoked and this thread will hang here - barrier3.await(); - } - - private void throwOnMainThreadViaCallable(final Throwable x) { - Callable callable = () -> { - if (x instanceof Error) throw (Error) x; - else throw (Exception) x; - }; - Foundation.callOnMainThread(callable); - } - - private void throwOnMainThreadViaRunnable(final Throwable x) { - Runnable runnable = () -> { - if (x instanceof Error) throw (Error) x; - else throw (RuntimeException) x; - }; - Foundation.runOnMainThread(runnable); - } - -} diff --git a/rococoa/rococoa-core/src/test/java/org/rococoa/FoundationMemoryAssumptionsTest.java b/rococoa/rococoa-core/src/test/java/org/rococoa/FoundationMemoryAssumptionsTest.java deleted file mode 100644 index cc9d062f..00000000 --- a/rococoa/rococoa-core/src/test/java/org/rococoa/FoundationMemoryAssumptionsTest.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa; - -import org.junit.Ignore; -import org.junit.Test; - -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.rococoa.test.RococoaTestCase.assertRetainCount; - -/** - * Showing some fundamentals of Cocoa memory management - *

- * Not a RococoaTestCase so that we know the state of autorelease pools. - *

- * TODO - don't run these when in ObjC GC - * - * @author duncan - */ -public class FoundationMemoryAssumptionsTest { - - @Test - public void classHasInfiniteRetainCount() { - assertRetainCount(-1, Foundation.getClass("NSString")); - } - - @Test - public void cFStringHasRetainCountOfOne() { - assertRetainCount(1, Foundation.cfString("Hello World")); - } - - @Test - public void initGivesRetainCountOfOne() { - ID idNSObject = Foundation.sendReturnsID(Foundation.getClass("NSObject"), "alloc"); - assertRetainCount(1, idNSObject); - } - - @Test - public void newGivesRetainCountOfOne() { - ID idNSObject = Foundation.sendReturnsID(Foundation.getClass("NSObject"), "new"); - assertRetainCount(1, idNSObject); - } - - @Test - public void testAutoreleasePool() { - ID idPool = Foundation.sendReturnsID(Foundation.getClass("NSAutoreleasePool"), "new"); - assertRetainCount(1, idPool); - - ID idNSObject = Foundation.sendReturnsID(Foundation.getClass("NSObject"), "new"); - assertRetainCount(1, idNSObject); - - assertEquals(idNSObject, Foundation.sendReturnsID(idNSObject, "autorelease")); - assertRetainCount(1, idNSObject); // pool doesn't retain, but does assume ownership. - // Effectively autorelease gives the object to the pool, rather than sharing - - // retain so that draining the pool doesn't free - assertEquals(idNSObject, Foundation.cfRetain(idNSObject)); - assertRetainCount(2, idNSObject); - - Foundation.sendReturnsVoid(idPool, "drain"); - assertRetainCount(1, idNSObject); - - Foundation.cfRelease(idNSObject); - } - - @Test - public void testAutoreleaseFactoryMethod() { - ID idPool = Foundation.sendReturnsID(Foundation.getClass("NSAutoreleasePool"), "new"); - assertRetainCount(1, idPool); - - ID idNSString = Foundation.sendReturnsID(Foundation.getClass("NSString"), "stringWithCString:", "kowabunga"); - assertRetainCount(1, idNSString); - - // retain so that draining the pool doesn't free - assertEquals(idNSString, Foundation.cfRetain(idNSString)); - assertRetainCount(2, idNSString); - - Foundation.sendReturnsVoid(idPool, "drain"); - assertRetainCount(1, idNSString); - - Foundation.cfRelease(idNSString); - } - - @Ignore - @Test - public void crashDoubleFreeing() { - ID idNSObject = Foundation.sendReturnsID(Foundation.getClass("NSObject"), "new"); - assertRetainCount(1, idNSObject); - - Foundation.cfRelease(idNSObject); - Foundation.cfRelease(idNSObject); // crash - } - - @Ignore - @Test - public void zombies() { - assertEquals("YES", System.getenv("NSZombiesEnabled")); - assertEquals("16", System.getenv("CFZombieLevel")); - - ID idNSObject = Foundation.sendReturnsID(Foundation.getClass("NSObject"), "new"); - assertRetainCount(1, idNSObject); - - Foundation.cfRelease(idNSObject); - Foundation.cfRelease(idNSObject); // crash, but with stderr logging - } - - @Test - public void nSStringSpecialCases() { - ID idEmptyNSString = Foundation.sendReturnsID(Foundation.getClass("NSString"), "alloc"); - assertRetainCount(-1, idEmptyNSString); // I guess that there is single empty string with infinite count - - ID idInitedNSString = Foundation.sendReturnsID(idEmptyNSString, "initWithCString:", "bananarama"); - assertThat(idInitedNSString, not(equalTo(idEmptyNSString))); - assertRetainCount(1, idInitedNSString); - } - - // Check that toll-free bridging applies to autorelease - @Test - public void autoReleaseWorksForCFString() { - ID idPool = Foundation.sendReturnsID(Foundation.getClass("NSAutoreleasePool"), "new"); - - ID cfStringRef = Foundation.cfString("awooga"); - assertRetainCount(1, cfStringRef); - - // retain so that draining the pool doesn't free - assertEquals(cfStringRef, Foundation.cfRetain(cfStringRef)); - assertRetainCount(2, cfStringRef); - - - Foundation.sendReturnsID(cfStringRef, "autorelease"); - assertRetainCount(2, cfStringRef); - - Foundation.sendReturnsVoid(idPool, "drain"); - assertRetainCount(1, cfStringRef); - } - -} diff --git a/rococoa/rococoa-core/src/test/java/org/rococoa/FoundationRetainReleaseTest.java b/rococoa/rococoa-core/src/test/java/org/rococoa/FoundationRetainReleaseTest.java deleted file mode 100644 index 3c824c38..00000000 --- a/rococoa/rococoa-core/src/test/java/org/rococoa/FoundationRetainReleaseTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa; - -import org.junit.Ignore; -import org.junit.Test; -import org.rococoa.cocoa.foundation.NSAutoreleasePool; -import org.rococoa.test.RococoaTestCase; - -import static org.junit.Assert.assertEquals; - -public class FoundationRetainReleaseTest extends RococoaTestCase { - - @Test - public void test() { - ID idOfString = Foundation.cfString("Hello world"); - assertRetainCount(1, idOfString); - - assertEquals(idOfString, Foundation.cfRetain(idOfString)); - assertRetainCount(2, idOfString); - - Foundation.cfRelease(idOfString); - assertRetainCount(1, idOfString); - - Foundation.cfRelease(idOfString); - // causes count to go to 0 and dispose will happen - } - - @Test - public void testAutorelease() { - NSAutoreleasePool pool = NSAutoreleasePool.new_(); - - ID idOfString = Foundation.cfString("Hello world"); - assertRetainCount(1, idOfString); - - Foundation.sendReturnsVoid(idOfString, "autorelease"); - assertRetainCount(1, idOfString); // autorelease does not increase the count - - Foundation.sendReturnsVoid(idOfString, "retain"); - assertRetainCount(2, idOfString); - - pool.drain(); - assertRetainCount(1, idOfString); - - Foundation.cfRelease(idOfString); - // causes count to go to 0 and dispose will happen - } - - @Test - public void testInitedObject() { - NSAutoreleasePool pool = NSAutoreleasePool.new_(); - - ID idOfClass = Foundation.getClass("NSString"); - ID idOfString = Foundation.sendReturnsID(idOfClass, "alloc"); - idOfString = Foundation.sendReturnsID(idOfString, "initWithCString:", "Hello world"); - assertRetainCount(-1, idOfString); - - // show that it wasn't in the pool - pool.drain(); - assertRetainCount(1, idOfString); - Foundation.cfRelease(idOfString); - } - -} diff --git a/rococoa/rococoa-core/src/test/java/org/rococoa/FoundationStructureReturnTest.java b/rococoa/rococoa-core/src/test/java/org/rococoa/FoundationStructureReturnTest.java deleted file mode 100644 index 3c97b288..00000000 --- a/rococoa/rococoa-core/src/test/java/org/rococoa/FoundationStructureReturnTest.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa; - -import com.sun.jna.Library; -import com.sun.jna.Native; -import org.junit.Test; -import org.rococoa.test.RococoaTestCase; - -import static org.junit.Assert.assertEquals; - -public class FoundationStructureReturnTest extends RococoaTestCase { - private interface StructLibrary extends Library { - TestStruct.ByValue createIntDoubleStruct(int a, double b); - - double addFieldsOfStructByValue(TestStruct.ByValue s); - - double addFieldsOfStructByValueVARARGS(int count, TestStruct.ByValue... objects); - } - - private StructLibrary library = Native.load("rococoa-test", StructLibrary.class); - - @Test - public void testStaticReceiveStructure() { - TestStruct.ByValue result = library.createIntDoubleStruct(42, Math.E); - assertEquals(42, result.anInt); - assertEquals(Math.E, result.aDouble, 0); - } - - @Test - public void testStaticPassStructure() { - TestStruct.ByValue arg = new TestStruct.ByValue(42, Math.PI); - double result = library.addFieldsOfStructByValue(arg); - assertEquals(42 + Math.PI, result, 0); - } - - @Test - public void testStaticPassStructureVARARGS() { - // demonstrate bug in JNA 3.0.3 - TestStruct.ByValue arg = new TestStruct.ByValue(42, Math.PI); - double result = library.addFieldsOfStructByValueVARARGS(1, arg); - assertEquals(42 + Math.PI, result, 0); - } - - @Test - public void testCallMethod() { - ID testID = Foundation.sendReturnsID(Foundation.getClass("TestShunt"), "new"); - Foundation.sendReturnsID(testID, "autorelease"); - Object[] args = {42, Math.E}; - TestStruct result = Foundation.send(testID, - Foundation.selector("testReturnStructByValue:and:"), - TestStruct.ByValue.class, args); - assertEquals(42, result.anInt); - assertEquals(Math.E, result.aDouble, 0); - } - - @Test - public void testAsPassStructAsArgument() { - ID testID = Foundation.sendReturnsID(Foundation.getClass("TestShunt"), "new"); - Foundation.sendReturnsID(testID, "autorelease"); - TestStruct.ByValue arg = new TestStruct.ByValue(42, Math.PI); - Object[] args = {arg}; - double result = Foundation.send(testID, - Foundation.selector("testAddFieldsOfStructByValue:"), - double.class, args); - assertEquals(42 + Math.PI, result, 0); - } - - @Test - public void testStructOfStruct() { - ID testID = Foundation.sendReturnsID(Foundation.getClass("TestShunt"), "new"); - Foundation.sendReturnsID(testID, "autorelease"); - Object[] args1 = {42, Math.E}; - TestStructOfStruct result = Foundation.send(testID, - Foundation.selector("testReturnStructOfStructByValue:and:"), - TestStructOfStruct.ByValue.class, args1); - assertEquals(Math.E, result.aDouble, 0); - assertEquals(42, result.aStruct.anInt); - assertEquals(Math.E, result.aStruct.aDouble, 0); - Object[] args = {result}; - - double result2 = Foundation.send(testID, - Foundation.selector("testPassStructOfStructByValue:"), - double.class, args); - assertEquals(Math.E, result2, 0); - } -} diff --git a/rococoa/rococoa-core/src/test/java/org/rococoa/FoundationTest.java b/rococoa/rococoa-core/src/test/java/org/rococoa/FoundationTest.java deleted file mode 100644 index 1f56b5f8..00000000 --- a/rococoa/rococoa-core/src/test/java/org/rococoa/FoundationTest.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa; - -import org.junit.Ignore; -import org.junit.Test; -import org.rococoa.test.RococoaTestCase; - -import static org.junit.Assert.*; - -public class FoundationTest extends RococoaTestCase { - - @Test - public void testCFString() { - ID string = Foundation.cfString("Hello World"); - assertNotNull(string); - assertEquals("Hello World", Foundation.toString(string)); - } - - @Test - public void testCFStringWithDifferentEncoding() throws Exception { - String stringWithOddChar = "Hello \u2648"; // Aries - ID string = Foundation.cfString(stringWithOddChar); - assertEquals(stringWithOddChar, Foundation.toString(string)); - } - - @SuppressWarnings("unused") - @Ignore("slow") - @Test - public void testStringPerformance() { - String stringWithOddChar = "Hello \u2648"; - StringBuilder longStringBuilder = new StringBuilder(); - for (int i = 0; i < 1000; i++) { - longStringBuilder.append(stringWithOddChar); - } - String longString = longStringBuilder.toString(); - ID string = Foundation.cfString(longString); - - for (int i = 0; i < 10000; i++) { - String s = Foundation.toStringViaUTF16(string); - } - } - - @Test - public void testInt() { - ID clas = Foundation.getClass("NSNumber"); - ID anInt = Foundation.sendReturnsID(clas, "numberWithInt:", 42); - int anIntValue = Foundation.send(anInt, "intValue", int.class); - assertEquals(42, anIntValue); - } - - @Test - public void testDouble() { - ID clas = Foundation.getClass("NSNumber"); - ID aDouble = Foundation.sendReturnsID(clas, "numberWithDouble:", Math.E); - Object[] args = {}; - double aDoubleValue = Foundation.send(aDouble, Foundation.selector("doubleValue"), double.class, args); - assertEquals(Math.E, aDoubleValue, 0.001); - } - - @Test - @Ignore - public void testFloat() { - ID clas = Foundation.getClass("NSNumber"); - ID aFloat = Foundation.sendReturnsID(clas, "numberWithFloat:", 5.485f); - Object[] args = {}; - float aFloatValue = Foundation.send(aFloat, Foundation.selector("floatValue"), float.class, args); - assertEquals(5.485f, aFloatValue, 0f); - } - - @Test - public void testSendNoArgs() { - ID clas = Foundation.getClass("NSDate"); - ID instance = Foundation.sendReturnsID(clas, "date"); - ID result = Foundation.sendReturnsID(instance, "description"); - assertTrue(Foundation.toString(result).startsWith("2")); // 2007-11-15 16:01:50 +0000 - } - - @Test - public void testSelector() { - Selector selector = Foundation.selector("selectorName:"); - assertTrue(selector.longValue() != 0); // selectors always exist - assertSame("selectorName:", selector.getName()); - - Selector noSuchSelector = Foundation.selector("noSelector:NamedThis:OrribleThing:"); - assertTrue(noSuchSelector.longValue() != 0); - assertSame("noSelector:NamedThis:OrribleThing:", noSuchSelector.getName()); - } - - @Test - public void sendMessageToNilIsOK() { - assertEquals(new ID(0), Foundation.sendReturnsID(new ID(0), "description")); - } - - // TODO - make work by wrapping call with native try- catch - @Ignore("to make work") - @Test - public void testInvokeUnknownSelector() { - Selector noSuchSelector = Foundation.selector("noSelector:NamedThis:OrribleThing:"); - assertTrue(noSuchSelector.longValue() != 0); - ID clas = Foundation.getClass("NSNumber"); - try { - Foundation.send(clas, noSuchSelector, int.class); - fail(); - } catch (NoSuchMethodError xpected) { - } - } -} diff --git a/rococoa/rococoa-core/src/test/java/org/rococoa/JavaProxyTest.java b/rococoa/rococoa-core/src/test/java/org/rococoa/JavaProxyTest.java deleted file mode 100644 index 8030d476..00000000 --- a/rococoa/rococoa-core/src/test/java/org/rococoa/JavaProxyTest.java +++ /dev/null @@ -1,289 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa; - -import com.sun.jna.NativeLong; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.rococoa.cocoa.foundation.*; -import org.rococoa.test.RococoaTestCase; - -import static org.junit.Assert.*; - - -public class JavaProxyTest extends RococoaTestCase { - - public static class JavaImplementor { - public Object arg; - - public void nothing() { - arg = null; - } - - public ID sayHello() { - return Foundation.cfString("Hello"); - } - - public ID testTakesIDReturnsID(ID id) { - arg = id; - return Foundation.cfString("Hello"); - } - - public NSObject takesNSObjectReturnsNSObject(NSObject s) { - arg = s; - return s; - } - - public void takesInt_AndInt(int a, int b) { - arg = new Object[]{a, b}; - } - - public byte takesStringReturnsByte(NSString s) { - arg = s; - return 42; - } - - public boolean takesBooleanReturnsBoolean(boolean b) { - arg = b; - return !b; - } - - public String takesJavaStringReturnsJavaString(String s) { - arg = s; - return s.toLowerCase(); - } - - public TestStruct takesStructureReturnsStructure(TestStruct s) { - arg = s; - return new TestStruct(s.anInt, s.aDouble); - } - - public TestStruct.ByValue takesStructureByValueReturnsStructureByValue(TestStruct.ByValue s) { - arg = s; - return new TestStruct.ByValue(s.anInt, s.aDouble); - } - - public NativeLong takesNativeLongReturnsNativeLong(NativeLong l) { - arg = l; - return l; - } - - public long takesLongReturnsLong(long l) { - arg = l; - return l; - } - - public double takesDoubleReturnsDouble(double d) { - arg = d; - return d; - } - - public void notify(NSNotification notification) { - this.arg = notification; - } - } - - private JavaImplementor implementor; - private NSObject proxy; - - @Before - public void setUp() throws Exception { - implementor = new JavaImplementor(); - proxy = Rococoa.proxy(implementor, NSObject.class); // hang onto this to prevent GC issues - } - - @Test - public void testRepondsToSelector() { - // respond to selector is required for delegates - assertEquals(0, (byte) Foundation.send(proxy.id(), "respondsToSelector:", - byte.class, new Selector[]{Foundation.selector("Bo")})); - assertEquals(1, (byte) Foundation.send(proxy.id(), "respondsToSelector:", - byte.class, new Selector[]{Foundation.selector("sayHello")})); - } - - @Test - public void testNoArgsReturnsVoid() { - implementor.arg = "something"; - ID result = Foundation.sendReturnsID(proxy.id(), "nothing"); - assertTrue(result.isNull()); - assertNull(implementor.arg); - } - - @Test - public void testNoArgsReturnsID() { - ID result = Foundation.sendReturnsID(proxy.id(), "sayHello"); - assertEquals("Hello", Foundation.toString(result)); - assertNull(implementor.arg); - } - - @Test - public void testTakesIDReturnsID() { - ID result = Foundation.sendReturnsID(proxy.id(), "testTakesIDReturnsID:", ID.fromLong(42)); - assertEquals("Hello", Foundation.toString(result)); - assertEquals(ID.fromLong(42), implementor.arg); - } - - @Test - public void testTakesNSObjectReturnsNSObject() { - ID result = Foundation.sendReturnsID(proxy.id(), "takesNSObjectReturnsNSObject:", - Foundation.cfString("hello")); - assertEquals("hello", Foundation.toString(result)); - assertEquals("hello", - Rococoa.cast((NSObject) implementor.arg, NSString.class).toString()); - // as parameter was NSObject, it lost its string-ness - } - - @Test - public void testTakesStringReturnsByte() { - byte result = Foundation.send(proxy.id(), "takesStringReturnsByte:", - byte.class, new Object[]{Foundation.cfString("hello")}); - assertEquals(42, result); - assertEquals("hello", ((NSString) implementor.arg).toString()); - } - - @Test - public void testTakesBooleanReturnsBoolean() { - assertTrue(Foundation.send(proxy.id(), "takesBooleanReturnsBoolean:", - boolean.class, new Object[]{false})); - assertFalse(Foundation.send(proxy.id(), "takesBooleanReturnsBoolean:", - boolean.class, new Object[]{true})); - } - - @Test - public void testTakesIntAndInt() { - ID result = Foundation.sendReturnsID(proxy.id(), "takesInt:AndInt:", - 42, -1); - assertTrue(result.isNull()); - Object[] arg = (Object[]) implementor.arg; - assertEquals(42, arg[0]); - assertEquals(-1, arg[1]); - } - - @Test - public void testTakesJavaStringReturnsJavaString() { - assertEquals("lower", Foundation.send(proxy.id(), "takesJavaStringReturnsJavaString:", - String.class, new String[]{"LoWeR"})); - } - - @Test - public void testSendAndReceiveStructByReference() { - TestStruct struct = new TestStruct(42, Math.PI); - TestStruct result = Foundation.send(proxy.id(), "takesStructureReturnsStructure:", - TestStruct.class, new TestStruct[]{struct}); - assertEquals("passing to java", 42, ((TestStruct) implementor.arg).anInt); - assertEquals("passing to java", Math.PI, ((TestStruct) implementor.arg).aDouble, 0.00001); - assertEquals("returning to OC", 42, result.anInt); - assertEquals("returning to OC", Math.PI, result.aDouble, 0.00001); - } - - @Test - public void testSendAndReceiveStructByValue() { - // Hmmm, difficult to prove this is passed by value - TestStruct.ByValue struct = new TestStruct.ByValue(42, Math.PI); - TestStruct result = Foundation.send(proxy.id(), "takesStructureByValueReturnsStructureByValue:", - TestStruct.ByValue.class, new TestStruct.ByValue[]{struct}); - assertEquals("passing to java", 42, ((TestStruct) implementor.arg).anInt); - assertEquals("passing to java", Math.PI, ((TestStruct) implementor.arg).aDouble, 0.00001); - assertEquals("returning to OC", 42, result.anInt); - assertEquals("returning to OC", Math.PI, result.aDouble, 0.00001); - } - - @Test - public void testSendAndReceiveNativeLong() { - NativeLong result = Foundation.send(proxy.id(), "takesNativeLongReturnsNativeLong:", - NativeLong.class, new NativeLong[]{new NativeLong(42)}); - assertEquals(42, result.longValue()); - } - - @Test - public void testSendAndReceiveLong() { - long result = Foundation.send(proxy.id(), "takesLongReturnsLong:", - long.class, new Integer[]{42}); - assertEquals(42, result); - - result = Foundation.send(proxy.id(), "takesLongReturnsLong:", - long.class, new Long[]{Long.MAX_VALUE}); - assertEquals(Long.MAX_VALUE, result); - } - - @Test - public void testSendAndReceiveDouble() { - double result = Foundation.send(proxy.id(), "takesDoubleReturnsDouble:", - double.class, new Double[]{Math.PI}); - assertEquals(Double.doubleToLongBits(Math.PI), Double.doubleToLongBits(result)); - - result = Foundation.send(proxy.id(), "takesDoubleReturnsDouble:", - double.class, new Double[]{Double.MAX_VALUE}); - assertEquals(Double.doubleToLongBits(Double.MAX_VALUE), Double.doubleToLongBits(result)); - } - - @Test - public void testMultipleCallbacks() { - // We managed to have static callback data, so that the last callback - // registered was always the one called! - // @see https://rococoa.dev.java.net/issues/show_bug.cgi?id=9 - JavaImplementor implementor2 = new JavaImplementor(); - ObjCObject proxy2 = Rococoa.proxy(implementor2); - - Foundation.sendReturnsVoid(proxy.id(), "testTakesIDReturnsID:", ID.fromLong(42)); - assertEquals(ID.fromLong(42), implementor.arg); - - Foundation.sendReturnsVoid(proxy2.id(), "testTakesIDReturnsID:", ID.fromLong(43)); - assertEquals(ID.fromLong(43), implementor2.arg); - } - - @Test - public void testNotifications() { - NSNotificationCenter notificationCentre = NSNotificationCenter.CLASS.defaultCenter(); - final ID observer = proxy.id(); - notificationCentre.addObserver_selector_name_object( - observer, - Foundation.selector("notify:"), - "MyNotification", - null); - - NSNotification notification = NSNotification.CLASS.notificationWithName_object("MyNotification", null); - - assertNull(implementor.arg); - notificationCentre.postNotification(notification); - assertEquals(notification, implementor.arg); - notificationCentre.removeObserver(observer); - } - - @Test - public void testMemoryManagement() { - // we were autorelease'ing the proxy - so that this failed - NSNotificationCenter notificationCentre = NSNotificationCenter.CLASS.defaultCenter(); - final ID observer = proxy.id(); - notificationCentre.addObserver_selector_name_object( - observer, - Foundation.selector("notify:"), - "MyNotification", - null); - pool.drain(); - pool = NSAutoreleasePool.new_(); - - NSNotification notification = NSNotification.CLASS.notificationWithName_object("MyNotification", null); - notificationCentre.postNotification(notification); - notificationCentre.removeObserver(observer); - } - -} diff --git a/rococoa/rococoa-core/src/test/java/org/rococoa/NSAutoreleasePoolTest.java b/rococoa/rococoa-core/src/test/java/org/rococoa/NSAutoreleasePoolTest.java deleted file mode 100644 index f6f5a8da..00000000 --- a/rococoa/rococoa-core/src/test/java/org/rococoa/NSAutoreleasePoolTest.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa; - -import org.junit.After; -import org.junit.Test; -import org.rococoa.cocoa.foundation.NSAutoreleasePool; -import org.rococoa.test.RococoaTestCase; - -/** - * NSAutoreleasePool's behaviour wrt retain counts is interesting. - *

- * Mike Swingler - "NSAutoreleasePools are magical, and are not actually - * allocated or released objects (though you get a point(er) to an id that does - * respond to selectors...but that's no different than an @"some string" constant." - *

- * This test documents the observed behaviour. - */ -public class NSAutoreleasePoolTest { - - private NSAutoreleasePool pool; - private ID idString; - - @Test - public void nothingAffectsReferenceCount() { - RococoaTestCase.assertRetainCount(1, pool); - pool.drain(); - RococoaTestCase.assertRetainCount(1, pool); - pool.release(); - RococoaTestCase.assertRetainCount(1, pool); - Foundation.cfRelease(pool.id()); - RococoaTestCase.assertRetainCount(1, pool); - } - - public NSAutoreleasePoolTest() { - idString = Foundation.cfString("test"); - pool = NSAutoreleasePool.new_(); - Foundation.cfRetain(idString); // keep from being deallocated - Foundation.sendReturnsID(idString, "autorelease"); - RococoaTestCase.assertRetainCount(2, idString); - } - - @After - public void tearDown() { - Foundation.cfRelease(idString); - } - - @Test - public void drainReleasesContents() { - pool.drain(); - RococoaTestCase.assertRetainCount(1, idString); - } - - @Test - public void releaseReleasesContents() { - pool.release(); - RococoaTestCase.assertRetainCount(1, idString); - } - - @Test - public void cfReleaseReleasesContents() { - Foundation.cfRelease(pool.id()); - RococoaTestCase.assertRetainCount(1, idString); - } - - @Test - public void drainOnAnotherThreadDoesntRelease() throws InterruptedException { - // If you are making Cocoa calls outside of the Application Kit’s main thread—for example - // if you create a Foundation-only application or if you detach a thread—you need to create - // your own autorelease pool. - Thread thread = new Thread("test") { - public void run() { - NSAutoreleasePool second = NSAutoreleasePool.new_(); - second.drain(); - } - }; - thread.start(); - thread.join(); - RococoaTestCase.assertRetainCount(2, idString); - } -} diff --git a/rococoa/rococoa-core/src/test/java/org/rococoa/NSAutoreleasePoolThreadTest.java b/rococoa/rococoa-core/src/test/java/org/rococoa/NSAutoreleasePoolThreadTest.java deleted file mode 100644 index 86218897..00000000 --- a/rococoa/rococoa-core/src/test/java/org/rococoa/NSAutoreleasePoolThreadTest.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa; - -import org.junit.Ignore; -import org.junit.Test; -import org.rococoa.cocoa.foundation.NSAutoreleasePool; -import org.rococoa.test.RococoaTestCase; - -import java.lang.ref.WeakReference; -import java.util.concurrent.CyclicBarrier; - -/** - * NSAutoreleasePool's behaviour wrt threads is interesting. It seems that if - * the thread that the pool was created on has finished, then draining the pool - * crashes. The tests here document the observed behaviour. - *

- * Our default policy is to release the pool's id in its finalizer - this is equivalent - * to draining it, and will fail if the finalizer is only run after the thread has - * exited. So we need a special case (currently in NSObjectInvocationHandler) to - * not release pools in their finalizer. - *

- * NB - not a RococoaTestCase so we know the state of the pools - * - * @author duncan - */ -public class NSAutoreleasePoolThreadTest { - - static { - RococoaTestCase.initializeLogging(); - } - - // This is the test that is made pass by marking NSAutoreleasePool as ReleaseInFinalize(false) - @Test - public void garbageCollectDrainedPool() throws InterruptedException { - Thread thread = new Thread("test") { - public void run() { - NSAutoreleasePool pool = NSAutoreleasePool.new_(); - pool.drain(); - } - }; - thread.start(); - thread.join(); - RococoaTestCase.gc(); - } - - - @Test - public void drainPoolAndFinalize() { - NSAutoreleasePool pool = NSAutoreleasePool.new_(); - pool.drain(); - WeakReference reference = new WeakReference(pool); - pool = null; - while (reference.get() != null) { - RococoaTestCase.gc(); - } - RococoaTestCase.gc(); - } - - @Test - public void drainPoolAndFinalizeOnAnotherThread() throws InterruptedException { - Thread thread = new Thread("test") { - public void run() { - drainPoolAndFinalize(); - } - }; - thread.start(); - thread.join(); - RococoaTestCase.gc(); - } - - @Ignore("crashes") - @Test - public void cantDrainPoolCreatedOnAFinishedThread() throws InterruptedException { - final NSAutoreleasePool[] poolHolder = new NSAutoreleasePool[1]; - Thread thread = new Thread("test") { - public void run() { - poolHolder[0] = NSAutoreleasePool.new_(); - } - }; - thread.start(); - thread.join(); - poolHolder[0].drain(); - } - - @Ignore("crashes") - @Test - public void drainPoolCreatedOnANotFinishedThread() throws InterruptedException { - final NSAutoreleasePool[] poolHolder = new NSAutoreleasePool[1]; - final CyclicBarrier beforeDrain = new CyclicBarrier(2); - final CyclicBarrier afterDrain = new CyclicBarrier(2); - Thread thread = new Thread("test") { - public void run() { - poolHolder[0] = NSAutoreleasePool.new_(); - await(beforeDrain); - await(afterDrain); - } - }; - thread.start(); - await(beforeDrain); - poolHolder[0].drain(); - await(afterDrain); - thread.join(); - } - - @Test - public void drainAlreadyDrainedPoolCreatedOnANotFinishedThread() throws InterruptedException { - final NSAutoreleasePool[] poolHolder = new NSAutoreleasePool[1]; - final CyclicBarrier beforeDrain = new CyclicBarrier(2); - final CyclicBarrier afterDrain = new CyclicBarrier(2); - Thread thread = new Thread("test") { - public void run() { - poolHolder[0] = NSAutoreleasePool.new_(); - poolHolder[0].drain(); - await(beforeDrain); - await(afterDrain); - } - }; - thread.start(); - await(beforeDrain); - poolHolder[0].drain(); - - await(afterDrain); - thread.join(); - } - - private void await(CyclicBarrier barrier) { - try { - barrier.await(); - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - } -} \ No newline at end of file diff --git a/rococoa/rococoa-core/src/test/java/org/rococoa/NSClassTest.java b/rococoa/rococoa-core/src/test/java/org/rococoa/NSClassTest.java deleted file mode 100644 index bf86cdcd..00000000 --- a/rococoa/rococoa-core/src/test/java/org/rococoa/NSClassTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa; - -import org.junit.Test; -import org.rococoa.cocoa.foundation.NSNumber; -import org.rococoa.test.RococoaTestCase; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -public class NSClassTest extends RococoaTestCase { - - @Test - public void test() { - NSNumber fortyTwo = NSNumber.CLASS.numberWithInt(42); - ID idOfNSNumber = Foundation.getClass("NSNumber"); - ID idOfNSString = Foundation.getClass("NSString"); - assertTrue(fortyTwo.isKindOfClass(idOfNSNumber)); - assertFalse(fortyTwo.isKindOfClass(idOfNSString)); - - assertTrue(fortyTwo.isKindOfClass(ObjCClass.CLASS.classWithName("NSNumber"))); - assertFalse(fortyTwo.isKindOfClass(ObjCClass.CLASS.classWithName("NSString"))); - } -} diff --git a/rococoa/rococoa-core/src/test/java/org/rococoa/RococoaAbstractClassTest.java b/rococoa/rococoa-core/src/test/java/org/rococoa/RococoaAbstractClassTest.java deleted file mode 100644 index cac7f84c..00000000 --- a/rococoa/rococoa-core/src/test/java/org/rococoa/RococoaAbstractClassTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; - -import org.junit.Test; -import org.rococoa.cocoa.foundation.NSObject; -import org.rococoa.test.RococoaTestCase; - - -public class RococoaAbstractClassTest extends RococoaTestCase { - - public static abstract class NSNumberAsClass extends NSObject { - - public static final _Class CLASS = Rococoa.createClass("NSNumber", _Class.class); //$NON-NLS-1$ - - public interface _Class extends ObjCClass { - NSNumberAsClass numberWithInt(int value); - } - - public static NSNumberAsClass numberWithInt(int value) { - return CLASS.numberWithInt(value); - } - - public abstract int intValue(); - - public int twice() { - return 2 * intValue(); - } - - } - - @Test - public void test() { - NSNumberAsClass number = NSNumberAsClass.numberWithInt(42); - assertEquals(42, number.intValue()); - assertEquals(84, number.twice()); - } - - @Test - public void testByteBuddyReusesClasses() { - NSNumberAsClass number = NSNumberAsClass.numberWithInt(42); - NSNumberAsClass number2 = NSNumberAsClass.numberWithInt(42); - assertSame(number.getClass(), number2.getClass()); - } - -} diff --git a/rococoa/rococoa-core/src/test/java/org/rococoa/RococoaMainThreadTest.java b/rococoa/rococoa-core/src/test/java/org/rococoa/RococoaMainThreadTest.java deleted file mode 100644 index 284d9094..00000000 --- a/rococoa/rococoa-core/src/test/java/org/rococoa/RococoaMainThreadTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.rococoa.test.RococoaTestCase; - -public class RococoaMainThreadTest extends RococoaTestCase { - private interface TestShunt extends ObjCObject { - boolean isMainThread(); - }; - - private @RunOnMainThread interface TestShuntOnMainThread extends TestShunt {}; - - @Test public void testNotMainThreadAtClassLevel() { - TestShunt testShunt = Rococoa.create("TestShunt", TestShunt.class); - assertFalse(testShunt.isMainThread()); - } - - @Test public void testOnMainThreadAtClassLevel() { - TestShunt testShunt = Rococoa.create("TestShunt", TestShuntOnMainThread.class); - assertTrue(testShunt.isMainThread()); - - } - - @Test public void testNotMainThreadAtMethodLevel() { - TestShunt testShunt = Rococoa.create("TestShunt", TestShuntUnAnnotatedMethod.class); - assertFalse(testShunt.isMainThread()); - } - - @Test public void testOnMainThreadAtMethodLevel() { - TestShunt testShunt = Rococoa.create("TestShunt", TestShuntAnnotatedMethod.class); - assertTrue(testShunt.isMainThread()); - - } - - private interface TestShuntAnnotatedMethod extends TestShunt { - @RunOnMainThread - boolean isMainThread(); - } - - private interface TestShuntUnAnnotatedMethod extends TestShunt { - boolean isMainThread(); - } -} diff --git a/rococoa/rococoa-core/src/test/java/org/rococoa/RococoaObjectOwnershipTest.java b/rococoa/rococoa-core/src/test/java/org/rococoa/RococoaObjectOwnershipTest.java deleted file mode 100644 index 2f4258db..00000000 --- a/rococoa/rococoa-core/src/test/java/org/rococoa/RococoaObjectOwnershipTest.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa; - -import org.junit.Test; -import org.rococoa.cocoa.foundation.*; -import org.rococoa.test.RococoaTestCase; - -import java.lang.ref.WeakReference; - -import static org.junit.Assert.assertSame; - -public class RococoaObjectOwnershipTest extends RococoaTestCase { - - public static boolean shouldBeInPool = true; - public static boolean shouldNotBeInPool = false; - - @Test - public void directFactoryMethodsReturnsYieldsPooledObject() throws Exception { - check(shouldBeInPool, - new Factory() { - public NSArray create() throws Exception { - return Rococoa.create("NSArray", NSArray.class, - NSArray._Class.class.getMethod("arrayWithObjects", NSObject[].class), - "arrayWithObjects:", NSNumber.CLASS.numberWithInt(0)); - } - }); - check(shouldBeInPool, - new Factory() { - public NSArray create() throws Exception { - return Rococoa.create("NSArray", NSArray.class, - "arrayWithObject:", NSNumber.CLASS.numberWithInt(0)); - } - }); - } - - @Test - public void factoryMethodOnClassYieldsPooledObject() throws Exception { - check(shouldBeInPool, - new Factory() { - public NSArray create() { - return NSArray.CLASS.arrayWithObjects(NSNumber.CLASS.numberWithInt(0)); - } - }); - } - - @Test - public void createYieldsNonPooledObject() throws Exception { - check(shouldNotBeInPool, - new Factory() { - public NSDate create() { - return Rococoa.create("NSDate", NSDate.class); - } - }); - } - - @Test - public void newYieldsNonPooledObject() throws Exception { - // calling new on an NSClass results in a NOT autorelease'd object - check(shouldNotBeInPool, - new Factory() { - public NSArray create() { - return Rococoa.create("NSArray", NSArray.class, "new"); - } - }); - } - - @Test - public void allocYieldsNonPooledObject() throws Exception { - // calling alloc on an NSClass results in a NOT autorelease'd object - check(shouldNotBeInPool, - new Factory() { - public NSObject create() { - // NSArray.alloc fails as it is an Umbrella class - return Rococoa.create("NSObject", NSObject.class, "alloc"); - } - }); - } - - private interface Factory { - NSObject create() throws Exception; - } - - private void check(boolean expectedAutorelease, Factory factory) throws Exception { - int expectedInitialRetainCount = expectedAutorelease ? 2 : 1; - // that will decrease the count IF it was pooled - int expectedFinalRetainCount = expectedAutorelease ? - expectedInitialRetainCount - 1 : expectedInitialRetainCount; - - NSAutoreleasePool pool = NSAutoreleasePool.new_(); - - NSObject object = factory.create(); - assertRetainCount(expectedInitialRetainCount, object); - - // aliasing should increase the retain count, as the alias also owns it - NSObject alias = Rococoa.cast(object, NSObject.class); - assertSame(object.id(), alias.id()); - assertRetainCount(expectedInitialRetainCount + 1, object); - assertRetainCount(expectedInitialRetainCount + 1, alias); - - // wait until object has been GC'd - WeakReference reference = new WeakReference(object); - object = null; - while (reference.get() != null) { - gc(); - } - gc(); - - // it should now have been release'd - assertRetainCount(expectedInitialRetainCount, alias); - - // now let the pool go - pool.drain(); - - assertRetainCount(expectedFinalRetainCount, alias); - } - -} diff --git a/rococoa/rococoa-core/src/test/java/org/rococoa/RococoaTest.java b/rococoa/rococoa-core/src/test/java/org/rococoa/RococoaTest.java deleted file mode 100644 index 894f2562..00000000 --- a/rococoa/rococoa-core/src/test/java/org/rococoa/RococoaTest.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa; - -import org.junit.Test; -import org.rococoa.cocoa.foundation.*; -import org.rococoa.test.RococoaTestCase; - -import static org.junit.Assert.*; - -public class RococoaTest extends RococoaTestCase { - - @Test - public void testCreate() { - NSNumber fortyTwo = NSNumber.CLASS.numberWithInt(42); - assertEquals(42, fortyTwo.intValue()); - } - - @Test - public void testEqualsWithAliases() { - NSNumber fortyTwo = NSNumber.CLASS.numberWithInt(42); - NSNumber fortyTwoAlias = Rococoa.wrap(fortyTwo.id(), NSNumber.class); - NSNumber fortyThree = NSNumber.CLASS.numberWithInt(43); - assertEquals(fortyTwo, fortyTwoAlias); - assertEquals(fortyTwoAlias, fortyTwo); - assertNotEquals(fortyTwo, fortyThree); - assertNotEquals(null, fortyTwo); - } - - @Test - public void testEqualsMapsToIsEqual() { - NSString s1 = NSString.stringWithString("string"); - NSString s2 = NSString.stringWithString("STRING").lowercaseString(); - assertNotSame(s1, s2); - assertNotEquals(s1.id(), s2.id()); - assertEquals(s1, s2); - } - - @Test - public void testReturnTypes() { - NSNumber e = NSNumber.CLASS.numberWithDouble(Math.E); - assertEquals(2, e.intValue()); - assertEquals(2, e.longValue()); - assertEquals((float) Math.E, e.floatValue(), 0.001); - assertEquals(Math.E, e.doubleValue(), 0.001); - } - - @Test - public void testPassOCObject() { - NSNumber fortyTwo = NSNumber.CLASS.numberWithInt(42); - NSNumber e = NSNumber.CLASS.numberWithDouble(Math.E); - - assertEquals(-1, e.compare(fortyTwo)); - assertEquals(0, e.compare(e)); - assertEquals(1, fortyTwo.compare(e)); - } - - @Test - public void testStringMarshalling() { - NSString string = NSString.CLASS.stringWithString("Hello world"); - assertTrue(string.isEqualToString("Hello world")); - assertFalse(string.isEqualToString("Hello worldy")); - } - - @Test - public void testKeywordMethod() { - // TODO - this method doesn't actually test keyword methods any more - NSDate epoc = NSDate.CLASS.dateWithTimeIntervalSince1970(0); - assertEquals(0, epoc.timeIntervalSince1970(), 0.000001f); - NSDate anotherDate = NSDate.CLASS.dateWithTimeIntervalSince1970(40d); - assertEquals(40, anotherDate.timeIntervalSince1970(), 0.000001f); - } - - @Test - public void testVarags() { - NSArray array = NSArray.CLASS.arrayWithObjects( - NSNumber.CLASS.numberWithBool(true), - NSNumber.CLASS.numberWithInt(42), - NSDate.CLASS.dateWithTimeIntervalSince1970(666) - ); - assertNotNull(array); - assertFalse(array.id().isNull()); - assertEquals(3, array.count()); - } - - @Test - public void testFactory() { - NSNumber._Class nsNumberClass = Rococoa.createClass("NSNumber", NSNumber._Class.class); //$NON-NLS-1$ - assertEquals(nsNumberClass.id(), Foundation.getClass("NSNumber")); - } - - public interface OddClass extends ObjCClass { - NSObject numberWithInt(int value); - } - - @Test - public void testDownCast() { - // this is OK - NSNumber numberAsObject = NSNumber.CLASS.numberWithInt(42); - assertEquals(42, numberAsObject.intValue()); - - // but when defined return type is NSObject, we can't cast Java objects - OddClass nsClass = Rococoa.createClass("NSNumber", OddClass.class); - NSObject returnAsObject = nsClass.numberWithInt(42); - try { - ((NSNumber) returnAsObject).intValue(); - fail(); - } catch (ClassCastException expected) { - } - - // we need to do this - assertEquals(42, Rococoa.cast(returnAsObject, NSNumber.class).intValue()); - } - - @Test - public void testToString() { - NSNumber fortyTwo = NSNumber.CLASS.numberWithInt(42); - assertEquals("42", fortyTwo.toString()); - } - - @Test - public void testGeneratedClassName() { - NSString string = NSString.stringWithString("Hello World"); - Class stringClass = string.getClass(); - assertEquals(NSString.class.getPackage().getName(), stringClass.getPackage().getName()); - assertEquals("NSString$$ByRococoa", stringClass.getSimpleName()); - } - -} diff --git a/rococoa/rococoa-core/src/test/java/org/rococoa/StructsInObjectsTest.java b/rococoa/rococoa-core/src/test/java/org/rococoa/StructsInObjectsTest.java deleted file mode 100644 index 75773f95..00000000 --- a/rococoa/rococoa-core/src/test/java/org/rococoa/StructsInObjectsTest.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa; - -import org.junit.Test; -import org.rococoa.cocoa.foundation.NSSize; -import org.rococoa.cocoa.foundation.NSValue; -import org.rococoa.test.RococoaTestCase; - -import static org.junit.Assert.assertEquals; - -/** - * Checks that we can embed a struct by value in a object. - */ -public class StructsInObjectsTest extends RococoaTestCase { - - @Test - public void test() throws Exception { - NSSize aSize = new NSSize(1f, 3f); - NSValue value = NSValue.CLASS.valueWithSize(aSize); - - - Foundation.send(value.id(), Foundation.selector("sizeValue"), NSSize.class); - NSSize size = value.sizeValue(); - // fails here with jna 3.0.6+ in Java 1.5, see StaticStructureReturnTest - - assertEquals(1.0, size.width.doubleValue(), 0.0001); - assertEquals(3.0, size.height.doubleValue(), 0.0001); - } -} diff --git a/rococoa/rococoa-core/src/test/java/org/rococoa/TestStruct.java b/rococoa/rococoa-core/src/test/java/org/rococoa/TestStruct.java deleted file mode 100644 index 22797d80..00000000 --- a/rococoa/rococoa-core/src/test/java/org/rococoa/TestStruct.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa; - -import com.sun.jna.Structure; - -import java.util.Arrays; -import java.util.List; - -public class TestStruct extends Structure { - public int anInt; - public double aDouble; - - public TestStruct() { - this(0, 0); - } - - public TestStruct(int anInt, double aDouble) { - this.anInt = anInt; - this.aDouble = aDouble; - } - - public static class ByValue extends TestStruct implements Structure.ByValue { - public ByValue() { - this(0, 0); - } - - public ByValue(int anInt, double aDouble) { - super(anInt, aDouble); - } - } - - - @Override - protected List getFieldOrder() { - return Arrays.asList("anInt", "aDouble"); - } -} \ No newline at end of file diff --git a/rococoa/rococoa-core/src/test/java/org/rococoa/TestStructOfStruct.java b/rococoa/rococoa-core/src/test/java/org/rococoa/TestStructOfStruct.java deleted file mode 100644 index 9b8448ed..00000000 --- a/rococoa/rococoa-core/src/test/java/org/rococoa/TestStructOfStruct.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa; - -import com.sun.jna.Structure; - -import java.util.Arrays; -import java.util.List; - -public class TestStructOfStruct extends Structure { - public double aDouble; - public TestStruct.ByValue aStruct; - - public static class ByValue extends TestStructOfStruct implements Structure.ByValue { - public ByValue() { - } - - public ByValue(int anInt, double aDouble) { - this.aDouble = aDouble; - this.aStruct = new TestStruct.ByValue(anInt, aDouble); - } - } - - @Override - protected List getFieldOrder() { - return Arrays.asList("aDouble", "aStruct"); - } -} \ No newline at end of file diff --git a/rococoa/rococoa-core/src/test/java/org/rococoa/cocoa/NSArrayTest.java b/rococoa/rococoa-core/src/test/java/org/rococoa/cocoa/NSArrayTest.java deleted file mode 100644 index fc4c36d1..00000000 --- a/rococoa/rococoa-core/src/test/java/org/rococoa/cocoa/NSArrayTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa; - -import org.junit.Test; -import org.rococoa.Rococoa; -import org.rococoa.cocoa.foundation.NSArray; -import org.rococoa.cocoa.foundation.NSNumber; -import org.rococoa.test.RococoaTestCase; - -import static org.junit.Assert.assertEquals; - -public class NSArrayTest extends RococoaTestCase { - - @Test - public void test() { - NSArray array = NSArray.CLASS.arrayWithObjects( - NSNumber.CLASS.numberWithInt(42), - NSNumber.CLASS.numberWithInt(64) - ); - assertEquals(2, array.count()); - NSNumber first = Rococoa.cast(array.objectAtIndex(0), NSNumber.class); - assertEquals(42, first.intValue()); - NSNumber second = Rococoa.cast(array.objectAtIndex(1), NSNumber.class); - assertEquals(64, second.intValue()); - } -} diff --git a/rococoa/rococoa-core/src/test/java/org/rococoa/cocoa/NSDataTest.java b/rococoa/rococoa-core/src/test/java/org/rococoa/cocoa/NSDataTest.java deleted file mode 100644 index ad2bc10c..00000000 --- a/rococoa/rococoa-core/src/test/java/org/rococoa/cocoa/NSDataTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa; - -import org.junit.Test; -import org.rococoa.cocoa.foundation.NSData; -import org.rococoa.cocoa.foundation.NSUInteger; -import org.rococoa.test.RococoaTestCase; - -import static org.junit.Assert.assertEquals; - -public class NSDataTest extends RococoaTestCase { - - @Test - public void testInitWithBytes() throws Exception { - byte[] bytes = "Hello".getBytes(); - - NSData data = NSData.CLASS.dataWithBytes_length(bytes, bytes.length); - assertEquals(bytes.length, data.length()); - - byte[] resultBytes = new byte[bytes.length]; - data.getBytes(resultBytes); - assertEquals("Hello", new String(resultBytes)); - } -} diff --git a/rococoa/rococoa-core/src/test/java/org/rococoa/cocoa/NSDictionaryTest.java b/rococoa/rococoa-core/src/test/java/org/rococoa/cocoa/NSDictionaryTest.java deleted file mode 100644 index 5b39c259..00000000 --- a/rococoa/rococoa-core/src/test/java/org/rococoa/cocoa/NSDictionaryTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa; - -import org.junit.Test; -import org.rococoa.Rococoa; -import org.rococoa.cocoa.foundation.*; -import org.rococoa.test.RococoaTestCase; - -import static org.junit.Assert.assertEquals; - -public class NSDictionaryTest extends RococoaTestCase { - - @Test - public void testDictionaryWithObjects_forKeys() { - NSArray objects = NSArray.CLASS.arrayWithObjects( - NSString.stringWithString("string value"), - NSNumber.CLASS.numberWithInt(42)); - NSArray keys = NSArray.CLASS.arrayWithObjects( - NSString.stringWithString("string key"), - NSString.stringWithString("int key")); - NSDictionary dictionary = NSDictionary.dictionaryWithObjects_forKeys(objects, keys); - - check(dictionary); - } - - @Test - public void testDictionaryWithObjectsAndKeys() { - NSDictionary dictionary = NSDictionary.dictionaryWithObjectsAndKeys( - NSString.stringWithString("string value"), NSString.stringWithString("string key"), - NSNumber.CLASS.numberWithInt(42), NSString.stringWithString("int key"), null); - - check(dictionary); - } - - @Test - public void testMutableDictionary() { - NSMutableDictionary dictionary = NSMutableDictionary.dictionaryWithCapacity(5); - assertEquals(0, dictionary.count()); - - dictionary.setValue_forKey( - NSString.stringWithString("string value"), NSString.stringWithString("string key")); - dictionary.setValue_forKey( - NSNumber.CLASS.numberWithInt(42), "int key"); - - check(dictionary); - } - - private void check(NSDictionary dictionary) { - assertEquals(2, dictionary.count()); - - NSString value = Rococoa.cast( - dictionary.objectForKey(NSString.stringWithString("string key")), - NSString.class); - assertEquals("string value", value.toString()); - - NSNumber value2 = Rococoa.cast( - dictionary.objectForKey("int key"), - NSNumber.class); - assertEquals(42, value2.intValue()); - } -} diff --git a/rococoa/rococoa-core/src/test/java/org/rococoa/cocoa/NSIndexSetTest.java b/rococoa/rococoa-core/src/test/java/org/rococoa/cocoa/NSIndexSetTest.java deleted file mode 100644 index b6a01264..00000000 --- a/rococoa/rococoa-core/src/test/java/org/rococoa/cocoa/NSIndexSetTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa; - -import org.junit.Test; -import org.rococoa.cocoa.foundation.NSMutableIndexSet; -import org.rococoa.cocoa.foundation.NSUInteger; -import org.rococoa.test.RococoaTestCase; - -import static org.junit.Assert.*; - -/** - * @author David Kocher - * @version $Id:$ - */ -public class NSIndexSetTest extends RococoaTestCase { - - @Test - public void testIndexWithRange() { - NSMutableIndexSet index = NSMutableIndexSet.new_(); - index.addIndex(new NSUInteger(1)); - index.addIndex(new NSUInteger(2)); - assertEquals(new NSUInteger(2), index.count()); - assertFalse(index.containsIndex(new NSUInteger(0))); - assertTrue(index.containsIndex(new NSUInteger(1))); - assertTrue(index.containsIndex(new NSUInteger(2))); - assertFalse(index.containsIndex(new NSUInteger(3))); - } - - @Test - public void testIndexWithDoubleRange() { - NSMutableIndexSet index = NSMutableIndexSet.new_(); - index.addIndex(new NSUInteger(1)); - index.addIndex(new NSUInteger(2)); - index.addIndex(new NSUInteger(4)); - index.addIndex(new NSUInteger(5)); - assertEquals(new NSUInteger(4), index.count()); - assertFalse(index.containsIndex(new NSUInteger(0))); - assertTrue(index.containsIndex(new NSUInteger(1))); - assertTrue(index.containsIndex(new NSUInteger(2))); - assertFalse(index.containsIndex(new NSUInteger(3))); - assertTrue(index.containsIndex(new NSUInteger(4))); - assertTrue(index.containsIndex(new NSUInteger(5))); - } -} diff --git a/rococoa/rococoa-core/src/test/java/org/rococoa/cocoa/NSMutableArrayTest.java b/rococoa/rococoa-core/src/test/java/org/rococoa/cocoa/NSMutableArrayTest.java deleted file mode 100644 index c05bda98..00000000 --- a/rococoa/rococoa-core/src/test/java/org/rococoa/cocoa/NSMutableArrayTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.cocoa; - -import org.junit.Test; -import org.rococoa.Rococoa; -import org.rococoa.cocoa.foundation.NSMutableArray; -import org.rococoa.cocoa.foundation.NSObject; -import org.rococoa.cocoa.foundation.NSString; -import org.rococoa.test.RococoaTestCase; - -import static org.junit.Assert.assertEquals; - -public class NSMutableArrayTest extends RococoaTestCase { - - @Test - public void test() { - NSMutableArray array = NSMutableArray.CLASS.arrayWithCapacity(3); - assertEquals(0, array.count()); - array.addObject(NSString.stringWithString("Hello")); - array.addObject("Goodbye"); - assertEquals(2, array.count()); - assertEquals("(\n Hello,\n Goodbye\n)", array.description()); - - NSObject first = array.objectAtIndex(0); - assertEquals(NSString.stringWithString("Hello"), first); - - NSString firstAsString = Rococoa.cast(first, NSString.class); - assertEquals("Hello", firstAsString.toString()); - assertEquals("Goodbye", - Rococoa.cast(array.objectAtIndex(1), NSString.class).toString()); - } -} diff --git a/rococoa/rococoa-core/src/test/java/org/rococoa/internal/AutoreleaseBatcherTest.java b/rococoa/rococoa-core/src/test/java/org/rococoa/internal/AutoreleaseBatcherTest.java deleted file mode 100644 index 522c108b..00000000 --- a/rococoa/rococoa-core/src/test/java/org/rococoa/internal/AutoreleaseBatcherTest.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.internal; - -import org.junit.Test; -import org.rococoa.Foundation; -import org.rococoa.ID; -import org.rococoa.test.RococoaTestCase; - -import static org.junit.Assert.assertNull; -import static org.rococoa.test.RococoaTestCase.assertRetainCount; - - -public class AutoreleaseBatcherTest { - static { - RococoaTestCase.initializeLogging(); - } - - private Throwable thrown; - - @Test - public void drains() { - AutoreleaseBatcher batcher = new AutoreleaseBatcher(1); - ID idNSObject = Foundation.cfRetain(autoreleasedObject()); - assertRetainCount(2, idNSObject); - - batcher.operate(); - assertRetainCount(1, idNSObject); - } - - @Test - public void batches() { - AutoreleaseBatcher batcher = new AutoreleaseBatcher(2); - ID idNSObject = Foundation.cfRetain(autoreleasedObject()); - assertRetainCount(2, idNSObject); - - batcher.operate(); - assertRetainCount(2, idNSObject); - - batcher.operate(); - assertRetainCount(1, idNSObject); - } - - @Test - public void resets() { - AutoreleaseBatcher batcher = new AutoreleaseBatcher(1); - - ID idNSObject1 = Foundation.cfRetain(autoreleasedObject()); - assertRetainCount(2, idNSObject1); - batcher.operate(); - assertRetainCount(1, idNSObject1); - - ID idNSObject2 = Foundation.cfRetain(autoreleasedObject()); - assertRetainCount(2, idNSObject2); - batcher.operate(); - assertRetainCount(1, idNSObject2); - } - - @Test - public void threadLocal() { - AutoreleaseBatcher.forThread(1); - ID idNSObject = Foundation.cfRetain(autoreleasedObject()); - assertRetainCount(2, idNSObject); - - AutoreleaseBatcher.forThread(1).operate(); - assertRetainCount(1, idNSObject); - } - - @Test - public void threadLocal2Threads() throws InterruptedException { - AutoreleaseBatcher.forThread(1); - ID idNSObject = Foundation.cfRetain(autoreleasedObject()); - assertRetainCount(2, idNSObject); - - Thread thread = new Thread() { - public void run() { - try { - AutoreleaseBatcher.forThread(1); - ID idNSObject = Foundation.cfRetain(autoreleasedObject()); - assertRetainCount(2, idNSObject); - - AutoreleaseBatcher.forThread(1).operate(); - assertRetainCount(1, idNSObject); - } catch (Throwable t) { - thrown = t; - } - } - }; - thread.run(); - thread.join(); - - AutoreleaseBatcher.forThread(1).operate(); - assertRetainCount(1, idNSObject); - assertNull(thrown); - } - - private ID autoreleasedObject() { - ID idNSObject = Foundation.sendReturnsID(Foundation.getClass("NSObject"), "new"); - return Foundation.sendReturnsID(idNSObject, "autorelease"); - - } -} diff --git a/rococoa/rococoa-core/src/test/java/org/rococoa/internal/BoolTest.java b/rococoa/rococoa-core/src/test/java/org/rococoa/internal/BoolTest.java deleted file mode 100644 index 82edb417..00000000 --- a/rococoa/rococoa-core/src/test/java/org/rococoa/internal/BoolTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2007-2010 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.internal; - -import org.junit.Test; -import org.rococoa.ObjCObject; -import org.rococoa.Rococoa; -import org.rococoa.test.RococoaTestCase; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - - -public class BoolTest extends RococoaTestCase { - - private interface TestShunt extends ObjCObject { - boolean valueIsYES(boolean a); - - boolean valueIsNO(boolean a); - } - - private TestShunt testShunt = Rococoa.create("TestShunt", TestShunt.class); - - @Test - public void test() { - assertTrue(testShunt.valueIsYES(true)); - assertFalse(testShunt.valueIsYES(false)); - assertTrue(testShunt.valueIsNO(false)); - assertFalse(testShunt.valueIsNO(true)); - } - -} diff --git a/rococoa/rococoa-core/src/test/java/org/rococoa/internal/NSInvocationMapperTest.java b/rococoa/rococoa-core/src/test/java/org/rococoa/internal/NSInvocationMapperTest.java deleted file mode 100644 index 608a160e..00000000 --- a/rococoa/rococoa-core/src/test/java/org/rococoa/internal/NSInvocationMapperTest.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.internal; - -import com.sun.jna.Native; -import com.sun.jna.NativeLong; -import org.junit.Test; -import org.rococoa.cocoa.CGFloat; -import org.rococoa.cocoa.foundation.NSInteger; -import org.rococoa.cocoa.foundation.NSUInteger; - -import static org.junit.Assert.assertEquals; - -public class NSInvocationMapperTest { - - @Test - public void testEncoding32() throws Exception { - if (Native.LONG_SIZE != 4) - return; - - /* These from calling @encode - bool: B - BOOL: c - char: c - signed char: c - unsigned char: C - signed short: s - unsigned short: S - signed int: i - unsigned int: I - signed long: l - unsigned long: L - signed long long: q - unsigned long long: Q - NSInteger: i - NSUInteger: I - CGFloat: f - float: f - double: d - long double: d - */ - check("c", boolean.class); - check("c", byte.class); - check("s", char.class); - check("s", short.class); - check("i", int.class); - check("q", long.class); - check("i", NSInteger.class); - check("I", NSUInteger.class); - check("l", NativeLong.class); - check("f", CGFloat.class); - check("f", float.class); - check("d", double.class); - } - - @Test - public void testEncoding64() throws Exception { - if (Native.LONG_SIZE == 4) - return; - - /* These from calling @encode - bool: B - BOOL: c - char: c - signed char: c - unsigned char: C - signed short: s - unsigned short: S - signed int: i - unsigned int: I - signed long: q - unsigned long: Q - signed long long: q - unsigned long long: Q - NSInteger: q - NSUInteger: Q - CGFloat: d - float: f - double: d - long double: d - */ - check("c", boolean.class); - check("c", byte.class); - check("s", char.class); - check("s", short.class); - check("i", int.class); - check("q", long.class); - check("q", NSInteger.class); - check("Q", NSUInteger.class); - check("q", NativeLong.class); - check("d", CGFloat.class); - check("f", float.class); - check("d", double.class); - } - - private void check(String expected, Class javaType) { - assertEquals(javaType.toString(), expected, NSInvocationMapperLookup.stringForType(javaType)); - } -} diff --git a/rococoa/rococoa-core/src/test/java/org/rococoa/internal/NSObjectInvocationHandlerTest.java b/rococoa/rococoa-core/src/test/java/org/rococoa/internal/NSObjectInvocationHandlerTest.java deleted file mode 100644 index a9734166..00000000 --- a/rococoa/rococoa-core/src/test/java/org/rococoa/internal/NSObjectInvocationHandlerTest.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.internal; - -import org.junit.Test; -import org.rococoa.ID; -import org.rococoa.cocoa.foundation.NSData; -import org.rococoa.cocoa.foundation.NSDictionary; -import org.rococoa.cocoa.foundation.NSObject; -import org.rococoa.cocoa.foundation.NSString; -import org.rococoa.test.RococoaTestCase; - -import java.lang.ref.WeakReference; - -import static org.junit.Assert.*; - -/** - * @version $Id$ - */ -public class NSObjectInvocationHandlerTest extends RococoaTestCase { - - public static abstract class NSImage extends NSObject { - private static final _Class CLASS = org.rococoa.Rococoa.createClass("NSImage", _Class.class); - - public interface _Class extends org.rococoa.ObjCClass { - NSImage alloc(); - } - - public abstract NSImage initWithData(NSData data); - } - - /** - * We test for the case when the init method is not able to complete the initialization - * In such a case,, the init... method could free the receiver and return nil, indicating that - * the requested object can’t be created. - *

- * Therefore, Rococoa should not release such instances. - *

- * Example: - * NSImage *img = [NSImage alloc]; - * This instance can be released using [img release] - * [img initWithData:nil]; - * The following would lead to a crash because the initializer above fails - * [img release]; - *

- * NSObjectInvocationHandler therefore must make sure to not release an - * object on finalization when there was an error in initialization and the receiver - * is already freed according to the recommendation in the documentation. - *

- * Summary: If nil is returned from a initializer, one must assume the object is already released - * - * @see org.rococoa.internal.ObjCObjectInvocationHandler#invokeCocoa(java.lang.reflect.Method, Object[]) - * @see "http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocAllocInit.html#//apple_ref/doc/uid/TP30001163-CH22-105952" - */ - @Test - public void testInitReturnsNil() { - NSImage image = NSImage.CLASS.alloc(); - assertNotNull("Allocation must return valid reference", image); - - NSImage failedInitializedImage = image.initWithData(null); - assertNull("Expected init to fail and return nil", failedInitializedImage); - assertTrue("Initial image should now be invalid too", image.id().isNull()); - // TODO - I'm a little unsure about whether this is the best course - - // We shall not crash after garbage collection when the NSObjectInvocationHandler is finalized - WeakReference reference = new WeakReference(failedInitializedImage); - failedInitializedImage = null; - while (reference.get() != null) { - gc(); - } - } - - @Test - public void testNilReturnValues() { - NSDictionary dict = NSDictionary.dictionaryWithObjectsAndKeys( - NSString.stringWithString("Value"), NSString.stringWithString("Key") - ); - ID id = dict.objectForKey((ID) null); - assertNull(id); - NSObject nsObject = dict.objectForKey((NSObject) null); - assertNull(nsObject); - } - - @Test - public void testReturnValues() { - NSDictionary dict = NSDictionary.dictionaryWithObjectsAndKeys( - NSString.stringWithString("Value"), NSString.stringWithString("Key") - ); - ID id = dict.objectForKey(NSString.stringWithString("Key").id()); - assertNotNull(id); - NSObject nsObject = dict.objectForKey(NSString.stringWithString("Key")); - assertNotNull(nsObject); - } -} diff --git a/rococoa/rococoa-core/src/test/java/org/rococoa/internal/OCInvocationCallbacksTest.java b/rococoa/rococoa-core/src/test/java/org/rococoa/internal/OCInvocationCallbacksTest.java deleted file mode 100644 index 1486af61..00000000 --- a/rococoa/rococoa-core/src/test/java/org/rococoa/internal/OCInvocationCallbacksTest.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.internal; - -import com.sun.jna.Native; -import com.sun.jna.NativeLong; -import org.junit.Test; -import org.rococoa.ID; -import org.rococoa.TestStruct; -import org.rococoa.cocoa.foundation.NSObject; -import org.rococoa.cocoa.foundation.NSString; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -public class OCInvocationCallbacksTest { - - public static class JavaImplementor { - public void returnsVoidTakesVoid() { - } - - public void returnsVoidTakesInt(int i) { - } - - public ID returnsIDTakesVoid() { - return null; - } - - public void returnsVoidTakesInt_andInt(int arg1, int arg2) { - } - - public void returnsVoidTakesOCObject(NSObject o) { - } - - public byte returnsByteTakesOCObject(NSObject o) { - return -1; - } - - public void returnsVoidTakesStruct(TestStruct s) { - } - - public void returnsVoidTakesStructByValue(TestStruct.ByValue s) { - } - - public TestStruct returnsStructTakesVoid() { - return null; - } - - public TestStruct.ByValue returnsStructByValueTakesVoid() { - return null; - } - - public NativeLong returnsNativeLongTakesNativeLong(NativeLong l) { - return null; - } - - public String returnsStringTakesString(String s) { - return null; - } - - public NSString returnsNSStringTakesNSString(NSString s) { - return null; - } - } - - private OCInvocationCallbacks callbacks = new OCInvocationCallbacks(new JavaImplementor()); - - @Test - public void testMethodForSelector() throws SecurityException, NoSuchMethodException { - assertNull(callbacks.methodForSelector("nosuch")); - assertEquals( - JavaImplementor.class.getDeclaredMethod("returnsIDTakesVoid"), - callbacks.methodForSelector("returnsIDTakesVoid")); - assertEquals( - JavaImplementor.class.getDeclaredMethod("returnsVoidTakesInt", int.class), - callbacks.methodForSelector("returnsVoidTakesInt:")); - assertEquals( - JavaImplementor.class.getDeclaredMethod("returnsVoidTakesInt_andInt", int.class, int.class), - callbacks.methodForSelector("returnsVoidTakesInt:andInt:")); - // wrong number of args - assertNull(callbacks.methodForSelector("returnsVoidTakesVoid:")); - assertNull(callbacks.methodForSelector("returnsVoidTakesInt")); - } - - @Test - public void testMethodSignatureForSelector() { - assertNull(callbacks.methodSignatureForSelector("nosuch")); - - assertEquals("v@:", callbacks.methodSignatureForSelector("returnsVoidTakesVoid")); - assertEquals("v@:i", callbacks.methodSignatureForSelector("returnsVoidTakesInt:")); - assertEquals("@@:", callbacks.methodSignatureForSelector("returnsIDTakesVoid")); - assertEquals("v@:ii", callbacks.methodSignatureForSelector("returnsVoidTakesInt:andInt:")); - assertEquals("v@:@", callbacks.methodSignatureForSelector("returnsVoidTakesOCObject:")); - assertEquals("c@:@", callbacks.methodSignatureForSelector("returnsByteTakesOCObject:")); - if (Native.LONG_SIZE == 4) - assertEquals("l@:l", callbacks.methodSignatureForSelector("returnsNativeLongTakesNativeLong:")); - else - assertEquals("q@:q", callbacks.methodSignatureForSelector("returnsNativeLongTakesNativeLong:")); - assertEquals("@@:@", callbacks.methodSignatureForSelector("returnsStringTakesString:")); - assertEquals("@@:@", callbacks.methodSignatureForSelector("returnsNSStringTakesNSString:")); - } - - - @Test - public void testMethodSignatureForSelectorForStructures() { - assertEquals("v@:^{TestStruct=id}", callbacks.methodSignatureForSelector("returnsVoidTakesStruct:")); - assertEquals("v@:{ByValue=id}", callbacks.methodSignatureForSelector("returnsVoidTakesStructByValue:")); - // TODO - better would be - // assertEquals("v@:{TestStruct_ByValue=id}", callbacks.methodSignatureForSelector("returnsVoidTakesStructByValue:")); - assertEquals("^{TestStruct=id}@:", callbacks.methodSignatureForSelector("returnsStructTakesVoid")); - assertEquals("{ByValue=id}@:", callbacks.methodSignatureForSelector("returnsStructByValueTakesVoid")); - } -} diff --git a/rococoa/rococoa-core/src/test/java/org/rococoa/internal/ObjCObjectTypeConverterTest.java b/rococoa/rococoa-core/src/test/java/org/rococoa/internal/ObjCObjectTypeConverterTest.java deleted file mode 100644 index c180d062..00000000 --- a/rococoa/rococoa-core/src/test/java/org/rococoa/internal/ObjCObjectTypeConverterTest.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.internal; - -import com.sun.jna.FromNativeConverter; -import com.sun.jna.NativeLong; -import com.sun.jna.ToNativeConverter; -import org.junit.Test; -import org.rococoa.Foundation; -import org.rococoa.ID; -import org.rococoa.ObjCObject; -import org.rococoa.Rococoa; -import org.rococoa.cocoa.foundation.NSNumber; -import org.rococoa.cocoa.foundation.NSObject; -import org.rococoa.cocoa.foundation.NSURL; -import org.rococoa.test.RococoaTestCase; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -@SuppressWarnings({"nls", "unchecked", "cast"}) -public class ObjCObjectTypeConverterTest extends RococoaTestCase { - - private static Class primitiveTypeOfID = - (Class) new ID().nativeType(); - - @Test - public void convertsNSObjectAsArgumentToID() { - ToNativeConverter converter = new ObjCObjectTypeConverter(ObjCObject.class); - // We treat all NSObject's equally in toNative, see RococoaTypeMapper - assertEquals(primitiveTypeOfID, converter.nativeType()); - - NSObject nsObject = Rococoa.create("NSObject", NSObject.class); - - Number nativeValue = (Number) converter.toNative(nsObject, null); - assertEquals(primitiveTypeOfID, nativeValue.getClass()); - assertEquals(nsObject.id().longValue(), nativeValue.longValue()); - } - - @Test - public void convertsNullAsArgumentToNull() { - // Not entirely sure about this, maybe 0 would be better than null, - // but JNA seems to interpret it properly - ToNativeConverter converter = new ObjCObjectTypeConverter(ObjCObject.class); - assertNull(converter.toNative(null, null)); - } - - @Test - public void convertsReturnedIDToNSObjectSubclass() { - FromNativeConverter converter = new ObjCObjectTypeConverter(NSNumber.class); - // returning is based on declared type, see RococoaTypeMapper - - NSNumber number = Rococoa.create("NSNumber", NSNumber.class, "numberWithInt:", 45); - - // We can cope with 64 bits on 64 and 32 - Number nativeValue = Long.valueOf(number.id().longValue()); - NSNumber converted = (NSNumber) converter.fromNative(nativeValue, null); - assertEquals(converted.id(), number.id()); - assertEquals(45, converted.intValue()); - - // We must cope with 32 bits on 32-bit - if (NativeLong.SIZE == 4) { - nativeValue = Integer.valueOf(number.id().intValue()); - converted = (NSNumber) converter.fromNative(nativeValue, null); - assertEquals(45, converted.intValue()); - } - } - - @Test - public void convertsReturnedNilToNull() { - // Again I'm not sure that this is desirable, but it is what happens. - FromNativeConverter converter = new ObjCObjectTypeConverter(NSNumber.class); - Number nativeValue = 0L; - assertNull(converter.fromNative(nativeValue, null)); - } - - @Test - public void returnedNSObjectIsNormallyRetained() { - FromNativeConverter converter = new ObjCObjectTypeConverter(NSNumber.class); - - NSURL number = Rococoa.create("NSURL", NSURL.class, "URLWithString:", "rococoa://"); - assertRetainCount(2, number); // one for the pool, one for Java - - NSNumber converted = (NSNumber) converter.fromNative(Long.valueOf(number.id().longValue()), null); - assertRetainCount(3, converted); // now we have another Java alias - assertRetainCount(3, number); - } - - @Test - public void returnedNSObjectIsNotRetainedIfMethodImpliesWeOwnIt() { - // This is difficult to unit test, as we cannot create FunctionResultContext's. - // Instead we step back look at the results through Foundation.send, which - // routes through the converter. - ID idClass = Foundation.getClass("NSObject"); - assertRetainCount(1, Foundation.send(idClass, "alloc", NSObject.class)); // not in the pool, so just one for Java - } -} diff --git a/rococoa/rococoa-core/src/test/java/org/rococoa/internal/OperationBatcherTest.java b/rococoa/rococoa-core/src/test/java/org/rococoa/internal/OperationBatcherTest.java deleted file mode 100644 index 4052cbce..00000000 --- a/rococoa/rococoa-core/src/test/java/org/rococoa/internal/OperationBatcherTest.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.internal; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - - -public class OperationBatcherTest { - - private TestBatcher batcher; - private int operationCount; - private int resetCount; - - private class TestBatcher extends OperationBatcher { - - public TestBatcher(int batchSize) { - super(batchSize); - } - - protected void operation() { - ++operationCount; - } - - protected void reset() { - ++resetCount; - } - } - - @Test - public void batchSizeOfOneAlwaysPerformsOperation() { - batcher = new TestBatcher(1); - assertEquals(0, operationCount); - assertEquals(1, resetCount); - - batcher.operate(); - assertEquals(1, operationCount); - assertEquals(2, resetCount); - - batcher.operate(); - assertEquals(2, operationCount); - assertEquals(3, resetCount); - } - - @Test - public void batchSizeThree() { - batcher = new TestBatcher(3); - assertEquals(0, operationCount); - assertEquals(1, resetCount); - - batcher.operate(); - assertEquals(0, operationCount); - assertEquals(1, resetCount); - batcher.operate(); - assertEquals(0, operationCount); - assertEquals(1, resetCount); - batcher.operate(); - assertEquals(1, operationCount); - assertEquals(2, resetCount); - - batcher.operate(); - assertEquals(1, operationCount); - assertEquals(2, resetCount); - } - - @Test - public void closeRunsButDoesntReset() { - batcher = new TestBatcher(3); - assertEquals(0, operationCount); - assertEquals(1, resetCount); - - batcher.operate(); - assertEquals(0, operationCount); - assertEquals(1, resetCount); - - batcher.close(); - assertEquals(1, operationCount); - assertEquals(1, resetCount); - - try { - batcher.operate(); - fail(); - } catch (IllegalStateException xpected) { - } - } -} diff --git a/rococoa/rococoa-core/src/test/java/org/rococoa/internal/RococoaObjCObjectByReferenceTest.java b/rococoa/rococoa-core/src/test/java/org/rococoa/internal/RococoaObjCObjectByReferenceTest.java deleted file mode 100644 index eecc8d38..00000000 --- a/rococoa/rococoa-core/src/test/java/org/rococoa/internal/RococoaObjCObjectByReferenceTest.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.internal; - -import org.junit.Ignore; -import org.junit.Test; -import org.rococoa.ID; -import org.rococoa.ObjCObject; -import org.rococoa.ObjCObjectByReference; -import org.rococoa.Rococoa; -import org.rococoa.cocoa.foundation.NSAutoreleasePool; -import org.rococoa.cocoa.foundation.NSNumber; -import org.rococoa.test.RococoaTestCase; - -import java.util.concurrent.CountDownLatch; - -import static org.junit.Assert.assertEquals; - -public class RococoaObjCObjectByReferenceTest extends RococoaTestCase { - - private interface TestShunt extends ObjCObject { - NSNumber testNumberFromInt(int value); - void testNSNumberByReference_with(ObjCObjectByReference reference, int value); - void testCallbackWithReference(ID delegate); - } - - private interface TestShuntDelegate { - void callback(ID reference); - } - - @Test - public void testArgumentInt() { - TestShunt shunt = Rococoa.create("TestShunt", TestShunt.class); - NSNumber value = shunt.testNumberFromInt(42); - assertEquals(42, value.intValue()); - } - - @Test - public void testNSNumberFromInt() { - NSNumber nsNumber = NSNumber.CLASS.numberWithInt(42); - assertEquals(42, nsNumber.intValue()); - } - - @Test - @Ignore - public void testArgument() { - NSAutoreleasePool pool = NSAutoreleasePool.new_(); - TestShunt shunt = Rococoa.create("TestShunt", TestShunt.class); - ObjCObjectByReference reference = new ObjCObjectByReference(); - shunt.testNSNumberByReference_with(reference, 42); - NSNumber value = reference.getValueAs(NSNumber.class); - assertEquals(42, value.intValue()); - - // we better have retained the result by the time it gets back - assertEquals(3, value.retainCount().intValue()); - pool.drain(); - assertEquals(2, value.retainCount().intValue()); - } - - @Test - public void testDelegate() { - NSAutoreleasePool pool = NSAutoreleasePool.new_(); - TestShunt shunt = Rococoa.create("TestShunt", TestShunt.class); - final CountDownLatch count = new CountDownLatch(1); - final ObjCObject callback = Rococoa.proxy(new TestShuntDelegate() { - public void callback(ID reference) { - // Success - count.countDown(); - } - }); - final ID delegate = callback.id(); - shunt.testCallbackWithReference(delegate); - assertEquals("Callback to delegate failed", 0, count.getCount()); - pool.drain(); - } -} diff --git a/rococoa/rococoa-core/src/test/java/org/rococoa/internal/RococoaTypeMapperTest.java b/rococoa/rococoa-core/src/test/java/org/rococoa/internal/RococoaTypeMapperTest.java deleted file mode 100644 index d6571222..00000000 --- a/rococoa/rococoa-core/src/test/java/org/rococoa/internal/RococoaTypeMapperTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.internal; - -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.rococoa.ObjCObject; -import org.rococoa.cocoa.foundation.NSNumber; -import org.rococoa.test.RococoaTestCase; - -import com.sun.jna.TypeMapper; - -@SuppressWarnings({"unchecked", "cast"}) -public class RococoaTypeMapperTest extends RococoaTestCase { - - private final TypeMapper typeMapper = new RococoaTypeMapper(); - - @Test - public void testString() { - assertTrue(typeMapper.getToNativeConverter(String.class) instanceof StringTypeConverter); - assertTrue(typeMapper.getFromNativeConverter(String.class) instanceof StringTypeConverter); - } - - @Test - public void testObjCObject() { - // ToNative only has to get the ID, so it only has to know about ObjCObject - ObjCObjectTypeConverter toNativeConverter = (ObjCObjectTypeConverter) typeMapper.getToNativeConverter(NSNumber.class); - assertTrue(toNativeConverter.convertsJavaType(ObjCObject.class)); - - // FromNative needs to know the actual type so that it can create the right Java subclass of ObjCObject - ObjCObjectTypeConverter fromNativeConverter = (ObjCObjectTypeConverter) typeMapper.getFromNativeConverter(NSNumber.class); - assertTrue(fromNativeConverter.convertsJavaType(NSNumber.class)); - } -} diff --git a/rococoa/rococoa-core/src/test/java/org/rococoa/internal/StaticStructureReturnTest.java b/rococoa/rococoa-core/src/test/java/org/rococoa/internal/StaticStructureReturnTest.java deleted file mode 100644 index 1ee34cbd..00000000 --- a/rococoa/rococoa-core/src/test/java/org/rococoa/internal/StaticStructureReturnTest.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.internal; - -import com.sun.jna.Library; -import com.sun.jna.Native; -import com.sun.jna.Structure; -import org.junit.Test; - -import java.util.Arrays; -import java.util.List; - -import static org.junit.Assert.assertEquals; - -/** - * Diagnosing a JNA bug (introduced in JNA 3.0.6) when returning small structures. - */ -public class StaticStructureReturnTest { - - public static class IntIntStruct extends Structure implements Structure.ByValue { - public int a; - public int b; - - public IntIntStruct() { - } - - public IntIntStruct(int a, int b) { - this.a = a; - this.b = b; - } - - @Override - protected List getFieldOrder() { - return Arrays.asList("a", "b"); - } - } - - public static class FloatFloatStruct extends Structure implements Structure.ByValue { - public float a; - public float b; - - public FloatFloatStruct() { - } - - public FloatFloatStruct(float a, float b) { - this.a = a; - this.b = b; - } - - @Override - protected List getFieldOrder() { - return Arrays.asList("a", "b"); - } - } - - public static class IntFloatStruct extends Structure implements Structure.ByValue { - public int a; - public float b; - - public IntFloatStruct() { - } - - public IntFloatStruct(int a, float b) { - this.a = a; - this.b = b; - } - - @Override - protected List getFieldOrder() { - return Arrays.asList("a", "b"); - } - } - - public static class IntLongStruct extends Structure implements Structure.ByValue { - public int a; - public long b; - - public IntLongStruct() { - } - - public IntLongStruct(int a, long b) { - this.a = a; - this.b = b; - } - - @Override - protected List getFieldOrder() { - return Arrays.asList("a", "b"); - } - } - - public static class IntDoubleStruct extends Structure implements Structure.ByValue { - public int a; - public double b; - - public IntDoubleStruct() { - } - - public IntDoubleStruct(int a, double b) { - this.a = a; - this.b = b; - } - - @Override - protected List getFieldOrder() { - return Arrays.asList("a", "b"); - } - } - - - public interface TestLibrary extends Library { - FloatFloatStruct createFloatFloatStruct(float a, float b); - - IntIntStruct createIntIntStruct(int a, int b); - - IntFloatStruct createIntFloatStruct(int a, float b); - - IntLongStruct createIntLongStruct(int a, long b); - - IntDoubleStruct createIntDoubleStruct(int a, double b); - } - - private TestLibrary library3 = Native.load("rococoa-test", TestLibrary.class); - - @Test - public void testIntInt() { - IntIntStruct struct = library3.createIntIntStruct(42, -99); - assertEquals(-99, struct.b); - assertEquals(42, struct.a); - } - - @Test - public void testFloatFloat() { - FloatFloatStruct struct = library3.createFloatFloatStruct((float) Math.E, (float) Math.PI); - assertEquals(Math.PI, struct.b, 0.001); - assertEquals(Math.E, struct.a, 0.001); - } - - @Test - public void testIntFloat() { - IntFloatStruct struct = library3.createIntFloatStruct(42, (float) Math.PI); - assertEquals(Math.PI, struct.b, 0.001); - assertEquals(42, struct.a); - } - - @Test - public void testIntLong() { - IntLongStruct struct = library3.createIntLongStruct(42, -99); - assertEquals(-99, struct.b); - assertEquals(42, struct.a); - } - - @Test - public void testIntDouble() { - IntDoubleStruct struct = library3.createIntDoubleStruct(42, Math.PI); - assertEquals(Math.PI, struct.b, 0.001); - assertEquals(42, struct.a); - } - -} diff --git a/rococoa/rococoa-core/src/test/java/org/rococoa/internal/StringTypeConverterTest.java b/rococoa/rococoa-core/src/test/java/org/rococoa/internal/StringTypeConverterTest.java deleted file mode 100644 index 551a1d24..00000000 --- a/rococoa/rococoa-core/src/test/java/org/rococoa/internal/StringTypeConverterTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.internal; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import org.junit.Test; -import org.rococoa.Foundation; -import org.rococoa.ID; -import org.rococoa.test.RococoaTestCase; - -import com.sun.jna.NativeLong; - -@SuppressWarnings({"nls", "unchecked", "cast"}) -public class StringTypeConverterTest extends RococoaTestCase { - - private static Class primitiveTypeOfID = - (Class) new NativeLong().nativeType(); - - private StringTypeConverter converter = new StringTypeConverter(); - - - @Test - public void convertsStringAsArgumentToIDofCFString() { - assertEquals(primitiveTypeOfID, converter.nativeType()); - - Number nativeValue = (Number) converter.toNative("Hello", null); - assertEquals(primitiveTypeOfID, nativeValue.getClass()); - assertEquals("Hello", Foundation.toString(ID.fromLong(nativeValue.longValue()))); - } - - @Test - public void convertsNullAsArgumentToNull() { - // Not entirely sure about this, maybe 0 would be better than null, - // but JNA seems to interpret it properly - assertNull(converter.toNative(null, null)); - } - - @Test - public void convertsReturnedIDToString() { - ID helloID = Foundation.cfString("Hello"); // just leaks - - // We can cope with 64 bits on 64 and 32 - Number nativeValue = new Long(helloID.longValue()); - String converted = converter.fromNative(nativeValue, null); - assertEquals("Hello", converted); - - // We must cope with 32 bits on 32-bit - if (NativeLong.SIZE == 4) { - nativeValue = new Integer(helloID.intValue()); - converted = converter.fromNative(nativeValue, null); - assertEquals("Hello", converted); - } - } - - @Test - public void convertsReturnedNilToNull() { - Number nativeValue = new Long(0); - assertNull(converter.fromNative(nativeValue, null)); - } - - -} diff --git a/rococoa/rococoa-core/src/test/java/org/rococoa/test/LogFormatter.java b/rococoa/rococoa-core/src/test/java/org/rococoa/test/LogFormatter.java deleted file mode 100644 index 70125421..00000000 --- a/rococoa/rococoa-core/src/test/java/org/rococoa/test/LogFormatter.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.test; - -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.logging.Formatter; -import java.util.logging.LogRecord; - -/** - * Print a brief summary of the LogRecord in a human readable format ON ONE LINE, and include details of - * the thread from which it was logged. Blatant copy of the default 'SimpleFormatter' included with JDK. - */ -public class LogFormatter extends Formatter -{ - private String lineSeparator = System.getProperty("line.separator"); - - /** - * Format the given LogRecord. - * - * @param record - * the log record to be formatted. - * @return a formatted log record - */ - public synchronized String format(LogRecord record) - { - StringBuffer sb = new StringBuffer(); - sb.append(shortName(Thread.currentThread())).append('\t'); - - try { - sb.append(Class.forName(record.getSourceClassName()).getSimpleName()); - } catch (Exception e) { - sb.append(record.getLoggerName()); - } - - if (record.getSourceMethodName() != null) - { - sb.append("."); - sb.append(record.getSourceMethodName()); - } - - sb.append(" - "); - sb.append(formatMessage(record)); - - appendExtras(record, sb); - sb.append(lineSeparator); - if (record.getThrown() != null) - { - try - { - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - record.getThrown().printStackTrace(pw); - pw.close(); - sb.append(sw.toString()); - } - catch (Exception ex) - { - } - } - return sb.toString(); - } - - private String shortName(Thread thread) { - String name = thread.getName(); - return name.length() <= 7 ? name : name.substring(0, 7); - } - - protected void appendExtras(LogRecord record, StringBuffer sb) { - } -} \ No newline at end of file diff --git a/rococoa/rococoa-core/src/test/java/org/rococoa/test/RococoaTestCase.java b/rococoa/rococoa-core/src/test/java/org/rococoa/test/RococoaTestCase.java deleted file mode 100644 index a221c282..00000000 --- a/rococoa/rococoa-core/src/test/java/org/rococoa/test/RococoaTestCase.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2007, 2008 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.test; - -import com.sun.jna.Native; -import org.junit.After; -import org.junit.Before; -import org.rococoa.ID; -import org.rococoa.cocoa.foundation.NSAutoreleasePool; -import org.rococoa.cocoa.foundation.NSObject; -import org.rococoa.internal.RococoaLibrary; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.util.logging.LogManager; -import java.util.logging.Logger; - -import static org.junit.Assert.assertNotNull; - -/** - * A TestCase which runs tests with an autorelease pool in place. - * - * @author duncan - */ -public abstract class RococoaTestCase { - static { - Native.load("rococoa-test", RococoaLibrary.class); - } - - // stress our memory management - public static boolean gcAfterTest = true; - protected final static Logger logging; - - static { - initializeLogging(); - logging = Logger.getLogger("org.rococoa.RococoaTestCase"); - logVersions(); - } - - public static void initializeLogging() { - try { - InputStream is = null; - try { - is = RococoaTestCase.class.getResourceAsStream("/test-logging.properties"); - if (is == null) - throw new FileNotFoundException("Cannot find test-logging.properties"); - LogManager.getLogManager().readConfiguration(is); - } finally { - if (is != null) - is.close(); - } - } catch (IOException x) { - throw new RuntimeException("Could not initialize logging", x); - } - } - - private static void logVersions() { - logging.info(String.format("Running with JAVA_HOME = %s, java.version = %s, sizeof(Pointer) = %s", - System.getenv("JAVA_HOME"), - System.getProperty("java.version"), - Native.POINTER_SIZE)); - } - - protected NSAutoreleasePool pool; - - @Before - public void preSetup() { - pool = NSAutoreleasePool.new_(); - assertNotNull(pool); - } - - @After - public void postTeardown() { - if (gcAfterTest) - gc(); - pool.drain(); - } - - public static void assertRetainCount(int expected, NSObject object) { - assertRetainCount(expected, object.id()); - } - - public static void assertRetainCount(int expected, ID id) { - //assertEquals(expected, Foundation.cfGetRetainCount(id).intValue()); - } - - public static void gc() { - System.gc(); - System.gc(); - System.runFinalization(); - } -} diff --git a/rococoa/rococoa-core/src/test/resources/test-logging.properties b/rococoa/rococoa-core/src/test/resources/test-logging.properties deleted file mode 100644 index ad13366c..00000000 --- a/rococoa/rococoa-core/src/test/resources/test-logging.properties +++ /dev/null @@ -1,8 +0,0 @@ -handlers= java.util.logging.ConsoleHandler - -org.rococoa.level = FINEST -org.rococoa.foundation.level = FINEST -org.rococoa.proxy.level = FINEST - -java.util.logging.ConsoleHandler.level = ALL -java.util.logging.ConsoleHandler.formatter = org.rococoa.test.LogFormatter \ No newline at end of file diff --git a/rococoa/rococoa-functionaltest/pom.xml b/rococoa/rococoa-functionaltest/pom.xml deleted file mode 100644 index c008c302..00000000 --- a/rococoa/rococoa-functionaltest/pom.xml +++ /dev/null @@ -1,55 +0,0 @@ - - - 4.0.0 - rococoa-functionaltest - Rococoa Functional Test - http://maven.apache.org - - - org.rococoa - rococoa-parent - 0.10.1-SNAPSHOT - - - - - org.rococoa - rococoa-core - - - org.rococoa - rococoa-cocoa - - - org.rococoa - rococoa-contrib - - - org.rococoa - rococoa-core - test-jar - - - org.rococoa - librococoa - test - dylib - test - - - - - - - maven-dependency-plugin - - - org.apache.maven.plugins - maven-deploy-plugin - - true - - - - - diff --git a/rococoa/rococoa-functionaltest/src/main/assembly/dist.xml b/rococoa/rococoa-functionaltest/src/main/assembly/dist.xml deleted file mode 100644 index 458471c3..00000000 --- a/rococoa/rococoa-functionaltest/src/main/assembly/dist.xml +++ /dev/null @@ -1,40 +0,0 @@ - - src - - tar.gz - zip - - - - target - dist - - *.jar - - - - target - lib - - *.jar - - - - src - - - src/main/doc - / - - * - - - - - - lib - false - runtime - - - \ No newline at end of file diff --git a/rococoa/rococoa-functionaltest/src/test/java/org/rococoa/contrib/growl/GrowlTest.java b/rococoa/rococoa-functionaltest/src/test/java/org/rococoa/contrib/growl/GrowlTest.java deleted file mode 100644 index d9436a01..00000000 --- a/rococoa/rococoa-functionaltest/src/test/java/org/rococoa/contrib/growl/GrowlTest.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2007, 2008, 2009 Duncan McGregor - * - * This file is part of Rococoa, a library to allow Java to talk to Cocoa. - * - * Rococoa is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rococoa 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Rococoa. If not, see . - */ - -package org.rococoa.contrib.growl; - -import org.rococoa.cocoa.foundation.NSAutoreleasePool; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; -import java.util.Arrays; - -/** - * TestGrowl - * - * @author Harald Kuhr - * @author last modified by $Author: haraldk$ - * @version $Id: TestGrowl.java,v 1.0 Mar 26, 2009 12:21:41 PM haraldk Exp$ - */ -public class GrowlTest { - private static final String MESSAGE = "Message"; - private static final String STARTUP = "Startup"; - - public static void main(final String[] pArgs) { - - System.setProperty("apple.laf.useScreenMenuBar", "true"); - - SwingUtilities.invokeLater(new Runnable() { - public void run() { - NSAutoreleasePool.new_(); // Hmmm.. This is needed only if I create Growl beofre Swing is initialized... - - final Growl growl = new Growl( - GrowlTest.class.getSimpleName(), - null, - Arrays.asList(MESSAGE, STARTUP), - Arrays.asList(MESSAGE, STARTUP), - true - ); - - JMenu menu = new JMenu("Growl"); - menu.add(new JMenuItem(new AbstractAction("message") { - { - putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_M, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); - putValue(Action.NAME, "Message"); - } - - public void actionPerformed(ActionEvent e) { - growl.postNotification(MESSAGE, "Message", "Growl says hello!"); - } - })); - - JMenuBar menubar = new JMenuBar(); - menubar.add(menu); - - JFrame frame = new JFrame("The frame..."); - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - frame.setPreferredSize(new Dimension(300, 200)); - frame.add(new JLabel("Pure Java. Almost...", JLabel.CENTER)); - frame.pack(); - frame.setLocationRelativeTo(null); - frame.setJMenuBar(menubar); - frame.setVisible(true); - - growl.postNotification(STARTUP, "Started", "GrowlTest started."); - } - }); - - } -} diff --git a/rococoa/scripts/create-sonatype-bundles b/rococoa/scripts/create-sonatype-bundles deleted file mode 100755 index 99982bf4..00000000 --- a/rococoa/scripts/create-sonatype-bundles +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash - -# To upload to Maven Central via Sonatype -# (see http://docs.sonatype.org/x/vgBl) : - -BASE_DIR="`pwd`" -OUT_DIR="`pwd`/target/bundles" -MVN_VERSION=$1 - -if [[ -z "$MVN_VERSION" ]] -then - echo "Usage: $0 mavenVersion" - exit 1 -fi - -cd $BASE_DIR - -#mvn install -DskipTests -Pgpg - -rm -fR $OUT_DIR -mkdir -p $OUT_DIR - -#PROJECTS="rococoa-parent rococoa-core rococoa-cocoa rococoa-contrib" -PROJECTS="rococoa-parent rococoa-core" - -for P in $PROJECTS ; do - cd $BASE_DIR/$P/target - - PREFIX="mvn gpg:sign-and-deploy-file -Durl=https://oss.sonatype.org/service/local/staging/deploy/maven2/ -DrepositoryId=sonatype-nexus-staging -DpomFile=$P-$MVN_VERSION.pom" - - if [[ ! -f "$P-$MVN_VERSION.jar" ]] ; then - $PREFIX -Dfile=$P-$MVN_VERSION.pom ; - else - $PREFIX -Dfile=$P-$MVN_VERSION.jar - $PREFIX -Dfile=$P-$MVN_VERSION-sources.jar -Dclassifier=sources - $PREFIX -Dfile=$P-$MVN_VERSION-javadoc.jar -Dclassifier=javadoc ; - fi - # jar -cvf $OUT_DIR/$P-$MVN_VERSION.jar `ls *$P-$MVN_VERSION.pom* *$P-$MVN_VERSION.jar* *$P-$MVN_VERSION-sources.* *$P-$MVN_VERSION-javadoc.*` - - # echo "Contents of $OUT_DIR/$P-$MVN_VERSION.jar : " - # unzip -l $OUT_DIR/$P-$MVN_VERSION.jar - echo "done for $P" ; -done - -open $OUT_DIR diff --git a/www/alm-process/snippets/page.xml b/www/alm-process/snippets/page.xml deleted file mode 100644 index 725def6e..00000000 --- a/www/alm-process/snippets/page.xml +++ /dev/null @@ -1,2 +0,0 @@ - -index.htmlSubprojects diff --git a/www/index.html b/www/index.html deleted file mode 100644 index f55755f3..00000000 --- a/www/index.html +++ /dev/null @@ -1,41 +0,0 @@ - - -Welcome to Rococoa - - - - - -

Welcome to Rococoa

- -

Rococoa is a generic Java binding to the Mac Objective-C object system. It -allows the creation and use of Objective-C objects in Java, and the -implementation of Objective-C interfaces in Java.

- -Fair Warning - -

Rococoa is very much work in progress. Much is subject to change. A lot isn't -good enough not to change. But given the recent deprecation of the Java-Cocoa -bridge, it's the best I've got. Just mind your head. And please give -feedback. -

- -

Oh, one big warning. Rococoa on PPC passes all but one of its tests, but that -shows that it has an -issue -returning longs from Objective-C methods. Please do -try it on PPC, and -let me know -any other problems.

- - - - - \ No newline at end of file diff --git a/www/objc_msgSend.html b/www/objc_msgSend.html deleted file mode 100644 index 9f30a8f9..00000000 --- a/www/objc_msgSend.html +++ /dev/null @@ -1,158 +0,0 @@ - - -Returning values from objc_msgSend etc - - - - - -

Returning values from objc_msgSend etc

- -

Here is my understanding so far

- -

From the - -Objective-C 2.0 Runtime Reference: - -

-id objc_msgSend(struct objc_super *super, SEL op,  ...)
-void objc_msgSend_stret(void * stretAddr, id theReceiver, SEL theSelector,  ...)
-
- -When it encounters a method call, the compiler generates a call to one of the -functions objc_msgSend, objc_msgSend_stret, objc_msgSendSuper, or -objc_msgSendSuper_stret. Messages sent to an object's superclass (using the -super keyword) are sent using objc_msgSendSuper; other messages are sent using -objc_msgSend. Methods that have data structures as return values are sent using -objc_msgSendSuper_stret and objc_msgSend_stret.

- -

So for methods returning id or int I call objc_msgSendSuper, casting the result -to the known return type of the method. So far so good.

- -

Now to return structs I have to call objc_msgSend_stret. This is -complicated (not that the previous reference mentions this), because, from -objc-runtime.h: - -

-/* Struct-returning Messaging Primitives (prototypes)
- *
- * For historical reasons, the prototypes for the struct-returning 
- * messengers are unusual. The portable, correct way to call these functions 
- * is to cast them to your desired return type first.
- * 
- * For example, `NSRect result = [myNSView frame]` could be written as:
- *   NSRect (*msgSend_stret_fn)(id, SEL, ...) = (NSRect(*)(id, SEL, ...))objc_msgSend_stret;
- *   NSRect result = (*msgSend_stret_fn)(myNSView, @selector(frame));
- * or, without the function pointer:
- *   NSRect result = (*(NSRect(*)(id, SEL, ...))objc_msgSend_stret)(myNSView, @selector(frame));
- * 
- * BE WARNED that these prototypes have changed in the past and will change 
- * in the future. Code that uses a cast like the example above will be 
- * unaffected. 
- */
-

- -

What I think this means is that despite the prototype saying that the -function returns void and takes void*, in reality it doesn't take void* at all, -does return a struct by value on -the stack, and your calling code had better clean it up. In C the way to make -this happen is to cast the function pointer to a pointer to a function that does -return the correct struct by value, thus tricking the compiler into generating -the correct cleanup code.

- -

If you don't have a C compiler handy to do this for you, this is going to be -tricky. Luckily Rococoa uses JNA, which -in turns uses libffi, which is very -close to having a C compiler to hand at runtime. Armed with a description of the -structure being returned, libffi sorts out the call stack after the call.

- -

It turns out that libffi doesn't only help with objc_msgSend_stret. It surprised -me early on with Rococoa that I could call objc_msgSend as if it returned Java long, -and everything worked OK. This didn't make sense, as a long is larger that an id -by some 32 bits. Now, not documented in objc-runtime.h, but in the - -Universal Binary Programming Guidelines, Second Edition it says that you -should pull the cast function pointer stunt with objc_msgSend as well.

- -If your application directly calls the Objective-C runtime function objc_msgSend, -you should always cast to the appropriate return value. For instance, for a method -that returns a BOOL data type, the following code executes properly on a PPC Macintosh -but might not on an Intel-based Macintosh computer: - -
-BOOL isEqual = objc_msgSend(string, @selector("isEqual:"), otherString);
-
- -To ensure that the code does executes properly on an Intel-based Macintosh computer, -you would change the code to the following: - -
-BOOL isEqual = ((BOOL (*)(id, SEL, id))objc_msgSend)(object, @selector("isEqual:"), otherString);
-
- -

So our long test is passing because the we are calling objc_msgSend through libffi, -telling it that the function returns 64 bits. Libffi obligingly fixes up the stack -as if 64 bits were returned, which it turns out they were, as objc_msgSend has -played the same game of hack the stack as objc_msgSend_stret. Or at least that -is my interpretation. I can't find any reference that says that this is actually -what happens when returning a long. (Also, returning a long does not work this way on PPC.)

- -

Just when I thought that I understood the rules, I tried calling a method that -returns NSSize. This is a struct, so objc_msgSend_stret applies. Except that it -doesn't. A bit of Googling yielded -this, -which says:

- -This fails because the struct type is NSPoint. In the i386 function -call ABI, sufficiently small structs like NSPoint are returned in -registers instead of in memory. In this case, you need to use -objc_msgSend() (cast to return NSPoint). objc_msgSend_stret() only -works for structs returned in memory. The PPC ABI returns eight-byte -structs in memory, so objc_msgSend_stret() is the correct call there. - -

Ooh, another special case, not even hinted at in the docs seen so far. -The post includes a link to the - -Mac OS X ABI Function Call Guide which is dense, and doesn't describe when -to use objc_msgSend or objc_msgSend_stret. It does say that 8 byte structs are -returned in registers in IA-32 and memory for PPC-32, which I guess hints at the -differentiation.

- -

Finally, we have double objc_msgSend_fpret(id self, SEL op, ...). -The -Objective-C 2.0 Runtime Reference says:

- -On the i386 platform, the ABI for functions returning a floating-point value -is incompatible with that for functions returning an integral type. On the i386 -platform, therefore, you must use objc_msgSend_fpret for functions that for -functions returning non-integral type. For float or long double return types, -cast the function to an appropriate function pointer type first.
-This function is not used on the PPC or PPC64 platforms.

- -

But Rococoa has been happily passing test which return float and double from -objC_msgSend on Intel, as I didn't know about this function. In fact, the only use I've yet found for -objc_msgSend_fpret is allowing me to interpret the stret in objc_msgSend_stret -as STructRET!

- -

Outstanding Questions

- -
    -
  • Am I right so far, or am have I got the wrong end of the stick?
  • - -
  • If both objc_msgSend_stret and objc_msgSend hack the stack to return different sized -return values, why are there 2 functions?
  • - -
  • Should I call objc_msgSend_stret when returning longs on PPC?
  • - -
  • Do I really need to call objc_msgSend_fpret for floating point on Intel?
  • - -
  • Is there a comprehensive reference to this subject that I'm missing?
  • -
- -

And Some Answers

- -

Pending a re-write of this page, some very helpful answers can be found on the - -Cocoa-dev Mailing List.

- - \ No newline at end of file diff --git a/www/rococoa-acknowledgements.html b/www/rococoa-acknowledgements.html deleted file mode 100644 index 150102f9..00000000 --- a/www/rococoa-acknowledgements.html +++ /dev/null @@ -1,32 +0,0 @@ - - -Rococoa Acknowledgements - - - - - -

Rococoa Acknowledgements

- -

Rococoa owes much to the following people and organisations

- -
    -
  • JNA does all the heavy -lifting of calling into Cocoa and marshaling parameters. Timothy Wall -also added pass struct by value and other extension points -to make our life simpler.
  • -
  • Paul Loy was the alpha guinea-pig. -
  • -
  • Simon Taylor, Gareth Sylvester-Bradley and Dion Crannitch for Objective-C -help.
  • -
  • Richard Care, Matt Bowers, Andy Collins and Morgan David let it go.
  • -
  • Apple Inc produced Quicktime, -Java on Mac OS, the Cocoa-Java Bridge and Quicktime for Java, then killed -at least 2 of them.
  • -
- -

If you know Java and Cocoa your name could be on this list! -Get involved!

- - - \ No newline at end of file diff --git a/www/rococoa-building.html b/www/rococoa-building.html deleted file mode 100644 index 40fd6609..00000000 --- a/www/rococoa-building.html +++ /dev/null @@ -1,85 +0,0 @@ - - -Building Rococoa - - - - - - -

Building Rococoa

- -

Prequisites

- -
    -
  • Maven 2
  • -
  • XCode 3.0
  • -
- -

I build on an early MacBook Pro, running 10.5.2. I haven't yet tried building on PPC. Early -builds were on Tiger, but I haven't gone back to check that it still does.

- -

Command-line Build Steps

- -
    -
  1. mkdir rococoa
  2. -
  3. -svn checkout https://rococoa.dev.java.net/svn/rococoa/trunk/rococoa . --username username
    -
  4. -
  5. The JNA library is not packaged for Maven. Acquire jna.jar (currently v3.0.1), either from -http://jna.dev.java.net -or from the lib directory of a prebuilt Rococoa distribution. Install it into the -Maven repository with -
    -mvn install:install-file -DgroupId=net.java.dev -DartifactId=jna \
    -    -Dversion=3.0.1 -Dpackaging=jar -Dfile=/path/to/file
    -
  6. -
  7. -Build and test with -
    mvn test
    -If all is successful, you should have a screenful of output, culminating in -
    -Results :
    -[surefire] Tests run: 58, Failures: 0, Errors: 0
    -
    -[INFO] ------------------------------------------------------------------------
    -[INFO] BUILD SUCCESSFUL
    -[INFO] ------------------------------------------------------------------------
    -[INFO] Total time: 1 minute 46 seconds
    -[INFO] Finished at: Fri Feb 22 11:39:09 GMT 2008
    -[INFO] Final Memory: 5M/10M
    -[INFO] ------------------------------------------------------------------------
    -
    -For some reason the native compile step takes an age to fire up xcodebuild on -my Leopard MacBook, but then XCode itself takes an age to start as well. Your -mileage may vary. -
  8. -
-

Other interesting Maven goals include

-
    -
  • mvn clean
  • -
  • mvn site
    generate javadoc and stuff
  • -
  • mvn package
    to build the distribution.
  • -
- -

Developing using Eclipse and XCode

- -

To generate an Eclipse project for the Maven build

- -
mvn eclipse:eclipse
- -

This will generate the .classpath and .project files for an Eclipse project, -that you can import into a workspace. The dependent libraries will be specified -relative to a Classpath Variable M2_REPO. This should be set ( -Eclipse/Preferences.../Java/Build Path/Classpath Variables) to -~/.m2/repository.

- -

If all is well the tests in rococoa/src/test/java should pass when -run with Eclipse's JUnit test runner.

- - - - - - - diff --git a/www/rococoa-help-wanted.html b/www/rococoa-help-wanted.html deleted file mode 100644 index 23aa3b96..00000000 --- a/www/rococoa-help-wanted.html +++ /dev/null @@ -1,40 +0,0 @@ - - -Rococoa Needs Help - - - - - -

Rococoa Needs Help

- -

Review

- -

I'm a Java hacker, and know very little Objective-C. Actually, I now know -more about the internals than I could possibly want to, but I'm really not -fluent in the ways of Cocoa.

- -

I'd really appreciate a review by someone who does know Objective-C, and -ideally some Java, to see if there are any issues that I haven't thought -about

- -

If you're really a Objective-C wizard, maybe you could look over -Returning values from objc_msgSend etc -and answer the questions there.

- -

Development

- -

If you'd like to help with development, that would be great too.

- -

Contrib

- -

Whilst writing Java wrappers for Cocoa classes isn't hard, it would be nice -if there was more available out of the box. If you've wrapped an Objective-C -class we don't have, or extended an available one, please send them back.

- -

In all cases, -posting -to the user or dev mailing list is probably the best way to get attention

- - - \ No newline at end of file diff --git a/www/rococoa-howto.html b/www/rococoa-howto.html deleted file mode 100644 index 4a2f8ff9..00000000 --- a/www/rococoa-howto.html +++ /dev/null @@ -1,85 +0,0 @@ - - -Rococoa How To - - - - - - -

Rococoa How To

- -

Download

- -

Download your choice of archive from -here.

- -

Link

- -

Unarchive your download. Add dist/rococoa-n.n.n.jar and -the jars in lib to your classpath.

- -

Add bin to your java.library.path. -

- -

Create a Java class representation of an Objective-C class

- -

For now, see the Whistlestop Tour. - -

Create an Objective-C instance

- -

For now, see the Whistlestop Tour. - -

Call methods on an Objective-C object

- -

For now, see the Whistlestop Tour. - -

Manage Memory

- -

See Memory Management. - -

Call methods with more than one parameter

- -

Call methods that have the name of a Java keyword

- -

Not define Objective-C classes

- -

Simplify factory methods

- -

Add Java behaviour to Rococoa wrappers

- -

Pass structures to methods

- -

Return structures from methods

- -

Debug

- -

Log calls

- -

Call static Mac functions

- -

Get more help

- -

See more examples

- -

Use Quicktime

- -

See Quicktime and Rococoa.

- -

Build Rococoa

- -

See Building Rococoa.

- -

See what's going on

- -

Turn the log level up : org.rococoa.level=FINEST. -This will log all message sending through Rococoa.

- -

Help

- -

See Help Wanted.

- - - - - diff --git a/www/rococoa-limitations.html b/www/rococoa-limitations.html deleted file mode 100644 index 19565146..00000000 --- a/www/rococoa-limitations.html +++ /dev/null @@ -1,28 +0,0 @@ - - -Rococoa Limitations - - - - - -

Rococoa Limitations

- -

For a complete list of logged defects and issues, apply -here.

- -

Cannot return long from Objective-C methods on PPC

- -

ref

- -

Cannot return small structs (except NSSize) on Intel

- -

ref

- -

Callbacks from Objective-C currently naff

- -

JavaProxyTest shows how it's currently done, even the names of -classes let you know that it's not done right.

- - - \ No newline at end of file diff --git a/www/rococoa-memory.html b/www/rococoa-memory.html deleted file mode 100644 index ec887875..00000000 --- a/www/rococoa-memory.html +++ /dev/null @@ -1,73 +0,0 @@ - - -Rococoa Memory Management - - - - - - -

Rococoa Memory Management

- -

While Java has garbage collection, Objective-C memory management (prior to v2) -is based around manual reference counting.

- -

-Essentially, objects have a reference count, 1 when first created, and -incremented by calling - (id)retain. On calling - (void)release -the count is decremented, and if it has fallen to 0, the object's memory is reclaimed.

- -

Conventionally, newly created objects are put into an autorelease pool, which -retains them, and when the pool itself is reclaimed, all of its -objects are released. If an object should live longer -than the current pool, then client code should retain the object -itself, and release when done with.

- -

Rococoa automatically retains Objective-C objects wrapped by the -Java NSObject, and releases them when the Java NSObject is garbage -collected. So why am I bothering you with all this detail? Because you need an -autorelease pool in the first place.

- -

At the moment the way Rococoa creates a pool is through -ID Foundation.createPool(), releasing it with -void Foundation.releasePool(ID pool). It's your job to make sure that -there is a current pool before you invoke any Objective-C methods which need to -allocate from it. For example, RococoaTestCase says - -

    
-    public void runBare() throws Throwable {
-        pool = Foundation.createPool();
-        try {
-            super.runBare();
-        } finally {
-            Foundation.releasePool(pool);
-        }
-    }
-
- -thus giving each test run its own pool.

- -

Helpfully, if you forget to create a pool, the Objective-C runtime will gently -chastise you on stderr with messages like -*** _NSAutoreleaseNoPool(): Object 0x1222a0 of class NSCFString autoreleased with no pool in place - just leaking

- -

Note that while a pool is required during allocation, objects can outlive -their pool, and will if you keep a reference to a Java NSObject.

- -

I plan to replace those nasty calls to Foundation with a Java NSAutoreleasePool -which you can just hang onto by reference. But the current system works, and it's -best to be conservative about memory, as accessing an already disposed object -will crash your app. Actually I'm pretty sure that there's at least one bug hiding in there -already - a small prize to anyone who finds it.

- -

Finally, note that if your code has been called by the Cocoa event thread (as -a result of a native button press for example) then Cocoa will already have -arranged a pool for you, and will dispose of it once the event is done.

- -

Really finally, I've no idea how this all relates to Objective-C garbage collection, -introduced in v2, and am hoping that someone will be able to tell me.

- - - - - diff --git a/www/rococoa-quicktime.html b/www/rococoa-quicktime.html deleted file mode 100644 index 6c3549e3..00000000 --- a/www/rococoa-quicktime.html +++ /dev/null @@ -1,66 +0,0 @@ - - -Quicktime and Rococoa - - - - - -

Quicktime and Rococoa

- -

Rococoa was written to allow the use of the -QTKit framework -from Java. It's by no means finished, but it is functional.

- -

The package org.rococoa.quicktime contains the work so far on -wrapping QTKit. An example of using the code to play a Quicktime Movie can be -found in PlayMovieExample.

- -
-public class PlayMovieExample {
-
-    static final File FILE = new File("testdata/DrWho.mov");
-
-    static {
-    	// load library
-        @SuppressWarnings("unused")
-        QTKit instance = QTKit.instance;
-    }
-
-    public static void main(String[] args) {
-        QTMovieView movieView = QTMovieView.CLASS.create();
-        movieView.setControllerVisible(true);
-        movieView.setPreservesAspectRatio(true);
-
-        MovieComponent component = new MovieComponent(movieView);
-        JFrame frame = new JFrame();
-        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-        frame.getContentPane().add(component);
-
-        QTMovie movie = QTMovie.movieWithFile_error(FILE.getPath(), null);
-        movieView.setMovie(movie);                
-        movie.gotoBeginning();
-        frame.pack();
-        frame.setVisible(true);
-    }
-
-}
-
- -

QTMovieTest gives other examples.

- -

One of the complications involved in using QTKit from Java is that all access -to QTKit must be on the Cocoa event thread, which is not the same as the -AWT event thread. The QTMovieView and QTMovie classes are -annotated with @RunOnMainThread - Rococoa dispatches -all method calls to such classes on the Cocoa event thread. If you plan to extend -the QTKit coverage your classes may need to be similarly annotated.

- -

You may notice the absence of calls to Foundation.createPool() -in the code above. I'm still trying to get my head around this. Because the method -calls are all dispatched on the Cocoa event thread, and Cocoa conveniently creates -an autorelease pool for event handling code, the calls themselves are in the -context of a pool. I don't believe that this is the case for parameters that you -pass in though, so bear with my while I think it through.

- - \ No newline at end of file diff --git a/www/rococoa-whistlestop.html b/www/rococoa-whistlestop.html deleted file mode 100644 index 0ce1ae40..00000000 --- a/www/rococoa-whistlestop.html +++ /dev/null @@ -1,288 +0,0 @@ - - -Rococoa Whistlestop Tour - - - - - -

Rococoa Whistlestop Tour

- -

First download and unzip the latest release. Add -dist/rococoa-n.n.n.jar and the jars in lib to -your classpath. Add bin/librococoa.dylib to your -java.library.path (the easiest way to do this is to drop it into -the directory from which you run code).

- -

I'm about to gloss over some memory management issues. Please don't -ship code based on Rococoa without getting at least as far as -that section.

- -

Now choose a Cocoa class you'd like to represent in Java. Let's say -NSMutableArray. Create a Java interface called NSMutableArray, extending -org.rococoa.NSObject.

- -

-public interface NSMutableArray extends NSObject {
-}
-
- -

To create an NSMutableArray in Objective-C we would call the class (static) -method + (id)arrayWithCapacity:(NSUInteger) numItems. We don't have -any way to add static methods to a Java interface, so add a nested class and add -the desired method to that.

- -
-public interface NSMutableArray extends NSObject {
-
-    public interface _Class extends NSClass {
-        NSMutableArray arrayWithCapacity(int numItems);
-    }    
-}
-
- -

The nested class name _Class is just a convention. The method -name should be the same as the Objective-C name, and primitive arguments just -map to their obvious Java equivalents. The id returned we know -represents an instance of NSMutableArray, so we may as well say so.

- -

Now we need an instance of this inner class to call our method. Rococoa will -create this for us, if we tell it the name of the Objective-C class that we are -wrapping, and the type of the wrapper. I call these statics -CLASS.

- -
-public interface NSMutableArray extends NSObject {
-
-    public static final _Class CLASS = Rococoa.createClass("NSMutableArray", _Class.class);
-    
-    public interface _Class extends NSClass {
-        NSMutableArray arrayWithCapacity(int numItems);
-    }
-}
-
- -

Now everything is in place to create an instance, let's do that and call the -NSObject method - (NSString *)description, mapped in NSObject.java -as String description().

- -

-public class NSMutableArrayTest extends RococoaTestCase {
-
-    public void test() {
-        NSMutableArray array = NSMutableArray.CLASS.arrayWithCapacity(3);
-        assertEquals("(\n)", array.description());
-    }   
-}
-
- -

OK, so it's not much of a description, but if it works, you've created an -Objective-C object and called a method on it. Let's add some more interesting -operations.

- -

Provided that it is implemented in Objective-C, adding an operation is simply -a question of adding to our Java interface. So in the parent of NSMutableArray, -NSArray, we find - (NSUInteger)count. We can add that to our -interface and then call it.

- -
-public interface NSMutableArray extends NSObject {
-
-    public static final _Class CLASS = Rococoa.createClass("NSMutableArray", Class.class);
-    public interface _Class extends NSClass {
-        NSMutableArray arrayWithCapacity(int numItems);
-    }
-    
-    int count();
-}
-
-public class NSMutableArrayTest extends RococoaTestCase {
-
-    public void test() {
-        NSMutableArray array = NSMutableArray.CLASS.arrayWithCapacity(3);
-        assertEquals("(\n)", array.description());
-        
-        assertEquals(0, array.count());
-    }   
-}
-
- -

Hmmm, pretty boring, but necessary if we're going to test - -(void)addObject:(id)anObject.

- -

That (id) parameter is Objective-C's way of saying any NSObject, -so the corresponding Java code is:

- -
-public interface NSMutableArray extends NSObject {
-
-    public static final _Class CLASS = Rococoa.createClass("NSMutableArray", _Class.class);
-    public interface _Class extends NSClass {
-        NSMutableArray arrayWithCapacity(int numItems);
-    }
-    
-    int count();
-    
-    void addObject(NSObject anObject);
-}.
-
- -

The only NSObject subclass that we've seen so far is our NSMutableArray (OK, -_Class is as well, smarty-pants), and adding an array to an array is too -hardcore, so for our test be glad that Rococoa has already implemented some of -NSString, and a factory method NSString stringWithString(java.lang.String -string).

- -
-public class NSMutableArrayTest extends RococoaTestCase {
-
-    public void test() {
-        NSMutableArray array = NSMutableArray.CLASS.arrayWithCapacity(3);
-        assertEquals(0, array.count());
-        
-        NSString aString = NSString.stringWithString("Hello"));
-        array.addObject(aString);
-        assertEquals(1, array.count());
-        assertEquals("(\n    Hello\n)", array.description());
-    }   
-}
-
- -

As passing strings around is pretty fundamental, Rococoa marsalls them -specially. If you declare a parameter as java.lang.String, Rococoa will create -the NSString for you.

- -
-public interface NSMutableArray extends NSObject {
-
-    public static final _Class CLASS = Rococoa.createClass("NSMutableArray", _Class.class);
-    public interface _Class extends NSClass {
-        NSMutableArray arrayWithCapacity(int numItems);
-    }
-    
-    int count();
-    void addObject(NSObject anObject);
-    
-    void addObject(String string);
-
-}
-
-public class NSMutableArrayTest extends RococoaTestCase {
-
-    public void test() {
-        NSMutableArray array = NSMutableArray.CLASS.arrayWithCapacity(3);
-        assertEquals(0, array.count());
-        array.addObject(NSString.stringWithString("Hello"));
-        
-        array.addObject("Goodbye");
-        assertEquals(2, array.count());
-        assertEquals("(\n    Hello,\n    Goodbye\n)",
-                array.description());
-    }   
-}
-
- -

The same is true for returning strings.

- -
-public interface NSMutableArray extends NSObject {
-
-    public static final _Class CLASS = Rococoa.createClass("NSMutableArray", _Class.class);
-    public interface _Class extends NSClass {
-        NSMutableArray arrayWithCapacity(int numItems);
-    }
-    
-    int count();
-    void addObject(NSObject anObject);
-    void addObject(String string);
-    
-    String objectAtIndex(int index);
-
-}
-
-public class NSMutableArrayTest extends RococoaTestCase {
-
-    public void test() {
-        NSMutableArray array = NSMutableArray.CLASS.arrayWithCapacity(3);
-        assertEquals(0, array.count());
-        array.addObject(NSString.stringWithString("Hello"));
-        array.addObject("Goodbye");
-        assertEquals(2, array.count());
-        
-        String first = array.objectAtIndex(0);
-        assertEquals("Hello", first);
-        assertEquals("Goodbye", array.objectAtIndex(1));
-    }   
-}
-
- -

Of course we can't overload String objectAtIndex(int index) and -add the more generic NSObject objectAtIndex(int index). Let's go -back to returning NSObject.

- -
-public interface NSMutableArray extends NSObject {
-
-    public static final _Class CLASS = Rococoa.createClass("NSMutableArray", _Class.class);
-    public interface _Class extends NSClass {
-        NSMutableArray arrayWithCapacity(int numItems);
-    }
-    
-    int count();
-    void addObject(NSObject anObject);
-    void addObject(String string);
-    
-    NSObject objectAtIndex(int index);
-}
-
- -

Now we can compare with an NSString.

- -
-public class NSMutableArrayTest extends RococoaTestCase {
-
-    public void test() {
-        NSMutableArray array = NSMutableArray.CLASS.arrayWithCapacity(3);
-        assertEquals(0, array.count());
-        array.addObject(NSString.stringWithString("Hello"));
-        array.addObject("Goodbye");
-        assertEquals(2, array.count());
-        
-        NSObject first = array.objectAtIndex(0);
-        assertEquals(NSString.stringWithString("Hello"), first);
-    }   
-}
-
- -

Alternatively we can downcast to NSString using Rococoa.cast(NSObject -object, Class desiredType).

- -
-public class NSMutableArrayTest extends RococoaTestCase {
-
-    public void test() {
-        NSMutableArray array = NSMutableArray.CLASS.arrayWithCapacity(3);
-        assertEquals(0, array.count());
-        array.addObject(NSString.stringWithString("Hello"));
-        array.addObject("Goodbye");
-        assertEquals(2, array.count());
-
-        NSObject first = array.objectAtIndex(0);
-        assertEquals(NSString.stringWithString("Hello"), first);
-        
-        NSString firstAsString = Rococoa.cast(first, NSString.class);
-        assertEquals("Hello", firstAsString.toString());
-        assertEquals("Goodbye", 
-                Rococoa.cast(array.objectAtIndex(1), NSString.class).toString());
-
-    }   
-}
-
- -

That's the end of our quick tour. I thought there were too many apostrophes, -but if that hasn't put you off, please see the How -To for more information.

- - - - diff --git a/www/rococoa-wiki.html b/www/rococoa-wiki.html deleted file mode 100644 index 7dd49a5a..00000000 --- a/www/rococoa-wiki.html +++ /dev/null @@ -1,40 +0,0 @@ - - -Rococoa Wiki - - - - - - - - - - - - \ No newline at end of file diff --git a/www/rococoa.css b/www/rococoa.css deleted file mode 100644 index e219d316..00000000 --- a/www/rococoa.css +++ /dev/null @@ -1,17 +0,0 @@ -.new { - font-weight: bold; -} -pre.block { - background-color: LightGoldenRodYellow; - white-space: pre; - font-family: courier; - font-size: 90%; -} -code { - white-space: pre; - font-family: courier; - font-size: 90%; -} -q { - font-style: italic; -} \ No newline at end of file pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy