|
|
@ -44,6 +44,7 @@ import com.github.weisj.darklaf.platform.decorations.CustomTitlePane; |
|
|
|
import com.github.weisj.darklaf.platform.windows.JNIDecorationsWindows; |
|
|
|
import com.github.weisj.darklaf.platform.windows.JNIDecorationsWindows; |
|
|
|
import com.github.weisj.darklaf.platform.windows.PointerUtil; |
|
|
|
import com.github.weisj.darklaf.platform.windows.PointerUtil; |
|
|
|
import com.github.weisj.darklaf.util.PropertyKey; |
|
|
|
import com.github.weisj.darklaf.util.PropertyKey; |
|
|
|
|
|
|
|
import com.github.weisj.darklaf.util.PropertyUtil; |
|
|
|
import com.github.weisj.darklaf.util.Scale; |
|
|
|
import com.github.weisj.darklaf.util.Scale; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -59,22 +60,14 @@ public class WindowsTitlePane extends CustomTitlePane { |
|
|
|
private static final int ICON_WIDTH = 32; |
|
|
|
private static final int ICON_WIDTH = 32; |
|
|
|
private static final int ICON_SIZE = ICON_WIDTH - 3 * PAD; |
|
|
|
private static final int ICON_SIZE = ICON_WIDTH - 3 * PAD; |
|
|
|
private final JRootPane rootPane; |
|
|
|
private final JRootPane rootPane; |
|
|
|
private final ContainerListener layeredPaneContainerListener = new ContainerListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void componentAdded(final ContainerEvent e) { |
|
|
|
|
|
|
|
if (e.getChild() instanceof JMenuBar) { |
|
|
|
|
|
|
|
addMenuBar(getRootPane().getJMenuBar()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (getRootPane().getJMenuBar() == null && menuBar != null) { |
|
|
|
|
|
|
|
removeMenuBar(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
private boolean unifiedMenuBar; |
|
|
|
public void componentRemoved(final ContainerEvent e) {} |
|
|
|
private ContainerListener rootPaneContainerListener; |
|
|
|
}; |
|
|
|
private ContainerListener layeredPaneContainerListener; |
|
|
|
|
|
|
|
|
|
|
|
private boolean oldResizable; |
|
|
|
private boolean oldResizable; |
|
|
|
private PropertyChangeListener propertyChangeListener; |
|
|
|
private PropertyChangeListener windowPropertyChangeListener; |
|
|
|
|
|
|
|
private PropertyChangeListener rootPanePropertyChangeListener; |
|
|
|
private WindowListener windowListener; |
|
|
|
private WindowListener windowListener; |
|
|
|
private ToggleIcon closeIcon; |
|
|
|
private ToggleIcon closeIcon; |
|
|
|
private ToggleIcon maximizeIcon; |
|
|
|
private ToggleIcon maximizeIcon; |
|
|
@ -92,21 +85,6 @@ public class WindowsTitlePane extends CustomTitlePane { |
|
|
|
private final Window window; |
|
|
|
private final Window window; |
|
|
|
private long windowHandle; |
|
|
|
private long windowHandle; |
|
|
|
private JMenuBar menuBar; |
|
|
|
private JMenuBar menuBar; |
|
|
|
private final ContainerListener rootPaneContainerListener = new ContainerListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void componentAdded(final ContainerEvent e) { |
|
|
|
|
|
|
|
if (e.getChild() instanceof JLayeredPane) { |
|
|
|
|
|
|
|
((JLayeredPane) e.getChild()).addContainerListener(layeredPaneContainerListener); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void componentRemoved(final ContainerEvent e) { |
|
|
|
|
|
|
|
if (e.getChild() instanceof JLayeredPane) { |
|
|
|
|
|
|
|
((JLayeredPane) e.getChild()).removeContainerListener(layeredPaneContainerListener); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
private int state; |
|
|
|
private int state; |
|
|
|
|
|
|
|
|
|
|
|
private Color inactiveBackground; |
|
|
|
private Color inactiveBackground; |
|
|
@ -131,8 +109,9 @@ public class WindowsTitlePane extends CustomTitlePane { |
|
|
|
this.window = window; |
|
|
|
this.window = window; |
|
|
|
bundle = ResourceBundle.getBundle("com.github.weisj.darklaf.bundles.actions", getLocale()); |
|
|
|
bundle = ResourceBundle.getBundle("com.github.weisj.darklaf.bundles.actions", getLocale()); |
|
|
|
this.decorationStyle = decorationStyle; |
|
|
|
this.decorationStyle = decorationStyle; |
|
|
|
rootPane.addContainerListener(rootPaneContainerListener); |
|
|
|
|
|
|
|
rootPane.getLayeredPane().addContainerListener(layeredPaneContainerListener); |
|
|
|
updateMenuBar(true); |
|
|
|
|
|
|
|
|
|
|
|
state = -1; |
|
|
|
state = -1; |
|
|
|
oldResizable = true; |
|
|
|
oldResizable = true; |
|
|
|
installSubcomponents(); |
|
|
|
installSubcomponents(); |
|
|
@ -140,6 +119,65 @@ public class WindowsTitlePane extends CustomTitlePane { |
|
|
|
setLayout(createLayout()); |
|
|
|
setLayout(createLayout()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void updateMenuBar(final boolean install) { |
|
|
|
|
|
|
|
unifiedMenuBar = PropertyUtil.getBooleanProperty(rootPane, "JRootPane.unifiedMenuBar"); |
|
|
|
|
|
|
|
if (unifiedMenuBar && install) { |
|
|
|
|
|
|
|
if (rootPaneContainerListener == null) { |
|
|
|
|
|
|
|
rootPaneContainerListener = createRootPaneContainerListener(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (layeredPaneContainerListener == null) { |
|
|
|
|
|
|
|
layeredPaneContainerListener = createLayeredPaneContainerListener(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
rootPane.addContainerListener(rootPaneContainerListener); |
|
|
|
|
|
|
|
rootPane.getLayeredPane().addContainerListener(layeredPaneContainerListener); |
|
|
|
|
|
|
|
addMenuBar(getRootPane().getJMenuBar()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
rootPane.removeContainerListener(rootPaneContainerListener); |
|
|
|
|
|
|
|
rootPane.getLayeredPane().removeContainerListener(layeredPaneContainerListener); |
|
|
|
|
|
|
|
if (menuBar != null) { |
|
|
|
|
|
|
|
getRootPane().setJMenuBar(menuBar); |
|
|
|
|
|
|
|
menuBar.setPreferredSize(null); |
|
|
|
|
|
|
|
menuBar = null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
rootPane.revalidate(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ContainerListener createRootPaneContainerListener() { |
|
|
|
|
|
|
|
return new ContainerListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void componentAdded(final ContainerEvent e) { |
|
|
|
|
|
|
|
if (e.getChild() instanceof JLayeredPane) { |
|
|
|
|
|
|
|
((JLayeredPane) e.getChild()).addContainerListener(layeredPaneContainerListener); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void componentRemoved(final ContainerEvent e) { |
|
|
|
|
|
|
|
if (e.getChild() instanceof JLayeredPane) { |
|
|
|
|
|
|
|
((JLayeredPane) e.getChild()).removeContainerListener(layeredPaneContainerListener); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ContainerListener createLayeredPaneContainerListener() { |
|
|
|
|
|
|
|
return new ContainerListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void componentAdded(final ContainerEvent e) { |
|
|
|
|
|
|
|
if (e.getChild() instanceof JMenuBar) { |
|
|
|
|
|
|
|
addMenuBar(getRootPane().getJMenuBar()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (getRootPane().getJMenuBar() == null && menuBar != null) { |
|
|
|
|
|
|
|
removeMenuBar(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void componentRemoved(final ContainerEvent e) {} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static JButton createButton(final Icon icon, final Action action) { |
|
|
|
private static JButton createButton(final Icon icon, final Action action) { |
|
|
|
return createButton(icon, action, false); |
|
|
|
return createButton(icon, action, false); |
|
|
|
} |
|
|
|
} |
|
|
@ -177,19 +215,16 @@ public class WindowsTitlePane extends CustomTitlePane { |
|
|
|
uninstallListeners(); |
|
|
|
uninstallListeners(); |
|
|
|
uninstallDecorations(removeDecorations); |
|
|
|
uninstallDecorations(removeDecorations); |
|
|
|
removeAll(); |
|
|
|
removeAll(); |
|
|
|
if (menuBar != null) { |
|
|
|
updateMenuBar(false); |
|
|
|
getRootPane().setJMenuBar(menuBar); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void uninstallListeners() { |
|
|
|
private void uninstallListeners() { |
|
|
|
if (window != null) { |
|
|
|
if (window != null) { |
|
|
|
window.removeWindowListener(windowListener); |
|
|
|
window.removeWindowListener(windowListener); |
|
|
|
window.removePropertyChangeListener(propertyChangeListener); |
|
|
|
window.removePropertyChangeListener(windowPropertyChangeListener); |
|
|
|
} |
|
|
|
} |
|
|
|
if (rootPane != null) { |
|
|
|
if (rootPane != null) { |
|
|
|
rootPane.removeContainerListener(rootPaneContainerListener); |
|
|
|
rootPane.removePropertyChangeListener(rootPanePropertyChangeListener); |
|
|
|
rootPane.getLayeredPane().removeContainerListener(layeredPaneContainerListener); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -259,8 +294,10 @@ public class WindowsTitlePane extends CustomTitlePane { |
|
|
|
if (window != null) { |
|
|
|
if (window != null) { |
|
|
|
windowListener = createWindowListener(); |
|
|
|
windowListener = createWindowListener(); |
|
|
|
window.addWindowListener(windowListener); |
|
|
|
window.addWindowListener(windowListener); |
|
|
|
propertyChangeListener = createWindowPropertyChangeListener(); |
|
|
|
windowPropertyChangeListener = createWindowPropertyChangeListener(); |
|
|
|
window.addPropertyChangeListener(propertyChangeListener); |
|
|
|
rootPanePropertyChangeListener = createRootPanePropertyChangeListener(); |
|
|
|
|
|
|
|
rootPane.addPropertyChangeListener(rootPanePropertyChangeListener); |
|
|
|
|
|
|
|
window.addPropertyChangeListener(windowPropertyChangeListener); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -269,7 +306,11 @@ public class WindowsTitlePane extends CustomTitlePane { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private PropertyChangeListener createWindowPropertyChangeListener() { |
|
|
|
private PropertyChangeListener createWindowPropertyChangeListener() { |
|
|
|
return new PropertyChangeHandler(); |
|
|
|
return new WindowPropertyChangeListener(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private PropertyChangeListener createRootPanePropertyChangeListener() { |
|
|
|
|
|
|
|
return new RootPanePropertyChangeListener(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void installSubcomponents() { |
|
|
|
private void installSubcomponents() { |
|
|
@ -294,7 +335,7 @@ public class WindowsTitlePane extends CustomTitlePane { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected void addMenuBar(final JMenuBar menuBar) { |
|
|
|
protected void addMenuBar(final JMenuBar menuBar) { |
|
|
|
if (menuBar != null) { |
|
|
|
if (menuBar != null && unifiedMenuBar) { |
|
|
|
this.menuBar = menuBar; |
|
|
|
this.menuBar = menuBar; |
|
|
|
// Otherwise, a white bar will appear where the menuBar used to be.
|
|
|
|
// Otherwise, a white bar will appear where the menuBar used to be.
|
|
|
|
menuBar.setPreferredSize(new Dimension(0, 0)); |
|
|
|
menuBar.setPreferredSize(new Dimension(0, 0)); |
|
|
@ -809,7 +850,7 @@ public class WindowsTitlePane extends CustomTitlePane { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected class PropertyChangeHandler implements PropertyChangeListener { |
|
|
|
protected class WindowPropertyChangeListener implements PropertyChangeListener { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void propertyChange(final PropertyChangeEvent pce) { |
|
|
|
public void propertyChange(final PropertyChangeEvent pce) { |
|
|
@ -842,6 +883,16 @@ public class WindowsTitlePane extends CustomTitlePane { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected class RootPanePropertyChangeListener implements PropertyChangeListener { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void propertyChange(final PropertyChangeEvent evt) { |
|
|
|
|
|
|
|
if ("JRootPane.unifiedMenuBar".equals(evt.getPropertyName())) { |
|
|
|
|
|
|
|
updateMenuBar(true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected class WindowHandler extends WindowAdapter { |
|
|
|
protected class WindowHandler extends WindowAdapter { |
|
|
|
|
|
|
|
|
|
|
|
public void windowActivated(final WindowEvent ev) { |
|
|
|
public void windowActivated(final WindowEvent ev) { |
|
|
|