How to call Z-functions from a plugin on ImageJ - plugins

Good Morning
I'm currently doing a plugIn for ImageJ in JAVA that needs to call the function "Maximum Intensity Z-projection", which I know that is already in ImageJ if you go for "Image/Stacks/Z Project...". Documentation here: http://imagej.net/Z-functions#Maximum_Intensity_Z-projection
I know how to call plugins from another plugins, but doing the same thing in this case I get all the time my "Error" message.
public class Maximum_Intensity implements PlugIn{
ImagePlus img = WindowManager.getCurrentImage();
#Override
public void run(String arg0) {
// TODO Auto-generated method stub
Object ZProjector = null;
ZProjector = IJ.runPlugIn(img, "ZProjector", arg0);
if(ZProjector==null){
String arg = "Error";
IJ.showMessage(arg);
}
}
}
How can I do it? Thank you so much.

You can easily use the macro recorder for help to record all commands in ImageJ, see:
https://imagej.nih.gov/ij/docs/guide/146-31.html#sub:Record...
Enable Java for the recorder and then use the "Create" action to create an ImageJ plugin from the recorded interface actions.
In the following example (created with the Recorder) I applied the Max. Intensity function on a stack.
import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.plugin.*;
public class My_Plugin implements PlugIn {
public void run(String arg) {
ImagePlus imp = IJ.openImage("http://imagej.nih.gov/ij/images/mri-stack.zip");
IJ.run(imp, "Z Project...", "projection=[Max Intensity]");
imp.show();
}
}
The ZProjector class description can be found here (for instantiation):
https://imagej.nih.gov/ij/developer/api/ij/plugin/ZProjector.html

Related

UnsatisfiedLinkError using Serial port from Processing in Eclipse

