1 /* 2 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.javafx.tools.ant; 27 28 import com.sun.javafx.tools.packager.DeployParams.RunMode; 29 import java.util.HashSet; 30 import java.util.LinkedList; 31 import java.util.List; 32 import java.util.Set; 33 import org.apache.tools.ant.BuildException; 34 import org.apache.tools.ant.types.DataType; 35 36 /** 37 * Application description for users. These details are shown in the system dialogs 38 * (if they need to be shown). 39 * 40 * Examples: 41 * <pre> 42 * <info vendor="Uncle Joe" description="Test program"> 43 * <splash href="customsplash.gif> 44 * </info> 45 * </pre> 46 * 47 * @ant.type name="info" category="javafx" 48 */ 49 50 public class Info extends DataType { 51 String title; 52 String vendor; 53 String appDescription; 54 String category; 55 String licenseType; 56 String copyright; 57 String email; 58 List<Icon> icons = new LinkedList<>(); 59 List<FileAssociation> fileAssociations = new LinkedList<>(); 60 61 /** 62 * Application category. 63 * Category of application is platform specific. 64 * Currently used by native bundlers only. 65 * 66 * In particular: 67 * Mac AppStore: 68 * http://developer.apple.com/library/mac/#releasenotes/General/SubmittingToMacAppStore/_index.html 69 * Linux (for desktop shortucts) 70 * http://standards.freedesktop.org/menu-spec/latest/ar01s03.html#desktop-entry-extensions-examples 71 * 72 * @ant.not-required 73 */ 74 public void setCategory(String v) { 75 category = v; 76 } 77 78 /** 79 * Type of application license. Format is platform specific. 80 * E.g. see Fedora guidelines - http://fedoraproject.org/wiki/Packaging:LicensingGuidelines 81 * 82 * Currently used by SOME of native bundlers only. 83 * 84 * @ant.not-required 85 */ 86 public void setLicense(String v) { 87 licenseType = v; 88 } 89 90 /** 91 * Application copyright. Format is platform specific. 92 * Currently used by SOME of native bundlers only. 93 * 94 * @ant.not-required 95 */ 96 public void setCopyright(String v) { 97 copyright = v; 98 } 99 100 /** 101 * Title of the application 102 * 103 * @ant.required 104 */ 105 public void setTitle(String v) { 106 title = v; 107 } 108 109 /** 110 * Provider of the application. 111 * 112 * @ant.required 113 */ 114 public void setVendor(String v) { 115 vendor = v; 116 } 117 118 /** 119 * A short statement describing the application. 120 * 121 * @ant.required 122 */ 123 public void setDescription(String v) { 124 appDescription = v; 125 } 126 127 /** 128 * Email contact of vendor. 129 * Required for Debian packages, not used by other bundlers 130 * 131 * Email will be combined with Vendor to create a maintainer contact for 132 * Debian package 133 * 134 * @param v 135 */ 136 public void setEmail(String v) { 137 email = v; 138 } 139 140 final static Set<String> iconTypes; 141 142 static { 143 iconTypes = new HashSet<String>() { 144 { 145 add("default"); 146 add("selected"); 147 add("disabled"); 148 add("rollover"); 149 add("splash"); 150 add("shortcut"); 151 } 152 }; 153 } 154 155 /** 156 * Describes an icon that can be used to identify the application to the user. 157 * Supported icon formats: gif, jpg, png, ico. 158 */ 159 public class Icon extends DataType { 160 String href; 161 String kind; 162 int width = UNDEFINED; 163 int height = UNDEFINED; 164 int depth = UNDEFINED; 165 166 final static int UNDEFINED = -1; 167 168 /** 169 * A URL pointing to the icon file. 170 * 171 * @ant.required 172 */ 173 public void setHref(String v) { 174 href = v; 175 } 176 177 /** 178 * Indicates the suggested use of the icon, can be: 179 * default, selected, disabled, rollover, or shortcut. 180 * 181 */ 182 public void setKind(String v) { 183 if (iconTypes.contains(v.toLowerCase())) { 184 kind = v.toLowerCase(); 185 } else { 186 StringBuffer msg = new StringBuffer("Usupported type of icon ["); 187 msg.append(v.toLowerCase()); 188 msg.append("]. Supported types: "); 189 for (String s: iconTypes) { 190 msg.append("\""+s+"\" "); 191 } 192 193 throw new BuildException(msg.toString()); 194 } 195 } 196 197 /** 198 * Can be used to indicate the width of the image. 199 */ 200 public void setWidth(int v) { 201 if (v > 0) { 202 width = v; 203 } else { 204 throw new BuildException("Width must be positive number"); 205 } 206 } 207 208 /** 209 * Can be used to indicate the height of the image. 210 */ 211 public void setHeight(int v) { 212 if (v > 0) { 213 height = v; 214 } else { 215 throw new BuildException("Height must be positive number"); 216 } 217 } 218 219 /** 220 * Can be used to indicate the resolution of the image. 221 */ 222 public void setDepth(int v) { 223 if (v > 0) { 224 depth = v; 225 } else { 226 throw new BuildException("Depth must be positive number"); 227 } 228 } 229 } 230 231 public Icon createIcon() { 232 Icon ic = new Icon(); 233 icons.add(ic); 234 return ic; 235 } 236 237 /** 238 * Splash image to be shown on the application start. 239 * In addition to icon properties can be also specific for particular 240 * execution mode. 241 */ 242 public class Splash extends Icon { 243 RunMode mode; 244 245 public Splash() { 246 super(); 247 kind = "splash"; 248 } 249 250 public void setKind() { 251 throw new BuildException("Can not change kind of splash. Use icon instead."); 252 } 253 254 /** 255 * Define execution mode to use splash for. 256 * Supported modes are: "webstart", "embedded", "standalone" and "any". 257 * 258 * Default value is "webstart" 259 */ 260 public void setMode(String v) { 261 String l = v.toLowerCase(); 262 if ("webstart".equals(l)) { 263 mode = RunMode.WEBSTART; 264 } else if ("embedded".equals(l)) { 265 mode = RunMode.EMBEDDED; 266 } else if ("standalone".equals(l)) { 267 mode = RunMode.STANDALONE; 268 } else if ("any".equals(l)) { 269 mode = RunMode.ALL; 270 } else { 271 throw new BuildException("Unsupported run mode: ["+v+"]."); 272 } 273 } 274 } 275 276 public Splash createSplash() { 277 Splash s = new Splash(); 278 icons.add(s); 279 return s; 280 } 281 282 /** 283 * A hint to the packager that it wishes to be registered with the 284 * operating system as the primary handler of certain extensions and 285 * a certain mime-type. 286 * 287 * @ant.not-required 288 */ 289 public FileAssociation createAssociation() { 290 FileAssociation fa = new FileAssociation(); 291 fileAssociations.add(fa); 292 return fa; 293 } 294 }