I'm running through Haxe Introduction and I wanted to get my source folder organized. So far I just have some inheritance examples to put in one folder.
My problem is I'm getting a type not found error that wont allow me to run my code. What am I doing wrong?
I have a folder structured like this:
source/inheritance
In this folder I have:
Animal.hx
Dog.hx
Cat.hx
Cat.hx
package;
// package inheritance;
class Cat extends Animal{
public function new(name:String, speed:Float, height:Float, weight:Float, legs:Int):Void {
super(name, speed, height, weight, legs);
}
public override function Speak():String {
return ("Meow");
}
}
Animal.hx
package inheritance;
class Animal {
private var name:String;
private var speed:Float;
private var height:Float;
private var weight:Float;
private var legs:Int;
private function new(name:String, speed:Float, height:Float, weight:Float, legs:Int):Void {
this.name = name;
this.speed = speed;
this.height = height;
this.weight = weight;
this.legs = legs;
}
private function toString():String {
return ("\nName: " + name + "\nSpeed: " + speed + " mph\nHeight: " + height + " inches\nWeight: " + weight + " lbs\nLegs: " + legs);
}
private function Speak():String {
return ("Needs to fill out");
}
}
Main.hx
package;
// package inheritance; //Tried both and neither work
// import inheritance; //Tried both and neither work
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxState;
import flixel.text.FlxText;
import flixel.ui.FlxButton;
import flixel.math.FlxMath;
class MenuState extends FlxState
{
private var x:Int;
private var myPoint:Point;
private var myPoint3D:Point3;
private var myDog:Dog;
private var myCat:Cat;
override public function create():Void
{
myPoint = new Point(7,0);
myPoint3D = new Point3(7,6,0);
myDog = new Dog("Dog", 10, 12, 15, 4);
myCat = new Cat("Cat", 12, 7, 6, 4);
trace(myCat);
trace(myCat.Speak());
super.create();
}
override public function update(elapsed:Float):Void
{
super.update(elapsed);
}
private function changeMe(?x:Int) {
this.x = x;
}
}
After looking through a lot of other peoples code I have found my error. It turns out I need to import the class in my Main.hx.
Main.hx
package;
import inheritance.*; // This is what was missing
import inheritance.Dog; //Can be used if you only want one file
import inheritance.Cat; //Can be used if you only want one file
class MenuState extends FlxState
{
private var x:Int;
private var myPoint:Point;
private var myPoint3D:Point3;
private var myDog:Dog;
private var myCat:Cat;
...
Related
I want rename the PowerPoint slide master by apache poi. In PowerPoint GUI we do View - Slide Master - then we right click the top most slide on left side and select Rename Master from context menu.
In a PowerPoint presentation the master is named such as it's theme. We can get all masters using XMLSlideShow.getSlideMasters. XSLFSlideMaster
extends XSLFSheet. So we can get the theme of each master using XSLFSheet.getTheme. Once we have the XSLFTheme there are getters and setters for the name.
Example:
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.apache.poi.xslf.usermodel.*;
public class XSLFRenameMasterTheme {
public static void main(String[] args) throws Exception {
XMLSlideShow slideshow = new XMLSlideShow(new FileInputStream("Presentation.pptx"));
for (XSLFSlideMaster master : slideshow.getSlideMasters()) {
XSLFTheme theme = master.getTheme();
String name = theme.getName();
System.out.println(name);
theme.setName(name + " renamed");
System.out.println(theme.getName());
}
FileOutputStream out = new FileOutputStream("PresentationRenamedMaster.pptx");
slideshow.write(out);
out.close();
slideshow.close();
}
}
For HSLFSlideShow is seems there is no access to master names supported. One can get the HSLFSlideMasters but not the names of them.
So if one needs doing that nevertheless, then one must know about the internals of the binary *.ppt file system. This is documented in [MS-PPT]: PowerPoint (.ppt) Binary File Format. The sheet names are in a SlideNameAtom. With knowledge about the internals one can create a class for that kind of record. This can providing methods for get and set the name then.
Example:
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.io.ByteArrayOutputStream;
import org.apache.poi.hslf.usermodel.*;
import org.apache.poi.hslf.record.Record;
import org.apache.poi.hslf.record.RecordAtom;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.StringUtil;
public class HSLFRenameMaster {
// method for get SlideNameAtom out of the master
private static SlideNameAtom getSlideNameAtom(HSLFSlideMaster master) throws Exception {
SlideNameAtom slideNameAtomRecord = null;
Record record = master.getSheetContainer().findFirstOfType(0x0FBA);
if (record != null) { // SlideNameAtom exists
// get present data
ByteArrayOutputStream out = new ByteArrayOutputStream();
record.writeOut(out);
out.flush();
byte[] data = out.toByteArray();
out.close();
// create new SlideNameAtom from data
slideNameAtomRecord = new SlideNameAtom(data);
// replace old record with new SlideNameAtom
master.getSheetContainer().addChildBefore(
slideNameAtomRecord,
record
);
master.getSheetContainer().removeChild(record);
}
return slideNameAtomRecord;
}
public static void main(String[] args) throws Exception {
HSLFSlideShow slideshow = new HSLFSlideShow(new FileInputStream("Presentation.ppt"));
for (HSLFSlideMaster master : slideshow.getSlideMasters()) {
SlideNameAtom slideNameAtomRecord = getSlideNameAtom(master);
if (slideNameAtomRecord != null) {
String name = slideNameAtomRecord.getName();
System.out.println(name);
slideNameAtomRecord.setName(name + " renamed");
System.out.println(slideNameAtomRecord.getName());
}
}
FileOutputStream out = new FileOutputStream("PresentationRenamedMaster.ppt");
slideshow.write(out);
out.close();
slideshow.close();
}
//class SlideNameAtom
//having methods for manipulating the [SlideNameAtom](https://msdn.microsoft.com/en-us/library/dd906297(v=office.12).aspx)
private static class SlideNameAtom extends RecordAtom {
private byte[] data;
private String name;
public SlideNameAtom() {
this.name = "Office";
setName(name);
}
public SlideNameAtom(byte[] data) {
this.data = data;
this.name = getName();
}
public void setName(String name) {
this.name = name;
int length = 8;
length += StringUtil.getToUnicodeLE(name).length;
this.data = new byte[length];
data[0] = (byte)0x20; data[1] = (byte)0x00;
data[2] = (byte)0xBA; data[3] = (byte)0x0F; //MUST be 0x0fba = RT_CString (little endian)
LittleEndian.putInt(data, 4, StringUtil.getToUnicodeLE(name).length);
StringUtil.putUnicodeLE(name, data, 8);
}
public String getName() {
return StringUtil.getFromUnicodeLE(this.data, 8, (this.data.length-8)/2);
}
#Override
public void writeOut(OutputStream out) throws IOException {
out.write(data);
}
#Override
public long getRecordType() { return 0x0FBA; }
}
}
The question is whether renaming the master is worth that effort.
I have a Combo Bx (Dropdown box) with an index range of 0-20. If there anyways I can use that index to specify which object I want data from? All of the objects use the same naming convention obj0, obj1, obj2, etc. Basically something like this...
public abstract class Person {
private String name;
private String title;
private String email;
private String job;
public Person(String name, String title, String email, String job){
this.name = name;
this.title = title;
this.email = email;
this.job = job;
}
//Getters and Setters
}
public class main extends javax.swing.JFrame {
...misc code...
private void btn_startActionPerformed(java.awt.event.ActionEvent evt) {
Person obj0 = new Person("Jon Doe",
"Program Coordinator",
"jon.doe#test.com",
"Faculty");
Person obj1 = ...
...
Person obj20 = ...
/*
Onclick it uses the index of the current index in the combobox (dropdown)
to specify which object to get the data from.
*/
private void btn_GetActionPerformed(java.awt.event.ActionEvent evt) {
//Uses the obj naming convention plus the index
string foo = "obj" + toString(combobox_Name.getSelectedIndex());
//Fills the textbox using the above string and the getName method
txtbox_username.setText(ToObject(foo).getName);
}
I have created a basic design of what I think you want:
This code creates 20 objects, adds them to a combobox and uses their predefined name when selected to change a textfield.
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BoxLayout;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
class ObjExample {
String name;
public ObjExample(String name) {
this.name = name;
}
#Override
public String toString() {
return name;
}
}
public class Main extends JFrame implements ActionListener {
JComboBox jcb = new JComboBox();
JTextField jtf = new JTextField("Text Field");
public Main() {
setSize(200, 200);
setDefaultCloseOperation(EXIT_ON_CLOSE);
for (int i = 0; i <= 20; i++) {
jcb.addItem(new ObjExample(Integer.toString(i)));
}
jcb.addActionListener(this);
add(jcb);
add(jtf);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
#Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == jcb) {
ObjExample obj = (ObjExample) jcb.getSelectedItem();
jtf.setText(obj.toString());
}
}
}
I have been trying to run two tasks on two threads and using their progress to be indicated on progress bar and progress indicator.
First task is copyTask and second is copy file.
The copyTask sends the file object to copyFile for file copy.
But the problem is only a single file gets copied and the file count seems to be correct.
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import java.util.concurrent.CountDownLatch;
import javafx.concurrent.Task;
import javafx.concurrent.WorkerStateEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.control.TextArea;
/**
* FXML Controller class
*
* #author ANIL
*/
public class ProgressIndicateController implements Initializable {
#FXML
private ProgressIndicator uploadIndicator;
#FXML
private ProgressBar uploadBar;
#FXML
private TextArea errTxt;
#FXML
private Label uploadTxt;
File f;
Thread parent,child;
CountDownLatch latch = new CountDownLatch(1);
#FXML
private Label sizeTXT;
// private CopyTask copyTask;
/**
* Initializes the controller class.
*/
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
// Unbind progress property
uploadBar.progressProperty().unbind();
// Bind progress property
uploadBar.progressProperty().bind(copyFile.progressProperty());
// Hủy bỏ kết nối thuộc tính progress
uploadIndicator.progressProperty().unbind();
// Bind progress property.
uploadIndicator.progressProperty().bind(copyTask.progressProperty());
// Unbind text property for Label.
uploadTxt.textProperty().unbind();
// Bind the text property of Label
// with message property of Task
uploadTxt.textProperty().bind(copyTask.messageProperty());
// Unbind text property for Label.
sizeTXT.textProperty().unbind();
// Bind the text property of Label
// with message property of Task
sizeTXT.textProperty().bind(copyFile.messageProperty());
// When completed tasks
copyTask.addEventHandler(WorkerStateEvent.WORKER_STATE_SUCCEEDED, //
new EventHandler<WorkerStateEvent>() {
#Override
public void handle(WorkerStateEvent t) {
List<File> copied = copyTask.getValue();
uploadTxt.textProperty().unbind();
uploadTxt.setText("Copied: " + copied.size());
}
});
copyFile.addEventHandler(WorkerStateEvent.WORKER_STATE_SUCCEEDED, //
new EventHandler<WorkerStateEvent>() {
#Override
public void handle(WorkerStateEvent t) {
File copied = copyFile.getValue();
sizeTXT.textProperty().unbind();
sizeTXT.setText("Copied: " + copied.getAbsolutePath());
}
});
// Start the Task.
parent= new Thread(copyTask);
parent.start();
}
Task<List<File>> copyTask = new Task<List<File>>() {
#Override
protected List<File> call() throws Exception {
File dir = new File("F:");
File[] files = dir.listFiles();
int count = files.length;
List<File> copied = new ArrayList<File>();
int i = 0;
for (File file : files) {
if (file.isFile()) {
this.copy(file);
copied.add(file);
}
i++;
this.updateProgress(i, count);
}
return copied;
}
private void copy(File file) throws Exception {
this.updateMessage("Copying: " + file.getAbsolutePath());
f = file;
child=new Thread(copyFile);
child.start();
this.wait();
}
};
Task<File> copyFile = new Task<File>() {
#Override
protected File call() throws Exception {
InputStream is = null;
OutputStream os = null;
File dest=null;
String name=f.getName();
dest=new File("D:\\OUTPUT\\"+name);
is = new FileInputStream(f);
os = new FileOutputStream(dest);
byte[] buffer = new byte[1024];
int length;
double i=0.0;
double l=f.length();
while ((length = is.read(buffer)) > 0) {
i+=length;
this.updateMessage("Copying: " + i +" bytes of " + l);
os.write(buffer, 0, length);
this.updateProgress(i, l);
Thread.sleep(500);
}
is.close();
os.close();
this.notifyAll();
return dest;
}
};
}
New Code:
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.concurrent.CyclicBarrier;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.control.TextArea;
/**
* FXML Controller class
*
* #author ANIL
*/
public class ProgressIndicateController implements Initializable {
#FXML
private ProgressIndicator uploadIndicator;
#FXML
private ProgressBar uploadBar;
#FXML
private TextArea errTxt;
#FXML
private Label uploadTxt;
#FXML
private Label sizeTXT;
CyclicBarrier cb = new CyclicBarrier(2);
final SimpleDoubleProperty prog1 = new SimpleDoubleProperty(0);
final SimpleDoubleProperty prog2 = new SimpleDoubleProperty(0);
final SimpleStringProperty text1 = new SimpleStringProperty("");
final SimpleStringProperty text2 = new SimpleStringProperty("");
final SimpleStringProperty err = new SimpleStringProperty("");
/**
* Initializes the controller class.
*/
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
// Unbind progress property
uploadBar.progressProperty().unbind();
// Bind progress property
uploadBar.progressProperty().bind(prog2);
// Hủy bỏ kết nối thuộc tính progress
uploadIndicator.progressProperty().unbind();
// Bind progress property.
uploadIndicator.progressProperty().bind(prog1);
// Unbind text property for Label.
uploadTxt.textProperty().unbind();
// Bind the text property of Label
// with message property of Task
uploadTxt.textProperty().bind(text1);
// Unbind text property for Label.
sizeTXT.textProperty().unbind();
// Bind the text property of Label
// with message property of Task
sizeTXT.textProperty().bind(text2);
//When completed tasks
errTxt.textProperty().unbind();
errTxt.textProperty().bind(err);
// Start the Task.
new Thread() {
#Override
public void run() {
File dir = new File("F:");
File[] files = dir.listFiles();
int count = files.length;
int i = 0;
for (File file : files) {
if (file.isFile()) {
try {
text1.setValue("Copying: " + file.getAbsolutePath());
InputStream is = null;
OutputStream os = null;
File dest = null;
String name = file.getName();
dest = new File("D:\\OUTPUT\\" + name);
is = new FileInputStream(file);
os = new FileOutputStream(dest);
byte[] buffer = new byte[1024];
int length;
double j = 0.0;
double l = file.length();
while ((length = is.read(buffer)) > 0) {
j += length;
text2.setValue("Copying: " + j + " bytes of " + l);
os.write(buffer, 0, length);
prog2.setValue(j / l);
Thread.sleep(100);
}
is.close();
os.close();
} catch (Exception ex) {
err.setValue(ex.toString());
}
i++;
prog1.setValue(i / count);
}
}
}
}.start();
}
}
I want to add repeatable properties to the Jenkins plugin I'm developing, and created a test plugin to make make sure I was using them correctly. My plugin seems to work fine, I can add as many properties as I want when I originally edit the config, and it saves and builds. However, when I try to edit the config a second time, the config screen shows the loading overlay endlessly. If I scroll down, I can see the properties I saved earlier are still there, but I can't edit anything.
My class looks like this:
public class RepeatableTest extends Builder {
private List<Prop> property = new ArrayList<Prop>();
#DataBoundConstructor
public RepeatableTest(List<Prop> property) {
this.property = property;
}
public List<Prop> getProperty() {
return property;
}
#Override
public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException {
listener.getLogger().println(property.get(0).name);
listener.getLogger().println(property.size());
return true;
}
#Override
public DescriptorImpl getDescriptor() {
return (DescriptorImpl)super.getDescriptor();
}
public static class Prop extends AbstractDescribableImpl<Prop> {
public String name;
public String getName(){
return name;
}
#DataBoundConstructor
public Prop(String name) {
this.name = name;
}
#Extension
public static class DescriptorImpl extends Descriptor<Prop> {
#Override
public String getDisplayName() {
return "";
}
}
}
#Extension // This indicates to Jenkins that this is an implementation of an extension point.
public static final class DescriptorImpl extends BuildStepDescriptor<Builder> {
private String phpLoc;
public DescriptorImpl() {
load();
}
public boolean isApplicable(Class<? extends AbstractProject> aClass) {
// Indicates that this builder can be used with all kinds of project types
return true;
}
public String getDisplayName() {
return "Repeatable Test";
}
#Override
public boolean configure(StaplerRequest req, JSONObject formData) throws FormException {
phpLoc = formData.getString("phpLoc");
save();
return super.configure(req,formData);
}
public String getPhpLoc() {
return phpLoc;
}
}
}
My config.groovy looks like this:
package uitestplugin.uitest.RepeatableTest;
import lib.JenkinsTagLib
import lib.FormTagLib
def f = namespace(lib.FormTagLib)
t=namespace(JenkinsTagLib.class)
f.form{
f.entry(title:"Properties"){
f.repeatableProperty(field:"property")
}
}
and my prop/config.groovy looks like this:
package uitestplugin.uitest.RepeatableTest.Prop;
def f = namespace(lib.FormTagLib)
f.entry(title:"Name", field:"name") {
f.textbox()
}
The config.xml:
<?xml version='1.0' encoding='UTF-8'?>
<project>
<actions/>
<description></description>
<keepDependencies>false</keepDependencies>
<properties/>
<scm class="hudson.scm.NullSCM"/>
<canRoam>true</canRoam>
<disabled>false</disabled>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<triggers/>
<concurrentBuild>false</concurrentBuild>
<builders>
<uitestplugin.uitest.RepeatableTest plugin="ui-test#1.0-SNAPSHOT">
<property>
<uitestplugin.uitest.RepeatableTest_-Prop>
<name>Prop1</name>
</uitestplugin.uitest.RepeatableTest_-Prop>
<uitestplugin.uitest.RepeatableTest_-Prop>
<name>Prop2</name>
</uitestplugin.uitest.RepeatableTest_-Prop>
</property>
</uitestplugin.uitest.RepeatableTest>
</builders>
<publishers/>
<buildWrappers/>
</project>
Any ideas as to what could cause this? I based a lot of the code from the ui-samples plugin (https://wiki.jenkins-ci.org/display/JENKINS/UI+Samples+Plugin).
EDIT: The current status of this is, well, I still haven't figured it out. I've done more research and tried tons of different examples, but the farthest I ever get is what I described above. It almost seems like you can't use repeatable through groovy. Anyways, I have one more piece of information to add. Using the web developer toolbar for Firefox, I can see that there is a Javascript error on the page. The error is:
Timestamp: 10/3/2014 12:58:49 PM
Error: TypeError: prototypes is undefined
Source File: http://localhost:8080/adjuncts/e58fb488/lib/form/hetero-list/hetero-list.js
Line: 16
And the code this relates to is(I've marked line 16 with a comment at the end of the line):
// #include lib.form.dragdrop.dragdrop
// do the ones that extract innerHTML so that they can get their original HTML before
// other behavior rules change them (like YUI buttons.)
Behaviour.specify("DIV.hetero-list-container", 'hetero-list', -100, function(e) {
e=$(e);
if(isInsideRemovable(e)) return;
// components for the add button
var menu = document.createElement("SELECT");
var btns = findElementsBySelector(e,"INPUT.hetero-list-add"),
btn = btns[btns.length-1]; // In case nested content also uses hetero-list
YAHOO.util.Dom.insertAfter(menu,btn);
var prototypes = $(e.lastChild);
while(!prototypes.hasClassName("prototypes")) //LINE 16, ERROR IS HERE
prototypes = prototypes.previous();
var insertionPoint = prototypes.previous(); // this is where the new item is inserted.
// extract templates
var templates = []; var i=0;
$(prototypes).childElements().each(function (n) {
var name = n.getAttribute("name");
var tooltip = n.getAttribute("tooltip");
var descriptorId = n.getAttribute("descriptorId");
menu.options[i] = new Option(n.getAttribute("title"),""+i);
templates.push({html:n.innerHTML, name:name, tooltip:tooltip,descriptorId:descriptorId});
i++;
});
Element.remove(prototypes);
var withDragDrop = initContainerDD(e);
var menuAlign = (btn.getAttribute("menualign")||"tl-bl");
var menuButton = new YAHOO.widget.Button(btn, { type: "menu", menu: menu, menualignment: menuAlign.split("-") });
$(menuButton._button).addClassName(btn.className); // copy class names
$(menuButton._button).setAttribute("suffix",btn.getAttribute("suffix"));
menuButton.getMenu().clickEvent.subscribe(function(type,args,value) {
var item = args[1];
if (item.cfg.getProperty("disabled")) return;
var t = templates[parseInt(item.value)];
var nc = document.createElement("div");
nc.className = "repeated-chunk";
nc.setAttribute("name",t.name);
nc.setAttribute("descriptorId",t.descriptorId);
nc.innerHTML = t.html;
$(nc).setOpacity(0);
var scroll = document.body.scrollTop;
renderOnDemand(findElementsBySelector(nc,"TR.config-page")[0],function() {
function findInsertionPoint() {
// given the element to be inserted 'prospect',
// and the array of existing items 'current',
// and preferred ordering function, return the position in the array
// the prospect should be inserted.
// (for example 0 if it should be the first item)
function findBestPosition(prospect,current,order) {
function desirability(pos) {
var count=0;
for (var i=0; i<current.length; i++) {
if ((i<pos) == (order(current[i])<=order(prospect)))
count++;
}
return count;
}
var bestScore = -1;
var bestPos = 0;
for (var i=0; i<=current.length; i++) {
var d = desirability(i);
if (bestScore<=d) {// prefer to insert them toward the end
bestScore = d;
bestPos = i;
}
}
return bestPos;
}
var current = e.childElements().findAll(function(e) {return e.match("DIV.repeated-chunk")});
function o(did) {
if (Object.isElement(did))
did = did.getAttribute("descriptorId");
for (var i=0; i<templates.length; i++)
if (templates[i].descriptorId==did)
return i;
return 0; // can't happen
}
var bestPos = findBestPosition(t.descriptorId, current, o);
if (bestPos<current.length)
return current[bestPos];
else
return insertionPoint;
}
(e.hasClassName("honor-order") ? findInsertionPoint() : insertionPoint).insert({before:nc});
if(withDragDrop) prepareDD(nc);
new YAHOO.util.Anim(nc, {
opacity: { to:1 }
}, 0.2, YAHOO.util.Easing.easeIn).animate();
Behaviour.applySubtree(nc,true);
ensureVisible(nc);
layoutUpdateCallback.call();
},true);
});
menuButton.getMenu().renderEvent.subscribe(function() {
// hook up tooltip for menu items
var items = menuButton.getMenu().getItems();
for(i=0; i<items.length; i++) {
var t = templates[i].tooltip;
if(t!=null)
applyTooltip(items[i].element,t);
}
});
if (e.hasClassName("one-each")) {
// does this container already has a ocnfigured instance of the specified descriptor ID?
function has(id) {
return Prototype.Selector.find(e.childElements(),"DIV.repeated-chunk[descriptorId=\""+id+"\"]")!=null;
}
menuButton.getMenu().showEvent.subscribe(function() {
var items = menuButton.getMenu().getItems();
for(i=0; i<items.length; i++) {
items[i].cfg.setProperty("disabled",has(templates[i].descriptorId));
}
});
}
});
Behaviour.specify("DIV.dd-handle", 'hetero-list', -100, function(e) {
e=$(e);
e.on("mouseover",function() {
$(this).up(".repeated-chunk").addClassName("hover");
});
e.on("mouseout",function() {
$(this).up(".repeated-chunk").removeClassName("hover");
});
});
I hope this is enough information to solve the problem. Any suggestions (even if they aren't complete answers) are really appreciated.
While not an exact answer, I did find a way to get this working. For some reason, putting the repeatableProperty in an advanced block stopped the javascript error from happening, so everything loaded fine.
So, my config.groovy for RepeatableTest looked like this:
package uitestplugin.uitest.RepeatableTest;
f = namespace(lib.FormTagLib)
f.advanced{
f.entry(title:"Properties"){
f.repeatableProperty(field:"property", minimum:"1"){
}
}
}
My config.groovy for Prop1 looked like this:
package uitestplugin.uitest.Prop1;
def f = namespace(lib.FormTagLib)
f.entry(title:"Name",field:"name") {
f.textbox()
}
f.entry {
div(align:"left") {
input(type:"button",value:"Delete",class:"repeatable-delete")
}
}
My prop 1 looked like this:
public class Prop1 extends AbstractDescribableImpl<Prop1> {
private final String name;
public String getName(){
return name;
}
#DataBoundConstructor
public Prop1( String name) {
this.name = name;
}
#Extension
public static class DescriptorImpl extends Descriptor<Prop1> {
#Override
public String getDisplayName() {
return "";
}
}
}
And my RepeatableTest.java looked like this:
public class RepeatableTest extends Builder {
private final List<Prop1> property;
// Fields in config.jelly must match the parameter names in the "DataBoundConstructor"
#DataBoundConstructor
public RepeatableTest(List<Prop1> property) {
this.property = property;
}
public List<Prop1> getProperty() {
return property;
}
#Override
public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException {
//Doesn't matter
}
#Override
public DescriptorImpl getDescriptor() {
return (DescriptorImpl)super.getDescriptor();
}
#Extension // This indicates to Jenkins that this is an implementation of an extension point.
public static final class DescriptorImpl extends BuildStepDescriptor<Builder> {
private String phpLoc;
public DescriptorImpl() {
load();
}
public boolean isApplicable(Class<? extends AbstractProject> aClass) {
// Indicates that this builder can be used with all kinds of project types
return true;
}
public String getDisplayName() {
return "Repeatable Test";
}
#Override
public boolean configure(StaplerRequest req, JSONObject formData) throws FormException {
phpLoc = formData.getString("phpLoc");
save();
return super.configure(req,formData);
}
public String getPhpLoc() {
return phpLoc;
}
}
}
I'm still new with programming android. I have a problem with my game project. The problem is I have a problem with moveYModifier for sprite to jump when I touch the screen. Other problem is I got an error when I try to make a touch event method. Can somebody help me, so I can understand how to write correctly the method. I do not use engine extension because I think it's enough by using moveYModifier. I already search the answer but I still confuse about it. Thanks.
here my code :
import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.engine.options.EngineOptions;
import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation;
import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.anddev.andengine.entity.modifier.MoveYModifier;
import org.anddev.andengine.entity.modifier.SequenceEntityModifier;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.scene.Scene.IOnSceneTouchListener;
import org.anddev.andengine.entity.scene.background.AutoParallaxBackground;
import org.anddev.andengine.entity.scene.background.ParallaxBackground.ParallaxEntity;
import org.anddev.andengine.entity.sprite.AnimatedSprite;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.entity.util.FPSLogger;
import org.anddev.andengine.input.touch.TouchEvent;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;
import org.anddev.andengine.ui.activity.BaseGameActivity;
public class KetigaMainActivity extends BaseGameActivity implements IOnSceneTouchListener{
private int CAMERA_WIDTH = 800;
private int CAMERA_HEIGHT = 480;
private BitmapTextureAtlas bitmapTextureAtlas;
private TiledTextureRegion playerTextureRegion;
private BitmapTextureAtlas autoParallaxBackgroundTexture;
private TextureRegion parallaxLayerBack;
private TextureRegion parallaxLayerMid;
private TextureRegion parallaxLayerFront;
private TextureRegion parallaxLayerBackMid;
private int jumpHeight = 100;
private int jumpDuration = 2;
private int playerX = CAMERA_WIDTH/2;
private int playerY = CAMERA_HEIGHT - playerTextureRegion.getTileHeight() - (parallaxLayerFront.getHeight()/3);
#Override
public Engine onLoadEngine() {
final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera));
}
#Override
public void onLoadResources(){
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
this.bitmapTextureAtlas = new BitmapTextureAtlas(512, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
this.playerTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.bitmapTextureAtlas, this, "ulat10.png",0,0,4,2);
this.autoParallaxBackgroundTexture = new BitmapTextureAtlas(1024, 1024, TextureOptions.DEFAULT);
this.parallaxLayerFront = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.autoParallaxBackgroundTexture, this, "tanah6.png",0,810);
this.parallaxLayerBack = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.autoParallaxBackgroundTexture, this, "background1.png",0,0);
this.parallaxLayerBackMid = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.autoParallaxBackgroundTexture, this, "gunung3.png",0,490);
this.parallaxLayerMid = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.autoParallaxBackgroundTexture, this, "awan5.png",0,700);
this.mEngine.getTextureManager().loadTextures(this.bitmapTextureAtlas, this.autoParallaxBackgroundTexture);
}
#Override
public Scene onLoadScene(){
new Scene();
this.mEngine.registerUpdateHandler(new FPSLogger());
final Scene scene = new Scene();
final AutoParallaxBackground autoParallaxBackground = new AutoParallaxBackground(0, 0, 0, 5);
autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(0.0f, new Sprite(0, CAMERA_HEIGHT - this.parallaxLayerBack.getHeight(), this.parallaxLayerBack)));
autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(-1/4.0f, new Sprite(0, CAMERA_HEIGHT - this.parallaxLayerBackMid.getHeight() - (parallaxLayerFront.getHeight()/6), this.parallaxLayerBackMid)));
autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(-1/2.0f, new Sprite(0, 0,this.parallaxLayerMid)));
autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(-3.0f, new Sprite(0, CAMERA_HEIGHT - this.parallaxLayerFront.getHeight(), this.parallaxLayerFront)));
scene.setBackground(autoParallaxBackground);
AnimatedSprite player = new AnimatedSprite(playerX, playerY, this.playerTextureRegion);
player.setScaleCenterY(this.playerTextureRegion.getTileHeight());
player.animate(new long[]{100, 100, 100},0 ,2, true);
scene.setOnSceneTouchListener(this);
scene.attachChild(player);
return scene;
}
#Override
public void onLoadComplete(){
}
#Override
public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {
if (pSceneTouchEvent.isActionDown()) {
jump(); // this where I got an error
}
return false;
}
public boolean jump(AnimatedSprite player){
final MoveYModifier moveUpModifier = new MoveYModifier(jumpDuration /2, playerY, playerY + jumpHeight);
final MoveYModifier moveDownModivier = new MoveYModifier(jumpDuration /2, playerY + jumpHeight, playerY );
final SequenceEntityModifier modifier = new SequenceEntityModifier(moveUpModifier, moveDownModivier);
player.registerEntityModifier(new SequenceEntityModifier (modifier));
return true;
}
}
#Override
public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent)
{
if (pSceneTouchEvent.isActionDown())
{
jump(player);
}
return false;
}
You can use the JumpModifier instead
public boolean jump(AnimatedSprite player){
//your innitial y-position
final float innitialYPosition = 120;
//-140 means jump upward, positive move downward
JumpModifier jumpModifier = new JumpModifier(1, fromX, toX, fromY, toY, -140, new IEntityModifier.IEntityModifierListener() {
#Override
public void onModifierStarted(IModifier<IEntity> pModifier, IEntity pItem) {
animatedSprite.stopAnimation(0);
}
#Override
public void onModifierFinished(IModifier<IEntity> pModifier, IEntity pItem) {
animatedSprite.animate(50);
animatedSprite.setY(innitialYPosition);
}
});
animatedSprite.registerEntityModifier(jumpModifier);
}