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);
}
}
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);
}
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);
}
}
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);
}
}
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);
}
Aggregations