use of org.jdom2.filter.Filter in project Arcade2 by ShootGame.
the class PointFactory method parsePointXml.
public Point parsePointXml(CaptureGame game, Element xml, Point point) {
// capture region
Element captureElement = xml.getChild("capture");
if (captureElement == null) {
return null;
}
PointCapture capture = this.parsePointCapture(game, captureElement, new PointCapture(game, point));
if (capture == null) {
return null;
}
// state region
Element stateElement = xml.getChild("state");
Region stateRegion = stateElement != null ? XMLRegion.parseUnion(game.getGame(), stateElement) : null;
if (stateRegion == null) {
// Set state region to the capture region (if it is not set).
stateRegion = capture.getRegion();
}
// setup
point.setCapture(capture);
point.setCaptureTime(Time.parseTime(xml.getAttributeValue("capture-time"), Point.DEFAULT_CAPTURE_TIME));
point.setCapturingCapturedEnabled(XMLParser.parseBoolean(xml.getAttributeValue("capturing-captured"), false));
point.setDominatorStrategy(this.findDominatorStrategy(xml, Point.DEFAULT_DOMINATOR_STRATEGY));
point.setDominateFilter(this.findFilter(game.getGame(), xml.getAttributeValue("dominate-filter"), Point.DEFAULT_DOMINATE_FILTER));
point.setLoseTime(Time.parseTime(xml.getAttributeValue("lose-time"), Point.DEFAULT_LOSE_TIME));
point.setNeutralColor(Color.parse(xml.getAttributeValue("color"), Point.DEFAULT_NEUTRAL_COLOR));
point.setObjective(XMLParser.parseBoolean(xml.getAttributeValue("objective"), false));
point.setPermanent(XMLParser.parseBoolean(xml.getAttributeValue("permanent"), false));
point.setPointReward(XMLParser.parseDouble(xml.getAttributeValue("point-reward"), Score.ZERO));
point.setStateRegion(stateRegion);
return point;
}
use of org.jdom2.filter.Filter in project pcgen by PCGen.
the class Initiative method refreshTabs.
//** End Initialization Functions **
/**
* Refresh the tabs
*/
public void refreshTabs() {
initList.stream().filter(anInitList -> ((anInitList.getStatus() != State.Dead) || showDead.isSelected()) && (anInitList instanceof Combatant)).forEach(anInitList -> {
Combatant cbt = (Combatant) anInitList;
removeTab(cbt);
addTab(cbt);
});
}
use of org.jdom2.filter.Filter in project JMRI by JMRI.
the class StartupActionsManager method initialize.
/**
* {@inheritDoc}
*
* Loads the startup action preferences and, if all required managers have
* initialized without exceptions, performs those actions. Startup actions
* are only performed if {@link apps.startup.StartupModel#isValid()} is true
* for the action. It is assumed that the action has retained an Exception
* that can be used to explain why isValid() is false.
*/
@Override
public void initialize(Profile profile) throws InitializationException {
if (!this.isInitialized(profile)) {
boolean perform = true;
try {
this.requiresNoInitializedWithExceptions(profile, Bundle.getMessage("StartupActionsManager.RefusalToInitialize"));
} catch (InitializationException ex) {
perform = false;
}
try {
Element startup;
try {
startup = JDOMUtil.toJDOMElement(ProfileUtils.getAuxiliaryConfiguration(profile).getConfigurationFragment(STARTUP, NAMESPACE, true));
} catch (NullPointerException ex) {
log.debug("Reading element from version 2.9.6 namespace...");
startup = JDOMUtil.toJDOMElement(ProfileUtils.getAuxiliaryConfiguration(profile).getConfigurationFragment(STARTUP, NAMESPACE_OLD, true));
}
for (Element action : startup.getChildren()) {
// NOI18N
String adapter = action.getAttributeValue("class");
// NOI18N
String name = action.getAttributeValue("name");
String override = StartupActionModelUtil.getDefault().getOverride(name);
if (override != null) {
action.setAttribute("name", override);
log.info("Overridding statup action class {} with {}", name, override);
this.addInitializationException(profile, new InitializationException(Bundle.getMessage(Locale.ENGLISH, "StartupActionsOverriddenClasses", name, override), Bundle.getMessage(Locale.ENGLISH, "StartupActionsOverriddenClasses", name, override)));
// after logging difference and creating error message
name = override;
}
// NOI18N
String type = action.getAttributeValue("type");
log.debug("Read {} {} adapter {}", type, name, adapter);
try {
log.debug("Creating {} {} adapter {}...", type, name, adapter);
// no perNode preferences
((XmlAdapter) Class.forName(adapter).newInstance()).load(action, null);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
log.error("Unable to create {} for {}", adapter, action, ex);
this.addInitializationException(profile, new InitializationException(Bundle.getMessage(Locale.ENGLISH, "StartupActionsCreationError", adapter, name), // NOI18N
Bundle.getMessage("StartupActionsCreationError", adapter, name)));
} catch (Exception ex) {
log.error("Unable to load {} into {}", action, adapter, ex);
this.addInitializationException(profile, new InitializationException(Bundle.getMessage(Locale.ENGLISH, "StartupActionsLoadError", adapter, name), // NOI18N
Bundle.getMessage("StartupActionsLoadError", adapter, name)));
}
}
} catch (NullPointerException ex) {
// ignore - this indicates migration has not occured
log.debug("No element to read");
}
if (perform) {
this.actions.stream().filter((action) -> (action.isValid())).forEachOrdered((action) -> {
try {
action.performAction();
} catch (JmriException ex) {
this.addInitializationException(profile, ex);
}
});
}
this.isDirty = false;
this.restartRequired = false;
this.setInitialized(profile, true);
List<Exception> exceptions = this.getInitializationExceptions(profile);
if (exceptions.size() == 1) {
throw new InitializationException(exceptions.get(0));
} else if (exceptions.size() > 1) {
throw new InitializationException(Bundle.getMessage(Locale.ENGLISH, "StartupActionsMultipleErrors"), // NOI18N
Bundle.getMessage("StartupActionsMultipleErrors"));
}
}
}
use of org.jdom2.filter.Filter in project JMRI by JMRI.
the class FullBackupImportAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
// ensure preferences will be found for read
FileUtil.createDirectory(LocoFile.getFileLocation());
// make sure instance loaded
Roster.getDefault();
// set up to read import file
ZipInputStream zipper = null;
FileInputStream inputfile = null;
try {
JFileChooser chooser = new JFileChooser();
String roster_filename_extension = "roster";
FileNameExtensionFilter filter = new FileNameExtensionFilter("JMRI full roster files", roster_filename_extension);
chooser.addChoosableFileFilter(filter);
int returnVal = chooser.showOpenDialog(mParent);
if (returnVal != JFileChooser.APPROVE_OPTION) {
return;
}
String filename = chooser.getSelectedFile().getAbsolutePath();
inputfile = new FileInputStream(filename);
zipper = new ZipInputStream(inputfile) {
@Override
public void close() {
}
};
// now iterate through each item in the stream. The get next
// entry call will return a ZipEntry for each file in the
// stream
ZipEntry entry;
while ((entry = zipper.getNextEntry()) != null) {
log.debug(String.format("Entry: %s len %d added %TD", entry.getName(), entry.getSize(), new Date(entry.getTime())));
// reading until read returns 0 or less.
try {
// need a dummy object to do this operation in next line
LocoFile xfile = new LocoFile();
Element lroot = xfile.rootFromInputStream(zipper).clone();
if (lroot.getChild("locomotive") == null) {
// that's the roster file
continue;
}
mToID = lroot.getChild("locomotive").getAttributeValue("id");
// see if user wants to do it
int retval = JOptionPane.showOptionDialog(mParent, Bundle.getMessage("ConfirmImportID", mToID), Bundle.getMessage("ConfirmImport"), 0, JOptionPane.INFORMATION_MESSAGE, null, new Object[] { Bundle.getMessage("CancelImports"), Bundle.getMessage("Skip"), Bundle.getMessage("ButtonOK") }, null);
if (retval == 0) {
break;
}
if (retval == 1) {
continue;
}
// see if duplicate
RosterEntry currentEntry = Roster.getDefault().getEntryForId(mToID);
if (currentEntry != null) {
retval = JOptionPane.showOptionDialog(mParent, Bundle.getMessage("ConfirmImportDup", mToID), Bundle.getMessage("ConfirmImport"), 0, JOptionPane.INFORMATION_MESSAGE, null, new Object[] { Bundle.getMessage("CancelImports"), Bundle.getMessage("Skip"), Bundle.getMessage("ButtonOK") }, null);
if (retval == 0) {
break;
}
if (retval == 1) {
continue;
}
// turn file into backup
// need a dummy object to do this operation in next line
LocoFile df = new LocoFile();
df.makeBackupFile(LocoFile.getFileLocation() + currentEntry.getFileName());
// delete entry
Roster.getDefault().removeEntry(currentEntry);
}
loadEntryFromElement(lroot);
addToEntryToRoster();
// use the new roster
Roster.getDefault().reloadRosterFile();
} catch (org.jdom2.JDOMException ex) {
ex.printStackTrace();
}
}
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (inputfile != null) {
try {
// zipper.close() is meaningless, see above, but this will do
inputfile.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
use of org.jdom2.filter.Filter in project JMRI by JMRI.
the class RpsPositionIconXml method load.
/**
* Create a PositionableLabel, then add to a target JLayeredPane
*
* @param element Top level Element to unpack.
* @param o an Editor as an Object
*/
@Override
public void load(Element element, Object o) {
Editor ed = (Editor) o;
RpsPositionIcon l = new RpsPositionIcon(ed);
// create the objects
String name = element.getAttribute("active").getValue();
NamedIcon active = NamedIcon.getIconByName(name);
if (active == null) {
active = ed.loadFailed("RpsPositionIcon: icon \"active\" ", name);
if (active == null) {
log.info("RpsPositionIcon: icon \"active\" removed for url= " + name);
return;
}
}
l.setActiveIcon(active);
name = element.getAttribute("error").getValue();
NamedIcon error = NamedIcon.getIconByName(name);
if (error == null) {
error = ed.loadFailed("RpsPositionIcon: icon \"error\" ", name);
if (error == null) {
log.info("RpsPositionIcon: \"error\" removed for url= " + name);
return;
}
}
l.setErrorIcon(error);
try {
Attribute a = element.getAttribute("rotate");
if (a != null) {
int rotation = element.getAttribute("rotate").getIntValue();
active.setRotation(rotation, l);
error.setRotation(rotation, l);
}
} catch (org.jdom2.DataConversionException e) {
}
Attribute a = element.getAttribute("momentary");
if ((a != null) && a.getValue().equals("true")) {
l.setMomentary(true);
} else {
l.setMomentary(false);
}
a = element.getAttribute("showid");
if ((a != null) && a.getValue().equals("true")) {
l.setShowID(true);
} else {
l.setShowID(false);
}
a = element.getAttribute("filter");
if (a != null) {
l.setFilter(a.getValue());
}
double sxScale = 0.;
double syScale = 0.;
int sxOrigin = 0;
int syOrigin = 0;
try {
sxScale = element.getAttribute("sxscale").getDoubleValue();
syScale = element.getAttribute("syscale").getDoubleValue();
sxOrigin = element.getAttribute("sxorigin").getIntValue();
syOrigin = element.getAttribute("syorigin").getIntValue();
} catch (NullPointerException e1) {
log.error("missing transform attribute");
} catch (org.jdom2.DataConversionException e2) {
log.error("failed to convert transform attributes");
}
l.setTransform(sxScale, syScale, sxOrigin, syOrigin);
NamedIcon icon = loadIcon(l, "active", element, "RpsPositionIcon ", ed);
if (icon != null) {
l.setActiveIcon(icon);
}
icon = loadIcon(l, "error", element, "RpsPositionIcon ", ed);
if (icon != null) {
l.setErrorIcon(icon);
}
ed.putItem(l);
// load individual item's option settings after editor has set its global settings
loadCommonAttributes(l, Editor.SENSORS, element);
}
Aggregations