aboutsummaryrefslogtreecommitdiffstats
path: root/netx/net/sourceforge/jnlp/security/viewer/CertificateViewer.java
Commit message (Collapse)AuthorAgeFilesLines
* All IcedTea-Web dialogues are centered to middle of active screenJiri Vanek2013-01-101-5/+2
| | | | | | Active screen in this context is the one, where the mouse is presented or default when no mouse presention detected. Patch is affecteing only IcedTea-Web custom dialogues.
* PR918: java applet windows uses a low resulution black/white iconOmair Majid2012-04-191-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 2012-04-19 Omair Majid <[email protected]> * NEWS: Update with fix. * netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java: Remove windowIcon. (initialize): Do not call loadWindowIcon. (getWindowIcon): Remove. (setWindowIcon): Remove. (loadWindowIcon): Remove. * netx/net/sourceforge/jnlp/runtime/JNLPSecurityManager.java (checkTopLevelWindow): Do not set the icon for all top level windows. Use the default java icon instead. * netx/net/sourceforge/jnlp/util/ImageResources.java: New file. Provides access to icons. * netx/net/sourceforge/jnlp/JNLPSplashScreen.java (JNLPSplashScreen), * netx/net/sourceforge/jnlp/cache/DefaultDownloadIndicator.java (getListener), * netx/net/sourceforge/jnlp/controlpanel/AdvancedProxySettingsDialog.java (AdvancedProxySettingsDialog), * netx/net/sourceforge/jnlp/controlpanel/CacheViewer.java (CacheViewer), * netx/net/sourceforge/jnlp/controlpanel/ControlPanel.java (ControlPanel), * netx/net/sourceforge/jnlp/security/SecurityDialog.java (SecurityDialog), * netx/net/sourceforge/jnlp/security/viewer/CertificateViewer.java (CertificateViewer), * netx/net/sourceforge/jnlp/util/BasicExceptionDialog.java (show), * plugin/icedteanp/java/sun/applet/JavaConsole.java (initialize): Explicitly load icons. * tests/netx/unit/net/sourceforge/jnlp/util/ImageResourcesTest.java: Test for ImageResources class.
* Fixed indentation and spacing for all .java files.Deepak Bhole2010-12-061-26/+25
| | | | | Added a new .settings directory which contains Eclipse preferences for code style.
* move a number of translatable string from code into Messages.propertiesOmair Majid2010-11-101-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 2010-11-09 Omair Majid <[email protected]> * netx/net/sourceforge/jnlp/resources/Messages.properties: Add ButAllow, ButClose, ButCopy, ButMoreInformation, ButProceed, ButRun, AlwaysAllowAction, Continue, Field, From, Name, Publisher, Value, Version, SNoAssociatedCertificate, SAlwaysTrustPublisher, SHttpsUnverified, SNotAllSignedSummary, SNotAllSignedDetail, SNotAllSignedQuestion, SCertificateDetails, SIssuer, SSerial, SMD5Fingerprint, SSHA1Fingerprint, SSignature, SSignatureAlgorithm, SSubject, SValidity, CVCertificateViewer, CVDetails, CVIssuedTo, CVExport, CVImport, CVIssuedBy, IssuedTo, CVRemove, CVRemoveConfirmMessage,CVRemoveConfirmTitle, CVUser, CVSystem, KS, KSCerts, KSJsseCerts, KSCaCerts, KSJsseCaCerts, and KSClientCerts. * netx/net/sourceforge/jnlp/security/AccessWarningPane.java (addComponents): Use localized strings. * netx/net/sourceforge/jnlp/security/CertWarningPane.java (addComponents): Likewise. * netx/net/sourceforge/jnlp/security/CertsInfoPane.java (parseCert): Likewise. (addComponents): Likewise. * netx/net/sourceforge/jnlp/security/MoreInfoPane.java (addComponents): Likewise. * netx/net/sourceforge/jnlp/security/NotAllSignedWarningPane.java (addComponents): Likewise. * netx/net/sourceforge/jnlp/security/viewer/CertificatePane.java: Likewise. (addComponents): Likewise. (CertificateType.toString): Likewise. (RemoveButtonListener.actionPerformed): Likewise.
* integrate multiple keystore support into certificate viewerOmair Majid2010-11-081-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 2010-11-04 Omair Majid <[email protected]> * netx/net/sourceforge/jnlp/runtime/DeploymentConfiguration.java: Add KEY_USER_TRUSTED_CA_CERTS, KEY_USER_TRUSTED_JSSE_CA_CERTS, KEY_USER_TRUSTED_CERTS, KEY_USER_TRUSTED_JSSE_CERTS, KEY_USER_TRUSTED_CLIENT_CERTS, KEY_SYSTEM_TRUSTED_CA_CERTS, KEY_SYSTEM_TRUSTED_JSSE_CA_CERTS, KEY_SYSTEM_TRUSTED_CERTS, KEY_SYSTEM_TRUSTED_JSSE_CERTS, KEY_SYSTEM_TRUSTED_CLIENT_CERTS (loadDefaultProperties): Use the defined constants. * netx/net/sourceforge/jnlp/security/KeyStores.java: New class. (getPassword): New method. Return the default password used for KeyStores. (getKeyStore(Level,Type)): New method. Returns the appropriate KeyStore. (getKeyStore(Level,Type,String)): Likewise. (getCertKeyStores): New method. Return all the trusted certificate KeyStores. (getCAKeyStores): New method. Return all the trusted CA certificate KeyStores. (getKeyStoreLocation): New method. Return the location of the appropriate KeyStore. (toTranslatableString): New method. Return a string that can be used to create a human-readable name for the KeyStore. (toDisplayableString): New method. Return a human-readable name for the KeyStore. (createKeyStoreFromFile): New method. Creates a new KeyStore object, initializing it from the given file if possible. * netx/net/sourceforge/jnlp/security/viewer/CertificatePane.java (CertificatePane): Create two JTables. Populate the tables when done creating the user interface. (initializeKeyStore): Use the correct keystore. (addComponents): Do not read KeyStore. Create more interface elements to show the new possible KeyStores. Mark some buttons to be disabled when needed. (repopulateTable): Renamed to... (repopulateTables): New method. Read KeyStore and use the contents to create the user and system tables. (CertificateType): New class. (CertificateTypeListener): New class. Listens to JComboBox change events. (TabChangeListener): New class. Listens to new tab selections. (ImportButtonListener): Import certificates to the appropriate KeyStore. (ExportButtonListener): Find the certificate from the right table. (RemoveButtonListener): Find the certificate from the right table and right the KeyStore. (DetailsButtonListener): Find the certificate from the right table. * netx/net/sourceforge/jnlp/security/viewer/CertificateViewer.java (showCertficaiteViewer): Initialize the JNLPRuntime so the configuration gets loaded. * netx/net/sourceforge/jnlp/tools/KeyTool.java (addToKeyStore(File,KeyStore)): New method. Adds certificate from the file to the KeyStore. (addToKeyStore(X509Certificate,KeyStore)): New method. Adds a certificate to a KeyStore.
* Initial import from IcedTea6.andrew2010-10-191-0/+120
2010-10-19 Andrew John Hughes <[email protected]> * .hgignore, * Makefile.am, * acinclude.m4, * autogen.sh, * configure.ac, * extra/net/sourceforge/jnlp/about/HTMLPanel.java, * extra/net/sourceforge/jnlp/about/Main.java, * extra/net/sourceforge/jnlp/about/resources/about.html, * extra/net/sourceforge/jnlp/about/resources/applications.html, * extra/net/sourceforge/jnlp/about/resources/notes.html, * javac.in, * javaws.desktop: Imported from IcedTea6. * launcher/java.c, * launcher/java.h, * launcher/java_md.c, * launcher/java_md.h, * launcher/jli_util.h, * launcher/jni.h, * launcher/jvm.h, * launcher/jvm_md.h, * launcher/manifest_info.h, * launcher/splashscreen.h, * launcher/splashscreen_stubs.c, * launcher/version_comp.h, * launcher/wildcard.h: Imported from OpenJDK. * netx/javaws.1, * netx/javax/jnlp/BasicService.java, * netx/javax/jnlp/ClipboardService.java, * netx/javax/jnlp/DownloadService.java, * netx/javax/jnlp/DownloadServiceListener.java, * netx/javax/jnlp/ExtendedService.java, * netx/javax/jnlp/ExtensionInstallerService.java, * netx/javax/jnlp/FileContents.java, * netx/javax/jnlp/FileOpenService.java, * netx/javax/jnlp/FileSaveService.java, * netx/javax/jnlp/JNLPRandomAccessFile.java, * netx/javax/jnlp/PersistenceService.java, * netx/javax/jnlp/PrintService.java, * netx/javax/jnlp/ServiceManager.java, * netx/javax/jnlp/ServiceManagerStub.java, * netx/javax/jnlp/SingleInstanceListener.java, * netx/javax/jnlp/SingleInstanceService.java, * netx/javax/jnlp/UnavailableServiceException.java, * netx/net/sourceforge/jnlp/AppletDesc.java, * netx/net/sourceforge/jnlp/ApplicationDesc.java, * netx/net/sourceforge/jnlp/AssociationDesc.java, * netx/net/sourceforge/jnlp/ComponentDesc.java, * netx/net/sourceforge/jnlp/DefaultLaunchHandler.java, * netx/net/sourceforge/jnlp/ExtensionDesc.java, * netx/net/sourceforge/jnlp/IconDesc.java, * netx/net/sourceforge/jnlp/InformationDesc.java, * netx/net/sourceforge/jnlp/InstallerDesc.java, * netx/net/sourceforge/jnlp/JARDesc.java, * netx/net/sourceforge/jnlp/JNLPFile.java, * netx/net/sourceforge/jnlp/JNLPSplashScreen.java, * netx/net/sourceforge/jnlp/JREDesc.java, * netx/net/sourceforge/jnlp/LaunchException.java, * netx/net/sourceforge/jnlp/LaunchHandler.java, * netx/net/sourceforge/jnlp/Launcher.java, * netx/net/sourceforge/jnlp/MenuDesc.java, * netx/net/sourceforge/jnlp/NetxPanel.java, * netx/net/sourceforge/jnlp/Node.java, * netx/net/sourceforge/jnlp/PackageDesc.java, * netx/net/sourceforge/jnlp/ParseException.java, * netx/net/sourceforge/jnlp/Parser.java, * netx/net/sourceforge/jnlp/PluginBridge.java, * netx/net/sourceforge/jnlp/PropertyDesc.java, * netx/net/sourceforge/jnlp/RelatedContentDesc.java, * netx/net/sourceforge/jnlp/ResourcesDesc.java, * netx/net/sourceforge/jnlp/SecurityDesc.java, * netx/net/sourceforge/jnlp/ShortcutDesc.java, * netx/net/sourceforge/jnlp/StreamEater.java, * netx/net/sourceforge/jnlp/UpdateDesc.java, * netx/net/sourceforge/jnlp/Version.java, * netx/net/sourceforge/jnlp/cache/CacheEntry.java, * netx/net/sourceforge/jnlp/cache/CacheUtil.java, * netx/net/sourceforge/jnlp/cache/DefaultDownloadIndicator.java, * netx/net/sourceforge/jnlp/cache/DownloadIndicator.java, * netx/net/sourceforge/jnlp/cache/Resource.java, * netx/net/sourceforge/jnlp/cache/ResourceTracker.java, * netx/net/sourceforge/jnlp/cache/UpdatePolicy.java, * netx/net/sourceforge/jnlp/cache/package.html, * netx/net/sourceforge/jnlp/event/ApplicationEvent.java, * netx/net/sourceforge/jnlp/event/ApplicationListener.java, * netx/net/sourceforge/jnlp/event/DownloadEvent.java, * netx/net/sourceforge/jnlp/event/DownloadListener.java, * netx/net/sourceforge/jnlp/event/package.html, * netx/net/sourceforge/jnlp/package.html, * netx/net/sourceforge/jnlp/resources/Manifest.mf, * netx/net/sourceforge/jnlp/resources/Messages.properties, * netx/net/sourceforge/jnlp/resources/about.jnlp, * netx/net/sourceforge/jnlp/resources/default.jnlp, * netx/net/sourceforge/jnlp/runtime/AppThreadGroup.java, * netx/net/sourceforge/jnlp/runtime/AppletAudioClip.java, * netx/net/sourceforge/jnlp/runtime/AppletEnvironment.java, * netx/net/sourceforge/jnlp/runtime/AppletInstance.java, * netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java, * netx/net/sourceforge/jnlp/runtime/Boot.java, * netx/net/sourceforge/jnlp/runtime/Boot13.java, * netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java, * netx/net/sourceforge/jnlp/runtime/JNLPPolicy.java, * netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java, * netx/net/sourceforge/jnlp/runtime/JNLPSecurityManager.java, * netx/net/sourceforge/jnlp/runtime/package.html, * netx/net/sourceforge/jnlp/security/AccessWarningPane.java, * netx/net/sourceforge/jnlp/security/AppletWarningPane.java, * netx/net/sourceforge/jnlp/security/CertVerifier.java, * netx/net/sourceforge/jnlp/security/CertWarningPane.java, * netx/net/sourceforge/jnlp/security/CertsInfoPane.java, * netx/net/sourceforge/jnlp/security/HttpsCertVerifier.java, * netx/net/sourceforge/jnlp/security/MoreInfoPane.java, * netx/net/sourceforge/jnlp/security/NotAllSignedWarningPane.java, * netx/net/sourceforge/jnlp/security/SecurityDialogPanel.java, * netx/net/sourceforge/jnlp/security/SecurityUtil.java, * netx/net/sourceforge/jnlp/security/SecurityWarningDialog.java, * netx/net/sourceforge/jnlp/security/SingleCertInfoPane.java, * netx/net/sourceforge/jnlp/security/VariableX509TrustManager.java, * netx/net/sourceforge/jnlp/security/viewer/CertificatePane.java, * netx/net/sourceforge/jnlp/security/viewer/CertificateViewer.java, * netx/net/sourceforge/jnlp/services/ExtendedSingleInstanceService.java, * netx/net/sourceforge/jnlp/services/InstanceExistsException.java, * netx/net/sourceforge/jnlp/services/ServiceUtil.java, * netx/net/sourceforge/jnlp/services/SingleInstanceLock.java, * netx/net/sourceforge/jnlp/services/XBasicService.java, * netx/net/sourceforge/jnlp/services/XClipboardService.java, * netx/net/sourceforge/jnlp/services/XDownloadService.java, * netx/net/sourceforge/jnlp/services/XExtendedService.java, * netx/net/sourceforge/jnlp/services/XExtensionInstallerService.java, * netx/net/sourceforge/jnlp/services/XFileContents.java, * netx/net/sourceforge/jnlp/services/XFileOpenService.java, * netx/net/sourceforge/jnlp/services/XFileSaveService.java, * netx/net/sourceforge/jnlp/services/XJNLPRandomAccessFile.java, * netx/net/sourceforge/jnlp/services/XPersistenceService.java, * netx/net/sourceforge/jnlp/services/XPrintService.java, * netx/net/sourceforge/jnlp/services/XServiceManagerStub.java, * netx/net/sourceforge/jnlp/services/XSingleInstanceService.java, * netx/net/sourceforge/jnlp/services/package.html, * netx/net/sourceforge/jnlp/tools/CharacterEncoder.java, * netx/net/sourceforge/jnlp/tools/HexDumpEncoder.java, * netx/net/sourceforge/jnlp/tools/JarRunner.java, * netx/net/sourceforge/jnlp/tools/JarSigner.java, * netx/net/sourceforge/jnlp/tools/JarSignerResources.java, * netx/net/sourceforge/jnlp/tools/KeyStoreUtil.java, * netx/net/sourceforge/jnlp/tools/KeyTool.java, * netx/net/sourceforge/jnlp/util/FileUtils.java, * netx/net/sourceforge/jnlp/util/PropertiesFile.java, * netx/net/sourceforge/jnlp/util/Reflect.java, * netx/net/sourceforge/jnlp/util/WeakList.java, * netx/net/sourceforge/jnlp/util/XDesktopEntry.java, * netx/net/sourceforge/nanoxml/XMLElement.java, * netx/net/sourceforge/nanoxml/XMLParseException.java, * plugin/icedteanp/IcedTeaJavaRequestProcessor.cc, * plugin/icedteanp/IcedTeaJavaRequestProcessor.h, * plugin/icedteanp/IcedTeaNPPlugin.cc, * plugin/icedteanp/IcedTeaNPPlugin.h, * plugin/icedteanp/IcedTeaPluginRequestProcessor.cc, * plugin/icedteanp/IcedTeaPluginRequestProcessor.h, * plugin/icedteanp/IcedTeaPluginUtils.cc, * plugin/icedteanp/IcedTeaPluginUtils.h, * plugin/icedteanp/IcedTeaRunnable.cc, * plugin/icedteanp/IcedTeaRunnable.h, * plugin/icedteanp/IcedTeaScriptablePluginObject.cc, * plugin/icedteanp/IcedTeaScriptablePluginObject.h, * plugin/icedteanp/java/netscape/javascript/JSException.java, * plugin/icedteanp/java/netscape/javascript/JSObject.java, * plugin/icedteanp/java/netscape/javascript/JSObjectCreatePermission.java, * plugin/icedteanp/java/netscape/javascript/JSProxy.java, * plugin/icedteanp/java/netscape/javascript/JSRunnable.java, * plugin/icedteanp/java/netscape/javascript/JSUtil.java, * plugin/icedteanp/java/netscape/security/ForbiddenTargetException.java, * plugin/icedteanp/java/sun/applet/AppletSecurityContextManager.java, * plugin/icedteanp/java/sun/applet/GetMemberPluginCallRequest.java, * plugin/icedteanp/java/sun/applet/GetWindowPluginCallRequest.java, * plugin/icedteanp/java/sun/applet/JavaConsole.java, * plugin/icedteanp/java/sun/applet/MethodOverloadResolver.java, * plugin/icedteanp/java/sun/applet/PasswordAuthenticationDialog.java, * plugin/icedteanp/java/sun/applet/PluginAppletSecurityContext.java, * plugin/icedteanp/java/sun/applet/PluginAppletViewer.java, * plugin/icedteanp/java/sun/applet/PluginCallRequest.java, * plugin/icedteanp/java/sun/applet/PluginCallRequestFactory.java, * plugin/icedteanp/java/sun/applet/PluginClassLoader.java, * plugin/icedteanp/java/sun/applet/PluginCookieInfoRequest.java, * plugin/icedteanp/java/sun/applet/PluginCookieManager.java, * plugin/icedteanp/java/sun/applet/PluginDebug.java, * plugin/icedteanp/java/sun/applet/PluginException.java, * plugin/icedteanp/java/sun/applet/PluginMain.java, * plugin/icedteanp/java/sun/applet/PluginMessageConsumer.java, * plugin/icedteanp/java/sun/applet/PluginMessageHandlerWorker.java, * plugin/icedteanp/java/sun/applet/PluginObjectStore.java, * plugin/icedteanp/java/sun/applet/PluginProxyInfoRequest.java, * plugin/icedteanp/java/sun/applet/PluginProxySelector.java, * plugin/icedteanp/java/sun/applet/PluginStreamHandler.java, * plugin/icedteanp/java/sun/applet/RequestQueue.java, * plugin/icedteanp/java/sun/applet/TestEnv.java, * plugin/icedteanp/java/sun/applet/VoidPluginCallRequest.java, * plugin/tests/LiveConnect/DummyObject.java, * plugin/tests/LiveConnect/OverloadTestHelper1.java, * plugin/tests/LiveConnect/OverloadTestHelper2.java, * plugin/tests/LiveConnect/OverloadTestHelper3.java, * plugin/tests/LiveConnect/PluginTest.java, * plugin/tests/LiveConnect/build, * plugin/tests/LiveConnect/common.js, * plugin/tests/LiveConnect/index.html, * plugin/tests/LiveConnect/jjs_eval_test.js, * plugin/tests/LiveConnect/jjs_func_parameters_tests.js, * plugin/tests/LiveConnect/jjs_func_rettype_tests.js, * plugin/tests/LiveConnect/jjs_get_tests.js, * plugin/tests/LiveConnect/jjs_set_tests.js, * plugin/tests/LiveConnect/jsj_func_overload_tests.js, * plugin/tests/LiveConnect/jsj_func_parameters_tests.js, * plugin/tests/LiveConnect/jsj_func_rettype_tests.js, * plugin/tests/LiveConnect/jsj_get_tests.js, * plugin/tests/LiveConnect/jsj_set_tests.js, * plugin/tests/LiveConnect/jsj_type_casting_tests.js, * plugin/tests/LiveConnect/jsj_type_conversion_tests.js: Initial import from IcedTea6. * AUTHORS, * COPYING * INSTALL, * NEWS, * README: New documentation.
id='n722' href='#n722'>722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
** 
** http://oss.sgi.com/projects/FreeB
** 
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
** 
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
** 
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
**
** $Date$ $Revision$
** $Header$
*/

