本文整理汇总了Java中org.opensourcephysics.controls.XMLControlElement类的典型用法代码示例。如果您正苦于以下问题:Java XMLControlElement类的具体用法?Java XMLControlElement怎么用?Java XMLControlElement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XMLControlElement类属于org.opensourcephysics.controls包,在下文中一共展示了XMLControlElement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: open
import org.opensourcephysics.controls.XMLControlElement; //导入依赖的package包/类
/**
* Opens an xml or data file specified by name.
*
* @param fileName the file name
* @return the file name, if successfully opened
*/
public String open(String fileName) {
dataList = null;
data = null;
OSPLog.fine("opening "+fileName); //$NON-NLS-1$
Resource res = ResourceLoader.getResource(fileName);
if(res!=null) {
Reader in = res.openReader();
String firstLine = readFirstLine(in);
// if xml, read the file into an XML control and add tab
if(firstLine.startsWith("<?xml")) { //$NON-NLS-1$
XMLControlElement control = new XMLControlElement(fileName);
dataList = control.getObjects(Data.class);
return fileName;
}
// if not xml, attempt to import data and add tab
else if(res.getString()!=null) {
data = parseData(res.getString(), fileName);
if(data!=null) {
return fileName;
}
}
}
OSPLog.finest("no data found"); //$NON-NLS-1$
return null;
}
示例2: setFixed
import org.opensourcephysics.controls.XMLControlElement; //导入依赖的package包/类
/**
* Sets the fixed position behavior (all frames identical).
*
* @param fix true to set the corner positions the same in all frames
* @param in true for input corners, false for output
*/
public void setFixed(boolean fix, boolean in) {
if (isFixed(in)!=fix) {
String filterState = new XMLControlElement(this).toXML();
if (in) fixedIn = fix;
else fixedOut = fix;
if (isFixed(in)) {
TreeSet<Integer> keyFrames = in? inKeyFrames: outKeyFrames;
keyFrames.clear();
saveCorners(fixedKey, in); // save input corners
}
support.firePropertyChange("fixed", filterState, null); //$NON-NLS-1$
}
}
示例3: setVideo
import org.opensourcephysics.controls.XMLControlElement; //导入依赖的package包/类
/**
* Sets the video.
*
* @param newVideo the video
* @param playAllSteps true to play all steps
*/
public void setVideo(Video newVideo, boolean playAllSteps) {
if(newVideo==video) {
return;
}
Video prev = video;
VideoClip prevClip = getPlayer().getVideoClip();
VideoClip newClip = new VideoClip(newVideo);
if (newVideo==null && prevClip!=null) {
XMLControl control = new XMLControlElement(prevClip);
control.setValue("video", null); //$NON-NLS-1$
control.loadObject(newClip);
}
newClip.setPlayAllSteps(playAllSteps);
getPlayer().setVideoClip(newClip);
if(prev!=null) {
prev.dispose();
}
}
示例4: clone
import org.opensourcephysics.controls.XMLControlElement; //导入依赖的package包/类
/**
* Returns a clone of the specified video.
*
* @param video the video to clone
* @return the clone
*/
public static Video clone(Video video) {
if(video==null) {
return null;
}
// ImageVideo is special case since may have pasted images
if(video instanceof ImageVideo) {
ImageVideo oldVid = (ImageVideo) video;
ImageVideo newVid = new ImageVideo(oldVid.getImages());
newVid.rawImage = newVid.images[0];
Collection<Filter> filters = video.getFilterStack().getFilters();
if(filters!=null) {
Iterator<Filter> it = filters.iterator();
while(it.hasNext()) {
Filter filter = it.next();
newVid.getFilterStack().addFilter(filter);
}
}
return newVid;
}
XMLControl control = new XMLControlElement(video);
return(Video) new XMLControlElement(control).loadObject(null);
}
示例5: send
import org.opensourcephysics.controls.XMLControlElement; //导入依赖的package包/类
@Override
public void send(Job job, Tool replyTo) throws RemoteException {
XMLControl control = new XMLControlElement();
control.readXML(job.getXML());
if (control.failedToRead()) return;
int sourceID = control.getInt("sourceID"); //$NON-NLS-1$
if (control.getBoolean("handshake")) { //$NON-NLS-1$
connected = true;
support.firePropertyChange("tracker_ready", sourceID, null); //$NON-NLS-1$
}
else if (control.getBoolean("exiting")) { //$NON-NLS-1$
remoteTool = null;
connected = false;
support.firePropertyChange("tracker_exited", null, null); //$NON-NLS-1$
}
}
示例6: getVideo
import org.opensourcephysics.controls.XMLControlElement; //导入依赖的package包/类
/**
* Opens a named image as an ImageVideo.
*
* @param name the name of the image
* @return a new image video
*/
public Video getVideo(String name) {
// if an XML file with the image name is found, load it in order to get frame duration
String xmlName = XML.stripExtension(name)+".xml"; //$NON-NLS-1$
XMLControl control = new XMLControlElement(xmlName);
if (!control.failedToRead() && control.getObjectClass()==ImageVideo.class) {
return (Video)control.loadObject(null);
}
// else load image(s) directly
try {
Video video = new ImageVideo(name, true);
video.setProperty("video_type", this); //$NON-NLS-1$
return video;
} catch(IOException ex) {
return null;
}
}
示例7: export
import org.opensourcephysics.controls.XMLControlElement; //导入依赖的package包/类
public void export(File file, List<Object> data) {
FileWriter fw = null;
try {
fw = new FileWriter(file);
} catch(IOException ex) {
JOptionPane.showMessageDialog(null, ToolsRes.getString("ExportFormat.Dialog.WriteError.Message"), //$NON-NLS-1$
ToolsRes.getString("ExportFormat.Dialog.WriteError.Title"), //$NON-NLS-1$
JOptionPane.ERROR_MESSAGE);
return;
}
PrintWriter pw = new PrintWriter(fw);
Iterator<Object> it = data.iterator();
while(it.hasNext()) {
XMLControl control = new XMLControlElement(it.next()); // convert the data to xml
pw.print(control.toXML());
pw.println();
}
pw.close();
}
示例8: main
import org.opensourcephysics.controls.XMLControlElement; //导入依赖的package包/类
/**
* Main entry point when used as application.
*
* @param args args[0] may be an xml file name
*/
public static void main(String[] args) {
// java.util.Locale.setDefault(new java.util.Locale("es"));
// OSPLog.setLevel(ConsoleLevel.ALL);
// get current memory size
java.lang.management.MemoryMXBean memory
= java.lang.management.ManagementFactory.getMemoryMXBean();
long memorySize = memory.getHeapMemoryUsage().getMax()/(1024*1024);
// open default xset, if any, and look for desired memory size
if (OSPRuntime.getLaunchJarName()!=null) {
String xset = XML.stripExtension(OSPRuntime.getLaunchJarName())+".xset"; //$NON-NLS-1$
String jarBase = OSPRuntime.getLaunchJarDirectory();
String path = XML.getResolvedPath(xset, jarBase);
XMLControl control = new XMLControlElement(path);
if (!control.failedToRead() && control.getPropertyNames().contains("memory_size")) { //$NON-NLS-1$
memorySize = control.getInt("memory_size"); //$NON-NLS-1$
}
}
start(args, memorySize);
}
示例9: addOSPLibrary
import org.opensourcephysics.controls.XMLControlElement; //导入依赖的package包/类
/**
* Adds an OSP-sponsored library. OSP libraries are not under user control.
*
* @param path the library path
* @return true if successfully added
*/
public boolean addOSPLibrary(String path) {
if (ospPathList.contains(path))
return false;
synchronized (ospPathList) {
XMLControl control = new XMLControlElement(path);
if (control.failedToRead() || control.getObjectClass() != Library.class) {
return false;
}
Library library = new Library();
control.loadObject(library);
library.browser = this.browser;
ospPathList.add(path);
ospPathToLibraryMap.put(path, library);
}
return true;
}
示例10: addSubLibrary
import org.opensourcephysics.controls.XMLControlElement; //导入依赖的package包/类
/**
* Adds a sublibrary. Sublibraries are shown as submenus in a Library's Collections menu.
* Sublibraries are not under user control.
*
* @param path the path to the sublibrary
* @return true if successfully added
*/
public boolean addSubLibrary(String path) {
if (subPathList.contains(path))
return false;
synchronized (subPathList) {
XMLControl control = new XMLControlElement(path);
if (control.failedToRead() || control.getObjectClass() != Library.class)
return false;
Library library = new Library();
library.browser = this.browser;
control.loadObject(library);
subPathList.add(path);
subPathToLibraryMap.put(path, library);
}
return true;
}
示例11: open
import org.opensourcephysics.controls.XMLControlElement; //导入依赖的package包/类
/**
* Opens an xml file specified by name.
*
* @param fileName the file name
* @return the file name, if successfully opened
*/
public String open(String fileName) {
OSPLog.fine("opening "+fileName); //$NON-NLS-1$
// read the file into an XML control
XMLControlElement control = new XMLControlElement();
control.setDecryptPolicy(XMLControlElement.NEVER_DECRYPT);
control.read(fileName);
if(control.failedToRead()) {
return null;
}
String pass = control.getPassword();
if(pass==null) {
passwordField.setText(null);
displayXML(control);
encryptedCheckBox.setEnabled(true);
} else if(passwordField.getText().equals(pass)) {
displayXML(decrypt(control));
encryptedCheckBox.setEnabled(true);
} else {
displayXML(control);
encryptedCheckBox.setEnabled(false);
}
this.fileName = fileName;
refreshGUI();
return fileName;
}
示例12: send
import org.opensourcephysics.controls.XMLControlElement; //导入依赖的package包/类
/**
* Sends a job to this tool and specifies a tool to reply to.
*
* @param job the Job
* @param replyTo the tool to notify when the job is complete (may be null)
* @throws RemoteException
*/
public void send(Job job, Tool replyTo) throws RemoteException {
// read xml into XMLControl and display the control
XMLControlElement control = new XMLControlElement();
control.setDecryptPolicy(XMLControlElement.NEVER_DECRYPT);
control.readXML(job.getXML());
if(control.failedToRead()) {
return;
}
String pass = control.getPassword();
if(pass==null) {
passwordField.setText(null);
displayXML(control);
} else if(passwordField.getText().equals(pass)) {
displayXML(decrypt(control));
} else {
displayXML(control);
}
fileName = null;
refreshGUI();
// log the job with the job manager
jobManager.log(job, replyTo);
}
示例13: save
import org.opensourcephysics.controls.XMLControlElement; //导入依赖的package包/类
/**
* Saves the current xml control to the specified file.
*
* @param fileName the file name
* @return the name of the saved file, or null if not saved
*/
private String save(String fileName) {
if((fileName==null)||fileName.equals("")) { //$NON-NLS-1$
return null;
}
if(passwordField.getBackground()==Color.yellow) {
passwordField.setBackground(Color.white);
setPassword(passwordField.getText());
}
XMLControlElement control = getCurrentControl();
if(control==null) {
return null;
}
if(control.getObjectClass()==Cryptic.class) {
control = decrypt(control);
}
if(control.write(fileName)==null) {
return null;
}
this.fileName = fileName;
refreshGUI();
return fileName;
}
示例14: send
import org.opensourcephysics.controls.XMLControlElement; //导入依赖的package包/类
/**
* Sends a job to this tool and specifies a tool to reply to.
*
* @param job the Job
* @param replyTo the tool to notify when the job is complete (may be null)
* @throws RemoteException
*/
public void send(Job job, Tool replyTo) throws RemoteException {
XMLControlElement control = new XMLControlElement(job.getXML());
if(control.failedToRead()||(control.getObjectClass()==Object.class)) {
return;
}
// log the job in
jobManager.log(job, replyTo);
// if control is for a Data object, load it into this tab
if(Data.class.isAssignableFrom(control.getObjectClass())) {
Data data = (Data) control.loadObject(null, true, true);
loadData(data, replaceColumnsWithMatchingNames);
jobManager.associate(job, dataManager);
refreshGUI();
}
// if control is for DataToolTab class, load this tab from control
else if(DataToolTab.class.isAssignableFrom(control.getObjectClass())) {
control.loadObject(this);
refreshGUI();
}
}
示例15: setEditing
import org.opensourcephysics.controls.XMLControlElement; //导入依赖的package包/类
/**
* Sets the editing state.
*
* @param edit true to start editing, false to stop
*/
protected void setEditing(boolean edit) {
isEditing = edit;
if (isEditing) {
displayPanel.add(editorPanel, BorderLayout.NORTH);
add(editorbar, BorderLayout.NORTH);
showInfo(getSelectedNode());
}
else {
displayPanel.remove(editorPanel);
remove(editorbar);
}
validate();
if (isEditing) {
revertControl = new XMLControlElement(rootResource);
}
}