本文整理汇总了Java中org.opensourcephysics.controls.XMLControl.loadObject方法的典型用法代码示例。如果您正苦于以下问题:Java XMLControl.loadObject方法的具体用法?Java XMLControl.loadObject怎么用?Java XMLControl.loadObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.opensourcephysics.controls.XMLControl
的用法示例。
在下文中一共展示了XMLControl.loadObject方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadObject
import org.opensourcephysics.controls.XMLControl; //导入方法依赖的package包/类
/**
* Loads the object with data from the control.
*
* @param control XMLControl
* @param obj Object
* @return Object
*/
public Object loadObject(XMLControl control, Object obj) {
DrawingFrame frame = ((DrawingFrame) obj);
DrawingPanel panel = frame.getDrawingPanel();
panel.clear();
XMLControl panelControl = control.getChildControl("drawing panel"); //$NON-NLS-1$
panelControl.loadObject(panel);
panel.repaint();
frame.setTitle(control.getString("title")); //$NON-NLS-1$
frame.setLocation(control.getInt("location x"), control.getInt("location y")); //$NON-NLS-1$ //$NON-NLS-2$
frame.setSize(control.getInt("width"), control.getInt("height")); //$NON-NLS-1$ //$NON-NLS-2$
if(control.getBoolean("showing")) { //$NON-NLS-1$
frame.setVisible(true);
}
return obj;
}
示例2: loadObject
import org.opensourcephysics.controls.XMLControl; //导入方法依赖的package包/类
public Object loadObject(XMLControl control, Object obj) {
DrawingFrame3D frame3D = ((DrawingFrame3D) obj);
javax.swing.JFrame frame = frame3D.getJFrame();
DrawingPanel3D panel = frame3D.getDrawingPanel3D();
panel.removeAllElements();
XMLControl panelControl = control.getChildControl("drawing panel"); //$NON-NLS-1$
panelControl.loadObject(panel);
panel.repaint();
frame.setTitle(control.getString("title")); //$NON-NLS-1$
frame.setLocation(control.getInt("location x"), control.getInt("location y")); //$NON-NLS-1$ //$NON-NLS-2$
frame.setSize(control.getInt("width"), control.getInt("height")); //$NON-NLS-1$ //$NON-NLS-2$
if(control.getBoolean("showing")) { //$NON-NLS-1$
frame.setVisible(true);
}
return obj;
}
示例3: setVideo
import org.opensourcephysics.controls.XMLControl; //导入方法依赖的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: getVideo
import org.opensourcephysics.controls.XMLControl; //导入方法依赖的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;
}
}
示例5: addOSPLibrary
import org.opensourcephysics.controls.XMLControl; //导入方法依赖的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;
}
示例6: addSubLibrary
import org.opensourcephysics.controls.XMLControl; //导入方法依赖的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;
}
示例7: getSearchCacheTargets
import org.opensourcephysics.controls.XMLControl; //导入方法依赖的package包/类
/**
* Returns the set of all searchable cache resources.
*
* @return a set of searchable resources
*/
protected Set<LibraryResource> getSearchCacheTargets() {
// set up search targets
Set<LibraryResource> searchTargets = new TreeSet<LibraryResource>();
File cache = ResourceLoader.getSearchCache();
FileFilter xmlFilter = new XMLFilter();
List<File> xmlFiles = ResourceLoader.getFiles(cache, xmlFilter);
for (File file: xmlFiles) {
XMLControl control = new XMLControlElement(file.getAbsolutePath());
if (!control.failedToRead() && LibraryResource.class.isAssignableFrom(control.getObjectClass())) {
LibraryResource resource = (LibraryResource)control.loadObject(null);
resource.collectionPath = control.getString("real_path"); //$NON-NLS-1$
searchTargets.add(resource);
}
}
return searchTargets;
}
示例8: pasteAction
import org.opensourcephysics.controls.XMLControl; //导入方法依赖的package包/类
/**
* Pastes drawables found in the specified xml control.
*
* @param control the xml control
*/
protected void pasteAction(XMLControlElement control) {
// get Drawables using an xml tree chooser
XMLTreeChooser chooser = new XMLTreeChooser(DisplayRes.getString("DrawingFrame.SelectDrawables_chooser_title"), DisplayRes.getString("DrawingFrame.SelectDrawables_chooser_message"), this); //$NON-NLS-1$ //$NON-NLS-2$
java.util.List<XMLProperty> props = chooser.choose(control, Drawable.class);
if(!props.isEmpty()) {
Iterator<XMLProperty> it = props.iterator();
while(it.hasNext()) {
XMLControl prop = (XMLControl) it.next();
Drawable drawable = (Drawable) prop.loadObject(null);
addDrawable(drawable);
}
}
drawingPanel.repaint();
}
示例9: importLibrary
import org.opensourcephysics.controls.XMLControl; //导入方法依赖的package包/类
/**
* Imports a library. Imported libraries are managed by the user.
*
* @param path the library path
* @return true if successfully imported
*/
public boolean importLibrary(String path) {
if (importedPathList.contains(path))
return false;
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);
return importLibrary(path, library);
}
示例10: loadFits
import org.opensourcephysics.controls.XMLControl; //导入方法依赖的package包/类
/**
* Loads fit functions from an XML file.
*
* @param path the path to the XML file
* @param loadAll true to load all fit functions defined in the file, false to let the user choose
* @return the path to the file opened, or null if failed
*/
private String loadFits(String path, boolean loadAll) {
if (path==null) return loadFits();
XMLControl control = new XMLControlElement(path);
if (control.failedToRead()) {
JOptionPane.showMessageDialog(FitBuilder.this,
ToolsRes.getString("Dialog.Invalid.Message"), //$NON-NLS-1$
ToolsRes.getString("Dialog.Invalid.Title"), //$NON-NLS-1$
JOptionPane.ERROR_MESSAGE);
return null;
}
Class<?> type = control.getObjectClass();
if (FitBuilder.class.isAssignableFrom(type)) {
// choose fits to load
if (loadAll || chooseFitFunctions(control, "Load")) { //$NON-NLS-1$
control.loadObject(this);
}
}
else {
JOptionPane.showMessageDialog(FitBuilder.this,
ToolsRes.getString("DatasetCurveFitter.FitBuilder.Dialog.WrongType.Message"), //$NON-NLS-1$
ToolsRes.getString("DatasetCurveFitter.FitBuilder.Dialog.WrongType.Title"), //$NON-NLS-1$
JOptionPane.ERROR_MESSAGE);
}
return path;
}
示例11: autoloadFits
import org.opensourcephysics.controls.XMLControl; //导入方法依赖的package包/类
/**
* Loads fit functions from all FitBuilder XMLControl files found in a specified directory.
*
* @param dirPath the directory path
*/
private void autoloadFits(String dirPath) {
if (dirPath==null) return;
File dir = new File(dirPath);
if (!dir.exists()) return;
File[] files = dir.listFiles(xmlFilter);
if (files!=null) {
for (File file: files) {
XMLControl control = new XMLControlElement(file.getPath());
if (control.failedToRead()) {
continue;
}
Class<?> type = control.getObjectClass();
if (type!=null && FitBuilder.class.isAssignableFrom(type)) {
// copy the control for modification if any functions are autoload_off
XMLControl copyControl = new XMLControlElement(control);
String filePath = XML.forwardSlash(file.getAbsolutePath());
eliminateExcludedFunctions(copyControl, filePath);
copyControl.loadObject(this);
}
}
}
}
示例12: load
import org.opensourcephysics.controls.XMLControl; //导入方法依赖的package包/类
/**
* Loads this library from an xml file.
*
* @param path the path to the file
*/
protected void load(String path) {
if (path==null) return;
XMLControl control = new XMLControlElement(path);
control.loadObject(this);
}
示例13: getSelfContainedData
import org.opensourcephysics.controls.XMLControl; //导入方法依赖的package包/类
/**
* Loads self-contained Data objects from an XMLControl.
*
* @param control the XMLControl
* @param useChooser true to present data choices to user
*
* @return a list of self-contained Data objects
*/
private static ArrayList<Data> getSelfContainedData(XMLControl control, boolean useChooser) {
ArrayList<Data> dataList = new ArrayList<Data>();
java.util.List<XMLProperty> xmlControls;
// first get the Data XMLControls
if(useChooser) {
// get user-selected Data XMLControls from an xml tree chooser
XMLTreeChooser chooser = new XMLTreeChooser(ToolsRes.getString("Chooser.Title"), //$NON-NLS-1$
ToolsRes.getString("Chooser.Label"), null); //$NON-NLS-1$
xmlControls = chooser.choose(control, Data.class);
} else {
// get all Data XMLControls
XMLTree tree = new XMLTree(control);
tree.setHighlightedClass(Data.class);
tree.selectHighlightedProperties();
xmlControls = tree.getSelectedProperties();
if(xmlControls.isEmpty()) {
JOptionPane.showMessageDialog(null, ToolsRes.getString("Dialog.NoDatasets.Message")); //$NON-NLS-1$
}
}
// load the Data XMLControls and collect Data objects
HashSet<Integer> IDs = new HashSet<Integer>();
for(XMLProperty prop : xmlControls) {
XMLControl next = (XMLControl) prop;
Data data = null;
if(next instanceof XMLControlElement) {
XMLControlElement element = (XMLControlElement) next;
data = (Data) element.loadObject(null, true, true);
} else {
data = (Data) next.loadObject(null);
}
if(data!=null) {
for(Data nextData : getSelfContainedData(data)) {
// check IDs to prevent duplicates
Integer id = new Integer(nextData.getID());
if(!IDs.contains(id)) {
IDs.add(id);
dataList.add(nextData);
// remove any previously added Datasets within DatasetManagers
if(nextData instanceof DatasetManager) {
for(Dataset dataset : nextData.getDatasets()) {
dataList.remove(dataset);
id = new Integer(dataset.getID());
IDs.add(id);
}
}
}
}
}
}
return dataList;
}