some UI Updates for Picking a custom Background color, and having Multiple Monitor Fullscreen!
This commit is contained in:
@@ -2,7 +2,7 @@ package io.swtc;
|
||||
|
||||
import com.github.sarxos.webcam.Webcam;
|
||||
import io.swtc.proccessing.ui.IconSetter;
|
||||
import io.swtc.proccessing.ui.iframe.*; // Your custom frames
|
||||
import io.swtc.proccessing.ui.iframe.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
@@ -10,6 +10,7 @@ import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class SwingIFrame {
|
||||
private final JFrame mainFrame;
|
||||
@@ -109,7 +110,14 @@ public class SwingIFrame {
|
||||
popupMenu.removeAll(); // clean slate
|
||||
|
||||
JCheckBoxMenuItem fullscreenItem = new JCheckBoxMenuItem("Fullscreen");
|
||||
JCheckBoxMenuItem mmfullscreenItem = new JCheckBoxMenuItem("Multi Monitor Fullscreen");
|
||||
JCheckBoxMenuItem backgroundcolor = new JCheckBoxMenuItem("Calmer Background");
|
||||
JMenuItem colorpicker = new JMenuItem("Set background color");
|
||||
|
||||
fullscreenItem.addActionListener(e -> toggleFullscreen());
|
||||
mmfullscreenItem.addActionListener(e -> toggleMMFullscreen());
|
||||
backgroundcolor.addActionListener(e -> toggleBackground());
|
||||
colorpicker.addActionListener(e -> chooseBgColor());
|
||||
|
||||
popupMenu.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
|
||||
@Override
|
||||
@@ -121,6 +129,22 @@ public class SwingIFrame {
|
||||
});
|
||||
|
||||
popupMenu.add(fullscreenItem);
|
||||
popupMenu.add(mmfullscreenItem);
|
||||
popupMenu.add(backgroundcolor);
|
||||
popupMenu.add(colorpicker);
|
||||
}
|
||||
|
||||
private void chooseBgColor() {
|
||||
Color selected = JColorChooser.showDialog(
|
||||
mainFrame,
|
||||
"Select Background Color",
|
||||
desktopPane.getBackground()
|
||||
);
|
||||
|
||||
if (!Objects.isNull(selected)) {
|
||||
desktopPane.setBackground(selected);
|
||||
desktopPane.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
private void setupBlackBg() {
|
||||
@@ -137,6 +161,7 @@ public class SwingIFrame {
|
||||
|
||||
private void setupFullscreenToggle() {
|
||||
JRootPane root = mainFrame.getRootPane();
|
||||
// One Monitor FS
|
||||
root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
|
||||
.put(KeyStroke.getKeyStroke("F11"), "toggleFullscreen");
|
||||
root.getActionMap().put("toggleFullscreen", new AbstractAction() {
|
||||
@@ -145,6 +170,16 @@ public class SwingIFrame {
|
||||
toggleFullscreen();
|
||||
}
|
||||
});
|
||||
|
||||
// Multi Monitor FS
|
||||
root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
|
||||
.put(KeyStroke.getKeyStroke("F12"), "toggleMMFullscreen");
|
||||
root.getActionMap().put("toggleMMFullscreen", new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
toggleMMFullscreen();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void toggleBackground() {
|
||||
@@ -153,6 +188,33 @@ public class SwingIFrame {
|
||||
desktopPane.repaint();
|
||||
}
|
||||
|
||||
private void toggleMMFullscreen() {
|
||||
if (!fullscreen) {
|
||||
windowedBounds = mainFrame.getBounds();
|
||||
|
||||
Rectangle virtualBounds = new Rectangle();
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
GraphicsDevice[] gs = ge.getScreenDevices();
|
||||
|
||||
for (GraphicsDevice gd : gs) {
|
||||
GraphicsConfiguration[] gc = gd.getConfigurations();
|
||||
for (GraphicsConfiguration configuration : gc) {
|
||||
virtualBounds = virtualBounds.union(configuration.getBounds());
|
||||
}
|
||||
}
|
||||
|
||||
mainFrame.dispose();
|
||||
mainFrame.setUndecorated(true);
|
||||
|
||||
mainFrame.setBounds(virtualBounds);
|
||||
mainFrame.setVisible(true);
|
||||
|
||||
fullscreen = true;
|
||||
} else {
|
||||
toggleFullscreen();
|
||||
}
|
||||
}
|
||||
|
||||
/** Toggle fullscreen mode */
|
||||
private void toggleFullscreen() {
|
||||
if (!fullscreen) {
|
||||
|
||||
Reference in New Issue
Block a user