当前位置: 首页>>代码示例>>Java>>正文


Java Context类代码示例

本文整理汇总了Java中org.scijava.Context的典型用法代码示例。如果您正苦于以下问题:Java Context类的具体用法?Java Context怎么用?Java Context使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Context类属于org.scijava包,在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ScijavaKernel

import org.scijava.Context; //导入依赖的package包/类
public ScijavaKernel(final Context context, final String id, final ScijavaEvaluator evaluator,
    ScijavaKernelConfigurationFile config, KernelSocketsFactory kernelSocketsFactory) {

super(id, evaluator, kernelSocketsFactory);
this.context = context;
this.context.inject(this);
this.config = config;

// Don't show output when it is null
Kernel.showNullExecutionResult = false;

this.setLogLevel(config.getLogLevel());
log.info("Log level used is : " + this.config.getLogLevel());

log.info("Scijava Kernel is started and ready to use.");
   }
 
开发者ID:scijava,项目名称:scijava-jupyter-kernel,代码行数:17,代码来源:ScijavaKernel.java

示例2: main

import org.scijava.Context; //导入依赖的package包/类
public static void main(String... args) {
final Context context = new Context();

// Remove the Display and Results post-processors to prevent output
// windows from being displayed
final PluginService pluginService = context.service(PluginService.class);
final PluginInfo<SciJavaPlugin> display = pluginService.getPlugin(DisplayPostprocessor.class);
final PluginInfo<SciJavaPlugin> results = pluginService.getPlugin(ResultsPostprocessor.class);
pluginService.removePlugin(display);
pluginService.removePlugin(results);

JupyterService jupyter = context.service(JupyterService.class);
jupyter.runKernel(args);

context.dispose();
   }
 
开发者ID:scijava,项目名称:scijava-jupyter-kernel,代码行数:17,代码来源:ScijavaKernel.java

示例3: main

import org.scijava.Context; //导入依赖的package包/类
public static void main(String[] args) throws ScriptException {
    // Only for testing purpose

    Context context = new Context();
    ScriptService scriptService = context.getService(ScriptService.class);
    ScriptLanguage scriptLanguage = scriptService.getLanguageByName("python");
    ScriptEngine engine = scriptLanguage.getScriptEngine();

    Object result = engine.eval("p=999\n555");
    System.out.println(result);

    scriptService = context.getService(ScriptService.class);
    scriptLanguage = scriptService.getLanguageByName("python");
    engine = scriptLanguage.getScriptEngine();
    
    result = engine.eval("555");
    System.out.println(result);

    context.dispose();
}
 
开发者ID:scijava,项目名称:scijava-jupyter-kernel,代码行数:21,代码来源:TestScriptEngine.java

示例4: testLocals

import org.scijava.Context; //导入依赖的package包/类
@Test
	public void testLocals() throws ScriptException {
		final Context context = new Context(ScriptService.class);
		final ScriptService scriptService = context.getService(ScriptService.class);

		final ScriptLanguage language = scriptService.getLanguageByExtension("kt");
		final ScriptEngine engine = language.getScriptEngine();
		assertTrue(engine.getFactory().getNames().contains("kotlin"));

		engine.put("hello", 17);
		assertEquals("17", engine.eval("bindings[\"hello\"]").toString());
		assertEquals("17", engine.get("hello").toString());

		engine.put("foo", "bar");
		assertEquals("bar", engine.eval("bindings[\"foo\"]").toString());
		assertEquals("bar", engine.get("foo").toString());
		// FIXME: You cannot modify or insert a variable in the bindings!
//		engine.eval("bindings[\"foo\"] = \"great\"");
//		assertEquals("great", engine.eval("bindings[\"foo\"]").toString());
//		assertEquals("great", engine.get("foo").toString());

		final Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
		bindings.clear();
		assertNull(engine.get("hello"));
	}
 
开发者ID:scijava,项目名称:scripting-kotlin,代码行数:26,代码来源:KotlinTest.java

示例5: write

