mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2025-02-13 08:14:23 +01:00
Reprecated/ begin removing swing code
This commit is contained in:
parent
0cc76ce574
commit
5411ca9e5d
5 changed files with 7 additions and 221 deletions
|
@ -1,33 +0,0 @@
|
|||
package com.minelittlepony.hdskins.gui;
|
||||
|
||||
import com.minelittlepony.common.client.gui.Checkbox;
|
||||
import com.minelittlepony.common.client.gui.GuiHost;
|
||||
import com.minelittlepony.common.client.gui.IGuiGuest;
|
||||
import com.minelittlepony.hdskins.HDSkins;
|
||||
import com.minelittlepony.hdskins.upload.GLWindow;
|
||||
|
||||
public class HDSkinsConfigPanel implements IGuiGuest {
|
||||
@Override
|
||||
public void initGui(GuiHost host) {
|
||||
final HDSkins mod = HDSkins.getInstance();
|
||||
|
||||
host.addButton(new Checkbox(40, 40, "hdskins.options.skindrops", mod.experimentalSkinDrop, checked -> {
|
||||
mod.experimentalSkinDrop = checked;
|
||||
|
||||
mod.saveConfig();
|
||||
|
||||
if (checked) {
|
||||
GLWindow.create();
|
||||
} else {
|
||||
GLWindow.dispose();
|
||||
}
|
||||
|
||||
return checked;
|
||||
})).setTooltip(host.formatMultiLine("hdskins.warning.experimental", 250));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return "HD Skins Settings";
|
||||
}
|
||||
}
|
|
@ -15,6 +15,8 @@ import javax.swing.JPanel;
|
|||
import javax.swing.JRootPane;
|
||||
import javax.swing.SwingConstants;
|
||||
|
||||
// TODO: No more swing
|
||||
@Deprecated
|
||||
public class FileDropper extends JFrame {
|
||||
private static final long serialVersionUID = -2945117328826695659L;
|
||||
|
||||
|
|
|
@ -1,28 +1,13 @@
|
|||
package com.minelittlepony.hdskins.upload;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.awt.Canvas;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Image;
|
||||
import java.awt.Window;
|
||||
import java.awt.dnd.DropTarget;
|
||||
import java.awt.dnd.DropTargetListener;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.TooManyListenersException;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
|
@ -52,40 +37,22 @@ public class GLWindow extends DropTarget {
|
|||
}
|
||||
|
||||
public static void create() {
|
||||
try {
|
||||
current().open();
|
||||
} catch (LWJGLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys the current GLWindow context and restores default behaviour.
|
||||
*/
|
||||
public static synchronized void dispose() {
|
||||
if (instance != null) {
|
||||
instance.close();
|
||||
}
|
||||
}
|
||||
|
||||
private static int getScaledPixelUnit(int i) {
|
||||
return Math.max((int)Math.round(i * Display.getPixelScaleFactor()), 0);
|
||||
}
|
||||
|
||||
private final Minecraft mc = Minecraft.getInstance();
|
||||
|
||||
private JFrame frame;
|
||||
private Canvas canvas;
|
||||
|
||||
private volatile DropTargetListener dropListener = null;
|
||||
|
||||
private int windowState = 0;
|
||||
|
||||
private boolean isFullscreen;
|
||||
|
||||
private boolean ready = false;
|
||||
private boolean closeRequested = false;
|
||||
|
||||
private GLWindow() {
|
||||
|
||||
}
|
||||
|
@ -94,162 +61,9 @@ public class GLWindow extends DropTarget {
|
|||
return frame;
|
||||
}
|
||||
|
||||
private int frameFactorX;
|
||||
private int frameFactorY;
|
||||
|
||||
private synchronized void open() throws LWJGLException {
|
||||
// Dimensions from LWJGL may have a non 1:1 scale on high DPI monitors.
|
||||
int x = getScaledPixelUnit(Display.getX());
|
||||
int y = getScaledPixelUnit(Display.getY());
|
||||
|
||||
int w = getScaledPixelUnit(Display.getWidth());
|
||||
int h = getScaledPixelUnit(Display.getHeight());
|
||||
|
||||
isFullscreen = mc.isFullScreen();
|
||||
|
||||
canvas = new Canvas();
|
||||
|
||||
frame = new JFrame(Display.getTitle());
|
||||
frame.add(canvas);
|
||||
frame.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosed(WindowEvent windowEvent) {
|
||||
if (!closeRequested) {
|
||||
for (Window w : Frame.getWindows()) {
|
||||
w.dispose();
|
||||
}
|
||||
|
||||
mc.shutdown();
|
||||
}
|
||||
closeRequested = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowStateChanged(WindowEvent event) {
|
||||
windowState = event.getNewState();
|
||||
onResize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowOpened(WindowEvent e) {
|
||||
// Once the window has opened compare the content and window dimensions to get
|
||||
// the OS's frame size then reassign adjusted dimensions to match LWJGL's window.
|
||||
frameFactorX = frame.getWidth() - frame.getContentPane().getWidth();
|
||||
frameFactorY = frame.getHeight() - frame.getContentPane().getHeight();
|
||||
|
||||
frame.setSize(w + frameFactorX, h + frameFactorY);
|
||||
}
|
||||
});
|
||||
frame.addComponentListener(new ComponentAdapter() {
|
||||
@Override
|
||||
public void componentResized(ComponentEvent componentEvent) {
|
||||
onResize();
|
||||
}
|
||||
});
|
||||
|
||||
// TODO: (Unconfirmed) reports say the icon appears small on some OSs.
|
||||
// I've yet to reproduce this.
|
||||
setIcons();
|
||||
|
||||
// Order here is important. Size is set _before_ displaying but
|
||||
// after events to ensure the window and canvas both get correct dimensions.
|
||||
frame.setResizable(Display.isResizable());
|
||||
frame.setLocation(x, y);
|
||||
frame.setSize(w, h);
|
||||
frame.setVisible(true);
|
||||
|
||||
Display.setParent(canvas);
|
||||
Display.setFullscreen(isFullscreen);
|
||||
|
||||
ready = true;
|
||||
}
|
||||
|
||||
private synchronized void close() {
|
||||
if (frame == null) {
|
||||
String msg = "GLClose was called in an illegal state! You cannot close the GLWindow before it has been opened.";
|
||||
logger.fatal(new IllegalStateException(msg));
|
||||
return;
|
||||
}
|
||||
|
||||
closeRequested = true;
|
||||
|
||||
try {
|
||||
Display.setParent(null);
|
||||
} catch (LWJGLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
if (isFullscreen) {
|
||||
Display.setFullscreen(true);
|
||||
} else {
|
||||
if ((windowState & JFrame.MAXIMIZED_BOTH) == JFrame.MAXIMIZED_BOTH) {
|
||||
Display.setLocation(0, 0);
|
||||
Display.setDisplayMode(Display.getDesktopDisplayMode());
|
||||
} else {
|
||||
Display.setDisplayMode(new DisplayMode(frame.getContentPane().getWidth(), frame.getContentPane().getHeight()));
|
||||
Display.setLocation(Math.max(0, frame.getX() + frameFactorX/3), Math.max(0, frame.getY() + frameFactorY/7));
|
||||
}
|
||||
|
||||
// https://bugs.mojang.com/browse/MC-68754
|
||||
Display.setResizable(false);
|
||||
Display.setResizable(true);
|
||||
}
|
||||
} catch (LWJGLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
frame.setVisible(false);
|
||||
frame.dispose();
|
||||
|
||||
for (Window w : Frame.getWindows()) {
|
||||
w.dispose();
|
||||
}
|
||||
|
||||
instance = null;
|
||||
}
|
||||
|
||||
private void setIcons() {
|
||||
// VanillaTweakInjector.loadIconsOnFrames();
|
||||
try {
|
||||
//
|
||||
// The icons are stored in Display#cached_icons. However they're not the _original_ values.
|
||||
// LWJGL copies the initial byte streams and then reverses them. The result is a stream that's not
|
||||
// only already consumed, but somehow invalid when you try to parse it through ImageIO.read.
|
||||
//
|
||||
DefaultResourcePack pack = (DefaultResourcePack) mc.getResourcePackRepository().rprDefaultResourcePack;
|
||||
|
||||
List<Image> images = Lists.newArrayList(
|
||||
ImageIO.read(pack.getInputStreamAssets(new ResourceLocation("icons/icon_16x16.png"))),
|
||||
ImageIO.read(pack.getInputStreamAssets(new ResourceLocation("icons/icon_32x32.png")))
|
||||
);
|
||||
|
||||
Frame[] frames = Frame.getFrames();
|
||||
|
||||
if (frames != null) {
|
||||
for (Frame frame : frames) {
|
||||
try {
|
||||
frame.setIconImages(images);
|
||||
} catch (Throwable t) {}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void onResize() {
|
||||
canvas.setBounds(0, 0, frame.getContentPane().getWidth(), frame.getContentPane().getHeight());
|
||||
}
|
||||
|
||||
public void refresh(boolean fullscreen) {
|
||||
if (ready && fullscreen != isFullscreen) {
|
||||
// Repaint the canvas, not the window.
|
||||
// The former strips the window of its state. The latter fixes a viewport scaling bug.
|
||||
canvas.setBounds(0, 0, 0, 0);
|
||||
onResize();
|
||||
isFullscreen = fullscreen;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public synchronized void clearDropTargetListener() {
|
||||
|
|
|
@ -5,6 +5,7 @@ import javax.swing.JFrame;
|
|||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@Deprecated
|
||||
final class InternalDialog {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
|
|
@ -16,6 +16,8 @@ import com.minelittlepony.hdskins.HDSkins;
|
|||
*
|
||||
* @author Adam Mummery-Smith
|
||||
*/
|
||||
//TODO: No more swing
|
||||
@Deprecated
|
||||
public abstract class ThreadOpenFile extends Thread implements IFileDialog {
|
||||
|
||||
protected String dialogTitle;
|
||||
|
|
Loading…
Reference in a new issue