/* 
 * Copyright (c) 2002-2004 LWJGL Project
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are 
 * met:
 * 
 * * Redistributions of source code must retain the above copyright 
 *   notice, this list of conditions and the following disclaimer.
 *
 * * Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the distribution.
 *
 * * Neither the name of 'LWJGL' nor the names of 
 *   its contributors may be used to endorse or promote products derived 
 *   from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * 
 * - Redistribution of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 * 
 * - Redistribution in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the distribution.
 * 
 * Neither the name of Sun Microsystems, Inc. or the names of
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * 
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
 * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
 * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
 * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
 * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
 * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
 * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 * 
 * You acknowledge that this software is not designed or intended for use
 * in the design, construction, operation or maintenance of any nuclear
 * facility.
 */

package com.sun.opengl.impl;

import javax.media.opengl.*;
import javax.media.opengl.glu.*;

/**
 * GLUquadricImpl.java
 * 
 * 
 * Created 22-dec-2003 (originally Quadric.java)
 * @author Erik Duijs
 * @author Kenneth Russell
 */

public class GLUquadricImpl implements GLUquadric {
  private int drawStyle;
  private int orientation;
  private boolean textureFlag;
  private int normals;

  public GLUquadricImpl() {
    drawStyle = GLU.GLU_FILL;
    orientation = GLU.GLU_OUTSIDE;
    textureFlag = false;
    normals = GLU.GLU_SMOOTH;
  }

  /**
   * specifies the draw style for quadrics.  
   *
   * The legal values are as follows:
   *
   * GLU.FILL:       Quadrics are rendered with polygon primitives. The polygons
   *                 are drawn in a counterclockwise fashion with respect to
   *                 their normals (as defined with glu.quadricOrientation).
   *
   * GLU.LINE:       Quadrics are rendered as a set of lines.
   *
   * GLU.SILHOUETTE: Quadrics are rendered as a set of lines, except that edges
   * 		   separating coplanar faces will not be drawn.
   *
   * GLU.POINT:       Quadrics are rendered as a set of points.
   * 
   * @param drawStyle The drawStyle to set
   */
  public void setDrawStyle(int drawStyle) {
    this.drawStyle = drawStyle;
  }

  /**
   * specifies what kind	of normals are desired for quadrics.
   * The legal values	are as follows:
   *
   * GLU.NONE:     No normals are generated.
   *
   * GLU.FLAT:     One normal is generated for every facet of a quadric.
   *
   * GLU.SMOOTH:   One normal is generated for every vertex of a quadric.  This
   *               is the default.
   * 
   * @param normals The normals to set
   */
  public void setNormals(int normals) {
    this.normals = normals;
  }

  /**
   * specifies what kind of orientation is desired for.
   * The orientation	values are as follows:
   *
   * GLU.OUTSIDE:  Quadrics are drawn with normals pointing outward.
   *
   * GLU.INSIDE:   Normals point inward. The default is GLU.OUTSIDE.
   *
   * Note that the interpretation of outward and inward depends on the quadric
   * being drawn.
   * 
   * @param orientation The orientation to set
   */
  public void setOrientation(int orientation) {
    this.orientation = orientation;
  }

