CMSC 335
__MACOSX/._CodeZip
CodeZip/CurrentThreadDemo.java
CodeZip/CurrentThreadDemo.java
// Controlling the main Thread.
class
CurrentThreadDemo
{
public
static
void
main
(
String
args
[])
{
Thread
t
=
Thread
.
currentThread
();
System
.
out
.
println
(
"Current thread: "
+
t
);
// change the name of the thread
t
.
setName
(
"My Thread"
);
System
.
out
.
println
(
"After name change: "
+
t
);
try
{
for
(
int
n
=
5
;
n
>
0
;
n
--
)
{
System
.
out
.
println
(
n
);
Thread
.
sleep
(
1000
);
}
}
catch
(
InterruptedException
e
)
{
System
.
out
.
println
(
"Main thread interrupted"
);
}
}
}
__MACOSX/CodeZip/._CurrentThreadDemo.java
CodeZip/MultiThreadDemo.java
CodeZip/MultiThreadDemo.java
class
MultiThreadDemo
{
public
static
void
main
(
String
args
[])
{
NewThread
nt1
=
new
NewThread
(
"One"
);
NewThread
nt2
=
new
NewThread
(
"Two"
);
NewThread
nt3
=
new
NewThread
(
"Three"
);
// Start the threads.
nt1
.
t
.
start
();
nt2
.
t
.
start
();
nt3
.
t
.
start
();
try
{
// wait for other threads to end
Thread
.
sleep
(
10000
);
}
catch
(
InterruptedException
e
)
{
System
.
out
.
println
(
"Main thread Interrupted"
);
}
System
.
out
.
println
(
"Main thread exiting."
);
}
}
// Create multiple threads.
class
NewThread
implements
Runnable
{
String
name
;
// name of thread
Thread
t
;
NewThread
(
String
threadname
)
{
name
=
threadname
;
t
=
new
Thread
(
this
,
name
);
System
.
out
.
println
(
"New thread: "
+
t
);
}
// This is the entry point for thread.
public
void
run
()
{
try
{
for
(
int
i
=
5
;
i
>
0
;
i
--
)
{
System
.
out
.
println
(
name
+
": "
+
i
);
Thread
.
sleep
(
1000
);
}
}
catch
(
InterruptedException
e
)
{
System
.
out
.
println
(
name
+
"Interrupted"
);
}
System
.
out
.
println
(
name
+
" exiting."
);
}
}
__MACOSX/CodeZip/._MultiThreadDemo.java
CodeZip/ListDemo.java
CodeZip/ListDemo.java
// Demonstrate a simple JList.
import
javax
.
swing
.
*
;
import
javax
.
swing
.
event
.
*
;
import
java
.
awt
.
*
;
import
java
.
awt
.
event
.
*
;
public
class
ListDemo
implements
ListSelectionListener
{
JList
<
String
>
jlst
;
JLabel
jlab
;
JScrollPane
jscrlp
;
// Create an array of names.
String
names
[]
=
{
"Sherry"
,
"Jon"
,
"Rachel"
,
"Sasha"
,
"Josselyn"
,
"Randy"
,
"Tom"
,
"Mary"
,
"Ken"
,
"Andrew"
,
"Matt"
,
"Todd"
};
ListDemo
()
{
// Create a new JFrame container.
JFrame
jfrm
=
new
JFrame
(
"JList Demo"
);
// Specify a flow Layout.
jfrm
.
setLayout
(
new
FlowLayout
());
// Give the frame an initial size.
jfrm
.
setSize
(
200
,
160
);
// Terminate the program when the user closes the application.
jfrm
.
setDefaultCloseOperation
(
JFrame
.
EXIT_ON_CLOSE
);
// Create a JList.
jlst
=
new
JList
<
String
>
(
names
);
// Set the list selection mode to single-selection.
jlst
.
setSelectionMode
(
ListSelectionModel
.
SINGLE_SELECTION
);
// Add list to a scroll pane.
jscrlp
=
new
JScrollPane
(
jlst
);
// Set the preferred size of the scroll pane.
jscrlp
.
setPreferredSize
(
new
Dimension
(
120
,
90
));
// Make a label that displays the selection.
jlab
=
new
JLabel
(
"Please choose a name"
);
// Add list selection handler.
jlst
.
addListSelectionListener
(
this
);
// Add the list and label to the content pane.
jfrm
.
add
(
jscrlp
);
jfrm
.
add
(
jlab
);
// Display the frame.
jfrm
.
setVisible
(
true
);
}
// Handle list selection events.
public
void
valueChanged
(
ListSelectionEvent
le
)
{
// Get the index of the changed item.
int
idx
=
jlst
.
getSelectedIndex
();
// Display selection, if item was selected.
if
(
idx
!=
-
1
)
jlab
.
setText
(
"Current selection: "
+
names
[
idx
]);
else
// Othewise, reprompt.
jlab
.
setText
(
"Please choose an name"
);
}
public
static
void
main
(
String
args
[])
{
// Create the frame on the event dispatching thread.
SwingUtilities
.
invokeLater
(
new
Runnable
()
{
public
void
run
()
{
new
ListDemo
();
}
});
}
}
__MACOSX/CodeZip/._ListDemo.java
CodeZip/CBDemo.java
CodeZip/CBDemo.java
// Demonstrate check boxes.
import
java
.
awt
.
*
;
import
java
.
awt
.
event
.
*
;
import
javax
.
swing
.
*
;
public
class
CBDemo
implements
ItemListener
{
JLabel
jlabSelected
;
JLabel
jlabChanged
;
JCheckBox
jcbAlpha
;
JCheckBox
jcbBeta
;
JCheckBox
jcbGamma
;
CBDemo
()
{
// Create a new JFrame container.
JFrame
jfrm
=
new
JFrame
(
"Demonstrate Check Boxes"
);
// Specify FlowLayout for the layout manager.
jfrm
.
setLayout
(
new
FlowLayout
());
// Give the frame an initial size.
jfrm
.
setSize
(
280
,
120
);
// Terminate the program when the user closes the application.
jfrm
.
setDefaultCloseOperation
(
JFrame
.
EXIT_ON_CLOSE
);
// Create empty labels.
jlabSelected
=
new
JLabel
(
""
);
jlabChanged
=
new
JLabel
(
""
);
// Make check boxes.
jcbAlpha
=
new
JCheckBox
(
"Alpha"
);
jcbBeta
=
new
JCheckBox
(
"Beta"
);
jcbGamma
=
new
JCheckBox
(
"Gamma"
);
// Events generated by the check boxes
// are handled in common by the itemStateChanged()
// method implemented by CBDemo.
jcbAlpha
.
addItemListener
(
this
);
jcbBeta
.
addItemListener
(
this
);
jcbGamma
.
addItemListener
(
this
);
// Add checkboxes and labels to the content pane.
jfrm
.
add
(
jcbAlpha
);
jfrm
.
add
(
jcbBeta
);
jfrm
.
add
(
jcbGamma
);
jfrm
.
add
(
jlabChanged
);
jfrm
.
add
(
jlabSelected
);
// Display the frame.
jfrm
.
setVisible
(
true
);
}
// This is the handler for the check boxes.
public
void
itemStateChanged
(
ItemEvent
ie
)
{
String
str
=
""
;
// Obtain a reference to the check box that
// caused the event.
JCheckBox
cb
=
(
JCheckBox
)
ie
.
getItem
();
// Report what check box changed.
if
(
cb
.
isSelected
())
jlabChanged
.
setText
(
cb
.
getText
()
+
" was just selected."
);
else
jlabChanged
.
setText
(
cb
.
getText
()
+
" was just cleared."
);
// Report all selected boxes.
if
(
jcbAlpha
.
isSelected
())
{
str
+=
"Alpha "
;
}
if
(
jcbBeta
.
isSelected
())
{
str
+=
"Beta "
;
}
if
(
jcbGamma
.
isSelected
())
{
str
+=
"Gamma"
;
}
jlabSelected
.
setText
(
"Selected check boxes: "
+
str
);
}
public
static
void
main
(
String
args
[])
{
// Create the frame on the event dispatching thread.
SwingUtilities
.
invokeLater
(
new
Runnable
()
{
public
void
run
()
{
new
CBDemo
();
}
});
}
}
__MACOSX/CodeZip/._CBDemo.java
CodeZip/ColorfulCirclesFX.zip
ColorfulCircles/build.xml
Builds, tests, and runs the project ColorfulCircles.
ColorfulCircles/License.txt
/* * Copyright (c) 2011, 2014 Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * * This file is available and licensed under the following license: * * 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 Oracle 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. */
ColorfulCircles/manifest.mf
Manifest-Version: 1.0 X-COMMENT: Main-Class will be added automatically by build
ColorfulCircles/nbproject/build-impl.xml
Must set platform.home Must set platform.bootcp Must set platform.java Must set platform.javac The J2SE Platform is not correctly set up. Your active platform is: ${platform.active}, but the corresponding property "platforms.${platform.active}.home" is not found in the project's properties files. Either open the project in the IDE and setup the Platform with the same name or add it manually. For example like this: ant -Duser.properties.file=<path_to_property_file> jar (where you put the property "platforms.${platform.active}.home" in a .properties file) or ant -Dplatforms.${platform.active}.home=<path_to_JDK_home> jar (where no properties file is used) Must set src.dir Must set build.dir Must set dist.dir Must set build.classes.dir Must set dist.javadoc.dir Must set build.test.classes.dir Must set build.test.results.dir Must set build.classes.excludes Must set dist.jar Must set javac.includes No tests executed. Must set JVM to use for profiling in profiler.info.jvm Must set profiler agent JVM arguments in profiler.info.jvmargs.agent Must select some files in the IDE or set javac.includes To run this application from the command line without Ant, try: ${platform.java} -jar "${dist.jar.resolved}" Must select one file in the IDE or set run.class Must select one file in the IDE or set run.class Must select one file in the IDE or set debug.class Must select one file in the IDE or set debug.class Must set fix.includes This target only works when run from inside the NetBeans IDE. Must select one file in the IDE or set profile.class This target only works when run from inside the NetBeans IDE. This target only works when run from inside the NetBeans IDE. This target only works when run from inside the NetBeans IDE. Must select one file in the IDE or set run.class Must select some files in the IDE or set test.includes Must select one file in the IDE or set run.class Must select one file in the IDE or set applet.url Must select some files in the IDE or set javac.includes Some tests failed; see details above. Must select some files in the IDE or set test.includes Some tests failed; see details above. Must select some files in the IDE or set test.class Must select some method in the IDE or set test.method Some tests failed; see details above. Must select one file in the IDE or set test.class Must select one file in the IDE or set test.class Must select some method in the IDE or set test.method Must select one file in the IDE or set applet.url Must select one file in the IDE or set applet.url
ColorfulCircles/nbproject/configs/Run_as_WebStart.properties
ColorfulCircles/nbproject/configs/Run_in_Browser.properties
ColorfulCircles/nbproject/genfiles.properties
build.xml.data.CRC32=4366db9d build.xml.script.CRC32=779e2fe4 build.xml.stylesheet.CRC32=8064a381@1.68.1.46 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. nbproject/build-impl.xml.data.CRC32=4366db9d nbproject/build-impl.xml.script.CRC32=a69c17d1 nbproject/build-impl.xml.stylesheet.CRC32=5a01deb7@1.68.1.46
ColorfulCircles/nbproject/jfx-impl.xml
JavaFX-specific Ant calls ${cssfileslist} self.addMappedName( (source.indexOf("jfxrt.jar") >= 0) || (source.indexOf("deploy.jar") >= 0) || (source.indexOf("javaws.jar") >= 0) || (source.indexOf("plugin.jar") >= 0) ? "" : source ); function prefix(s, len) { if(s == null || len <= 0 || s.length == 0) { return new String(""); } return new String(s.substr(0, len)); } function defined(s) { return (s != null) && (s != "null") && (s.length > 0); } var pathConvert = project.createTask("pathconvert"); pathConvert.setProperty("run.and.lib.classpath"); var classPath = new String(project.getProperty("run.classpath.without.build.classes.and.dist.dir")); var fileSeparator = new String(project.getProperty("file.separator")); if(defined(classPath)) { var classPathCopy = pathConvert.createPath(); classPathCopy.setPath(classPath); var pathArray; if(classPath.indexOf(";") != -1) { pathArray = classPath.split(";"); } else { pathArray = classPath.split(":"); } var added = new java.lang.StringBuilder(); for (var i = 0; i < pathArray.length; i++) { var index = pathArray[i].lastIndexOf(fileSeparator); if (index >= 0) { var onePath = prefix(pathArray[i], index+1).concat("lib"); var oneDir = new java.io.File(onePath); if(oneDir.exists()) { var fs = project.createDataType( "fileset" ); fs.setDir( oneDir ); fs.setIncludes("*.jar"); var ds = fs.getDirectoryScanner(project); var srcFiles = ds.getIncludedFiles(); for (var j = 0; j < srcFiles.length; j++) { if(classPath.indexOf( srcFiles[j] ) == -1 && added.indexOf( srcFiles[j] ) == -1) { var path = pathConvert.createPath(); path.setPath( onePath.concat(fileSeparator).concat(srcFiles[j]) ); added.append( srcFiles[j] ); } } } } } } pathConvert.perform(); var dir = new String(project.getProperty("pp_rebase_dir")); var fDir = new java.io.File(dir); if( fDir.exists() ) { var callTask = project.createTask("antcall"); callTask.setTarget("-rebase-libs-macro-call"); var param = callTask.createParam(); param.setName("jar.file.to.rebase"); var includes = new String(project.getProperty("pp_rebase_fs")); var fs = project.createDataType("fileset"); fs.setDir( fDir ); fs.setIncludes(includes); var ds = fs.getDirectoryScanner(project); var srcFiles = ds.getIncludedFiles(); for (var i = 0; i < srcFiles.length; i++) { param.setValue(dir.concat("${file.separator}").concat(srcFiles[i])); callTask.perform(); } } var UTF_8 = "UTF-8"; var ATTR_CLASS_PATH = "Class-Path"; var ATTR_CLASS_PATH_FX = "JavaFX-Class-Path"; function endsWith(s, suffix) { var i = s.lastIndexOf(suffix); return (i != -1) && (i == (s.length - suffix.length)); } function isSigned(manifest) { var sections = manifest.getSectionNames(); while(sections.hasMoreElements()) { var sectionname = new String(sections.nextElement()); var section = manifest.getSection(sectionname); if(section != null) { var sectionKeys = section.getAttributeKeys(); while (sectionKeys.hasMoreElements()) { var element = new String(sectionKeys.nextElement()); if (endsWith(element, "-Digest") || endsWith(element, "-digest")) { return true; } } } } return false; } var src = new String(project.getProperty("manifest.file.temp")); var srf = new java.io.File(src); var manifest; try { var fis = new java.io.FileInputStream(srf); try { var isr = new java.io.InputStreamReader(fis, UTF_8); try { manifest = new org.apache.tools.ant.taskdefs.Manifest(isr); } finally { isr.close(); } } finally { fis.close(); } } catch(e) { manifest = null; } if(manifest != null) { if(isSigned(manifest)) { print("Warning: Signed JAR can not be rebased."); } else { var mainSection = manifest.getMainSection(); var classPath = mainSection.getAttributeValue(ATTR_CLASS_PATH); var classPathAttr = null; if (classPath != null) { classPathAttr = ATTR_CLASS_PATH; } else { classPath = mainSection.getAttributeValue(ATTR_CLASS_PATH_FX); if(classPath != null) { classPathAttr = ATTR_CLASS_PATH_FX; } } if(classPath != null) { var result = new java.lang.StringBuilder(); var changed = false; var pathArray = classPath.split(" "); for (var i = 0; i < pathArray.length; i++) { if (result.length() > 0) { result.append(' '); } var index = pathArray[i].lastIndexOf('/'); if (index >= 0 && index < pathArray[i].length - 1) { pathArray[i] = pathArray[i].substring(index+1); changed = true; } result.append(pathArray[i]); } mainSection.removeAttribute(classPathAttr); mainSection.addAttributeAndCheck(new org.apache.tools.ant.taskdefs.Manifest.Attribute(classPathAttr, result.toString())); var tgt = new String(project.getProperty("manifest.file.temp.new")); var tgf = new java.io.File(tgt); try { var fos = new java.io.FileOutputStream(tgf); try { var osw = new java.io.OutputStreamWriter(fos, UTF_8); try { var manifestOut = new java.io.PrintWriter(osw); manifest.write(manifestOut); manifestOut.close(); } finally { osw.close(); } } finally { fos.close(); } } catch(e) { print("Warning: problem storing rebased manifest file."); } } } } function isTrue(prop) { return prop != null && ( prop.toLowerCase() == "true" || prop.toLowerCase() == "yes" || prop.toLowerCase() == "on" ); } function prefix(s, len) { if(s == null || len <= 0 || s.length == 0) { return new String(""); } return new String(s.substr(0, len)); } function replaceSuffix(s, os, ns) { return prefix(s, s.indexOf(os)).concat(ns); } function startsWith(s, prefix) { return (s != null) && (s.indexOf(prefix) == 0); } function endsWith(s, suffix) { var i = s.lastIndexOf(suffix); return (i != -1) && (i == (s.length - suffix.length)); } function defined(s) { return (s != null) && (s != "null") && (s.length > 0); } function contains(array, prop) { for (var i = 0; i < array.length; i++) { var s1 = new String(array[i]); var s2 = new String(prop); if( s1.toLowerCase() == s2.toLowerCase() ) { return true; } } return false; } var S = new String(java.io.File.separator); var JFXPAR = "javafx.param"; var JFXMAN = "javafx.manifest.entry"; var JFXPARN = "name"; var JFXPARV = "value"; var JFXPARH = "hidden"; var JFXLAZY = "download.mode.lazy.jar"; var withpreloader = new String(project.getProperty("app-with-preloader")); var fx_ant_api_1_1 = new String(project.getProperty("have-fx-ant-api-1.1")); var fx_ant_api_1_2 = new String(project.getProperty("have-fx-ant-api-1.2")); var fx_in_swing_app = new String(project.getProperty("fx-in-swing-app")); // get jars with lazy download mode property set function getLazyJars() { var jars = new Array(); var keys = project.getProperties().keys(); while(keys.hasMoreElements()) { var pn = new String(keys.nextElement()); if(startsWith(pn, JFXLAZY)) { var fname = new String(pn.substring(JFXLAZY.length+1)); jars.push(fname); } } return jars.length > 0 ? jars : null; } // set download mode of dependent libraries function setDownloadMode(fsEager, fsLazy, jars) { for(var i = 0; i < jars.length; i++) { fsEager.setExcludes("lib" + S + jars[i]); fsLazy.setIncludes("lib" + S + jars[i]); } } // fx:jar var jar = project.createTask("fx_jar"); jar.setProject(project); var destfile = new String(project.getProperty("pp_jar_destfile")); jar.setDestfile(destfile); // fx:application var app = jar.createApplication(); app.setProject(project); var title = new String(project.getProperty("application.title")); var mainclass; if(isTrue(fx_in_swing_app) && isTrue(fx_ant_api_1_2)) { mainclass = new String(project.getProperty("main.class")); app.setToolkit("swing"); } else { mainclass = new String(project.getProperty("javafx.main.class")); } var fallback = new String(project.getProperty("javafx.fallback.class")); app.setName(title); app.setMainClass(mainclass); app.setFallbackClass(fallback); if(isTrue(withpreloader)) { preloaderclass = new String(project.getProperty("javafx.preloader.class")); app.setPreloaderClass(preloaderclass); } var appversion = new String(project.getProperty("javafx.application.implementation.version")); if(defined(appversion)) { app.setVersion(appversion); } else { app.setVersion("1.0"); } // fx:param, fx:argument var searchHides = project.getProperties().keys(); var hides = new Array(); while(searchHides.hasMoreElements()) { // collect all hidden property names var pns = new String(searchHides.nextElement()); if(startsWith(pns, JFXPAR) && endsWith(pns, JFXPARN)) { var propns = new String(project.getProperty(pns)); var phs = replaceSuffix(pns, JFXPARN, JFXPARH); var proph = new String(project.getProperty(phs)); if(isTrue(proph)) { hides.push(propns); } } } var keys = project.getProperties().keys(); while(keys.hasMoreElements()) { var pn = new String(keys.nextElement()); if(startsWith(pn, JFXPAR) && endsWith(pn, JFXPARN)) { var propn = new String(project.getProperty(pn)); if(defined(propn) && !contains(hides, propn)) { var pv = replaceSuffix(pn, JFXPARN, JFXPARV); var propv = new String(project.getProperty(pv)); if(defined(propv)) { var par = app.createParam(); par.setName(propn); par.setValue(propv); } else { if(isTrue(fx_ant_api_1_1)) { var arg = app.createArgument(); arg.addText(propn); } else { print("Warning: Unnamed parameters not supported by this version of JavaFX SDK deployment Ant tasks. Upgrade JavaFX to 2.0.2 or higher."); } } } } } // fx:resources var res = jar.createResources(); res.setProject(project); var pdir = new String(project.getProperty("pp_jar_dir")); if(isTrue(withpreloader)) { var f1 = res.createFileSet(); f1.setProject(project); f1.setDir(new java.io.File(pdir)); var i1 = new String(project.getProperty("pp_jar_fs1")); f1.setIncludes(i1); f1.setRequiredFor("preloader"); var f2 = res.createFileSet(); f2.setProject(project); f2.setDir(new java.io.File(pdir)); var i2a = new String(project.getProperty("jfx.deployment.jar")); var i2b = new String(project.getProperty("pp_jar_fs2")); var e2c = new String(project.getProperty("pp_jar_fs1")); f2.setIncludes(i2a); f2.setIncludes(i2b); f2.setExcludes(e2c); f2.setRequiredFor("startup"); var lazyjars = getLazyJars(); if(lazyjars != null) { var f3 = res.createFileSet(); f3.setProject(project); f3.setDir(new java.io.File(pdir)); f3.setRequiredFor("runtime"); setDownloadMode(f2,f3,lazyjars); } } else { var fn = res.createFileSet(); fn.setProject(project); fn.setDir(new java.io.File(pdir)); var ia = new String(project.getProperty("jfx.deployment.jar")); var ib = new String(project.getProperty("pp_jar_fs2")); fn.setIncludes(ia); fn.setIncludes(ib); fn.setRequiredFor("startup"); var lazyjars = getLazyJars(); if(lazyjars != null) { var fn2 = res.createFileSet(); fn2.setProject(project); fn2.setDir(new java.io.File(pdir)); fn2.setRequiredFor("runtime"); setDownloadMode(fn,fn2,lazyjars); } } // fileset to exclude *.css or *.bss var fs = jar.createFileSet(); fs.setProject(project); var buildcls = new String(project.getProperty("pp_jar_buildclasses")); var exc = new String(project.getProperty("pp_jar_cssbss")); fs.setDir(new java.io.File(buildcls)); fs.setExcludes(exc); // manifest var man = jar.createManifest(); var a1val = new String(project.getProperty("application.vendor")); var a1 = new org.apache.tools.ant.taskdefs.Manifest.Attribute(); a1.setName("Implementation-Vendor"); a1.setValue(a1val); man.addConfiguredAttribute(a1); var a2val = new String(project.getProperty("application.title")); var a2 = new org.apache.tools.ant.taskdefs.Manifest.Attribute(); a2.setName("Implementation-Title"); a2.setValue(a2val); man.addConfiguredAttribute(a2); if(defined(appversion)) { var a3 = new org.apache.tools.ant.taskdefs.Manifest.Attribute(); a3.setName("Implementation-Version"); a3.setValue(appversion); man.addConfiguredAttribute(a3); } var a4prop = new String(project.getProperty("javafx.deploy.disable.proxy")); if(isTrue(a4prop)) { var a4 = new org.apache.tools.ant.taskdefs.Manifest.Attribute(); a4.setName("JavaFX-Feature-Proxy"); a4.setValue("None"); man.addConfiguredAttribute(a4); } // custom manifest entries var searchManifestHides = project.getProperties().keys(); var manifestHides = new Array(); while(searchManifestHides.hasMoreElements()) { // collect all hidden property names var pns = new String(searchManifestHides.nextElement()); if(startsWith(pns, JFXMAN) && endsWith(pns, JFXPARN)) { var propns = new String(project.getProperty(pns)); var phs = replaceSuffix(pns, JFXPARN, JFXPARH); var proph = new String(project.getProperty(phs)); if(isTrue(proph)) { manifestHides.push(propns); } } } var manifestKeys = project.getProperties().keys(); while(manifestKeys.hasMoreElements()) { var pn = new String(manifestKeys.nextElement()); if(startsWith(pn, JFXMAN) && endsWith(pn, JFXPARN)) { var propn = new String(project.getProperty(pn)); if(defined(propn) && !contains(manifestHides, propn)) { var propnr = propn.replace(/\s/g, "-"); var entry = new org.apache.tools.ant.taskdefs.Manifest.Attribute(); entry.setName(propnr); var pv = replaceSuffix(pn, JFXPARN, JFXPARV); var propv = new String(project.getProperty(pv)); if(defined(propv)) { entry.setValue(propv); } else { entry.setValue(""); } man.addConfiguredAttribute(entry); } } } var profileAvailable = new String(project.getProperty("profile.available")); if (defined(profileAvailable)) { var profileAttribute = new org.apache.tools.ant.taskdefs.Manifest.Attribute(); profileAttribute.setName("Profile"); profileAttribute.setValue(new String(project.getProperty("javac.profile"))); man.addConfiguredAttribute(profileAttribute); } var perm_elev = new String(project.getProperty("permissions.elevated")); var cust_perm = new String(project.getProperty("manifest.custom.permissions")); var cust_cb = new String(project.getProperty("manifest.custom.codebase")); var sa1 = new org.apache.tools.ant.taskdefs.Manifest.Attribute(); sa1.setName("Codebase"); if(!defined(cust_cb) || cust_cb == "*") { sa1.setValue("*"); print("Warning: From JDK7u25 the Codebase manifest attribute should be used to restrict JAR repurposing."); print(" Please set manifest.custom.codebase property to override the current default non-secure value '*'."); } else { sa1.setValue(cust_cb); } man.addConfiguredAttribute(sa1); var sa2 = new org.apache.tools.ant.taskdefs.Manifest.Attribute(); sa2.setName("Permissions"); if(!defined(cust_perm)) { if(isTrue(perm_elev)) { sa2.setValue("all-permissions"); } else { sa2.setValue("sandbox"); } } else { if(cust_perm == "all-permissions") { sa2.setValue("all-permissions"); } else { sa2.setValue("sandbox"); } } man.addConfiguredAttribute(sa2); // Note: see JavaFX Jira issue #RT-25003 if attribute names are created lowercase in manifest jar.perform(); function isTrue(prop) { return prop != null && (prop.toLowerCase()=="true" || prop.toLowerCase()=="yes" || prop.toLowerCase()=="on"); } function prefix(s, len) { if(s == null || len <= 0 || s.length == 0) { return new String(""); } return new String(s.substr(0, len)); } function replaceSuffix(s, os, ns) { return prefix(s, s.indexOf(os)).concat(ns); } function startsWith(s, prefix) { return (s != null) && (s.indexOf(prefix) == 0); } function endsWith(s, suffix) { var i = s.lastIndexOf(suffix); return (i != -1) && (i == (s.length - suffix.length)); } function defined(s) { return (s != null) && (s != "null") && (s.length > 0); } function contains(array, prop) { for (var i = 0; i < array.length; i++) { var s1 = new String(array[i]); var s2 = new String(prop); if( s1.toLowerCase() == s2.toLowerCase() ) { return true; } } return false; } var S = java.io.File.separator; var JFXPAR = "javafx.param"; var JFXPARN = "name"; var JFXPARV = "value"; var JFXPARH = "hidden"; var JFXCALLB = "javafx.jscallback"; var JFXLAZY = "download.mode.lazy.jar"; var withpreloader = new String(project.getProperty("app-with-preloader")); var fx_ant_api_1_1 = new String(project.getProperty("have-fx-ant-api-1.1")); var fx_ant_api_1_2 = new String(project.getProperty("have-fx-ant-api-1.2")); var have_jdk_pre7u14 = new String(project.getProperty("have-jdk-pre7u14")); var fx_in_swing_app = new String(project.getProperty("fx-in-swing-app")); var debug_in_browser = new String(project.getProperty("project.state.debugging.in.browser")); // get jars with lazy download mode property set function getLazyJars() { var jars = new Array(); var keys = project.getProperties().keys(); while(keys.hasMoreElements()) { var pn = new String(keys.nextElement()); if(startsWith(pn, JFXLAZY)) { var fname = pn.substring(JFXLAZY.length+1); jars.push(fname); } } return jars.length > 0 ? jars : null; } // set download mode of dependent libraries function setDownloadMode(fsEager, fsLazy, jars) { for(var i = 0; i < jars.length; i++) { fsEager.setExcludes("lib" + S + jars[i]); fsLazy.setIncludes("lib" + S + jars[i]); } } // convert path to absolute if relative function derelativizePath(path) { var f = new java.io.File(path); if(!f.exists()) { f = new java.io.File(new String(project.getBaseDir()) + S + path); } if(f.exists()) { try { return f.getCanonicalPath(); } catch(err) { return path; } } return path; } // fx:deploy var deploy = project.createTask("fx_deploy"); deploy.setProject(project); var width = new String(project.getProperty("javafx.width")); var height = new String(project.getProperty("javafx.height")); var outdir = new String(project.getProperty("jfx.deployment.dir")); var embedJNLP = new String(project.getProperty("javafx.deploy.embedJNLP")); var updatemode = new String(project.getProperty("update-mode")); var outfile = new String(project.getProperty("application.title")); var includeDT = new String(project.getProperty("javafx.deploy.includeDT")); var offline = new String(project.getProperty("javafx.deploy.allowoffline")); deploy.setWidth(width); deploy.setHeight(height); deploy.setOutdir(outdir); deploy.setEmbedJNLP(isTrue(embedJNLP)); deploy.setUpdateMode(updatemode); deploy.setOutfile(outfile); deploy.setIncludeDT(isTrue(includeDT)); if(defined(offline)) { if(isTrue(fx_ant_api_1_1)) { deploy.setOfflineAllowed(isTrue(offline)); } else { print("Warning: offlineAllowed not supported by this version of JavaFX SDK deployment Ant task. Please upgrade JavaFX to 2.0.2 or higher."); } } // native packaging (time consuming, thus applied in explicit build only) var nativeEnabled = new String(project.getProperty("do.build.native.package")); var nativeType = new String(project.getProperty("javafx.native.bundling.type")); var projStateRun = new String(project.getProperty("project.state.running")); var projStateDbg = new String(project.getProperty("project.state.debugging")); var projStatePrf = new String(project.getProperty("project.state.profiling")); if(isTrue(nativeEnabled) && defined(nativeType) && nativeType != "none") { if(!isTrue(projStateRun) && !isTrue(projStateDbg) && !isTrue(projStatePrf)) { if(isTrue(fx_ant_api_1_2)) { deploy.setNativeBundles(nativeType); print("Note: To create native bundles the <fx:deploy> task may require external tools. See JavaFX 2.2+ documentation for details."); print(""); print("Launching <fx:deploy> in native packager mode..."); } else { print("Warning: Native packaging is not supported by this version of JavaFX SDK deployment Ant task. Please upgrade to JDK 7u6 or higher."); } } } // fx:application var app = deploy.createApplication(); app.setProject(project); var title = new String(project.getProperty("application.title")); var mainclass; if(isTrue(fx_in_swing_app) && isTrue(fx_ant_api_1_2)) { mainclass = new String(project.getProperty("main.class")); app.setToolkit("swing"); } else { mainclass = new String(project.getProperty("javafx.main.class")); } var fallback = new String(project.getProperty("javafx.fallback.class")); app.setName(title); app.setMainClass(mainclass); app.setFallbackClass(fallback); if(isTrue(withpreloader)) { preloaderclass = new String(project.getProperty("javafx.preloader.class")); app.setPreloaderClass(preloaderclass); } var appversion = new String(project.getProperty("javafx.application.implementation.version")); if(defined(appversion)) { app.setVersion(appversion); } else { app.setVersion("1.0"); } // fx:param, fx:argument var searchHides = project.getProperties().keys(); var hides = new Array(); while(searchHides.hasMoreElements()) { // collect all hidden property names var pns = new String(searchHides.nextElement()); if(startsWith(pns, JFXPAR) && endsWith(pns, JFXPARN)) { var propns = new String(project.getProperty(pns)); var phs = replaceSuffix(pns, JFXPARN, JFXPARH); var proph = new String(project.getProperty(phs)); if(isTrue(proph)) { hides.push(propns); } } } var keys = project.getProperties().keys(); while(keys.hasMoreElements()) { var pn = new String(keys.nextElement()); if(startsWith(pn, JFXPAR) && endsWith(pn, JFXPARN)) { var propn = new String(project.getProperty(pn)); if(defined(propn) && !contains(hides, propn)) { var pv = replaceSuffix(pn, JFXPARN, JFXPARV); var propv = new String(project.getProperty(pv)); if(defined(propv)) { var par = app.createParam(); par.setName(propn); par.setValue(propv); } else { if(isTrue(fx_ant_api_1_1)) { var arg = app.createArgument(); arg.addText(propn); } else { print("Warning: Unnamed parameters not supported by this version of JavaFX SDK deployment Ant tasks. Upgrade JavaFX to 2.0.2 or higher."); } } } } } // fx:resources var res = deploy.createResources(); res.setProject(project); var deploydir = new String(project.getProperty("pp_deploy_dir")); if(isTrue(withpreloader)) { var f1 = res.createFileSet(); f1.setProject(project); f1.setDir(new java.io.File(deploydir)); var i1 = new String(project.getProperty("pp_deploy_fs1")); f1.setIncludes(i1); f1.setRequiredFor("preloader"); var f2 = res.createFileSet(); f2.setProject(project); f2.setDir(new java.io.File(deploydir)); var i2a = new String(project.getProperty("jfx.deployment.jar")); var i2b = new String(project.getProperty("pp_deploy_fs2")); var e2c = new String(project.getProperty("pp_deploy_fs1")); f2.setIncludes(i2a); f2.setIncludes(i2b); f2.setExcludes(e2c); f2.setRequiredFor("startup"); var lazyjars = getLazyJars(); if(lazyjars != null) { var f3 = res.createFileSet(); f3.setProject(project); f3.setDir(new java.io.File(deploydir)); f3.setRequiredFor("runtime"); setDownloadMode(f2,f3,lazyjars); } } else { var fn = res.createFileSet(); fn.setProject(project); fn.setDir(new java.io.File(deploydir)); var ia = new String(project.getProperty("jfx.deployment.jar")); var ib = new String(project.getProperty("pp_deploy_fs2")); fn.setIncludes(ia); fn.setIncludes(ib); fn.setRequiredFor("startup"); var lazyjars = getLazyJars(); if(lazyjars != null) { var fn2 = res.createFileSet(); fn2.setProject(project); fn2.setDir(new java.io.File(deploydir)); fn2.setRequiredFor("runtime"); setDownloadMode(fn,fn2,lazyjars); } } // fx:info var info = deploy.createInfo(); info.setProject(project); var vendor = new String(project.getProperty("application.vendor")); var description = new String(project.getProperty("application.desc")); info.setTitle(title); // title known from before info.setVendor(vendor); info.setDescription(description); var splash = new String(project.getProperty("javafx.deploy.splash")); if(defined(splash)) { if(isTrue(fx_ant_api_1_1)) { var sicon = info.createSplash(); sicon.setHref(splash); sicon.setMode("any"); print("Adding splash image reference: " + splash); } else { print("Warning: Splash Image not supported by this version of JavaFX SDK deployment Ant task. Please upgrade JavaFX to 2.0.2 or higher."); } } if(isTrue(nativeEnabled) && defined(nativeType) && nativeType != "none") { var icon = new String(project.getProperty("javafx.deploy.icon.native")); if(defined(icon)) { if(isTrue(fx_ant_api_1_2) && !isTrue(have_jdk_pre7u14)) { var dicon = derelativizePath(icon); // create temporary icon copy renamed to application name (required by native packager) var baseDir = new String(project.getProperty("basedir")); var buildDir = new String(project.getProperty("build.dir")); var deployBase = new String(project.getProperty("jfx.deployment.base")); var copyTask = project.createTask("copy"); var source = new java.io.File(dicon); var sourceName = new String(source.getName()); var lastDot = sourceName.lastIndexOf("."); var sourceExt; if(lastDot >=0) { sourceExt = sourceName.substr(lastDot); } else { sourceExt = new String(""); } var target = new java.io.File(baseDir.concat(S).concat(buildDir).concat(S).concat("icon").concat(S).concat(deployBase).concat(sourceExt)); copyTask.setFile(source); copyTask.setTofile(target); copyTask.setFlatten(true); copyTask.setFailOnError(false); copyTask.perform(); var tempicon; if(target.exists()) { try { tempicon = target.getCanonicalPath(); } catch(err) { tempicon = dicon; } } else { tempicon = dicon; } var nicon = info.createIcon(); nicon.setHref(tempicon); print("Source native icon reference: " + dicon); print("Processed native icon reference: " + tempicon); } else { print("Warning: Native Package icon not supported by this version of JavaFX SDK deployment Ant task. Please upgrade to JDK7u14."); } } } else { var icon = new String(project.getProperty("javafx.deploy.icon")); if(defined(icon)) { if(isTrue(fx_ant_api_1_1)) { var iicon = info.createIcon(); iicon.setHref(icon); print("Adding WebStart icon reference: " + icon); } else { print("Warning: WebStart Icon not supported by this version of JavaFX SDK deployment Ant task. Please upgrade JavaFX to 2.0.2 or higher."); } } } // fx:permissions var perm = deploy.createPermissions(); perm.setProject(project); var elev = new String(project.getProperty("permissions.elevated")); perm.setElevated(isTrue(elev)); // fx:preferences var pref = deploy.createPreferences(); pref.setProject(project); var scut = new String(project.getProperty("javafx.deploy.adddesktopshortcut")); var instp = new String(project.getProperty("javafx.deploy.installpermanently")); var smenu = new String(project.getProperty("javafx.deploy.addstartmenushortcut")); pref.setShortcut(isTrue(scut)); pref.setInstall(isTrue(instp)); pref.setMenu(isTrue(smenu)); // fx:template var templ = new String(project.getProperty("javafx.run.htmltemplate")); var templp = new String(project.getProperty("javafx.run.htmltemplate.processed")); if(defined(templ) && defined(templp)) { var temp = deploy.createTemplate(); temp.setProject(project); temp.setFile(new java.io.File(templ)); temp.setTofile(new java.io.File(templp)); } // fx:platform var plat = deploy.createPlatform(); plat.setProject(project); var requestRT = new String(project.getProperty("javafx.deploy.request.runtime")); if(defined(requestRT)) { plat.setJavafx(requestRT); } var jvmargs = new String(project.getProperty("run.jvmargs")); if(defined(jvmargs)) { var jvmargss = jvmargs.split(" "); for(var i = 0; i < jvmargss.length; i++) { if(defined(jvmargss[i])) { var vmarg = plat.createJvmarg(); vmarg.setValue(jvmargss[i]); } } } if(isTrue(debug_in_browser)) { var vmarg = plat.createJvmarg(); vmarg.setValue(new String("-ea:javafx.browserdebug")); } if(isTrue(nativeEnabled) && defined(nativeType) && nativeType != "none") { if(!isTrue(projStateRun) && !isTrue(projStateDbg) && !isTrue(projStatePrf)) { if(plat.setBasedir) { var sdkdir = new String(project.getProperty("javafx.sdk")); if(defined(sdkdir)) { plat.setBasedir(sdkdir); } } else { print("Note: the current version of native packager Ant task can bundle the default JRE only."); } } } // fx:callbacks var callbs = deploy.createCallbacks(); callbs.setProject(project); var keys = project.getProperties().keys(); while(keys.hasMoreElements()) { var pn = new String(keys.nextElement()); if(startsWith(pn, JFXCALLB)) { var prop = new String(project.getProperty(pn)); if(defined(prop)) { var cname = pn.substring(JFXCALLB.length+1); var cb = callbs.createCallback(); cb.setProject(project); cb.setName(cname); cb.addText(prop); } } } deploy.perform(); function prefix(s, len) { if(s == null || len <= 0 || s.length == 0) { return new String(""); } return new String(s.substr(0, len)); } function replaceSuffix(s, os, ns) { return prefix(s, s.indexOf(os)).concat(ns); } function startsWith(s, prefix) { return (s != null) && (s.indexOf(prefix) == 0); } function endsWith(s, suffix) { var i = s.lastIndexOf(suffix); return (i != -1) && (i == (s.length - suffix.length)); } function defined(s) { return (s != null) && (s != "null") && (s.length > 0); } var JFXPAR = "javafx.param"; var JFXPARN = "name"; var JFXPARV = "value"; var params = new java.lang.StringBuilder(); var args = new java.lang.StringBuilder(); var keys = project.getProperties().keys(); while(keys.hasMoreElements()) { var pn = new String(keys.nextElement()); if(startsWith(pn, JFXPAR) && endsWith(pn, JFXPARN)) { var propn = new String(project.getProperty(pn)); if(defined(propn)) { var pv = replaceSuffix(pn, JFXPARN, JFXPARV); var propv = new String(project.getProperty(pv)); if(defined(propv)) { params.append("\n <param name=\""); params.append(propn); params.append("\" value=\""); params.append(propv); params.append("\"/>"); args.append("\n <argument>"); args.append(propn); args.append("="); args.append(propv); args.append("</argument>"); } else { params.append("\n <param name=\""); params.append(propn); params.append("\" value=\"\"/>"); args.append("\n <argument>"); args.append(propn); args.append("</argument>"); } } } } project.setProperty("applet-params-token", new String(params.toString())); project.setProperty("application-args-token", new String(args.toString())); function startsWith(s, prefix) { return (s != null) && (s.indexOf(prefix) == 0); } function defined(s) { return (s != null) && (s != "null") && (s.length > 0); } var PREF = "file:"; var doCopyIcon = new String(project.getProperty("local-icon-filename-available")); if(defined(doCopyIcon)) { var iconProp = new String(project.getProperty("javafx.deploy.icon")); if(startsWith(iconProp, PREF)) { iconProp = iconProp.slice(PREF.length); } while(iconProp.charAt(0) == "/") { iconProp = iconProp.slice(1); } var S = java.io.File.separator; var baseDir = new String(project.getProperty("basedir")); var distDir = new String(project.getProperty("dist.dir")); var copyTask = new String(project.createTask("copy")); var source = new java.io.File(iconProp); var target = new java.io.File(baseDir.concat(S).concat(distDir)); copyTask.setFile(source); copyTask.setTodir(target); copyTask.setFlatten(true); copyTask.setFailOnError(false); copyTask.perform(); } var doCopyHTMLFrom = new String(project.getProperty("html-template-available")); var doCopyHTMLTo = new String(project.getProperty("html-template-processed-available")); if(defined(doCopyHTMLFrom) && defined(doCopyHTMLTo)) { var htmlFrom = new String(project.getProperty("javafx.run.htmltemplate")); if(startsWith(htmlFrom, PREF)) { htmlFrom = htmlFrom.slice(PREF.length); } while(startsWith(htmlFrom, "/")) { htmlFrom = htmlFrom.slice(1); } var htmlTo = new String(project.getProperty("javafx.run.htmltemplate.processed")); if(startsWith(htmlTo, PREF)) { htmlTo = htmlTo.slice(PREF.length); } while(startsWith(htmlTo, "/")) { htmlTo = htmlTo.slice(1); } var copyTask = project.createTask("copy"); var source = new java.io.File(htmlFrom); var target = new java.io.File(htmlTo); copyTask.setFile(source); copyTask.setTofile(target); copyTask.setFailOnError(false); copyTask.perform(); }
ColorfulCircles/nbproject/jfx-impl_backup.xml
JavaFX-specific Ant calls ${cssfileslist} var pathConvert = project.createTask("pathconvert"); pathConvert.setProperty("run.and.lib.classpath"); var classPath = project.getProperty("run.classpath.without.build.classes.and.dist.dir"); var fileSeparator = project.getProperty("file.separator"); if(classPath != null) { var classPathCopy = pathConvert.createPath(); classPathCopy.setPath(classPath); if(classPath.indexOf(";") != -1) { var pathArray = classPath.split(";"); } else { var pathArray = classPath.split(":"); } var added = ""; for (var i=0; i<pathArray.length; i++) { var index = pathArray[i].lastIndexOf(fileSeparator); if (index >=0) { var onePath = pathArray[i].substr(0,index+1) + "lib"; var oneDir = new java.io.File(onePath); if(oneDir.exists()) { var fs = project.createDataType("fileset"); fs.setDir( oneDir ); fs.setIncludes("*.jar"); var ds = fs.getDirectoryScanner(project); var srcFiles = ds.getIncludedFiles(); for (j=0; j<srcFiles.length; j++) { if(classPath.indexOf(srcFiles[j]) == -1 && added.indexOf(srcFiles[j]) == -1) { var path = pathConvert.createPath(); path.setPath(onePath + fileSeparator + srcFiles[j]); added += srcFiles[j]; } } } } } } pathConvert.perform(); var UTF_8 = "UTF-8"; var ATTR_CLASS_PATH = "Class-Path"; var ATTR_CLASS_PATH_FX = "JavaFX-Class-Path"; function isSigned(manifest) { var sections = manifest.getSectionNames(); while(sections.hasMoreElements()) { var sectionname = sections.nextElement(); var section = manifest.getSection(sectionname); if(section != null) { var sectionKeys = section.getAttributeKeys(); while (sectionKeys.hasMoreElements()) { var element = sectionKeys.nextElement(); if (element.endsWith("-Digest") || element.endsWith("-digest")) { return true; } } } } return false; } var src = project.getProperty("manifest.file.temp"); var srf = new java.io.File(src); try { var fis = new java.io.FileInputStream(srf); try { var isr = new java.io.InputStreamReader(fis, UTF_8); try { var manifest = new org.apache.tools.ant.taskdefs.Manifest(isr); } finally { isr.close(); } } finally { fis.close(); } } catch(e) { var manifest = null; } if(manifest != null) { if(isSigned(manifest)) { println("Warning: Signed JAR can not be rebased."); } else { var mainSection = manifest.getMainSection(); var classPath = mainSection.getAttributeValue(ATTR_CLASS_PATH); if (classPath != null) { var classPathAttr = ATTR_CLASS_PATH; } else { classPath = mainSection.getAttributeValue(ATTR_CLASS_PATH_FX); if(classPath != null) { var classPathAttr = ATTR_CLASS_PATH_FX; } } if(classPath != null) { var result = new java.lang.StringBuilder(); var changed = false; var pathArray = classPath.split(" "); for (var i=0; i<pathArray.length; i++) { if (result.length() > 0) { result.append(' '); } var index = pathArray[i].lastIndexOf('/'); if (index >=0 && index < pathArray[i].length()-1) { pathArray[i] = pathArray[i].substring(index+1); changed = true; } result.append(pathArray[i]); } mainSection.removeAttribute(classPathAttr); mainSection.addAttributeAndCheck(new org.apache.tools.ant.taskdefs.Manifest.Attribute(classPathAttr, result.toString())); var tgt = project.getProperty("manifest.file.temp.new"); var tgf = new java.io.File(tgt); try { var fos = new java.io.FileOutputStream(tgf); try { var osw = new java.io.OutputStreamWriter(fos, UTF_8); try { var manifestOut = new java.io.PrintWriter(osw); manifest.write(manifestOut); manifestOut.close(); } finally { osw.close(); } } finally { fos.close(); } } catch(e) { println("Warning: problem storing rebased manifest file."); } } } } var dir = project.getProperty("pp_rebase_dir"); var fDir = new java.io.File(dir); if( fDir.exists() ) { var callTask = project.createTask("antcall"); callTask.setTarget("-rebase-libs-macro-call"); var param = callTask.createParam(); param.setName("jar.file.to.rebase"); var includes = project.getProperty("pp_rebase_fs"); var fs = project.createDataType("fileset"); fs.setDir( fDir ); fs.setIncludes(includes); var ds = fs.getDirectoryScanner(project); var srcFiles = ds.getIncludedFiles(); for (i=0; i<srcFiles.length; i++) { param.setValue(dir + "${file.separator}" + srcFiles[i]); callTask.perform(); } } var S = java.io.File.separator; var JFXPAR = "javafx.param"; var JFXPARN = "name"; var JFXPARV = "value"; var JFXLAZY = "download.mode.lazy.jar"; var withpreloader = project.getProperty("app-with-preloader"); var fx_ant_api_1_1 = project.getProperty("have-fx-ant-api-1.1"); // get jars with lazy download mode property set function getLazyJars() { var jars = new Array(); var keys = project.getProperties().keys(); while(keys.hasMoreElements()) { var pn = keys.nextElement(); if(pn.substr(0,JFXLAZY.length) == JFXLAZY) { var fname = pn.substring(JFXLAZY.length+1); jars.push(fname); } } return jars.length > 0 ? jars : null; } // set download mode of dependent libraries function setDownloadMode(fsEager, fsLazy, jars) { for(i = 0; i < jars.length; i++) { fsEager.setExcludes("lib" + S + jars[i]); fsLazy.setIncludes("lib" + S + jars[i]); } } // fx:jar var jar = project.createTask("fx_jar"); jar.setProject(project); var destfile = project.getProperty("pp_jar_destfile"); jar.setDestfile(destfile); // fx:application var app = jar.createApplication(); app.setProject(project); var title = project.getProperty("application.title"); var mainclass = project.getProperty("javafx.main.class"); var fallback = project.getProperty("javafx.fallback.class"); app.setName(title); app.setMainClass(mainclass); app.setFallbackClass(fallback); if(withpreloader == "true") { preloaderclass = project.getProperty("javafx.preloader.class"); app.setPreloaderClass(preloaderclass); } // fx:param, fx:argument var keys = project.getProperties().keys(); while(keys.hasMoreElements()) { var pn = keys.nextElement(); if(pn.substr(0,JFXPAR.length) == JFXPAR && pn.indexOf(JFXPARN) == (pn.length()-JFXPARN.length)) { var propn = project.getProperty(pn); if(propn != null && propn.length() > 0) { var pv = pn.substr(0,pn.indexOf(JFXPARN)) + JFXPARV; var propv = project.getProperty(pv); if(propv != null && propv.length() > 0) { var par = app.createParam(); par.setName(propn); par.setValue(propv); } else { if(fx_ant_api_1_1 == "true") { var arg = app.createArgument(); arg.addText(propn); } } } } } // fx:resources var res = jar.createResources(); res.setProject(project); var pdir = project.getProperty("pp_jar_dir"); if(withpreloader == "true") { var f1 = res.createFileSet(); f1.setProject(project); f1.setDir(new java.io.File(pdir)); var i1 = project.getProperty("pp_jar_fs1"); f1.setIncludes(i1); f1.setRequiredFor("preloader"); var f2 = res.createFileSet(); f2.setProject(project); f2.setDir(new java.io.File(pdir)); var i2a = project.getProperty("jfx.deployment.jar"); var i2b = project.getProperty("pp_jar_fs2"); var e2c = project.getProperty("pp_jar_fs1"); f2.setIncludes(i2a); f2.setIncludes(i2b); f2.setExcludes(e2c); f2.setRequiredFor("startup"); var lazyjars = getLazyJars(); if(lazyjars != null) { var f3 = res.createFileSet(); f3.setProject(project); f3.setDir(new java.io.File(pdir)); f3.setRequiredFor("runtime"); setDownloadMode(f2,f3,lazyjars); } } else { var fn = res.createFileSet(); fn.setProject(project); fn.setDir(new java.io.File(pdir)); var ia = project.getProperty("jfx.deployment.jar"); var ib = project.getProperty("pp_jar_fs2"); fn.setIncludes(ia); fn.setIncludes(ib); fn.setRequiredFor("startup"); var lazyjars = getLazyJars(); if(lazyjars != null) { var fn2 = res.createFileSet(); fn2.setProject(project); fn2.setDir(new java.io.File(pdir)); fn2.setRequiredFor("runtime"); setDownloadMode(fn,fn2,lazyjars); } } // fileset to exclude *.css or *.bss var fs = jar.createFileSet(); fs.setProject(project); var buildcls = project.getProperty("pp_jar_buildclasses"); var exc = project.getProperty("pp_jar_cssbss"); fs.setDir(new java.io.File(buildcls)); fs.setExcludes(exc); // manifest var man = jar.createManifest(); var a1val = project.getProperty("application.vendor"); var a1 = new org.apache.tools.ant.taskdefs.Manifest.Attribute(); a1.setName("Implementation-Vendor"); a1.setValue(a1val); man.addConfiguredAttribute(a1); var a2val = project.getProperty("application.title"); var a2 = new org.apache.tools.ant.taskdefs.Manifest.Attribute(); a2.setName("Implementation-Title"); a2.setValue(a2val); man.addConfiguredAttribute(a2); var a3 = new org.apache.tools.ant.taskdefs.Manifest.Attribute(); a3.setName("Implementation-Version"); a3.setValue("1.0"); man.addConfiguredAttribute(a3); jar.perform(); function isTrue(prop) { return prop != null && (prop.toLowerCase()=="true" || prop.toLowerCase()=="yes" || prop.toLowerCase()=="on"); } var S = java.io.File.separator; var JFXPAR = "javafx.param"; var JFXPARN = "name"; var JFXPARV = "value"; var JFXCALLB = "javafx.jscallback"; var JFXLAZY = "download.mode.lazy.jar"; var withpreloader = project.getProperty("app-with-preloader"); var fx_ant_api_1_1 = project.getProperty("have-fx-ant-api-1.1"); // get jars with lazy download mode property set function getLazyJars() { var jars = new Array(); var keys = project.getProperties().keys(); while(keys.hasMoreElements()) { var pn = keys.nextElement(); if(pn.substr(0,JFXLAZY.length) == JFXLAZY) { var fname = pn.substring(JFXLAZY.length+1); jars.push(fname); } } return jars.length > 0 ? jars : null; } // set download mode of dependent libraries function setDownloadMode(fsEager, fsLazy, jars) { for(i = 0; i < jars.length; i++) { fsEager.setExcludes("lib" + S + jars[i]); fsLazy.setIncludes("lib" + S + jars[i]); } } // fx:deploy var deploy = project.createTask("fx_deploy"); deploy.setProject(project); var width = project.getProperty("javafx.width"); var height = project.getProperty("javafx.height"); var outdir = project.getProperty("jfx.deployment.dir"); var embedJNLP = project.getProperty("javafx.deploy.embedJNLP"); var updatemode = project.getProperty("update-mode"); var outfile = project.getProperty("application.title"); var includeDT = project.getProperty("javafx.deploy.includeDT"); var offline = project.getProperty("javafx.deploy.allowoffline"); deploy.setWidth(width); deploy.setHeight(height); deploy.setOutdir(outdir); deploy.setEmbedJNLP(isTrue(embedJNLP)); deploy.setUpdateMode(updatemode); deploy.setOutfile(outfile); deploy.setIncludeDT(isTrue(includeDT)); if(offline != null) { if(fx_ant_api_1_1 == "true") { deploy.setOfflineAllowed(isTrue(offline)); } else { println("Warning: offlineAllowed not supported by this version of JavaFX SDK deployment Ant task. Please upgrade JavaFX to 2.0.2 or higher."); } } // fx:application var app = deploy.createApplication(); app.setProject(project); var title = project.getProperty("application.title"); var mainclass = project.getProperty("javafx.main.class"); var fallback = project.getProperty("javafx.fallback.class"); app.setName(title); app.setMainClass(mainclass); app.setFallbackClass(fallback); if(withpreloader == "true") { preloaderclass = project.getProperty("javafx.preloader.class"); app.setPreloaderClass(preloaderclass); } // fx:param, fx:argument var keys = project.getProperties().keys(); while(keys.hasMoreElements()) { var pn = keys.nextElement(); if(pn.substr(0,JFXPAR.length) == JFXPAR && pn.indexOf(JFXPARN) == (pn.length()-JFXPARN.length)) { var propn = project.getProperty(pn); if(propn != null && propn.length() > 0) { var pv = pn.substr(0,pn.indexOf(JFXPARN)) + JFXPARV; var propv = project.getProperty(pv); if(propv != null && propv.length() > 0) { var par = app.createParam(); par.setName(propn); par.setValue(propv); } else { if(fx_ant_api_1_1 == "true") { var arg = app.createArgument(); arg.addText(propn); } else { println("Warning: Unnamed parameters not supported by this version of JavaFX SDK deployment Ant tasks. Upgrade JavaFX to 2.0.2 or higher."); } } } } } // fx:resources var res = deploy.createResources(); res.setProject(project); var deploydir = project.getProperty("pp_deploy_dir"); if(withpreloader == "true") { var f1 = res.createFileSet(); f1.setProject(project); f1.setDir(new java.io.File(deploydir)); var i1 = project.getProperty("pp_deploy_fs1"); f1.setIncludes(i1); f1.setRequiredFor("preloader"); var f2 = res.createFileSet(); f2.setProject(project); f2.setDir(new java.io.File(deploydir)); var i2a = project.getProperty("jfx.deployment.jar"); var i2b = project.getProperty("pp_deploy_fs2"); var e2c = project.getProperty("pp_deploy_fs1"); f2.setIncludes(i2a); f2.setIncludes(i2b); f2.setExcludes(e2c); f2.setRequiredFor("startup"); var lazyjars = getLazyJars(); if(lazyjars != null) { var f3 = res.createFileSet(); f3.setProject(project); f3.setDir(new java.io.File(deploydir)); f3.setRequiredFor("runtime"); setDownloadMode(f2,f3,lazyjars); } } else { var fn = res.createFileSet(); fn.setProject(project); fn.setDir(new java.io.File(deploydir)); var ia = project.getProperty("jfx.deployment.jar"); var ib = project.getProperty("pp_deploy_fs2"); fn.setIncludes(ia); fn.setIncludes(ib); fn.setRequiredFor("startup"); var lazyjars = getLazyJars(); if(lazyjars != null) { var fn2 = res.createFileSet(); fn2.setProject(project); fn2.setDir(new java.io.File(deploydir)); fn2.setRequiredFor("runtime"); setDownloadMode(fn,fn2,lazyjars); } } // fx:info var info = deploy.createInfo(); info.setProject(project); var vendor = project.getProperty("application.vendor"); info.setTitle(title); // title known from before info.setVendor(vendor); var icon = project.getProperty("javafx.deploy.icon"); if(icon != null) { if(fx_ant_api_1_1 == "true") { var iicon = info.createIcon(); iicon.setHref(icon); } else { println("Warning: Icon not supported by this version of JavaFX SDK deployment Ant task. Please upgrade JavaFX to 2.0.2 or higher."); } } // fx:permissions var perm = deploy.createPermissions(); perm.setProject(project); var elev = project.getProperty("permissions.elevated"); perm.setElevated(isTrue(elev)); // fx:preferences var pref = deploy.createPreferences(); pref.setProject(project); var scut = project.getProperty("javafx.deploy.adddesktopshortcut"); var instp = project.getProperty("javafx.deploy.installpermanently"); var smenu = project.getProperty("javafx.deploy.addstartmenushortcut"); pref.setShortcut(isTrue(scut)); pref.setInstall(isTrue(instp)); pref.setMenu(isTrue(smenu)); // fx:template var templ = project.getProperty("javafx.run.htmltemplate"); var templp = project.getProperty("javafx.run.htmltemplate.processed"); if(templ != null && templp != null && templ.length() > 0 && templp.length() > 0) { var temp = deploy.createTemplate(); temp.setProject(project); temp.setFile(new java.io.File(templ)); temp.setTofile(new java.io.File(templp)); } // fx:platform var plat = deploy.createPlatform(); plat.setProject(project); plat.setJavafx("2.0+"); var jvmargs = project.getProperty("run.jvmargs"); if(jvmargs != null && jvmargs.length() > 0) { var jvmargss = jvmargs.split(" "); for(i = 0; i < jvmargss.length; i++) { if(jvmargss[i] != null && jvmargss[i].length() > 0) { var vmarg = plat.createJvmarg(); vmarg.setValue(jvmargss[i]); } } } // fx:callbacks var callbs = deploy.createCallbacks(); callbs.setProject(project); var keys = project.getProperties().keys(); while(keys.hasMoreElements()) { var pn = keys.nextElement(); if(pn.substr(0,JFXCALLB.length) == JFXCALLB) { var prop = project.getProperty(pn); if(prop != null && prop.length() > 0) { var cname = pn.substring(JFXCALLB.length+1); var cb = callbs.createCallback(); cb.setProject(project); cb.setName(cname); cb.addText(prop); } } } deploy.perform();
ColorfulCircles/nbproject/jfx-impl_backup_1.xml
JavaFX-specific Ant calls ${cssfileslist} var pathConvert = project.createTask("pathconvert"); pathConvert.setProperty("run.and.lib.classpath"); var classPath = project.getProperty("run.classpath.without.build.classes.and.dist.dir"); var fileSeparator = project.getProperty("file.separator"); if(classPath != null) { var classPathCopy = pathConvert.createPath(); classPathCopy.setPath(classPath); if(classPath.indexOf(";") != -1) { var pathArray = classPath.split(";"); } else { var pathArray = classPath.split(":"); } var added = ""; for (var i=0; i<pathArray.length; i++) { var index = pathArray[i].lastIndexOf(fileSeparator); if (index >=0) { var onePath = pathArray[i].substr(0,index+1) + "lib"; var oneDir = new java.io.File(onePath); if(oneDir.exists()) { var fs = project.createDataType("fileset"); fs.setDir( oneDir ); fs.setIncludes("*.jar"); var ds = fs.getDirectoryScanner(project); var srcFiles = ds.getIncludedFiles(); for (j=0; j<srcFiles.length; j++) { if(classPath.indexOf(srcFiles[j]) == -1 && added.indexOf(srcFiles[j]) == -1) { var path = pathConvert.createPath(); path.setPath(onePath + fileSeparator + srcFiles[j]); added += srcFiles[j]; } } } } } } pathConvert.perform(); var UTF_8 = "UTF-8"; var ATTR_CLASS_PATH = "Class-Path"; var ATTR_CLASS_PATH_FX = "JavaFX-Class-Path"; function isSigned(manifest) { var sections = manifest.getSectionNames(); while(sections.hasMoreElements()) { var sectionname = sections.nextElement(); var section = manifest.getSection(sectionname); if(section != null) { var sectionKeys = section.getAttributeKeys(); while (sectionKeys.hasMoreElements()) { var element = sectionKeys.nextElement(); if (element.endsWith("-Digest") || element.endsWith("-digest")) { return true; } } } } return false; } var src = project.getProperty("manifest.file.temp"); var srf = new java.io.File(src); try { var fis = new java.io.FileInputStream(srf); try { var isr = new java.io.InputStreamReader(fis, UTF_8); try { var manifest = new org.apache.tools.ant.taskdefs.Manifest(isr); } finally { isr.close(); } } finally { fis.close(); } } catch(e) { var manifest = null; } if(manifest != null) { if(isSigned(manifest)) { println("Warning: Signed JAR can not be rebased."); } else { var mainSection = manifest.getMainSection(); var classPath = mainSection.getAttributeValue(ATTR_CLASS_PATH); if (classPath != null) { var classPathAttr = ATTR_CLASS_PATH; } else { classPath = mainSection.getAttributeValue(ATTR_CLASS_PATH_FX); if(classPath != null) { var classPathAttr = ATTR_CLASS_PATH_FX; } } if(classPath != null) { var result = new java.lang.StringBuilder(); var changed = false; var pathArray = classPath.split(" "); for (var i=0; i<pathArray.length; i++) { if (result.length() > 0) { result.append(' '); } var index = pathArray[i].lastIndexOf('/'); if (index >=0 && index < pathArray[i].length()-1) { pathArray[i] = pathArray[i].substring(index+1); changed = true; } result.append(pathArray[i]); } mainSection.removeAttribute(classPathAttr); mainSection.addAttributeAndCheck(new org.apache.tools.ant.taskdefs.Manifest.Attribute(classPathAttr, result.toString())); var tgt = project.getProperty("manifest.file.temp.new"); var tgf = new java.io.File(tgt); try { var fos = new java.io.FileOutputStream(tgf); try { var osw = new java.io.OutputStreamWriter(fos, UTF_8); try { var manifestOut = new java.io.PrintWriter(osw); manifest.write(manifestOut); manifestOut.close(); } finally { osw.close(); } } finally { fos.close(); } } catch(e) { println("Warning: problem storing rebased manifest file."); } } } } var dir = project.getProperty("pp_rebase_dir"); var fDir = new java.io.File(dir); if( fDir.exists() ) { var callTask = project.createTask("antcall"); callTask.setTarget("-rebase-libs-macro-call"); var param = callTask.createParam(); param.setName("jar.file.to.rebase"); var includes = project.getProperty("pp_rebase_fs"); var fs = project.createDataType("fileset"); fs.setDir( fDir ); fs.setIncludes(includes); var ds = fs.getDirectoryScanner(project); var srcFiles = ds.getIncludedFiles(); for (i=0; i<srcFiles.length; i++) { param.setValue(dir + "${file.separator}" + srcFiles[i]); callTask.perform(); } } var S = java.io.File.separator; var JFXPAR = "javafx.param"; var JFXPARN = "name"; var JFXPARV = "value"; var JFXLAZY = "download.mode.lazy.jar"; var withpreloader = project.getProperty("app-with-preloader"); var fx_ant_api_1_1 = project.getProperty("have-fx-ant-api-1.1"); // get jars with lazy download mode property set function getLazyJars() { var jars = new Array(); var keys = project.getProperties().keys(); while(keys.hasMoreElements()) { var pn = keys.nextElement(); if(pn.substr(0,JFXLAZY.length) == JFXLAZY) { var fname = pn.substring(JFXLAZY.length+1); jars.push(fname); } } return jars.length > 0 ? jars : null; } // set download mode of dependent libraries function setDownloadMode(fsEager, fsLazy, jars) { for(i = 0; i < jars.length; i++) { fsEager.setExcludes("lib" + S + jars[i]); fsLazy.setIncludes("lib" + S + jars[i]); } } // fx:jar var jar = project.createTask("fx_jar"); jar.setProject(project); var destfile = project.getProperty("pp_jar_destfile"); jar.setDestfile(destfile); // fx:application var app = jar.createApplication(); app.setProject(project); var title = project.getProperty("application.title"); var mainclass = project.getProperty("javafx.main.class"); var fallback = project.getProperty("javafx.fallback.class"); app.setName(title); app.setMainClass(mainclass); app.setFallbackClass(fallback); if(withpreloader == "true") { preloaderclass = project.getProperty("javafx.preloader.class"); app.setPreloaderClass(preloaderclass); } // fx:param, fx:argument var keys = project.getProperties().keys(); while(keys.hasMoreElements()) { var pn = keys.nextElement(); if(pn.substr(0,JFXPAR.length) == JFXPAR && pn.indexOf(JFXPARN) == (pn.length()-JFXPARN.length)) { var propn = project.getProperty(pn); if(propn != null && propn.length() > 0) { var pv = pn.substr(0,pn.indexOf(JFXPARN)) + JFXPARV; var propv = project.getProperty(pv); if(propv != null && propv.length() > 0) { var par = app.createParam(); par.setName(propn); par.setValue(propv); } else { if(fx_ant_api_1_1 == "true") { var arg = app.createArgument(); arg.addText(propn); } } } } } // fx:resources var res = jar.createResources(); res.setProject(project); var pdir = project.getProperty("pp_jar_dir"); if(withpreloader == "true") { var f1 = res.createFileSet(); f1.setProject(project); f1.setDir(new java.io.File(pdir)); var i1 = project.getProperty("pp_jar_fs1"); f1.setIncludes(i1); f1.setRequiredFor("preloader"); var f2 = res.createFileSet(); f2.setProject(project); f2.setDir(new java.io.File(pdir)); var i2a = project.getProperty("jfx.deployment.jar"); var i2b = project.getProperty("pp_jar_fs2"); var e2c = project.getProperty("pp_jar_fs1"); f2.setIncludes(i2a); f2.setIncludes(i2b); f2.setExcludes(e2c); f2.setRequiredFor("startup"); var lazyjars = getLazyJars(); if(lazyjars != null) { var f3 = res.createFileSet(); f3.setProject(project); f3.setDir(new java.io.File(pdir)); f3.setRequiredFor("runtime"); setDownloadMode(f2,f3,lazyjars); } } else { var fn = res.createFileSet(); fn.setProject(project); fn.setDir(new java.io.File(pdir)); var ia = project.getProperty("jfx.deployment.jar"); var ib = project.getProperty("pp_jar_fs2"); fn.setIncludes(ia); fn.setIncludes(ib); fn.setRequiredFor("startup"); var lazyjars = getLazyJars(); if(lazyjars != null) { var fn2 = res.createFileSet(); fn2.setProject(project); fn2.setDir(new java.io.File(pdir)); fn2.setRequiredFor("runtime"); setDownloadMode(fn,fn2,lazyjars); } } // fileset to exclude *.css or *.bss var fs = jar.createFileSet(); fs.setProject(project); var buildcls = project.getProperty("pp_jar_buildclasses"); var exc = project.getProperty("pp_jar_cssbss"); fs.setDir(new java.io.File(buildcls)); fs.setExcludes(exc); // manifest var man = jar.createManifest(); var a1val = project.getProperty("application.vendor"); var a1 = new org.apache.tools.ant.taskdefs.Manifest.Attribute(); a1.setName("Implementation-Vendor"); a1.setValue(a1val); man.addConfiguredAttribute(a1); var a2val = project.getProperty("application.title"); var a2 = new org.apache.tools.ant.taskdefs.Manifest.Attribute(); a2.setName("Implementation-Title"); a2.setValue(a2val); man.addConfiguredAttribute(a2); var a3 = new org.apache.tools.ant.taskdefs.Manifest.Attribute(); a3.setName("Implementation-Version"); a3.setValue("1.0"); man.addConfiguredAttribute(a3); jar.perform(); function isTrue(prop) { return prop != null && (prop.toLowerCase()=="true" || prop.toLowerCase()=="yes" || prop.toLowerCase()=="on"); } var S = java.io.File.separator; var JFXPAR = "javafx.param"; var JFXPARN = "name"; var JFXPARV = "value"; var JFXCALLB = "javafx.jscallback"; var JFXLAZY = "download.mode.lazy.jar"; var withpreloader = project.getProperty("app-with-preloader"); var fx_ant_api_1_1 = project.getProperty("have-fx-ant-api-1.1"); // get jars with lazy download mode property set function getLazyJars() { var jars = new Array(); var keys = project.getProperties().keys(); while(keys.hasMoreElements()) { var pn = keys.nextElement(); if(pn.substr(0,JFXLAZY.length) == JFXLAZY) { var fname = pn.substring(JFXLAZY.length+1); jars.push(fname); } } return jars.length > 0 ? jars : null; } // set download mode of dependent libraries function setDownloadMode(fsEager, fsLazy, jars) { for(i = 0; i < jars.length; i++) { fsEager.setExcludes("lib" + S + jars[i]); fsLazy.setIncludes("lib" + S + jars[i]); } } // fx:deploy var deploy = project.createTask("fx_deploy"); deploy.setProject(project); var width = project.getProperty("javafx.width"); var height = project.getProperty("javafx.height"); var outdir = project.getProperty("jfx.deployment.dir"); var embedJNLP = project.getProperty("javafx.deploy.embedJNLP"); var updatemode = project.getProperty("update-mode"); var outfile = project.getProperty("application.title"); var includeDT = project.getProperty("javafx.deploy.includeDT"); var offline = project.getProperty("javafx.deploy.allowoffline"); deploy.setWidth(width); deploy.setHeight(height); deploy.setOutdir(outdir); deploy.setEmbedJNLP(isTrue(embedJNLP)); deploy.setUpdateMode(updatemode); deploy.setOutfile(outfile); deploy.setIncludeDT(isTrue(includeDT)); if(offline != null) { if(fx_ant_api_1_1 == "true") { deploy.setOfflineAllowed(isTrue(offline)); } else { println("Warning: offlineAllowed not supported by this version of JavaFX SDK deployment Ant task. Please upgrade JavaFX to 2.0.2 or higher."); } } // fx:application var app = deploy.createApplication(); app.setProject(project); var title = project.getProperty("application.title"); var mainclass = project.getProperty("javafx.main.class"); var fallback = project.getProperty("javafx.fallback.class"); app.setName(title); app.setMainClass(mainclass); app.setFallbackClass(fallback); if(withpreloader == "true") { preloaderclass = project.getProperty("javafx.preloader.class"); app.setPreloaderClass(preloaderclass); } // fx:param, fx:argument var keys = project.getProperties().keys(); while(keys.hasMoreElements()) { var pn = keys.nextElement(); if(pn.substr(0,JFXPAR.length) == JFXPAR && pn.indexOf(JFXPARN) == (pn.length()-JFXPARN.length)) { var propn = project.getProperty(pn); if(propn != null && propn.length() > 0) { var pv = pn.substr(0,pn.indexOf(JFXPARN)) + JFXPARV; var propv = project.getProperty(pv); if(propv != null && propv.length() > 0) { var par = app.createParam(); par.setName(propn); par.setValue(propv); } else { if(fx_ant_api_1_1 == "true") { var arg = app.createArgument(); arg.addText(propn); } else { println("Warning: Unnamed parameters not supported by this version of JavaFX SDK deployment Ant tasks. Upgrade JavaFX to 2.0.2 or higher."); } } } } } // fx:resources var res = deploy.createResources(); res.setProject(project); var deploydir = project.getProperty("pp_deploy_dir"); if(withpreloader == "true") { var f1 = res.createFileSet(); f1.setProject(project); f1.setDir(new java.io.File(deploydir)); var i1 = project.getProperty("pp_deploy_fs1"); f1.setIncludes(i1); f1.setRequiredFor("preloader"); var f2 = res.createFileSet(); f2.setProject(project); f2.setDir(new java.io.File(deploydir)); var i2a = project.getProperty("jfx.deployment.jar"); var i2b = project.getProperty("pp_deploy_fs2"); var e2c = project.getProperty("pp_deploy_fs1"); f2.setIncludes(i2a); f2.setIncludes(i2b); f2.setExcludes(e2c); f2.setRequiredFor("startup"); var lazyjars = getLazyJars(); if(lazyjars != null) { var f3 = res.createFileSet(); f3.setProject(project); f3.setDir(new java.io.File(deploydir)); f3.setRequiredFor("runtime"); setDownloadMode(f2,f3,lazyjars); } } else { var fn = res.createFileSet(); fn.setProject(project); fn.setDir(new java.io.File(deploydir)); var ia = project.getProperty("jfx.deployment.jar"); var ib = project.getProperty("pp_deploy_fs2"); fn.setIncludes(ia); fn.setIncludes(ib); fn.setRequiredFor("startup"); var lazyjars = getLazyJars(); if(lazyjars != null) { var fn2 = res.createFileSet(); fn2.setProject(project); fn2.setDir(new java.io.File(deploydir)); fn2.setRequiredFor("runtime"); setDownloadMode(fn,fn2,lazyjars); } } // fx:info var info = deploy.createInfo(); info.setProject(project); var vendor = project.getProperty("application.vendor"); info.setTitle(title); // title known from before info.setVendor(vendor); var icon = project.getProperty("javafx.deploy.icon"); if(icon != null) { if(fx_ant_api_1_1 == "true") { var iicon = info.createIcon(); iicon.setHref(icon); } else { println("Warning: Icon not supported by this version of JavaFX SDK deployment Ant task. Please upgrade JavaFX to 2.0.2 or higher."); } } // fx:permissions var perm = deploy.createPermissions(); perm.setProject(project); var elev = project.getProperty("permissions.elevated"); perm.setElevated(isTrue(elev)); // fx:preferences var pref = deploy.createPreferences(); pref.setProject(project); var scut = project.getProperty("javafx.deploy.adddesktopshortcut"); var instp = project.getProperty("javafx.deploy.installpermanently"); var smenu = project.getProperty("javafx.deploy.addstartmenushortcut"); pref.setShortcut(isTrue(scut)); pref.setInstall(isTrue(instp)); pref.setMenu(isTrue(smenu)); // fx:template var templ = project.getProperty("javafx.run.htmltemplate"); var templp = project.getProperty("javafx.run.htmltemplate.processed"); if(templ != null && templp != null && templ.length() > 0 && templp.length() > 0) { var temp = deploy.createTemplate(); temp.setProject(project); temp.setFile(new java.io.File(templ)); temp.setTofile(new java.io.File(templp)); } // fx:platform var plat = deploy.createPlatform(); plat.setProject(project); var jvmargs = project.getProperty("run.jvmargs"); if(jvmargs != null && jvmargs.length() > 0) { var jvmargss = jvmargs.split(" "); for(i = 0; i < jvmargss.length; i++) { if(jvmargss[i] != null && jvmargss[i].length() > 0) { var vmarg = plat.createJvmarg(); vmarg.setValue(jvmargss[i]); } } } // fx:callbacks var callbs = deploy.createCallbacks(); callbs.setProject(project); var keys = project.getProperties().keys(); while(keys.hasMoreElements()) { var pn = keys.nextElement(); if(pn.substr(0,JFXCALLB.length) == JFXCALLB) { var prop = project.getProperty(pn); if(prop != null && prop.length() > 0) { var cname = pn.substring(JFXCALLB.length+1); var cb = callbs.createCallback(); cb.setProject(project); cb.setName(cname); cb.addText(prop); } } } deploy.perform(); var JFXPAR = "javafx.param"; var JFXPARN = "name"; var JFXPARV = "value"; var params = ""; var args = ""; var keys = project.getProperties().keys(); while(keys.hasMoreElements()) { var pn = keys.nextElement(); if(pn.substr(0,JFXPAR.length) == JFXPAR && pn.indexOf(JFXPARN) == (pn.length()-JFXPARN.length)) { var propn = project.getProperty(pn); if(propn != null && propn.length() > 0) { var pv = pn.substr(0,pn.indexOf(JFXPARN)) + JFXPARV; var propv = project.getProperty(pv); if(propv != null && propv.length() > 0) { params += "\n <param name=\"" + propn + "\" value=\"" + propv + "\"/>"; args += "\n <argument>" + propn + "=" + propv + "</argument>"; } else { params += "\n <param name=\"" + propn + "\" value=\"\"/>"; args += "\n <argument>" + propn + "</argument>"; } } } } project.setProperty("applet-params-token", params); project.setProperty("application-args-token", args); var PREF = "file:"; var doCopyIcon = project.getProperty("local-icon-filename-available"); if(doCopyIcon != null) { var iconProp = project.getProperty("javafx.deploy.icon"); if(iconProp.indexOf(PREF) == 0) { iconProp = iconProp.slice(PREF.length); } while(iconProp.charAt(0) == "/") { iconProp = iconProp.slice(1); } var S = java.io.File.separator; var baseDir = project.getProperty("basedir"); var distDir = project.getProperty("dist.dir"); var copyTask = project.createTask("copy"); var source = new java.io.File(iconProp); var target = new java.io.File(baseDir + S + distDir); copyTask.setFile(source); copyTask.setTodir(target); copyTask.setFlatten(true); copyTask.setFailOnError(false); copyTask.perform(); } var doCopyHTMLFrom = project.getProperty("html-template-available"); var doCopyHTMLTo = project.getProperty("html-template-processed-available"); if(doCopyHTMLFrom != null && doCopyHTMLTo != null) { var htmlFrom = project.getProperty("javafx.run.htmltemplate"); if(htmlFrom.indexOf(PREF) == 0) { htmlFrom = htmlFrom.slice(PREF.length); } while(htmlFrom.charAt(0) == "/") { htmlFrom = htmlFrom.slice(1); } var htmlTo = project.getProperty("javafx.run.htmltemplate.processed"); if(htmlTo.indexOf(PREF) == 0) { htmlTo = htmlTo.slice(PREF.length); } while(htmlTo.charAt(0) == "/") { htmlTo = htmlTo.slice(1); } var copyTask = project.createTask("copy"); var source = new java.io.File(htmlFrom); var target = new java.io.File(htmlTo); copyTask.setFile(source); copyTask.setTofile(target); copyTask.setFailOnError(false); copyTask.perform(); }
ColorfulCircles/nbproject/private/configs/Run_as_WebStart.properties
# Do not modify this property in this configuration. It can be re-generated. $label=Run as WebStart # Do not modify this property in this configuration. It can be re-generated. javafx.run.as=webstart
ColorfulCircles/nbproject/private/configs/Run_in_Browser.properties
# Do not modify this property in this configuration. It can be re-generated. $label=Run in Browser # Do not modify this property in this configuration. It can be re-generated. javafx.run.as=embedded
ColorfulCircles/nbproject/private/private.properties
auxiliary.org-netbeans-modules-projectapi.issue214819_5f_fx_5f_enabled=true compile.on.save=true do.depend=false do.jar=true javac.debug=true javadoc.preview=true javafx.run.as=standalone javafx.run.inbrowser=<Default System Browser> javafx.run.inbrowser.path=C:\\Documents and Settings\\nhildebr.ST-USERS\\Local Settings\\Application Data\\Google\\Chrome\\Application\\chrome.exe user.properties.file=C:\\Users\\cmcastil.ST-USERS\\AppData\\Roaming\\NetBeans\\7.4\\build.properties
ColorfulCircles/nbproject/private/private.xml
ColorfulCircles/nbproject/project.properties
annotation.processing.enabled=true annotation.processing.enabled.in.editor=false annotation.processing.processors.list= annotation.processing.run.all.processors=true annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output application.title=ColorfulCircles application.vendor=Oracle build.classes.dir=${build.dir}/classes build.classes.excludes=**/*.java,**/*.form # This directory is removed when the project is cleaned: build.dir=build build.generated.dir=${build.dir}/generated build.generated.sources.dir=${build.dir}/generated-sources # Only compile against the classpath explicitly listed here: build.sysclasspath=ignore build.test.classes.dir=${build.dir}/test/classes build.test.results.dir=${build.dir}/test/results compile.on.save=true compile.on.save.unsupported.javafx=true # Uncomment to specify the preferred debugger connection transport: #debug.transport=dt_socket debug.classpath=\ ${run.classpath} debug.test.classpath=\ ${run.test.classpath} # This directory is removed when the project is cleaned: dist.dir=dist dist.jar=${dist.dir}/ColorfulCircles.jar dist.javadoc.dir=${dist.dir}/javadoc endorsed.classpath= excludes= includes=** # Non-JavaFX 2.0 jar file creation is deactivated in JavaFX 2.0 projects jar.archive.disabled=true jar.compress=false javac.classpath=\ ${javafx.classpath.extension} # Space-separated list of extra javac options javac.compilerargs= javac.deprecation=false javac.processorpath=\ ${javac.classpath} javac.source=1.7 javac.target=1.7 javac.test.classpath=\ ${javac.classpath}:\ ${build.classes.dir} javac.test.processorpath=\ ${javac.test.classpath} javadoc.additionalparam= javadoc.author=false javadoc.encoding=${source.encoding} javadoc.noindex=false javadoc.nonavbar=false javadoc.notree=false javadoc.private=false javadoc.splitindex=true javadoc.use=true javadoc.version=false javadoc.windowtitle= javafx.application.implementation.version=1.0 javafx.binarycss=false javafx.classpath.extension=\ ${platforms.JDK_1.8.home}/jre/lib/javaws.jar:\ ${platforms.JDK_1.8.home}/jre/lib/deploy.jar:\ ${platforms.JDK_1.8.home}/jre/lib/plugin.jar javafx.deploy.adddesktopshortcut=false javafx.deploy.addstartmenushortcut=false javafx.deploy.allowoffline=true # If true, application update mode is set to 'background', if false, update mode is set to 'eager' javafx.deploy.backgroundupdate=true javafx.deploy.disable.proxy=false javafx.deploy.embedJNLP=true javafx.deploy.includeDT=true javafx.deploy.installpermanently=false javafx.deploy.permissionselevated=false # This is a JavaFX project javafx.enabled=true javafx.fallback.class=com.javafx.main.NoJavaFXFallback # Main class for JavaFX javafx.main.class=colorfulcircles.ColorfulCircles javafx.preloader.class= # This project does not use Preloader javafx.preloader.enabled=false javafx.preloader.jar.filename= javafx.preloader.jar.path= javafx.preloader.project.path= javafx.preloader.type=none javafx.run.height=600 javafx.run.width=800 javafx.signing.blob=false javafx.signing.enabled=false javafx.signing.type=notsigned # Pre-JavaFX 2.0 WebStart is deactivated in JavaFX 2.0 projects jnlp.enabled=false # Main class for Java launcher main.class=com.javafx.main.Main # For improved security specify narrower Codebase manifest attribute to prevent RIAs from being repurposed manifest.custom.codebase=* # Specify Permissions manifest attribute to override default (choices: sandbox, all-permissions) manifest.custom.permissions= manifest.file=manifest.mf meta.inf.dir=${src.dir}/META-INF mkdist.disabled=false native.bundling.enabled=false platform.active=JDK_1.8 run.classpath=\ ${javac.classpath}:\ ${build.classes.dir} run.test.classpath=\ ${javac.test.classpath}:\ ${build.test.classes.dir} source.encoding=UTF-8 src.dir=src
ColorfulCircles/nbproject/project.xml
org.netbeans.modules.java.j2seproject ColorfulCircles
ColorfulCircles/nbproject/UPDATED.TXT
============================================ Project ColorfulCircles build script updated ============================================ Project build script file jfx-impl.xml in nbproject sub-directory has not been recognized as compliant with this version of NetBeans JavaFX support module. To ensure correct and complete functionality within this NetBeans installation the script file has been backed up to jfx-impl_backup_1.xml and then updated to the currently supported state. FX Project build script auto-update may be triggered on project open either after NetBeans installation update or by manual changes in jfx-impl.xml. Please note that changing jfx-impl.xml manually is not recommended. Any build customization code should be placed only in build.xml in project root directory. Remark: The auto-update mechanism can be disabled by setting property javafx.disable.autoupdate=true Automatic opening of this notification when project files are updated can be disabled by setting property javafx.disable.autoupdate.notification=true (in build.properties, private.properties or project.properties). Remark: Files nbproject/jfx-impl_backup*.xml and this file nbproject/UPDATED.TXT are not used when building the project and can be freely deleted.
ColorfulCircles/src/colorfulcircles/ColorfulCircles.java
ColorfulCircles/src/colorfulcircles/ColorfulCircles.java
/*
* Copyright (c) 2011, 2014 Oracle and/or its affiliates.
* All rights reserved. Use is subject to license terms.
*
* This file is available and licensed under the following license:
*
* 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 Oracle 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.
*/
package
colorfulcircles
;
import
javafx
.
animation
.
KeyFrame
;
import
javafx
.
animation
.
KeyValue
;
import
javafx
.
animation
.
Timeline
;
import
javafx
.
application
.
Application
;
import
javafx
.
scene
.
Group
;
import
javafx
.
scene
.
Node
;
import
javafx
.
scene
.
Scene
;
import
javafx
.
scene
.
effect
.
BlendMode
;
import
javafx
.
scene
.
effect
.
BoxBlur
;
import
javafx
.
scene
.
paint
.
Color
;
import
javafx
.
scene
.
paint
.
CycleMethod
;
import
javafx
.
scene
.
paint
.
LinearGradient
;
import
javafx
.
scene
.
paint
.
Stop
;
import
javafx
.
scene
.
shape
.
Circle
;
import
javafx
.
scene
.
shape
.
Rectangle
;
import
javafx
.
scene
.
shape
.
StrokeType
;
import
javafx
.
stage
.
Stage
;
import
javafx
.
util
.
Duration
;
import
static
java
.
lang
.
Math
.
random
;
public
class
ColorfulCircles
extends
Application
{
public
static
void
main
(
String
[]
args
)
{
launch
(
args
);
}
@
Override
public
void
start
(
Stage
primaryStage
)
{
Group
root
=
new
Group
();
Scene
scene
=
new
Scene
(
root
,
800
,
600
,
Color
.
BLACK
);
primaryStage
.
setScene
(
scene
);
Group
circles
=
new
Group
();
for
(
int
i
=
0
;
i
<
30
;
i
++
)
{
Circle
circle
=
new
Circle
(
150
,
Color
.
web
(
"white"
,
0.05
));
circle
.
setStrokeType
(
StrokeType
.
OUTSIDE
);
circle
.
setStroke
(
Color
.
web
(
"white"
,
0.16
));
circle
.
setStrokeWidth
(
4
);
circles
.
getChildren
().
add
(
circle
);
}
Rectangle
colors
=
new
Rectangle
(
scene
.
getWidth
(),
scene
.
getHeight
(),
new
LinearGradient
(
0f
,
1f
,
1f
,
0f
,
true
,
CycleMethod
.
NO_CYCLE
,
new
Stop
[]{
new
Stop
(
0
,
Color
.
web
(
"#f8bd55"
)),
new
Stop
(
0.14
,
Color
.
web
(
"#c0fe56"
)),
new
Stop
(
0.28
,
Color
.
web
(
"#5dfbc1"
)),
new
Stop
(
0.43
,
Color
.
web
(
"#64c2f8"
)),
new
Stop
(
0.57
,
Color
.
web
(
"#be4af7"
)),
new
Stop
(
0.71
,
Color
.
web
(
"#ed5fc2"
)),
new
Stop
(
0.85
,
Color
.
web
(
"#ef504c"
)),
new
Stop
(
1
,
Color
.
web
(
"#f2660f"
)),}));
colors
.
widthProperty
().
bind
(
scene
.
widthProperty
());
colors
.
heightProperty
().
bind
(
scene
.
heightProperty
());
Group
blendModeGroup
=
new
Group
(
new
Group
(
new
Rectangle
(
scene
.
getWidth
(),
scene
.
getHeight
(),
Color
.
BLACK
),
circles
),
colors
);
colors
.
setBlendMode
(
BlendMode
.
OVERLAY
);
root
.
getChildren
().
add
(
blendModeGroup
);
circles
.
setEffect
(
new
BoxBlur
(
10
,
10
,
3
));
Timeline
timeline
=
new
Timeline
();
for
(
Node
circle
:
circles
.
getChildren
())
{
timeline
.
getKeyFrames
().
addAll
(
new
KeyFrame
(
Duration
.
ZERO
,
// set start position at 0
new
KeyValue
(
circle
.
translateXProperty
(),
random
()
*
800
),
new
KeyValue
(
circle
.
translateYProperty
(),
random
()
*
600
)),
new
KeyFrame
(
new
Duration
(
40000
),
// set end position at 40s
new
KeyValue
(
circle
.
translateXProperty
(),
random
()
*
800
),
new
KeyValue
(
circle
.
translateYProperty
(),
random
()
*
600
)));
}
// play 40s of animation
timeline
.
play
();
primaryStage
.
show
();
}
}
__MACOSX/CodeZip/._ColorfulCirclesFX.zip
CodeZip/Main.java
CodeZip/Main.java
class
Calculator
implements
Runnable
{
private
int
number
;
public
Calculator
(
int
number
)
{
this
.
number
=
number
;
}
@
Override
public
void
run
()
{
for
(
int
i
=
1
;
i
<=
10
;
i
++
){
System
.
out
.
printf
(
"%s: %d * %d = %d\n"
,
Thread
.
currentThread
().
getName
(),
number
,
i
,
i
*
number
);
}
}
}
public
class
Main
{
public
static
void
main
(
String
[]
args
)
{
for
(
int
i
=
1
;
i
<=
10
;
i
++
){
Calculator
calculator
=
new
Calculator
(
i
);
Thread
thread
=
new
Thread
(
calculator
);
thread
.
start
();
}
}
}
__MACOSX/CodeZip/._Main.java
CodeZip/TrafficLightDemo.java
CodeZip/TrafficLightDemo.java
// Try This 12-1
// A simulation of a traffic light that uses
// an enumeration to describe the light's color.
// An enumeration of the colors of a traffic light.
enum
TrafficLightColor
{
RED
,
GREEN
,
YELLOW
}
// A computerized traffic light.
class
TrafficLightSimulator
implements
Runnable
{
private
TrafficLightColor
tlc
;
// holds the current traffic light color
private
boolean
stop
=
false
;
// set to true to stop the simulation
private
boolean
changed
=
false
;
// true when the light has changed
TrafficLightSimulator
(
TrafficLightColor
init
)
{
tlc
=
init
;
}
TrafficLightSimulator
()
{
tlc
=
TrafficLightColor
.
RED
;
}
// Start up the light.
public
void
run
()
{
while
(
!
stop
)
{
try
{
switch
(
tlc
)
{
case
GREEN
:
Thread
.
sleep
(
10000
);
// green for 10 seconds
break
;
case
YELLOW
:
Thread
.
sleep
(
2000
);
// yellow for 2 seconds
break
;
case
RED
:
Thread
.
sleep
(
12000
);
// red for 12 seconds
break
;
}
}
catch
(
InterruptedException
exc
)
{
System
.
out
.
println
(
exc
);
}
changeColor
();
}
}
// Change color.
synchronized
void
changeColor
()
{
switch
(
tlc
)
{
case
RED
:
tlc
=
TrafficLightColor
.
GREEN
;
break
;
case
YELLOW
:
tlc
=
TrafficLightColor
.
RED
;
break
;
case
GREEN
:
tlc
=
TrafficLightColor
.
YELLOW
;
}
changed
=
true
;
notify
();
// signal that the light has changed
}
// Wait until a light change occurs.
synchronized
void
waitForChange
()
{
try
{
while
(
!
changed
)
wait
();
// wait for light to change
changed
=
false
;
}
catch
(
InterruptedException
exc
)
{
System
.
out
.
println
(
exc
);
}
}
// Return current color.
synchronized
TrafficLightColor
getColor
()
{
return
tlc
;
}
// Stop the traffic light.
synchronized
void
cancel
()
{
stop
=
true
;
}
}
class
TrafficLightDemo
{
public
static
void
main
(
String
args
[])
{
TrafficLightSimulator
tl
=
new
TrafficLightSimulator
(
TrafficLightColor
.
GREEN
);
Thread
thrd
=
new
Thread
(
tl
);
thrd
.
start
();
for
(
int
i
=
0
;
i
<
9
;
i
++
)
{
System
.
out
.
println
(
tl
.
getColor
());
tl
.
waitForChange
();
}
tl
.
cancel
();
}
}
__MACOSX/CodeZip/._TrafficLightDemo.java
CodeZip/TFDemo.java
CodeZip/TFDemo.java
// Use a text field.
import
java
.
awt
.
*
;
import
java
.
awt
.
event
.
*
;
import
javax
.
swing
.
*
;
public
class
TFDemo
implements
ActionListener
{
JTextField
jtf
;
JButton
jbtnRev
;
JLabel
jlabPrompt
,
jlabContents
;
TFDemo
()
{
// Create a new JFrame container.
JFrame
jfrm
=
new
JFrame
(
"Use a Text Field"
);
// Specify FlowLayout for the layout manager.
jfrm
.
setLayout
(
new
FlowLayout
());
// Give the frame an initial size.
jfrm
.
setSize
(
240
,
120
);
// Terminate the program when the user closes the application.
jfrm
.
setDefaultCloseOperation
(
JFrame
.
EXIT_ON_CLOSE
);
// Create a text field.
jtf
=
new
JTextField
(
10
);
// Set the action commands for the text field.
jtf
.
setActionCommand
(
"myTF"
);
// Create the Reverse button.
JButton
jbtnRev
=
new
JButton
(
"Reverse"
);
// Add action listeners.
jtf
.
addActionListener
(
this
);
jbtnRev
.
addActionListener
(
this
);
// Create the labels.
jlabPrompt
=
new
JLabel
(
"Enter text: "
);
jlabContents
=
new
JLabel
(
""
);
// Add the components to the content pane.
jfrm
.
add
(
jlabPrompt
);
jfrm
.
add
(
jtf
);
jfrm
.
add
(
jbtnRev
);
jfrm
.
add
(
jlabContents
);
// Display the frame.
jfrm
.
setVisible
(
true
);
}
// Handle action events.
public
void
actionPerformed
(
ActionEvent
ae
)
{
if
(
ae
.
getActionCommand
().
equals
(
"Reverse"
))
{
// The Reverse button was pressed.
String
orgStr
=
jtf
.
getText
();
String
resStr
=
""
;
// Reverse the string in the text field.
for
(
int
i
=
orgStr
.
length
()
-
1
;
i
>=
0
;
i
--
)
resStr
+=
orgStr
.
charAt
(
i
);
// Store the reversed string in the text field.
jtf
.
setText
(
resStr
);
}
else
// Enter was pressed while focus was in the
// text field.
jlabContents
.
setText
(
"You pressed ENTER. Text is: "
+
jtf
.
getText
());
}
public
static
void
main
(
String
args
[])
{
// Create the frame on the event dispatching thread.
SwingUtilities
.
invokeLater
(
new
Runnable
()
{
public
void
run
()
{
new
TFDemo
();
new
ButtonDemo
();
new
FileMain
();
}
});
}
}
__MACOSX/CodeZip/._TFDemo.java
CodeZip/ButtonDemo.java
CodeZip/ButtonDemo.java
// Demonstrate a push button and handle action events.
import
java
.
awt
.
*
;
import
java
.
awt
.
event
.
*
;
import
javax
.
swing
.
*
;
public
class
ButtonDemo
implements
ActionListener
{
JLabel
jlab
;
JTextField
jtf
;
ButtonDemo
()
{
// Create a new JFrame container.
JFrame
jfrm
=
new
JFrame
(
"A Button Example"
);
// Specify FlowLayout for the layout manager.
jfrm
.
setLayout
(
new
FlowLayout
());
// Give the frame an initial size.
jfrm
.
setSize
(
220
,
90
);
// Terminate the program when the user closes the application.
jfrm
.
setDefaultCloseOperation
(
JFrame
.
EXIT_ON_CLOSE
);
// Make two buttons.
JButton
jbtnUp
=
new
JButton
(
"Up"
);
JButton
jbtnDown
=
new
JButton
(
"Down"
);
// Create a text field.
jtf
=
new
JTextField
(
10
);
// Add action listeners.
jbtnUp
.
addActionListener
(
this
);
jbtnDown
.
addActionListener
(
this
);
// Add the buttons to the content pane.
jfrm
.
add
(
jbtnUp
);
jfrm
.
add
(
jbtnDown
);
jfrm
.
add
(
jtf
);
// Create a label.
jlab
=
new
JLabel
(
"Press a button."
);
// Add the label to the frame.
jfrm
.
add
(
jlab
);
// Display the frame.
jfrm
.
setVisible
(
true
);
}
// Handle button events.
public
void
actionPerformed
(
ActionEvent
ae
)
{
if
(
ae
.
getActionCommand
().
equals
(
"Up"
))
{
jlab
.
setText
(
"You pressed Up."
);
FileClock
clock1
=
new
FileClock
(
jtf
);
Thread
thread1
=
new
Thread
(
clock1
);
thread1
.
start
();
}
else
jlab
.
setText
(
"You pressed down. "
);
}
public
static
void
main
(
String
args
[])
{
// Create the frame on the event dispatching thread.
SwingUtilities
.
invokeLater
(
new
Runnable
()
{
public
void
run
()
{
new
ButtonDemo
();
}
});
}
}
__MACOSX/CodeZip/._ButtonDemo.java
CodeZip/SwingDemo.java
CodeZip/SwingDemo.java
// A simple Swing program.
import
javax
.
swing
.
*
;
public
class
SwingDemo
{
SwingDemo
()
{
// Create a new JFrame container.
JFrame
jfrm
=
new
JFrame
(
"A Simple Swing Application"
);
// Give the frame an initial size.
jfrm
.
setSize
(
275
,
100
);
// Terminate the program when the user closes the application.
jfrm
.
setDefaultCloseOperation
(
JFrame
.
EXIT_ON_CLOSE
);
// Create a text-based label.
JLabel
jlab
=
new
JLabel
(
" GUI programming is easy with Swing."
);
// Add the label to the content pane.
jfrm
.
add
(
jlab
);
// Display the frame.
jfrm
.
setVisible
(
true
);
}
public
static
void
main
(
String
args
[])
{
// Create the frame on the event dispatching thread.
SwingUtilities
.
invokeLater
(
new
Runnable
()
{
public
void
run
()
{
new
SwingDemo
();
}
});
}
}
__MACOSX/CodeZip/._SwingDemo.java
CodeZip/FileMain.java
CodeZip/FileMain.java
import
java
.
util
.
Date
;
import
javax
.
swing
.
*
;
class
FileClock
implements
Runnable
{
JTextField
jtf
;
public
FileClock
(
JTextField
jtf
){
this
.
jtf
=
jtf
;
}
@
Override
public
void
run
()
{
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
System
.
out
.
printf
(
"%s\n"
,
new
Date
());
Date
d1
=
new
Date
();
jtf
.
setText
(
d1
.
toString
());
try
{
Thread
.
sleep
(
1000
);
}
catch
(
InterruptedException
e
)
{
System
.
out
.
printf
(
"The FileClock has been interrupted"
);
}
}
}
}
public
class
FileMain
{
public
static
void
main
(
String
[]
args
)
{
JTextField
jtf
=
new
JTextField
();
FileClock
clock1
=
new
FileClock
(
jtf
);
FileClock
clock2
=
new
FileClock
(
jtf
);
Thread
thread1
=
new
Thread
(
clock1
);
thread1
.
start
();
Thread
thread2
=
new
Thread
(
clock2
);
thread2
.
start
();
NewThread
nt1
=
new
NewThread
(
"One"
);
NewThread
nt2
=
new
NewThread
(
"Two"
);
NewThread
nt3
=
new
NewThread
(
"Three"
);
// Start the threads.
nt1
.
t
.
start
();
nt2
.
t
.
start
();
nt3
.
t
.
start
();
try
{
Thread
.
sleep
(
5000
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
};
thread1
.
interrupt
();
thread2
.
interrupt
();
}
}
__MACOSX/CodeZip/._FileMain.java
CodeZip/SwingFC.java
CodeZip/SwingFC.java
/*
Try This 16-1
A Swing-based file comparison utility.
*/
import
java
.
awt
.
*
;
import
java
.
awt
.
event
.
*
;
import
javax
.
swing
.
*
;
import
java
.
io
.
*
;
public
class
SwingFC
implements
ActionListener
{
JTextField
jtfFirst
;
// holds the first file name
JTextField
jtfSecond
;
// holds the second file name
JButton
jbtnComp
;
// button to compare the files
JLabel
jlabFirst
,
jlabSecond
;
// displays prompts
JLabel
jlabResult
;
// displays results and error messages
SwingFC
()
{
// Create a new JFrame container.
JFrame
jfrm
=
new
JFrame
(
"Compare Files"
);
// Specify FlowLayout for the layout manager.
jfrm
.
setLayout
(
new
FlowLayout
());
// Give the frame an initial size.
jfrm
.
setSize
(
200
,
190
);
// Terminate the program when the user closes the application.
jfrm
.
setDefaultCloseOperation
(
JFrame
.
EXIT_ON_CLOSE
);
// Create the text fields for the file names..
jtfFirst
=
new
JTextField
(
14
);
jtfSecond
=
new
JTextField
(
14
);
// Set the action commands for the text fields.
jtfFirst
.
setActionCommand
(
"fileA"
);
jtfSecond
.
setActionCommand
(
"fileB"
);
// Create the Compare button.
JButton
jbtnComp
=
new
JButton
(
"Compare"
);
// Add action listener for the Compare button.
jbtnComp
.
addActionListener
(
this
);
// Create the labels.
jlabFirst
=
new
JLabel
(
"First file: "
);
jlabSecond
=
new
JLabel
(
"Second file: "
);
jlabResult
=
new
JLabel
(
""
);
// Add the components to the content pane.
jfrm
.
add
(
jlabFirst
);
jfrm
.
add
(
jtfFirst
);
jfrm
.
add
(
jlabSecond
);
jfrm
.
add
(
jtfSecond
);
jfrm
.
add
(
jbtnComp
);
jfrm
.
add
(
jlabResult
);
// Display the frame.
jfrm
.
setVisible
(
true
);
}
// Compare the files when the Compare button is pressed.
public
void
actionPerformed
(
ActionEvent
ae
)
{
int
i
=
0
,
j
=
0
;
// First, confirm that both file names have
// been entered.
if
(
jtfFirst
.
getText
().
equals
(
""
))
{
jlabResult
.
setText
(
"First file name missing."
);
return
;
}
if
(
jtfSecond
.
getText
().
equals
(
""
))
{
jlabResult
.
setText
(
"Second file name missing."
);
return
;
}
// Compare files. Use try-with-resources to manage the files.
try
(
FileInputStream
f1
=
new
FileInputStream
(
jtfFirst
.
getText
());
FileInputStream
f2
=
new
FileInputStream
(
jtfSecond
.
getText
()))
{
// Check the contents of each file.
do
{
i
=
f1
.
read
();
j
=
f2
.
read
();
if
(
i
!=
j
)
break
;
}
while
(
i
!=
-
1
&&
j
!=
-
1
);
if
(
i
!=
j
)
jlabResult
.
setText
(
"Files are not the same."
);
else
jlabResult
.
setText
(
"Files compare equal."
);
}
catch
(
IOException
exc
)
{
jlabResult
.
setText
(
"File Error"
);
}
}
public
static
void
main
(
String
args
[])
{
// Create the frame on the event dispatching thread.
SwingUtilities
.
invokeLater
(
new
Runnable
()
{
public
void
run
()
{
new
SwingFC
();
}
});
}
}