1 /* 2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. 3 * All rights reserved. Use is subject to license terms. 4 * 5 * This file is available and licensed under the following license: 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * - Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * - Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the distribution. 16 * - Neither the name of Oracle Corporation nor the names of its 17 * contributors may be used to endorse or promote products derived 18 * from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 package com.oracle.javafx.scenebuilder.app.about; 33 34 import com.oracle.javafx.scenebuilder.app.SceneBuilderApp; 35 import com.oracle.javafx.scenebuilder.app.i18n.I18N; 36 import com.oracle.javafx.scenebuilder.kit.editor.panel.util.AbstractFxmlWindowController; 37 import com.sun.javafx.tk.Toolkit; 38 import com.sun.prism.GraphicsPipeline; 39 import java.io.File; 40 import java.io.IOException; 41 import java.io.InputStream; 42 import java.util.Properties; 43 import javafx.fxml.FXML; 44 import javafx.scene.control.TextArea; 45 import javafx.scene.input.MouseEvent; 46 import javafx.scene.layout.VBox; 47 import javafx.stage.Modality; 48 import javafx.stage.WindowEvent; 49 50 /** 51 * 52 */ 53 public final class AboutWindowController extends AbstractFxmlWindowController { 54 55 @FXML 56 private VBox vbox; 57 @FXML 58 private TextArea textArea; 59 60 private String sbBuildInfo = "PLACEHOLDER"; //NOI18N 61 private String sbBuildDate = "PLACEHOLDER"; //NOI18N 62 private String sbBuildJavaVersion = "PLACEHOLDER"; //NOI18N 63 // The resource bundle contains two keys: about.copyright and about.copyright.open 64 private String sbAboutCopyrightKeyName = "about.copyright.open"; //NOI18N 65 // File name must be in sync with what we use in logging.properties 66 private final String LOG_FILE_NAME = "scenebuilder-2.0.1.log"; //NOI18N 67 68 public AboutWindowController() { 69 super(AboutWindowController.class.getResource("About.fxml"), //NOI18N 70 I18N.getBundle()); 71 try (InputStream in = getClass().getResourceAsStream("about.properties")) { //NOI18N 72 73 if (in != null) { 74 Properties sbProps = new Properties(); 75 sbProps.load(in); 76 sbBuildInfo = sbProps.getProperty("build.info", "UNSET"); //NOI18N 77 sbBuildDate = sbProps.getProperty("build.date", "UNSET"); //NOI18N 78 sbBuildJavaVersion = sbProps.getProperty("build.java.version", "UNSET"); //NOI18N 79 sbAboutCopyrightKeyName = sbProps.getProperty("copyright.key.name", "UNSET"); //NOI18N 80 } 81 } catch (IOException ex) { 82 // We go with default values 83 } 84 } 85 86 @FXML 87 public void onMousePressed(MouseEvent event) { 88 if ((event.getClickCount() == 2) && event.isAltDown()) { 89 SceneBuilderApp.getSingleton().toggleDebugMenu(); 90 } 91 } 92 93 @Override 94 public void onCloseRequest(WindowEvent event) { 95 closeWindow(); 96 } 97 98 /* 99 * AbstractWindowController 100 */ 101 @Override 102 protected void controllerDidCreateStage() { 103 assert getRoot() != null; 104 assert getRoot().getScene() != null; 105 assert getRoot().getScene().getWindow() != null; 106 107 getStage().setTitle(I18N.getString("about.title")); 108 getStage().initModality(Modality.APPLICATION_MODAL); 109 } 110 111 @Override 112 protected void controllerDidLoadFxml() { 113 super.controllerDidLoadFxml(); 114 assert vbox != null; 115 assert textArea != null; 116 textArea.setText(getAboutText()); 117 } 118 119 private String getAboutText() { 120 121 StringBuilder text = getVersionParagraph() 122 .append(getBuildInfoParagraph()) 123 .append(getLoggingParagraph()) 124 .append(getFxParagraph()) 125 .append(getJavaParagraph()) 126 .append(getOsParagraph()) 127 .append(I18N.getString(sbAboutCopyrightKeyName)); 128 129 return text.toString(); 130 } 131 132 /** 133 * 134 * @treatAsPrivate 135 */ 136 public String getBuildJavaVersion() { 137 return sbBuildJavaVersion; 138 } 139 140 /** 141 * 142 * @treatAsPrivate 143 */ 144 public String getBuildInfo() { 145 return sbBuildInfo; 146 } 147 148 private StringBuilder getVersionParagraph() { 149 StringBuilder sb = new StringBuilder(I18N.getString("about.product.version")); 150 sb.append("\nJavaFX Scene Builder 2.0.1\n\n"); //NOI18N 151 return sb; 152 } 153 private String getLogFilePath() { 154 StringBuilder sb = new StringBuilder(System.getProperty("java.io.tmpdir")); //NOI18N 155 if (sb.charAt(sb.length() - 1) != File.separatorChar) { 156 sb.append(File.separatorChar); 157 } 158 sb.append(LOG_FILE_NAME); 159 return sb.toString(); 160 161 } 162 163 private StringBuilder getBuildInfoParagraph() { 164 StringBuilder sb = new StringBuilder(I18N.getString("about.build.information")); 165 sb.append("\n").append(sbBuildInfo).append("\n") //NOI18N 166 .append(I18N.getString("about.build.date", sbBuildDate)) 167 .append("\n\n"); //NOI18N 168 return sb; 169 } 170 171 private StringBuilder getLoggingParagraph() { 172 StringBuilder sb = new StringBuilder(I18N.getString("about.logging.title")); 173 sb.append("\n") //NOI18N 174 .append(I18N.getString("about.logging.body.first", LOG_FILE_NAME)) 175 .append("\n") //NOI18N 176 .append(I18N.getString("about.logging.body.second", getLogFilePath())) 177 .append("\n\n"); //NOI18N 178 return sb; 179 } 180 181 private StringBuilder getFxParagraph() { 182 boolean hwAccelerated = false; 183 String tk = Toolkit.getToolkit().getClass().getSimpleName(); 184 StringBuilder fxtra = new StringBuilder("JavaFX\n"); //NOI18N 185 fxtra.append(I18N.getString("about.fx.toolkit")) 186 .append(" = ").append(tk).append("\n"); //NOI18N 187 188 if ("GlassToolkit".equals(tk) || "PrismToolkit".equals(tk) //NOI18N 189 || "QuantumToolkit".equals(tk)) { //NOI18N 190 String ppl = GraphicsPipeline.getPipeline().getClass().getSimpleName(); 191 fxtra.append(I18N.getString("about.fx.pipeline")) 192 .append(" = ").append(ppl).append("\n"); //NOI18N 193 if (ppl.trim().equals("D3DPipeline") //NOI18N 194 || ppl.trim().equals("ES1Pipeline") //NOI18N 195 || ppl.trim().equals("ES2Pipeline")) { //NOI18N 196 hwAccelerated = true; 197 } 198 } 199 fxtra.append(I18N.getString("about.fx.hardware.acceleration")) 200 .append(" ") //NOI18N 201 .append(hwAccelerated ? I18N.getString("about.fx.hardware.acceleration.enabled") 202 : I18N.getString("about.fx.hardware.acceleration.disabled")) 203 .append("\n\n"); //NOI18N 204 205 return fxtra; 206 } 207 208 private StringBuilder getJavaParagraph() { 209 StringBuilder sb = new StringBuilder("Java\n"); //NOI18N 210 sb.append(System.getProperty("java.runtime.version")).append(", ") //NOI18N 211 .append(System.getProperty("java.vendor")).append("\n\n"); //NOI18N 212 return sb; 213 } 214 215 private StringBuilder getOsParagraph() { 216 StringBuilder sb = new StringBuilder(I18N.getString("about.operating.system")); 217 sb.append("\n").append(System.getProperty("os.name")).append(", ") //NOI18N 218 .append(System.getProperty("os.arch")).append(", ") //NOI18N 219 .append(System.getProperty("os.version")).append("\n\n"); //NOI18N 220 return sb; 221 } 222 }