  /**
   * specifies if texture coordinates should be generated for
   * quadrics rendered with qobj. If the value of textureCoords is true,
   * then texture coordinates are generated, and if textureCoords is false,
   * they are not.. The default is false.
   *
   * The manner in which texture coordinates are generated depends upon the
   * specific quadric rendered.
   * 
   * @param textureFlag The textureFlag to set
   */
  public void setTextureFlag(boolean textureFlag) {
    this.textureFlag = textureFlag;
  }

  /**
   * Returns the drawStyle.
   * @return int
   */
  public int getDrawStyle() {
    return drawStyle;
  }

  /**
   * Returns the normals.
   * @return int
   */
  public int getNormals() {
    return normals;
  }

  /**
   * Returns the orientation.
   * @return int
   */
  public int getOrientation() {
    return orientation;
  }

  /**
   * Returns the textureFlag.
   * @return boolean
   */
  public boolean getTextureFlag() {
    return textureFlag;
  }

  /**
   * draws a cylinder oriented along the z axis. The base of the
   * cylinder is placed at z = 0, and the top at z=height. Like a sphere, a
   * cylinder is subdivided around the z axis into slices, and along the z axis
   * into stacks.
   *
   * Note that if topRadius is set to zero, then this routine will generate a
   * cone.
   *
   * If the orientation is set to GLU.OUTSIDE (with glu.quadricOrientation), then
   * any generated normals point away from the z axis. Otherwise, they point
   * toward the z axis.
   *
   * If texturing is turned on (with glu.quadricTexture), then texture
   * coordinates are generated so that t ranges linearly from 0.0 at z = 0 to
   * 1.0 at z = height, and s ranges from 0.0 at the +y axis, to 0.25 at the +x
   * axis, to 0.5 at the -y axis, to 0.75 at the -x axis, and back to 1.0 at the
   * +y axis.
   *
   * @param baseRadius  Specifies the radius of the cylinder at z = 0.
   * @param topRadius   Specifies the radius of the cylinder at z = height.
   * @param height      Specifies the height of the cylinder.
   * @param slices      Specifies the number of subdivisions around the z axis.
   * @param stacks      Specifies the number of subdivisions along the z axis.
   */
  public void drawCylinder(GL gl, float baseRadius, float topRadius, float height, int slices, int stacks) {

    float da, r, dr, dz;
    float x, y, z, nz, nsign;
    int i, j;

    if (orientation == GLU.GLU_INSIDE) {
      nsign = -1.0f;
    } else {
      nsign = 1.0f;
    }

    da = 2.0f * PI / slices;
    dr = (topRadius - baseRadius) / stacks;
    dz = height / stacks;
    nz = (baseRadius - topRadius) / height;
    // Z component of normal vectors

    if (drawStyle == GLU.GLU_POINT) {
      gl.glBegin(GL.GL_POINTS);
      for (i = 0; i < slices; i++) {
        x = cos((i * da));
        y = sin((i * da));
        normal3f(gl, x * nsign, y * nsign, nz * nsign);

        z = 0.0f;
        r = baseRadius;
        for (j = 0; j <= stacks; j++) {
          gl.glVertex3f((x * r), (y * r), z);
          z += dz;
          r += dr;
        }
      }
      gl.glEnd();
    } else if (drawStyle == GLU.GLU_LINE || drawStyle == GLU.GLU_SILHOUETTE) {
      // Draw rings
      if (drawStyle == GLU.GLU_LINE) {
        z = 0.0f;
        r = baseRadius;
        for (j = 0; j <= stacks; j++) {
          gl.glBegin(GL.GL_LINE_LOOP);
          for (i = 0; i < slices; i++) {
            x = cos((i * da));
            y = sin((i * da));
            normal3f(gl, x * nsign, y * nsign, nz * nsign);
            gl.glVertex3f((x * r), (y * r), z);
          }
          gl.glEnd();
          z += dz;
          r += dr;
        }
      } else {
        // draw one ring at each end
        if (baseRadius != 0.0) {
          gl.glBegin(GL.GL_LINE_LOOP);
          for (i = 0; i < slices; i++) {
            x = cos((i * da));
            y = sin((i * da));
            normal3f(gl, x * nsign, y * nsign, nz * nsign);
            gl.glVertex3f((x * baseRadius), (y * baseRadius), 0.0f);
          }
          gl.glEnd();
          gl.glBegin(GL.GL_LINE_LOOP);
          for (i = 0; i < slices; i++) {
            x = cos((i * da));
            y = sin((i * da));
            normal3f(gl, x * nsign, y * nsign, nz * nsign);
            gl.glVertex3f((x * topRadius), (y * topRadius), height);
          }
          gl.glEnd();
        }
      }
      // draw length lines
      gl.glBegin(GL.GL_LINES);
      for (i = 0; i < slices; i++) {
        x = cos((i * da));
        y = sin((i * da));
        normal3f(gl, x * nsign, y * nsign, nz * nsign);
        gl.glVertex3f((x * baseRadius), (y * baseRadius), 0.0f);
        gl.glVertex3f((x * topRadius), (y * topRadius), (height));
      }
      gl.glEnd();
    } else if (drawStyle == GLU.GLU_FILL) {
      float ds = 1.0f / slices;
      float dt = 1.0f / stacks;
      float t = 0.0f;
      z = 0.0f;
      r = baseRadius;
      for (j = 0; j < stacks; j++) {
        float s = 0.0f;
        gl.glBegin(GL.GL_QUAD_STRIP);
        for (i = 0; i <= slices; i++) {
          if (i == slices) {
            x = sin(0.0f);
            y = cos(0.0f);
          } else {
            x = sin((i * da));
            y = cos((i * da));
          }
          if (nsign == 1.0f) {
            normal3f(gl, (x * nsign), (y * nsign), (nz * nsign));
            TXTR_COORD(gl, s, t);
            gl.glVertex3f((x * r), (y * r), z);
            normal3f(gl, (x * nsign), (y * nsign), (nz * nsign));
            TXTR_COORD(gl, s, t + dt);
            gl.glVertex3f((x * (r + dr)), (y * (r + dr)), (z + dz));
          } else {
            normal3f(gl, x * nsign, y * nsign, nz * nsign);
            TXTR_COORD(gl, s, t);
            gl.glVertex3f((x * r), (y * r), z);
            normal3f(gl, x * nsign, y * nsign, nz * nsign);
            TXTR_COORD(gl, s, t + dt);
            gl.glVertex3f((x * (r + dr)), (y * (r + dr)), (z + dz));
          }
          s += ds;
        } // for slices
        gl.glEnd();
        r += dr;
        t += dt;
        z += dz;
      } // for stacks
    }
  }

