MCPcopy Index your code
hub / github.com/OpenSourcePhysics/osp / Tool

Interface Tool

src/org/opensourcephysics/tools/Tool.java:26–74  ·  view source on GitHub ↗

This is a Tool interface for osp data transfers via XML. @author Wolfgang Christian and Doug Brown @version 0.1

Source from the content-addressed store, hash-verified

24 * @version 0.1
25 */
26public interface Tool {
27 /**
28 * Sends a job to this tool and specifies a tool to reply to.
29 *
30 * @param job the Job
31 * @param replyTo the tool to notify when the job is complete (may be null)
32 */
33 public void send(Job job, Tool replyTo);
34
35 /**
36 *
37 * @param item
38 * @param data
39 * @param replyTo
40 * @param andDisplay
41 * @param toolClass
42 */
43 static boolean setSendAction(JMenuItem item, String toolName, Object data, Tool replyTo, boolean andDisplay) {
44 try {
45 Class<?> toolClass = Class.forName("org.opensourcephysics.tools." + toolName); //$NON-NLS-1$
46 item.addActionListener((e) -> {
47 try {
48 Method m = toolClass.getMethod("getTool", (Class[]) null); //$NON-NLS-1$
49 Tool tool = (Tool) m.invoke(null, (Object[]) null);
50 tool.send(new LocalJob(data), replyTo);
51 if (andDisplay) {
52 if (tool instanceof OSPFrame) {
53 ((OSPFrame) tool).setKeepHidden(false);
54 }
55 ((JFrame) tool).setVisible(true);
56 }
57 } catch (Exception ex) {
58 ex.printStackTrace();
59 }
60 });
61 return true;
62 } catch (Exception ex) {
63 ex.printStackTrace();
64 OSPLog.finest("Cannot instantiate " + toolName + ":\n" + ex.getMessage()); //$NON-NLS-1$
65 return false;
66 }
67 }
68
69 public static void reply(Tool replyTo, Job job, Tool from, Data reply) {
70 job.setXML(new XMLControlElement(reply).toXML());
71 replyTo.send(job, from);
72 }
73
74}
75
76/*
77 * Open Source Physics software is free software; you can redistribute it and/or

Callers 7

sendRepliesMethod · 0.95
actionPerformedMethod · 0.65
loadToolsMenuMethod · 0.95
loadToolsMenuMethod · 0.95
createMenuBarMethod · 0.95
loadToolsMenuMethod · 0.95
sendMethod · 0.95

Implementers 9

JarToolsrc/org/opensourcephysics/tools/JarToo
DataToolTabsrc/org/opensourcephysics/tools/DataTo
DataRefreshToolsrc/org/opensourcephysics/tools/DataRe
DataToolsrc/org/opensourcephysics/tools/DataTo
SnapshotToolsrc/org/opensourcephysics/tools/Snapsh
ExportToolsrc/org/opensourcephysics/tools/Export
TranslatorToolsrc/org/opensourcephysics/tools/Transl
EncryptionToolsrc/org/opensourcephysics/tools/Encryp
VideoCaptureToolsrc/org/opensourcephysics/tools/VideoC

Calls

no outgoing calls

Tested by

no test coverage detected