This is a Tool interface for osp data transfers via XML. @author Wolfgang Christian and Doug Brown @version 0.1
| 24 | * @version 0.1 |
| 25 | */ |
| 26 | public 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 |
no outgoing calls
no test coverage detected