  /**
   * renders a disk on the z = 0  plane.  The disk has a radius of
   * outerRadius, and contains a concentric circular hole with a radius of
   * innerRadius. If innerRadius is 0, then no hole is generated. The disk is
   * subdivided around the z axis into slices (like pizza slices), and also
   * about the z axis into rings (as specified by slices and loops,
   * respectively).
   *
   * With respect to orientation, the +z side of the disk is considered to be
   * "outside" (see glu.quadricOrientation).  This means that if the orientation
   * is set to GLU.OUTSIDE, then any normals generated point along the +z axis.
   * Otherwise, they point along the -z axis.
   *
   * If texturing is turned on (with glu.quadricTexture), texture coordinates are
   * generated linearly such that where r=outerRadius, the value at (r, 0, 0) is
   * (1, 0.5), at (0, r, 0) it is (0.5, 1), at (-r, 0, 0) it is (0, 0.5), and at
   * (0, -r, 0) it is (0.5, 0).
   */
  public void drawDisk(GL gl, float innerRadius, float outerRadius, int slices, int loops)
  {
    float da, dr;

    /* Normal vectors */
    if (normals != GLU.GLU_NONE) {
      if (orientation == GLU.GLU_OUTSIDE) {
        gl.glNormal3f(0.0f, 0.0f, +1.0f);
      }
      else {
        gl.glNormal3f(0.0f, 0.0f, -1.0f);
      }
    }
	
    da = 2.0f * PI / slices;
    dr = (outerRadius - innerRadius) /  loops;
	
    switch (drawStyle) {
    case GLU.GLU_FILL:
      {
        /* texture of a gluDisk is a cut out of the texture unit square
         * x, y in [-outerRadius, +outerRadius]; s, t in [0, 1]
         * (linear mapping)
         */
        float dtc = 2.0f * outerRadius;
        float sa, ca;
        float r1 = innerRadius;
        int l;
        for (l = 0; l < loops; l++) {
          float r2 = r1 + dr;
          if (orientation == GLU.GLU_OUTSIDE) {
            int s;
            gl.glBegin(gl.GL_QUAD_STRIP);
            for (s = 0; s <= slices; s++) {
              float a;
              if (s == slices)
                a = 0.0f;
              else
                a = s * da;
              sa = sin(a);
              ca = cos(a);
              TXTR_COORD(gl, 0.5f + sa * r2 / dtc, 0.5f + ca * r2 / dtc);
              gl.glVertex2f(r2 * sa, r2 * ca);
              TXTR_COORD(gl, 0.5f + sa * r1 / dtc, 0.5f + ca * r1 / dtc);
              gl.glVertex2f(r1 * sa, r1 * ca);
            }
            gl.glEnd();
          }
          else {
            int s;
            gl.glBegin(GL.GL_QUAD_STRIP);
            for (s = slices; s >= 0; s--) {
              float a;
              if (s == slices)
                a = 0.0f;
              else
                a = s * da;
              sa = sin(a);
              ca = cos(a);
              TXTR_COORD(gl, 0.5f - sa * r2 / dtc, 0.5f + ca * r2 / dtc);
              gl.glVertex2f(r2 * sa, r2 * ca);
              TXTR_COORD(gl, 0.5f - sa * r1 / dtc, 0.5f + ca * r1 / dtc);
              gl.glVertex2f(r1 * sa, r1 * ca);
            }
            gl.glEnd();
          }
          r1 = r2;
        }
        break;
      }
    case GLU.GLU_LINE:
      {
        int l, s;
        /* draw loops */
        for (l = 0; l <= loops; l++) {
          float r = innerRadius + l * dr;
          gl.glBegin(GL.GL_LINE_LOOP);
          for (s = 0; s < slices; s++) {
            float a = s * da;
            gl.glVertex2f(r * sin(a), r * cos(a));
          }
          gl.glEnd();
        }
        /* draw spokes */
        for (s = 0; s < slices; s++) {
          float a = s * da;
          float x = sin(a);
          float y = cos(a);
          gl.glBegin(GL.GL_LINE_STRIP);
          for (l = 0; l <= loops; l++) {
            float r = innerRadius + l * dr;
            gl.glVertex2f(r * x, r * y);
          }
          gl.glEnd();
        }
        break;
      }
    case GLU.GLU_POINT:
      {
        int s;
        gl.glBegin(GL.GL_POINTS);
        for (s = 0; s < slices; s++) {
          float a = s * da;
          float x = sin(a);
          float y = cos(a);
          int l;
          for (l = 0; l <= loops; l++) {
            float r = innerRadius * l * dr;
            gl.glVertex2f(r * x, r * y);
          }
        }
        gl.glEnd();
        break;
      }
    case GLU.GLU_SILHOUETTE:
      {
        if (innerRadius != 0.0) {
          float a;
          gl.glBegin(GL.GL_LINE_LOOP);
          for (a = 0.0f; a < 2.0 * PI; a += da) {
            float x = innerRadius * sin(a);
            float y = innerRadius * cos(a);
            gl.glVertex2f(x, y);
          }
          gl.glEnd();
        }
        {
          float a;
          gl.glBegin(GL.GL_LINE_LOOP);
          for (a = 0; a < 2.0f * PI; a += da) {
            float x = outerRadius * sin(a);
            float y = outerRadius * cos(a);
            gl.glVertex2f(x, y);
          }
          gl.glEnd();
        }
        break;
      }
    default:
      return;
    }
  }