import org.scijava.Context; //导入依赖的package包/类
public void write(Dataset data, FileLinkElement elementToWrite)
        throws SlideSetException {
    final Context context = data.getContext();
    String path = elementToWrite.getUnderlying();
    path = elementToWrite.getOwner().resolvePath(path);
    final File pathF = new File(path);
    if(!pathF.getParentFile().exists())
        try {
            pathF.getParentFile().mkdirs();
        } catch(Exception ex) {
            throw new LinkNotFoundException(
                    path + " could not be created.", ex);
        }
    try {
        if(pathF.exists())
            pathF.delete(); // This is less than ideal, but there seems to be an ImageJ bug overwriting exisiting images, especially if the new image has different dimensions.
        context.getService(DatasetService.class).save(data, path);
    } catch(Exception e) {
        throw new ImgLinkException(e);
    }
}
 
开发者ID:bnanes,项目名称:slideset,代码行数:22,代码来源:DatasetToImageFileWriter.java

示例6: setUp

import org.scijava.Context; //导入依赖的package包/类
@Override
@Before
public void setUp() {
	context = new Context(OpService.class);
	ops = context.service(OpService.class);

	in = ArrayImgs.bytes(20, 20, 21);
	out = ArrayImgs.bytes(20, 20, 21);

	// fill array img with values (plane position = value in px);

	for (final Cursor<ByteType> cur = in.cursor(); cur.hasNext();) {
		cur.fwd();
		cur.get().set((byte) cur.getIntPosition(2));
	}
}
 
开发者ID:imagej,项目名称:imagej-ops,代码行数:17,代码来源:SliceTest.java

示例7: testLocals

import org.scijava.Context; //导入依赖的package包/类
@Test
public void testLocals() throws ScriptException {
	final Context context = new Context(ScriptService.class);
	final ScriptService scriptService = context.getService(ScriptService.class);

	final ScriptLanguage language = scriptService.getLanguageByExtension("r");
	final ScriptEngine engine = language.getScriptEngine();
	assertEquals(RenjinScriptEngine.class, engine.getClass());
	engine.put("hello", 17);
	assertEquals(17, RenjinUtils.getJavaValue((SEXP) engine.eval("hello")));
	assertEquals(17, RenjinUtils.getJavaValue((SEXP) engine.get("hello")));

	final Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
	bindings.clear();
	assertNull(RenjinUtils.getJavaValue((SEXP) engine.get("hello")));
	assertNull(RenjinUtils.getJavaValue((SEXP) engine.get("polar_kraken")));
}
 
开发者ID:scijava,项目名称:scripting-renjin,代码行数:18,代码来源:RenjinTest.java

示例8: testParameters

import org.scijava.Context; //导入依赖的package包/类
@Test
public void testParameters() throws InterruptedException, ExecutionException, IOException, ScriptException {
	final Context context = new Context(ScriptService.class);
	final ScriptService scriptService = context.getService(ScriptService.class);

	final String script = "" + //
			"# @ScriptService ss\n" + //
			"# @OUTPUT String name\n" + //
			"language <- ss$getLanguageByName('Renjin')\n" + //
			"name <- language$languageName\n";
	final ScriptModule m = scriptService.run("hello.r", script, true).get();

	final Object actual = m.getOutput("name");
	final String expected = scriptService.getLanguageByName("Renjin").getLanguageName();
	assertEquals(expected, actual);
}
 
开发者ID:scijava,项目名称:scripting-renjin,代码行数:17,代码来源:RenjinTest.java

示例9: TiffSaver

import org.scijava.Context; //导入依赖的package包/类
/**
 * Constructs a new TIFF saver from the given output source.
 *
 * @param out Output stream to save TIFF data to.
 * @param filename Filename of the output stream that we may use to create
 *          extra input or output streams as required.
 */
public TiffSaver(final Context ctx, final RandomAccessOutputStream out,
	final String filename)
{
	if (out == null) {
		throw new IllegalArgumentException(
			"Output stream expected to be not-null");
	}
	if (filename == null) {
		throw new IllegalArgumentException("Filename expected to be not null");
	}
	this.out = out;
	this.filename = filename;
	setContext(ctx);
	scifio = new SCIFIO(ctx);
	log = scifio.log();
}
 
开发者ID:scifio,项目名称:scifio,代码行数:24,代码来源:TiffSaver.java

示例10: Location

