From e442d4605e93923cb9858c0fa2d3e96d69a06802 Mon Sep 17 00:00:00 2001 From: JoePfeiffer Date: Mon, 7 Feb 2022 15:03:37 -0700 Subject: [PATCH] Update license dialog Quit quoting entire GPL in dialog; insert hrefs pointing to it. Add other licenses: Apache license, for Dave's components library DejaVu font license. I wasn't able to find an "authoritative" source for this license to point people at. BSD 2-Clause license for commonmark-java library. This license is so short I left it in the dialog. To my surprise, I also didn't find an "authoritative" source for this license to point people at --- .../gui/components/DescriptionArea.java | 14 +- .../openrocket/gui/dialogs/LicenseDialog.java | 172 ++++++++++++++---- 2 files changed, 144 insertions(+), 42 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/components/DescriptionArea.java b/swing/src/net/sf/openrocket/gui/components/DescriptionArea.java index 324c186f2..6c17891ed 100644 --- a/swing/src/net/sf/openrocket/gui/components/DescriptionArea.java +++ b/swing/src/net/sf/openrocket/gui/components/DescriptionArea.java @@ -107,7 +107,8 @@ public class DescriptionArea extends JScrollPane { prefix = resourceName.substring(0, dotIndex); suffix = resourceName.substring(dotIndex+1); } - + + // create temporary file and copy resource to it File of = null; BufferedOutputStream os = null; @@ -122,13 +123,9 @@ public class DescriptionArea extends JScrollPane { uri = of.toURI(); try { - int avail = is.available(); - while (avail > 0) { - byte buffer[] = new byte[avail]; - int bytesread = is.read(buffer, 0, avail); - os.write(buffer, 0, bytesread); - avail = is.available(); - } + byte buffer[] = is.readAllBytes(); + os.write(buffer); + os.close(); } catch (Exception ex) { throw new RuntimeException(ex); @@ -162,7 +159,6 @@ public class DescriptionArea extends JScrollPane { Dimension dim = editorPane.getPreferredSize(); dim.height = lineheight * rows + extraheight + 2; - this.setPreferredSize(dim); this.setViewportView(editorPane); this.setText(text); diff --git a/swing/src/net/sf/openrocket/gui/dialogs/LicenseDialog.java b/swing/src/net/sf/openrocket/gui/dialogs/LicenseDialog.java index 7ac41ce05..535bab300 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/LicenseDialog.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/LicenseDialog.java @@ -3,66 +3,172 @@ package net.sf.openrocket.gui.dialogs; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.net.URL; import java.io.BufferedReader; +import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JFrame; +import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import net.miginfocom.swing.MigLayout; +import net.sf.openrocket.gui.components.DescriptionArea; import net.sf.openrocket.gui.components.StyledLabel; import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.startup.Application; +import net.sf.openrocket.gui.util.Icons; import net.sf.openrocket.gui.widgets.SelectColorButton; +import net.sf.openrocket.util.BuildProperties; +import net.sf.openrocket.util.Chars; public class LicenseDialog extends JDialog { - private static final String LICENSE_FILENAME = "LICENSE.TXT"; private static final Translator trans = Application.getTranslator(); - private static final String DEFAULT_LICENSE_TEXT = - "\n" + - "Error: Unable to load " + LICENSE_FILENAME + "!\n" + - "\n" + - "OpenRocket is licensed under the GNU GPL version 3, with additional permissions.\n" + - "See http://openrocket.sourceforge.net/ for details."; - public LicenseDialog(JFrame parent) { super(parent, true); JPanel panel = new JPanel(new MigLayout("fill")); - panel.add(new StyledLabel("OpenRocket license", 10), "ax 50%, wrap para"); - - String licenseText; - try { - - BufferedReader reader = new BufferedReader( - new InputStreamReader(ClassLoader.getSystemResourceAsStream(LICENSE_FILENAME))); - StringBuffer sb = new StringBuffer(); - for (String s = reader.readLine(); s != null; s = reader.readLine()) { - sb.append(s); - sb.append('\n'); - } - licenseText = sb.toString(); - - } catch (IOException e) { - - licenseText = DEFAULT_LICENSE_TEXT; - - } + // OpenRocket logo + panel.add(new JLabel(Icons.loadImageIcon("pix/icon/icon-about.png", "OpenRocket")), "top"); - JTextArea text = new JTextArea(licenseText); - text.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); - text.setRows(20); - text.setColumns(80); - text.setEditable(false); - panel.add(new JScrollPane(text),"grow, wrap para"); + panel.add(new StyledLabel("Software Licenses", 10), "ax 50%, wrap para"); + + final String jarUrl = "jar:" + getClass().getProtectionDomain().getCodeSource().getLocation().toString(); + final String copyrightYear = BuildProperties.getCopyrightYear(); + + /*****************************************************************************************************************************/ + /* */ + /* LICENSE TEXT: each of the licenses we're using is described here. At the end, they are all concatenated for insertion */ + /* in the description window */ + /* */ + /*****************************************************************************************************************************/ + + /*****************************************************************************************************************************/ + /* GPL: overall project */ + /*****************************************************************************************************************************/ + final String gplInternalHref = "here"; + final String orLicense = "GNU GENERAL PUBLIC LICENSE" + "
" + + "
" + + "OpenRocket - A model rocket simulator
" + + "Copyright " + Chars.COPY + " 2007-" + copyrightYear + "Sampo Niskanen and others
" + + "Project page: https://openrocket.info/
" + + "
" + + "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 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 " + gplInternalHref + " for more details.
" + + "
" + + "A copy of the GNU General Public License may be viewed " + gplInternalHref + ". " + + "You may also obtain a copy of the License at:
" + + "
" + + "https://www.gnu.org/licenses/gpl-3.0.html
" + + "
" + + "OpenRocket developers may be contacted electronically at:
" + + "
" + + "mailto:openrocket-devel@lists.sourceforge.net
" + + "https://github.com/openrocket
" + + "
"; + + /*****************************************************************************************************************************/ + /* APACHE: components library */ + /*****************************************************************************************************************************/ + final String apacheInternalHref = "here"; + final String componentsLicense = + "APACHE LICENSE
" + + "
" + + "Enhanced components database for OpenRocket
" + + "Copyright " + Chars.COPY + " 2015-" + copyrightYear + " David B. Cook
" + + "Project page: https://github.com/dbcook/openrocket-database
" + + "
" + + "Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this work except in compliance with the License. " + + " A copy of the Apache License may be viewed " + apacheInternalHref + ". You may also obtain a copy of the License at:
" + + "
" + + "http://www.apache.org/licenses/LICENSE-2.0

