Search in sources :

Example 26 with Filter

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;
}
Also used : Element(org.jdom2.Element) XMLRegion(pl.themolka.arcade.xml.XMLRegion) Region(pl.themolka.arcade.region.Region)

Example 27 with Filter

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);
    });
}
Also used : PluginManager(pcgen.pluginmgr.PluginManager) Globals(pcgen.core.Globals) Combatant(gmgen.plugin.Combatant) InfoCharacterDetails(gmgen.plugin.InfoCharacterDetails) HyperlinkEvent(javax.swing.event.HyperlinkEvent) JDialog(javax.swing.JDialog) DiceRollModel(plugin.initiative.DiceRollModel) JTableHeader(javax.swing.table.JTableHeader) TableCellRenderer(javax.swing.table.TableCellRenderer) NumberFormatter(javax.swing.text.NumberFormatter) PcgCombatant(gmgen.plugin.PcgCombatant) Document(org.jdom2.Document) Dice(gmgen.plugin.dice.Dice) Vector(java.util.Vector) SettingsHandler(pcgen.core.SettingsHandler) LogUtilities(gmgen.util.LogUtilities) JFileChooser(javax.swing.JFileChooser) DefaultFormatter(javax.swing.text.DefaultFormatter) JComboBox(javax.swing.JComboBox) ListSelectionEvent(javax.swing.event.ListSelectionEvent) FlippingSplitPane(gmgen.gui.FlippingSplitPane) InitHolder(gmgen.plugin.InitHolder) DefaultTableModel(javax.swing.table.DefaultTableModel) Format(org.jdom2.output.Format) Logging(pcgen.util.Logging) Spell(gmgen.plugin.Spell) PCStat(pcgen.core.PCStat) SpellModel(plugin.initiative.SpellModel) GMGenSystem(gmgen.GMGenSystem) Component(java.awt.Component) Collectors(java.util.stream.Collectors) SystemInitiative(gmgen.plugin.SystemInitiative) List(java.util.List) InitHolderList(gmgen.plugin.InitHolderList) CheckModel(plugin.initiative.CheckModel) JSeparator(javax.swing.JSeparator) Writer(java.io.Writer) JCheckBox(javax.swing.JCheckBox) JTable(javax.swing.JTable) XMLCombatant(plugin.initiative.XMLCombatant) Element(org.jdom2.Element) State(gmgen.plugin.State) PlayerCharacter(pcgen.core.PlayerCharacter) PObjectModel(plugin.initiative.PObjectModel) TableColumnModel(javax.swing.table.TableColumnModel) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) InitiativePlugin(plugin.initiative.InitiativePlugin) ArrayList(java.util.ArrayList) AttackModel(plugin.initiative.AttackModel) PCGenMessageHandler(pcgen.pluginmgr.PCGenMessageHandler) SystemHP(gmgen.plugin.SystemHP) LanguageBundle(pcgen.system.LanguageBundle) PCGenSettings(pcgen.system.PCGenSettings) HyperlinkListener(javax.swing.event.HyperlinkListener) SAXBuilder(org.jdom2.input.SAXBuilder) JButton(javax.swing.JButton) JFormattedTextField(javax.swing.JFormattedTextField) TableColumn(javax.swing.table.TableColumn) FileWriter(java.io.FileWriter) IOException(java.io.IOException) JOptionPane(javax.swing.JOptionPane) FileFilter(javax.swing.filechooser.FileFilter) ActionEvent(java.awt.event.ActionEvent) File(java.io.File) DefaultCellEditor(javax.swing.DefaultCellEditor) XMLOutputter(org.jdom2.output.XMLOutputter) CombatantHasBeenUpdatedMessage(gmgen.pluginmgr.messages.CombatantHasBeenUpdatedMessage) Event(gmgen.plugin.Event) SaveModel(plugin.initiative.SaveModel) Combatant(gmgen.plugin.Combatant) PcgCombatant(gmgen.plugin.PcgCombatant) XMLCombatant(plugin.initiative.XMLCombatant)

Example 28 with Filter

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"));
        }
    }
}
Also used : ConfigXmlManager(jmri.configurexml.ConfigXmlManager) StartupModel(apps.startup.StartupModel) AbstractPreferencesManager(jmri.util.prefs.AbstractPreferencesManager) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) InitializationException(jmri.util.prefs.InitializationException) ArrayList(java.util.ArrayList) JDOMException(org.jdom2.JDOMException) RosterConfigManager(jmri.jmrit.roster.RosterConfigManager) JDOMUtil(jmri.util.jdom.JDOMUtil) ProgrammerConfigManager(jmri.jmrit.symbolicprog.ProgrammerConfigManager) ProfileUtils(jmri.profile.ProfileUtils) Locale(java.util.Locale) Profile(jmri.profile.Profile) XmlAdapter(jmri.configurexml.XmlAdapter) Logger(org.slf4j.Logger) FileLocationsPreferences(jmri.implementation.FileLocationsPreferences) GuiLafPreferencesManager(apps.gui.GuiLafPreferencesManager) JmriException(jmri.JmriException) WarrantPreferences(jmri.jmrit.logix.WarrantPreferences) Set(java.util.Set) ServiceLoader(java.util.ServiceLoader) StartupActionModelUtil(apps.startup.StartupActionModelUtil) List(java.util.List) ManagerDefaultSelector(jmri.managers.ManagerDefaultSelector) PreferencesManager(jmri.spi.PreferencesManager) StartupModelFactory(apps.startup.StartupModelFactory) Element(org.jdom2.Element) Element(org.jdom2.Element) JmriException(jmri.JmriException) InitializationException(jmri.util.prefs.InitializationException) InitializationException(jmri.util.prefs.InitializationException) JDOMException(org.jdom2.JDOMException) JmriException(jmri.JmriException) XmlAdapter(jmri.configurexml.XmlAdapter)

Example 29 with Filter

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();
            }
        }
    }
}
Also used : ZipEntry(java.util.zip.ZipEntry) Element(org.jdom2.Element) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) FileInputStream(java.io.FileInputStream) Date(java.util.Date) ZipInputStream(java.util.zip.ZipInputStream) JFileChooser(javax.swing.JFileChooser)

Example 30 with Filter

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);
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) Attribute(org.jdom2.Attribute) Editor(jmri.jmrit.display.Editor) RpsPositionIcon(jmri.jmrit.display.RpsPositionIcon)

Aggregations

Element (org.jdom2.Element)43 Document (org.jdom2.Document)24 List (java.util.List)22 IOException (java.io.IOException)20 ArrayList (java.util.ArrayList)19 LogManager (org.apache.logging.log4j.LogManager)17 Logger (org.apache.logging.log4j.Logger)17 JDOMException (org.jdom2.JDOMException)17 Collectors (java.util.stream.Collectors)16 File (java.io.File)11 MCRException (org.mycore.common.MCRException)11 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)11 Collections (java.util.Collections)10 MCRObject (org.mycore.datamodel.metadata.MCRObject)10 Map (java.util.Map)9 MCRAccessException (org.mycore.access.MCRAccessException)9 MCRConstants (org.mycore.common.MCRConstants)9 MCRDerivate (org.mycore.datamodel.metadata.MCRDerivate)9 MCRMetadataManager (org.mycore.datamodel.metadata.MCRMetadataManager)9 Files (java.nio.file.Files)8