Skip to content

Commit

Permalink
Updated to used active monitor in multi monitor setup
Browse files Browse the repository at this point in the history
  • Loading branch information
C4J committed Jun 8, 2024
1 parent d94ac88 commit b588d0d
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 11 deletions.
4 changes: 2 additions & 2 deletions b6Middleware/b6middleware.install4j
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<install4j version="10.0.7" transformSequenceNumber="10">
<install4j version="10.0.8" transformSequenceNumber="10">
<directoryPresets config="./samples/advanced" />
<application name="Commander4j Middleware" applicationId="1915-8055-3520-8512" mediaDir="../../../Distribution/java17/b6middleware4j" compression="9" shortName="c4jMiddleware" publisher="David Garratt" publisherWeb="http://www.commander4j.com" version="5.24" allPathsRelative="true" macVolumeId="ebde9226275d23ed" javaMinVersion="17" javaMaxVersion="17">
<application name="Commander4j Middleware" applicationId="1915-8055-3520-8512" mediaDir="../../../Distribution/java17/b6middleware4j" compression="9" shortName="c4jMiddleware" publisher="David Garratt" publisherWeb="http://www.commander4j.com" version="5.25" allPathsRelative="true" macVolumeId="ebde9226275d23ed" javaMinVersion="17" javaMaxVersion="17">
<languages skipLanguageSelection="true">
<additionalLanguages>
<language id="da" />
Expand Down
Binary file modified b6Middleware/c4jMiddleware.jar
Binary file not shown.
25 changes: 17 additions & 8 deletions b6Middleware/src/com/commander4j/mw/StartGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
Expand All @@ -21,6 +22,7 @@
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListModel;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.border.BevelBorder;
import javax.swing.border.EmptyBorder;
Expand All @@ -29,7 +31,6 @@
import com.commander4j.gui.JList4j;
import com.commander4j.sys.Common;
import com.commander4j.util.Utility;
import javax.swing.ListSelectionModel;

public class StartGUI extends JFrame
{
Expand Down Expand Up @@ -106,8 +107,17 @@ public void run()
{
try
{
StartGUI.frame = new StartGUI();
StartGUI.frame.setVisible(true);
frame = new StartGUI();

GraphicsDevice gd = Utility.getGraphicsDevice();

GraphicsConfiguration gc = gd.getDefaultConfiguration();

Rectangle screenBounds = gc.getBounds();

frame.setBounds(screenBounds.x + ((screenBounds.width - frame.getWidth()) / 2), screenBounds.y + ((screenBounds.height - frame.getHeight()) / 2), frame.getWidth(), frame.getHeight());

frame.setVisible(true);

} catch (Exception e)
{
Expand All @@ -126,16 +136,15 @@ public StartGUI()
setTitle("Commander4j Middleware" + " " + StartMain.version);
util.initLogging("");
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
setBounds(100, 100, 1319, 765);

setSize(1319, 765);

contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
addWindowListener(new WindowListener());

Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle window = getBounds();
setLocation((screen.width - window.width) / 2, (screen.height - window.height) / 2);

JButton btnClose = new JButton(Common.icon_close);
btnClose.setFont(new Font("Dialog", Font.PLAIN, 12));
Expand Down
2 changes: 1 addition & 1 deletion b6Middleware/src/com/commander4j/mw/StartMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class StartMain

Logger logger = org.apache.logging.log4j.LogManager.getLogger((StartMain.class));
public MiddlewareConfig cfg;
public static String version = "5.24";
public static String version = "5.25";
Boolean running = false;
LogArchiveThread archiveLog;
StatusThread statusthread;
Expand Down
58 changes: 58 additions & 0 deletions b6Middleware/src/com/commander4j/util/Utility.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.commander4j.util;

import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.HeadlessException;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.Rectangle;
import java.io.File;
import java.io.StringWriter;
import java.net.InetAddress;
Expand All @@ -23,6 +29,58 @@
public class Utility
{

public static GraphicsDevice getGraphicsDevice()
{
GraphicsDevice result;

Point mouseLocation = MouseInfo.getPointerInfo().getLocation();

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

GraphicsDevice[] devices;

try
{
devices = ge.getScreenDevices();

GraphicsDevice currentDevice = null;

for (GraphicsDevice device : devices)
{
Rectangle bounds = device.getDefaultConfiguration().getBounds();
if (bounds.contains(mouseLocation))
{
currentDevice = device;
break;
}
}

GraphicsDevice[] gs = ge.getScreenDevices();

String defaultID = currentDevice.getIDstring();

int monitorIndex = 0;

for (int x = 0; x < gs.length; x++)
{
if (gs[x].getIDstring().equals(defaultID))
{
monitorIndex = x;
break;
}
}

result = gs[monitorIndex];
}
catch (HeadlessException ex)
{
result = null;
}

return result;
}


public Timestamp getTimeStampFromISOString(String isoString)
{
Timestamp result;
Expand Down

0 comments on commit b588d0d

Please sign in to comment.