import org.scijava.Context; //导入依赖的package包/类
public Location(final Context context, final String pathname) {
	this(context);
	log().trace("Location(" + pathname + ")");

	final Matcher m = urlPattern.matcher(pathname);
	if(m.find()) {
		try {
			url = new URL(locationService.getMappedId(pathname));
		}
		catch (final MalformedURLException e) {
			log().trace("Location is not a URL", e);
			isURL = false;
		}
	}
	else {
		isURL = false;
	}
	if (!isURL) file = new File(locationService.getMappedId(pathname));
}
 
开发者ID:scifio,项目名称:scifio,代码行数:20,代码来源:Location.java

示例11: createMock

import org.scijava.Context; //导入依赖的package包/类
@Override
public IRandomAccess createMock(final byte[] page, final String mode,
	final int bufferSize) throws IOException
{
	final File pageFile = File.createTempFile("page", ".dat");
	final OutputStream stream = new FileOutputStream(pageFile);
	try {
		stream.write(page);
	}
	finally {
		stream.close();
	}
	final Context context = new Context(NIOService.class);
	final NIOService nioService = context.getService(NIOService.class);
	return new NIOFileHandle(nioService, pageFile, mode, bufferSize);
}
 
开发者ID:scifio,项目名称:scifio,代码行数:17,代码来源:NIOFileHandleProvider.java

示例12: run

import org.scijava.Context; //导入依赖的package包/类
/**
 * This method is called when the plugin is loaded. See
 * {@link ij.plugin.PlugIn#run(java.lang.String)} Prompts user for a new
 * snippet that will be saved in {@code BAR/My_Routines/}
 *
 * @param arg
 *            ignored (Otherwise specified in plugins.config).
 */
@Override
public void run(final String arg) {
	Utils.shiftClickWarning();
	if (new GuiUtils().getFileCount(Utils.getLibDir()) == 0) {
		final YesNoCancelDialog query = new YesNoCancelDialog(null, "Install lib Files?",
				"Some of the code generated by this plugin assumes the adoption\n"
						+ "of centralized lib files, but none seem to exist in your local directory\n" + "("
						+ Utils.getLibDir() + ")\nWould you like to install them now?");
		if (query.cancelPressed()) {
			return;
		} else if (query.yesPressed()) {
			final Context context = (Context) IJ.runPlugIn("org.scijava.Context", "");
			final CommandService commandService = context.getService(CommandService.class);
			commandService.run(Installer.class, true);
			return;
		}
	}
	if (showDialog()) {
		if (sContents.length()>0)
			saveAndOpenSnippet();
		else
			IJ.showStatus(sFilename +" was empty. No file was saved...");
	}

}
 
开发者ID:tferr,项目名称:Scripts,代码行数:34,代码来源:SnippetCreator.java

示例13: testBasic

import org.scijava.Context; //导入依赖的package包/类
@Test
public void testBasic() throws Exception {
	final Context context = new Context(ScriptService.class);
	final ScriptService scriptService = context.getService(ScriptService.class);

	final ScriptLanguage language =
		scriptService.getLanguageByExtension("scala");
	final ScriptEngine engine = language.getScriptEngine();

	final SimpleScriptContext ssc = new SimpleScriptContext();
	final StringWriter writer = new StringWriter();
	ssc.setWriter(writer);

	final String script = "print(\"3\");";
	engine.eval(script, ssc);
	assertEquals("3", writer.toString());
}
 
开发者ID:scijava,项目名称:scripting-scala,代码行数:18,代码来源:ScalaTest.java

示例14: main

import org.scijava.Context; //导入依赖的package包/类
public static void main(String... args) {
    Context context = new Context();

    LogService log = context.service(LogService.class);
    log.setLevel(LogLevel.INFO);

    JupyterService jupyter = context.service(JupyterService.class);
    jupyter.installKernel(args);

    context.dispose();
}
 
开发者ID:scijava,项目名称:scijava-jupyter-kernel,代码行数:12,代码来源:InstallScijavaKernel.java

示例15: main

import org.scijava.Context; //导入依赖的package包/类
public static void main(final String[] args) {

        // Warning : if run from your IDE the classpath won't be set to your Fiji installation
        Context context = new Context();
        JupyterService jupyter = context.service(JupyterService.class);
        jupyter.runKernel("jython", "info", "");
        context.dispose();
    }
 
开发者ID:scijava,项目名称:scijava-jupyter-kernel,代码行数:9,代码来源:TestRunKernel.java


注:本文中的org.scijava.Context类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。