Search in sources :

Example 11 with LionEngineException

use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.

the class TextAwtTest method testAlignUnknown.

/**
 * Test align unknown.
 */
@Test
public void testAlignUnknown() {
    final Text text = Graphics.createText(Constant.FONT_DIALOG, 12, TextStyle.NORMAL);
    try {
        final Graphic g = Graphics.createGraphic();
        g.setGraphic(ToolsAwt.createImage(1, 1, java.awt.Transparency.OPAQUE).createGraphics());
        text.draw(g, 0, 0, UtilEnum.make(Align.class, "FAIL"), Constant.EMPTY_STRING);
        Assert.fail();
    } catch (final LionEngineException exception) {
        Assert.assertNotNull(exception);
    }
}
Also used : Align(com.b3dgs.lionengine.Align) LionEngineException(com.b3dgs.lionengine.LionEngineException) Graphic(com.b3dgs.lionengine.graphic.Graphic) Text(com.b3dgs.lionengine.graphic.Text) Test(org.junit.Test)

Example 12 with LionEngineException

use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.

the class Medias method getJarResources.

/**
 * Get the running JAR resources. Load from JAR must be enabled.
 *
 * @return The JAR file.
 * @throws LionEngineException If JAR not available.
 */
public static synchronized File getJarResources() {
    if (!loader.isPresent()) {
        throw new LionEngineException(JAR_LOADER_ERROR);
    }
    final Media media = Medias.create(Constant.EMPTY_STRING);
    final String path = media.getFile().getPath().replace(File.separator, Constant.SLASH);
    final String prefix = loader.get().getPackage().getName().replace(Constant.DOT, Constant.SLASH);
    final int jarSeparatorIndex = path.indexOf(prefix);
    final String jar = path.substring(0, jarSeparatorIndex);
    return new File(jar);
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) Media(com.b3dgs.lionengine.Media) UtilFile(com.b3dgs.lionengine.util.UtilFile) File(java.io.File)

Example 13 with LionEngineException

use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.

the class Medias method getByExtension.

/**
 * Get all media by extension found in the direct path (does not search in sub folders).
 *
 * @param extension The extension without dot; eg: png (must not be <code>null</code>).
 * @param folder The folder to search in (must not be <code>null</code>).
 * @return The medias found.
 * @throws LionEngineException If invalid parameters.
 */
public static synchronized List<Media> getByExtension(String extension, Media folder) {
    Check.notNull(extension);
    Check.notNull(folder);
    try {
        final File jar = getJarResources();
        final String prefix = getJarResourcesPrefix();
        final String fullPath = Medias.create(prefix, folder.getPath()).getPath();
        final int prefixLength = prefix.length() + 1;
        return getByExtension(jar, fullPath, prefixLength, extension);
    } catch (@SuppressWarnings("unused") final LionEngineException exception) {
        return getFilesByExtension(folder, extension);
    }
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) UtilFile(com.b3dgs.lionengine.util.UtilFile) File(java.io.File)

Example 14 with LionEngineException

use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.

the class Xml method save.

/**
 * Save an XML tree to a file.
 *
 * @param media The output media path (must not be <code>null</code>).
 * @throws LionEngineException If error when saving media.
 */
public void save(Media media) {
    Check.notNull(media);
    try (OutputStream output = media.getOutputStream()) {
        final Transformer transformer = DocumentFactory.createTransformer();
        normalize(NORMALIZE);
        writeString(Constant.XML_HEADER, Constant.ENGINE_WEBSITE);
        final DOMSource source = new DOMSource(root);
        final StreamResult result = new StreamResult(output);
        final String yes = "yes";
        transformer.setOutputProperty(OutputKeys.INDENT, yes);
        transformer.setOutputProperty(OutputKeys.STANDALONE, yes);
        transformer.setOutputProperty(PROPERTY_INDENT, "4");
        transformer.transform(source, result);
    } catch (final TransformerException | IOException exception) {
        throw new LionEngineException(exception, media, ERROR_WRITING);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) LionEngineException(com.b3dgs.lionengine.LionEngineException) OutputStream(java.io.OutputStream) IOException(java.io.IOException) TransformerException(javax.xml.transform.TransformerException)

Example 15 with LionEngineException

use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.

the class Xml method getChild.

/**
 * Get a child node from its name.
 *
 * @param name The child name (must not be <code>null</code>).
 * @return The child node reference.
 * @throws LionEngineException If no node is found at this child name.
 */
public Xml getChild(String name) {
    Check.notNull(name);
    final NodeList list = root.getChildNodes();
    for (int i = 0; i < list.getLength(); i++) {
        final Node node = list.item(i);
        if (node instanceof Element && node.getNodeName().equals(name)) {
            return new Xml(document, (Element) node);
        }
    }
    throw new LionEngineException(ERROR_NODE + name);
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element)

Aggregations

LionEngineException (com.b3dgs.lionengine.LionEngineException)75 IOException (java.io.IOException)13 File (java.io.File)8 OutputStream (java.io.OutputStream)7 ArrayList (java.util.ArrayList)7 XmlReader (com.b3dgs.lionengine.XmlReader)6 Field (java.lang.reflect.Field)6 Test (org.junit.Test)6 Media (com.b3dgs.lionengine.Media)5 Configurer (com.b3dgs.lionengine.game.Configurer)4 UtilFile (com.b3dgs.lionengine.UtilFile)3 Graphic (com.b3dgs.lionengine.graphic.Graphic)3 UtilFile (com.b3dgs.lionengine.util.UtilFile)3 DisplayMode (java.awt.DisplayMode)3 BufferedImage (java.awt.image.BufferedImage)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 AfterAll (org.junit.jupiter.api.AfterAll)3 Animation (com.b3dgs.lionengine.Animation)2 AnimationConfig (com.b3dgs.lionengine.game.AnimationConfig)2 Feature (com.b3dgs.lionengine.game.Feature)2