2222package de .quippy .javamod .main .gui ;
2323
2424import java .awt .Color ;
25- import java .awt .Dimension ;
2625import java .awt .GraphicsConfiguration ;
2726import java .awt .GraphicsDevice ;
2827import java .awt .Rectangle ;
@@ -58,17 +57,19 @@ public class XmasScreenConfigPanel extends JPanel
5857
5958 private static final String PROPERTY_XMAS_ENABLED = "javamod.xmas.enabled." ;
6059 private static final String PROPERTY_XMAS_WITHSPACE = "javamod.xmas.withspace." ;
60+ private static final String PROPERTY_XMAS_ALWAYSONTOP = "javamod.xmas.alwaysontop." ;
6161 private static final String PROPERTY_XMAS_FLICKERTYPE = "javamod.xmas.flickertype." ;
6262 private static final String PROPERTY_XMAS_UPDATEFPS = "javamod.xmas.updatefps." ;
6363
6464 private JCheckBox xmasEnabledCheckBox = null ;
65+ private JCheckBox alwaysOnTopCheckBox = null ;
6566 private JCheckBox withSpaceCheckBox = null ;
6667 private JLabel flickerTypeLabel = null ;
6768 private JLabel updateFPSLabel = null ;
6869 private JComboBox <String > flickerTypeSelector = null ;
6970 private JSlider updateFPSSelector = null ;
7071
71- private JWindow transparentJFrame = null ;
72+ private JWindow transparentWindow = null ;
7273 private XmasDecorationPanel xmasDecorationPanel = null ;
7374
7475 private final int screenFPS ;
@@ -93,11 +94,12 @@ private void initialize()
9394 setName ("Xmas Screen Config for Screen" );
9495 setLayout (new java .awt .GridBagLayout ());
9596 add (getXmasEnabledCheckBox (), Helpers .getGridBagConstraint (0 , 0 , 1 , 3 , java .awt .GridBagConstraints .NONE , java .awt .GridBagConstraints .WEST , 0.0 , 0.0 ));
96- add (getWithSpaceCheckBox (), Helpers .getGridBagConstraint (0 , 1 , 1 , 1 , java .awt .GridBagConstraints .NONE , java .awt .GridBagConstraints .WEST , 0.0 , 0.0 ));
97- add (getFlickerTypeLabel (), Helpers .getGridBagConstraint (1 , 1 , 1 , 1 , java .awt .GridBagConstraints .NONE , java .awt .GridBagConstraints .WEST , 0.0 , 0.0 ));
98- add (getFlickerTypeSelector (), Helpers .getGridBagConstraint (2 , 1 , 1 , 1 , java .awt .GridBagConstraints .NONE , java .awt .GridBagConstraints .WEST , 0.0 , 0.0 ));
99- add (getUpdateFPSLabel (), Helpers .getGridBagConstraint (0 , 2 , 1 , 1 , java .awt .GridBagConstraints .NONE , java .awt .GridBagConstraints .WEST , 0.0 , 0.0 ));
100- add (getUpdateFPSSelector (), Helpers .getGridBagConstraint (1 , 2 , 1 , 2 , java .awt .GridBagConstraints .HORIZONTAL , java .awt .GridBagConstraints .WEST , 1.0 , 0.0 ));
97+ add (getAlwaysOnTopBox (), Helpers .getGridBagConstraint (0 , 1 , 1 , 1 , java .awt .GridBagConstraints .NONE , java .awt .GridBagConstraints .WEST , 0.0 , 0.0 ));
98+ add (getWithSpaceCheckBox (), Helpers .getGridBagConstraint (0 , 2 , 1 , 1 , java .awt .GridBagConstraints .NONE , java .awt .GridBagConstraints .WEST , 0.0 , 0.0 ));
99+ add (getFlickerTypeLabel (), Helpers .getGridBagConstraint (1 , 2 , 1 , 1 , java .awt .GridBagConstraints .NONE , java .awt .GridBagConstraints .WEST , 0.0 , 0.0 ));
100+ add (getFlickerTypeSelector (), Helpers .getGridBagConstraint (2 , 2 , 1 , 1 , java .awt .GridBagConstraints .NONE , java .awt .GridBagConstraints .WEST , 0.0 , 0.0 ));
101+ add (getUpdateFPSLabel (), Helpers .getGridBagConstraint (0 , 3 , 1 , 1 , java .awt .GridBagConstraints .NONE , java .awt .GridBagConstraints .WEST , 0.0 , 0.0 ));
102+ add (getUpdateFPSSelector (), Helpers .getGridBagConstraint (1 , 3 , 1 , 2 , java .awt .GridBagConstraints .HORIZONTAL , java .awt .GridBagConstraints .WEST , 1.0 , 0.0 ));
101103 }
102104 private JCheckBox getXmasEnabledCheckBox ()
103105 {
@@ -124,13 +126,38 @@ public void itemStateChanged(final ItemEvent e)
124126 }
125127 return xmasEnabledCheckBox ;
126128 }
129+ private JCheckBox getAlwaysOnTopBox ()
130+ {
131+ if (alwaysOnTopCheckBox == null )
132+ {
133+ alwaysOnTopCheckBox = new javax .swing .JCheckBox ();
134+ alwaysOnTopCheckBox .setName ("alwaysOnTopCheckBox" );
135+ alwaysOnTopCheckBox .setText ("always on top" );
136+ alwaysOnTopCheckBox .setFont (Helpers .getDialogFont ());
137+ alwaysOnTopCheckBox .setSelected (isWithSpaceEnabled ());
138+ alwaysOnTopCheckBox .addItemListener (new ItemListener ()
139+ {
140+ @ Override
141+ public void itemStateChanged (final ItemEvent e )
142+ {
143+ if (e .getStateChange ()==ItemEvent .SELECTED || e .getStateChange ()==ItemEvent .DESELECTED )
144+ {
145+ final boolean isOnTop = getAlwaysOnTopBox ().isSelected ();
146+ getTransparentJWindow ().setAlwaysOnTop (isOnTop );
147+ if (isOnTop ) getTransparentJWindow ().toFront ();
148+ }
149+ }
150+ });
151+ }
152+ return alwaysOnTopCheckBox ;
153+ }
127154 private JCheckBox getWithSpaceCheckBox ()
128155 {
129156 if (withSpaceCheckBox == null )
130157 {
131158 withSpaceCheckBox = new javax .swing .JCheckBox ();
132159 withSpaceCheckBox .setName ("withSpaceCheckBox" );
133- withSpaceCheckBox .setText ("with Space " );
160+ withSpaceCheckBox .setText ("with space " );
134161 withSpaceCheckBox .setFont (Helpers .getDialogFont ());
135162 withSpaceCheckBox .setSelected (isWithSpaceEnabled ());
136163 withSpaceCheckBox .addItemListener (new ItemListener ()
@@ -235,23 +262,29 @@ private JWindow getTransparentJWindow()
235262 // But whatever the difference of a JWindow to a Window is, a Window
236263 // does not work with the OpenGL render pipeline.
237264 // On Linux / KDE the OpenGL pipeline reduces flicker, however the
238- // Window inherits the alpha value of the underlying window...
239- if (transparentJFrame == null )
265+ // Window inherits the alpha value of the underlying window..
266+ // A JFrame is possibly like using a sledgehammer to crack a nut - and
267+ // will create an icon in the taskbar at Linux
268+ if (transparentWindow == null )
240269 {
241- transparentJFrame = new JWindow ();
242- transparentJFrame .setAlwaysOnTop (true );
270+ transparentWindow = new JWindow ();
243271
244272 final GraphicsConfiguration gc = screen .getDefaultConfiguration ();
245273 final Rectangle bounds = gc .getBounds ();
246274 bounds .height = defaultScreenHeight ;
247- transparentJFrame .setBounds (bounds );
275+ transparentWindow .setBounds (bounds );
276+ transparentWindow .setAlwaysOnTop (true );
277+ transparentWindow .toFront (); // just in case...
278+ //transparentWindow.setUndecorated(true); - JFrame needs this
279+ transparentWindow .setFocusable (false );
280+ transparentWindow .setFocusableWindowState (false );
281+ transparentWindow .setBackground (new Color (0 , true ));
248282
249- transparentJFrame .setBackground (new Color (0 , true ));
250- transparentJFrame .setContentPane (getXmasDecorationPanel ());
251- transparentJFrame .setFocusable (false );
252- transparentJFrame .setFocusableWindowState (false );
283+ final XmasDecorationPanel xmasDecorationPanel = getXmasDecorationPanel ();
284+ xmasDecorationPanel .setSize (transparentWindow .getSize ());
285+ transparentWindow .setContentPane (xmasDecorationPanel );
253286 }
254- return transparentJFrame ;
287+ return transparentWindow ;
255288 }
256289 private XmasDecorationPanel getXmasDecorationPanel ()
257290 {
@@ -261,8 +294,6 @@ private XmasDecorationPanel getXmasDecorationPanel()
261294 xmasDecorationPanel .setBorder (BorderFactory .createEmptyBorder ());
262295 xmasDecorationPanel .setOpaque (false );
263296 xmasDecorationPanel .setBackground (new Color (0 , true ));
264- final Dimension d = getTransparentJWindow ().getSize ();
265- xmasDecorationPanel .setSize (d );
266297 }
267298 return xmasDecorationPanel ;
268299 }
@@ -274,6 +305,14 @@ private void setXmasEnabled(final boolean xmasEnabled)
274305 {
275306 getXmasEnabledCheckBox ().setSelected (xmasEnabled );
276307 }
308+ private boolean isAlwaysOnTopEnabled ()
309+ {
310+ return getAlwaysOnTopBox ().isSelected ();
311+ }
312+ private void setAlwaysOnTopEnabled (final boolean alwaysOnTopEnabled )
313+ {
314+ getAlwaysOnTopBox ().setSelected (alwaysOnTopEnabled );
315+ }
277316 private boolean isWithSpaceEnabled ()
278317 {
279318 return getWithSpaceCheckBox ().isSelected ();
@@ -309,12 +348,14 @@ public void readProperties(final Properties props, final int forScreen)
309348 setFlickerType (Integer .parseInt (props .getProperty (PROPERTY_XMAS_FLICKERTYPE +index , "4" )));
310349 setUpdateFPS (Integer .parseInt (props .getProperty (PROPERTY_XMAS_UPDATEFPS +index , "2" )));
311350 setWithSpaceEnabled (Boolean .parseBoolean (props .getProperty (PROPERTY_XMAS_WITHSPACE +index , "FALSE" )));
351+ setAlwaysOnTopEnabled (Boolean .parseBoolean (props .getProperty (PROPERTY_XMAS_ALWAYSONTOP +index , "TRUE" )));
312352 setXmasEnabled (Boolean .parseBoolean (props .getProperty (PROPERTY_XMAS_ENABLED +index , "FALSE" )));
313353 }
314354 public void writeProperties (final Properties props , final int forScreen )
315355 {
316356 final String index = Integer .toString (forScreen );
317357 props .setProperty (PROPERTY_XMAS_ENABLED +index , Boolean .toString (isXmasEnabled ()));
358+ props .setProperty (PROPERTY_XMAS_ALWAYSONTOP +index , Boolean .toString (isAlwaysOnTopEnabled ()));
318359 props .setProperty (PROPERTY_XMAS_WITHSPACE +index , Boolean .toString (isWithSpaceEnabled ()));
319360 props .setProperty (PROPERTY_XMAS_FLICKERTYPE +index , Integer .toString (getFlickerType ()));
320361 props .setProperty (PROPERTY_XMAS_UPDATEFPS +index , Integer .toString (getUpdateFPS ()));
0 commit comments