]> Softwares of Agnibho - dietsurvey.git/commitdiff
First Commit
authoragnibho <agni2111@gmail.com>
Wed, 12 Mar 2014 16:42:29 +0000 (22:12 +0530)
committeragnibho <agni2111@gmail.com>
Wed, 12 Mar 2014 16:42:29 +0000 (22:12 +0530)
20 files changed:
LICENSE.TXT [new file with mode: 0644]
README.TXT [new file with mode: 0644]
com/agnibho/code/dietSurvey/Assess.java [new file with mode: 0644]
com/agnibho/code/dietSurvey/CustomFood.java [new file with mode: 0644]
com/agnibho/code/dietSurvey/DocHandler.java [new file with mode: 0644]
com/agnibho/code/dietSurvey/FoodPanel.java [new file with mode: 0644]
com/agnibho/code/dietSurvey/Help.java [new file with mode: 0644]
com/agnibho/code/dietSurvey/IdPanel.java [new file with mode: 0644]
com/agnibho/code/dietSurvey/LICENSE.TXT [new file with mode: 0644]
com/agnibho/code/dietSurvey/NutrientGraph.java [new file with mode: 0644]
com/agnibho/code/dietSurvey/ResultPanel.java [new file with mode: 0644]
com/agnibho/code/dietSurvey/UI.java [new file with mode: 0644]
com/agnibho/code/dietSurvey/Update.java [new file with mode: 0644]
com/agnibho/code/dietSurvey/Zipper.java [new file with mode: 0644]
com/agnibho/code/resources/customFood.xsd [new file with mode: 0644]
com/agnibho/code/resources/food.xml [new file with mode: 0644]
com/agnibho/code/resources/rda.xml [new file with mode: 0644]
com/agnibho/code/resources/style.css [new file with mode: 0644]
com/agnibho/code/resources/style.xsl [new file with mode: 0644]
com/agnibho/code/resources/summary.xsl [new file with mode: 0644]

