Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleans up warnings in jme3-desktop #2244

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 77 additions & 105 deletions jme3-desktop/src/main/java/com/jme3/cursors/plugins/CursorLoader.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public boolean isEnabled() {
return enabled;
}

public void setEnabled(final boolean enabled) {
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

Expand Down Expand Up @@ -444,8 +444,7 @@ public void bind(Component destination, Application application, ViewPort viewPo
* @param main
* true if this processor is main.
*/
public void bind(final Component destination, final Application application, ViewPort viewPort,
boolean main) {
public void bind(Component destination, Application application, ViewPort viewPort, boolean main) {

if (hasApplication()) {
throw new RuntimeException("This process is already bonded.");
Expand Down Expand Up @@ -584,8 +583,7 @@ protected void unbindListeners() {
* true to fix the aspect ratio.
* @return the new frame transfer.
*/
protected AWTComponentRenderer reshapeInThread(final int width, final int height,
final boolean fixAspect) {
protected AWTComponentRenderer reshapeInThread(int width, int height, boolean fixAspect) {

reshapeCurrentViewPort(width, height);

Expand Down Expand Up @@ -661,7 +659,7 @@ protected void reshapeCurrentViewPort(int width, int height) {
viewPort.setOutputFrameBuffer(frameBuffer);
}

for (final SceneProcessor sceneProcessor : processors) {
for (SceneProcessor sceneProcessor : processors) {
if (!sceneProcessor.isInitialized()) {
sceneProcessor.initialize(renderManager, viewPort);
} else {
Expand Down
9 changes: 5 additions & 4 deletions jme3-desktop/src/main/java/com/jme3/system/AWTUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@

import com.jme3.texture.FrameBuffer;
import com.jme3.texture.Image;
import com.jme3.texture.FrameBuffer.FrameBufferTarget;

public class AWTUtils {
/**
* This should be a Temporary solution. FrameBuffer functions and Image-Formats are deprecated.
* Returns a Frame buffer.
*
* @param width
* @param height
* @param samples
* @return
*/
@SuppressWarnings("deprecation")
public static FrameBuffer getFrameBuffer(int width, int height, int samples) {
Copy link
Member

@richardTingle richardTingle Jun 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this have @SuppressWarnings("deprecation")? The warnings are valid. More generally; why extract this out into a seperate method (if we want to discourage using these deprecated things we don't want to make reuse easier)

FrameBuffer frameBuffer = new FrameBuffer(width, height, samples);
frameBuffer.setDepthBuffer(Image.Format.Depth);
frameBuffer.setColorBuffer(Image.Format.RGBA8);

frameBuffer.addColorTarget(FrameBufferTarget.newTarget(Image.Format.RGBA8));
frameBuffer.setDepthTarget(FrameBufferTarget.newTarget(Image.Format.Depth));
frameBuffer.setSrgb(true);

return frameBuffer;
Expand Down
55 changes: 24 additions & 31 deletions jme3-desktop/src/main/java/com/jme3/system/JmeDesktopSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,22 @@ public JmeDesktopSystem() {
public URL getPlatformAssetConfigURL() {
return Resources.getResource("com/jme3/asset/Desktop.cfg");
}

private static BufferedImage verticalFlip(BufferedImage original) {
AffineTransform tx = AffineTransform.getScaleInstance(1, -1);
tx.translate(0, -original.getHeight());
AffineTransformOp transformOp = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
BufferedImage awtImage = new BufferedImage(original.getWidth(), original.getHeight(), original.getType());
BufferedImage awtImage = new BufferedImage(original.getWidth(), original.getHeight(),
original.getType());
Graphics2D g2d = awtImage.createGraphics();
g2d.setRenderingHint(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_SPEED);
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
g2d.drawImage(original, transformOp, 0, 0);
g2d.dispose();
return awtImage;
}

private static BufferedImage ensureOpaque(BufferedImage original) {
if (original.getTransparency() == BufferedImage.OPAQUE)
return original;
if (original.getTransparency() == BufferedImage.OPAQUE) return original;
int w = original.getWidth();
int h = original.getHeight();
int[] pixels = new int[w * h];
Expand All @@ -101,8 +100,11 @@ private static BufferedImage ensureOpaque(BufferedImage original) {
}

@Override
public void writeImageFile(OutputStream outStream, String format, ByteBuffer imageData, int width, int height) throws IOException {
BufferedImage awtImage = ImageToAwt.convert(new Image(Image.Format.RGBA8, width, height, imageData.duplicate(), ColorSpace.Linear), false, true, 0);
public void writeImageFile(OutputStream outStream, String format, ByteBuffer imageData, int width,
int height) throws IOException {
BufferedImage awtImage = ImageToAwt.convert(
new Image(Image.Format.RGBA8, width, height, imageData.duplicate(), ColorSpace.Linear), false,
true, 0);
awtImage = verticalFlip(awtImage);

ImageWriter writer = ImageIO.getImageWritersByFormatName(format).next();
Expand All @@ -115,7 +117,7 @@ public void writeImageFile(OutputStream outStream, String format, ByteBuffer ima
jpegParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
jpegParam.setCompressionQuality(0.95f);
}

ImageOutputStream imgOut = new MemoryCacheImageOutputStream(outStream);
writer.setOutput(imgOut);
IIOImage outputImage = new IIOImage(awtImage, null, null);
Expand All @@ -127,7 +129,6 @@ public void writeImageFile(OutputStream outStream, String format, ByteBuffer ima
}
}

//@SuppressWarnings("unchecked")
private JmeContext newContextLwjgl(AppSettings settings, JmeContext.Type type) {
try {
Class<?> ctxClazz = null;
Expand All @@ -146,9 +147,8 @@ private JmeContext newContextLwjgl(AppSettings settings, JmeContext.Type type) {
}

return (JmeContext) ctxClazz.getDeclaredConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException
| IllegalArgumentException | InvocationTargetException
| NoSuchMethodException | SecurityException ex) {
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | NoSuchMethodException | SecurityException ex) {
logger.log(Level.SEVERE, "Failed to create context", ex);
} catch (ClassNotFoundException ex) {
logger.log(Level.SEVERE, "CRITICAL ERROR: Context class is missing!\n"
Expand All @@ -158,7 +158,6 @@ private JmeContext newContextLwjgl(AppSettings settings, JmeContext.Type type) {
return null;
}

//@SuppressWarnings("unchecked")
private JmeContext newContextJogl(AppSettings settings, JmeContext.Type type) {
try {
Class<?> ctxClazz = null;
Expand All @@ -177,9 +176,8 @@ private JmeContext newContextJogl(AppSettings settings, JmeContext.Type type) {
}

return (JmeContext) ctxClazz.getDeclaredConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException
| IllegalArgumentException | InvocationTargetException
| NoSuchMethodException | SecurityException ex) {
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | NoSuchMethodException | SecurityException ex) {
logger.log(Level.SEVERE, "Failed to create context", ex);
} catch (ClassNotFoundException ex) {
logger.log(Level.SEVERE, "CRITICAL ERROR: Context class is missing!\n"
Expand All @@ -196,9 +194,8 @@ private JmeContext newContextCustom(AppSettings settings, JmeContext.Type type)

Class<JmeContext> ctxClazz = (Class<JmeContext>) Class.forName(className);
return ctxClazz.getDeclaredConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException
| IllegalArgumentException | InvocationTargetException
| NoSuchMethodException | SecurityException ex) {
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | NoSuchMethodException | SecurityException ex) {
logger.log(Level.SEVERE, "Failed to create context", ex);
} catch (ClassNotFoundException ex) {
logger.log(Level.SEVERE, "CRITICAL ERROR: Context class is missing!", ex);
Expand All @@ -211,8 +208,7 @@ private JmeContext newContextCustom(AppSettings settings, JmeContext.Type type)
public JmeContext newContext(AppSettings settings, Type contextType) {
initialize(settings);
JmeContext ctx;
if (settings.getRenderer() == null
|| settings.getRenderer().equals("NULL")
if (settings.getRenderer() == null || settings.getRenderer().equals("NULL")
|| contextType == JmeContext.Type.Headless) {
ctx = new NullContext();
ctx.setSettings(settings);
Expand All @@ -227,8 +223,7 @@ public JmeContext newContext(AppSettings settings, Type contextType) {
ctx.setSettings(settings);
} else {
throw new UnsupportedOperationException(
"Unrecognizable renderer specified: "
+ settings.getRenderer());
"Unrecognizable renderer specified: " + settings.getRenderer());
}
return ctx;
}
Expand All @@ -239,11 +234,10 @@ private <T> T newObject(String className) {
Class<T> clazz = (Class<T>) Class.forName(className);
return clazz.getDeclaredConstructor().newInstance();
} catch (ClassNotFoundException ex) {
logger.log(Level.SEVERE, "CRITICAL ERROR: Audio implementation class "
+ className + " is missing!\n", ex);
} catch (InstantiationException | IllegalAccessException
| IllegalArgumentException | InvocationTargetException
| NoSuchMethodException | SecurityException ex) {
logger.log(Level.SEVERE,
"CRITICAL ERROR: Audio implementation class " + className + " is missing!\n", ex);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | NoSuchMethodException | SecurityException ex) {
logger.log(Level.SEVERE, "Failed to create context", ex);
}

Expand All @@ -267,8 +261,7 @@ public AudioRenderer newAudioRenderer(AppSettings settings) {
efx = newObject("com.jme3.audio.joal.JoalEFX");
} else {
throw new UnsupportedOperationException(
"Unrecognizable audio renderer specified: "
+ settings.getAudioRenderer());
"Unrecognizable audio renderer specified: " + settings.getAudioRenderer());
}

if (al == null || alc == null || efx == null) {
Expand Down
Loading
Loading