" + + + "Unless required by applicable law or agreed to in writing, software distributed under the License is distributed " + + "on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License " + + apacheInternalHref + " for the specific language governing permissions and limitations under the License.
" + + "
"; + + + /*****************************************************************************************************************************/ + /* BITSTREAM VERA: Deja Vu font */ + /*****************************************************************************************************************************/ + final String dejaLicenseUrl = jarUrl + "!/dejavu-font/LICENSE"; + final String fontLicense = + "Bitstream Vera Font License
" + + "
" + + "DejaVu Serif Font
" + + "Fonts are Copyright " + Chars.COPY + " 2003 by Bitstream, Inc. All Rights Reserved. Bitstream Vera is a trademark of Bitstream, Inc.
" + + "DejaVu changes are in the public domain
" + + "Glyphs imported from Arev Fonts Copyright " + Chars.COPY + " 2006 by Tavmjong Bah. All Rights Reserved.
" + + "
" + + "Licensed according to the Bitstream Vera Font License which may be found here." + + "
" + + "THE FONT SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS " + + "OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY " + + "FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, " + + "TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL BITSTREAM OR THE GNOME " + + "FOUNDATION BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING " + + "ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, " + + "WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF " + + "THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE " + + "FONT SOFTWARE.
" + + "
" + + "See the License for the specific language" + + "governing permissions and limitations under the License.
" + + "
"; + + + /*****************************************************************************************************************************/ + /* BSD 2-Clause: commonmark-java library */ + /*****************************************************************************************************************************/ + final String commonmarkLicense = + "BSD 2-Clause License
" + + "
" + + "Commonmark-Java Library
" + + "Copyright " + Chars.COPY + " 2015-2016 Atlassian Pty Ltd
" + + "All rights reserved.
" + + "
" + + "Redistribution and use in source and binary forms, with or without" + + "modification, are permitted provided that the following conditions are met:
" + + "" + + "
" + + "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 HOLDER 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.
" + + "
"; + + /*****************************************************************************************************************************/ + /* End of license text */ + /*****************************************************************************************************************************/ + + DescriptionArea info = new DescriptionArea(20); + info.setText(orLicense + componentsLicense + fontLicense + commonmarkLicense); + panel.add(info, "newline, width 600lp, height 150lp, grow, spanx, wrap para"); //Close button JButton close = new SelectColorButton(trans.get("dlg.but.close"));