diff --git a/LICENSE.TXT b/LICENSE.TXT
new file mode 100644 (file)
index 0000000..94a9ed0
--- /dev/null
@@ -0,0 +1,674 @@
+                    GNU GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+  The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works.  By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users.  We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors.  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+  To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights.  Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received.  You must make sure that they, too, receive
+or can get the source code.  And you must show them these terms so they
+know their rights.
+
+  Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+  For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software.  For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+  Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so.  This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software.  The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable.  Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products.  If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+  Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary.  To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                       TERMS AND CONDITIONS
+
+  0. Definitions.
+
+  "This License" refers to version 3 of the GNU General Public License.
+
+  "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+  "The Program" refers to any copyrightable work licensed under this
+License.  Each licensee is addressed as "you".  "Licensees" and
+"recipients" may be individuals or organizations.
+
+  To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy.  The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+  A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+  To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy.  Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+  To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies.  Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+  An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License.  If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+  1. Source Code.
+
+  The "source code" for a work means the preferred form of the work
+for making modifications to it.  "Object code" means any non-source
+form of a work.
+
+  A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+  The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form.  A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+  The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities.  However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work.  For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+  The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+  The Corresponding Source for a work in source code form is that
+same work.
+
+  2. Basic Permissions.
+
+  All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met.  This License explicitly affirms your unlimited
+permission to run the unmodified Program.  The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work.  This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+  You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force.  You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright.  Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+  Conveying under any other circumstances is permitted solely under
+the conditions stated below.  Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+  No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+  When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+  4. Conveying Verbatim Copies.
+
+  You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+  You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+  5. Conveying Modified Source Versions.
+
+  You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+    a) The work must carry prominent notices stating that you modified
+    it, and giving a relevant date.
+
+    b) The work must carry prominent notices stating that it is
+    released under this License and any conditions added under section
+    7.  This requirement modifies the requirement in section 4 to
+    "keep intact all notices".
+
+    c) You must license the entire work, as a whole, under this
+    License to anyone who comes into possession of a copy.  This
+    License will therefore apply, along with any applicable section 7
+    additional terms, to the whole of the work, and all its parts,
+    regardless of how they are packaged.  This License gives no
+    permission to license the work in any other way, but it does not
+    invalidate such permission if you have separately received it.
+
+    d) If the work has interactive user interfaces, each must display
+    Appropriate Legal Notices; however, if the Program has interactive
+    interfaces that do not display Appropriate Legal Notices, your
+    work need not make them do so.
+
+  A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit.  Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+  6. Conveying Non-Source Forms.
+
+  You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+    a) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by the
+    Corresponding Source fixed on a durable physical medium
+    customarily used for software interchange.
+
+    b) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by a
+    written offer, valid for at least three years and valid for as
+    long as you offer spare parts or customer support for that product
+    model, to give anyone who possesses the object code either (1) a
+    copy of the Corresponding Source for all the software in the
+    product that is covered by this License, on a durable physical
+    medium customarily used for software interchange, for a price no
+    more than your reasonable cost of physically performing this
+    conveying of source, or (2) access to copy the
+    Corresponding Source from a network server at no charge.
+
+    c) Convey individual copies of the object code with a copy of the
+    written offer to provide the Corresponding Source.  This
+    alternative is allowed only occasionally and noncommercially, and
+    only if you received the object code with such an offer, in accord
+    with subsection 6b.
+
+    d) Convey the object code by offering access from a designated
+    place (gratis or for a charge), and offer equivalent access to the
+    Corresponding Source in the same way through the same place at no
+    further charge.  You need not require recipients to copy the
+    Corresponding Source along with the object code.  If the place to
+    copy the object code is a network server, the Corresponding Source
+    may be on a different server (operated by you or a third party)
+    that supports equivalent copying facilities, provided you maintain
+    clear directions next to the object code saying where to find the
+    Corresponding Source.  Regardless of what server hosts the
+    Corresponding Source, you remain obligated to ensure that it is
+    available for as long as needed to satisfy these requirements.
+
+    e) Convey the object code using peer-to-peer transmission, provided
+    you inform other peers where the object code and Corresponding
+    Source of the work are being offered to the general public at no
+    charge under subsection 6d.
+
+  A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+  A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling.  In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage.  For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product.  A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+  "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source.  The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+  If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information.  But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+  The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed.  Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+  Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+  7. Additional Terms.
+
+  "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law.  If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+  When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it.  (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.)  You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+  Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+    a) Disclaiming warranty or limiting liability differently from the
+    terms of sections 15 and 16 of this License; or
+
+    b) Requiring preservation of specified reasonable legal notices or
+    author attributions in that material or in the Appropriate Legal
+    Notices displayed by works containing it; or
+
+    c) Prohibiting misrepresentation of the origin of that material, or
+    requiring that modified versions of such material be marked in
+    reasonable ways as different from the original version; or
+
+    d) Limiting the use for publicity purposes of names of licensors or
+    authors of the material; or
+
+    e) Declining to grant rights under trademark law for use of some
+    trade names, trademarks, or service marks; or
+
+    f) Requiring indemnification of licensors and authors of that
+    material by anyone who conveys the material (or modified versions of
+    it) with contractual assumptions of liability to the recipient, for
+    any liability that these contractual assumptions directly impose on
+    those licensors and authors.
+
+  All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10.  If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term.  If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+  If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+  Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+  8. Termination.
+
+  You may not propagate or modify a covered work except as expressly
+provided under this License.  Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+  However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+  Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+  Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License.  If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+  9. Acceptance Not Required for Having Copies.
+
+  You are not required to accept this License in order to receive or
+run a copy of the Program.  Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance.  However,
+nothing other than this License grants you permission to propagate or
+modify any covered work.  These actions infringe copyright if you do
+not accept this License.  Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+  10. Automatic Licensing of Downstream Recipients.
+
+  Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License.  You are not responsible
+for enforcing compliance by third parties with this License.
+
+  An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations.  If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+  You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License.  For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+  11. Patents.
+
+  A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based.  The
+work thus licensed is called the contributor's "contributor version".
+
+  A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version.  For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+  Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+  In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement).  To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+  If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients.  "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+  If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+  A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License.  You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+  Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+  12. No Surrender of Others' Freedom.
+
+  If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all.  For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+  13. Use with the GNU Affero General Public License.
+
+  Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work.  The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+  14. Revised Versions of this License.
+
+  The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+  Each version is given a distinguishing version number.  If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation.  If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+  If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+  Later license versions may give you additional or different
+permissions.  However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+  15. Disclaimer of Warranty.
+
+  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. Limitation of Liability.
+
+  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+  17. Interpretation of Sections 15 and 16.
+
+  If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+                     END OF TERMS AND CONDITIONS
+
+            How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+  If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+    <program>  Copyright (C) <year>  <name of author>
+    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+  You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+  The GNU General Public License does not permit incorporating your program
+into proprietary programs.  If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library.  If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.  But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
diff --git a/README.TXT b/README.TXT
new file mode 100644 (file)
index 0000000..65b7acd
--- /dev/null
@@ -0,0 +1,40 @@
+=============
+Anagram 1.0.0
+=============
+
+General Usage Notes
+-------------------
+-Anagram finds angram for a given word
+-Multiworded search may take a long time to complete and may be resource consuming
+-Grammatical filtering for multiworded search is not yet available
+-No installaion is required, just double click the downloaded .jar file to launch Anagram
+
+Program Notes
+-------------
+-Anagram is programmed in Java SE
+-The source code is available at http://code.agnibho.com/dietsurvey
+
+Contact Information
+-------------------
+Agnibho Mondal
+mail@agnibho.com
+www.agnibho.com
+
+Copyright Information
+---------------------
+Anagram- Find anagrams of a word
+Copyright (C) 2013  Agnibho Mondal
+
+This file is part of Anagram.
+Anagram 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.
+
+Anagram 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 Anagram.  If not, see <http://www.gnu.org/licenses/>.
\ No newline at end of file
diff --git a/com/agnibho/code/dietSurvey/Assess.java b/com/agnibho/code/dietSurvey/Assess.java
new file mode 100644 (file)
index 0000000..da4c17a
--- /dev/null
@@ -0,0 +1,751 @@
+/*
+    Diet-Survey: Perform diet survey based on 24 hours recall
+    Copyright (C) 2013  Agnibho Mondal
+    
+    This file is part of Diet-Survey.
+
+    Diet-Survey 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.
+
+    Diet-Survey 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 Diet-Survey.  If not, see <http://www.gnu.org/licenses/>.
+*/
+package com.agnibho.code.dietSurvey;
+
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.swing.JFrame;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpressionException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+public class Assess {
+    
+    private double totalEnergyRequirement=0;
+    private double totalProteinRequirement=0;
+    private double totalIronRequirement=0;
+    private double totalVitARequirement=0;
+    private double totalThiamineRequirement=0;
+    private double totalRiboflavinRequirement=0;
+    private double totalVitCRequirement=0;
+    
+    private double totalEnergyConsumed=0;
+    private double totalProteinConsumed=0;
+    private double totalIronConsumed=0;
+    private double totalVitAConsumed=0;
+    private double totalThiamineConsumed=0;
+    private double totalRiboflavinConsumed=0;
+    private double totalVitCConsumed=0;
+    
+    private DocHandler dh;
+    private Document input;
+    private Document output;
+    private Document rda;
+    private Document food;
+    private Document customFoods;
+    private XPath xp=DocHandler.getXpInstance();
+
+    public Assess(Document in) throws TransformerConfigurationException, SAXException, IOException, ParserConfigurationException, XPathExpressionException {
+       dh=new DocHandler();
+       
+       input=in;
+       output=dh.getDocInstance();
+       rda=dh.getDocument(java.lang.ClassLoader.getSystemResourceAsStream("com/agnibho/code/resources/rda.xml"));
+       food=dh.getDocument(java.lang.ClassLoader.getSystemResourceAsStream("com/agnibho/code/resources/food.xml"));
+       
+       Node node=output;
+       node.appendChild(output.createElement("assessment"));
+    }
+
+    private void combine(){
+       try{
+           customFoods=new DocHandler().getValidatedDocument(new File(UI.LOC+File.separator+"custom_food.xml"), java.lang.ClassLoader.getSystemResourceAsStream("com/agnibho/code/resources/customFood.xsd"));
+           NodeList custom=(NodeList) xp.evaluate("foodList/food", customFoods, XPathConstants.NODESET);
+           Node del;
+           for(int i=0; i<custom.getLength(); i++){
+               if((boolean) xp.evaluate("/foodList/food[name='"+xp.evaluate("name", custom.item(i))+"']", food, XPathConstants.BOOLEAN)){
+                   del=(Node) xp.evaluate("/foodList/food[name='"+xp.evaluate("name", custom.item(i))+"']", food, XPathConstants.NODE);
+                   del.getParentNode().removeChild(del);
+               }
+               food.getLastChild().appendChild(food.importNode(custom.item(i), true));
+           }
+       }catch(Exception e){
+           System.out.println(e);
+       }
+    }
+    
+    public Document getOutput() throws XPathExpressionException{
+       combine();
+       calculateRequirement();
+       calculateConsumption();
+       calculateStatus();
+       return output;
+    }
+    
+    /**
+     * 
+     * REQUIREMENT
+     * 
+     */
+    
+    private void calculateRequirement() throws XPathExpressionException{
+       Node node;
+       node=(Node) xp.evaluate("/assessment", output, XPathConstants.NODE);
+       node.appendChild(output.createElement("requirement"));
+       NodeList nl=(NodeList) xp.evaluate("/record/id/member", input, XPathConstants.NODESET);
+       for(int i=0; i<nl.getLength(); i++){
+           memberRequirement(nl.item(i));
+       }
+       node=(Node) xp.evaluate("/assessment/requirement", output, XPathConstants.NODE);
+       node.appendChild(output.createElement("total"));
+       node=node.getLastChild();
+       node.appendChild(output.createElement("energy"));
+       node.getLastChild().appendChild(output.createTextNode(String.valueOf(totalEnergyRequirement)));
+       node.appendChild(output.createElement("protein"));
+       node.getLastChild().appendChild(output.createTextNode(String.valueOf(totalProteinRequirement)));
+       node.appendChild(output.createElement("iron"));
+       node.getLastChild().appendChild(output.createTextNode(String.valueOf(totalIronRequirement)));
+       node.appendChild(output.createElement("vitA"));
+       node.getLastChild().appendChild(output.createTextNode(String.valueOf(totalVitARequirement)));
+       node.appendChild(output.createElement("thiamine"));
+       node.getLastChild().appendChild(output.createTextNode(String.valueOf(totalThiamineRequirement)));
+       node.appendChild(output.createElement("riboflavin"));
+       node.getLastChild().appendChild(output.createTextNode(String.valueOf(totalRiboflavinRequirement)));
+       node.appendChild(output.createElement("vitC"));
+       node.getLastChild().appendChild(output.createTextNode(String.valueOf(totalVitCRequirement)));
+    }
+    //Individual
+    private void memberRequirement(Node inNode) throws XPathExpressionException{
+       Node outNode=(Node) xp.evaluate("/assessment/requirement", output, XPathConstants.NODE);
+       outNode.appendChild(output.createElement("member"));
+       outNode=outNode.getLastChild();
+       outNode.appendChild(output.importNode((Node) xp.evaluate("name", inNode, XPathConstants.NODE), true));
+       
+       /*
+        * ENERGY
+        */
+       
+       outNode.appendChild(output.createElement("energy"));
+       outNode=outNode.getLastChild();
+       if(xp.evaluate("infant", inNode, XPathConstants.NODE) != null){
+           int age=Integer.parseInt(xp.evaluate("infant", inNode));
+           outNode.appendChild(output.createTextNode(xp.evaluate("/rda/energy/infant/age[@lower<="+age+"][@upper>="+age+"]", rda)));
+       }
+       else if(xp.evaluate("sex", inNode).equals("male")){
+           int age=Integer.parseInt(xp.evaluate("age", inNode));
+           if(age<18){
+               outNode.appendChild(output.createTextNode(xp.evaluate("/rda/energy/male/age[@lower<="+age+"][@upper>="+age+"]", rda)));
+           }
+           else{
+               if(xp.evaluate("occupation", inNode).equals("sedentary")){
+                   outNode.appendChild(output.createTextNode(xp.evaluate("/rda/energy/male/age/sedentary", rda)));
+               }
+               else if(xp.evaluate("occupation", inNode).equals("moderate"))
+                   outNode.appendChild(output.createTextNode(xp.evaluate("/rda/energy/male/age/moderate", rda)));
+               else if(xp.evaluate("occupation", inNode).equals("heavy"))
+                   outNode.appendChild(output.createTextNode(xp.evaluate("/rda/energy/male/age/heavy", rda)));
+           }
+       }
+       else{
+           int age=Integer.parseInt(xp.evaluate("age", inNode));
+           double energy=0;
+           if(age<18){
+               outNode.appendChild(output.createTextNode(xp.evaluate("/rda/energy/female/age[@lower<="+age+"][@upper>="+age+"]", rda)));
+           }
+           else{
+               if((boolean) xp.evaluate("pregnant", inNode, XPathConstants.BOOLEAN)){
+                   energy=Double.parseDouble(xp.evaluate("/rda/energy/female/pregnantExtra", rda));
+               }
+               if((boolean) xp.evaluate("lactating", inNode, XPathConstants.BOOLEAN)){
+                   if((boolean) xp.evaluate("beyond6m", inNode, XPathConstants.BOOLEAN))
+                       energy=Double.parseDouble(xp.evaluate("/rda/energy/female/lactatingExtra/above6m", rda));
+                   else
+                       energy=Double.parseDouble(xp.evaluate("/rda/energy/female/lactatingExtra/below6m", rda));
+               }
+               if(xp.evaluate("occupation", inNode).equals("sedentary"))
+                   outNode.appendChild(output.createTextNode(String.valueOf(energy+Double.parseDouble(xp.evaluate("/rda/energy/female/age/sedentary", rda)))));
+               else if(xp.evaluate("occupation", inNode).equals("moderate"))
+                   outNode.appendChild(output.createTextNode(String.valueOf(energy+Double.parseDouble(xp.evaluate("/rda/energy/female/age/moderate", rda)))));
+               else if(xp.evaluate("occupation", inNode).equals("heavy"))
+                   outNode.appendChild(output.createTextNode(String.valueOf(energy+Double.parseDouble(xp.evaluate("/rda/energy/female/age/heavy", rda)))));
+           }
+       }
+       totalEnergyRequirement=totalEnergyRequirement+Double.parseDouble(xp.evaluate(".", outNode));
+       
+       /*
+        * PROTEIN
+        */
+       
+       outNode=outNode.getParentNode();
+       outNode.appendChild(output.createElement("protein"));
+       outNode=outNode.getLastChild();
+       if(xp.evaluate("infant", inNode, XPathConstants.NODE) != null){
+           int age=Integer.parseInt(xp.evaluate("infant", inNode));
+           outNode.appendChild(output.createTextNode(xp.evaluate("/rda/protein/infant/age[@lower<="+age+"][@upper>"+age+"]", rda)));
+       }
+       else if(xp.evaluate("sex", inNode).equals("male")){
+           int age=Integer.parseInt(xp.evaluate("age", inNode));
+           if(age<18){
+               outNode.appendChild(output.createTextNode(xp.evaluate("/rda/protein/male/age[@lower<="+age+"][@upper>"+age+"]", rda)));
+           }
+           else{
+               outNode.appendChild(output.createTextNode(xp.evaluate("/rda/protein/male/age[@lower='18']", rda)));
+           }
+       }
+       else{
+           int age=Integer.parseInt(xp.evaluate("age", inNode));
+           if(age<18){
+               outNode.appendChild(output.createTextNode(xp.evaluate("/rda/protein/female/age[@lower<="+age+"][@upper>"+age+"]", rda)));
+           }
+           else{
+               if((boolean) xp.evaluate("pregnant", inNode, XPathConstants.BOOLEAN)){
+                   outNode.appendChild(output.createTextNode(xp.evaluate("/rda/protein/female/pregnant", rda)));
+               }
+               else if((boolean) xp.evaluate("lactating", inNode, XPathConstants.BOOLEAN)){
+                   if((boolean) xp.evaluate("beyond6m", inNode, XPathConstants.BOOLEAN))
+                       outNode.appendChild(output.createTextNode(xp.evaluate("/rda/protein/female/lactatingAbove6m", rda)));
+                   else
+                       outNode.appendChild(output.createTextNode(xp.evaluate("/rda/protein/female/lactatingBelow6m", rda)));
+               }
+               else
+                   outNode.appendChild(output.createTextNode(xp.evaluate("/rda/protein/female/age[@lower='18']", rda)));
+           }
+       }
+       totalProteinRequirement=totalProteinRequirement+Double.parseDouble(xp.evaluate(".", outNode));
+
+       /*
+        * IRON
+        */
+       
+       outNode=outNode.getParentNode();
+       outNode.appendChild(output.createElement("iron"));
+       outNode=outNode.getLastChild();
+       if(xp.evaluate("infant", inNode, XPathConstants.NODE) != null){
+           int age=Integer.parseInt(xp.evaluate("infant", inNode));
+           outNode.appendChild(output.createTextNode(xp.evaluate("/rda/iron/infant/age[@lower<="+age+"][@upper>="+age+"]", rda)));
+       }
+       else if(xp.evaluate("sex", inNode).equals("male")){
+           int age=Integer.parseInt(xp.evaluate("age", inNode));
+           if(age<18){
+               outNode.appendChild(output.createTextNode(xp.evaluate("/rda/iron/male/age[@lower<="+age+"][@upper>="+age+"]", rda)));
+           }
+           else{
+               outNode.appendChild(output.createTextNode(xp.evaluate("/rda/iron/male/age[@lower='18']", rda)));
+           }
+       }
+       else{
+           int age=Integer.parseInt(xp.evaluate("age", inNode));
+           if(age<18){
+               outNode.appendChild(output.createTextNode(xp.evaluate("/rda/iron/female/age[@lower<="+age+"][@upper>="+age+"]", rda)));
+           }
+           else{
+               if((boolean) xp.evaluate("pregnant", inNode, XPathConstants.BOOLEAN)){
+                   outNode.appendChild(output.createTextNode(xp.evaluate("/rda/iron/female/pregnant", rda)));
+               }
+               else if((boolean) xp.evaluate("lactating", inNode, XPathConstants.BOOLEAN)){
+                   if((boolean) xp.evaluate("beyond6m", inNode, XPathConstants.BOOLEAN))
+                       outNode.appendChild(output.createTextNode(xp.evaluate("/rda/iron/female/lactatingAbove6m", rda)));
+                   else
+                       outNode.appendChild(output.createTextNode(xp.evaluate("/rda/iron/female/lactatingBelow6m", rda)));
+               }
+               else
+                   outNode.appendChild(output.createTextNode(xp.evaluate("/rda/iron/female/age[@lower='18']", rda)));
+           }
+       }
+       totalIronRequirement=totalIronRequirement+Double.parseDouble(xp.evaluate(".", outNode));
+       /*
+        * vitA
+        */
+       
+       outNode=outNode.getParentNode();
+       outNode.appendChild(output.createElement("vitA"));
+       outNode=outNode.getLastChild();
+       if(xp.evaluate("infant", inNode, XPathConstants.NODE) != null){
+           int age=Integer.parseInt(xp.evaluate("infant", inNode));
+           outNode.appendChild(output.createTextNode(xp.evaluate("/rda/vitA/infant/age[@lower<="+age+"][@upper>="+age+"]", rda)));
+       }
+       else if(xp.evaluate("sex", inNode).equals("male")){
+           int age=Integer.parseInt(xp.evaluate("age", inNode));
+           if(age<18){
+               outNode.appendChild(output.createTextNode(xp.evaluate("/rda/vitA/male/age[@lower<="+age+"][@upper>="+age+"]", rda)));
+           }
+           else{
+               outNode.appendChild(output.createTextNode(xp.evaluate("/rda/vitA/male/age[@lower='18']", rda)));
+           }
+       }
+       else{
+           int age=Integer.parseInt(xp.evaluate("age", inNode));
+           if(age<18){
+               outNode.appendChild(output.createTextNode(xp.evaluate("/rda/vitA/female/age[@lower<="+age+"][@upper>="+age+"]", rda)));
+           }
+           else{
+               if((boolean) xp.evaluate("pregnant", inNode, XPathConstants.BOOLEAN)){
+                   outNode.appendChild(output.createTextNode(xp.evaluate("/rda/vitA/female/pregnant", rda)));
+               }
+               else if((boolean) xp.evaluate("lactating", inNode, XPathConstants.BOOLEAN)){
+                   if((boolean) xp.evaluate("beyond6m", inNode, XPathConstants.BOOLEAN))
+                       outNode.appendChild(output.createTextNode(xp.evaluate("/rda/vitA/female/lactatingAbove6m", rda)));
+                   else
+                       outNode.appendChild(output.createTextNode(xp.evaluate("/rda/vitA/female/lactatingBelow6m", rda)));
+               }
+               else
+                   outNode.appendChild(output.createTextNode(xp.evaluate("/rda/vitA/female/age[@lower='18']", rda)));
+           }
+       }
+       totalVitARequirement=totalVitARequirement+Double.parseDouble(xp.evaluate(".", outNode));
+       
+       /*
+        * THIAMINE
+        */
+       
+       outNode=outNode.getParentNode();
+       outNode.appendChild(output.createElement("thiamine"));
+       outNode=outNode.getLastChild();
+       if(xp.evaluate("infant", inNode, XPathConstants.NODE) != null){
+           int age=Integer.parseInt(xp.evaluate("infant", inNode));
+           outNode.appendChild(output.createTextNode(xp.evaluate("/rda/thiamine/infant/age[@lower<="+age+"][@upper>="+age+"]", rda)));
+       }
+       else if(xp.evaluate("sex", inNode).equals("male")){
+           int age=Integer.parseInt(xp.evaluate("age", inNode));
+           if(age<18){
+               outNode.appendChild(output.createTextNode(xp.evaluate("/rda/thiamine/male/age[@lower<="+age+"][@upper>="+age+"]", rda)));
+           }
+           else{
+               if(xp.evaluate("occupation", inNode).equals("sedentary")){
+                   outNode.appendChild(output.createTextNode(xp.evaluate("/rda/thiamine/male/age/sedentary", rda)));
+               }
+               else if(xp.evaluate("occupation", inNode).equals("moderate"))
+                   outNode.appendChild(output.createTextNode(xp.evaluate("/rda/thiamine/male/age/moderate", rda)));
+               else if(xp.evaluate("occupation", inNode).equals("heavy"))
+                   outNode.appendChild(output.createTextNode(xp.evaluate("/rda/thiamine/male/age/heavy", rda)));
+           }
+       }
+       else{
+           int age=Integer.parseInt(xp.evaluate("age", inNode));
+           double thiamine=0;
+           if(age<18){
+               outNode.appendChild(output.createTextNode(xp.evaluate("/rda/thiamine/female/age[@lower<="+age+"][@upper>="+age+"]", rda)));
+           }
+           else{
+               if((boolean) xp.evaluate("pregnant", inNode, XPathConstants.BOOLEAN)){
+                   thiamine=Double.parseDouble(xp.evaluate("/rda/thiamine/female/pregnantExtra", rda));
+               }
+               if((boolean) xp.evaluate("lactating", inNode, XPathConstants.BOOLEAN)){
+                   if((boolean) xp.evaluate("beyond6m", inNode, XPathConstants.BOOLEAN))
+                       thiamine=Double.parseDouble(xp.evaluate("/rda/thiamine/female/lactatingExtra/above6m", rda));
+                   else
+                       thiamine=Double.parseDouble(xp.evaluate("/rda/thiamine/female/lactatingExtra/below6m", rda));
+               }
+               if(xp.evaluate("occupation", inNode).equals("sedentary"))
+                   outNode.appendChild(output.createTextNode(String.valueOf(thiamine+Double.parseDouble(xp.evaluate("/rda/thiamine/female/age/sedentary", rda)))));
+               else if(xp.evaluate("occupation", inNode).equals("moderate"))
+                   outNode.appendChild(output.createTextNode(String.valueOf(thiamine+Double.parseDouble(xp.evaluate("/rda/thiamine/female/age/moderate", rda)))));
+               else if(xp.evaluate("occupation", inNode).equals("heavy"))
+                   outNode.appendChild(output.createTextNode(String.valueOf(thiamine+Double.parseDouble(xp.evaluate("/rda/thiamine/female/age/heavy", rda)))));
+           }
+       }
+       totalThiamineRequirement=totalThiamineRequirement+Double.parseDouble(xp.evaluate(".", outNode));
+
+       /*
+        * RIBOFLAVIN
+        */
+       
+       outNode=outNode.getParentNode();
+       outNode.appendChild(output.createElement("riboflavin"));
+       outNode=outNode.getLastChild();
+       if(xp.evaluate("infant", inNode, XPathConstants.NODE) != null){
+           int age=Integer.parseInt(xp.evaluate("infant", inNode));
+           outNode.appendChild(output.createTextNode(xp.evaluate("/rda/riboflavin/infant/age[@lower<="+age+"][@upper>="+age+"]", rda)));
+       }
+       else if(xp.evaluate("sex", inNode).equals("male")){
+           int age=Integer.parseInt(xp.evaluate("age", inNode));
+           if(age<18){
+               outNode.appendChild(output.createTextNode(xp.evaluate("/rda/riboflavin/male/age[@lower<="+age+"][@upper>="+age+"]", rda)));
+           }
+           else{
+               if(xp.evaluate("occupation", inNode).equals("sedentary")){
+                   outNode.appendChild(output.createTextNode(xp.evaluate("/rda/riboflavin/male/age/sedentary", rda)));
+               }
+               else if(xp.evaluate("occupation", inNode).equals("moderate"))
+                   outNode.appendChild(output.createTextNode(xp.evaluate("/rda/riboflavin/male/age/moderate", rda)));
+               else if(xp.evaluate("occupation", inNode).equals("heavy"))
+                   outNode.appendChild(output.createTextNode(xp.evaluate("/rda/riboflavin/male/age/heavy", rda)));
+           }
+       }
+       else{
+           int age=Integer.parseInt(xp.evaluate("age", inNode));
+           double riboflavin=0;
+           if(age<18){
+               outNode.appendChild(output.createTextNode(xp.evaluate("/rda/riboflavin/female/age[@lower<="+age+"][@upper>="+age+"]", rda)));
+           }
+           else{
+               if((boolean) xp.evaluate("pregnant", inNode, XPathConstants.BOOLEAN)){
+                   riboflavin=Double.parseDouble(xp.evaluate("/rda/riboflavin/female/pregnantExtra", rda));
+               }
+               if((boolean) xp.evaluate("lactating", inNode, XPathConstants.BOOLEAN)){
+                   if((boolean) xp.evaluate("beyond6m", inNode, XPathConstants.BOOLEAN))
+                       riboflavin=Double.parseDouble(xp.evaluate("/rda/riboflavin/female/lactatingExtra/above6m", rda));
+                   else
+                       riboflavin=Double.parseDouble(xp.evaluate("/rda/riboflavin/female/lactatingExtra/below6m", rda));
+               }
+               if(xp.evaluate("occupation", inNode).equals("sedentary"))
+                   outNode.appendChild(output.createTextNode(String.valueOf(riboflavin+Double.parseDouble(xp.evaluate("/rda/riboflavin/female/age/sedentary", rda)))));
+               else if(xp.evaluate("occupation", inNode).equals("moderate"))
+                   outNode.appendChild(output.createTextNode(String.valueOf(riboflavin+Double.parseDouble(xp.evaluate("/rda/riboflavin/female/age/moderate", rda)))));
+               else if(xp.evaluate("occupation", inNode).equals("heavy"))
+                   outNode.appendChild(output.createTextNode(String.valueOf(riboflavin+Double.parseDouble(xp.evaluate("/rda/riboflavin/female/age/heavy", rda)))));
+           }
+       }
+       totalRiboflavinRequirement=totalRiboflavinRequirement+Double.parseDouble(xp.evaluate(".", outNode));
+
+       /*
+        * VITAMIN-C
+        */
+       
+       outNode=outNode.getParentNode();
+       outNode.appendChild(output.createElement("vitC"));
+       outNode=outNode.getLastChild();
+       if(xp.evaluate("infant", inNode, XPathConstants.NODE) != null){
+           int age=Integer.parseInt(xp.evaluate("infant", inNode));
+           outNode.appendChild(output.createTextNode(xp.evaluate("/rda/vitC/infant/age[@lower<="+age+"][@upper>="+age+"]", rda)));
+       }
+       else if(xp.evaluate("sex", inNode).equals("male")){
+           int age=Integer.parseInt(xp.evaluate("age", inNode));
+           if(age<18){
+               outNode.appendChild(output.createTextNode(xp.evaluate("/rda/vitC/male/age[@lower<="+age+"][@upper>="+age+"]", rda)));
+           }
+           else{
+               outNode.appendChild(output.createTextNode(xp.evaluate("/rda/vitC/male/age[@lower='18']", rda)));
+           }
+       }
+       else{
+           int age=Integer.parseInt(xp.evaluate("age", inNode));
+           if(age<18){
+               outNode.appendChild(output.createTextNode(xp.evaluate("/rda/vitC/female/age[@lower<="+age+"][@upper>="+age+"]", rda)));
+           }
+           else{
+               if((boolean) xp.evaluate("pregnant", inNode, XPathConstants.BOOLEAN)){
+                   outNode.appendChild(output.createTextNode(xp.evaluate("/rda/vitC/female/pregnant", rda)));
+               }
+               else if((boolean) xp.evaluate("lactating", inNode, XPathConstants.BOOLEAN)){
+                   if((boolean) xp.evaluate("beyond6m", inNode, XPathConstants.BOOLEAN))
+                       outNode.appendChild(output.createTextNode(xp.evaluate("/rda/vitC/female/lactatingAbove6m", rda)));
+                   else
+                       outNode.appendChild(output.createTextNode(xp.evaluate("/rda/vitC/female/lactatingBelow6m", rda)));
+               }
+               else
+                   outNode.appendChild(output.createTextNode(xp.evaluate("/rda/vitC/female/age[@lower='18']", rda)));
+           }
+       }
+       totalVitCRequirement=totalVitCRequirement+Double.parseDouble(xp.evaluate(".", outNode));
+    }
+
+    /**
+     * 
+     * CONSUMPTION
+     * 
+     */
+    
+    private void calculateConsumption() throws XPathExpressionException{
+       Node node;
+       node=(Node) xp.evaluate("/assessment", output, XPathConstants.NODE);
+       node.appendChild(output.createElement("consumption"));
+       NodeList nl=(NodeList) xp.evaluate("/record/intake/food", input, XPathConstants.NODESET);
+       for(int i=0; i<nl.getLength(); i++){
+           perFoodNutrition(nl.item(i));
+       }
+       node=(Node) xp.evaluate("/assessment/consumption", output, XPathConstants.NODE);
+       node.appendChild(output.createElement("total"));
+       node=node.getLastChild();
+       node.appendChild(output.createElement("energy"));
+       node.getLastChild().appendChild(output.createTextNode(String.valueOf(totalEnergyConsumed)));
+       node.appendChild(output.createElement("protein"));
+       node.getLastChild().appendChild(output.createTextNode(String.valueOf(totalProteinConsumed)));
+       node.appendChild(output.createElement("iron"));
+       node.getLastChild().appendChild(output.createTextNode(String.valueOf(totalIronConsumed)));
+       node.appendChild(output.createElement("vitA"));
+       node.getLastChild().appendChild(output.createTextNode(String.valueOf(totalVitAConsumed)));
+       node.appendChild(output.createElement("thiamine"));
+       node.getLastChild().appendChild(output.createTextNode(String.valueOf(totalThiamineConsumed)));
+       node.appendChild(output.createElement("riboflavin"));
+       node.getLastChild().appendChild(output.createTextNode(String.valueOf(totalRiboflavinConsumed)));
+       node.appendChild(output.createElement("vitC"));
+       node.getLastChild().appendChild(output.createTextNode(String.valueOf(totalVitCConsumed)));
+    }
+    //Individual
+    private void perFoodNutrition(Node inNode) throws XPathExpressionException{
+       Node outNode=(Node) xp.evaluate("/assessment/consumption", output, XPathConstants.NODE);
+       outNode.appendChild(output.createElement("food"));
+       outNode=outNode.getLastChild();
+       outNode.appendChild(output.importNode((Node) xp.evaluate("name", inNode, XPathConstants.NODE), true));
+       
+       /*
+        * ENERGY
+        */
+       
+       outNode.appendChild(output.createElement("energy"));
+       double energy=Double.parseDouble(xp.evaluate("/foodList/food[name='"+xp.evaluate("name", inNode)+"']/energy", food))*Double.parseDouble(xp.evaluate("amount", inNode))/100;
+       outNode.getLastChild().appendChild(output.createTextNode(String.valueOf(energy)));
+       totalEnergyConsumed=totalEnergyConsumed+energy;
+
+       /*
+        * PROTEIN
+        */
+       
+       outNode.appendChild(output.createElement("protein"));
+       double protein=Double.parseDouble(xp.evaluate("/foodList/food[name='"+xp.evaluate("name", inNode)+"']/protein", food))*Double.parseDouble(xp.evaluate("amount", inNode))/100;
+       outNode.getLastChild().appendChild(output.createTextNode(String.valueOf(protein)));
+       totalProteinConsumed=totalProteinConsumed+protein;
+
+       /*
+        * IRON
+        */
+       
+       outNode.appendChild(output.createElement("iron"));
+       double iron=Double.parseDouble(xp.evaluate("/foodList/food[name='"+xp.evaluate("name", inNode)+"']/iron", food))*Double.parseDouble(xp.evaluate("amount", inNode))/100;
+       outNode.getLastChild().appendChild(output.createTextNode(String.valueOf(iron)));
+       totalIronConsumed=totalIronConsumed+iron;
+
+       /*
+        * VIT-A
+        */
+       
+       outNode.appendChild(output.createElement("vitA"));
+       double vitA=Double.parseDouble(xp.evaluate("/foodList/food[name='"+xp.evaluate("name", inNode)+"']/vitA", food))*Double.parseDouble(xp.evaluate("amount", inNode))/100;
+       outNode.getLastChild().appendChild(output.createTextNode(String.valueOf(vitA)));
+       totalVitAConsumed=totalVitAConsumed+vitA;
+
+       /*
+        * THIAMINE
+        */
+       
+       outNode.appendChild(output.createElement("thiamine"));
+       double thiamine=Double.parseDouble(xp.evaluate("/foodList/food[name='"+xp.evaluate("name", inNode)+"']/thiamine", food))*Double.parseDouble(xp.evaluate("amount", inNode))/100;
+       outNode.getLastChild().appendChild(output.createTextNode(String.valueOf(thiamine)));
+       totalThiamineConsumed=totalThiamineConsumed+thiamine;
+
+       /*
+        * RIBOFLAVIN
+        */
+       
+       outNode.appendChild(output.createElement("riboflavin"));
+       double riboflavin=Double.parseDouble(xp.evaluate("/foodList/food[name='"+xp.evaluate("name", inNode)+"']/riboflavin", food))*Double.parseDouble(xp.evaluate("amount", inNode))/100;
+       outNode.getLastChild().appendChild(output.createTextNode(String.valueOf(riboflavin)));
+       totalRiboflavinConsumed=totalRiboflavinConsumed+riboflavin;
+
+       /*
+        * VIT-C
+        */
+       
+       outNode.appendChild(output.createElement("vitC"));
+       double vitC=Double.parseDouble(xp.evaluate("/foodList/food[name='"+xp.evaluate("name", inNode)+"']/vitC", food))*Double.parseDouble(xp.evaluate("amount", inNode))/100;
+       outNode.getLastChild().appendChild(output.createTextNode(String.valueOf(vitC)));
+       totalVitCConsumed=totalVitCConsumed+vitC;
+    }
+    
+    /**
+     * 
+     * STATUS
+     * 
+     */
+    
+    private void calculateStatus() throws XPathExpressionException{
+       Node node;
+       node=(Node) xp.evaluate("/assessment", output, XPathConstants.NODE);
+       node.appendChild(output.createElement("nutritionalStatus"));
+       node=node.getLastChild();
+       
+       //ENERGY
+       node.appendChild(output.createElement("energy"));
+       node=node.getLastChild();
+       double energyR=Double.parseDouble(xp.evaluate("/assessment/requirement/total/energy", output));
+       double energyC=Double.parseDouble(xp.evaluate("/assessment/consumption/total/energy", output));
+       if(energyR>=energyC){
+           node.appendChild(output.createElement("status"));
+           node.getLastChild().appendChild(output.createTextNode("deficient"));
+           node.appendChild(output.createElement("amount"));
+           node.getLastChild().appendChild(output.createTextNode(String.valueOf(energyR-energyC)));
+           node.appendChild(output.createElement("percentage"));
+           node.getLastChild().appendChild(output.createTextNode(String.valueOf((energyR-energyC)*100/energyR)));
+       }
+       else{
+           node.appendChild(output.createElement("status"));
+           node.getLastChild().appendChild(output.createTextNode("excess"));
+           node.appendChild(output.createElement("amount"));
+           node.getLastChild().appendChild(output.createTextNode(String.valueOf(energyC-energyR)));
+           node.appendChild(output.createElement("percentage"));
+           node.getLastChild().appendChild(output.createTextNode(String.valueOf((energyC-energyR)*100/energyR)));
+       }
+       //PROTEIN
+       node=node.getParentNode();
+       node.appendChild(output.createElement("protein"));
+       node=node.getLastChild();
+       double proteinR=Double.parseDouble(xp.evaluate("/assessment/requirement/total/protein", output));
+       double proteinC=Double.parseDouble(xp.evaluate("/assessment/consumption/total/protein", output));
+       if(proteinR>=proteinC){
+           node.appendChild(output.createElement("status"));
+           node.getLastChild().appendChild(output.createTextNode("deficient"));
+           node.appendChild(output.createElement("amount"));
+           node.getLastChild().appendChild(output.createTextNode(String.valueOf(proteinR-proteinC)));
+           node.appendChild(output.createElement("percentage"));
+           node.getLastChild().appendChild(output.createTextNode(String.valueOf((proteinR-proteinC)*100/proteinR)));
+       }
+       else{
+           node.appendChild(output.createElement("status"));
+           node.getLastChild().appendChild(output.createTextNode("excess"));
+           node.appendChild(output.createElement("amount"));
+           node.getLastChild().appendChild(output.createTextNode(String.valueOf(proteinC-proteinR)));
+           node.appendChild(output.createElement("percentage"));
+           node.getLastChild().appendChild(output.createTextNode(String.valueOf((proteinC-proteinR)*100/proteinR)));
+       }
+       //IRON
+       node=node.getParentNode();
+       node.appendChild(output.createElement("iron"));
+       node=node.getLastChild();
+       double ironR=Double.parseDouble(xp.evaluate("/assessment/requirement/total/iron", output));
+       double ironC=Double.parseDouble(xp.evaluate("/assessment/consumption/total/iron", output));
+       if(ironR>=ironC){
+           node.appendChild(output.createElement("status"));
+           node.getLastChild().appendChild(output.createTextNode("deficient"));
+           node.appendChild(output.createElement("amount"));
+           node.getLastChild().appendChild(output.createTextNode(String.valueOf(ironR-ironC)));
+           node.appendChild(output.createElement("percentage"));
+           node.getLastChild().appendChild(output.createTextNode(String.valueOf((ironR-ironC)*100/ironR)));
+       }
+       else{
+           node.appendChild(output.createElement("status"));
+           node.getLastChild().appendChild(output.createTextNode("excess"));
+           node.appendChild(output.createElement("amount"));
+           node.getLastChild().appendChild(output.createTextNode(String.valueOf(ironC-ironR)));
+           node.appendChild(output.createElement("percentage"));
+           node.getLastChild().appendChild(output.createTextNode(String.valueOf((ironC-ironR)*100/ironR)));
+       }
+       //VIT-A
+       node=node.getParentNode();
+       node.appendChild(output.createElement("vitA"));
+       node=node.getLastChild();
+       double vitAR=Double.parseDouble(xp.evaluate("/assessment/requirement/total/vitA", output));
+       double vitAC=Double.parseDouble(xp.evaluate("/assessment/consumption/total/vitA", output));
+       if(vitAR>=vitAC){
+           node.appendChild(output.createElement("status"));
+           node.getLastChild().appendChild(output.createTextNode("deficient"));
+           node.appendChild(output.createElement("amount"));
+           node.getLastChild().appendChild(output.createTextNode(String.valueOf(vitAR-vitAC)));
+           node.appendChild(output.createElement("percentage"));
+           node.getLastChild().appendChild(output.createTextNode(String.valueOf((vitAR-vitAC)*100/vitAR)));
+       }
+       else{
+           node.appendChild(output.createElement("status"));
+           node.getLastChild().appendChild(output.createTextNode("excess"));
+           node.appendChild(output.createElement("amount"));
+           node.getLastChild().appendChild(output.createTextNode(String.valueOf(vitAC-vitAR)));
+           node.appendChild(output.createElement("percentage"));
+           node.getLastChild().appendChild(output.createTextNode(String.valueOf((vitAC-vitAR)*100/vitAR)));
+       }
+       //THIAMINE
+       node=node.getParentNode();
+       node.appendChild(output.createElement("thiamine"));
+       node=node.getLastChild();
+       double thiamineR=Double.parseDouble(xp.evaluate("/assessment/requirement/total/thiamine", output));
+       double thiamineC=Double.parseDouble(xp.evaluate("/assessment/consumption/total/thiamine", output));
+       if(thiamineR>=thiamineC){
+           node.appendChild(output.createElement("status"));
+           node.getLastChild().appendChild(output.createTextNode("deficient"));
+           node.appendChild(output.createElement("amount"));
+           node.getLastChild().appendChild(output.createTextNode(String.valueOf(thiamineR-thiamineC)));
+           node.appendChild(output.createElement("percentage"));
+           node.getLastChild().appendChild(output.createTextNode(String.valueOf((thiamineR-thiamineC)*100/thiamineR)));
+       }
+       else{
+           node.appendChild(output.createElement("status"));
+           node.getLastChild().appendChild(output.createTextNode("excess"));
+           node.appendChild(output.createElement("amount"));
+           node.getLastChild().appendChild(output.createTextNode(String.valueOf(thiamineC-thiamineR)));
+           node.appendChild(output.createElement("percentage"));
+           node.getLastChild().appendChild(output.createTextNode(String.valueOf((thiamineC-thiamineR)*100/thiamineR)));
+       }
+       //RIBOFLAVIN
+       node=node.getParentNode();
+       node.appendChild(output.createElement("riboflavin"));
+       node=node.getLastChild();
+       double riboflavinR=Double.parseDouble(xp.evaluate("/assessment/requirement/total/riboflavin", output));
+       double riboflavinC=Double.parseDouble(xp.evaluate("/assessment/consumption/total/riboflavin", output));
+       if(riboflavinR>=riboflavinC){
+           node.appendChild(output.createElement("status"));
+           node.getLastChild().appendChild(output.createTextNode("deficient"));
+           node.appendChild(output.createElement("amount"));
+           node.getLastChild().appendChild(output.createTextNode(String.valueOf(riboflavinR-riboflavinC)));
+           node.appendChild(output.createElement("percentage"));
+           node.getLastChild().appendChild(output.createTextNode(String.valueOf((riboflavinR-riboflavinC)*100/riboflavinR)));
+       }
+       else{
+           node.appendChild(output.createElement("status"));
+           node.getLastChild().appendChild(output.createTextNode("excess"));
+           node.appendChild(output.createElement("amount"));
+           node.getLastChild().appendChild(output.createTextNode(String.valueOf(riboflavinC-riboflavinR)));
+           node.appendChild(output.createElement("percentage"));
+           node.getLastChild().appendChild(output.createTextNode(String.valueOf((riboflavinC-riboflavinR)*100/riboflavinR)));
+       }
+       //VITAMIN-C
+       node=node.getParentNode();
+       node.appendChild(output.createElement("vitC"));
+       node=node.getLastChild();
+       double vitCR=Double.parseDouble(xp.evaluate("/assessment/requirement/total/vitC", output));
+       double vitCC=Double.parseDouble(xp.evaluate("/assessment/consumption/total/vitC", output));
+       if(vitCR>=vitCC){
+           node.appendChild(output.createElement("status"));
+           node.getLastChild().appendChild(output.createTextNode("deficient"));
+           node.appendChild(output.createElement("amount"));
+           node.getLastChild().appendChild(output.createTextNode(String.valueOf(vitCR-vitCC)));
+           node.appendChild(output.createElement("percentage"));
+           node.getLastChild().appendChild(output.createTextNode(String.valueOf((vitCR-vitCC)*100/vitCR)));
+       }
+       else{
+           node.appendChild(output.createElement("status"));
+           node.getLastChild().appendChild(output.createTextNode("excess"));
+           node.appendChild(output.createElement("amount"));
+           node.getLastChild().appendChild(output.createTextNode(String.valueOf(vitCC-vitCR)));
+           node.appendChild(output.createElement("percentage"));
+           node.getLastChild().appendChild(output.createTextNode(String.valueOf((vitCC-vitCR)*100/vitCR)));
+       }
+    }
+    
+    public InputStream getGraphImage() throws IOException{
+       InputStream is;
+       NutrientGraph ng=new NutrientGraph((totalEnergyConsumed/totalEnergyRequirement)*100, (totalProteinConsumed/totalProteinRequirement)*100,
+               (totalIronConsumed/totalIronRequirement)*100, (totalVitAConsumed/totalVitARequirement)*100, (totalThiamineConsumed/totalThiamineRequirement)*100,
+               (totalRiboflavinConsumed/totalRiboflavinRequirement)*100, (totalVitCConsumed/totalVitCRequirement)*100);
+       JFrame frame = new JFrame();
+       frame.setBackground(Color.white);
+       frame.setUndecorated(true);
+       frame.getContentPane().add(ng);
+       frame.pack();
+       frame.setVisible(true);
+       BufferedImage image = new BufferedImage(ng.getWidth(), ng.getHeight(), BufferedImage.TYPE_INT_ARGB);
+       Graphics2D graphics = image.createGraphics();
+       ng.print(graphics);
+       is=ng.getAsInputStream();
+       graphics.dispose();
+       frame.dispose();
+       return is;
+    }
+}
diff --git a/com/agnibho/code/dietSurvey/CustomFood.java b/com/agnibho/code/dietSurvey/CustomFood.java
new file mode 100644 (file)
index 0000000..52d3f44
--- /dev/null
@@ -0,0 +1,376 @@
+/*
+    Diet-Survey: Perform diet survey based on 24 hours recall
+    Copyright (C) 2013  Agnibho Mondal
+    
+    This file is part of Diet-Survey.
+
+    Diet-Survey 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.
+
+    Diet-Survey 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 Diet-Survey.  If not, see <http://www.gnu.org/licenses/>.
+*/
+package com.agnibho.code.dietSurvey;
+
+import java.awt.Dimension;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.File;
+import java.io.IOException;
+
+import javax.swing.GroupLayout;
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JTextField;
+import javax.swing.SwingConstants;
+import javax.swing.WindowConstants;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpressionException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+@SuppressWarnings("serial")
+public class CustomFood extends JFrame implements ActionListener {
+    private static final String newFood="***Add New Food Item";
+
+    GroupLayout layout;
+
+    File file;
+    DocHandler dh;
+    Document doc;
+    XPath xp=DocHandler.getXpInstance();
+    Node node;
+
+    JLabel heading;
+    JComboBox<String> listBox;
+    JButton save;
+    JButton remove;
+    JLabel nameLabel;
+    JTextField nameField;
+    JLabel groupLabel;
+    JComboBox<String> groupBox;
+    JLabel energyLabel;
+    JTextField energyField;
+    JLabel proteinLabel;
+    JTextField proteinField;
+    JLabel ironLabel;
+    JTextField ironField;
+    JLabel vitALabel;
+    JTextField vitAField;
+    JLabel thiamineLabel;
+    JTextField thiamineField;
+    JLabel riboflavinLabel;
+    JTextField riboflavinField;
+    JLabel vitCLabel;
+    JTextField vitCField;
+
+    String[] foodList;
+    String[] groups={"Cereals", "Pulses", "Green leafy vegetables", "Roots and tubers", "Other vegetatables",
+           "Fruits", "Milk and milk products", "Flesh foods", "Fats and oils", "Sugar and jaggery", "Nuts and oilseeds", "Spices and condiments",
+           "Miscellaneous"};
+
+    public CustomFood() throws TransformerConfigurationException, ParserConfigurationException, SAXException, IOException, XPathExpressionException {
+       file=new File(UI.LOC+File.separator+"custom_food.xml");
+       dh=new DocHandler();
+       if(file.exists())
+           doc=new DocHandler().getValidatedDocument(new File(UI.LOC+File.separator+"custom_food.xml"), java.lang.ClassLoader.getSystemResourceAsStream("com/agnibho/code/resources/customFood.xsd"));
+       else{
+           doc=dh.getDocInstance();
+           doc.appendChild(doc.createElement("foodList"));
+       }
+       NodeList nl=(NodeList) xp.evaluate("/foodList/food", doc, XPathConstants.NODESET);
+       foodList=new String[nl.getLength()+1];
+       foodList[0]=newFood;
+       for(int i=0; i<nl.getLength(); i++){
+           foodList[i+1]=xp.evaluate("name", nl.item(i));
+       }
+
+
+       listBox=new JComboBox<String>(foodList);
+       listBox.setActionCommand("select");
+       listBox.addActionListener(this);
+       listBox.setPreferredSize(new Dimension(100, 40));
+
+       save=new JButton("Save");
+       save.setActionCommand("save");
+       save.addActionListener(this);
+
+       remove=new JButton("Remove");
+       remove.setEnabled(false);
+       remove.setActionCommand("remove");
+       remove.addActionListener(this);
+
+       heading=new JLabel("<html><h2>Enter Food Details</h2></html>", SwingConstants.CENTER);
+       heading.setPreferredSize(new Dimension(200, 40));
+
+       nameLabel=new JLabel("<html><b>Enter Name:</b></html>");
+       nameLabel.setPreferredSize(new Dimension(200, 20));
+       nameField=new JTextField(30);
+       nameField.setMaximumSize(new Dimension(Integer.MAX_VALUE, 30));
+
+       groupLabel=new JLabel("<html><b>Food Group:</b></html>");
+       nameLabel.setPreferredSize(new Dimension(200, 20));
+       groupBox=new JComboBox<String>(groups);
+       groupBox.setMaximumSize(new Dimension(Integer.MAX_VALUE, 30));
+
+       energyLabel=new JLabel("<html><b>Energy(kcal/100g):</b></html>");
+       energyLabel.setPreferredSize(new Dimension(200, 20));
+       energyField=new JTextField(30);
+       energyField.setMaximumSize(new Dimension(Integer.MAX_VALUE, 30));
+
+       proteinLabel=new JLabel("<html><b>Protein(g/100g)</b></html>");
+       proteinLabel.setPreferredSize(new Dimension(200, 20));
+       proteinField=new JTextField(30);
+       proteinField.setMaximumSize(new Dimension(Integer.MAX_VALUE, 30));
+
+       ironLabel=new JLabel("<html><b>Iron(mg/100g)</b></html>");
+       ironLabel.setPreferredSize(new Dimension(200, 20));
+       ironField=new JTextField(30);
+       ironField.setMaximumSize(new Dimension(Integer.MAX_VALUE, 30));
+
+       vitALabel=new JLabel("<html><b>Vitamin A(mcg/100g):</b></html>");
+       vitALabel.setPreferredSize(new Dimension(200, 20));
+       vitAField=new JTextField(30);
+       vitAField.setMaximumSize(new Dimension(Integer.MAX_VALUE, 30));
+
+       thiamineLabel=new JLabel("<html><b>Thiamine(mg/100g):</b></html>");
+       thiamineLabel.setPreferredSize(new Dimension(200, 20));
+       thiamineField=new JTextField(30);
+       thiamineField.setMaximumSize(new Dimension(Integer.MAX_VALUE, 30));
+
+       riboflavinLabel=new JLabel("<html><b>Riboflavin(mg/100g)</b></html>");
+       riboflavinLabel.setPreferredSize(new Dimension(200, 20));
+       riboflavinField=new JTextField(30);
+       riboflavinField.setMaximumSize(new Dimension(Integer.MAX_VALUE, 30));
+
+       vitCLabel=new JLabel("<html><b>Vitamin C(mg/100g):</b></html>");
+       vitCLabel.setPreferredSize(new Dimension(200, 20));
+       vitCField=new JTextField(30);
+       vitCField.setMaximumSize(new Dimension(Integer.MAX_VALUE, 30));
+
+       layout=new GroupLayout(getContentPane());
+       getContentPane().setLayout(layout);
+       layout.setAutoCreateGaps(true);
+       layout.setAutoCreateContainerGaps(true);
+       layout.setVerticalGroup(layout.createSequentialGroup()
+               .addComponent(heading)
+               .addGroup(layout.createParallelGroup()
+                       .addComponent(listBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
+                       .addComponent(save)
+                       .addComponent(remove))
+                       .addGroup(layout.createParallelGroup()
+                               .addComponent(nameLabel)
+                               .addComponent(nameField))
+                               .addGroup(layout.createParallelGroup()
+                                       .addComponent(groupLabel)
+                                       .addComponent(groupBox))
+                                       .addGroup(layout.createParallelGroup()
+                                               .addComponent(energyLabel)
+                                               .addComponent(energyField))
+                                               .addGroup(layout.createParallelGroup()
+                                                       .addComponent(proteinLabel)
+                                                       .addComponent(proteinField))
+                                                       .addGroup(layout.createParallelGroup()
+                                                               .addComponent(ironLabel)
+                                                               .addComponent(ironField))
+                                                               .addGroup(layout.createParallelGroup()
+                                                                       .addComponent(vitALabel)
+                                                                       .addComponent(vitAField))
+                                                                       .addGroup(layout.createParallelGroup()
+                                                                               .addComponent(thiamineLabel)
+                                                                               .addComponent(thiamineField))
+                                                                               .addGroup(layout.createParallelGroup()
+                                                                                       .addComponent(riboflavinLabel)
+                                                                                       .addComponent(riboflavinField))
+                                                                                       .addGroup(layout.createParallelGroup()
+                                                                                               .addComponent(vitCLabel)
+                                                                                               .addComponent(vitCField))
+               );
+       layout.setHorizontalGroup(layout.createParallelGroup()
+               .addComponent(heading)
+               .addGroup(layout.createSequentialGroup()
+                       .addComponent(listBox)
+                       .addComponent(save)
+                       .addComponent(remove))
+                       .addGroup(layout.createSequentialGroup()
+                               .addComponent(nameLabel)
+                               .addComponent(nameField))
+                               .addGroup(layout.createSequentialGroup()
+                                       .addComponent(groupLabel)
+                                       .addComponent(groupBox))
+                                       .addGroup(layout.createSequentialGroup()
+                                               .addComponent(energyLabel)
+                                               .addComponent(energyField))
+                                               .addGroup(layout.createSequentialGroup()
+                                                       .addComponent(proteinLabel)
+                                                       .addComponent(proteinField))
+                                                       .addGroup(layout.createSequentialGroup()
+                                                               .addComponent(ironLabel)
+                                                               .addComponent(ironField))
+                                                               .addGroup(layout.createSequentialGroup()
+                                                                       .addComponent(vitALabel)
+                                                                       .addComponent(vitAField))
+                                                                       .addGroup(layout.createSequentialGroup()
+                                                                               .addComponent(thiamineLabel)
+                                                                               .addComponent(thiamineField))
+                                                                               .addGroup(layout.createSequentialGroup()
+                                                                                       .addComponent(riboflavinLabel)
+                                                                                       .addComponent(riboflavinField))
+                                                                                       .addGroup(layout.createSequentialGroup()
+                                                                                               .addComponent(vitCLabel)
+                                                                                               .addComponent(vitCField))
+               );
+       layout.linkSize(nameLabel, groupLabel, energyLabel, proteinLabel, ironLabel, vitALabel, thiamineLabel, riboflavinLabel, vitCLabel);
+       layout.linkSize(SwingConstants.VERTICAL, listBox, save, remove);
+       layout.linkSize(SwingConstants.HORIZONTAL, save, remove);
+
+       setTitle("Custom Food Item");
+       pack();
+       setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
+       setSize(600, 480);
+       setLocationRelativeTo(null);
+       setResizable(false);
+       setAlwaysOnTop(true);
+    }
+
+    private boolean isComplete(){
+       String name=nameField.getText().trim();
+       name=name.replaceAll("\\s+", " ");
+       if(!(name.length()>0)){
+           JOptionPane.showMessageDialog(this, "Please enter the name of the food.", "Error", JOptionPane.ERROR_MESSAGE);
+           return false;
+       }
+       try{
+           Double.parseDouble(energyField.getText());
+           Double.parseDouble(proteinField.getText());
+           Double.parseDouble(ironField.getText());
+           Double.parseDouble(vitAField.getText());
+           Double.parseDouble(thiamineField.getText());
+           Double.parseDouble(riboflavinField.getText());
+           Double.parseDouble(vitCField.getText());
+       }catch(NumberFormatException e){
+           JOptionPane.showMessageDialog(this, "Invalid number detected.\nPlease try again.", "Error", JOptionPane.ERROR_MESSAGE);
+           return false;
+       }
+       nameField.setText(name);
+       return true;
+    }
+
+    @Override
+    public void actionPerformed(ActionEvent ae) {
+       try{
+           if(ae.getActionCommand().equals("select")){
+               if(listBox.getSelectedItem().equals(newFood)){
+                   remove.setEnabled(false);
+                   nameField.setEditable(true);
+                   nameField.setText("");
+                   groupBox.setSelectedIndex(0);;
+                   energyField.setText("");
+                   proteinField.setText("");
+                   ironField.setText("");
+                   vitAField.setText("");
+                   thiamineField.setText("");
+                   riboflavinField.setText("");
+                   vitCField.setText("");
+               }
+               else{
+                   String name=listBox.getSelectedItem().toString();
+                   remove.setEnabled(true);
+                   nameField.setEditable(false);
+                   nameField.setText(xp.evaluate("foodList/food[name='"+name+"']/name", doc));
+                   groupBox.setSelectedItem(xp.evaluate("foodList/food[name='"+name+"']/group", doc));
+                   energyField.setText(xp.evaluate("foodList/food[name='"+name+"']/energy", doc));
+                   proteinField.setText(xp.evaluate("foodList/food[name='"+name+"']/protein", doc));
+                   ironField.setText(xp.evaluate("foodList/food[name='"+name+"']/iron", doc));
+                   vitAField.setText(xp.evaluate("foodList/food[name='"+name+"']/vitA", doc));
+                   thiamineField.setText(xp.evaluate("foodList/food[name='"+name+"']/thiamine", doc));
+                   riboflavinField.setText(xp.evaluate("foodList/food[name='"+name+"']/riboflavin", doc));
+                   vitCField.setText(xp.evaluate("foodList/food[name='"+name+"']/vitC", doc));
+               }
+           }
+           else if(ae.getActionCommand().equals("save")){
+               if(isComplete()){
+                   if(listBox.getSelectedItem().equals(newFood)){
+                       node=(Node) xp.evaluate("/foodList", doc, XPathConstants.NODE);
+                       node.appendChild(doc.createElement("food"));
+                       node=node.getLastChild();
+                       node.appendChild(doc.createElement("name"));
+                       node.getLastChild().appendChild(doc.createTextNode(nameField.getText().trim()));
+                       node.appendChild(doc.createElement("group"));
+                       node.getLastChild().appendChild(doc.createTextNode(groupBox.getSelectedItem().toString()));
+                       node.appendChild(doc.createElement("energy"));
+                       node.getLastChild().appendChild(doc.createTextNode(energyField.getText().trim()));
+                       node.appendChild(doc.createElement("protein"));
+                       node.getLastChild().appendChild(doc.createTextNode(proteinField.getText().trim()));
+                       node.appendChild(doc.createElement("iron"));
+                       node.getLastChild().appendChild(doc.createTextNode(ironField.getText().trim()));
+                       node.appendChild(doc.createElement("vitA"));
+                       node.getLastChild().appendChild(doc.createTextNode(vitAField.getText().trim()));
+                       node.appendChild(doc.createElement("thiamine"));
+                       node.getLastChild().appendChild(doc.createTextNode(thiamineField.getText().trim()));
+                       node.appendChild(doc.createElement("riboflavin"));
+                       node.getLastChild().appendChild(doc.createTextNode(riboflavinField.getText().trim()));
+                       node.appendChild(doc.createElement("vitC"));
+                       node.getLastChild().appendChild(doc.createTextNode(vitCField.getText().trim()));
+                       listBox.addItem(nameField.getText().toString());
+                       listBox.setSelectedItem(nameField.getText().toString());
+                   }
+                   else{
+                       node=(Node) xp.evaluate("/foodList/food['"+nameField.getText()+"']", doc, XPathConstants.NODE);
+                       node.getParentNode().removeChild(node);
+                       node=(Node) xp.evaluate("/foodList", doc, XPathConstants.NODE);
+                       node.appendChild(doc.createElement("food"));
+                       node=node.getLastChild();
+                       node.appendChild(doc.createElement("name"));
+                       node.getLastChild().appendChild(doc.createTextNode(nameField.getText().trim()));
+                       node.appendChild(doc.createElement("group"));
+                       node.getLastChild().appendChild(doc.createTextNode(groupBox.getSelectedItem().toString()));
+                       node.appendChild(doc.createElement("energy"));
+                       node.getLastChild().appendChild(doc.createTextNode(energyField.getText().trim()));
+                       node.appendChild(doc.createElement("protein"));
+                       node.getLastChild().appendChild(doc.createTextNode(proteinField.getText().trim()));
+                       node.appendChild(doc.createElement("iron"));
+                       node.getLastChild().appendChild(doc.createTextNode(ironField.getText().trim()));
+                       node.appendChild(doc.createElement("vitA"));
+                       node.getLastChild().appendChild(doc.createTextNode(vitAField.getText().trim()));
+                       node.appendChild(doc.createElement("thiamine"));
+                       node.getLastChild().appendChild(doc.createTextNode(thiamineField.getText().trim()));
+                       node.appendChild(doc.createElement("riboflavin"));
+                       node.getLastChild().appendChild(doc.createTextNode(riboflavinField.getText().trim()));
+                       node.appendChild(doc.createElement("vitC"));
+                       node.getLastChild().appendChild(doc.createTextNode(vitCField.getText().trim()));
+                   }
+                   dh.writeToDisk(doc, file);
+                   listBox.setSelectedItem(nameField.getText().toString());
+               }
+           }
+           else if(ae.getActionCommand().equals("remove")){
+               node=(Node) xp.evaluate("/foodList/food['"+nameField.getText().toString()+"']", doc, XPathConstants.NODE);
+               node.getParentNode().removeChild(node);
+               dh.writeToDisk(doc, file);
+               listBox.removeItem(nameField.getText().toString());
+           }
+       } catch (XPathExpressionException | TransformerException e) {
+           JOptionPane.showMessageDialog(this, "An error has occured.\n"+e.toString(), "Error", JOptionPane.ERROR_MESSAGE);
+           e.printStackTrace();
+       }
+    }
+
+}
diff --git a/com/agnibho/code/dietSurvey/DocHandler.java b/com/agnibho/code/dietSurvey/DocHandler.java
new file mode 100644 (file)
index 0000000..640f77e
--- /dev/null
@@ -0,0 +1,150 @@
+/*
+    Diet-Survey: Perform diet survey based on 24 hours recall
+    Copyright (C) 2013  Agnibho Mondal
+    
+    This file is part of Diet-Survey.
+
+    Diet-Survey 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.
+
+    Diet-Survey 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 Diet-Survey.  If not, see <http://www.gnu.org/licenses/>.
+*/
+package com.agnibho.code.dietSurvey;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerFactoryConfigurationError;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathFactory;
+
+import org.w3c.dom.Document;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+public class DocHandler {
+    static final String JAXP_SCHEMA_LANGUAGE="http://java.sun.com/xml/jaxp/properties/schemaLanguage";
+    static final String W3C_XML_SCHEMA="http://www.w3.org/2001/XMLSchema";
+    static final String JAXP_SCHEMA_SOURCE ="http://java.sun.com/xml/jaxp/properties/schemaSource";
+    
+    private DocumentBuilderFactory dbf;
+    private DocumentBuilder db;
+    private static XPathFactory xpf;
+    
+    private TransformerFactory tff;
+    private Transformer tf;
+
+    public DocHandler() throws ParserConfigurationException, TransformerConfigurationException {
+       dbf=DocumentBuilderFactory.newInstance();
+       db=dbf.newDocumentBuilder();
+       xpf=XPathFactory.newInstance();
+       
+       tff=TransformerFactory.newInstance();
+       tf=tff.newTransformer();
+       tf.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
+       tf.setOutputProperty(OutputKeys.INDENT, "yes");
+    }
+
+    public Document getDocInstance(){
+       return db.newDocument();
+    }
+    public Document getDocument(InputStream in) throws SAXException, IOException{
+       return db.parse(in);
+    }
+    public Document getDocument(File file) throws SAXException, IOException{
+       return db.parse(file);
+    }
+    public Document getValidatedDocument(File file, InputStream schema) throws ParserConfigurationException, SAXException, IOException{
+       DocumentBuilderFactory vDbf=DocumentBuilderFactory.newInstance();
+       vDbf.setValidating(true);
+       vDbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
+       vDbf.setAttribute(JAXP_SCHEMA_SOURCE, schema);
+       DocumentBuilder vDb=vDbf.newDocumentBuilder();
+       vDb.setErrorHandler(new EH());
+       Document doc=vDb.parse(file);
+       return doc;
+    }
+    public static XPath getXpInstance(){
+       return xpf.newXPath();
+    }
+    public void writeToDisk(Document doc, File file) throws TransformerException{
+       DOMSource source=new DOMSource(doc);
+       StreamResult result=new StreamResult(file);
+       tf.transform(source, result);
+    }
+    public InputStream getAsInputStream(Document doc) throws TransformerConfigurationException, TransformerException, TransformerFactoryConfigurationError, UnsupportedEncodingException{
+       DOMSource source=new DOMSource(doc);
+       StringWriter writer=new StringWriter();
+       StreamResult result=new StreamResult(writer);
+       tf.transform(source, result);
+       ByteArrayInputStream inputStream = new ByteArrayInputStream(writer.toString().getBytes("UTF-8"));
+       return inputStream;
+    }
+    public InputStream generateSummary(Document doc) throws TransformerException, UnsupportedEncodingException{
+       DOMSource source=new DOMSource(doc);
+       StringWriter writer=new StringWriter();
+       StreamResult result=new StreamResult(writer);
+       Transformer trans=tff.newTransformer(new StreamSource(java.lang.ClassLoader.getSystemResourceAsStream("com/agnibho/code/resources/summary.xsl")));
+       trans.transform(source, result);
+       ByteArrayInputStream inputStream = new ByteArrayInputStream(writer.toString().getBytes("UTF-8"));
+       return inputStream;
+    }
+    public InputStream generateReport(Document input, Document assess) throws TransformerException, UnsupportedEncodingException{
+       DOMSource source=new DOMSource(combine(input, assess));
+       StringWriter writer=new StringWriter();
+       StreamResult result=new StreamResult(writer);
+       Transformer trans=tff.newTransformer(new StreamSource(java.lang.ClassLoader.getSystemResourceAsStream("com/agnibho/code/resources/style.xsl")));
+       trans.transform(source, result);
+       ByteArrayInputStream inputStream = new ByteArrayInputStream(writer.toString().getBytes("UTF-8"));
+       return inputStream;
+    }
+    public Document combine(Document in1, Document in2){
+       Document out=getDocInstance();
+       out.appendChild(out.createElement("ds"));
+       out.getFirstChild().appendChild(out.importNode(in1.getFirstChild(), true));
+       out.getFirstChild().appendChild(out.importNode(in2.getFirstChild(), true));
+       return out;
+    }
+    
+    private class EH implements ErrorHandler {
+
+       @Override
+       public void error(SAXParseException exception) throws SAXException {
+           throw new SAXException();
+       }
+
+       @Override
+       public void fatalError(SAXParseException exception) throws SAXException {
+           throw new SAXException();
+       }
+
+       @Override
+       public void warning(SAXParseException exception) throws SAXException {
+           throw new SAXException();
+       }
+    }
+}
diff --git a/com/agnibho/code/dietSurvey/FoodPanel.java b/com/agnibho/code/dietSurvey/FoodPanel.java
new file mode 100644 (file)
index 0000000..dd9679a
--- /dev/null
@@ -0,0 +1,286 @@
+/*
+    Diet-Survey: Perform diet survey based on 24 hours recall
+    Copyright (C) 2013  Agnibho Mondal
+    
+    This file is part of Diet-Survey.
+
+    Diet-Survey 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.
+
+    Diet-Survey 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 Diet-Survey.  If not, see <http://www.gnu.org/licenses/>.
+*/
+package com.agnibho.code.dietSurvey;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import javax.swing.BorderFactory;
+import javax.swing.GroupLayout;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTextField;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpressionException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+@SuppressWarnings("serial")
+public class FoodPanel extends JPanel implements ActionListener {
+    private GroupLayout layout;
+    
+    private JPanel multiPanel;
+    private JScrollPane multiScroll;
+    private GroupLayout multiLayout;
+
+    private JLabel label;
+    private JButton add;
+    private JButton remove;
+    private List<Food> foods;
+    
+    private XPath xp=DocHandler.getXpInstance();
+    Document availableFoods;
+    Document customFoods;
+    List<String> foodList;
+    
+    public FoodPanel() throws TransformerConfigurationException, SAXException, IOException, ParserConfigurationException, XPathExpressionException {
+       foods=new ArrayList<Food>();
+       
+       label=new JLabel("<html><h4>Enter list of foods consumed in last 24 hours:</h4></html>");
+       add=new JButton("Add Food");
+       add.setActionCommand("add");
+       add.addActionListener(this);
+       
+       remove=new JButton("Remove selected foods");
+       remove.setActionCommand("remove");
+       remove.addActionListener(this);
+       
+       multiPanel=new JPanel();
+       multiScroll=new JScrollPane(multiPanel);
+       
+       loadData();
+       foods.add(new Food());
+       
+       refreshLayout();
+    }
+    private void refreshLayout(){
+       this.removeAll();
+       multiPanel.removeAll();
+       
+       layout=new GroupLayout(this);
+       this.setLayout(layout);
+       layout.setAutoCreateGaps(true);
+       layout.setAutoCreateContainerGaps(true);
+       
+       multiLayout=new GroupLayout(multiPanel);
+       multiPanel.setLayout(multiLayout);
+       multiLayout.setAutoCreateGaps(true);
+       multiLayout.setAutoCreateContainerGaps(true);
+       
+       GroupLayout.ParallelGroup pg=multiLayout.createParallelGroup();
+       GroupLayout.SequentialGroup sg=multiLayout.createSequentialGroup();
+       for(int i=0; i<foods.size(); i++){
+           foods.get(i).updateNum(i+1);
+           pg.addComponent(foods.get(i));
+           sg.addComponent(foods.get(i));
+       }
+       
+       multiLayout.setVerticalGroup(sg);
+       multiLayout.setHorizontalGroup(pg);
+       
+       layout.setVerticalGroup(layout.createSequentialGroup()
+               .addComponent(label)
+               .addGroup(layout.createParallelGroup()
+                       .addComponent(add)
+                       .addComponent(remove))
+                       .addComponent(multiScroll));
+       layout.setHorizontalGroup(layout.createParallelGroup()
+               .addComponent(label)
+               .addGroup(layout.createSequentialGroup()
+                       .addComponent(add)
+                       .addComponent(remove))
+                       .addComponent(multiScroll));
+    }
+    private void addFood(){
+       foods.add(new Food());
+       refreshLayout();
+    }
+    private void removeFood(){
+       int i=0;
+       while(i<foods.size()){
+           if(foods.get(i).isSelected())
+               foods.remove(i);
+           else
+               i++;
+       }
+       refreshLayout();
+    }
+    private void combine() throws XPathExpressionException{
+       NodeList custom=(NodeList) xp.evaluate("foodList/food", customFoods, XPathConstants.NODESET);
+       Node del;
+       for(int i=0; i<custom.getLength(); i++){
+           System.out.println(xp.evaluate("name", custom.item(i)));
+           if((boolean) xp.evaluate("/foodList/food[name='"+xp.evaluate("name", custom.item(i))+"']", availableFoods, XPathConstants.BOOLEAN)){
+               del=(Node) xp.evaluate("/foodList/food[name='"+xp.evaluate("name", custom.item(i))+"']", availableFoods, XPathConstants.NODE);
+               del.getParentNode().removeChild(del);
+           }
+           availableFoods.getLastChild().appendChild(availableFoods.importNode(custom.item(i), true));
+       }
+    }
+    public void loadData() throws TransformerConfigurationException, SAXException, IOException, ParserConfigurationException, XPathExpressionException{
+       availableFoods=new DocHandler().getDocument(java.lang.ClassLoader.getSystemResourceAsStream("com/agnibho/code/resources/food.xml"));
+       try{
+           customFoods=new DocHandler().getValidatedDocument(new File(UI.LOC+File.separator+"custom_food.xml"), java.lang.ClassLoader.getSystemResourceAsStream("com/agnibho/code/resources/customFood.xsd"));
+           combine();
+       }catch(IOException | TransformerConfigurationException | SAXException | ParserConfigurationException | XPathExpressionException e){
+           System.out.println(e);
+       }
+       NodeList nl;
+       nl=(NodeList) xp.evaluate("/foodList/food", availableFoods, XPathConstants.NODESET);
+       foodList=new ArrayList<String>();
+       for(int i=0; i<nl.getLength(); i++){
+           foodList.add(xp.evaluate("name", nl.item(i)));
+       }
+       Collections.sort(foodList);
+
+       for(int i=0; i<foods.size(); i++){
+           foods.get(i).updateBox();
+       }
+       refreshLayout();
+    }
+    public boolean isComplete(){
+       if(foods.size()==0){
+           JOptionPane.showMessageDialog(this, "No food was found.", "Error", JOptionPane.ERROR_MESSAGE);
+           return false;
+       }
+       for(int i=0; i<foods.size(); i++){
+           if(!foods.get(i).isComplete()){
+               return false;
+           }
+       }
+       return true;
+    }
+    public Document copyToDoc(Document doc) throws XPathExpressionException{
+       for(int i=0; i<foods.size(); i++){
+           doc=foods.get(i).copyToDoc(doc);
+       }
+       return doc;
+    }
+
+    @Override
+    public void actionPerformed(ActionEvent ae) {
+       if(ae.getActionCommand().equals("add")){
+           addFood();
+       }
+       else if(ae.getActionCommand().equals("remove")){
+           removeFood();
+       }
+    }
+
+    private class Food extends JPanel {
+       GroupLayout layout;
+       
+       JCheckBox selection;
+       JLabel nameLabel;
+       JComboBox<String> names;
+       JLabel amountLabel;
+       JTextField amount;
+       
+       public Food(){
+           selection=new JCheckBox("Select this food");
+           nameLabel=new JLabel("<html><b>Enter name of food:</b></html>");
+           names=new JComboBox<String>();
+           for(int i=0; i<foodList.size(); i++)
+               names.addItem(foodList.get(i));
+           names.setMaximumSize(new Dimension(Integer.MAX_VALUE, 30));
+           amountLabel=new JLabel("<html><b>Enter consumed amount:<br>(in gram or ml)</b></html>");
+           amount=new JTextField();
+           amount.setMaximumSize(new Dimension(Integer.MAX_VALUE, 30));
+
+           layout=new GroupLayout(this);
+           this.setLayout(layout);
+           layout.setAutoCreateGaps(true);
+           layout.setAutoCreateContainerGaps(true);
+           layout.setVerticalGroup(layout.createSequentialGroup()
+                   .addComponent(selection)
+                   .addGroup(layout.createParallelGroup()
+                           .addComponent(nameLabel)
+                           .addComponent(names))
+                           .addGroup(layout.createParallelGroup()
+                                   .addComponent(amountLabel)
+                                   .addComponent(amount)));
+           layout.setHorizontalGroup(layout.createParallelGroup()
+                   .addComponent(selection)
+                   .addGroup(layout.createSequentialGroup()
+                           .addComponent(nameLabel)
+                           .addComponent(names))
+                           .addGroup(layout.createSequentialGroup()
+                                   .addComponent(amountLabel)
+                                   .addComponent(amount)));
+           layout.linkSize(nameLabel, amountLabel);
+           this.setBorder(BorderFactory.createLineBorder(Color.gray));
+       }
+       public void updateNum(int num){
+           selection.setText("<html><h4>Food "+String.valueOf(num));
+       }
+       public boolean isSelected(){
+           return selection.isSelected();
+       }
+       public void updateBox(){
+           names.removeAllItems();
+           for(int i=0; i<foodList.size(); i++)
+               names.addItem(foodList.get(i));
+       }
+       public boolean isComplete(){
+           if(names.getSelectedItem().toString().trim().length()==0){
+               JOptionPane.showMessageDialog(this, "Please enter valid name of food", "Error", JOptionPane.ERROR_MESSAGE);
+               return false;
+           }
+           try{
+               if(Double.parseDouble(amount.getText().trim())<0){
+                   JOptionPane.showMessageDialog(this, "Please enter valid amount of food", "Error", JOptionPane.ERROR_MESSAGE);
+                   return false;
+               }
+           }catch(NumberFormatException e){
+               JOptionPane.showMessageDialog(this, "Please enter valid amount of food", "Error", JOptionPane.ERROR_MESSAGE);
+               return false;
+           }
+           return true;
+       }
+       public Document copyToDoc(Document doc) throws XPathExpressionException{
+           Node node=(Node) xp.evaluate("/record/intake", doc, XPathConstants.NODE);
+           node.appendChild(doc.createElement("food"));
+           node=node.getLastChild();
+           node.appendChild(doc.createElement("name"));
+           node.getLastChild().appendChild(doc.createTextNode(names.getSelectedItem().toString().toString()));
+           node.appendChild(doc.createElement("amount"));
+           node.getLastChild().appendChild(doc.createTextNode(amount.getText().toString().trim()));
+           return doc;
+       }
+    }
+}
diff --git a/com/agnibho/code/dietSurvey/Help.java b/com/agnibho/code/dietSurvey/Help.java
new file mode 100644 (file)
index 0000000..44296cd
--- /dev/null
@@ -0,0 +1,210 @@
+/*
+    Diet-Survey: Perform diet survey based on 24 hours recall
+    Copyright (C) 2013  Agnibho Mondal
+    
+    This file is part of Diet-Survey.
+
+    Diet-Survey 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.
+
+    Diet-Survey 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 Diet-Survey.  If not, see <http://www.gnu.org/licenses/>.
+*/
+package com.agnibho.code.dietSurvey;
+
+import java.awt.*;
+import java.io.IOException;
+import java.net.URISyntaxException;
+
+import javax.swing.*;
+import javax.swing.event.*;
+
+@SuppressWarnings("serial")
+public class Help extends JFrame implements ListSelectionListener {
+    private static Help instance=null;
+
+    private JSplitPane splitPane;
+    private JList<String> list;
+    private JScrollPane listScroll;
+    private String[] index;
+    private JEditorPane show;
+    private JScrollPane showScroll;
+    private String[] content;
+    
+    public static JFrame getInstance(){
+       if(instance==null){
+           instance=new Help();
+       }
+       return instance;
+    }
+    
+    private Help(){
+       setup();
+       
+       list = new JList<String>(index);
+        list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+        list.setSelectedIndex(0);
+        list.addListSelectionListener(this);
+        
+        listScroll=new JScrollPane(list);
+        
+        show=new JEditorPane();
+       show.setEditable(false);
+       show.setContentType("text/html");
+       show.addHyperlinkListener(link);
+       show.setText(content[0]);
+       
+       showScroll=new JScrollPane(show);
+       showScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
+       showScroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
+       showScroll.setPreferredSize(new Dimension(300, 400));
+
+       splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, listScroll, showScroll);
+       splitPane.setOneTouchExpandable(true);
+       splitPane.setContinuousLayout(true);
+       splitPane.setDividerLocation(150);
+
+       Dimension minimumSize = new Dimension(50, 100);
+       listScroll.setMinimumSize(minimumSize);
+       showScroll.setMinimumSize(minimumSize);
+
+       splitPane.setPreferredSize(new Dimension(800, 400));
+       
+       this.getContentPane().add(splitPane);
+       
+       setTitle("Help");
+       pack();
+       setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
+       setLocationRelativeTo(null);
+    }
+    
+    public void valueChanged(ListSelectionEvent e) {
+        if(list.getSelectedIndex()==4){
+            if(Update.currentStatus.equals(Update.Status.NOT_CHECKED)){
+               show.setText(content[4]+"<h2 align='center'>Checking for update...</h2></html>");
+               SwingWorker<Void, Void> worker=new SwingWorker<Void, Void>() {
+                   @Override
+                   protected Void doInBackground() throws Exception {
+                       Update.checkUpdate();
+                       return null;
+                   }
+                   @Override
+                   protected void done(){
+                       if(list.getSelectedIndex()==4){
+                           if(Update.currentStatus.equals(Update.Status.NEW_VERSION_AVAILABLE))
+                               show.setText(content[4]+"<h2 align='center'>A new version is available</h2></html>");
+                           else if(Update.currentStatus.equals(Update.Status.UP_TO_DATE))
+                               show.setText(content[4]+"<h2 align='center'>The software is up to date.</h2></html>");
+                       }
+                   }
+               };
+               worker.execute();
+            }
+            else if(Update.currentStatus.equals(Update.Status.NEW_VERSION_AVAILABLE))
+               show.setText(content[4]+"<h2 align='center'>A new version is available</h2></html>");
+            else if(Update.currentStatus.equals(Update.Status.UP_TO_DATE))
+               show.setText(content[4]+"<h2 align='center'>The software is up to date.</h2></html>");
+        }
+        else
+            updateContent(list.getSelectedIndex());
+    }
+    
+    private void updateContent (int id) {
+        show.setText(content[id]);
+        show.setCaretPosition(0);
+    }
+    
+    public JSplitPane getSplitPane() {
+        return splitPane;
+    }
+    
+    HyperlinkListener link = new HyperlinkListener() {
+       @Override
+       public void hyperlinkUpdate(HyperlinkEvent event) {
+           if (HyperlinkEvent.EventType.ACTIVATED == event.getEventType()) {
+               try {
+                   Desktop.getDesktop().browse(event.getURL().toURI());
+               } catch (IOException | URISyntaxException e) {
+                   e.printStackTrace();
+               }
+           }
+       }
+    };
+    
+    private void setup(){
+       index=new String[6];
+       content=new String[6];
+       
+       index[0]="Introduction";
+       content[0]="<html>"
+               +"<h1 align='center'>Diet Survey</h1>"
+               +"<h2 align='center'>Diet survey based on 24 hours recall</h2>"
+               +"<p align='center'>Calculate daily requirement and nutritional status of a family based on food consumption in last 24 hours.</p>"
+               +"</html>";
+       index[1]="Survey";
+       content[1]="<html>"
+               +"<h3>Follow the steps to complete the survey</h3>"
+               +"<ol>"
+               +"<li>Enter the name of head of the family. It is used to identify the family.</li>"
+               +"<li>Enter the date of survey.</li>"
+               +"<li>Enter details of all the family members. One member field is provided by default. Use the 'Add member' and 'Remove member' button to add or remove famiy members respectively. The check box at the top right corner of each member entry can be used to select the respective entry. Enter the age in years, to enter age below 1 year enter the age in months followed by the letter 'm'.</li>"
+               +"<li>Click 'Next Section' to enter the name of foods consumed in last 24 hours. If necessary you can come back to the first page by clicking 'Previous Section' button</li>"
+               +"<li>Enter details for each food consumed in last 24 hours. Use 'Add food' and 'Remove food' to add or delete food items respectively. The check box at the top right corner of each member entry can be used to select the respective entry.</li>"
+               +"<li>Click 'Finish' to get the result of the survey. only the summary is shown on the screen</li>"
+               +"<li>Click 'View full Report' to open the detailed report in a web browser.</li>"
+               +"<li>To save the detailed report click on 'Save' button and select the folder and a filename. The file will be saved as a zip archive.</li>"
+               +"<li>The 'report.html' file inside the zip archive can be opened in a web browser to view the full report.</li>"
+               +"</ol>"
+               +"</html>";
+       
+       index[2]="Custom Food List";
+       content[2]="<html>"
+               +"<h3>To enter your own food list follow the steps as below</h3>"
+               +"<ol>"
+               +"<li>At the family panel (where the information about the family memebers are entered) click on the 'Edit' button</li>"
+               +"<li>The food editor panel will open up and it will load any existing custom food if present.</li>"
+               +"<li>To enter new food select '***Add new food item' from the combo box and enter food details. Click 'Save' to save the new food.</li>"
+               +"<li>To modify existing food select the food name from the combo box and modify the values of nutrients. Click 'Save' to save the changes.</li>"
+               +"<li>Use the 'Remove' button to remove the selected food in the combo box</li>"
+               +"</ol>"
+               +"<h3>More about custom food</h3>"
+               +"<ul>"
+               +"<li>The custom foods are saved in the 'custom_food.xml' file in the same folder as this application.</li>"
+               +"<li>The 'custom_food.xml' file can be modified directly but it must be in the proper format (valid against the schema)</li>"
+               +"<li>The entries in the 'custom_food.xml' overrides the default foods (If the file contains an entry with the same name as a default food, the entry in the 'custom_food.xml' will be used)</li>"
+               +"</html>";
+       
+       index[3]="References";
+       content[3]="<html>"
+               +"<dl>"
+               +"<dt><h3>For Recommended Dietary Allowance (RDA)</h3></dt>"
+               +"<dd>NUTRIENT REQUIREMENTS AND RECOMMENDED DIETARY ALLOWANCES FOR INDIANS- A Report of the Expert Group of the Indian Council of Medical Research 2009, NATIONAL INSTITUTE OF NUTRITION, Indian Council of Medical Research</dd>"
+               +"<dt><h3>For nutrient contents of foods</h3></dt>"
+               +"<dd>Nutritive Value of Indian Foods, ICMR, 1989</dd>"
+               +"</dl>"
+               +"</html>";
+       index[4]="Update";
+       content[4]="<html>"
+               +"<h1 align='center'>Diet Survey</h1>"
+               +"<h2 align='center'>Version: "+Update.VERSION+"</h2>"
+               +"<h3 align='center'>For latest updates visit <a href='http://code.agnibho.com/'>http://code.agnibho.com/</a>";
+       index[5]="About";
+       content[5]="<html>"
+               +"<h2>Developed by:</h2>"
+               +"<h1>Agnibho Mondal</h1>"
+               +"<h3><a href='http://www.agnibho.com/'>www.agnibho.com</a></h3>"
+               +"<h3><a href='http://code.agnibho.com/'>Visit page to view source code</a></h3>"
+               +"<hr>"
+               +"Diet-Survey Copyright (C) 2013  Agnibho Mondal<br>"
+               +"This program comes with ABSOLUTELY NO WARRANTY<br>"
+               +"This is free software, and you are welcome to redistribute it under certain conditions"
+               +"</html>";
+    }
+}
diff --git a/com/agnibho/code/dietSurvey/IdPanel.java b/com/agnibho/code/dietSurvey/IdPanel.java
new file mode 100644 (file)
index 0000000..1491eb6
--- /dev/null
@@ -0,0 +1,540 @@
+/*
+    Diet-Survey: Perform diet survey based on 24 hours recall
+    Copyright (C) 2013  Agnibho Mondal
+    
+    This file is part of Diet-Survey.
+
+    Diet-Survey 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.
+
+    Diet-Survey 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 Diet-Survey.  If not, see <http://www.gnu.org/licenses/>.
+*/
+package com.agnibho.code.dietSurvey;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.swing.BorderFactory;
+import javax.swing.ButtonGroup;
+import javax.swing.GroupLayout;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JRadioButton;
+import javax.swing.JScrollPane;
+import javax.swing.JTextField;
+import javax.swing.LayoutStyle;
+import javax.swing.SwingUtilities;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpressionException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+@SuppressWarnings("serial")
+public class IdPanel extends JPanel implements ActionListener {
+    private GroupLayout layout;
+    
+    private JPanel multiPanel;
+    private JScrollPane multiScroll;
+    private GroupLayout multiLayout;
+
+    private JLabel hofLabel;
+    private JTextField hofField;
+    private JLabel dateLabel;
+    private JTextField dateField;
+    private JButton add;
+    private JButton remove;
+    private List<Member> members;
+
+    public IdPanel() {
+       hofLabel=new JLabel("<html><h4>Enter the name of Head of Family:</h4></html>", JLabel.TRAILING);
+       hofField=new JTextField();
+       hofField.setMaximumSize(new Dimension(Integer.MAX_VALUE, 30));
+       dateLabel=new JLabel("<html><h4>Enter the date:</h4></html>", JLabel.TRAILING);
+       dateField=new JTextField();
+       dateField.setText("dd-mm-yyyy");
+       dateField.addFocusListener(new java.awt.event.FocusAdapter() {
+           public void focusGained(java.awt.event.FocusEvent evt) {
+               SwingUtilities.invokeLater( new Runnable() {
+                   @Override
+                   public void run() {
+                       dateField.selectAll();          
+                   }
+               });
+           }
+       });
+       dateField.setMaximumSize(new Dimension(Integer.MAX_VALUE, 30));
+       add=new JButton("Add Family Member");
+       add.setActionCommand("add");
+       add.addActionListener(this);
+       remove=new JButton("Remove Selected Members");
+       remove.setActionCommand("remove");
+       remove.addActionListener(this);
+       
+       multiPanel=new JPanel();
+       multiScroll=new JScrollPane(multiPanel);
+       
+       members=new ArrayList<Member>();
+       members.add(new Member());
+       refreshLayout();
+    }
+    private void refreshLayout(){
+       this.removeAll();
+       multiPanel.removeAll();
+       
+       layout=new GroupLayout(this);
+       this.setLayout(layout);
+       layout.setAutoCreateGaps(true);
+       layout.setAutoCreateContainerGaps(true);
+       
+       multiLayout=new GroupLayout(multiPanel);
+       multiPanel.setLayout(multiLayout);
+       multiLayout.setAutoCreateGaps(true);
+       multiLayout.setAutoCreateContainerGaps(true);
+       
+       GroupLayout.ParallelGroup pg=multiLayout.createParallelGroup();
+       GroupLayout.SequentialGroup sg=multiLayout.createSequentialGroup();
+       
+       for(int i=0; i<members.size(); i++){
+           members.get(i).updateNum(i+1);
+           pg.addComponent(members.get(i));
+           sg.addComponent(members.get(i));
+       }
+       sg.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE);
+       multiLayout.setVerticalGroup(sg);
+       multiLayout.setHorizontalGroup(pg);
+       
+       layout.setVerticalGroup(layout.createSequentialGroup()
+               .addGroup(layout.createParallelGroup()
+                       .addComponent(hofLabel)
+                       .addComponent(hofField))
+                       .addGroup(layout.createParallelGroup()
+                               .addComponent(dateLabel)
+                               .addComponent(dateField))
+                               .addGroup(layout.createParallelGroup()
+                                       .addComponent(add)
+                                       .addComponent(remove))
+                                       .addComponent(multiScroll));
+       layout.setHorizontalGroup(layout.createParallelGroup()
+               .addGroup(layout.createSequentialGroup()
+                       .addComponent(hofLabel)
+                       .addComponent(hofField))
+                       .addGroup(layout.createSequentialGroup()
+                               .addComponent(dateLabel)
+                               .addComponent(dateField))
+                               .addGroup(layout.createSequentialGroup()
+                                       .addComponent(add)
+                                       .addComponent(remove))
+                                       .addComponent(multiScroll));
+       layout.linkSize(hofLabel, dateLabel);
+    }
+    private void addMember(){
+       members.add(new Member());
+       refreshLayout();
+    }
+    private void removeMember(){
+       int i=0;
+       while(i<members.size()){
+           if(members.get(i).isSelected())
+               members.remove(i);
+           else
+               i++;
+       }
+       refreshLayout();
+    }
+    private boolean checkDate(String date){
+       date=date.trim();
+       String[] parts;
+       if(date.contains("/"))
+           parts=date.split("/");
+       else if(date.contains("."))
+           parts=date.split(".");
+       else if(date.contains("-"))
+           parts=date.split("-");
+       else
+           return false;
+       if(parts.length!=3)
+           return false;
+       try{
+           if(Integer.parseInt(parts[0])<1||Integer.parseInt(parts[0])>31)
+               return false;
+           if(Integer.parseInt(parts[1])<1||Integer.parseInt(parts[1])>12)
+               return false;
+           if(!((Integer.parseInt(parts[2])>=1950&&Integer.parseInt(parts[2])<=2050)||(Integer.parseInt(parts[2])>=0||Integer.parseInt(parts[2])<=99)))
+               return false;
+       }catch(NumberFormatException e){
+           return false;
+       }
+       return true;
+    }
+    public boolean isComplete(){
+       if(hofField.getText().toString().trim().length()==0){
+           JOptionPane.showMessageDialog(this, "Please enter the name of Head of Family", "Error", JOptionPane.ERROR_MESSAGE);
+           return false;
+       }
+       if(!checkDate(dateField.getText())){
+           JOptionPane.showMessageDialog(this, "Invalid date.", "Error", JOptionPane.ERROR_MESSAGE);
+           return false;
+       }
+       if(members.size()==0){
+           JOptionPane.showMessageDialog(this, "No member was found.", "Error", JOptionPane.ERROR_MESSAGE);
+           return false;
+       }
+       for(int i=0; i<members.size(); i++){
+           if(!members.get(i).isComplete())
+               return false;
+       }
+       return true;
+    }
+    public Document copyToDoc(Document doc) throws XPathExpressionException, ParserConfigurationException{
+       XPath xp=DocHandler.getXpInstance();
+       Node node=(Node) xp.evaluate("/record/id", doc, XPathConstants.NODE);
+       node.appendChild(doc.createElement("hof"));
+       node.getFirstChild().appendChild(doc.createTextNode(hofField.getText().toString().trim()));
+       node.appendChild(doc.createElement("date"));
+       if(checkDate(dateField.getText()))
+           node.getLastChild().appendChild(doc.createTextNode(dateField.getText().toString().trim()));
+       for(int i=0; i<members.size(); i++){
+           doc=members.get(i).copyToDoc(doc);
+       }
+       return doc;
+    }
+
+    @Override
+    public void actionPerformed(ActionEvent ae) {
+       if(ae.getActionCommand().equals("add"))
+           addMember();
+       else if(ae.getActionCommand().equals("remove"))
+           removeMember();
+    }
+    
+    private class Member extends JPanel implements ActionListener {
+       GroupLayout layout;
+
+       JCheckBox selection;
+       JLabel nameLabel;
+       JTextField nameField;
+       JLabel ageLabel;
+       JTextField ageField;
+       JLabel sexLabel;
+       ButtonGroup sex;
+       JRadioButton male;
+       JRadioButton female;
+       JLabel jobLabel;
+       JComboBox<String> jobBox;
+       JLabel pregLabel;
+       ButtonGroup preg;
+       JRadioButton yesP;
+       JRadioButton noP;
+       JLabel lacLabel;
+       ButtonGroup lac;
+       JRadioButton yesLbelow6;
+       JRadioButton yesLabove6;
+       JRadioButton noL;
+
+       Member(){
+           selection=new JCheckBox();
+           
+           nameLabel=new JLabel("<html><b>Enter name:</b></html>");
+           nameLabel.setPreferredSize(new Dimension(120, 20));
+           nameField=new JTextField(30);
+           nameField.setMaximumSize(new Dimension(Integer.MAX_VALUE, 30));
+           
+           ageLabel=new JLabel("<html><b>Enter age:</b></html>");
+           ageField=new JTextField();
+           ageField.setActionCommand("check");
+           ageField.addActionListener(this);
+           ageField.setMaximumSize(new Dimension(Integer.MAX_VALUE, 30));
+           
+           sexLabel=new JLabel("<html><b>Enter Sex:</b></html>");
+           male=new JRadioButton("Male");
+           male.setActionCommand("check");
+           male.addActionListener(this);
+           female=new JRadioButton("Female");
+           female.setActionCommand("check");
+           female.addActionListener(this);
+           sex=new ButtonGroup();
+           sex.add(male);
+           sex.add(female);
+           
+           jobLabel=new JLabel("<html><b>Enter Work Type:</b></html>");
+           jobLabel.setVisible(false);
+           String[] jobCat={"Sedentary", "Moderate", "Heavy"};
+           jobBox=new JComboBox<String>(jobCat);
+           jobBox.setMaximumSize(new Dimension(Integer.MAX_VALUE, 30));
+           jobBox.setVisible(false);
+           
+           pregLabel=new JLabel("<html><b>Is she pregnant?</b></html>");
+           pregLabel.setVisible(false);
+           yesP=new JRadioButton("Yes");
+           yesP.setActionCommand("check");
+           yesP.addActionListener(this);
+           yesP.setVisible(false);
+           noP=new JRadioButton("No");
+           noP.setVisible(false);
+           preg=new ButtonGroup();
+           preg.add(yesP);
+           preg.add(noP);
+           
+           lacLabel=new JLabel("<html><b>Is she lactating?</b></html>");
+           lacLabel.setVisible(false);
+           yesLbelow6=new JRadioButton("Yes, below 6 months");
+           yesLbelow6.setActionCommand("check");
+           yesLbelow6.addActionListener(this);
+           yesLbelow6.setVisible(false);
+           yesLabove6=new JRadioButton("Yes, above 6 months");
+           yesLabove6.setActionCommand("check");
+           yesLabove6.addActionListener(this);
+           yesLabove6.setVisible(false);
+           noL=new JRadioButton("No");
+           noL.setVisible(false);
+           lac=new ButtonGroup();
+           lac.add(yesLbelow6);
+           lac.add(yesLabove6);
+           lac.add(noL);
+
+           layout=new GroupLayout(this);
+           this.setLayout(layout);
+           layout.setAutoCreateGaps(true);
+           layout.setAutoCreateContainerGaps(true);
+           layout.setVerticalGroup(
+                   layout.createSequentialGroup()
+                   .addComponent(selection)
+                   .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE)
+                   .addGroup(layout.createParallelGroup()
+                           .addComponent(nameLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
+                           .addComponent(nameField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
+                           .addGroup(layout.createParallelGroup()
+                                   .addComponent(ageLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
+                                   .addComponent(ageField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
+                                   .addGroup(layout.createParallelGroup()
+                                           .addComponent(sexLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
+                                           .addComponent(male, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
+                                           .addComponent(female, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
+                                           .addGroup(layout.createParallelGroup()
+                                                   .addComponent(jobLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
+                                                   .addComponent(jobBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
+                                                   .addGroup(layout.createParallelGroup()
+                                                           .addComponent(pregLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
+                                                           .addComponent(yesP, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
+                                                           .addComponent(noP, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
+                                                           .addGroup(layout.createParallelGroup()
+                                                                   .addComponent(lacLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
+                                                                   .addComponent(yesLbelow6, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
+                                                                   .addComponent(yesLabove6, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
+                                                                   .addComponent(noL, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
+                                                                   //.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+                   );
+           layout.setHorizontalGroup(
+                   layout.createParallelGroup()
+                   .addComponent(selection)
+                   .addGroup(layout.createSequentialGroup()
+                           .addComponent(nameLabel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+                           .addComponent(nameField, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+                           .addGroup(layout.createSequentialGroup()
+                                   .addComponent(ageLabel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+                                   .addComponent(ageField, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+                                   .addGroup(layout.createSequentialGroup()
+                                           .addComponent(sexLabel)
+                                           .addComponent(male)
+                                           .addComponent(female))
+                                           .addGroup(layout.createSequentialGroup()
+                                                   .addComponent(jobLabel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+                                                   .addComponent(jobBox, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+                                                   .addGroup(layout.createSequentialGroup()
+                                                           .addComponent(pregLabel)
+                                                           .addComponent(yesP)
+                                                           .addComponent(noP))
+                                                           .addGroup(layout.createSequentialGroup()
+                                                                   .addComponent(lacLabel)
+                                                                   .addComponent(yesLbelow6)
+                                                                   .addComponent(yesLabove6)
+                                                                   .addComponent(noL)));
+           layout.linkSize(nameLabel, ageLabel, sexLabel, jobLabel, pregLabel, lacLabel);
+           this.setBorder(BorderFactory.createLineBorder(Color.gray));
+       }
+       
+       public void updateNum(int num){
+           selection.setText("<html><h4>Member "+String.valueOf(num)+"</h4></html>");
+       }
+       
+       public boolean isSelected(){
+           return selection.isSelected();
+       }
+       
+       public void check(){
+           if(!ageField.getText().toString().trim().endsWith("m")){
+               try{
+                   if(Integer.parseInt(ageField.getText().toString().trim())>=18){
+                       jobLabel.setVisible(true);
+                       jobBox.setVisible(true);
+                   }
+                   else{
+                       jobLabel.setVisible(false);
+                       jobBox.setVisible(false);
+                       pregLabel.setVisible(false);
+                       yesP.setVisible(false);
+                       noP.setVisible(false);
+                       lacLabel.setVisible(false);
+                       yesLbelow6.setVisible(false);
+                       yesLabove6.setVisible(false);
+                       noL.setVisible(false);
+                   }
+                   if(female.isSelected()&&Integer.parseInt(ageField.getText().toString().trim())>=18&&Integer.parseInt(ageField.getText().toString().trim())<=45){
+                       pregLabel.setVisible(true);
+                       yesP.setVisible(true);
+                       noP.setVisible(true);
+                       lacLabel.setVisible(true);
+                       yesLbelow6.setVisible(true);
+                       yesLabove6.setVisible(true);
+                       noL.setVisible(true);
+                   }
+                   else{
+                       pregLabel.setVisible(false);
+                       yesP.setVisible(false);
+                       noP.setVisible(false);
+                       lacLabel.setVisible(false);
+                       yesLbelow6.setVisible(false);
+                       yesLabove6.setVisible(false);
+                       noL.setVisible(false);
+                   }
+                   if(yesP.isSelected())
+                       noL.setSelected(true);
+                   else if(yesLbelow6.isSelected()||yesLabove6.isSelected())
+                       noP.setSelected(true);
+               }catch(NumberFormatException e){
+                   
+               }
+           }
+           else{
+               jobLabel.setVisible(false);
+               jobBox.setVisible(false);
+               pregLabel.setVisible(false);
+               yesP.setVisible(false);
+               noP.setVisible(false);
+               lacLabel.setVisible(false);
+               yesLbelow6.setVisible(false);
+               yesLabove6.setVisible(false);
+               noL.setVisible(false);
+           }
+       }
+       
+       public boolean isComplete(){
+           String age=ageField.getText().toString().trim();
+           try{
+               if(Integer.parseInt(age)>=18 && !jobBox.isVisible()){
+                   JOptionPane.showMessageDialog(this, "Please enter the work type.", "Error", JOptionPane.ERROR_MESSAGE);
+                   check();
+                   return false;
+               }
+               if(age.endsWith("m")){
+                   if(Integer.parseInt(age.substring(0, age.length()-1).trim())<0 && Integer.parseInt(age.substring(0, age.length()-2).trim())>11){
+                       JOptionPane.showMessageDialog(this, "Invalid age. Please try again.", "Error", JOptionPane.ERROR_MESSAGE);
+                       return false;
+                   }
+               }
+               else{
+                   if(Integer.parseInt(age)<1){
+                       JOptionPane.showMessageDialog(this, "Invalid age. Please try again.", "Error", JOptionPane.ERROR_MESSAGE);
+                       return false;
+                   }
+               }
+           }catch(NumberFormatException e){
+               JOptionPane.showMessageDialog(this, "Invalid age. Please try again.", "Error", JOptionPane.ERROR_MESSAGE);
+               return false;
+           }
+           
+           check();
+           
+           if(!(male.isSelected()||female.isSelected())){
+               JOptionPane.showMessageDialog(this, "Please enter sex", "Error", JOptionPane.ERROR_MESSAGE);
+               return false;
+           }
+           if(pregLabel.isVisible()&&!(yesP.isSelected()||noP.isSelected())){
+               JOptionPane.showMessageDialog(this, "Please enter pregnancy status.", "Error", JOptionPane.ERROR_MESSAGE);
+               return false;
+           }
+           if(lacLabel.isVisible()&&!(yesLbelow6.isSelected()||yesLabove6.isSelected()||noL.isSelected())){
+               JOptionPane.showMessageDialog(this, "Please enter lactation status", "Error", JOptionPane.ERROR_MESSAGE);
+               return false;
+           }
+           return true;
+       }
+       
+       public Document copyToDoc(Document doc) throws XPathExpressionException{
+           XPath xp=DocHandler.getXpInstance();
+           Node node=(Node) xp.evaluate("/record/id", doc, XPathConstants.NODE);
+           node.appendChild(doc.createElement("member"));
+           node=node.getLastChild();
+           if(nameField.getText().toString().trim().length()>0){
+               node.appendChild(doc.createElement("name"));
+               node.getLastChild().appendChild(doc.createTextNode(nameField.getText().toString().trim()));
+           }
+           
+           String age=ageField.getText().toString().trim();
+           if(age.endsWith("m")){
+               node.appendChild(doc.createElement("infant"));
+               node.getLastChild().appendChild(doc.createTextNode(age.substring(0, age.length()-1).trim()));
+           }
+           else{
+               node.appendChild(doc.createElement("age"));
+               node.getLastChild().appendChild(doc.createTextNode(age));
+           }
+           node.appendChild(doc.createElement("sex"));
+           if(male.isSelected())
+               node.getLastChild().appendChild(doc.createTextNode("male"));
+           else
+               node.getLastChild().appendChild(doc.createTextNode("female"));
+           if(jobBox.isVisible()){
+               node.appendChild(doc.createElement("occupation"));
+               node.getLastChild().appendChild(doc.createTextNode(jobBox.getSelectedItem().toString().trim().toLowerCase()));
+           }
+           if(pregLabel.isVisible()){
+               node.appendChild(doc.createElement("pregnant"));
+               if(yesP.isSelected())
+                   node.getLastChild().appendChild(doc.createTextNode("true"));
+               else
+                   node.getLastChild().appendChild(doc.createTextNode("false"));
+           }
+           if(lacLabel.isVisible()){
+               node.appendChild(doc.createElement("lactating"));
+               if(yesLbelow6.isSelected()||yesLabove6.isSelected()){
+                   node.getLastChild().appendChild(doc.createTextNode("true"));
+                   node.appendChild(doc.createElement("beyond6m"));
+                   if(yesLabove6.isSelected())
+                       node.getLastChild().appendChild(doc.createTextNode("true"));
+                   else
+                       node.getLastChild().appendChild(doc.createTextNode("false"));
+               }
+               else
+                   node.getLastChild().appendChild(doc.createTextNode("false"));
+           }
+           return doc;
+       }
+
+       @Override
+       public void actionPerformed(ActionEvent ae) {
+           if(ae.getActionCommand().equals("check")){
+               check();
+           }
+       }
+    }
+}
diff --git a/com/agnibho/code/dietSurvey/LICENSE.TXT b/com/agnibho/code/dietSurvey/LICENSE.TXT
new file mode 100644 (file)
index 0000000..94a9ed0
--- /dev/null
@@ -0,0 +1,674 @@
+                    GNU GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+  The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works.  By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users.  We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors.  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+  To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights.  Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received.  You must make sure that they, too, receive
+or can get the source code.  And you must show them these terms so they
+know their rights.
+
+  Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+  For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software.  For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+  Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so.  This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software.  The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable.  Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products.  If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+  Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary.  To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                       TERMS AND CONDITIONS
+
+  0. Definitions.
+
+  "This License" refers to version 3 of the GNU General Public License.
+
+  "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+  "The Program" refers to any copyrightable work licensed under this
+License.  Each licensee is addressed as "you".  "Licensees" and
+"recipients" may be individuals or organizations.
+
+  To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy.  The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+  A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+  To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy.  Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+  To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies.  Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+  An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License.  If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+  1. Source Code.
+
+  The "source code" for a work means the preferred form of the work
+for making modifications to it.  "Object code" means any non-source
+form of a work.
+
+  A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+  The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form.  A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+  The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities.  However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work.  For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+  The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+  The Corresponding Source for a work in source code form is that
+same work.
+
+  2. Basic Permissions.
+
+  All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met.  This License explicitly affirms your unlimited
+permission to run the unmodified Program.  The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work.  This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+  You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force.  You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright.  Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+  Conveying under any other circumstances is permitted solely under
+the conditions stated below.  Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+  No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+  When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+  4. Conveying Verbatim Copies.
+
+  You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+  You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+  5. Conveying Modified Source Versions.
+
+  You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+    a) The work must carry prominent notices stating that you modified
+    it, and giving a relevant date.
+
+    b) The work must carry prominent notices stating that it is
+    released under this License and any conditions added under section
+    7.  This requirement modifies the requirement in section 4 to
+    "keep intact all notices".
+
+    c) You must license the entire work, as a whole, under this
+    License to anyone who comes into possession of a copy.  This
+    License will therefore apply, along with any applicable section 7
+    additional terms, to the whole of the work, and all its parts,
+    regardless of how they are packaged.  This License gives no
+    permission to license the work in any other way, but it does not
+    invalidate such permission if you have separately received it.
+
+    d) If the work has interactive user interfaces, each must display
+    Appropriate Legal Notices; however, if the Program has interactive
+    interfaces that do not display Appropriate Legal Notices, your
+    work need not make them do so.
+
+  A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit.  Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+  6. Conveying Non-Source Forms.
+
+  You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+    a) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by the
+    Corresponding Source fixed on a durable physical medium
+    customarily used for software interchange.
+
+    b) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by a
+    written offer, valid for at least three years and valid for as
+    long as you offer spare parts or customer support for that product
+    model, to give anyone who possesses the object code either (1) a
+    copy of the Corresponding Source for all the software in the
+    product that is covered by this License, on a durable physical
+    medium customarily used for software interchange, for a price no
+    more than your reasonable cost of physically performing this
+    conveying of source, or (2) access to copy the
+    Corresponding Source from a network server at no charge.
+
+    c) Convey individual copies of the object code with a copy of the
+    written offer to provide the Corresponding Source.  This
+    alternative is allowed only occasionally and noncommercially, and
+    only if you received the object code with such an offer, in accord
+    with subsection 6b.
+
+    d) Convey the object code by offering access from a designated
+    place (gratis or for a charge), and offer equivalent access to the
+    Corresponding Source in the same way through the same place at no
+    further charge.  You need not require recipients to copy the
+    Corresponding Source along with the object code.  If the place to
+    copy the object code is a network server, the Corresponding Source
+    may be on a different server (operated by you or a third party)
+    that supports equivalent copying facilities, provided you maintain
+    clear directions next to the object code saying where to find the
+    Corresponding Source.  Regardless of what server hosts the
+    Corresponding Source, you remain obligated to ensure that it is
+    available for as long as needed to satisfy these requirements.
+
+    e) Convey the object code using peer-to-peer transmission, provided
+    you inform other peers where the object code and Corresponding
+    Source of the work are being offered to the general public at no
+    charge under subsection 6d.
+
+  A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+  A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling.  In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage.  For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product.  A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+  "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source.  The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+  If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information.  But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+  The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed.  Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+  Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+  7. Additional Terms.
+
+  "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law.  If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+  When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it.  (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.)  You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+  Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+    a) Disclaiming warranty or limiting liability differently from the
+    terms of sections 15 and 16 of this License; or
+
+    b) Requiring preservation of specified reasonable legal notices or
+    author attributions in that material or in the Appropriate Legal
+    Notices displayed by works containing it; or
+
+    c) Prohibiting misrepresentation of the origin of that material, or
+    requiring that modified versions of such material be marked in
+    reasonable ways as different from the original version; or
+
+    d) Limiting the use for publicity purposes of names of licensors or
+    authors of the material; or
+
+    e) Declining to grant rights under trademark law for use of some
+    trade names, trademarks, or service marks; or
+
+    f) Requiring indemnification of licensors and authors of that
+    material by anyone who conveys the material (or modified versions of
+    it) with contractual assumptions of liability to the recipient, for
+    any liability that these contractual assumptions directly impose on
+    those licensors and authors.
+
+  All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10.  If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term.  If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+  If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+  Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+  8. Termination.
+
+  You may not propagate or modify a covered work except as expressly
+provided under this License.  Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+  However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+  Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+  Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License.  If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+  9. Acceptance Not Required for Having Copies.
+
+  You are not required to accept this License in order to receive or
+run a copy of the Program.  Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance.  However,
+nothing other than this License grants you permission to propagate or
+modify any covered work.  These actions infringe copyright if you do
+not accept this License.  Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+  10. Automatic Licensing of Downstream Recipients.
+
+  Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License.  You are not responsible
+for enforcing compliance by third parties with this License.
+
+  An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations.  If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+  You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License.  For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+  11. Patents.
+
+  A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based.  The
+work thus licensed is called the contributor's "contributor version".
+
+  A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version.  For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+  Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+  In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement).  To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+  If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients.  "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+  If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+  A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License.  You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+  Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+  12. No Surrender of Others' Freedom.
+
+  If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all.  For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+  13. Use with the GNU Affero General Public License.
+
+  Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work.  The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+  14. Revised Versions of this License.
+
+  The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+  Each version is given a distinguishing version number.  If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation.  If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+  If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+  Later license versions may give you additional or different
+permissions.  However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+  15. Disclaimer of Warranty.
+
+  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. Limitation of Liability.
+
+  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+  17. Interpretation of Sections 15 and 16.
+
+  If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+                     END OF TERMS AND CONDITIONS
+
+            How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+  If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+    <program>  Copyright (C) <year>  <name of author>
+    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+  You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+  The GNU General Public License does not permit incorporating your program
+into proprietary programs.  If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library.  If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.  But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
diff --git a/com/agnibho/code/dietSurvey/NutrientGraph.java b/com/agnibho/code/dietSurvey/NutrientGraph.java
new file mode 100644 (file)
index 0000000..1fe8481
--- /dev/null
@@ -0,0 +1,188 @@
+/*
+    Diet-Survey: Perform diet survey based on 24 hours recall
+    Copyright (C) 2013  Agnibho Mondal
+    
+    This file is part of Diet-Survey.
+
+    Diet-Survey 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.
+
+    Diet-Survey 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 Diet-Survey.  If not, see <http://www.gnu.org/licenses/>.
+*/
+package com.agnibho.code.dietSurvey;
+
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.font.TextAttribute;
+import java.awt.geom.Line2D;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Hashtable;
+
+import javax.imageio.ImageIO;
+import javax.swing.JPanel;
+
+@SuppressWarnings("serial")
+public class NutrientGraph extends JPanel {
+
+    private double energy;
+    private double protein;
+    private double iron;
+    private double vitA;
+    private double thiamine;
+    private double riboflavin;
+    private double vitC;
+    
+    private int mag=2;
+    
+    private double base;
+    private Point2D root;
+    private Point2D maxX;
+    private Point2D maxY;
+    private Point2D norm;
+    
+    BufferedImage img;
+    
+    public NutrientGraph(){
+       new NutrientGraph(0, 0, 0, 0, 0, 0, 0);
+    }
+    
+    public NutrientGraph(double energy, double protein, double iron, double vitA, double thiamine, double riboflavin, double vitC){
+       this.energy=energy;
+       this.protein=protein;
+       this.iron=iron;
+       this.vitA=vitA;
+       this.thiamine=thiamine;
+       this.riboflavin=riboflavin;
+       this.vitC=vitC;
+       
+       base=Math.max(energy, Math.max(protein, Math.max(iron, Math.max(vitA, Math.max(thiamine, Math.max(riboflavin, Math.max(vitC, 100)))))))*mag;
+       root=new Point2D.Double(50, base+50);
+       maxX=new Point2D.Double(490, base+50);
+       maxY=new Point2D.Double(50, 50);
+       norm=new Point2D.Double(root.getX(), root.getY()-(mag*100));
+       
+       img=new BufferedImage((int)maxX.getX()+50, (int)maxX.getY()+80, BufferedImage.TYPE_INT_RGB);
+    }
+    
+    @Override
+    public void paint(Graphics g){
+       Graphics2D panelG2=(Graphics2D) g;
+       Graphics2D g2=img.createGraphics();
+       
+       Font font=new Font(Font.SERIF, Font.PLAIN, 12);
+       g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
+       
+       g2.setPaint(Color.white);
+       g2.fill(new Rectangle2D.Double(0, 0, maxX.getX()+50, maxX.getY()+80));
+       g2.setPaint(Color.black);
+       g2.draw(new Line2D.Double(root, maxX));
+       g2.draw(new Line2D.Double(root, maxY));
+       g2.draw(new Line2D.Double(norm.getX(), norm.getY(), maxX.getX(), norm.getY()));
+       
+       g2.setPaint(Color.blue);
+       for(double i=root.getY(), per=0; i>=maxY.getY(); i=i-(mag*10), per=per+10){
+           g2.drawString(String.valueOf((int)per), (float)root.getX()-25, (float)i);
+       }
+       
+       g2.drawString("Energy", (int)root.getX()+20, (int)root.getY()+20);
+       g2.drawString("Protein", (int)root.getX()+80, (int)root.getY()+20);
+       g2.drawString("Iron", (int)root.getX()+140, (int)root.getY()+20);
+       g2.drawString("Vitamine A", (int)root.getX()+200, (int)root.getY()+20);
+       g2.drawString("Thiamine", (int)root.getX()+260, (int)root.getY()+20);
+       g2.drawString("Riboflavin", (int)root.getX()+320, (int)root.getY()+20);
+       g2.drawString("Vitamin C", (int)root.getX()+380, (int)root.getY()+20);
+       
+       if(energy>=100)
+           g2.setPaint(Color.green);
+       else
+           g2.setPaint(Color.red);
+       g2.fill(new Rectangle2D.Double(root.getX()+20, root.getY()-(mag*energy), 40, mag*energy));
+       g2.setPaint(Color.blue);
+       g2.drawString(String.format("%.2f", energy)+"%", (float)root.getX()+20, (float)(root.getY()-(mag*energy)-5));
+       if(protein>=100)
+           g2.setPaint(Color.green);
+       else
+           g2.setPaint(Color.red);
+       g2.fill(new Rectangle2D.Double(root.getX()+80, root.getY()-(mag*protein), 40, mag*protein));
+       g2.setPaint(Color.blue);
+       g2.drawString(String.format("%.2f", protein)+"%", (float)root.getX()+80, (float)(root.getY()-(mag*protein)-5));
+       if(iron>=100)
+           g2.setPaint(Color.green);
+       else
+           g2.setPaint(Color.red);
+       g2.fill(new Rectangle2D.Double(root.getX()+140, root.getY()-(mag*iron), 40, mag*iron));
+       g2.setPaint(Color.blue);
+       g2.drawString(String.format("%.2f", iron)+"%", (float)root.getX()+140, (float)(root.getY()-(mag*iron)-5));
+       if(vitA>=100)
+           g2.setPaint(Color.green);
+       else
+           g2.setPaint(Color.red);
+       g2.fill(new Rectangle2D.Double(root.getX()+200, root.getY()-(mag*vitA), 40, mag*vitA));
+       g2.setPaint(Color.blue);
+       g2.drawString(String.format("%.2f", vitA)+"%", (float)root.getX()+200, (float)(root.getY()-(mag*vitA)-5));
+       if(thiamine>=100)
+           g2.setPaint(Color.green);
+       else
+           g2.setPaint(Color.red);
+       g2.fill(new Rectangle2D.Double(root.getX()+260, root.getY()-(mag*thiamine), 40, mag*thiamine));
+       g2.setPaint(Color.blue);
+       g2.drawString(String.format("%.2f", thiamine)+"%", (float)root.getX()+260, (float)(root.getY()-(mag*thiamine)-5));
+       if(riboflavin>=100)
+           g2.setPaint(Color.green);
+       else
+           g2.setPaint(Color.red);
+       g2.fill(new Rectangle2D.Double(root.getX()+320, root.getY()-(mag*riboflavin), 40, mag*riboflavin));
+       g2.setPaint(Color.blue);
+       g2.drawString(String.format("%.2f", riboflavin)+"%", (float)root.getX()+320, (float)(root.getY()-(mag*riboflavin)-5));
+       if(vitC>=100)
+           g2.setPaint(Color.green);
+       else
+           g2.setPaint(Color.red);
+       g2.fill(new Rectangle2D.Double(root.getX()+380, root.getY()-(mag*vitC), 40, mag*vitC));
+       g2.setPaint(Color.blue);
+       g2.drawString(String.format("%.2f", vitC)+"%", (float)root.getX()+380, (float)(root.getY()-(mag*vitC)-5));
+       
+       Hashtable<TextAttribute, Object> ht=new Hashtable<TextAttribute, Object>();
+       ht.put(TextAttribute.SIZE, 18);
+       font=font.deriveFont(ht);
+       g2.setFont(font);
+       g2.drawString("Fig: Bar diagram showing percentage intake of different nutrients", (float)root.getX(), (float)root.getY()+60);
+       
+       panelG2.drawImage(img, null, 0, 0);
+       
+       /*try {
+           ImageIO.write(img, "png", new File("E:\\test.png"));
+       } catch (IOException e) {
+           JOptionPane.showMessageDialog(this, "An error has occured.\n"+e.toString(), "Error", JOptionPane.ERROR_MESSAGE);
+           e.printStackTrace();
+       }*/
+    }
+    
+    public BufferedImage getImage(){
+       return img;
+    }
+    public InputStream getAsInputStream() throws IOException{
+       ByteArrayOutputStream os = new ByteArrayOutputStream();
+       ImageIO.write(img, "png", os);
+       InputStream is = new ByteArrayInputStream(os.toByteArray());
+       return is;
+    }
+
+}
diff --git a/com/agnibho/code/dietSurvey/ResultPanel.java b/com/agnibho/code/dietSurvey/ResultPanel.java
new file mode 100644 (file)
index 0000000..2d5ca3e
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+    Diet-Survey: Perform diet survey based on 24 hours recall
+    Copyright (C) 2013  Agnibho Mondal
+    
+    This file is part of Diet-Survey.
+
+    Diet-Survey 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.
+
+    Diet-Survey 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 Diet-Survey.  If not, see <http://www.gnu.org/licenses/>.
+*/
+package com.agnibho.code.dietSurvey;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Scanner;
+
+import javax.swing.GroupLayout;
+import javax.swing.JEditorPane;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.text.html.HTMLEditorKit;
+
+@SuppressWarnings("serial")
+public class ResultPanel extends JPanel {
+    private GroupLayout layout;
+
+    private JEditorPane display;
+    private JScrollPane scroll;
+
+    public ResultPanel(){
+
+       display=new JEditorPane();
+       display.setContentType("text/html;charset=UTF-8");
+       display.setEditorKit(new HTMLEditorKit());
+       display.setEditable(false);
+       scroll=new JScrollPane(display);
+
+       layout=new GroupLayout(this);
+       this.setLayout(layout);
+       layout.setAutoCreateGaps(true);
+       layout.setAutoCreateContainerGaps(true);
+       layout.setVerticalGroup(layout.createSequentialGroup().addComponent(scroll));
+       layout.setHorizontalGroup(layout.createParallelGroup().addComponent(scroll));
+    }
+    
+    public void display(InputStream in) throws IOException{
+       
+       Scanner scanner = new Scanner(in,"UTF-8");
+       String content=scanner.useDelimiter("\\A").next();
+       scanner.close();
+       display.setText(content);
+       display.setCaretPosition(0);
+    }
+}
diff --git a/com/agnibho/code/dietSurvey/UI.java b/com/agnibho/code/dietSurvey/UI.java
new file mode 100644 (file)
index 0000000..c4917ca
--- /dev/null
@@ -0,0 +1,425 @@
+/*
+    Diet-Survey: Perform diet survey based on 24 hours recall
+    Copyright (C) 2013  Agnibho Mondal
+    
+    This file is part of Diet-Survey.
+
+    Diet-Survey 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.
+
+    Diet-Survey 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 Diet-Survey.  If not, see <http://www.gnu.org/licenses/>.
+*/
+package com.agnibho.code.dietSurvey;
+
+import javax.swing.*;
+import javax.swing.filechooser.FileNameExtensionFilter;
+import javax.xml.bind.JAXBException;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactoryConfigurationError;
+import javax.xml.xpath.XPathExpressionException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
+
+import java.awt.Desktop;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ *
+ * @author SPARK
+ */
+@SuppressWarnings("serial")
+public class UI extends JFrame implements ActionListener {
+    
+    public static final String LOC=getAppLocation();
+    
+    GroupLayout layout;
+    
+    private boolean unsaved=false;
+    private Path path=null;
+    
+    private Zipper zip;
+    private DocHandler dh;
+    private Document input;
+    private Document output;
+    private Node node;
+    
+    private JFileChooser fc;
+    
+    private Assess assesser;
+    private List<InputStream> report;
+
+    private JLabel heading;
+    private IdPanel id;
+    private FoodPanel food;
+    private ResultPanel result;
+    private CustomFood custom;
+    private JFrame helpFrame;
+    private JButton next;
+    private JButton prev;
+    private JButton finish;
+    private JButton save;
+    private JButton view;
+    private JButton reset;
+    private JButton customEdit;
+    private JButton help;
+
+    public UI() throws JAXBException, SAXException, ParserConfigurationException, XPathExpressionException, IOException, TransformerException{
+       zip=new Zipper();
+       dh=new DocHandler();
+       input=dh.getDocInstance();
+       node=input;
+       node.appendChild(input.createElement("record"));
+       node.getFirstChild().appendChild(input.createElement("id"));
+       node.getFirstChild().appendChild(input.createElement("intake"));
+       
+       fc=new JFileChooser();
+       fc.setFileFilter(new FileNameExtensionFilter("Zip Archive", "zip"));
+       
+       
+       heading=new JLabel("Diet Survey", JLabel.CENTER);
+       heading.setFont(new java.awt.Font(null, 0, 24));
+       
+       id=new IdPanel();
+       
+       food=new FoodPanel();
+       
+       result=new ResultPanel();
+       
+       helpFrame=Help.getInstance();
+       
+       next=new JButton("Next Section>");
+       next.setActionCommand("next");
+       next.addActionListener(this);
+       
+       prev=new JButton("<Previous Section");
+       prev.setActionCommand("prev");
+       prev.addActionListener(this);
+       prev.setEnabled(false);
+       
+       finish=new JButton("Finish");
+       finish.setActionCommand("finish");
+       finish.addActionListener(this);
+       finish.setEnabled(false);
+       
+       save=new JButton("Save Report to File");
+       save.setActionCommand("save");
+       save.addActionListener(this);
+       save.setEnabled(false);
+       
+       view=new JButton("View Full Report");
+       view.setActionCommand("view");
+       view.addActionListener(this);
+       view.setEnabled(false);
+       
+       reset=new JButton("Restart Survey");
+       reset.setActionCommand("reset");
+       reset.addActionListener(this);
+       
+       customEdit=new JButton("Edit");
+       customEdit.setToolTipText("Edit Custom Food List");
+       customEdit.setActionCommand("customEdit");
+       customEdit.addActionListener(this);
+       
+       help=new JButton("Help");
+       help.setActionCommand("help");
+       help.addActionListener(this);
+
+       layout=new GroupLayout(getContentPane());
+       getContentPane().setLayout(layout);
+       layout.setAutoCreateGaps(true);
+       layout.setAutoCreateContainerGaps(true);
+       layout.setVerticalGroup(
+               layout.createSequentialGroup()
+               .addComponent(heading, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
+               .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE)
+               .addComponent(id, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+               .addGroup(layout.createParallelGroup()
+                       .addComponent(prev)
+                       .addComponent(next)
+                       .addComponent(finish)
+                       .addComponent(customEdit)
+                       .addComponent(help))
+                       .addGap(25)
+               );
+       layout.setHorizontalGroup(
+               layout.createParallelGroup()
+               .addComponent(heading, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+               .addComponent(id, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+               .addGroup(layout.createSequentialGroup()
+                       .addComponent(prev)
+                       .addComponent(next)
+                       .addComponent(finish)
+                       .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+                       .addComponent(customEdit)
+                       .addComponent(help))
+               );
+       
+       try{
+           custom=new CustomFood();
+       }catch(Exception e){
+           JOptionPane.showMessageDialog(this, "Problem opening custom_food.xml\nFile may contain error."+e.toString(), "Error", JOptionPane.ERROR_MESSAGE);
+           customEdit.setEnabled(false);
+       }
+       
+       setTitle("Diet Survey");
+       pack();
+       setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
+       addWindowListener(new WindowAdapter(){
+           @Override
+           public void windowClosing(WindowEvent we){
+               int ret;
+               if(unsaved){
+                   ret=JOptionPane.showConfirmDialog(null, "Exiting may result in loss of unsaved data.\nDo you want to exit?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
+                   if(ret!=JFileChooser.APPROVE_OPTION)
+                       return;
+               }
+               System.exit(0);
+           }
+       });
+       SwingWorker<Void, Void> worker=new SwingWorker<Void, Void>() {
+           @Override
+           protected Void doInBackground() throws Exception {
+               Update.checkUpdate();
+               return null;
+           }
+       };
+       worker.execute();
+       setSize(800, 600);
+       setLocationRelativeTo(null);
+       setResizable(true);
+    }
+    
+    private static String getAppLocation(){
+       try {
+           String loc;
+           loc=new File(UI.class.getProtectionDomain().getCodeSource().getLocation().toURI()).toString();
+           String[] array=loc.split(File.separator+File.separator);
+           loc="";
+           for(int i=0; i<array.length; i++){
+               if(array[i].endsWith(".jar")||array[i].endsWith(".zip")||array[i].endsWith(".exe"))
+                   return loc;
+               else
+                   loc=loc+array[i]+File.separator;
+           }
+           loc=loc.substring(0, loc.length()-1);
+           return loc;
+       }
+       catch (Exception e){
+           e.printStackTrace();
+           return "";
+       }
+    }
+
+    public void saveFile(File file){
+       report=new ArrayList<InputStream>();
+       try {
+           report.add(dh.getAsInputStream(input));
+           report.add(dh.getAsInputStream(output));
+           report.add(dh.generateReport(input, output));
+           report.add(assesser.getGraphImage());
+           report.add(java.lang.ClassLoader.getSystemResourceAsStream("com/agnibho/code/resources/style.css"));
+           zip.writeZip(file, report);
+           unsaved=false;
+       } catch (TransformerException | TransformerFactoryConfigurationError | IOException e) {
+           JOptionPane.showMessageDialog(this, "An error has occured.\n"+e.toString(), "Error", JOptionPane.ERROR_MESSAGE);
+           e.printStackTrace();
+       }
+    }
+
+    @Override
+    public void actionPerformed(ActionEvent ae){
+       if(ae.getActionCommand().equals("next")){
+           if(id.isComplete()){
+               layout.replace(id, food);
+               try {
+                   food.loadData();
+               } catch (TransformerConfigurationException | XPathExpressionException | SAXException | IOException | ParserConfigurationException e) {
+                   JOptionPane.showMessageDialog(this, "An error has occured.\n"+e.toString(), "Error", JOptionPane.ERROR_MESSAGE);
+                   e.printStackTrace();
+               }
+               prev.setEnabled(true);
+               next.setEnabled(false);
+               finish.setEnabled(true);
+               customEdit.setVisible(false);
+           }
+       }
+       else if(ae.getActionCommand().equals("prev")){
+           layout.replace(food, id);
+           prev.setEnabled(false);
+           next.setEnabled(true);
+           finish.setEnabled(false);
+       }
+       else if(ae.getActionCommand().equals("finish")){
+           if(id.isComplete()&&food.isComplete()){
+               try {
+                   input=id.copyToDoc(input);
+                   input=food.copyToDoc(input);
+                   assesser=new Assess(input);
+                   output=assesser.getOutput();
+                   layout.replace(food, result);
+                   layout.replace(prev, save);
+                   save.setEnabled(true);
+                   layout.replace(next, view);
+                   view.setEnabled(true);
+                   layout.replace(finish, reset);
+                   reset.setEnabled(true);
+                   result.display(dh.generateSummary(output));
+               } catch (XPathExpressionException | ParserConfigurationException | TransformerException | SAXException | IOException e) {
+                   JOptionPane.showMessageDialog(this, "An error has occured.\n"+e.toString(), "Error", JOptionPane.ERROR_MESSAGE);
+                   e.printStackTrace();
+               }
+               unsaved=true;
+               JOptionPane.showMessageDialog(this, "Survey Complete!", "Complete", JOptionPane.INFORMATION_MESSAGE);
+           }
+       }
+       else if(ae.getActionCommand().equals("save")){
+           int ret=fc.showSaveDialog(this);
+           if(ret==JFileChooser.APPROVE_OPTION){
+               File file=fc.getSelectedFile();
+               if(!file.getName().endsWith(".zip"))
+                   file=new File(file.getAbsolutePath()+".zip");
+               if(file.exists()){
+                   ret=JOptionPane.showConfirmDialog(this, "The file you selected already exists.\nDo you want to overwrite the file?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
+                   if(ret==JOptionPane.YES_OPTION){
+                       saveFile(file);
+                   }
+               }
+               else{
+                   saveFile(file);
+               }
+           }
+       }
+       else if(ae.getActionCommand().equals("view")){
+           try {
+               if(path==null){
+                   path=Files.createTempDirectory(Paths.get(UI.LOC), null);
+                   path.toFile().deleteOnExit();
+               }
+               
+               int read = 0;
+               byte[] bytes = new byte[1024];
+               InputStream is;
+               FileOutputStream fos;
+               File file;
+               
+               is=dh.generateReport(input, output);
+               file=new File(path.toString()+File.separator+"report.html");
+               fos=new FileOutputStream(file);
+               while ((read=is.read(bytes))!=-1) {
+                   fos.write(bytes, 0, read);
+               }
+               fos.close();
+               file.deleteOnExit();
+               
+               is=assesser.getGraphImage();
+               file=new File(path.toString()+File.separator+"bar_diagram.png");
+               fos=new FileOutputStream(file);
+               while ((read=is.read(bytes))!=-1) {
+                   fos.write(bytes, 0, read);
+               }
+               fos.close();
+               file.deleteOnExit();
+               
+               is=java.lang.ClassLoader.getSystemResourceAsStream("com/agnibho/code/resources/style.css");
+               file=new File(path.toString()+File.separator+"style.css");
+               fos=new FileOutputStream(file);
+               while ((read=is.read(bytes))!=-1) {
+                   fos.write(bytes, 0, read);
+               }
+               fos.close();
+               file.deleteOnExit();
+
+               Desktop.getDesktop().open(new File(path.toString()+File.separator+"report.html"));
+           } catch (IOException | TransformerException e) {
+               e.printStackTrace();
+           }
+       }
+       else if(ae.getActionCommand().equals("reset")){
+           try {
+               int ret;
+               if(unsaved){
+                   ret=JOptionPane.showConfirmDialog(this, "Restarting survey may result in loss of unsaved data.\nDo you want to restart the survey?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
+                   if(ret!=JFileChooser.APPROVE_OPTION)
+                       return;
+               }
+               id=new IdPanel();
+               layout.replace(result, id);
+               layout.replace(save, prev);
+               prev.setEnabled(false);
+               layout.replace(view, next);
+               next.setEnabled(true);
+               layout.replace(reset, finish);
+               finish.setEnabled(false);
+               customEdit.setVisible(true);
+               food=new FoodPanel();
+               result=new ResultPanel();
+               
+               input=dh.getDocInstance();
+               node=input;
+               node.appendChild(input.createElement("record"));
+               node.getFirstChild().appendChild(input.createElement("id"));
+               node.getFirstChild().appendChild(input.createElement("intake"));
+           } catch (TransformerConfigurationException | XPathExpressionException | SAXException | IOException | ParserConfigurationException e) {
+               JOptionPane.showMessageDialog(this, "An error has occured.\n"+e.toString(), "Error", JOptionPane.ERROR_MESSAGE);
+               e.printStackTrace();
+           }
+       }
+       else if(ae.getActionCommand().equals("help")){
+           if(helpFrame.isVisible())
+               helpFrame.toFront();
+           else
+               helpFrame.setVisible(true);
+       }
+       else if(ae.getActionCommand().equals("customEdit"))
+           custom.setVisible(true);
+    }
+
+
+
+    /**
+     * @param args the command line arguments
+     */
+    public static void main(String[] args) {
+       SwingUtilities.invokeLater(new Runnable(){
+           public void run(){
+               try{
+                   UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+               }
+               catch (Exception ex){
+                   JOptionPane.showMessageDialog(null, "An error has occured.\n"+ex.toString(), "Error", JOptionPane.ERROR_MESSAGE);
+                   ex.printStackTrace();
+               }
+               try {
+                   new UI().setVisible(true);
+               } catch (JAXBException | SAXException | ParserConfigurationException | XPathExpressionException | IOException | TransformerException e) {
+                   JOptionPane.showMessageDialog(null, "An error has occured.\n"+e.toString(), "Error", JOptionPane.ERROR_MESSAGE);
+                   e.printStackTrace();
+               }
+           }
+       });
+    }
+}
diff --git a/com/agnibho/code/dietSurvey/Update.java b/com/agnibho/code/dietSurvey/Update.java
new file mode 100644 (file)
index 0000000..28e1c95
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+    Diet-Survey: Perform diet survey based on 24 hours recall
+    Copyright (C) 2013  Agnibho Mondal
+    
+    This file is part of Diet-Survey.
+
+    Diet-Survey 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.
+
+    Diet-Survey 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 Diet-Survey.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+package com.agnibho.code.dietSurvey;
+
+import java.awt.Desktop;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import javax.swing.JOptionPane;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.xpath.XPathExpressionException;
+
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+public class Update {
+
+    public static final String VERSION="1.0.1";
+    public static final String UPDATE_URL="http://cdn.agnibho.com/java/diet-survey/version/";
+    
+    public enum Status {NOT_CHECKED, UP_TO_DATE, NEW_VERSION_AVAILABLE}
+
+    public static String updateVersion;
+    public static Status currentStatus=Status.NOT_CHECKED;
+
+    private Update() {
+
+    }
+
+    public static void checkUpdate() throws IOException, TransformerConfigurationException, SAXException, ParserConfigurationException, XPathExpressionException {
+       URL url=new URL(Update.UPDATE_URL);
+       InputStream in=url.openStream();
+       Document doc=new DocHandler().getDocument(in);
+       updateVersion=DocHandler.getXpInstance().evaluate("/version/current", doc);
+       in.close();
+
+       int[] usingVer=new int[3];
+       int[] updateVer=new int[3];
+
+       String[] array;
+       array=VERSION.split("\\.");
+       usingVer[0]=Integer.parseInt(array[0]);
+       usingVer[1]=Integer.parseInt(array[1]);
+       usingVer[2]=Integer.parseInt(array[2]);
+       array=updateVersion.split("\\.");
+       updateVer[0]=Integer.parseInt(array[0]);
+       updateVer[1]=Integer.parseInt(array[1]);
+       updateVer[2]=Integer.parseInt(array[2]);
+
+       if(usingVer[0]<updateVer[0]){
+           currentStatus=Status.NEW_VERSION_AVAILABLE;
+           showUpdate();
+       }
+       else if(usingVer[1]<updateVer[1]){
+           currentStatus=Status.NEW_VERSION_AVAILABLE;
+           showUpdate();
+       }
+       else if(usingVer[2]<updateVer[2]){
+           currentStatus=Status.NEW_VERSION_AVAILABLE;
+           showUpdate();
+       }
+       else{
+           currentStatus=Status.UP_TO_DATE;
+       }
+    }
+    public static void showUpdate(){
+       int ret=JOptionPane.showConfirmDialog(null, "Version "+updateVersion+" is available.\nVisit the download page now?", "New Version Available", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
+       if(ret==JOptionPane.YES_OPTION){
+           try {
+               Desktop.getDesktop().browse(new URL("http://code.agnibho.com/diet-survey/").toURI());
+           } catch (IOException | URISyntaxException e) {
+               e.printStackTrace();
+           }
+       }
+    }
+    public static void showUpToDate(){
+       JOptionPane.showMessageDialog(null, "The program is up to date.", "Up to date", JOptionPane.INFORMATION_MESSAGE);
+    }
+
+}
diff --git a/com/agnibho/code/dietSurvey/Zipper.java b/com/agnibho/code/dietSurvey/Zipper.java
new file mode 100644 (file)
index 0000000..0534a83
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+    Diet-Survey: Perform diet survey based on 24 hours recall
+    Copyright (C) 2013  Agnibho Mondal
+    
+    This file is part of Diet-Survey.
+
+    Diet-Survey 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.
+
+    Diet-Survey 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 Diet-Survey.  If not, see <http://www.gnu.org/licenses/>.
+*/
+package com.agnibho.code.dietSurvey;
+
+import java.awt.Desktop;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import javax.swing.JOptionPane;
+
+public class Zipper {
+    
+    private InputStream in;
+    private FileOutputStream fos;
+    private ZipOutputStream zos;
+    private ZipEntry ze;
+
+    public Zipper() {
+       
+    }
+
+    public void writeZip(File output, List<InputStream> files) throws IOException{
+       try {
+           byte[] buffer=new byte[1024];
+           
+           fos=new FileOutputStream(output);
+           zos=new ZipOutputStream(fos);
+           for(int i=0; i<files.size(); i++){
+               if(i==0)
+                   ze=new ZipEntry("input.xml");
+               else if(i==1)
+                   ze=new ZipEntry("assessment.xml");
+               else if(i==2)
+                   ze=new ZipEntry("report.html");
+               else if(i==3)
+                   ze=new ZipEntry("bar_diagram.png");
+               else if(i==4)
+                   ze=new ZipEntry("style.css");
+               else
+                   ze=new ZipEntry(String.valueOf(i)+".xml");
+               zos.putNextEntry(ze);
+               in=files.get(i);
+               
+               int len;
+               while((len=in.read(buffer))>0){
+                   zos.write(buffer, 0, len);
+               }
+               in.close();
+               zos.closeEntry();
+               Desktop.getDesktop().open(output);
+           }
+           zos.close();
+       } catch (FileNotFoundException e) {
+           JOptionPane.showMessageDialog(null, "An error has occured.\n"+e.toString(), "Error", JOptionPane.ERROR_MESSAGE);
+           e.printStackTrace();
+       }
+    }
+}
diff --git a/com/agnibho/code/resources/customFood.xsd b/com/agnibho/code/resources/customFood.xsd
new file mode 100644 (file)
index 0000000..b9a2e9d
--- /dev/null
@@ -0,0 +1,70 @@
+<?xml version="1.0"?>
+
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+xmlns="http://www.w3schools.com"
+elementFormDefault="qualified">
+
+<xs:element name="foodList">
+       <xs:complexType>
+               <xs:sequence>
+                       <xs:element name="food" minOccurs="0" maxOccurs="unbounded">
+                               <xs:complexType>
+                                       <xs:all>
+                                               <xs:element name="name" type="xs:string"/>
+                                               <xs:element name="group" type="xs:string"/>
+                                               <xs:element name="energy">
+                                                       <xs:simpleType>
+                                                               <xs:restriction base="xs:decimal">
+                                                                       <xs:minInclusive value="0"/>
+                                                               </xs:restriction>
+                                                       </xs:simpleType>
+                                               </xs:element>
+                                               <xs:element name="protein">
+                                                       <xs:simpleType>
+                                                               <xs:restriction base="xs:decimal">
+                                                                       <xs:minInclusive value="0"/>
+                                                               </xs:restriction>
+                                                       </xs:simpleType>
+                                               </xs:element>
+                                               <xs:element name="iron">
+                                                       <xs:simpleType>
+                                                               <xs:restriction base="xs:decimal">
+                                                                       <xs:minInclusive value="0"/>
+                                                               </xs:restriction>
+                                                       </xs:simpleType>
+                                               </xs:element>
+                                               <xs:element name="vitA">
+                                                       <xs:simpleType>
+                                                               <xs:restriction base="xs:decimal">
+                                                                       <xs:minInclusive value="0"/>
+                                                               </xs:restriction>
+                                                       </xs:simpleType>
+                                               </xs:element>
+                                               <xs:element name="thiamine">
+                                                       <xs:simpleType>
+                                                               <xs:restriction base="xs:decimal">
+                                                                       <xs:minInclusive value="0"/>
+                                                               </xs:restriction>
+                                                       </xs:simpleType>
+                                               </xs:element>
+                                               <xs:element name="riboflavin">
+                                                       <xs:simpleType>
+                                                               <xs:restriction base="xs:decimal">
+                                                                       <xs:minInclusive value="0"/>
+                                                               </xs:restriction>
+                                                       </xs:simpleType>
+                                               </xs:element>
+                                               <xs:element name="vitC">
+                                                       <xs:simpleType>
+                                                               <xs:restriction base="xs:decimal">
+                                                                       <xs:minInclusive value="0"/>
+                                                               </xs:restriction>
+                                                       </xs:simpleType>
+                                               </xs:element>
+                                       </xs:all>
+                               </xs:complexType>
+                       </xs:element>
+               </xs:sequence>
+       </xs:complexType>
+</xs:element>
+</xs:schema>
\ No newline at end of file
diff --git a/com/agnibho/code/resources/food.xml b/com/agnibho/code/resources/food.xml
new file mode 100644 (file)
index 0000000..ce9961f
--- /dev/null
@@ -0,0 +1,510 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<foodList xmlns="http://hobbyware.wordpress.com/DietSurvey">
+       <food>
+               <name>Rice, parboiled milled</name>
+               <group>Cereals</group>
+               <energy>348</energy>
+               <protein>6.4</protein>
+               <fat>0.4</fat>
+               <iron>1.0</iron>
+               <calcium>9.0</calcium>
+               <vitA>0.0</vitA>
+               <vitC>0.0</vitC>
+               <thiamine>0.21</thiamine>
+               <riboflavin>0.05</riboflavin>
+       </food>
+       <food>
+               <name>Wheat Flour, whole</name>
+               <group>Cereals</group>
+               <energy>341</energy>
+               <protein>12.1</protein>
+               <fat>1.7</fat>
+               <iron>4.9</iron>
+               <calcium>48</calcium>
+               <vitA>29</vitA>
+               <vitC>0.0</vitC>
+               <thiamine>0.49</thiamine>
+               <riboflavin>0.17</riboflavin>
+       </food>
+       <food>
+               <name>Dal, green gram</name>
+               <group>Pulses</group>
+               <energy>348</energy>
+               <protein>24.5</protein>
+               <fat>1.2</fat>
+               <iron>3.9</iron>
+               <calcium>75</calcium>
+               <vitA>49</vitA>
+               <vitC>0.0</vitC>
+               <thiamine>0.47</thiamine>
+               <riboflavin>0.21</riboflavin>
+       </food>
+       <food>
+               <name>Lentil</name>
+               <group>Pulses</group>
+               <energy>343</energy>
+               <protein>25.1</protein>
+               <fat>0.6</fat>
+               <iron>7.60</iron>
+               <calcium>69</calcium>
+               <vitA>270</vitA>
+               <vitC>0.0</vitC>
+               <thiamine>0.45</thiamine>
+               <riboflavin>0.20</riboflavin>
+       </food>
+       <food>
+               <name>Soyabean</name>
+               <group>Pulses</group>
+               <energy>432</energy>
+               <protein>43.2</protein>
+               <fat>19.5</fat>
+               <iron>10.4</iron>
+               <calcium>240</calcium>
+               <vitA>426</vitA>
+               <vitC>0.0</vitC>
+               <thiamine>0.73</thiamine>
+               <riboflavin>0.39</riboflavin>
+       </food>
+       <food>
+               <name>Ground nut</name>
+               <group>Nuts and oilseeds</group>
+               <energy>567</energy>
+               <protein>25.3</protein>
+               <fat>40.1</fat>
+               <iron>2.5</iron>
+               <calcium>90</calcium>
+               <vitA>37</vitA>
+               <vitC>0.0</vitC>
+               <thiamine>0.9</thiamine>
+               <riboflavin>0.13</riboflavin>
+       </food>
+       <food>
+               <name>Amaranth</name>
+               <group>Green leafy vegetables</group>
+               <energy>45</energy>
+               <protein>4.0</protein>
+               <fat>0.5</fat>
+               <iron>3.49</iron>
+               <calcium>397</calcium>
+               <vitA>5520</vitA>
+               <vitC>99</vitC>
+               <thiamine>0.03</thiamine>
+               <riboflavin>0.3</riboflavin>
+       </food>
+       <food>
+               <name>Cabbage</name>
+               <group>Green leafy vegetables</group>
+               <energy>27</energy>
+               <protein>1.8</protein>
+               <fat>0.1</fat>
+               <iron>0.8</iron>
+               <calcium>39</calcium>
+               <vitA>120</vitA>
+               <vitC>124</vitC>
+               <thiamine>0.06</thiamine>
+               <riboflavin>0.09</riboflavin>
+       </food>
+       <food>
+               <name>Spinach</name>
+               <group>Green leafy vegetables</group>
+               <energy>26</energy>
+               <protein>2.0</protein>
+               <fat>0.7</fat>
+               <iron>1.14</iron>
+               <calcium>73</calcium>
+               <vitA>5580</vitA>
+               <vitC>28</vitC>
+               <thiamine>0.03</thiamine>
+               <riboflavin>0.25</riboflavin>
+       </food>
+       <food>
+               <name>Bottle gourd</name>
+               <group>Other vegetables</group>
+               <energy>12</energy>
+               <protein>0.2</protein>
+               <fat>0.1</fat>
+               <iron>0.46</iron>
+               <calcium>20</calcium>
+               <vitA>0.0</vitA>
+               <vitC>0.0</vitC>
+               <thiamine>0.03</thiamine>
+               <riboflavin>0.01</riboflavin>
+       </food>
+       <food>
+               <name>Brinjal</name>
+               <group>Other vegetables</group>
+               <energy>24</energy>
+               <protein>1.4</protein>
+               <fat>0.3</fat>
+               <iron>0.38</iron>
+               <calcium>18</calcium>
+               <vitA>74</vitA>
+               <vitC>12</vitC>
+               <thiamine>0.04</thiamine>
+               <riboflavin>0.11</riboflavin>
+       </food>
+       <food>
+               <name>Cauliflower</name>
+               <group>Other vegetables</group>
+               <energy>30</energy>
+               <protein>2.6</protein>
+               <fat>0.4</fat>
+               <iron>1.23</iron>
+               <calcium>33</calcium>
+               <vitA>30</vitA>
+               <vitC>56</vitC>
+               <thiamine>0.04</thiamine>
+               <riboflavin>0.10</riboflavin>
+       </food>
+       <food>
+               <name>Cucumber</name>
+               <group>Other vegetables</group>
+               <energy>13</energy>
+               <protein>0.4</protein>
+               <fat>0.1</fat>
+               <iron>0.60</iron>
+               <calcium>10</calcium>
+               <vitA>0.0</vitA>
+               <vitC>7.0</vitC>
+               <thiamine>0.03</thiamine>
+               <riboflavin>0.0</riboflavin>
+       </food>
+       <food>
+               <name>Ladies finger</name>
+               <group>Other vegetables</group>
+               <energy>35</energy>
+               <protein>1.9</protein>
+               <fat>0.2</fat>
+               <iron>0.35</iron>
+               <calcium>66</calcium>
+               <vitA>52</vitA>
+               <vitC>13</vitC>
+               <thiamine>0.07</thiamine>
+               <riboflavin>0.10</riboflavin>
+       </food>
+       <food>
+               <name>Papaya, green</name>
+               <group>Other vegetables</group>
+               <energy>27</energy>
+               <protein>0.7</protein>
+               <fat>0.2</fat>
+               <iron>0.9</iron>
+               <calcium>28</calcium>
+               <vitA>0.0</vitA>
+               <vitC>12</vitC>
+               <thiamine>0.01</thiamine>
+               <riboflavin>0.01</riboflavin>
+       </food>
+       <food>
+               <name>Parwar</name>
+               <group>Other vegetables</group>
+               <energy>20</energy>
+               <protein>2.0</protein>
+               <fat>0.3</fat>
+               <iron>1.7</iron>
+               <calcium>30</calcium>
+               <vitA>153</vitA>
+               <vitC>29</vitC>
+               <thiamine>0.05</thiamine>
+               <riboflavin>0.06</riboflavin>
+       </food>
+       <food>
+               <name>Pumpkin</name>
+               <group>Other vegetables</group>
+               <energy>25</energy>
+               <protein>1.4</protein>
+               <fat>0.1</fat>
+               <iron>0.44</iron>
+               <calcium>10.0</calcium>
+               <vitA>50.0</vitA>
+               <vitC>2.0</vitC>
+               <thiamine>0.06</thiamine>
+               <riboflavin>0.04</riboflavin>
+       </food>
+       <food>
+               <name>Plantain, green</name>
+               <group>Other vegetables</group>
+               <energy>64</energy>
+               <protein>1.4</protein>
+               <fat>0.2</fat>
+               <iron>6.27</iron>
+               <calcium>10</calcium>
+               <vitA>30</vitA>
+               <vitC>24</vitC>
+               <thiamine>0.05</thiamine>
+               <riboflavin>0.02</riboflavin>
+       </food>
+       <food>
+               <name>Carrot</name>
+               <group>Roots and tubers</group>
+               <energy>48</energy>
+               <protein>0.9</protein>
+               <fat>0.2</fat>
+               <iron>1.03</iron>
+               <calcium>80.0</calcium>
+               <vitA>1890.0</vitA>
+               <vitC>3.0</vitC>
+               <thiamine>0.04</thiamine>
+               <riboflavin>0.02</riboflavin>
+       </food>
+       <food>
+               <name>Onion</name>
+               <group>Roots and tubers</group>
+               <energy>50</energy>
+               <protein>1.2</protein>
+               <fat>0.1</fat>
+               <iron>0.6</iron>
+               <calcium>47.0</calcium>
+               <vitA>0.0</vitA>
+               <vitC>11</vitC>
+               <thiamine>0.06</thiamine>
+               <riboflavin>0.01</riboflavin>
+       </food>
+       <food>
+               <name>Potato</name>
+               <group>Roots and tubers</group>
+               <energy>97</energy>
+               <protein>1.6</protein>
+               <fat>0.1</fat>
+               <iron>0.48</iron>
+               <calcium>10</calcium>
+               <vitA>24</vitA>
+               <vitC>17</vitC>
+               <thiamine>0.10</thiamine>
+               <riboflavin>0.01</riboflavin>
+       </food>
+       <food>
+               <name>Radish</name>
+               <group>Roots and tubers</group>
+               <energy>32</energy>
+               <protein>0.6</protein>
+               <fat>0.3</fat>
+               <iron>0.37</iron>
+               <calcium>50</calcium>
+               <vitA>3</vitA>
+               <vitC>17</vitC>
+               <thiamine>0.06</thiamine>
+               <riboflavin>0.02</riboflavin>
+       </food>
+       <food>
+               <name>Amla</name>
+               <group>Fruits</group>
+               <energy>58</energy>
+               <protein>0.5</protein>
+               <fat>0.1</fat>
+               <iron>1.20</iron>
+               <calcium>50</calcium>
+               <vitA>9</vitA>
+               <vitC>600</vitC>
+               <thiamine>0.03</thiamine>
+               <riboflavin>0.01</riboflavin>
+       </food>
+       <food>
+               <name>Apple</name>
+               <group>Fruits</group>
+               <energy>59</energy>
+               <protein>0.2</protein>
+               <fat>0.66</fat>
+               <iron>1.00</iron>
+               <calcium>10</calcium>
+               <vitA>0</vitA>
+               <vitC>1</vitC>
+               <thiamine>0</thiamine>
+               <riboflavin>0</riboflavin>
+       </food>
+       <food>
+               <name>Banana, ripe</name>
+               <group>Fruits</group>
+               <energy>116</energy>
+               <protein>1.2</protein>
+               <fat>0.36</fat>
+               <iron>0.90</iron>
+               <calcium>17</calcium>
+               <vitA>78</vitA>
+               <vitC>7</vitC>
+               <thiamine>0.05</thiamine>
+               <riboflavin>0.08</riboflavin>
+       </food>
+       <food>
+               <name>Grape</name>
+               <group>71</group>
+               <energy>0.5</energy>
+               <protein>0.3</protein>
+               <fat>0.50</fat>
+               <iron>20</iron>
+               <calcium>0</calcium>
+               <vitA>1</vitA>
+               <vitC>0</vitC>
+               <thiamine>0</thiamine>
+               <riboflavin>0</riboflavin>
+       </food>
+       <food>
+               <name>Lemon</name>
+               <group>Fruits</group>
+               <energy>57</energy>
+               <protein>1.0</protein>
+               <fat>0.9</fat>
+               <iron>0.26</iron>
+               <calcium>70</calcium>
+               <vitA>0</vitA>
+               <vitC>39</vitC>
+               <thiamine>0.02</thiamine>
+               <riboflavin>0.01</riboflavin>
+       </food>
+       <food>
+               <name>Guava</name>
+               <group>Fruits</group>
+               <energy>51</energy>
+               <protein>0.9</protein>
+               <fat>0.3</fat>
+               <iron>0.27</iron>
+               <calcium>10</calcium>
+               <vitA>0</vitA>
+               <vitC>212</vitC>
+               <thiamine>0.03</thiamine>
+               <riboflavin>0.03</riboflavin>
+       </food>
+       <food>
+               <name>Mango, ripe</name>
+               <group>Fruits</group>
+               <energy>74</energy>
+               <protein>0.6</protein>
+               <fat>0.4</fat>
+               <iron>1.30</iron>
+               <calcium>14</calcium>
+               <vitA>2743</vitA>
+               <vitC>16</vitC>
+               <thiamine>0.06</thiamine>
+               <riboflavin>0.09</riboflavin>
+       </food>
+       <food>
+               <name>Orange</name>
+               <group>Fruits</group>
+               <energy>48</energy>
+               <protein>0.7</protein>
+               <fat>0.2</fat>
+               <iron>0.32</iron>
+               <calcium>26</calcium>
+               <vitA>1104</vitA>
+               <vitC>30</vitC>
+               <thiamine>0</thiamine>
+               <riboflavin>0</riboflavin>
+       </food>
+       <food>
+               <name>Papaya, ripe</name>
+               <group>Fruits</group>
+               <energy>32</energy>
+               <protein>0.6</protein>
+               <fat>0.1</fat>
+               <iron>0.50</iron>
+               <calcium>17</calcium>
+               <vitA>666</vitA>
+               <vitC>57</vitC>
+               <thiamine>0.04</thiamine>
+               <riboflavin>0.25</riboflavin>
+       </food>
+       <food>
+               <name>Tomato, ripe</name>
+               <group>Fruits</group>
+               <energy>20</energy>
+               <protein>0.9</protein>
+               <fat>0.2</fat>
+               <iron>0.64</iron>
+               <calcium>48</calcium>
+               <vitA>351</vitA>
+               <vitC>27</vitC>
+               <thiamine>0.12</thiamine>
+               <riboflavin>0.06</riboflavin>
+       </food>
+       <food>
+               <name>Milk, cow</name>
+               <group>Milk and milk products</group>
+               <energy>67</energy>
+               <protein>3.2</protein>
+               <fat>4.1</fat>
+               <iron>0.20</iron>
+               <calcium>120</calcium>
+               <vitA>53</vitA>
+               <vitC>2</vitC>
+               <thiamine>0.05</thiamine>
+               <riboflavin>0.19</riboflavin>
+       </food>
+       <food>
+               <name>Milk, human</name>
+               <group>Milk and milk products</group>
+               <energy>65</energy>
+               <protein>1.1</protein>
+               <fat>3.4</fat>
+               <iron>0</iron>
+               <calcium>28</calcium>
+               <vitA>41</vitA>
+               <vitC>3</vitC>
+               <thiamine>0.02</thiamine>
+               <riboflavin>0.02</riboflavin>
+       </food>
+       <food>
+               <name>Egg, hen</name>
+               <group>Flesh foods</group>
+               <energy>173</energy>
+               <protein>13.3</protein>
+               <fat>13.3</fat>
+               <iron>2.10</iron>
+               <calcium>60</calcium>
+               <vitA>420</vitA>
+               <vitC>0</vitC>
+               <thiamine>0.10</thiamine>
+               <riboflavin>0.40</riboflavin>
+       </food>
+       <food>
+               <name>Fish, rohu</name>
+               <group>Flesh foods</group>
+               <energy>92</energy>
+               <protein>16.6</protein>
+               <fat>1.4</fat>
+               <iron>1.00</iron>
+               <calcium>650</calcium>
+               <vitA>0</vitA>
+               <vitC>22</vitC>
+               <thiamine>0.05</thiamine>
+               <riboflavin>0.07</riboflavin>
+       </food>
+       <food>
+               <name>Chillies, green</name>
+               <group>Spices and condiments</group>
+               <energy>29</energy>
+               <protein>2.9</protein>
+               <fat>0.6</fat>
+               <iron>4.4</iron>
+               <calcium>30</calcium>
+               <vitA>175</vitA>
+               <vitC>111</vitC>
+               <thiamine>0.19</thiamine>
+               <riboflavin>0.39</riboflavin>
+       </food>
+       <food>
+               <name>Oil, cooking</name>
+               <group>Fats and oils</group>
+               <energy>900</energy>
+               <protein>0</protein>
+               <fat>100</fat>
+               <iron>0</iron>
+               <calcium>0</calcium>
+               <vitA>0</vitA>
+               <vitC>0</vitC>
+               <thiamine>0</thiamine>
+               <riboflavin>0</riboflavin>
+       </food>
+       <food>
+               <name>Sugar</name>
+               <group>Sugar and jaggery</group>
+               <energy>398</energy>
+               <protein>0.1</protein>
+               <fat>0</fat>
+               <iron>0.16</iron>
+               <calcium>12</calcium>
+               <vitA>0</vitA>
+               <vitC>0</vitC>
+               <thiamine>0</thiamine>
+               <riboflavin>0</riboflavin>
+       </food>
+</foodList>
\ No newline at end of file
diff --git a/com/agnibho/code/resources/rda.xml b/com/agnibho/code/resources/rda.xml
new file mode 100644 (file)
index 0000000..65de48a
--- /dev/null
@@ -0,0 +1,239 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<rda xmlns="http://hobbyware.wordpress.com/DietSurvey">
+       <energy>
+               <infant>
+                       <age lower="0" upper="6">500</age>
+                       <age lower="6" upper="12">670</age>
+               </infant>
+               <male>
+                       <age lower="1" upper="3">1060</age>
+                       <age lower="4" upper="6">1350</age>
+                       <age lower="7" upper="9">1690</age>
+                       <age lower="10" upper="12">2190</age>
+                       <age lower="13" upper="15">2750</age>
+                       <age lower="16" upper="17">3020</age>
+                       <age lower="18">
+                               <sedentary>2320</sedentary>
+                               <moderate>2730</moderate>
+                               <heavy>3490</heavy>
+                       </age>
+               </male>
+               <female>
+                       <age lower="1" upper="3">1060</age>
+                       <age lower="4" upper="6">1350</age>
+                       <age lower="7" upper="9">1690</age>
+                       <age lower="10" upper="12">2010</age>
+                       <age lower="13" upper="15">2330</age>
+                       <age lower="16" upper="17">2440</age>
+                       <age lower="18">
+                               <sedentary>1900</sedentary>
+                               <moderate>2230</moderate>
+                               <heavy>2850</heavy>
+                       </age>
+                       <pregnantExtra>350</pregnantExtra>
+                       <lactatingExtra>
+                               <below6m>600</below6m>
+                               <above6m>520</above6m>
+                       </lactatingExtra>
+               </female>
+       </energy>
+       <protein>
+               <infant>
+                       <age lower="0" upper="6">0</age>
+                       <age lower="6" upper="9">13.4</age>
+                       <age lower="9" upper="12">14.9</age>
+               </infant>
+               <male>
+                       <age lower="1" upper="2">15.1</age>
+                       <age lower="2" upper="3">16.0</age>
+                       <age lower="3" upper="4">17.2</age>
+                       <age lower="4" upper="5">18.3</age>
+                       <age lower="5" upper="6">19.8</age>
+                       <age lower="6" upper="7">23.5</age>
+                       <age lower="7" upper="8">26.6</age>
+                       <age lower="8" upper="9">29.7</age>
+                       <age lower="9" upper="10">33.0</age>
+                       <age lower="10" upper="11">36.3</age>
+                       <age lower="11" upper="12">39.6</age>
+                       <age lower="12" upper="13">43.7</age>
+                       <age lower="13" upper="14">49.8</age>
+                       <age lower="14" upper="15">54.7</age>
+                       <age lower="15" upper="16">58.2</age>
+                       <age lower="16" upper="17">60.8</age>
+                       <age lower="17" upper="18">62.2</age>
+                       <age lower="18">60</age>
+               </male>
+               <female>
+                       <age lower="1" upper="2">14.1</age>
+                       <age lower="2" upper="3">15.1</age>
+                       <age lower="3" upper="4">16.8</age>
+                       <age lower="4" upper="5">17.8</age>
+                       <age lower="5" upper="6">19.3</age>
+                       <age lower="6" upper="7">23.0</age>
+                       <age lower="7" upper="8">26.1</age>
+                       <age lower="8" upper="9">29.5</age>
+                       <age lower="9" upper="10">32.6</age>
+                       <age lower="10" upper="11">36.8</age>
+                       <age lower="11" upper="12">40.0</age>
+                       <age lower="12" upper="13">44.5</age>
+                       <age lower="13" upper="14">49.0</age>
+                       <age lower="14" upper="15">52.8</age>
+                       <age lower="15" upper="16">53.8</age>
+                       <age lower="16" upper="17">54.9</age>
+                       <age lower="17" upper="18">56.0</age>
+                       <age lower="18">55</age>
+                       <pregnant>78</pregnant>
+                       <lactatingBelow6m>74</lactatingBelow6m>
+                       <lactatingAbove6m>68</lactatingAbove6m>
+               </female>
+       </protein>
+       <iron>
+               <infant>
+                       <age lower="0" upper="6">0</age>
+                       <age lower="6" upper="12">5</age>
+               </infant>
+               <male>
+                       <age lower="1" upper="3">9</age>
+                       <age lower="4" upper="6">13</age>
+                       <age lower="7" upper="9">16</age>
+                       <age lower="10" upper="12">21</age>
+                       <age lower="13" upper="15">32</age>
+                       <age lower="16" upper="17">28</age>
+                       <age lower="18">17</age>
+               </male>
+               <female>
+                       <age lower="1" upper="3">9</age>
+                       <age lower="4" upper="6">13</age>
+                       <age lower="7" upper="9">16</age>
+                       <age lower="10" upper="12">27</age>
+                       <age lower="13" upper="15">27</age>
+                       <age lower="16" upper="17">26</age>
+                       <age lower="18">21</age>
+                       <pregnant>35</pregnant>
+                       <lactatingBelow6m>25</lactatingBelow6m>
+                       <lactatingAbove6m>21</lactatingAbove6m>
+               </female>
+       </iron>
+       <vitA>
+               <infant>
+                       <age lower="0" upper="6">0</age>
+                       <age lower="6" upper="12">2100</age>
+               </infant>
+               <male>
+                       <age lower="1" upper="6">3200</age>
+                       <age lower="7" upper="9">4800</age>
+                       <age lower="10" upper="17">4800</age>
+                       <age lower="18">4800</age>
+               </male>
+               <female>
+                       <age lower="1" upper="6">3200</age>
+                       <age lower="7" upper="9">4800</age>
+                       <age lower="10" upper="17">4800</age>
+                       <age lower="18">4800</age>
+                       <pregnant>6400</pregnant>
+                       <lactatingBelow6m>7600</lactatingBelow6m>
+                       <lactatingAbove6m>7600</lactatingAbove6m>
+               </female>
+       </vitA>
+       <thiamine>
+               <infant>
+                       <age lower="0" upper="6">0.2</age>
+                       <age lower="6" upper="12">0.3</age>
+               </infant>
+               <male>
+                       <age lower="1" upper="3">0.5</age>
+                       <age lower="4" upper="6">0.7</age>
+                       <age lower="7" upper="9">0.8</age>
+                       <age lower="10" upper="12">1.1</age>
+                       <age lower="13" upper="15">1.4</age>
+                       <age lower="16" upper="17">1.5</age>
+                       <age lower="18">
+                               <sedentary>1.2</sedentary>
+                               <moderate>1.4</moderate>
+                               <heavy>1.7</heavy>
+                       </age>
+               </male>
+               <female>
+                       <age lower="1" upper="3">0.5</age>
+                       <age lower="4" upper="6">0.7</age>
+                       <age lower="7" upper="9">0.8</age>
+                       <age lower="10" upper="12">1.0</age>
+                       <age lower="13" upper="15">1.2</age>
+                       <age lower="16" upper="17">1.0</age>
+                       <age lower="18">
+                               <sedentary>1</sedentary>
+                               <moderate>1.1</moderate>
+                               <heavy>1.4</heavy>
+                       </age>
+                       <pregnantExtra>0.2</pregnantExtra>
+                       <lactatingExtra>
+                               <below6m>0.3</below6m>
+                               <above6m>0.2</above6m>
+                       </lactatingExtra>
+               </female>
+       </thiamine>
+       <riboflavin>
+               <infant>
+                       <age lower="0" upper="6">0.3</age>
+                       <age lower="6" upper="12">0.4</age>
+               </infant>
+               <male>
+                       <age lower="1" upper="3">0.6</age>
+                       <age lower="4" upper="6">0.8</age>
+                       <age lower="7" upper="9">1.0</age>
+                       <age lower="10" upper="12">1.3</age>
+                       <age lower="13" upper="15">1.6</age>
+                       <age lower="16" upper="17">1.8</age>
+                       <age lower="18">
+                               <sedentary>1.4</sedentary>
+                               <moderate>1.6</moderate>
+                               <heavy>2.1</heavy>
+                       </age>
+               </male>
+               <female>
+                       <age lower="1" upper="3">0.6</age>
+                       <age lower="4" upper="6">0.8</age>
+                       <age lower="7" upper="9">1.0</age>
+                       <age lower="10" upper="12">1.2</age>
+                       <age lower="13" upper="15">1.4</age>
+                       <age lower="16" upper="17">1.2</age>
+                       <age lower="18">
+                               <sedentary>1.1</sedentary>
+                               <moderate>1.3</moderate>
+                               <heavy>1.7</heavy>
+                       </age>
+                       <pregnantExtra>0.3</pregnantExtra>
+                       <lactatingExtra>
+                               <below6m>0.4</below6m>
+                               <above6m>0.3</above6m>
+                       </lactatingExtra>
+               </female>
+       </riboflavin>
+       <vitC>
+               <infant>
+                       <age lower="0" upper="6">25</age>
+                       <age lower="7" upper="12">25</age>
+               </infant>
+               <male>
+                       <age lower="1" upper="3">40</age>
+                       <age lower="4" upper="6">40</age>
+                       <age lower="7" upper="9">40</age>
+                       <age lower="10" upper="12">40</age>
+                       <age lower="13" upper="15">40</age>
+                       <age lower="16" upper="17">40</age>
+                       <age lower="18">40</age>
+               </male>
+               <female>
+                       <age lower="1" upper="3">40</age>
+                       <age lower="4" upper="6">40</age>
+                       <age lower="7" upper="9">40</age>
+                       <age lower="10" upper="12">40</age>
+                       <age lower="13" upper="15">40</age>
+                       <age lower="16" upper="17">40</age>
+                       <age lower="18">40</age>
+                       <pregnant>60</pregnant>
+                       <lactatingBelow6m>80</lactatingBelow6m>
+                       <lactatingAbove6m>80</lactatingAbove6m>
+               </female>
+       </vitC>
+</rda>
\ No newline at end of file
diff --git a/com/agnibho/code/resources/style.css b/com/agnibho/code/resources/style.css
new file mode 100644 (file)
index 0000000..c586439
--- /dev/null
@@ -0,0 +1,111 @@
+h1 {
+background:green;
+color:white;
+text-align:center;
+text-shadow:2px 2px grey;
+font-size:72px;
+border:5px ridge red;
+}
+h2 {
+color:red;
+text-align:center;
+text-shadow:1px 1px grey;
+font-size:48px;
+border:3px ridge green;
+}
+h3{
+color:green;
+text-align:center;
+text-shadow:1px 1px grey;
+font-size:36px;
+border:2px ridge red;
+}
+h5 {
+color:green;
+text-align:center;
+font-size:18px;
+}
+p {
+color:blue;
+text-align:center;
+font-size:24px;
+}
+table {
+border-collapse:collapse;
+border: 2px solid black;
+width: 600px;
+margin-left:auto;
+margin-right:auto;
+}
+table.paired{
+border:none;
+}
+table.sum{
+border:2px ridge orchid;
+}
+caption {
+font-size:28px;
+color:purple;
+text-shadow:1px 1px grey;
+}
+caption.sum{
+background:orchid;
+color:white;
+font-size:36px;
+}
+th, td {
+border: 1px solid black;
+height: 50px;
+text-align:center;
+color:navy;
+}
+th{
+background-color:green;
+color: white;
+}
+td.marked{
+font-weight:bold;
+color:purple;
+}
+td.key{
+border:none;
+text-align:left;
+font-size: 22px;
+font-weight:bold;
+}
+td.value{
+border:none;
+text-align:left;
+font-size: 22px
+}
+td.excess, td.deficient{
+padding-left:20px;
+border:none;
+text-align:left;
+color:white;
+font-size:24px;
+}
+td.excess {
+background:ForestGreen;
+}
+td.deficient{
+background:tomato;
+}
+ul , ol{
+width:600px;
+margin-left:auto;
+margin-right:auto;
+}
+li {
+color:blue;
+text-align:leading;
+font-size:24px;
+}
+img{
+width:600px;
+display:block;
+margin-left:auto;
+margin-right:auto;
+margin-top:50px;
+border:2px ridge indigo;
+}
\ No newline at end of file
diff --git a/com/agnibho/code/resources/style.xsl b/com/agnibho/code/resources/style.xsl
new file mode 100644 (file)
index 0000000..3c325a7
--- /dev/null
@@ -0,0 +1,248 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<xsl:stylesheet version="1.0"
+xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+       <xsl:template match="/">
+               <html>
+                       <head>
+                               <title>Diet Survey</title>
+                               <link rel="stylesheet" type="text/css" href="style.css"/>
+                       </head>
+                       <body>
+                               <h1>Diet Survey</h1>
+                               <h2>Diet survey based on 24 hours recall</h2>
+                               <h3>Family Information</h3>
+                               <table class="paired">
+                                       <tr><td class="key">Head of the Family: </td><td class="value"><xsl:value-of select="/ds/record/id/hof"/></td></tr>
+                                       <tr><td class="key">Date of Survey: </td><td class="value"><xsl:value-of select="/ds/record/id/date"/></td></tr>
+                               </table>
+                               <table>
+                                       <caption>Family Members</caption>
+                                       <tr><th>Name</th><th>Age</th><th>Sex</th></tr>
+                                       <xsl:for-each select="/ds/record/id/member">
+                                               <tr>
+                                                       <td><xsl:value-of select="name"/></td>
+                                                       <td>
+                                                       <xsl:choose>
+                                                               <xsl:when test="boolean(infant)">
+                                                                       <xsl:value-of select="infant"/> months
+                                                               </xsl:when>
+                                                               <xsl:otherwise>
+                                                                       <xsl:value-of select="age"/> years
+                                                               </xsl:otherwise>
+                                                       </xsl:choose>
+                                                       </td>
+                                                       <td><xsl:value-of select="sex"/></td>
+                                               </tr>
+                                       </xsl:for-each>
+                               </table>
+                               <ul>
+                                       <xsl:for-each select="/ds/record/id/member">
+                                               <xsl:if test="age &gt; 18">
+                                                       <li><xsl:value-of select="name"/> is a <xsl:value-of select="occupation"/> worker.</li>
+                                                       <xsl:if test="sex='female'">
+                                                               <xsl:choose>
+                                                                       <xsl:when test="pregnant='true'">
+                                                                               <li><xsl:value-of select="name"/> is pregnant.</li>
+                                                                       </xsl:when>
+                                                                       <xsl:when test="lactating='true'">
+                                                                               <xsl:choose>
+                                                                                       <xsl:when test="beyond6m='true'">
+                                                                                               <li><xsl:value-of select="name"/> is lactating over 6 months.</li>
+                                                                                       </xsl:when>
+                                                                                       <xsl:otherwise>
+                                                                                               <li><xsl:value-of select="name"/> is lactating below 6 months.</li>
+                                                                                       </xsl:otherwise>
+                                                                               </xsl:choose>
+                                                                       </xsl:when>
+                                                                       <xsl:otherwise>
+                                                                               <li><xsl:value-of select="name"/> is non-pregnant and non-lactating.</li>
+                                                                       </xsl:otherwise>
+                                                               </xsl:choose>
+                                                       </xsl:if>
+                                               </xsl:if>
+                                       </xsl:for-each>
+                               </ul>
+                               <h3>Foods consumed in last 24 hours</h3>
+                               <h5>(Amount is in mg or ml)</h5>
+                               <ol>
+                                       <xsl:for-each select="/ds/record/intake/food">
+                                               <li>
+                                                       <b><xsl:value-of select="name"/>: </b>
+                                                       <xsl:value-of select="amount"/>
+                                               </li>
+                                       </xsl:for-each>
+                               </ol>
+                               <h3>Nutrient requirement<sup>1</sup></h3>
+                               <table>
+                                       <tr>
+                                               <th>Name of Member</th><th>Energy (kcal)</th><th>Protein (gm)</th><th>Iron (mg)</th><th>Vitamin A (&#956;g)</th><th>Thiamine (mg)</th><th>Riboflavin (mg)</th><th>Vitamin C (mg)</th>
+                                       </tr>
+                                       <xsl:for-each select="/ds/assessment/requirement/member">
+                                               <tr>
+                                                       <td><xsl:value-of select="name"/></td>
+                                                       <td><xsl:value-of select="format-number(energy, '##0.##')"/></td>
+                                                       <td><xsl:value-of select="format-number(protein, '##0.##')"/></td>
+                                                       <td><xsl:value-of select="format-number(iron, '##0.##')"/></td>
+                                                       <td><xsl:value-of select="format-number(vitA, '##0.##')"/></td>
+                                                       <td><xsl:value-of select="format-number(thiamine, '##0.##')"/></td>
+                                                       <td><xsl:value-of select="format-number(riboflavin, '##0.##')"/></td>
+                                                       <td><xsl:value-of select="format-number(vitC, '##0.##')"/></td>
+                                               </tr>
+                                       </xsl:for-each>
+                                       <tr>
+                                               <td class="marked">Total</td>
+                                               <td class="marked"><xsl:value-of select="format-number(/ds/assessment/requirement/total/energy, '##0.##')"/></td>
+                                               <td class="marked"><xsl:value-of select="format-number(/ds/assessment/requirement/total/protein, '##0.##')"/></td>
+                                               <td class="marked"><xsl:value-of select="format-number(/ds/assessment/requirement/total/iron, '##0.##')"/></td>
+                                               <td class="marked"><xsl:value-of select="format-number(/ds/assessment/requirement/total/vitA, '##0.##')"/></td>
+                                               <td class="marked"><xsl:value-of select="format-number(/ds/assessment/requirement/total/thiamine, '##0.##')"/></td>
+                                               <td class="marked"><xsl:value-of select="format-number(/ds/assessment/requirement/total/riboflavin, '##0.##')"/></td>
+                                               <td class="marked"><xsl:value-of select="format-number(/ds/assessment/requirement/total/vitC, '##0.##')"/></td>
+                                       </tr>
+                               </table>
+                               <h3>Nutritional value of consumed foods<sup>2</sup></h3>
+                               <table>
+                                       <tr>
+                                               <th>Name of Food</th><th>Energy (kcal)</th><th>Protein (g)</th><th>Iron (mg)</th><th>Vitamin A (&#956;g)</th><th>Thiamine (mg)</th><th>Riboflavin (mg)</th><th>Vitamin C (mg)</th>
+                                       </tr>
+                                       <xsl:for-each select="/ds/assessment/consumption/food">
+                                               <tr>
+                                                       <td><xsl:value-of select="name"/></td>
+                                                       <td><xsl:value-of select="format-number(energy, '##0.##')"/></td>
+                                                       <td><xsl:value-of select="format-number(protein, '##0.##')"/></td>
+                                                       <td><xsl:value-of select="format-number(iron, '##0.##')"/></td>
+                                                       <td><xsl:value-of select="format-number(vitA, '##0.##')"/></td>
+                                                       <td><xsl:value-of select="format-number(thiamine, '##0.##')"/></td>
+                                                       <td><xsl:value-of select="format-number(riboflavin, '##0.##')"/></td>
+                                                       <td><xsl:value-of select="format-number(vitC, '##0.##')"/></td>
+                                               </tr>
+                                       </xsl:for-each>
+                                       <tr>
+                                               <td class="marked">Total</td>
+                                               <td class="marked"><xsl:value-of select="format-number(/ds/assessment/consumption/total/energy, '##0.##')"/></td>
+                                               <td class="marked"><xsl:value-of select="format-number(/ds/assessment/consumption/total/protein, '##0.##')"/></td>
+                                               <td class="marked"><xsl:value-of select="format-number(/ds/assessment/consumption/total/iron, '##0.##')"/></td>
+                                               <td class="marked"><xsl:value-of select="format-number(/ds/assessment/consumption/total/vitA, '##0.##')"/></td>
+                                               <td class="marked"><xsl:value-of select="format-number(/ds/assessment/consumption/total/thiamine, '##0.##')"/></td>
+                                               <td class="marked"><xsl:value-of select="format-number(/ds/assessment/consumption/total/riboflavin, '##0.##')"/></td>
+                                               <td class="marked"><xsl:value-of select="format-number(/ds/assessment/consumption/total/vitC, '##0.##')"/></td>
+                                       </tr>
+                               </table>
+                               <h3>Comparison of total nutrients intake</h3>
+                               <table>
+                                       <tr>
+                                               <th>Nutrient</th><th>Requirement</th><th>Intake</th><th>Deficiency/Excess</th>
+                                       </tr>
+                                       <tr>
+                                               <td>Energy</td>
+                                               <td><xsl:value-of select="format-number(/ds/assessment/requirement/total/energy, '##0.##')"/> kcal</td>
+                                               <td><xsl:value-of select="format-number(/ds/assessment/consumption/total/energy, '##0.##')"/> kcal</td>
+                                               <td><xsl:value-of select="format-number(/ds/assessment/nutritionalStatus/energy/amount, '##0.##')"/> kcal 
+                                                       <xsl:value-of select="/ds/assessment/nutritionalStatus/energy/status"/>
+                                                       (<xsl:value-of select="format-number(/ds/assessment/nutritionalStatus/energy/percentage, '##0.##')"/>%)</td>
+                                       </tr>
+                                       <tr>
+                                               <td>Protein</td>
+                                               <td><xsl:value-of select="format-number(/ds/assessment/requirement/total/protein, '##0.##')"/> g</td>
+                                               <td><xsl:value-of select="format-number(/ds/assessment/consumption/total/protein, '##0.##')"/> g</td>
+                                               <td><xsl:value-of select="format-number(/ds/assessment/nutritionalStatus/protein/amount, '##0.##')"/> g 
+                                                       <xsl:value-of select="/ds/assessment/nutritionalStatus/protein/status"/>
+                                                       (<xsl:value-of select="format-number(/ds/assessment/nutritionalStatus/protein/percentage, '##0.##')"/>%)</td>
+                                       </tr>
+                                       <tr>
+                                               <td>Iron</td>
+                                               <td><xsl:value-of select="format-number(/ds/assessment/requirement/total/iron, '##0.##')"/> mg</td>
+                                               <td><xsl:value-of select="format-number(/ds/assessment/consumption/total/iron, '##0.##')"/> mg</td>
+                                               <td><xsl:value-of select="format-number(/ds/assessment/nutritionalStatus/iron/amount, '##0.##')"/> mg 
+                                                       <xsl:value-of select="/ds/assessment/nutritionalStatus/iron/status"/>
+                                                       (<xsl:value-of select="format-number(/ds/assessment/nutritionalStatus/iron/percentage, '##0.##')"/>%)</td>
+                                       </tr>
+                                       <tr>
+                                               <td>Vitamin A</td>
+                                               <td><xsl:value-of select="format-number(/ds/assessment/requirement/total/vitA, '##0.##')"/> &#956;g</td>
+                                               <td><xsl:value-of select="format-number(/ds/assessment/consumption/total/vitA, '##0.##')"/> &#956;g</td>
+                                               <td><xsl:value-of select="format-number(/ds/assessment/nutritionalStatus/vitA/amount, '##0.##')"/> &#956;g 
+                                                       <xsl:value-of select="/ds/assessment/nutritionalStatus/vitA/status"/>
+                                                       (<xsl:value-of select="format-number(/ds/assessment/nutritionalStatus/vitA/percentage, '##0.##')"/>%)</td>
+                                       </tr>
+                                       <tr>
+                                               <td>Thiamine</td>
+                                               <td><xsl:value-of select="format-number(/ds/assessment/requirement/total/thiamine, '##0.##')"/> mg</td>
+                                               <td><xsl:value-of select="format-number(/ds/assessment/consumption/total/thiamine, '##0.##')"/> mg</td>
+                                               <td><xsl:value-of select="format-number(/ds/assessment/nutritionalStatus/thiamine/amount, '##0.##')"/> mg 
+                                                       <xsl:value-of select="/ds/assessment/nutritionalStatus/thiamine/status"/>
+                                                       (<xsl:value-of select="format-number(/ds/assessment/nutritionalStatus/thiamine/percentage, '##0.##')"/>%)</td>
+                                       </tr>
+                                       <tr>
+                                               <td>Riboflavin</td>
+                                               <td><xsl:value-of select="format-number(/ds/assessment/requirement/total/riboflavin, '##0.##')"/> mg</td>
+                                               <td><xsl:value-of select="format-number(/ds/assessment/consumption/total/riboflavin, '##0.##')"/> mg</td>
+                                               <td><xsl:value-of select="format-number(/ds/assessment/nutritionalStatus/riboflavin/amount, '##0.##')"/> mg 
+                                                       <xsl:value-of select="/ds/assessment/nutritionalStatus/riboflavin/status"/>
+                                                       (<xsl:value-of select="format-number(/ds/assessment/nutritionalStatus/riboflavin/percentage, '##0.##')"/>%)</td>
+                                       </tr>
+                                       <tr>
+                                               <td>Vitamin C</td>
+                                               <td><xsl:value-of select="format-number(/ds/assessment/requirement/total/vitC, '##0.##')"/> mg</td>
+                                               <td><xsl:value-of select="format-number(/ds/assessment/consumption/total/vitC, '##0.##')"/> mg</td>
+                                               <td><xsl:value-of select="format-number(/ds/assessment/nutritionalStatus/vitC/amount, '##0.##')"/> mg 
+                                                       <xsl:value-of select="/ds/assessment/nutritionalStatus/vitC/status"/>
+                                                       (<xsl:value-of select="format-number(/ds/assessment/nutritionalStatus/vitC/percentage, '##0.##')"/>%)</td>
+                                       </tr>
+                               </table>
+                               <h3>Assesment of dietary nutrients</h3>
+                               <table class="sum">
+                                       <caption class="sum">Summary</caption>
+                                       <xsl:if test="/ds/assessment/nutritionalStatus/energy/status='excess'">
+                                               <tr><td class="excess">Energy consumption is excess by <xsl:value-of select="format-number(/ds/assessment/nutritionalStatus/energy/percentage, '##0.##')"/> %.</td></tr>
+                                       </xsl:if>
+                                       <xsl:if test="/ds/assessment/nutritionalStatus/energy/status='deficient'">
+                                               <tr><td class="deficient">Energy consumption is deficient by <xsl:value-of select="format-number(/ds/assessment/nutritionalStatus/energy/percentage, '##0.##')"/> %.</td></tr>
+                                       </xsl:if>
+                                       <xsl:if test="/ds/assessment/nutritionalStatus/protein/status='excess'">
+                                               <tr><td class="excess">Protein consumption is excess by <xsl:value-of select="format-number(/ds/assessment/nutritionalStatus/protein/percentage, '##0.##')"/> %.</td></tr>
+                                       </xsl:if>
+                                       <xsl:if test="/ds/assessment/nutritionalStatus/protein/status='deficient'">
+                                               <tr><td class="deficient">Protein consumption is deficient by <xsl:value-of select="format-number(/ds/assessment/nutritionalStatus/protein/percentage, '##0.##')"/> %.</td></tr>
+                                       </xsl:if>
+                                       <xsl:if test="/ds/assessment/nutritionalStatus/iron/status='excess'">
+                                               <tr><td class="excess">Iron consumption is excess by <xsl:value-of select="format-number(/ds/assessment/nutritionalStatus/iron/percentage, '##0.##')"/> %.</td></tr>
+                                       </xsl:if>
+                                       <xsl:if test="/ds/assessment/nutritionalStatus/iron/status='deficient'">
+                                               <tr><td class="deficient">Iron consumption is deficient by <xsl:value-of select="format-number(/ds/assessment/nutritionalStatus/iron/percentage, '##0.##')"/> %.</td></tr>
+                                       </xsl:if>
+                                       <xsl:if test="/ds/assessment/nutritionalStatus/vitA/status='excess'">
+                                               <tr><td class="excess">Vitamin A consumption is excess by <xsl:value-of select="format-number(/ds/assessment/nutritionalStatus/vitA/percentage, '##0.##')"/> %.</td></tr>
+                                       </xsl:if>
+                                       <xsl:if test="/ds/assessment/nutritionalStatus/vitA/status='deficient'">
+                                               <tr><td class="deficient">Viamin A consumption is deficient by <xsl:value-of select="format-number(/ds/assessment/nutritionalStatus/vitA/percentage, '##0.##')"/> %.</td></tr>
+                                       </xsl:if>
+                                       <xsl:if test="/ds/assessment/nutritionalStatus/thiamine/status='excess'">
+                                               <tr><td class="excess">Thiamine consumption is excess by <xsl:value-of select="format-number(/ds/assessment/nutritionalStatus/thiamine/percentage, '##0.##')"/> %.</td></tr>
+                                       </xsl:if>
+                                       <xsl:if test="/ds/assessment/nutritionalStatus/thiamine/status='deficient'">
+                                               <tr><td class="deficient">Thiamine consumption is deficient by <xsl:value-of select="format-number(/ds/assessment/nutritionalStatus/thiamine/percentage, '##0.##')"/> %.</td></tr>
+                                       </xsl:if>
+                                       <xsl:if test="/ds/assessment/nutritionalStatus/riboflavin/status='excess'">
+                                               <tr><td class="excess">Riboflavin consumption is excess by <xsl:value-of select="format-number(/ds/assessment/nutritionalStatus/riboflavin/percentage, '##0.##')"/> %.</td></tr>
+                                       </xsl:if>
+                                       <xsl:if test="/ds/assessment/nutritionalStatus/riboflavin/status='deficient'">
+                                               <tr><td class="deficient">Riboflavin consumption is deficient by <xsl:value-of select="format-number(/ds/assessment/nutritionalStatus/riboflavin/percentage, '##0.##')"/> %.</td></tr>
+                                       </xsl:if>
+                                       <xsl:if test="/ds/assessment/nutritionalStatus/vitC/status='excess'">
+                                               <tr><td class="excess">Vitamin C consumption is excess by <xsl:value-of select="format-number(/ds/assessment/nutritionalStatus/vitC/percentage, '##0.##')"/> %.</td></tr>
+                                       </xsl:if>
+                                       <xsl:if test="/ds/assessment/nutritionalStatus/vitC/status='deficient'">
+                                               <tr><td class="deficient">Viamin C consumption is deficient by <xsl:value-of select="format-number(/ds/assessment/nutritionalStatus/vitC/percentage, '##0.##')"/> %.</td></tr>
+                                       </xsl:if>
+                               </table>
+                               <img src="bar_diagram.png"/>
+                               <h3>Reference</h3>
+                               <ol>
+                                       <li>NUTRIENT REQUIREMENTS AND RECOMMENDED DIETARY ALLOWANCES FOR INDIANS- A Report of the Expert Group of the Indian Council of Medical Research 2009, NATIONAL INSTITUTE OF NUTRITION, Indian Council of Medical Research</li>
+                                       <li>Nutritive Value of Indian Foods, ICMR, 1989</li>
+                               </ol>
+                       </body>
+               </html>
+       </xsl:template>
+</xsl:stylesheet>
\ No newline at end of file
diff --git a/com/agnibho/code/resources/summary.xsl b/com/agnibho/code/resources/summary.xsl
new file mode 100644 (file)
index 0000000..72ca26c
--- /dev/null
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<xsl:stylesheet version="1.0"
+xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+       <xsl:output method="html" indent="yes" version="5.0"/>
+       <xsl:template match="/">
+               <html>
+                       <body>
+                               <h1 style="background:green; color:white; text-align:center; text-shadow:2px 2px grey; font-size:28px; border:5px ridge red;">Diet Survey</h1>
+                               <h2 style="color:green; text-align:center; text-shadow:1px 1px grey; font-size:24px; border:2px ridge red;">Assesment of dietary nutrients in last 24 hours</h2>
+                               <table style="border-collapse:collapse; border:2px ridge yellow; width:600px; margin-left:auto; margin-right:auto" align="center">
+                                       <caption style="font-size:20px; color:blue; background:yellow; border:2px ridge yellow;">Summary</caption>
+                                       <xsl:if test="/assessment/nutritionalStatus/energy/status='excess'">
+                                               <tr><td style="background:Green; height: 40px; padding-left:20px; border:none; text-align:left; color:white; font-size:16px;">Energy consumption is excess by <xsl:value-of select="format-number(/assessment/nutritionalStatus/energy/percentage, '##0.##')"/> %.</td></tr>
+                                       </xsl:if>
+                                       <xsl:if test="/assessment/nutritionalStatus/energy/status='deficient'">
+                                               <tr><td style="background:red; height: 40px; padding-left:20px; border:none; text-align:left; color:white; font-size:16px;">Energy consumption is deficient by <xsl:value-of select="format-number(/assessment/nutritionalStatus/energy/percentage, '##0.##')"/> %.</td></tr>
+                                       </xsl:if>
+                                       <xsl:if test="/assessment/nutritionalStatus/protein/status='excess'">
+                                               <tr><td  style="background:Green; height: 40px; padding-left:20px; border:none; text-align:left; color:white; font-size:16px;">Protein consumption is excess by <xsl:value-of select="format-number(/assessment/nutritionalStatus/protein/percentage, '##0.##')"/> %.</td></tr>
+                                       </xsl:if>
+                                       <xsl:if test="/assessment/nutritionalStatus/protein/status='deficient'">
+                                               <tr><td style="background:red; height: 40px; padding-left:20px; border:none; text-align:left; color:white; font-size:16px;">Protein consumption is deficient by <xsl:value-of select="format-number(/assessment/nutritionalStatus/protein/percentage, '##0.##')"/> %.</td></tr>
+                                       </xsl:if>
+                                       <xsl:if test="/assessment/nutritionalStatus/iron/status='excess'">
+                                               <tr><td  style="background:Green; height: 40px; padding-left:20px; border:none; text-align:left; color:white; font-size:16px;">Iron consumption is excess by <xsl:value-of select="format-number(/assessment/nutritionalStatus/iron/percentage, '##0.##')"/> %.</td></tr>
+                                       </xsl:if>
+                                       <xsl:if test="/assessment/nutritionalStatus/iron/status='deficient'">
+                                               <tr><td style="background:red; height: 40px; padding-left:20px; border:none; text-align:left; color:white; font-size:16px;">Iron consumption is deficient by <xsl:value-of select="format-number(/assessment/nutritionalStatus/iron/percentage, '##0.##')"/> %.</td></tr>
+                                       </xsl:if>
+                                       <xsl:if test="/assessment/nutritionalStatus/vitA/status='excess'">
+                                               <tr><td  style="background:Green; height: 40px; padding-left:20px; border:none; text-align:left; color:white; font-size:16px;">Vitamin A consumption is excess by <xsl:value-of select="format-number(/assessment/nutritionalStatus/vitA/percentage, '##0.##')"/> %.</td></tr>
+                                       </xsl:if>
+                                       <xsl:if test="/assessment/nutritionalStatus/vitA/status='deficient'">
+                                               <tr><td style="background:red; height: 40px; padding-left:20px; border:none; text-align:left; color:white; font-size:16px;">Viamin A consumption is deficient by <xsl:value-of select="format-number(/assessment/nutritionalStatus/vitA/percentage, '##0.##')"/> %.</td></tr>
+                                       </xsl:if>
+                                       <xsl:if test="/assessment/nutritionalStatus/thiamine/status='excess'">
+                                               <tr><td  style="background:Green; height: 40px; padding-left:20px; border:none; text-align:left; color:white; font-size:16px;">Thiamine consumption is excess by <xsl:value-of select="format-number(/assessment/nutritionalStatus/thiamine/percentage, '##0.##')"/> %.</td></tr>
+                                       </xsl:if>
+                                       <xsl:if test="/assessment/nutritionalStatus/thiamine/status='deficient'">
+                                               <tr><td style="background:red; height: 40px; padding-left:20px; border:none; text-align:left; color:white; font-size:16px;">Thiamine consumption is deficient by <xsl:value-of select="format-number(/assessment/nutritionalStatus/thiamine/percentage, '##0.##')"/> %.</td></tr>
+                                       </xsl:if>
+                                       <xsl:if test="/assessment/nutritionalStatus/riboflavin/status='excess'">
+                                               <tr><td  style="background:Green; height: 40px; padding-left:20px; border:none; text-align:left; color:white; font-size:16px;">Riboflavin consumption is excess by <xsl:value-of select="format-number(/assessment/nutritionalStatus/riboflavin/percentage, '##0.##')"/> %.</td></tr>
+                                       </xsl:if>
+                                       <xsl:if test="/assessment/nutritionalStatus/riboflavin/status='deficient'">
+                                               <tr><td style="background:red; height: 40px; padding-left:20px; border:none; text-align:left; color:white; font-size:16px;">Riboflavin consumption is deficient by <xsl:value-of select="format-number(/assessment/nutritionalStatus/riboflavin/percentage, '##0.##')"/> %.</td></tr>
+                                       </xsl:if>
+                                       <xsl:if test="/assessment/nutritionalStatus/vitC/status='excess'">
+                                               <tr><td  style="background:Green; height: 40px; padding-left:20px; border:none; text-align:left; color:white; font-size:16px;">Vitamin C consumption is excess by <xsl:value-of select="format-number(/assessment/nutritionalStatus/vitC/percentage, '##0.##')"/> %.</td></tr>
+                                       </xsl:if>
+                                       <xsl:if test="/assessment/nutritionalStatus/vitC/status='deficient'">
+                                               <tr><td style="background:red; height: 40px; padding-left:20px; border:none; text-align:left; color:white; font-size:16px;">Viamin C consumption is deficient by <xsl:value-of select="format-number(/assessment/nutritionalStatus/vitC/percentage, '##0.##')"/> %.</td></tr>
+                                       </xsl:if>
+                               </table>
+                       </body>
+               </html>
+       </xsl:template>
+</xsl:stylesheet>
\ No newline at end of file