MCPcopy Create free account
hub / github.com/OpenSourcePhysics/osp / ArrowLoader

Class ArrowLoader

src/org/opensourcephysics/display/ArrowLoader.java:16–61  ·  view source on GitHub ↗

A class to save and load Arrow objects in an XMLControl.

Source from the content-addressed store, hash-verified

14 * A class to save and load Arrow objects in an XMLControl.
15 */
16public class ArrowLoader extends XMLLoader {
17 /**
18 * Saves the Arrow's data in the xml control.
19 * @param control XMLControl
20 * @param obj Object
21 */
22 @Override
23public void saveObject(XMLControl control, Object obj) {
24 Arrow arrow = (Arrow) obj;
25 control.setValue("x", arrow.x); //$NON-NLS-1$
26 control.setValue("y", arrow.y); //$NON-NLS-1$
27 control.setValue("a", arrow.a); //$NON-NLS-1$
28 control.setValue("b", arrow.b); //$NON-NLS-1$
29 control.setValue("head size", arrow.headSize); //$NON-NLS-1$
30 control.setValue("color", arrow.color); //$NON-NLS-1$
31 }
32
33 /**
34 * Creates an Arrow.
35 * @param control XMLControl
36 * @return Object
37 */
38 @Override
39public Object createObject(XMLControl control) {
40 return new Arrow(0, 0, 0, 0);
41 }
42
43 /**
44 * Loads data from the xml control into the Arrow object.
45 * @param control XMLControl
46 * @param obj Object
47 * @return Object
48 */
49 @Override
50public Object loadObject(XMLControl control, Object obj) {
51 Arrow arrow = (Arrow) obj;
52 arrow.x = control.getDouble("x"); //$NON-NLS-1$
53 arrow.y = control.getDouble("y"); //$NON-NLS-1$
54 arrow.a = control.getDouble("a"); //$NON-NLS-1$
55 arrow.b = control.getDouble("b"); //$NON-NLS-1$
56 arrow.headSize = (float) control.getDouble("head size"); //$NON-NLS-1$
57 arrow.color = (Color) control.getObject("color"); //$NON-NLS-1$
58 return obj;
59 }
60
61}
62
63/*
64 * Open Source Physics software is free software; you can redistribute

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected