diff --git a/src/main/java/mdlaf/components/button/MaterialButtonUI.java b/src/main/java/mdlaf/components/button/MaterialButtonUI.java index 9e581f9..7180698 100644 --- a/src/main/java/mdlaf/components/button/MaterialButtonUI.java +++ b/src/main/java/mdlaf/components/button/MaterialButtonUI.java @@ -96,9 +96,11 @@ public void installUI(JComponent c) { } /** - * Inside the future version 1.2 this method will contain all component that work with listener, - * because this method is call before the installListener and I can insert the control of the - * listener inside the native method. TODO make the button installDefault change + * The installDefaults method is a good place to add the default setting, because it is called + * before to install methods and this give to the user the possibility to change the button style + * inside the installation method without worried about the order pre and post super.install call. + * + *

FIXME: starting the transition to the workflow described in the comment */ @Override protected void installDefaults(AbstractButton b) { diff --git a/src/main/java/mdlaf/components/button/MaterialButtonsComponentsUI.java b/src/main/java/mdlaf/components/button/MaterialButtonsComponentsUI.java index 062b4cf..129f187 100644 --- a/src/main/java/mdlaf/components/button/MaterialButtonsComponentsUI.java +++ b/src/main/java/mdlaf/components/button/MaterialButtonsComponentsUI.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2019-2020 Vincenzo Palazzo vincenzopalazzo1996@gmail.com + * Copyright (c) 2019-2022 Vincenzo Palazzo vincenzopalazzo1996@gmail.com * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -23,7 +23,6 @@ */ package mdlaf.components.button; -import java.awt.*; import javax.swing.*; /** @@ -45,11 +44,4 @@ public void installUI(JComponent c) { borderEnabled = false; buttonBorderToAll = false; } - - @Override - protected void paintFocus( - Graphics g, AbstractButton b, Rectangle viewRect, Rectangle textRect, Rectangle iconRect) {} - - @Override - protected void paintBorderButton(Graphics graphics, JComponent b) {} } diff --git a/src/main/java/mdlaf/components/titlepane/MaterialTitlePane.java b/src/main/java/mdlaf/components/titlepane/MaterialTitlePane.java index 5035c80..d68a6b8 100644 --- a/src/main/java/mdlaf/components/titlepane/MaterialTitlePane.java +++ b/src/main/java/mdlaf/components/titlepane/MaterialTitlePane.java @@ -23,7 +23,7 @@ import javax.accessibility.AccessibleContext; import javax.swing.*; import javax.swing.plaf.UIResource; -import mdlaf.components.button.MaterialButtonUI; +import mdlaf.components.button.MaterialButtonsComponentsUI; import mdlaf.utils.MaterialDrawingUtils; import mdlaf.utils.MaterialManagerListener; import mdlaf.utils.WrapperSwingUtilities; @@ -172,53 +172,9 @@ protected void initMaterialButtonClose() { } protected void determineColors() { - switch (getWindowDecorationStyle()) { - case JRootPane.FRAME: - myActiveBackground = UIManager.getColor("Material.activeCaption"); - myActiveForeground = UIManager.getColor("Material.activeCaptionText"); - myActiveShadow = UIManager.getColor("Material.activeCaptionBorder"); - break; - case JRootPane.ERROR_DIALOG: - myActiveBackground = UIManager.getColor("OptionPane.errorDialog.titlePane.background"); - myActiveForeground = UIManager.getColor("OptionPane.errorDialog.titlePane.foreground"); - myActiveShadow = UIManager.getColor("OptionPane.errorDialog.titlePane.shadow"); - break; - case JRootPane.QUESTION_DIALOG: - myActiveBackground = UIManager.getColor("OptionPane.questionDialog.titlePane.background"); - myActiveForeground = UIManager.getColor("OptionPane.questionDialog.titlePane.foreground"); - myActiveShadow = UIManager.getColor("OptionPane.questionDialog.titlePane.shadow"); - break; - case JRootPane.COLOR_CHOOSER_DIALOG: - myActiveBackground = UIManager.getColor("OptionPane.questionDialog.titlePane.background"); - myActiveForeground = UIManager.getColor("OptionPane.questionDialog.titlePane.foreground"); - myActiveShadow = UIManager.getColor("OptionPane.questionDialog.titlePane.shadow"); - break; - case JRootPane.FILE_CHOOSER_DIALOG: - myActiveBackground = UIManager.getColor("OptionPane.questionDialog.titlePane.background"); - myActiveForeground = UIManager.getColor("OptionPane.questionDialog.titlePane.foreground"); - myActiveShadow = myActiveBackground; - break; - case JRootPane.WARNING_DIALOG: - myActiveBackground = UIManager.getColor("OptionPane.warningDialog.titlePane.background"); - myActiveForeground = UIManager.getColor("OptionPane.warningDialog.titlePane.foreground"); - myActiveShadow = UIManager.getColor("OptionPane.warningDialog.titlePane.shadow"); - break; - case JRootPane.PLAIN_DIALOG: - myActiveBackground = UIManager.getColor("OptionPane.questionDialog.titlePane.background"); - myActiveForeground = UIManager.getColor("OptionPane.questionDialog.titlePane.foreground"); - myActiveShadow = UIManager.getColor("OptionPane.questionDialog.titlePane.shadow"); - break; - case JRootPane.INFORMATION_DIALOG: - myActiveBackground = UIManager.getColor("OptionPane.errorDialog.titlePane.background"); - myActiveForeground = UIManager.getColor("OptionPane.errorDialog.titlePane.foreground"); - myActiveShadow = UIManager.getColor("OptionPane.errorDialog.titlePane.shadow"); - break; - default: - myActiveBackground = UIManager.getColor("Material.activeCaption"); - myActiveForeground = UIManager.getColor("Material.activeCaptionText"); - myActiveShadow = UIManager.getColor("Material.activeCaptionBorder"); - break; - } + myActiveBackground = UIManager.getColor("Material.activeCaption"); + myActiveForeground = UIManager.getColor("Material.activeCaptionText"); + myActiveShadow = UIManager.getColor("Material.activeCaptionBorder"); } protected void installDefaults() { @@ -285,12 +241,13 @@ protected void addMenuItems(JMenu menu) { menu.add(myCloseAction); } - protected static JButton createButton(String accessibleName, Icon icon, Action action) { - JButton button = new TitlePaneButton(Color.BLACK, true); + protected JButton createButton(String accessibleName, Icon icon, Action action) { + JButton button = new TitlePaneButton(); button.putClientProperty("paintActive", Boolean.TRUE); button.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, accessibleName); button.setAction(action); button.setIcon(icon); + button.setBackground(myActiveBackground); return button; } @@ -319,10 +276,6 @@ protected void createButtons() { myIconifyButton = createButton("Iconify", UIManager.getIcon("InternalFrame.iconifyIcon"), myIconifyAction); myToggleButton = createButton("Maximize", myMaximizeIcon, myRestoreAction); - - myCloseButton.setBackground(myActiveBackground); - myIconifyButton.setBackground(myActiveBackground); - myToggleButton.setBackground(myActiveBackground); } } @@ -555,30 +508,6 @@ public void actionPerformed(ActionEvent e) { } } - protected void activeChanged(boolean active) { - boolean hasEmbeddedMenuBar = - myRootPane.getJMenuBar() != null && myRootPane.getJMenuBar().isVisible(); - Color background = active ? myActiveBackground : myInactiveBackground; - Color foreground = active ? myActiveForeground : myInactiveForeground; - Color titleForeground = foreground; - - setBackground(background); - myWindow.setForeground(titleForeground); - // myIconifyButton.setForeground(foreground); - // maximizeButton.setForeground(foreground); - myIconifyButton.setForeground(foreground); - myCloseButton.setForeground(foreground); - - // titleLabel.setHorizontalAlignment(hasEmbeddedMenuBar ? SwingConstants.CENTER : - // SwingConstants.LEADING); - - // this is necessary because hover/pressed colors are derived from background color - myIconifyButton.setBackground(background); - // maximizeButton.setBackground(background); - myToggleButton.setBackground(background); - myCloseButton.setBackground(background); - } - protected class TitlePaneLayout implements LayoutManager { public void addLayoutComponent(String name, Component c) {} @@ -843,13 +772,7 @@ public void componentHidden(ComponentEvent e) {} protected static class TitlePaneButton extends JButton { - protected Color background; - protected Boolean state; - - public TitlePaneButton(Color background, Boolean state) { - this.background = background; - this.state = state; - } + public TitlePaneButton() {} @Override protected void init(String text, Icon icon) { @@ -857,21 +780,34 @@ protected void init(String text, Icon icon) { setUI(new TitlePaneButtonUI()); } - private static class TitlePaneButtonUI extends MaterialButtonUI { + @Override + public void updateUI() { + super.updateUI(); + setUI(new TitlePaneButtonUI()); + } + private static class TitlePaneButtonUI extends MaterialButtonsComponentsUI { @Override public void installUI(JComponent c) { - mouseHoverEnabled = false; super.installUI(c); - c.setFocusable(false); - c.setOpaque(true); - c.setBackground(background); - c.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); + super.background = UIManager.getColor("Material.activeCaption"); + super.defaultBackground = UIManager.getColor("Material.activeCaption"); c.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } @Override protected void paintButtonPressed(Graphics g, AbstractButton b) {} + + @Override + protected void paintBorderButton(Graphics graphics, JComponent b) {} + + @Override + protected void paintFocus( + Graphics g, + AbstractButton b, + Rectangle viewRect, + Rectangle textRect, + Rectangle iconRect) {} } } } diff --git a/src/main/java/mdlaf/components/titlepane/MaterialTitlePaneUI.java b/src/main/java/mdlaf/components/titlepane/MaterialTitlePaneUI.java index 0e0799d..be8d35e 100644 --- a/src/main/java/mdlaf/components/titlepane/MaterialTitlePaneUI.java +++ b/src/main/java/mdlaf/components/titlepane/MaterialTitlePaneUI.java @@ -25,7 +25,6 @@ import java.util.List; import javax.accessibility.AccessibleContext; import javax.swing.*; -import javax.swing.border.EmptyBorder; import javax.swing.plaf.UIResource; import mdlaf.components.button.MaterialButtonsComponentsUI; import mdlaf.utils.MaterialDrawingUtils; @@ -35,6 +34,7 @@ /** * @author Konstantin Bulenkov this code is copyed by OpenJDK * @author https://github.com/users/vincenzopalazzo + * @deprecated Use MaterialTitlePane */ public class MaterialTitlePaneUI extends JComponent { @@ -245,15 +245,11 @@ protected void addMenuItems(JMenu menu) { menu.add(myCloseAction); } - protected static JButton createButton(String accessibleName, Icon icon, Action action) { + protected JButton createButton(String accessibleName, Icon icon, Action action) { JButton button = new JButtonNoMouseHoverNative(); - button.setFocusPainted(false); - button.setFocusable(false); - button.setOpaque(true); + button.setUI(new JButtonNoMouseHoverNative.JButtonNoMouseHoverUI()); button.putClientProperty("paintActive", Boolean.TRUE); button.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, accessibleName); - button.setBorder(new EmptyBorder(0, 0, 0, 0)); - button.setText(null); button.setAction(action); button.setIcon(icon); return button; @@ -666,7 +662,9 @@ public void windowDeactivated(WindowEvent ev) { protected static class JButtonNoMouseHoverNative extends JButton { - public JButtonNoMouseHoverNative() {} + public JButtonNoMouseHoverNative() { + super(); + } public JButtonNoMouseHoverNative(Icon icon) { super(icon); @@ -684,12 +682,6 @@ public JButtonNoMouseHoverNative(String text, Icon icon) { super(text, icon); } - @Override - protected void init(String text, Icon icon) { - super.init(text, icon); - setUI(new JButtonNoMouseHoverUI()); - } - @Override public void updateUI() { setUI(new JButtonNoMouseHoverUI()); @@ -700,13 +692,13 @@ private static class JButtonNoMouseHoverUI extends MaterialButtonsComponentsUI { @Override public void installUI(JComponent c) { super.installUI(c); + super.background = UIManager.getColor("TitlePane.background"); + super.defaultBackground = UIManager.getColor("TitlePane.background"); c.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } @Override - protected void paintButtonPressed(Graphics g, AbstractButton b) { - // doNothing - } + protected void paintButtonPressed(Graphics g, AbstractButton b) {} @Override protected void paintBorderButton(Graphics graphics, JComponent b) {} @@ -717,9 +709,7 @@ protected void paintFocus( AbstractButton b, Rectangle viewRect, Rectangle textRect, - Rectangle iconRect) { - // do nothing - } + Rectangle iconRect) {} } } } diff --git a/src/test/java/integration/gui/mock/DemoGUITest.java b/src/test/java/integration/gui/mock/DemoGUITest.java index 26a30c1..306b596 100644 --- a/src/test/java/integration/gui/mock/DemoGUITest.java +++ b/src/test/java/integration/gui/mock/DemoGUITest.java @@ -54,8 +54,8 @@ public class DemoGUITest extends JFrame { JDialog.setDefaultLookAndFeelDecorated(true); // FIXME: finish support for the JFrame.setDefaultLookAndFeelDecorated JFrame.setDefaultLookAndFeelDecorated(true); - UIManager.setLookAndFeel(new MaterialLookAndFeel(new MaterialLiteTheme())); - // UIManager.setLookAndFeel(new MaterialLookAndFeel(new DarkStackOverflowTheme())); + // UIManager.setLookAndFeel(new MaterialLookAndFeel(new MaterialLiteTheme())); + UIManager.setLookAndFeel(new MaterialLookAndFeel(new DarkStackOverflowTheme())); UIManager.put( "Button.mouseHoverEnable", true); // Because the test are more difficult with effect mouse hover