  /**
   * renders a partial disk on the z=0 plane. A partial disk is similar to a
   * full disk, except that only the subset of the disk from startAngle
   * through startAngle + sweepAngle is included (where 0 degrees is along
   * the +y axis, 90 degrees along the +x axis, 180 along the -y axis, and
   * 270 along the -x axis).
   * 
   * The partial disk has a radius of outerRadius, and contains a concentric
   * circular hole with a radius of innerRadius. If innerRadius is zero, then
   * no hole is generated. The partial disk is subdivided around the z axis
   * into slices (like pizza slices), and also about the z axis into rings
   * (as specified by slices and loops, respectively).
   * 
   * With respect to orientation, the +z side of the partial disk is
   * considered to be outside (see gluQuadricOrientation). This means that if
   * the orientation is set to GLU.GLU_OUTSIDE, then any normals generated point
   * along the +z axis. Otherwise, they point along the -z axis.
   * 
   * If texturing is turned on (with gluQuadricTexture), texture coordinates
   * are generated linearly such that where r=outerRadius, the value at (r, 0, 0)
   * is (1, 0.5), at (0, r, 0) it is (0.5, 1), at (-r, 0, 0) it is (0, 0.5),
   * and at (0, -r, 0) it is (0.5, 0).
   */
  public void drawPartialDisk(GL gl,
                              float innerRadius,
                              float outerRadius,
                              int slices,
                              int loops,
                              float startAngle,
                              float sweepAngle) {
    int i, j, max;
    float[] sinCache = new float[CACHE_SIZE];
    float[] cosCache = new float[CACHE_SIZE];
    float angle;
    float x, y;
    float sintemp, costemp;
    float deltaRadius;
    float radiusLow, radiusHigh;
    float texLow = 0, texHigh = 0;
    float angleOffset;
    int slices2;
    int finish;

    if (slices >= CACHE_SIZE)
      slices = CACHE_SIZE - 1;
    if (slices < 2
        || loops < 1
        || outerRadius <= 0.0f
        || innerRadius < 0.0f
        || innerRadius > outerRadius) {
      //gluQuadricError(qobj, GLU.GLU_INVALID_VALUE);
      System.err.println("PartialDisk: GLU_INVALID_VALUE");
      return;
    }

    if (sweepAngle < -360.0f)
      sweepAngle = 360.0f;
    if (sweepAngle > 360.0f)
      sweepAngle = 360.0f;
    if (sweepAngle < 0) {
      startAngle += sweepAngle;
      sweepAngle = -sweepAngle;
    }

    if (sweepAngle == 360.0f) {
      slices2 = slices;
    } else {
      slices2 = slices + 1;
    }

    /* Compute length (needed for normal calculations) */
    deltaRadius = outerRadius - innerRadius;

    /* Cache is the vertex locations cache */

    angleOffset = startAngle / 180.0f * PI;
    for (i = 0; i <= slices; i++) {
      angle = angleOffset + ((PI * sweepAngle) / 180.0f) * i / slices;
      sinCache[i] = sin(angle);
      cosCache[i] = cos(angle);
    }

    if (sweepAngle == 360.0f) {
      sinCache[slices] = sinCache[0];
      cosCache[slices] = cosCache[0];
    }

    switch (normals) {
    case GLU.GLU_FLAT :
    case GLU.GLU_SMOOTH :
      if (orientation == GLU.GLU_OUTSIDE) {
        gl.glNormal3f(0.0f, 0.0f, 1.0f);
      } else {
        gl.glNormal3f(0.0f, 0.0f, -1.0f);
      }
      break;
    default :
    case GLU.GLU_NONE :
      break;
    }

    switch (drawStyle) {
    case GLU.GLU_FILL :
      if (innerRadius == .0f) {
        finish = loops - 1;
        /* Triangle strip for inner polygons */
        gl.glBegin(GL.GL_TRIANGLE_FAN);
        if (textureFlag) {
          gl.glTexCoord2f(0.5f, 0.5f);
        }
        gl.glVertex3f(0.0f, 0.0f, 0.0f);
        radiusLow = outerRadius - deltaRadius * ((float) (loops - 1) / loops);
        if (textureFlag) {
          texLow = radiusLow / outerRadius / 2;
        }

        if (orientation == GLU.GLU_OUTSIDE) {
          for (i = slices; i >= 0; i--) {
            if (textureFlag) {
              gl.glTexCoord2f(texLow * sinCache[i] + 0.5f,
                              texLow * cosCache[i] + 0.5f);
            }
            gl.glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f);
          }
        } else {
          for (i = 0; i <= slices; i++) {
            if (textureFlag) {
              gl.glTexCoord2f(texLow * sinCache[i] + 0.5f,
                              texLow * cosCache[i] + 0.5f);
            }
            gl.glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f);
          }
        }
        gl.glEnd();
      } else {
        finish = loops;
      }
      for (j = 0; j < finish; j++) {
        radiusLow = outerRadius - deltaRadius * ((float) j / loops);
        radiusHigh = outerRadius - deltaRadius * ((float) (j + 1) / loops);
        if (textureFlag) {
          texLow = radiusLow / outerRadius / 2;
          texHigh = radiusHigh / outerRadius / 2;
        }

        gl.glBegin(GL.GL_QUAD_STRIP);
        for (i = 0; i <= slices; i++) {
          if (orientation == GLU.GLU_OUTSIDE) {
            if (textureFlag) {
              gl.glTexCoord2f(texLow * sinCache[i] + 0.5f,
                              texLow * cosCache[i] + 0.5f);
            }
            gl.glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f);

            if (textureFlag) {
              gl.glTexCoord2f(texHigh * sinCache[i] + 0.5f,
                              texHigh * cosCache[i] + 0.5f);
            }
            gl.glVertex3f(radiusHigh * sinCache[i],
                          radiusHigh * cosCache[i],
                          0.0f);
          } else {
            if (textureFlag) {
              gl.glTexCoord2f(texHigh * sinCache[i] + 0.5f,
                              texHigh * cosCache[i] + 0.5f);
            }
            gl.glVertex3f(radiusHigh * sinCache[i],
                          radiusHigh * cosCache[i],
                          0.0f);

            if (textureFlag) {
              gl.glTexCoord2f(texLow * sinCache[i] + 0.5f,
                              texLow * cosCache[i] + 0.5f);
            }
            gl.glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f);
          }
        }
        gl.glEnd();
      }
      break;
    case GLU.GLU_POINT :
      gl.glBegin(GL.GL_POINTS);
      for (i = 0; i < slices2; i++) {
        sintemp = sinCache[i];
        costemp = cosCache[i];
        for (j = 0; j <= loops; j++) {
          radiusLow = outerRadius - deltaRadius * ((float) j / loops);

          if (textureFlag) {
            texLow = radiusLow / outerRadius / 2;

            gl.glTexCoord2f(texLow * sinCache[i] + 0.5f,
                            texLow * cosCache[i] + 0.5f);
          }
          gl.glVertex3f(radiusLow * sintemp, radiusLow * costemp, 0.0f);
        }
      }
      gl.glEnd();
      break;
    case GLU.GLU_LINE :
      if (innerRadius == outerRadius) {
        gl.glBegin(GL.GL_LINE_STRIP);

        for (i = 0; i <= slices; i++) {
          if (textureFlag) {
            gl.glTexCoord2f(sinCache[i] / 2 + 0.5f, cosCache[i] / 2 + 0.5f);
          }
          gl.glVertex3f(innerRadius * sinCache[i], innerRadius * cosCache[i], 0.0f);
        }
        gl.glEnd();
        break;
      }
      for (j = 0; j <= loops; j++) {
        radiusLow = outerRadius - deltaRadius * ((float) j / loops);
        if (textureFlag) {
          texLow = radiusLow / outerRadius / 2;
        }

        gl.glBegin(GL.GL_LINE_STRIP);
        for (i = 0; i <= slices; i++) {
          if (textureFlag) {
            gl.glTexCoord2f(texLow * sinCache[i] + 0.5f,
                            texLow * cosCache[i] + 0.5f);
          }
          gl.glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f);
        }
        gl.glEnd();
      }
      for (i = 0; i < slices2; i++) {
        sintemp = sinCache[i];
        costemp = cosCache[i];
        gl.glBegin(GL.GL_LINE_STRIP);
        for (j = 0; j <= loops; j++) {
          radiusLow = outerRadius - deltaRadius * ((float) j / loops);
          if (textureFlag) {
            texLow = radiusLow / outerRadius / 2;
          }

          if (textureFlag) {
            gl.glTexCoord2f(texLow * sinCache[i] + 0.5f,
                            texLow * cosCache[i] + 0.5f);
          }
          gl.glVertex3f(radiusLow * sintemp, radiusLow * costemp, 0.0f);
        }
        gl.glEnd();
      }
      break;
    case GLU.GLU_SILHOUETTE :
      if (sweepAngle < 360.0f) {
        for (i = 0; i <= slices; i += slices) {
          sintemp = sinCache[i];
          costemp = cosCache[i];
          gl.glBegin(GL.GL_LINE_STRIP);
          for (j = 0; j <= loops; j++) {
            radiusLow = outerRadius - deltaRadius * ((float) j / loops);

            if (textureFlag) {
              texLow = radiusLow / outerRadius / 2;
              gl.glTexCoord2f(texLow * sinCache[i] + 0.5f,
                              texLow * cosCache[i] + 0.5f);
            }
            gl.glVertex3f(radiusLow * sintemp, radiusLow * costemp, 0.0f);
          }
          gl.glEnd();
        }
      }
      for (j = 0; j <= loops; j += loops) {
        radiusLow = outerRadius - deltaRadius * ((float) j / loops);
        if (textureFlag) {
          texLow = radiusLow / outerRadius / 2;
        }

        gl.glBegin(GL.GL_LINE_STRIP);
        for (i = 0; i <= slices; i++) {
          if (textureFlag) {
            gl.glTexCoord2f(texLow * sinCache[i] + 0.5f,
                            texLow * cosCache[i] + 0.5f);
          }
          gl.glVertex3f(radiusLow * sinCache[i], radiusLow * cosCache[i], 0.0f);
        }
        gl.glEnd();
        if (innerRadius == outerRadius)
          break;
      }
      break;
    default :
      break;
    }
  }

  /**
   * draws a sphere of the given	radius centered	around the origin.
   * The sphere is subdivided around the z axis into slices and along the z axis
   * into stacks (similar to lines of longitude and latitude).
   *
   * If the orientation is set to GLU.OUTSIDE (with glu.quadricOrientation), then
   * any normals generated point away from the center of the sphere. Otherwise,
   * they point toward the center of the sphere.

   * If texturing is turned on (with glu.quadricTexture), then texture
   * coordinates are generated so that t ranges from 0.0 at z=-radius to 1.0 at
   * z=radius (t increases linearly along longitudinal lines), and s ranges from
   * 0.0 at the +y axis, to 0.25 at the +x axis, to 0.5 at the -y axis, to 0.75
   * at the -x axis, and back to 1.0 at the +y axis.
   */
  public void drawSphere(GL gl, float radius, int slices, int stacks) {
    // TODO

    float rho, drho, theta, dtheta;
    float x, y, z;
    float s, t, ds, dt;
    int i, j, imin, imax;
    boolean normals;
    float nsign;

    normals = (this.normals != GLU.GLU_NONE);

    if (orientation == GLU.GLU_INSIDE) {
      nsign = -1.0f;
    } else {
      nsign = 1.0f;
    }

    drho = PI / stacks;
    dtheta = 2.0f * PI / slices;

    if (drawStyle == GLU.GLU_FILL) {
      if (!textureFlag) {
        // draw +Z end as a triangle fan
        gl.glBegin(GL.GL_TRIANGLE_FAN);
        gl.glNormal3f(0.0f, 0.0f, 1.0f);
        gl.glVertex3f(0.0f, 0.0f, nsign * radius);
        for (j = 0; j <= slices; j++) {
          theta = (j == slices) ? 0.0f : j * dtheta;
          x = -sin(theta) * sin(drho);
          y = cos(theta) * sin(drho);
          z = nsign * cos(drho);
          if (normals) {
            gl.glNormal3f(x * nsign, y * nsign, z * nsign);
          }
          gl.glVertex3f(x * radius, y * radius, z * radius);
        }
        gl.glEnd();
      }

      ds = 1.0f / slices;
      dt = 1.0f / stacks;
      t = 1.0f; // because loop now runs from 0
      if (textureFlag) {
        imin = 0;
        imax = stacks;
      } else {
        imin = 1;
        imax = stacks - 1;
      }

      // draw intermediate stacks as quad strips
      for (i = imin; i < imax; i++) {
        rho = i * drho;
        gl.glBegin(GL.GL_QUAD_STRIP);
        s = 0.0f;
        for (j = 0; j <= slices; j++) {
          theta = (j == slices) ? 0.0f : j * dtheta;
          x = -sin(theta) * sin(rho);
          y = cos(theta) * sin(rho);
          z = nsign * cos(rho);
          if (normals) {
            gl.glNormal3f(x * nsign, y * nsign, z * nsign);
          }
          TXTR_COORD(gl, s, t);
          gl.glVertex3f(x * radius, y * radius, z * radius);
          x = -sin(theta) * sin(rho + drho);
          y = cos(theta) * sin(rho + drho);
          z = nsign * cos(rho + drho);
          if (normals) {
            gl.glNormal3f(x * nsign, y * nsign, z * nsign);
          }
          TXTR_COORD(gl, s, t - dt);
          s += ds;
          gl.glVertex3f(x * radius, y * radius, z * radius);
        }
        gl.glEnd();
        t -= dt;
      }

      if (!textureFlag) {
        // draw -Z end as a triangle fan
        gl.glBegin(GL.GL_TRIANGLE_FAN);
        gl.glNormal3f(0.0f, 0.0f, -1.0f);
        gl.glVertex3f(0.0f, 0.0f, -radius * nsign);
        rho = PI - drho;
        s = 1.0f;
        for (j = slices; j >= 0; j--) {
          theta = (j == slices) ? 0.0f : j * dtheta;
          x = -sin(theta) * sin(rho);
          y = cos(theta) * sin(rho);
          z = nsign * cos(rho);
          if (normals)
            gl.glNormal3f(x * nsign, y * nsign, z * nsign);
          s -= ds;
          gl.glVertex3f(x * radius, y * radius, z * radius);
        }
        gl.glEnd();
      }
    } else if (
               drawStyle == GLU.GLU_LINE
               || drawStyle == GLU.GLU_SILHOUETTE) {
      // draw stack lines
      for (i = 1;
           i < stacks;
           i++) { // stack line at i==stacks-1 was missing here
        rho = i * drho;
        gl.glBegin(GL.GL_LINE_LOOP);
        for (j = 0; j < slices; j++) {
          theta = j * dtheta;
          x = cos(theta) * sin(rho);
          y = sin(theta) * sin(rho);
          z = cos(rho);
          if (normals)
            gl.glNormal3f(x * nsign, y * nsign, z * nsign);
          gl.glVertex3f(x * radius, y * radius, z * radius);
        }
        gl.glEnd();
      }
      // draw slice lines
      for (j = 0; j < slices; j++) {
        theta = j * dtheta;
        gl.glBegin(GL.GL_LINE_STRIP);
        for (i = 0; i <= stacks; i++) {
          rho = i * drho;
          x = cos(theta) * sin(rho);
          y = sin(theta) * sin(rho);
          z = cos(rho);
          if (normals)
            gl.glNormal3f(x * nsign, y * nsign, z * nsign);
          gl.glVertex3f(x * radius, y * radius, z * radius);
        }
        gl.glEnd();
      }
    } else if (drawStyle == GLU.GLU_POINT) {
      // top and bottom-most points
      gl.glBegin(GL.GL_POINTS);
      if (normals)
        gl.glNormal3f(0.0f, 0.0f, nsign);
      gl.glVertex3f(0.0f, 0.0f, radius);
      if (normals)
        gl.glNormal3f(0.0f, 0.0f, -nsign);
      gl.glVertex3f(0.0f, 0.0f, -radius);

      // loop over stacks
      for (i = 1; i < stacks - 1; i++) {
        rho = i * drho;
        for (j = 0; j < slices; j++) {
          theta = j * dtheta;
          x = cos(theta) * sin(rho);
          y = sin(theta) * sin(rho);
          z = cos(rho);
          if (normals)
            gl.glNormal3f(x * nsign, y * nsign, z * nsign);
          gl.glVertex3f(x * radius, y * radius, z * radius);
        }
      }
      gl.glEnd();
    }
  }


  //----------------------------------------------------------------------
  // Internals only below this point
  //

  private static final float PI = (float)Math.PI;
  private static final int CACHE_SIZE = 240;

  /**
   * Call glNormal3f after scaling normal to unit length.
   *
   * @param x
   * @param y
   * @param z
   */
  private void normal3f(GL gl, float x, float y, float z) {
    float mag;
	
    mag = (float)Math.sqrt(x * x + y * y + z * z);
    if (mag > 0.00001F) {
      x /= mag;
      y /= mag;
      z /= mag;
    }
    gl.glNormal3f(x, y, z);
  }

  private void TXTR_COORD(GL gl, float x, float y) {
    if (textureFlag) gl.glTexCoord2f(x,y);
  }

  private float sin(float r) {
    return (float)Math.sin(r);
  }

  private float cos(float r) {
    return (float)Math.cos(r);
  }
}