I have a processing program that is supposed to read the data from a serial port created by an arduino uno. I got the program to work perfectly in Processing but not in Eclipse. I added core.jar serial.jar and jssc.jar to my java project's build path, but am still getting an error calling the port with Serial.list()[0].
I have seen similar questions on here, but none have helpful answers. I don't know if I'm missing something or need to import a different jar file to my build path.
import processing.core.PApplet;
import processing.serial.*;
public class Processing extends PApplet {
public Processing() {
// TODO Auto-generated constructor stub
}
public static void main(String[] args) {
PApplet.main("Processing");
}
Serial myPort;
String val;
public void setup() {
myPort = new Serial(this, Serial.list()[0], 9600);
}
public void draw() {
if ( myPort.available() > 0) {
val = myPort.readString();
}
if (val != null) {
println(val);
}
delay(250);
}
}
Error Message:
java.lang.UnsatisfiedLinkError: jssc.SerialNativeInterface.getSerialPortNames()[Ljava/lang/String;
at jssc.SerialNativeInterface.getSerialPortNames(Native Method)
at jssc.SerialPortList.getWindowsPortNames(SerialPortList.java:309)
at jssc.SerialPortList.getPortNames(SerialPortList.java:298)
at jssc.SerialPortList.getPortNames(SerialPortList.java:182)
at processing.serial.Serial.list(Unknown Source)
at Performance.Processing.setup(Processing.java:44)
at processing.core.PApplet.handleDraw(PApplet.java:2425)
at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1547)
at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:313)
You have added jssc.jar to the Java Build Path which is great, however jssc uses a native c++ library which you need to also reference:
From the Java Build Path > Libraries section
use the arrow to expand jssc.jar and select Native library location
click Edit... on the right hand side and select the folder containing the native c++ library for your OS (in my case that's macosx right now)
Once you apply the changes, the link error will be satisfied.

Selenium WebDriver Stale Element Reference Exception for GWT

Ok I read all the other links, and i tried variants of the different solutions mentioned, however none of them work for me.
My Issue, I have the following Code:
package com.autotest.test.css;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
import com.google.common.base.Predicate;
import java.util.concurrent.TimeUnit;
import cucumber.annotation.*;
import cucumber.annotation.en.*;
import static org.junit.Assert.assertEquals;
public class SaleStepsPre {
private WebDriver driver;
private String baseUrl;
#Before
public void setUp() {
System.setProperty("webdriver.chrome.driver", "/Users/AppData/Local/Google/Chrome/Application/chromedriver.exe");
driver = new ChromeDriver();
baseUrl = "http://xxxxx";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#Given("^I navigate to the css application$")
public void I_navigate_to_the_css_application() {
driver.get(baseUrl + "/care/a#brochureware-home");
}
#When("^I select the prepaid catalog$")
public void I_select_the_prepaid_catalog() {
driver.findElement(By.xpath("//div[#id='brochureware-home']/div/div/div/div[2]/div[2]/div/div")).click();
}
#When("^I select the add to basket for product$")
public void I_select_the_add_to_basket_for_product() {
driver.findElement(By.xpath("//*[#id='salesItem']/div[1]/div[1]/div/div[5]/div[1]/button")).click();
}
#When("^then I Click on the basket icon to go to basket$")
public void then_I_Click_on_the_basket_icon_to_go_to_basket() {
// times out after 5 seconds
// while the following loop runs, the DOM changes -
// page is refreshed, or element is removed and re-added
//driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//WebElement searchBox;
//searchBox = driver.findElement(By.xpath("//input[#type='text']"));
//driver.findElement(By.xpath("html/body/div[2]/div[1]/nav/div[1]/div[3]/div[2]/div/ul[1]/li[5]/a/img")).click();
driver.findElement(By.cssSelector("c-menuimage")).click();
}
//#When("^then I click on the checkout button$")
//public void then_I_click_on_the_checkout_button() {
//driver.findElement(By.xpath("(//button[#type='button'])[9]")).click();
//}
#Then("^show product y$")
public void show_product_y() {
}
}
However I get following error:
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
B
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
This is the css path of basket icon, which is on a menu.
body > div:nth-child(3) > div:nth-child(1) > nav > div.container-fluid.c-wide > div.c-kill > div.collapse.navbar-collapse.c-2ndmenu > div > ul.nav.navbar-nav.navbar-left > li:nth-child(5) > a > img
The website is GWT, and the steps are:
1. Click on item add to basket
2. Adds to basket
3. Click on basket to go to basket.
However I cant seem to get this right.
I had problems, that the implicit wait only works for real page reloads, when the page is dynamicaly reloaded (like ajax) , then this will fail.
You can try expected conditions to wait for for items, they are nice and easy to use and robust. You can configure them to ignore certain exceptions,
so you can try to locate an element for a given time and then fail. This works even with ajax
In my case i have a small method like (it ignored the NoSuchElement exception):
protected <T> T waitForPageToLoad(ExpectedCondition<T> condition, String errorMessage) {
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(MAX_WAITING_TIME, SECONDS).ignoring(StaleElementReferenceException.class).ignoring(NoSuchElementException.class).pollingEvery(100, MILLISECONDS).withMessage(errorMessage);
T result = wait.until(condition);
return result;
}
MAX_WAITING_TIME is the time until this method throws an exception
Then you can use this with an expected condition like this:
public static final ExpectedCondition<Boolean> WAIT_FOR_BASKET = ExpectedConditions.visibilityOfElementLocated(By.cssSelector("c-menuimage"));
I have plenty of them in a utility class so they are static. you can do it like you want.
The full usage looks like:
WebElement elem = waitForPageToLoad(waitForPageToLoad);
elem.click();
This solution is originated here at stack overflow but i cant find the original question/answer, so kudos to the real guy who posted this

Play framework 2 + JPA with multiple persistenceUnit

I'm struggling with Play and JPA in order to be able to use two different javax.persistence.Entity model associated to two different persistence units (needed to be able to connect to different DB - for example an Oracle and a MySQL db).
The problem come from the Transaction which is always bind to the default JPA persitenceUnit (see jpa.default option).
Here is two controller actions which show the solution I found to manually define the persistence :
package controllers;
import models.Company;
import models.User;
import play.db.jpa.JPA;
import play.db.jpa.Transactional;
import play.mvc.Controller;
import play.mvc.Result;
public class Application extends Controller {
//This method run with the otherPersistenceUnit
#Transactional(value="other")
public static Result test1() {
JPA.em().persist(new Company("MyCompany"));
//Transaction is run with the "defaultPersistenceUnit"
JPA.withTransaction(new play.libs.F.Callback0() {
#Override
public void invoke() throws Throwable {
JPA.em().persist(new User("Bobby"));
}
});
return ok();
}
//This action run with the otherPersistenceUnit
#Transactional
public static Result test2() {
JPA.em().persist(new User("Ryan"));
try {
JPA.withTransaction("other", false, new play.libs.F.Function0<Void>() {
public Void apply() throws Throwable {
JPA.em().persist(new Company("YourCompany"));
return null;
}
});
} catch (Throwable throwable) {
throw new RuntimeException(throwable);
}
return ok();
}
}
This solution doesn't seem to be really "clean". I'd like to know if you know a better way to avoid the need to manually modify the transaction used.
For this purpose, I created a repo on git with a working sample application which shows how I configured the project.
https://github.com/cm0s/play2-jpa-multiple-persistenceunit
Thank you for your help
i met the same problem, too. too many advices are about PersistenceUnit annotation or getJPAConfig. but both them seem not work in play framework.
i found out a method which works well in my projects. maybe you can try it.
playframework2 how to open multi-datasource configuration with jpa
gud luk!

Writing to stdout from an Eclipse plugin

My aim is to extend the eclipse QuickFix component and automate the process of solving syntax errors. Basically, the QuickFix component provides a list of solutions and my task is to select the best possible fix and apply it to the buggy code. But, for now I've been requested to print the resolutions for a marker in the console. I've tried to work out a tutorial and I'm kind of stuck right now. The tutorial I've tried to workout is: http://www.informit.com/articles/article.aspx?p=370625&seqNum=21
I've first added the extension in my plugin.xml file
<extension point="org.eclipse.ui.ide.markerResolution">
<markerResolutionGenerator
markerType="org.eclipse.core.resources.problemmarker"
class="org.eclipse.escript.quickfix.QuickFixer"/>
</extension>
Then i have created the two classes QuickFixer and QuickFix.
package quickfixer;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.ui.IMarkerResolution;
import org.eclipse.ui.IMarkerResolutionGenerator;
class QuickFixer implements IMarkerResolutionGenerator {
public IMarkerResolution[] getResolutions(IMarker arg0) {
try {
Object problem = arg0.getAttribute("Whatsup");
return new IMarkerResolution[] {
new QuickFix("Fix #1 for "+problem),
new QuickFix("Fix #2 for "+problem),
};
} catch(CoreException e) {
return new IMarkerResolution[0];
}
}
}
then the class QuickFix:
package quickfixer;
import org.eclipse.core.resources.IMarker;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.IMarkerResolution;
public class QuickFix implements IMarkerResolution {
String label;
QuickFix(String label) {
this.label = label;
}
public String getLabel() {
return label;
}
public void run(IMarker arg0) {
MessageDialog.openInformation(null, "QuickFix Demo",
"This quick-fix is not yet implemented");
System.out.println("Label: " + label);
}
}
I've managed to correct all the errors i encountered and then i have run the plugin.
I have not been able to get the label printed out in the console.Any suggestions???...
Using System.out is not a good idea. Check the relevant FAQ on why
you should avoid using standard output or standard error in your
plug-in
and use proper logging (or the debugger).

How to get input from Output tab in NetBeans

I have an Output tab created and I would like to listen for user's input (to do a chat like component). Of course you can't predict when the user is going to type.
I found the org.jivesoftware.smack.util package and the related ObservableReader and ReaderListener that should do the trick, but I'm missing something and can't figure it out... yet.
Here's the code I have:
/*
* Enable/create the tabs we need for the component
*/
package sample.component;
import com.dreamer.outputhandler.OutputHandler;
import org.jivesoftware.smack.util.ObservableReader;
import org.jivesoftware.smack.util.ReaderListener;
import org.openide.modules.ModuleInstall;
/**
* Manages a module's lifecycle. Remember that an installer is optional and
* often not needed at all.
*/
public class Installer extends ModuleInstall implements ReaderListener {
private final String normal = "Output";
#Override
public void restored() {
OutputHandler.output(normal, "Welcome! Type something below.");
OutputHandler.setInputEnabled(normal, true);
ObservableReader reader = new ObservableReader(OutputHandler.getReader(normal));
reader.addReaderListener(this);
}
#Override
public void read(String read) {
System.out.println("Read: " + read);
OutputHandler.output(normal, "You typed: " + read);
}
}
OutPutHandler is a helper class I created to handle the output tabs. You can see its source here
Any idea?
Finally got it! It was a mix of the above code with this forum post and this classes: org.jivesoftware.smack.util.ObservableReader and org.jivesoftware.smack.util.ReaderListener. See the FAQ here