Skip to content

Commit

Permalink
Remember window size and position between restarts
Browse files Browse the repository at this point in the history
Added window and taskbar icons
  • Loading branch information
Eirenliel committed Sep 2, 2021
1 parent 6c27186 commit 7e95c9f
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 5 deletions.
24 changes: 24 additions & 0 deletions src/main/java/io/eiren/gui/AbstractComponentListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.eiren.gui;

import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;

public abstract class AbstractComponentListener implements ComponentListener {

@Override
public void componentResized(ComponentEvent e) {
}

@Override
public void componentMoved(ComponentEvent e) {
}

@Override
public void componentShown(ComponentEvent e) {
}

@Override
public void componentHidden(ComponentEvent e) {
}

}
35 changes: 35 additions & 0 deletions src/main/java/io/eiren/gui/AbstractWindowListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.eiren.gui;

import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

public abstract class AbstractWindowListener implements WindowListener {

@Override
public void windowOpened(WindowEvent e) {
}

@Override
public void windowClosing(WindowEvent e) {
}

@Override
public void windowClosed(WindowEvent e) {
}

@Override
public void windowIconified(WindowEvent e) {
}

@Override
public void windowDeiconified(WindowEvent e) {
}

@Override
public void windowActivated(WindowEvent e) {
}

@Override
public void windowDeactivated(WindowEvent e) {
}
}
60 changes: 56 additions & 4 deletions src/main/java/io/eiren/gui/VRServerGUI.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package io.eiren.gui;

import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.event.MouseInputAdapter;

import io.eiren.util.MacOSX;
import io.eiren.util.OperatingSystem;
import io.eiren.util.StringUtils;
import io.eiren.util.ann.AWTThread;
import io.eiren.vr.Main;
Expand All @@ -13,15 +16,24 @@
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GraphicsConfiguration;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentEvent;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import static javax.swing.BoxLayout.PAGE_AXIS;
import static javax.swing.BoxLayout.LINE_AXIS;

public class VRServerGUI extends JFrame {

public static final String TITLE = "SlimeVR Server (" + Main.VERSION + ")";

public final VRServer server;
private final TrackersList trackersList;
private final SkeletonList skeletonList;
Expand All @@ -34,13 +46,29 @@ public class VRServerGUI extends JFrame {

@AWTThread
public VRServerGUI(VRServer server) {
super("SlimeVR Server (" + Main.VERSION + ")");
super(TITLE);
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch(Exception e) {
e.printStackTrace();
}
//increaseFontSize();
if(OperatingSystem.getCurrentPlatform() == OperatingSystem.OSX)
MacOSX.setTitle(TITLE);
try {
List<BufferedImage> images = new ArrayList<BufferedImage>(6);
images.add(ImageIO.read(VRServerGUI.class.getResource("/icon16.png")));
images.add(ImageIO.read(VRServerGUI.class.getResource("/icon32.png")));
images.add(ImageIO.read(VRServerGUI.class.getResource("/icon48.png")));
images.add(ImageIO.read(VRServerGUI.class.getResource("/icon64.png")));
images.add(ImageIO.read(VRServerGUI.class.getResource("/icon128.png")));
images.add(ImageIO.read(VRServerGUI.class.getResource("/icon256.png")));
setIconImages(images);
if(OperatingSystem.getCurrentPlatform() == OperatingSystem.OSX) {
MacOSX.setIcons(images);
}
} catch(IOException e1) {
e1.printStackTrace();
}

this.server = server;

Expand All @@ -56,12 +84,37 @@ public VRServerGUI(VRServer server) {
this.skeletonList = new SkeletonList(server, this);

add(scroll = new JScrollPane(pane = new EJBox(PAGE_AXIS), ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED));
GraphicsConfiguration gc = getGraphicsConfiguration();
Rectangle screenBounds = gc.getBounds();
setMinimumSize(new Dimension(100, 100));
setSize(Math.min(server.config.getInt("window.width", 800), screenBounds.width), Math.min(server.config.getInt("window.height", 800), screenBounds.height));
setLocation(server.config.getInt("window.posx", screenBounds.x + (screenBounds.width - getSize().width) / 2), screenBounds.y + server.config.getInt("window.posy", (screenBounds.height - getSize().height) / 2));

setMinimumSize(new Dimension(1280, 1080));
// Resize and close listeners to save position and size betwen launcher starts
addComponentListener(new AbstractComponentListener() {
@Override
public void componentResized(ComponentEvent e) {
saveFrameInfo();
}

@Override
public void componentMoved(ComponentEvent e) {
saveFrameInfo();
}
});

build();
}

protected void saveFrameInfo() {
Rectangle b = getBounds();
server.config.setProperty("window.width", b.width);
server.config.setProperty("window.height", b.height);
server.config.setProperty("window.posx", b.x);
server.config.setProperty("window.posy", b.y);
server.saveConfig();
}

public float getZoom() {
return this.zoom;
}
Expand Down Expand Up @@ -196,7 +249,6 @@ public void actionPerformed(ActionEvent e) {
}});

refresh();
setLocationRelativeTo(null);

server.addOnTick(trackersList::updateTrackers);
server.addOnTick(skeletonList::updateBones);
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/io/eiren/vr/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class Main {

public static String VERSION = "0.0.17";
public static String VERSION = "0.0.18";

public static VRServer vrServer;

Expand All @@ -29,6 +29,12 @@ public static void main(String[] args) {
new VRServerGUI(vrServer);
} catch(Throwable e) {
e.printStackTrace();
try {
Thread.sleep(2000L);
} catch(InterruptedException e2) {
e.printStackTrace();
}
System.exit(1); // Exit in case error happened on init and window not appeared, but some thread started
} finally {
try {
Thread.sleep(2000L);
Expand Down
Binary file added src/main/resources/icon128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/icon16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/icon256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/icon32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/icon48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/icon64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7e95c9f

Please sign in to comment.