diff --git a/demo/Demo-Swing-set3.tar b/demo/Demo-Swing-set3.tar new file mode 100644 index 0000000..988242f Binary files /dev/null and b/demo/Demo-Swing-set3.tar differ diff --git a/src/main/java/mdlaf/MaterialLookAndFeel.java b/src/main/java/mdlaf/MaterialLookAndFeel.java index 500e4d6..9102fd7 100644 --- a/src/main/java/mdlaf/MaterialLookAndFeel.java +++ b/src/main/java/mdlaf/MaterialLookAndFeel.java @@ -1,3 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2018-2019 atharva washimkar, + * Copyright (c) 2019 Vincent Palazzo vincenzopalazzodev@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 + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package mdlaf; import mdlaf.components.button.MaterialButtonUI; @@ -7,6 +31,7 @@ import mdlaf.components.filechooser.MaterialFileChooserUI; import mdlaf.components.formattertextfield.MaterialFormattedTextFieldUI; import mdlaf.components.label.MaterialLabelUI; +import mdlaf.components.list.MaterialListUI; import mdlaf.components.menu.MaterialMenuUI; import mdlaf.components.menubar.MaterialMenuBarUI; import mdlaf.components.menuitem.MaterialMenuItemUI; @@ -36,12 +61,13 @@ import mdlaf.utils.MaterialFonts; import mdlaf.utils.MaterialImages; -import javax.swing.BorderFactory; -import javax.swing.ImageIcon; -import javax.swing.UIDefaults; -import javax.swing.UIManager; +import javax.swing.*; +import javax.swing.plaf.basic.BasicLookAndFeel; +import javax.swing.plaf.metal.DefaultMetalTheme; import javax.swing.plaf.metal.MetalLookAndFeel; +import javax.swing.text.DefaultEditorKit; import java.awt.Color; +import java.lang.reflect.Method; public class MaterialLookAndFeel extends MetalLookAndFeel { @@ -77,6 +103,18 @@ public class MaterialLookAndFeel extends MetalLookAndFeel { private static final String taskPaneUI = MaterialTaskPaneUI.class.getCanonicalName (); private static final String optionPaneUI = MaterialOptionPaneUI.class.getCanonicalName(); private static final String formattedTextFieldUI = MaterialFormattedTextFieldUI.class.getCanonicalName(); + private static final String listUI = MaterialListUI.class.getCanonicalName(); + + private BasicLookAndFeel basicLookAndFeel; + + public MaterialLookAndFeel() { + try { + basicLookAndFeel = new MetalLookAndFeel(); + MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme()); + } catch (Exception ignore) { + //do nothing + } + } @Override public String getName () { @@ -135,191 +173,208 @@ protected void initClassDefaults (UIDefaults table) { table.put ("SeparatorUI", separatorUI); table.put ("FileChooserUI", fileChooserUI); table.put ("ToolTipUI", toolTipUI); - table.put ("swingx/TaskPaneUI", taskPaneUI); table.put("OptionPaneUI", optionPaneUI); table.put("FormattedTextFieldUI", formattedTextFieldUI); + table.put("ListUI", listUI); + + table.put ("swingx/TaskPaneUI", taskPaneUI); } @Override protected void initComponentDefaults (UIDefaults table) { super.initComponentDefaults (table); - table.put ("Button.highlight", MaterialColors.GRAY_200); - table.put ("Button.opaque", true); - table.put ("Button.border", BorderFactory.createEmptyBorder (7, 17, 7, 17)); - table.put ("Button.background", MaterialColors.WHITE); - table.put ("Button.foreground", Color.BLACK); - table.put ("Button.font", MaterialFonts.MEDIUM); + table.put("Button.highlight", MaterialColors.GRAY_200); + table.put("Button.opaque", true); + table.put("Button.border", BorderFactory.createEmptyBorder (7, 17, 7, 17)); + table.put("Button.background", MaterialColors.GRAY_200); + table.put("Button.foreground", Color.BLACK); + table.put("Button.font", MaterialFonts.MEDIUM); table.put("Button.mouseHoverColor", MaterialColors.GRAY_400); table.put("Button.mouseHoverEnable", true); - - table.put ("CheckBox.font", MaterialFonts.REGULAR); - table.put ("CheckBox.background", Color.WHITE); - table.put ("CheckBox.foreground", Color.BLACK); - table.put ("CheckBox.icon", new ImageIcon (MaterialImages.UNCHECKED_BOX)); - table.put ("CheckBox.selectedIcon", new ImageIcon (MaterialImages.PAINTED_CHECKED_BOX)); - table.put ("ComboBox.font", MaterialFonts.REGULAR); - table.put ("ComboBox.background", Color.WHITE); - table.put ("ComboBox.foreground", Color.BLACK); - table.put ("ComboBox.border", BorderFactory.createCompoundBorder (MaterialBorders.LIGHT_LINE_BORDER, BorderFactory.createEmptyBorder (0, 5, 0, 0))); - table.put ("ComboBox.buttonBackground", MaterialColors.GRAY_300); - table.put ("ComboBox.selectionBackground", MaterialColors.GRAY_300); - table.put ("ComboBox.selectionForeground", MaterialColors.BLACK); - table.put ("ComboBox.selectedInDropDownBackground", MaterialColors.GRAY_200); + table.put("Button.focusable", false); + table.put("Button[focus].color", MaterialColors.GRAY_900); + table.put("Button.disabledText", MaterialColors.GRAY_700); + + table.put("CheckBox.font", MaterialFonts.REGULAR); + table.put("CheckBox.background", Color.WHITE); + table.put("CheckBox.foreground", Color.BLACK); + table.put("CheckBox.icon", new ImageIcon (MaterialImages.UNCHECKED_BOX)); + table.put("CheckBox.selectedIcon", new ImageIcon (MaterialImages.PAINTED_CHECKED_BOX)); + + table.put("ComboBox.font", MaterialFonts.REGULAR); + table.put("ComboBox.background", Color.WHITE); + table.put("ComboBox.foreground", Color.BLACK); + table.put("ComboBox.border", BorderFactory.createCompoundBorder (MaterialBorders.LIGHT_LINE_BORDER, BorderFactory.createEmptyBorder (0, 5, 0, 0))); + table.put("ComboBox.buttonBackground", MaterialColors.GRAY_300); + table.put("ComboBox.selectionBackground", MaterialColors.GRAY_300); + table.put("ComboBox.disabledBackground", MaterialColors.GRAY_500); + table.put("ComboBox.disabledForeground", MaterialColors.GRAY_900); + table.put("ComboBox.selectionForeground", MaterialColors.BLACK); + table.put("ComboBox.selectedInDropDownBackground", MaterialColors.GRAY_200); table.put("ComboBox.mouseHoverColor", MaterialColors.GRAY_400); table.put("ComboBox.mouseHoverEnabled", true); - table.put ("Label.font", MaterialFonts.REGULAR); - table.put ("Label.background", Color.WHITE); - table.put ("Label.foreground", Color.BLACK); - table.put ("Label.border", BorderFactory.createEmptyBorder ()); - - table.put ("Menu.font", MaterialFonts.BOLD); - table.put ("Menu.border", BorderFactory.createEmptyBorder (5, 5, 5, 5)); - table.put ("Menu.background", Color.WHITE); - table.put ("Menu.foreground", Color.BLACK); - table.put ("Menu.opaque", true); - table.put ("Menu.selectionBackground", MaterialColors.GRAY_200); - table.put ("Menu.selectionForeground", Color.BLACK); - table.put ("Menu.disabledForeground", new Color (0, 0, 0, 100)); - table.put ("Menu.menuPopupOffsetY", 3); + table.put("Label.font", MaterialFonts.REGULAR); + table.put("Label.background", Color.WHITE); + table.put("Label.foreground", Color.BLACK); + table.put("Label.border", BorderFactory.createEmptyBorder ()); + + table.put("Menu.font", MaterialFonts.BOLD); + table.put("Menu.border", BorderFactory.createEmptyBorder (5, 5, 5, 5)); + table.put("Menu.background", Color.WHITE); + table.put("Menu.foreground", Color.BLACK); + table.put("Menu.opaque", true); + table.put("Menu.selectionBackground", MaterialColors.GRAY_200); + table.put("Menu.selectionForeground", Color.BLACK); + table.put("Menu.disabledForeground", new Color (0, 0, 0, 100)); + table.put("Menu.menuPopupOffsetY", 3); table.put("Menu[MouseOver].enable", true); //TODO testing //TODO refactoinh and using the convensioni Component[Action].ohYeah - table.put ("MenuBar.font", MaterialFonts.BOLD); - table.put ("MenuBar.background", Color.WHITE); - table.put ("MenuBar.border", MaterialBorders.LIGHT_SHADOW_BORDER); - table.put ("MenuBar.foreground", Color.BLACK); - - table.put ("MenuItem.disabledForeground", new Color (0, 0, 0, 100)); - table.put ("MenuItem.selectionBackground", MaterialColors.GRAY_200); - table.put ("MenuItem.selectionForeground", Color.BLACK); - table.put ("MenuItem.font", MaterialFonts.MEDIUM); - table.put ("MenuItem.background", Color.WHITE); - table.put ("MenuItem.foreground", Color.BLACK); - table.put ("MenuItem.border", BorderFactory.createEmptyBorder (5, 0, 5, 0)); - - table.put ("OptionPane.background", Color.WHITE); - table.put ("OptionPane.border", MaterialBorders.DEFAULT_SHADOW_BORDER); - table.put ("OptionPane.font", MaterialFonts.REGULAR); - - table.put ("Panel.font", MaterialFonts.REGULAR); - table.put ("Panel.background", Color.WHITE); - table.put ("Panel.border", BorderFactory.createEmptyBorder ()); - - table.put ("PopupMenu.border", MaterialBorders.LIGHT_LINE_BORDER); - table.put ("PopupMenu.background", Color.WHITE); - table.put ("PopupMenu.foreground", Color.BLACK); - - table.put ("RadioButton.font", MaterialFonts.REGULAR); - table.put ("RadioButton.background", Color.WHITE); - table.put ("RadioButton.foreground", Color.BLACK); - table.put ("RadioButton.icon", new ImageIcon (MaterialImages.RADIO_BUTTON_OFF)); - table.put ("RadioButton.selectedIcon", new ImageIcon (MaterialImages.RADIO_BUTTON_ON)); - - table.put ("Spinner.font", MaterialFonts.REGULAR); - table.put ("Spinner.background", Color.WHITE); - table.put ("Spinner.foreground", Color.BLACK); - table.put ("Spinner.border", MaterialBorders.LIGHT_LINE_BORDER); - table.put ("Spinner.arrowButtonBackground", MaterialColors.GRAY_200); - table.put ("Spinner.arrowButtonBorder", BorderFactory.createEmptyBorder ()); + table.put("MenuBar.font", MaterialFonts.BOLD); + table.put("MenuBar.background", Color.WHITE); + table.put("MenuBar.border", MaterialBorders.LIGHT_SHADOW_BORDER); + table.put("MenuBar.foreground", Color.BLACK); + + table.put("MenuItem.disabledForeground", new Color (0, 0, 0, 100)); + table.put("MenuItem.selectionBackground", MaterialColors.GRAY_200); + table.put("MenuItem.selectionForeground", Color.BLACK); + table.put("MenuItem.font", MaterialFonts.MEDIUM); + table.put("MenuItem.background", Color.WHITE); + table.put("MenuItem.foreground", Color.BLACK); + table.put("MenuItem.border", BorderFactory.createEmptyBorder (5, 0, 5, 0)); + + table.put("OptionPane.background", Color.WHITE); + table.put("OptionPane.border", MaterialBorders.DEFAULT_SHADOW_BORDER); + table.put("OptionPane.font", MaterialFonts.REGULAR); + + table.put("Panel.font", MaterialFonts.REGULAR); + table.put("Panel.background", Color.WHITE); + table.put("Panel.border", BorderFactory.createEmptyBorder ()); + + table.put("PopupMenu.border", MaterialBorders.LIGHT_LINE_BORDER); + table.put("PopupMenu.background", Color.WHITE); + table.put("PopupMenu.foreground", Color.BLACK); + + table.put("RadioButton.font", MaterialFonts.REGULAR); + table.put("RadioButton.background", Color.WHITE); + table.put("RadioButton.foreground", Color.BLACK); + table.put("RadioButton.icon", new ImageIcon (MaterialImages.RADIO_BUTTON_OFF)); + table.put("RadioButton.selectedIcon", new ImageIcon (MaterialImages.RADIO_BUTTON_ON)); + + table.put("Spinner.font", MaterialFonts.REGULAR); + table.put("Spinner.background", Color.WHITE); + table.put("Spinner.foreground", Color.BLACK); + table.put("Spinner.border", MaterialBorders.LIGHT_LINE_BORDER); + table.put("Spinner.arrowButtonBackground", MaterialColors.GRAY_200); + table.put("Spinner.arrowButtonBorder", BorderFactory.createEmptyBorder ()); table.put("Spinner.mouseHoverEnabled", true); table.put("Spinner.mouseHoverColor", MaterialColors.GRAY_400); - table.put ("ScrollBar.font", MaterialFonts.REGULAR); - table.put ("ScrollBar.track", MaterialColors.GRAY_200); - table.put ("ScrollBar.thumb", MaterialColors.GRAY_300); - table.put ("ScrollBar.thumbDarkShadow", MaterialColors.GRAY_300); - table.put ("ScrollBar.thumbHighlight", MaterialColors.GRAY_300); - table.put ("ScrollBar.thumbShadow", MaterialColors.GRAY_300); - table.put ("ScrollBar.arrowButtonBackground", MaterialColors.GRAY_300); - table.put("ScrollBar.arrowButtonBorder", MaterialBorders.LIGHT_LINE_BORDER); + table.put("ScrollBar.font", MaterialFonts.REGULAR); + table.put("ScrollBar.track", MaterialColors.GRAY_200); + table.put("ScrollBar.thumb", MaterialColors.GRAY_500); + table.put("ScrollBar.thumbDarkShadow", MaterialColors.GRAY_500); + table.put("ScrollBar.thumbHighlight", MaterialColors.GRAY_500); + table.put("ScrollBar.thumbShadow", MaterialColors.GRAY_500); + table.put("ScrollBar.arrowButtonBackground", MaterialColors.GRAY_200); + table.put("ScrollBar.enableArrow", true); + table.put("ScrollBar.arrowButtonBorder", BorderFactory.createEmptyBorder()); table.put("ScrollBar[MouseHover].enable", true); table.put("ScrollBar[MouseHover].color", MaterialColors.GRAY_400); table.put("ScrollBar[OnClick].color", MaterialColors.GRAY_500); - table.put ("ScrollPane.background", Color.WHITE); - table.put ("ScrollPane.border", BorderFactory.createEmptyBorder ()); - table.put ("ScrollPane.font", MaterialFonts.REGULAR); - - table.put ("Slider.font", MaterialFonts.REGULAR); - table.put ("Slider.background", Color.WHITE); - table.put ("Slider.foreground", MaterialColors.LIGHT_BLUE_400); - table.put ("Slider.trackColor", Color.BLACK); - table.put ("Slider.border", BorderFactory.createCompoundBorder (MaterialBorders.LIGHT_LINE_BORDER, BorderFactory.createEmptyBorder (20, 20, 20, 20))); - - table.put ("SplitPane.border", BorderFactory.createEmptyBorder ()); - table.put ("SplitPane.background", Color.WHITE); - table.put ("SplitPane.dividerSize", 5); - table.put ("SplitPaneDivider.border", BorderFactory.createEmptyBorder ()); - - table.put ("TabbedPane.font", MaterialFonts.REGULAR); - table.put ("TabbedPane.background", Color.WHITE); - table.put ("TabbedPane.foreground", Color.BLACK); - table.put ("TabbedPane.border", BorderFactory.createEmptyBorder ()); - table.put ("TabbedPane.shadow", null); - table.put ("TabbedPane.darkShadow", null); - table.put ("TabbedPane.highlight", MaterialColors.GRAY_200); - table.put ("TabbedPane.borderHighlightColor", MaterialColors.GRAY_300); - - table.put ("Table.selectionBackground", MaterialColors.GRAY_100); - table.put ("Table.selectionForeground", Color.BLACK); - table.put ("Table.background", Color.WHITE); - table.put ("Table.font", MaterialFonts.REGULAR); - table.put ("Table.border", MaterialBorders.LIGHT_LINE_BORDER); - table.put ("Table.gridColor", MaterialColors.GRAY_200); - table.put ("TableHeader.background", MaterialColors.GRAY_200); - table.put ("TableHeader.font", MaterialFonts.BOLD); - table.put ("TableHeader.cellBorder", BorderFactory.createCompoundBorder (MaterialBorders.LIGHT_LINE_BORDER, BorderFactory.createEmptyBorder (5, 5, 5, 5))); - - table.put ("TextArea.background", MaterialColors.GRAY_200); - table.put ("TextArea.border", BorderFactory.createEmptyBorder ()); - table.put ("TextArea.foreground", Color.BLACK); - - table.put ("TextField.inactiveForeground", MaterialColors.GRAY_800); - table.put ("TextField.inactiveBackground", MaterialColors.GRAY_200); - table.put ("TextField.selectionBackground", MaterialColors.LIGHT_BLUE_400); - table.put ("TextField.selectionForeground", Color.BLACK); - table.put ("TextField.border", BorderFactory.createEmptyBorder(3, 5, 2, 5)); - - table.put ("ToggleButton.border", BorderFactory.createEmptyBorder ()); - table.put ("ToggleButton.font", MaterialFonts.REGULAR); - table.put ("ToggleButton.background", Color.WHITE); - table.put ("ToggleButton.foreground", Color.BLACK); - table.put ("ToggleButton.icon", new ImageIcon (MaterialImages.TOGGLE_BUTTON_OFF)); - table.put ("ToggleButton.selectedIcon", new ImageIcon (MaterialImages.TOGGLE_BUTTON_ON)); - - table.put ("ToolBar.font", MaterialFonts.REGULAR); - table.put ("ToolBar.background", Color.WHITE); - table.put ("ToolBar.foreground", Color.BLACK); - table.put ("ToolBar.border", MaterialBorders.LIGHT_SHADOW_BORDER); - table.put ("ToolBar.dockingBackground", MaterialColors.LIGHT_GREEN_A100); - table.put ("ToolBar.floatingBackground", MaterialColors.GRAY_200); - - table.put ("Tree.font", MaterialFonts.REGULAR); - table.put ("Tree.selectionForeground", Color.BLACK); - table.put ("Tree.foreground", Color.BLACK); - table.put ("Tree.selectionBackground", MaterialColors.GRAY_200); - table.put ("Tree.background", Color.WHITE); - table.put ("Tree.closedIcon", new ImageIcon (MaterialImages.RIGHT_ARROW)); - table.put ("Tree.openIcon", new ImageIcon (MaterialImages.DOWN_ARROW)); - table.put ("Tree.selectionBorderColor", null); - - table.put ("RadioButtonMenuItem.foreground", Color.BLACK); - table.put ("RadioButtonMenuItem.selectionForeground", Color.BLACK); + table.put("ScrollPane.background", Color.WHITE); + table.put("ScrollPane.border", BorderFactory.createEmptyBorder ()); + table.put("ScrollPane.font", MaterialFonts.REGULAR); + + table.put("Slider.font", MaterialFonts.REGULAR); + table.put("Slider.background", Color.WHITE); + table.put("Slider.foreground", MaterialColors.LIGHT_BLUE_400); + table.put("Slider.trackColor", Color.BLACK); + table.put("Slider.border", BorderFactory.createCompoundBorder (MaterialBorders.LIGHT_LINE_BORDER, BorderFactory.createEmptyBorder (20, 20, 20, 20))); + + table.put("SplitPane.border", BorderFactory.createEmptyBorder ()); + table.put("SplitPane.background", Color.WHITE); + table.put("SplitPane.dividerSize", 5); + table.put("SplitPaneDivider.border", BorderFactory.createEmptyBorder ()); + + table.put("TabbedPane.font", MaterialFonts.REGULAR); + table.put("TabbedPane.background", Color.WHITE); + table.put("TabbedPane.foreground", Color.BLACK); + table.put("TabbedPane.border", BorderFactory.createEmptyBorder ()); + table.put("TabbedPane.shadow", null); + table.put("TabbedPane.darkShadow", null); + table.put("TabbedPane.highlight", MaterialColors.GRAY_200); + table.put("TabbedPane.borderHighlightColor", MaterialColors.GRAY_300); + + table.put("Table.selectionBackground", MaterialColors.GRAY_100); + table.put("Table.selectionForeground", Color.BLACK); + table.put("Table.background", Color.WHITE); + table.put("Table.font", MaterialFonts.REGULAR); + table.put("Table.border", MaterialBorders.LIGHT_LINE_BORDER); + table.put("Table.gridColor", MaterialColors.GRAY_200); + table.put("TableHeader.background", MaterialColors.GRAY_200); + table.put("TableHeader.font", MaterialFonts.BOLD); + table.put("TableHeader.cellBorder", BorderFactory.createCompoundBorder (MaterialBorders.LIGHT_LINE_BORDER, BorderFactory.createEmptyBorder (5, 5, 5, 5))); + + table.put("TextArea.background", MaterialColors.GRAY_200); + table.put("TextArea.border", BorderFactory.createEmptyBorder ()); + table.put("TextArea.foreground", Color.BLACK); + + table.put("TextField.inactiveForeground", MaterialColors.GRAY_800); + table.put("TextField.inactiveBackground", MaterialColors.GRAY_200); + table.put("TextField.selectionBackground", MaterialColors.LIGHT_BLUE_400); + table.put("TextField.selectionForeground", MaterialColors.BLACK); + table.put("TextField.border", BorderFactory.createEmptyBorder(3, 5, 2, 5)); + table.put("TextField.focusInputMap", fieldInputMap); //install shortcut + + table.put("PasswordField.inactiveForeground", MaterialColors.GRAY_800); + table.put("PasswordField.inactiveBackground", MaterialColors.GRAY_200); + table.put("PasswordField.selectionBackground", MaterialColors.LIGHT_BLUE_400); + table.put("PasswordField.selectionForeground", MaterialColors.BLACK); + table.put("PasswordField.border", BorderFactory.createEmptyBorder(3, 5, 2, 5)); + table.put("PasswordField.focusInputMap", fieldInputMap); //install shortcut + + table.put("ToggleButton.border", BorderFactory.createEmptyBorder ()); + table.put("ToggleButton.font", MaterialFonts.REGULAR); + table.put("ToggleButton.background", Color.WHITE); + table.put("ToggleButton.foreground", Color.BLACK); + table.put("ToggleButton.icon", new ImageIcon (MaterialImages.TOGGLE_BUTTON_OFF)); + table.put("ToggleButton.selectedIcon", new ImageIcon (MaterialImages.TOGGLE_BUTTON_ON)); + + table.put("ToolBar.font", MaterialFonts.REGULAR); + table.put("ToolBar.background", Color.WHITE); + table.put("ToolBar.foreground", Color.BLACK); + table.put("ToolBar.border", MaterialBorders.LIGHT_SHADOW_BORDER); + table.put("ToolBar.dockingBackground", MaterialColors.LIGHT_GREEN_A100); + table.put("ToolBar.floatingBackground", MaterialColors.GRAY_200); + + table.put("Tree.font", MaterialFonts.REGULAR); + table.put("Tree.selectionForeground", Color.BLACK); + table.put("Tree.foreground", Color.BLACK); + table.put("Tree.selectionBackground", MaterialColors.GRAY_200); + table.put("Tree.background", Color.WHITE); + table.put("Tree.closedIcon", new ImageIcon (MaterialImages.RIGHT_ARROW)); + table.put("Tree.openIcon", new ImageIcon (MaterialImages.DOWN_ARROW)); + table.put("Tree.selectionBorderColor", null); + + table.put("RadioButtonMenuItem.foreground", Color.BLACK); + table.put("RadioButtonMenuItem.selectionForeground", Color.BLACK); //If it changes the background of the menuitem it must change this too, irrespective of its setting - table.put ("RadioButtonMenuItem.background", UIManager.getColor ("MenuItem.background")); - table.put ("RadioButtonMenuItem.selectionBackground", MaterialColors.GRAY_200); - table.put ("RadioButtonMenuItem.border", BorderFactory.createEmptyBorder (5, 5, 5, 5)); - table.put ("RadioButtonMenuItem.checkIcon", new ImageIcon (MaterialImages.RADIO_BUTTON_OFF)); - table.put ("RadioButtonMenuItem.selectedCheckIcon", new ImageIcon (MaterialImages.RADIO_BUTTON_ON)); + table.put("RadioButtonMenuItem.background", UIManager.getColor ("MenuItem.background")); + table.put("RadioButtonMenuItem.selectionBackground", MaterialColors.GRAY_200); + table.put("RadioButtonMenuItem.border", BorderFactory.createEmptyBorder (5, 0, 5, 0)); + table.put("RadioButtonMenuItem.checkIcon", new ImageIcon (MaterialImages.RADIO_BUTTON_OFF)); + table.put("RadioButtonMenuItem.selectedCheckIcon", new ImageIcon (MaterialImages.RADIO_BUTTON_ON)); //If it changes the background of the menuitem it must change this too, irrespective of its setting table.put ("CheckBoxMenuItem.background", UIManager.getColor ("MenuItem.background")); table.put ("CheckBoxMenuItem.selectionBackground", MaterialColors.GRAY_200); table.put ("CheckBoxMenuItem.foreground", Color.BLACK); table.put ("CheckBoxMenuItem.selectionForeground", Color.BLACK); - table.put ("CheckBoxMenuItem.border", BorderFactory.createEmptyBorder (5, 5, 5, 5)); + table.put ("CheckBoxMenuItem.border", BorderFactory.createEmptyBorder(5, 0, 5, 0)); table.put ("CheckBoxMenuItem.checkIcon", new ImageIcon (MaterialImages.UNCHECKED_BOX)); table.put ("CheckBoxMenuItem.selectedCheckIcon", new ImageIcon (MaterialImages.PAINTED_CHECKED_BOX)); @@ -370,5 +425,142 @@ protected void initComponentDefaults (UIDefaults table) { table.put ("FormattedTextField.selectionBackground", MaterialColors.LIGHT_BLUE_400); table.put ("FormattedTextField.selectionForeground", Color.BLACK); table.put("FormattedTextField.border", BorderFactory.createEmptyBorder(3, 5, 2, 5)); + + table.put("List.background", MaterialColors.WHITE); + table.put("List.foreground", MaterialColors.BLACK); + table.put("List.border", MaterialBorders.LIGHT_SHADOW_BORDER); + table.put("List.font", MaterialFonts.MEDIUM); + table.put("List.selectionBackground", MaterialColors.GRAY_400); + table.put("List.selectionForeground", MaterialColors.BLACK); + table.put("List.focusable", true); + } + + @Override + public UIDefaults getDefaults() { + try { + final Method superMethod = BasicLookAndFeel.class.getDeclaredMethod("getDefaults"); + superMethod.setAccessible(true); + final UIDefaults defaults = (UIDefaults)superMethod.invoke(basicLookAndFeel); + initClassDefaults(defaults); + initComponentDefaults(defaults); + defaults.put("OptionPane.warningIcon", new ImageIcon(MaterialImages.WARNING)); + defaults.put("OptionPane.errorIcon", new ImageIcon(MaterialImages.ERROR)); + defaults.put("OptionPane.questionIcon", new ImageIcon(MaterialImages.QUESTION)); + defaults.put("OptionPane.informationIcon", new ImageIcon(MaterialImages.INFORMATION)); + return defaults; + } + catch (Exception ignore) { + } + return super.getDefaults(); } + + /*Shortcut for filed input*/ + Object fieldInputMap = new UIDefaults.LazyInputMap(new Object[]{ + "ctrl C", DefaultEditorKit.copyAction, + "ctrl V", DefaultEditorKit.pasteAction, + "ctrl X", DefaultEditorKit.cutAction, + "COPY", DefaultEditorKit.copyAction, + "PASTE", DefaultEditorKit.pasteAction, + "CUT", DefaultEditorKit.cutAction, + "control INSERT", DefaultEditorKit.copyAction, + "shift INSERT", DefaultEditorKit.pasteAction, + "shift DELETE", DefaultEditorKit.cutAction, + "shift LEFT", DefaultEditorKit.selectionBackwardAction, + "shift KP_LEFT", DefaultEditorKit.selectionBackwardAction, + "shift RIGHT", DefaultEditorKit.selectionForwardAction, + "shift KP_RIGHT", DefaultEditorKit.selectionForwardAction, + "ctrl LEFT", DefaultEditorKit.previousWordAction, + "ctrl KP_LEFT", DefaultEditorKit.previousWordAction, + "ctrl RIGHT", DefaultEditorKit.nextWordAction, + "ctrl KP_RIGHT", DefaultEditorKit.nextWordAction, + "ctrl shift LEFT", DefaultEditorKit.selectionPreviousWordAction, + "ctrl shift KP_LEFT", DefaultEditorKit.selectionPreviousWordAction, + "ctrl shift RIGHT", DefaultEditorKit.selectionNextWordAction, + "ctrl shift KP_RIGHT", DefaultEditorKit.selectionNextWordAction, + "ctrl A", DefaultEditorKit.selectAllAction, + "HOME", DefaultEditorKit.beginLineAction, + "END", DefaultEditorKit.endLineAction, + "shift HOME", DefaultEditorKit.selectionBeginLineAction, + "shift END", DefaultEditorKit.selectionEndLineAction, + "BACK_SPACE", DefaultEditorKit.deletePrevCharAction, + "shift BACK_SPACE", DefaultEditorKit.deletePrevCharAction, + "ctrl H", DefaultEditorKit.deletePrevCharAction, + "DELETE", DefaultEditorKit.deleteNextCharAction, + "ctrl DELETE", DefaultEditorKit.deleteNextWordAction, + "ctrl BACK_SPACE", DefaultEditorKit.deletePrevWordAction, + "RIGHT", DefaultEditorKit.forwardAction, + "LEFT", DefaultEditorKit.backwardAction, + "KP_RIGHT", DefaultEditorKit.forwardAction, + "KP_LEFT", DefaultEditorKit.backwardAction, + "ENTER", JTextField.notifyAction, + "ctrl BACK_SLASH", "unselect"/*DefaultEditorKit.unselectAction*/, + "control shift O", "toggle-componentOrientation"/*DefaultEditorKit.toggleComponentOrientation*/ + }); + + + /*Shortcut for multiline input*/ + Object multilineInputMap = new UIDefaults.LazyInputMap(new Object[]{ + "ctrl C", DefaultEditorKit.copyAction, + "ctrl V", DefaultEditorKit.pasteAction, + "ctrl X", DefaultEditorKit.cutAction, + "COPY", DefaultEditorKit.copyAction, + "PASTE", DefaultEditorKit.pasteAction, + "CUT", DefaultEditorKit.cutAction, + "control INSERT", DefaultEditorKit.copyAction, + "shift INSERT", DefaultEditorKit.pasteAction, + "shift DELETE", DefaultEditorKit.cutAction, + "shift LEFT", DefaultEditorKit.selectionBackwardAction, + "shift KP_LEFT", DefaultEditorKit.selectionBackwardAction, + "shift RIGHT", DefaultEditorKit.selectionForwardAction, + "shift KP_RIGHT", DefaultEditorKit.selectionForwardAction, + "ctrl LEFT", DefaultEditorKit.previousWordAction, + "ctrl KP_LEFT", DefaultEditorKit.previousWordAction, + "ctrl RIGHT", DefaultEditorKit.nextWordAction, + "ctrl KP_RIGHT", DefaultEditorKit.nextWordAction, + "ctrl shift LEFT", DefaultEditorKit.selectionPreviousWordAction, + "ctrl shift KP_LEFT", DefaultEditorKit.selectionPreviousWordAction, + "ctrl shift RIGHT", DefaultEditorKit.selectionNextWordAction, + "ctrl shift KP_RIGHT", DefaultEditorKit.selectionNextWordAction, + "ctrl A", DefaultEditorKit.selectAllAction, + "HOME", DefaultEditorKit.beginLineAction, + "END", DefaultEditorKit.endLineAction, + "shift HOME", DefaultEditorKit.selectionBeginLineAction, + "shift END", DefaultEditorKit.selectionEndLineAction, + + "UP", DefaultEditorKit.upAction, + "KP_UP", DefaultEditorKit.upAction, + "DOWN", DefaultEditorKit.downAction, + "KP_DOWN", DefaultEditorKit.downAction, + "PAGE_UP", DefaultEditorKit.pageUpAction, + "PAGE_DOWN", DefaultEditorKit.pageDownAction, + "shift PAGE_UP", "selection-page-up", + "shift PAGE_DOWN", "selection-page-down", + "ctrl shift PAGE_UP", "selection-page-left", + "ctrl shift PAGE_DOWN", "selection-page-right", + "shift UP", DefaultEditorKit.selectionUpAction, + "shift KP_UP", DefaultEditorKit.selectionUpAction, + "shift DOWN", DefaultEditorKit.selectionDownAction, + "shift KP_DOWN", DefaultEditorKit.selectionDownAction, + "ENTER", DefaultEditorKit.insertBreakAction, + "BACK_SPACE", DefaultEditorKit.deletePrevCharAction, + "shift BACK_SPACE", DefaultEditorKit.deletePrevCharAction, + "ctrl H", DefaultEditorKit.deletePrevCharAction, + "DELETE", DefaultEditorKit.deleteNextCharAction, + "ctrl DELETE", DefaultEditorKit.deleteNextWordAction, + "ctrl BACK_SPACE", DefaultEditorKit.deletePrevWordAction, + "RIGHT", DefaultEditorKit.forwardAction, + "LEFT", DefaultEditorKit.backwardAction, + "KP_RIGHT", DefaultEditorKit.forwardAction, + "KP_LEFT", DefaultEditorKit.backwardAction, + "TAB", DefaultEditorKit.insertTabAction, + "ctrl BACK_SLASH", "unselect"/*DefaultEditorKit.unselectAction*/, + "ctrl HOME", DefaultEditorKit.beginAction, + "ctrl END", DefaultEditorKit.endAction, + "ctrl shift HOME", DefaultEditorKit.selectionBeginAction, + "ctrl shift END", DefaultEditorKit.selectionEndAction, + "ctrl T", "next-link-action", + "ctrl shift T", "previous-link-action", + "ctrl SPACE", "activate-link-action", + "control shift O", "toggle-componentOrientation"/*DefaultEditorKit.toggleComponentOrientation*/ + }); } diff --git a/src/main/java/mdlaf/animation/MaterialUIStaticMovement.java b/src/main/java/mdlaf/animation/MaterialUIStaticMovement.java index 699cbd9..5f56ea1 100644 --- a/src/main/java/mdlaf/animation/MaterialUIStaticMovement.java +++ b/src/main/java/mdlaf/animation/MaterialUIStaticMovement.java @@ -1,3 +1,26 @@ +/* + * MIT License + * + * Copyright (c) 2019 Vincent Palazzo vincenzopalazzodev@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 + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package mdlaf.animation; import javax.swing.*; @@ -24,16 +47,11 @@ public MaterialUIStaticMovement(Color before, Color after, Color strongOnClick) @Override public void mouseClicked(MouseEvent e) { - /*For effect click, need create a timer ?*/ - /* if(e == null){ - throw new IllegalArgumentException("MouseEvent null"); - } - setColorComponent(e, after);*/ + // do nothing } @Override public void mousePressed(MouseEvent e) { - /*For effect click, need create a timer ?*/ if(e == null){ throw new IllegalArgumentException("MouseEvent null"); } @@ -42,7 +60,6 @@ public void mousePressed(MouseEvent e) { @Override public void mouseReleased(MouseEvent e) { - /*For effect click, need create a timer ?*/ if(e == null){ throw new IllegalArgumentException("MouseEvent null"); } @@ -65,7 +82,7 @@ public void mouseExited(MouseEvent e) { setColorComponent(e, before); } - /*** + /** * This is service method for recicle code */ private void setColorComponent(MouseEvent e, Color colorComponent){ diff --git a/src/main/java/mdlaf/animation/MaterialUITimer.java b/src/main/java/mdlaf/animation/MaterialUITimer.java index 40aab04..1525382 100644 --- a/src/main/java/mdlaf/animation/MaterialUITimer.java +++ b/src/main/java/mdlaf/animation/MaterialUITimer.java @@ -1,7 +1,8 @@ /* * MIT License * - * Copyright (c) 2018 atharva washimkar, Vincent Palazzo + * Copyright (c) 2018 atharva washimkar + * Copyright (c) 2019 Vincent Palazzo vincenzopalazzodev@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 @@ -27,7 +28,7 @@ import java.awt.Color; import java.awt.event.*; -public class MaterialUITimer implements MouseListener, ActionListener, MouseMotionListener { +class MaterialUITimer implements MouseListener, ActionListener, MouseMotionListener { private Color from, to; private boolean forward; @@ -60,7 +61,6 @@ protected MaterialUITimer(JComponent component, Color to, int steps, int interva this.steps = steps; this.component = component; - this.component.addMouseListener(this); timer = new Timer(interval, this); component.setBackground(from); } @@ -90,6 +90,9 @@ public void mousePressed(MouseEvent me) { } alpha = steps - 1; forward = false; + if(timer.isRunning()){ + timer.stop(); + } timer.start(); alpha = 0; @@ -99,12 +102,12 @@ public void mousePressed(MouseEvent me) { @Override public void mouseReleased(MouseEvent me) { - + //do nothing } @Override public void mouseClicked(MouseEvent me) { - + //do nothing } @Override @@ -112,6 +115,9 @@ public void mouseExited(MouseEvent me) { if (!me.getComponent().isEnabled()) { return; } + if(timer.isRunning()){ + timer.stop(); + } alpha = steps - 1; forward = false; timer.start(); @@ -124,6 +130,9 @@ public void mouseEntered(MouseEvent me) { } alpha = 0; forward = true; + if(timer.isRunning()){ + timer.stop(); + } timer.start(); } @@ -138,7 +147,9 @@ public void actionPerformed(ActionEvent ae) { } if (alpha == steps + 1 || alpha == -1) { - timer.stop(); + if(timer.isRunning()){ + timer.stop(); + } } } diff --git a/src/main/java/mdlaf/components/button/MaterialButtonUI.java b/src/main/java/mdlaf/components/button/MaterialButtonUI.java index 09856c8..bff402e 100644 --- a/src/main/java/mdlaf/components/button/MaterialButtonUI.java +++ b/src/main/java/mdlaf/components/button/MaterialButtonUI.java @@ -2,23 +2,23 @@ import mdlaf.animation.MaterialUIMovement; import mdlaf.utils.MaterialDrawingUtils; -import javax.swing.AbstractButton; -import javax.swing.JComponent; -import javax.swing.UIManager; + +import javax.swing.*; import javax.swing.plaf.ComponentUI; -import javax.swing.plaf.basic.BasicButtonUI; +import javax.swing.plaf.metal.MetalButtonUI; import java.awt.*; /** * @contributor https://github.com/vincenzopalazzo */ - -public class MaterialButtonUI extends BasicButtonUI { - +public class MaterialButtonUI extends MetalButtonUI { public static ComponentUI createUI(final JComponent c) { return new MaterialButtonUI(); } + private Color foreground; + private Color background; + @Override public void installUI(JComponent c) { super.installUI(c); @@ -26,36 +26,40 @@ public void installUI(JComponent c) { AbstractButton button = (AbstractButton) c; button.setOpaque(UIManager.getBoolean("Button.opaque")); button.setBorder(UIManager.getBorder("Button.border")); - button.setBackground(UIManager.getColor("Button.background")); - button.setForeground(UIManager.getColor("Button.foreground")); + foreground = UIManager.getColor("Button.foreground"); + background = UIManager.getColor("Button.background"); + button.setBackground(background); + button.setForeground(foreground); button.setFont(UIManager.getFont("Button.font")); button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); button.addMouseListener(MaterialUIMovement.getMovement(button, UIManager.getColor("Button.mouseHoverColor"))); + button.setFocusable(UIManager.getBoolean("Button.focusable")); } @Override public void paint(Graphics g, JComponent c) { - AbstractButton b = (AbstractButton) c; - g = MaterialDrawingUtils.getAliasedGraphics(g); + JButton b = (JButton) c; if (b.isContentAreaFilled()) { paintBackground(MaterialDrawingUtils.getAliasedGraphics(g), b); } + super.paint(MaterialDrawingUtils.getAliasedGraphics(g), c); } - //Fix to #73 border were pixeled, fixde by https://github.com/vincenzopalazzo + private void paintBackground(Graphics g, JComponent c) { - //g.setColor(c.getBackground()); - //g.fillRoundRect(0, 0, c.getWidth(), c.getHeight(), 7, 7); Graphics2D graphics2D = (Graphics2D) g; graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g = graphics2D; g.setColor(c.getBackground()); g.fillRoundRect(0, 0, c.getWidth(), c.getHeight(), 7, 7); + + paintStateButton(c, g); } @Override - protected void paintButtonPressed(Graphics g, AbstractButton b) { - super.paintButtonPressed(g, b); + protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect, Rectangle textRect, Rectangle iconRect) { + super.paintFocus(g, b, viewRect, textRect, iconRect); + driveLine(g, (JButton) b); } @Override @@ -64,5 +68,25 @@ public void update(Graphics g, JComponent c) { c.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } + @Override + protected void paintButtonPressed(Graphics g, AbstractButton b) { + g.fillRoundRect(0, 0, b.getWidth(), b.getHeight(), 7, 7); + } + + protected void driveLine(Graphics g, JButton b){ + g.setColor(UIManager.getColor("Button[focus].color")); + g.drawLine(20 , (b.getHeight() / 2) + 10, b.getWidth() - 20, (b.getHeight() / 2) + 10); + } + + protected void paintStateButton(JComponent component, Graphics graphics) { + if(component == null){ + throw new IllegalArgumentException("Input null"); + } + JButton b = (JButton) component; + if(b.isDefaultButton()){ + driveLine(graphics, b); + } + } + } \ No newline at end of file diff --git a/src/main/java/mdlaf/components/checkbox/MaterialCheckBoxUI.java b/src/main/java/mdlaf/components/checkbox/MaterialCheckBoxUI.java index 32e3d39..847dad8 100644 --- a/src/main/java/mdlaf/components/checkbox/MaterialCheckBoxUI.java +++ b/src/main/java/mdlaf/components/checkbox/MaterialCheckBoxUI.java @@ -2,14 +2,11 @@ import mdlaf.utils.MaterialDrawingUtils; -import javax.swing.JCheckBox; -import javax.swing.JComponent; -import javax.swing.UIManager; +import javax.swing.*; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicCheckBoxUI; import java.awt.*; -//TODO cambio colore icone combo box public class MaterialCheckBoxUI extends BasicCheckBoxUI { public static ComponentUI createUI (JComponent c) { @@ -26,8 +23,7 @@ public void installUI (JComponent c) { checkBox.setForeground (UIManager.getColor ("CheckBox.foreground")); checkBox.setIcon (UIManager.getIcon ("CheckBox.icon")); checkBox.setSelectedIcon (UIManager.getIcon ("CheckBox.selectedIcon")); - c.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - + checkBox.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } @Override diff --git a/src/main/java/mdlaf/components/checkboxmenuitem/MaterialCheckBoxMenuItemUI.java b/src/main/java/mdlaf/components/checkboxmenuitem/MaterialCheckBoxMenuItemUI.java index 3ac84b5..c8610db 100644 --- a/src/main/java/mdlaf/components/checkboxmenuitem/MaterialCheckBoxMenuItemUI.java +++ b/src/main/java/mdlaf/components/checkboxmenuitem/MaterialCheckBoxMenuItemUI.java @@ -13,7 +13,6 @@ /** * @author https://github.com/vincenzopalazzo */ - public class MaterialCheckBoxMenuItemUI extends BasicCheckBoxMenuItemUI { public static ComponentUI createUI (JComponent c) { @@ -23,6 +22,11 @@ public static ComponentUI createUI (JComponent c) { @Override public void installUI (JComponent c) { super.installUI (c); + + c.setBackground(UIManager.getColor("CheckBoxMenuItem.background")); + c.setForeground(UIManager.getColor("CheckBoxMenuItem.foreground")); + c.setBorder(UIManager.getBorder("CheckBoxMenuItem.border")); + c.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } @Override @@ -33,7 +37,6 @@ public void paint (Graphics g, JComponent c) { @Override protected void paintMenuItem (Graphics g, JComponent c, Icon checkIcon, Icon arrowIcon, Color background, Color foreground, int defaultTextIconGap) { JCheckBoxMenuItem checkBoxMenuItem = (JCheckBoxMenuItem) c; - c.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); if (checkBoxMenuItem.isSelected ()) { super.paintMenuItem (MaterialDrawingUtils.getAliasedGraphics (g), checkBoxMenuItem, UIManager.getIcon ("CheckBoxMenuItem.selectedCheckIcon"), arrowIcon, background, foreground, defaultTextIconGap); return; diff --git a/src/main/java/mdlaf/components/combobox/MaterialComboBoxRenderer.java b/src/main/java/mdlaf/components/combobox/MaterialComboBoxRenderer.java index 1c4992d..180a03b 100644 --- a/src/main/java/mdlaf/components/combobox/MaterialComboBoxRenderer.java +++ b/src/main/java/mdlaf/components/combobox/MaterialComboBoxRenderer.java @@ -16,11 +16,12 @@ public Component getListCellRendererComponent (JList list, Object value, int ind component.setBorder (BorderFactory.createEmptyBorder (5, 5, 5, 5)); component.setForeground (UIManager.getColor ("ComboBox.foreground")); component.setBackground (isSelected || cellHasFocus ? - UIManager.getColor ("ComboBox.selectedInDropDownBackground") : - UIManager.getColor ("ComboBox.background")); + UIManager.getColor("ComboBox.selectedInDropDownBackground") : + UIManager.getColor("ComboBox.background")); return component; } + } diff --git a/src/main/java/mdlaf/components/combobox/MaterialComboBoxUI.java b/src/main/java/mdlaf/components/combobox/MaterialComboBoxUI.java index d37cb48..d414867 100644 --- a/src/main/java/mdlaf/components/combobox/MaterialComboBoxUI.java +++ b/src/main/java/mdlaf/components/combobox/MaterialComboBoxUI.java @@ -4,17 +4,12 @@ import mdlaf.utils.MaterialBorders; import mdlaf.utils.MaterialDrawingUtils; import mdlaf.utils.MaterialManagerListener; -import javax.swing.Icon; -import javax.swing.JButton; -import javax.swing.JComboBox; -import javax.swing.JComponent; -import javax.swing.SwingConstants; -import javax.swing.UIManager; + +import javax.swing.*; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicArrowButton; import javax.swing.plaf.basic.BasicComboBoxUI; -import java.awt.Cursor; -import java.awt.Graphics; +import java.awt.*; /** * @contributor https://github.com/vincenzopalazzo @@ -35,7 +30,6 @@ public void installUI (JComponent c) { comboBox.setForeground (UIManager.getColor ("ComboBox.foreground")); comboBox.setBorder (UIManager.getBorder ("ComboBox.border")); comboBox.setLightWeightPopupEnabled (true); - comboBox.setRenderer (new MaterialComboBoxRenderer ()); comboBox.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } @@ -64,5 +58,8 @@ public void paint (Graphics g, JComponent c) { super.paint (MaterialDrawingUtils.getAliasedGraphics (g), c); } - + @Override + protected ListCellRenderer createRenderer() { + return new MaterialComboBoxRenderer(); + } } diff --git a/src/main/java/mdlaf/components/list/MaterialListUI.java b/src/main/java/mdlaf/components/list/MaterialListUI.java new file mode 100644 index 0000000..8030621 --- /dev/null +++ b/src/main/java/mdlaf/components/list/MaterialListUI.java @@ -0,0 +1,58 @@ +/* + * MIT License + * Copyright (c) 2018 atharva washimkar + * Copyright (c) 2019 Vincent Palazzo vincenzopalazzodev@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 + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package mdlaf.components.list; + +import javax.swing.*; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.basic.BasicListUI; +import java.awt.*; + +/** + * @author https://github.com/vincenzopalazzo + */ +public class MaterialListUI extends BasicListUI { + + @SuppressWarnings({"MethodOverridesStaticMethodOfSuperclass", "UnusedDeclaration"}) + public static ComponentUI createUI(JComponent c) { + return new MaterialListUI(); + } + + @Override + public void installUI(JComponent c) { + super.installUI(c); + + list = (JList) c; + list.setBackground(UIManager.getColor("List.background")); + list.setForeground(UIManager.getColor("List.foreground")); + list.setBorder(UIManager.getBorder("List.border")); + list.setFont(UIManager.getFont("List.font")); + list.setSelectionBackground(UIManager.getColor("List.selectionBackground")); + list.setSelectionForeground(UIManager.getColor("List.selectionForeground")); + list.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + list.setFocusable(UIManager.getBoolean("List.focusable")); + } + + + +} diff --git a/src/main/java/mdlaf/components/optionpane/MaterialOptionPaneUI.java b/src/main/java/mdlaf/components/optionpane/MaterialOptionPaneUI.java index e3c8612..d181250 100644 --- a/src/main/java/mdlaf/components/optionpane/MaterialOptionPaneUI.java +++ b/src/main/java/mdlaf/components/optionpane/MaterialOptionPaneUI.java @@ -1,6 +1,28 @@ +/* + * MIT License + * Copyright (c) 2018 atharva washimkar + * Copyright (c) 2019 Vincent Palazzo vincenzopalazzodev@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 + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package mdlaf.components.optionpane; - import javax.swing.*; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicOptionPaneUI; @@ -11,13 +33,11 @@ */ public class MaterialOptionPaneUI extends BasicOptionPaneUI { - @SuppressWarnings({"MethodOverridesStaticMethodOfSuperclass", "UnusedDeclaration"}) public static ComponentUI createUI(JComponent c) { return new MaterialOptionPaneUI(); } - @Override public void update(Graphics g, JComponent c) { super.update(g, c); @@ -25,18 +45,11 @@ public void update(Graphics g, JComponent c) { @Override protected Icon getIconForType(int messageType) { - if(messageType == JOptionPane.ERROR_MESSAGE){ - return UIManager.getIcon("OptionPaneUI.errorIcon"); - } - if(messageType == JOptionPane.INFORMATION_MESSAGE){ - return UIManager.getIcon("OptionPaneUI.informationIcon"); - } - if(messageType == JOptionPane.QUESTION_MESSAGE){ - return UIManager.getIcon("OptionPaneUI.questionIcon"); - } - if(messageType == JOptionPane.WARNING_MESSAGE){ - return UIManager.getIcon("OptionPaneUI.warningIcon"); - } return super.getIconForType(messageType); } + + @Override + protected void addButtonComponents(Container container, Object[] buttons, int initialIndex) { + super.addButtonComponents(container, buttons, initialIndex); + } } diff --git a/src/main/java/mdlaf/components/password/MaterialPasswordFieldUI.java b/src/main/java/mdlaf/components/password/MaterialPasswordFieldUI.java index f88572f..cab6752 100644 --- a/src/main/java/mdlaf/components/password/MaterialPasswordFieldUI.java +++ b/src/main/java/mdlaf/components/password/MaterialPasswordFieldUI.java @@ -1,29 +1,39 @@ +/* + * MIT License + * Copyright (c) 2018 atharva washimkar + * Copyright (c) 2019 Vincent Palazzo vincenzopalazzodev@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 + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package mdlaf.components.password; -import mdlaf.utils.MaterialColors; import mdlaf.utils.MaterialDrawingUtils; -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.BorderFactory; -import javax.swing.JComponent; -import javax.swing.JPasswordField; -import javax.swing.KeyStroke; +import javax.swing.*; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicPasswordFieldUI; import javax.swing.text.Element; import javax.swing.text.PasswordView; import javax.swing.text.View; -import java.awt.Color; -import java.awt.FontMetrics; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.RenderingHints; -import java.awt.Toolkit; -import java.awt.event.ActionEvent; +import java.awt.*; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; -import java.awt.event.KeyEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; @@ -32,167 +42,184 @@ */ public class MaterialPasswordFieldUI extends BasicPasswordFieldUI implements FocusListener, PropertyChangeListener { - private Color focusedBackground; - private Color unfocusedBackground; - private Color focusedSelectionBackground; - private Color unfocusedSelectionBackground; + private boolean drawLine; + private Color activeBackground; + private Color activeForeground; + private Color inactiveBackground; + private Color inactiveForeground; - public static ComponentUI createUI (JComponent c) { - return new MaterialPasswordFieldUI (); + public MaterialPasswordFieldUI() { + this(true); } - @Override - public void installUI (JComponent c) { - super.installUI (c); + public MaterialPasswordFieldUI(boolean drawLine) { + super(); + this.drawLine = drawLine; + } + + public static ComponentUI createUI(JComponent c) { + return new MaterialPasswordFieldUI(); + } + @Override + public void installUI(JComponent c) { + super.installUI(c); JPasswordField passwordField = (JPasswordField) c; - passwordField.setOpaque (false); - passwordField.setBorder (BorderFactory.createEmptyBorder (5, 2, 2, 0)); - passwordField.setBackground (MaterialColors.LIGHT_BLUE_400); + passwordField.setEchoChar('\u2022'); + } + + @Override + protected void installDefaults() { + super.installDefaults(); + installMaterialDefault(); + } - this.focusedBackground = passwordField.getBackground (); - this.unfocusedBackground = MaterialColors.GRAY_200; + @Override + protected void uninstallDefaults() { + getComponent().setBorder(null); + super.uninstallDefaults(); + } - this.focusedSelectionBackground = MaterialColors.bleach (focusedBackground, 0.3f); - this.unfocusedSelectionBackground = unfocusedBackground; + @Override + protected void installListeners() { + super.installListeners(); + getComponent().addFocusListener(this); + getComponent().addPropertyChangeListener(this); } @Override - protected void installListeners () { - getComponent ().addFocusListener (this); - getComponent ().addPropertyChangeListener (this); + protected void uninstallListeners() { + getComponent().removeFocusListener(this); + super.uninstallListeners(); } @Override - protected void installKeyboardActions () { - super.installKeyboardActions (); - - Action selectAll = new AbstractAction () { - @Override - public void actionPerformed (ActionEvent e) { - getComponent ().selectAll (); - } - }; - - Action delete = new AbstractAction () { - @Override - public void actionPerformed (ActionEvent e) { - if (getComponent ().getSelectedText () == null) { - int pos = getComponent ().getCaretPosition () - 1; - - if (pos >= 0) { - getComponent ().select (pos, pos + 1); - getComponent ().replaceSelection (""); - } - } - else { - getComponent ().replaceSelection (""); - } - } - }; - - Action left = new AbstractAction () { - @Override - public void actionPerformed (ActionEvent e) { - getComponent ().setCaretPosition (Math.max (0, getComponent ().getCaretPosition () - 1)); - } - }; - - Action right = new AbstractAction () { - @Override - public void actionPerformed (ActionEvent e) { - getComponent ().setCaretPosition (Math.min (getComponent ().getText ().length (), getComponent ().getCaretPosition () + 1)); - } - }; - - // note getMenuShortcutKeyMask() is deprecated in Java 10 - change to getMenuShortcutKeyMaskEx() - getComponent ().getInputMap ().put (KeyStroke.getKeyStroke (KeyEvent.VK_A, Toolkit.getDefaultToolkit ().getMenuShortcutKeyMask ()), "selectAll"); - getComponent ().getInputMap ().put (KeyStroke.getKeyStroke (KeyEvent.VK_BACK_SPACE, 0), "delete"); - getComponent ().getInputMap ().put (KeyStroke.getKeyStroke (KeyEvent.VK_LEFT, 0), "left"); - getComponent ().getInputMap ().put (KeyStroke.getKeyStroke (KeyEvent.VK_RIGHT, 0), "right"); - - getComponent ().getActionMap ().put ("selectAll", selectAll); - getComponent ().getActionMap ().put ("delete", delete); - getComponent ().getActionMap ().put ("left", left); - getComponent ().getActionMap ().put ("right", right); + protected void paintBackground(Graphics g) { + super.paintBackground(MaterialDrawingUtils.getAliasedGraphics(g)); } @Override - public void paintSafely (Graphics g) { - JPasswordField c = (JPasswordField) getComponent (); - g = MaterialDrawingUtils.getAliasedGraphics (g); + public void focusGained(FocusEvent e) { + changeColorOnFocus(true); + } - if (getComponent ().hasFocus ()) { - c.setBackground (focusedBackground); - c.setSelectionColor (focusedSelectionBackground); - } - else { - c.setBackground (unfocusedBackground); - c.setSelectionColor (unfocusedSelectionBackground); - } + @Override + public void focusLost(FocusEvent e) { + changeColorOnFocus(false); + } - int x = getComponent ().getInsets ().left; - int y = getComponent ().getInsets ().top; - int w = getComponent ().getWidth () - getComponent ().getInsets ().left - getComponent ().getInsets ().right; + @Override + public void paintSafely(Graphics g) { + JPasswordField c = (JPasswordField) getComponent(); + super.paintSafely(g); - g.setColor (c.getBackground ()); - g.fillRect (x, c.getHeight () - y + 1, w, 1); + if (drawLine) { + int x = c.getInsets().left; + int y = c.getInsets().top; + int w = c.getWidth() - c.getInsets().left - c.getInsets().right; + g.setColor(c.getSelectionColor()); + + g.fillRect(x, c.getHeight() - y, w, 1); + } - super.paintSafely (g); } @Override - public void paintBackground (Graphics g) { - super.paintBackground (MaterialDrawingUtils.getAliasedGraphics (g)); + public void propertyChange(PropertyChangeEvent pce) { + super.propertyChange(pce); + + if (pce.getPropertyName().equals("selectionColor")) { + Color newColor = (Color) pce.getNewValue(); + logicForPropertyChange(newColor, false); + } + + if (pce.getPropertyName().equals("selectedTextColor")) { + Color newColor = (Color) pce.getNewValue(); + logicForPropertyChange(newColor, true); + } + if (pce.getPropertyName().equals("background")) { + getComponent().repaint(); + } + } @Override - public void focusGained (FocusEvent e) { - e.getComponent ().setBackground (focusedBackground); + public View create(Element elem) { + return new MaterialPasswordView(elem); } - @Override - public void focusLost (FocusEvent e) { - e.getComponent ().setBackground (unfocusedBackground); + protected void installMaterialDefault() { + this.activeBackground = UIManager.getColor("PasswordField.selectionBackground"); + this.activeForeground = UIManager.getColor("PasswordField.selectionForeground"); + this.inactiveBackground = UIManager.getColor("PasswordField.inactiveBackground"); + this.inactiveForeground = UIManager.getColor("PasswordField.inactiveForeground"); + getComponent().setFont(UIManager.getFont("PasswordField.font")); + + getComponent().setSelectionColor(getComponent().hasFocus() && getComponent().isEnabled() ? activeBackground : inactiveBackground); + getComponent().setSelectedTextColor(getComponent().hasFocus() && getComponent().isEnabled() ? activeForeground : inactiveForeground); + getComponent().setForeground(getComponent().hasFocus() && getComponent().isEnabled() ? activeForeground : inactiveForeground); + getComponent().setBorder(UIManager.getBorder("PasswordField.border")); } - @Override - public void propertyChange (PropertyChangeEvent pce) { - if (pce.getPropertyName ().equals ("background")) { - Color newColor = (Color) pce.getNewValue (); - - if (!newColor.equals (focusedBackground) && !newColor.equals (unfocusedBackground)) { - this.focusedBackground = (Color) pce.getNewValue (); - this.focusedSelectionBackground = MaterialColors.bleach (this.focusedBackground, 0.3f); - } + protected void changeColorOnFocus(boolean hasFocus) { + JPasswordField c = (JPasswordField) getComponent(); + if (c == null) { + return; + } + if (hasFocus && (activeBackground != null) && (activeForeground != null)) { + logicForChangeColorOnFocus(c, activeBackground, activeForeground); } + if (!hasFocus && (inactiveBackground != null) && (inactiveForeground != null)) { + logicForChangeColorOnFocus(c, inactiveBackground, inactiveForeground); + } + c.paint(c.getGraphics()); } - @Override - public View create (Element elem) { - return new MaterialPasswordView (elem); + protected void logicForChangeColorOnFocus(JComponent component, Color background, Color foreground) { + if (background == null || foreground == null) { + throw new IllegalArgumentException("Argument function null"); + } + JTextField textField = (JTextField) component; + textField.setSelectionColor(background); + textField.setForeground(foreground); + textField.setSelectedTextColor(foreground); } - private static class MaterialPasswordView extends PasswordView { + protected void logicForPropertyChange(Color newColor, boolean isForeground){ + if(newColor == null){ + throw new IllegalArgumentException("The inpur argument is null"); + } + if (isForeground && !newColor.equals(activeForeground) && !newColor.equals(inactiveForeground)) { + this.activeForeground = newColor; + getComponent().repaint(); + } + if (!isForeground && !newColor.equals(activeBackground) && !newColor.equals(inactiveBackground)) { + this.activeBackground = newColor; + getComponent().repaint(); + } + } - private MaterialPasswordView (Element elem) { - super (elem); + protected static class MaterialPasswordView extends PasswordView { + + private MaterialPasswordView(Element elem) { + super(elem); } // depreciated in Java 9 and above - replace method with float drawEchoCharacter(Graphics2D g, float x, float y, char c) @Override - protected int drawEchoCharacter (Graphics g, int x, int y, char c) { - Graphics2D g2 = (Graphics2D) g.create (); - g2.setRenderingHint (RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + protected int drawEchoCharacter(Graphics g, int x, int y, char c) { + Graphics2D g2 = (Graphics2D) g.create(); + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - FontMetrics fm = g2.getFontMetrics (); - int r = fm.charWidth (c) - 2; + FontMetrics fm = g2.getFontMetrics(); + int r = fm.charWidth(c) - 2; - g2.setPaint (Color.BLACK); - g2.fillOval (x + 1, y + 5 - fm.getAscent (), r, r); - g2.dispose (); + g2.setPaint(Color.BLACK); + g2.fillOval(x + 1, y + 5 - fm.getAscent(), r, r); + g2.dispose(); - return x + fm.charWidth (c); + return x + fm.charWidth(c); } } + } \ No newline at end of file diff --git a/src/main/java/mdlaf/components/radiobuttonmenuitem/MaterialRadioButtonMenuItemUI.java b/src/main/java/mdlaf/components/radiobuttonmenuitem/MaterialRadioButtonMenuItemUI.java index 9d26be2..7698f38 100644 --- a/src/main/java/mdlaf/components/radiobuttonmenuitem/MaterialRadioButtonMenuItemUI.java +++ b/src/main/java/mdlaf/components/radiobuttonmenuitem/MaterialRadioButtonMenuItemUI.java @@ -13,7 +13,6 @@ /** * @author https://github.com/vincenzopalazzo */ - public class MaterialRadioButtonMenuItemUI extends BasicRadioButtonMenuItemUI { public static ComponentUI createUI (JComponent c) { @@ -23,9 +22,10 @@ public static ComponentUI createUI (JComponent c) { @Override public void installUI (JComponent c) { super.installUI (c); - JRadioButtonMenuItem j = (JRadioButtonMenuItem) c; - //j.setBackground(MaterialColors.WHITE); - j.setBorder (UIManager.getBorder ("MenuItem.border")); + + c.setBackground(UIManager.getColor("RadioButtonMenuItem.background")); + c.setForeground(UIManager.getColor("RadioButtonMenuItem.foreground")); + c.setBorder(UIManager.getBorder("RadioButtonMenuItem.border")); c.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } diff --git a/src/main/java/mdlaf/components/scrollbar/MaterialScrollBarUI.java b/src/main/java/mdlaf/components/scrollbar/MaterialScrollBarUI.java index cfbc5f7..a4d5787 100644 --- a/src/main/java/mdlaf/components/scrollbar/MaterialScrollBarUI.java +++ b/src/main/java/mdlaf/components/scrollbar/MaterialScrollBarUI.java @@ -1,23 +1,40 @@ +/* + * MIT License + * Copyright (c) 2018 atharva washimkar + * Copyright (c) 2019 Vincent Palazzo vincenzopalazzodev@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 + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package mdlaf.components.scrollbar; import mdlaf.animation.MaterialUIMovement; -import mdlaf.utils.MaterialColors; -import mdlaf.utils.MaterialDrawingUtils; -import mdlaf.utils.MaterialManagerListener; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.UIManager; +import mdlaf.utils.*; +import javax.swing.*; import javax.swing.plaf.ComponentUI; -import javax.swing.plaf.basic.BasicArrowButton; import javax.swing.plaf.basic.BasicScrollBarUI; import java.awt.*; /* - * Contributed by https://github.com/downToHell - * Contributed for refactoring by https://github.com/vincenzopalazzo - * */ - + * @contributor by https://github.com/downToHell + * @contributor for refactoring by https://github.com/vincenzopalazzo + */ public class MaterialScrollBarUI extends BasicScrollBarUI { public static ComponentUI createUI (JComponent c) { @@ -54,32 +71,61 @@ protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) { protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) { super.paintThumb(g, c, thumbBounds); g.setColor(UIManager.getColor ("ScrollBar.thumb")); + + } + + @Override + protected void configureScrollBarColors() { + super.configureScrollBarColors(); + thumbDarkShadowColor = UIManager.getColor ("ScrollBar.thumbDarkShadow"); + thumbHighlightColor = UIManager.getColor ("ScrollBar.thumbHighlight"); + thumbLightShadowColor = UIManager.getColor ("ScrollBar.thumbShadow"); } - /** - * Method service for not duplicate code - * @author https://github.com/vincenzopalazzo - * @param orientation - * @return JButton with correct orientation - */ - private JButton installButton(int orientation){ - JButton button = new BasicArrowButton (orientation); + private void setIconArrowButton(JButton button, int orientation) { + if(button == null){ + throw new IllegalArgumentException("Input null"); + } + if (orientation == SwingConstants.NORTH){ + button.setIcon(new ImageIcon(MaterialImages.UP_ARROW)); + return; + }else if(orientation == SwingConstants.SOUTH){ + button.setIcon(new ImageIcon(MaterialImages.DOWN_ARROW)); + return; + }else if(orientation == SwingConstants.EAST){ + button.setIcon(new ImageIcon(MaterialImages.RIGHT_ARROW)); + return; + }else if(orientation == SwingConstants.WEST){ + button.setIcon(new ImageIcon(MaterialImages.LEFT_ARROW)); + return; + } + throw new IllegalArgumentException("orientation not valid"); + } + + private void createInvisibleButton(JComponent component){ + if(component == null){ + throw new IllegalArgumentException("Argument function null"); + } + component.setPreferredSize(new Dimension(0, 0)); + component.setMinimumSize(new Dimension(0, 0)); + component.setMaximumSize(new Dimension(0, 0)); + } + + protected JButton installButton(int orientation){ + JButton button = new JButton(); MaterialManagerListener.removeAllMouseListener(button); button.setOpaque (true); button.setBackground (UIManager.getColor ("ScrollBar.arrowButtonBackground")); + if(!UIManager.getBoolean("ScrollBar.enableArrow")){ + createInvisibleButton(button); + return button; + } + setIconArrowButton(button, orientation); if(UIManager.getBoolean("ScrollBar[MouseHover].enable")){ button.addMouseListener(MaterialUIMovement.getStaticMovement(button,UIManager.getColor("ScrollBar[MouseHover].color"), UIManager.getColor("ScrollBar[OnClick].color"))); } - button.setBorder (UIManager.getBorder ("ScrollBar.arrowButtonBorder")); + button.setBorder (UIManager.getBorder("ScrollBar.arrowButtonBorder")); return button; } - - @Override - protected void configureScrollBarColors() { - super.configureScrollBarColors(); - thumbDarkShadowColor = UIManager.getColor ("ScrollBar.thumbDarkShadow"); - thumbHighlightColor = UIManager.getColor ("ScrollBar.thumbHighlight"); - thumbLightShadowColor = UIManager.getColor ("ScrollBar.thumbShadow"); - } } \ No newline at end of file diff --git a/src/main/java/mdlaf/components/spinner/MaterialSpinnerUI.java b/src/main/java/mdlaf/components/spinner/MaterialSpinnerUI.java index 8915df5..3c0f9c7 100644 --- a/src/main/java/mdlaf/components/spinner/MaterialSpinnerUI.java +++ b/src/main/java/mdlaf/components/spinner/MaterialSpinnerUI.java @@ -3,7 +3,6 @@ import mdlaf.animation.MaterialUIMovement; import mdlaf.utils.MaterialBorders; import mdlaf.utils.MaterialDrawingUtils; -import mdlaf.utils.MaterialManagerListener; import javax.swing.*; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicArrowButton; @@ -56,7 +55,6 @@ protected Component createNextButton() { } else { button = new BasicArrowButton(SwingConstants.NORTH); } - MaterialManagerListener.removeAllMouseListener(button); button.setOpaque(true); button.setBackground(UIManager.getColor("Spinner.arrowButtonBackground")); button.setBorder(UIManager.getBorder("Spinner.arrowButtonBorder")); @@ -77,7 +75,6 @@ protected Component createPreviousButton() { } else { button = new BasicArrowButton(SwingConstants.SOUTH); } - MaterialManagerListener.removeAllMouseListener(button); button.setOpaque(true); button.setBackground(UIManager.getColor("Spinner.arrowButtonBackground")); button.setBorder(UIManager.getBorder("Spinner.arrowButtonBorder")); diff --git a/src/main/java/mdlaf/components/textfield/MaterialTextFieldUI.java b/src/main/java/mdlaf/components/textfield/MaterialTextFieldUI.java index e911508..46451aa 100644 --- a/src/main/java/mdlaf/components/textfield/MaterialTextFieldUI.java +++ b/src/main/java/mdlaf/components/textfield/MaterialTextFieldUI.java @@ -1,24 +1,37 @@ +/* + * MIT License + * Copyright (c) 2018 atharva washimkar + * Copyright (c) 2019 Vincent Palazzo vincenzopalazzodev@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 + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package mdlaf.components.textfield; import mdlaf.utils.MaterialDrawingUtils; -import mdlaf.utils.MaterialFonts; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.BorderFactory; -import javax.swing.JComponent; -import javax.swing.JTextField; -import javax.swing.KeyStroke; -import javax.swing.UIManager; + +import javax.swing.*; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicTextFieldUI; import java.awt.Color; import java.awt.Graphics; -import java.awt.Toolkit; -import java.awt.event.ActionEvent; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; -import java.awt.event.KeyEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; @@ -47,18 +60,15 @@ public static ComponentUI createUI(JComponent c) { } @Override - /** - * This method not override because non paint correct in the JFileChooser - * @fixed by https://github.com/vincenzopalazzo - */ public void installUI(JComponent c) { super.installUI(c); + } @Override protected void installDefaults() { super.installDefaults(); - installMyDefaults(); + installMaterialDefault(); } @Override @@ -80,24 +90,11 @@ protected void uninstallListeners() { super.uninstallListeners(); } - private void installMyDefaults() { - this.activeBackground = UIManager.getColor("TextField.selectionBackground"); - this.activeForeground = UIManager.getColor("TextField.selectionForeground"); - this.inactiveBackground = UIManager.getColor("TextField.inactiveBackground"); - this.inactiveForeground = UIManager.getColor("TextField.inactiveForeground"); - getComponent().setFont(MaterialFonts.REGULAR); - - getComponent().setSelectionColor(getComponent().hasFocus() && getComponent().isEnabled() ? activeBackground : inactiveBackground); - getComponent().setSelectedTextColor(getComponent().hasFocus() && getComponent().isEnabled() ? activeForeground : inactiveForeground); - getComponent().setForeground(getComponent().hasFocus() && getComponent().isEnabled() ? activeForeground : inactiveForeground); - getComponent().setBorder(UIManager.getBorder("TextField.border")); - } @Override protected void paintBackground(Graphics g) { super.paintBackground(MaterialDrawingUtils.getAliasedGraphics(g)); } - @Override public void focusGained(FocusEvent e) { changeColorOnFocus(true); @@ -108,100 +105,7 @@ public void focusLost(FocusEvent e) { changeColorOnFocus(false); } - private void changeColorOnFocus(boolean hasFocus) { - JTextField c = (JTextField) getComponent(); - /*c.setSelectionColor(hasFocus ? activeBackground : inactiveBackground); - c.setForeground(hasFocus ? activeForeground : inactiveForeground); - c.setSelectedTextColor(hasFocus ? activeForeground : inactiveForeground);*/ - if(hasFocus && (activeBackground != null) && (activeForeground != null)){ - c.setSelectionColor(activeBackground); - c.setForeground(activeForeground); - c.setSelectedTextColor(activeForeground); - } - - if(!hasFocus && (inactiveBackground != null) && (inactiveForeground != null)){ - c.setSelectionColor(inactiveBackground); - c.setForeground(inactiveForeground); - c.setSelectedTextColor(inactiveForeground); - } - c.paint(c.getGraphics()); - } - - @Override - protected void installKeyboardActions() { - super.installKeyboardActions(); - - Action selectAll = new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - if(getComponent() != null){ - getComponent().selectAll(); - } - } - }; - - Action delete = new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - if (getComponent().getSelectedText() != null) { - int pos = getComponent().getCaretPosition() - 1; - - if (pos >= 0) { - getComponent().select(pos, pos + 1); - getComponent().replaceSelection(""); - } - } else { - getComponent().replaceSelection(""); - } - } - }; - - Action left = new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - if(getComponent() != null){ - getComponent().setCaretPosition(Math.max(0, getComponent().getCaretPosition() - 1)); - } - } - }; - - Action right = new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - if(getComponent() != null){ - getComponent().setCaretPosition(Math.min(getComponent().getText().length(), getComponent().getCaretPosition() + 1)); - } - } - }; - - Action enter = new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - if(getComponent() != null){ - ((JTextField) getComponent()).postActionEvent(); - } - } - }; - - // note getMenuShortcutKeyMask() is deprecated in Java 10 - change to getMenuShortcutKeyMaskEx() - getComponent().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_A, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "selectAll"); - getComponent().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), "delete"); - getComponent().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), "left"); - getComponent().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), "right"); - getComponent().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enter"); - - getComponent().getActionMap().put("selectAll", selectAll); - getComponent().getActionMap().put("delete", delete); - getComponent().getActionMap().put("left", left); - getComponent().getActionMap().put("right", right); - getComponent().getActionMap().put("enter", enter); - } - @Override - /** - *This method drive a line button on JTextField - * @fixed by https://github.com/vincenzopalazzo - */ public void paintSafely(Graphics g) { JTextField c = (JTextField) getComponent(); super.paintSafely(g); @@ -219,26 +123,74 @@ public void paintSafely(Graphics g) { @Override public void propertyChange(PropertyChangeEvent pce) { super.propertyChange(pce); - + if(getComponent() == null){ + return; + } if (pce.getPropertyName().equals("selectionColor")) { Color newColor = (Color) pce.getNewValue(); - if (!newColor.equals(activeBackground) && !newColor.equals(inactiveBackground)) { - this.activeBackground = newColor; - getComponent().repaint(); - } + logicForPropertyChange(newColor, false); } if (pce.getPropertyName().equals("selectedTextColor")) { Color newColor = (Color) pce.getNewValue(); - if (!newColor.equals(activeForeground) && !newColor.equals(inactiveForeground)) { - this.activeForeground = newColor; - getComponent().repaint(); - } + logicForPropertyChange(newColor, true); } if (pce.getPropertyName().equals("background")) { getComponent().repaint(); } + } + + protected void logicForChangeColorOnFocus(JComponent component, Color background, Color foreground){ + if(background == null || foreground == null){ + throw new IllegalArgumentException("Argument function null"); + } + JTextField textField = (JTextField) component; + textField.setSelectionColor(background); + textField.setForeground(foreground); + textField.setSelectedTextColor(foreground); + } + + protected void logicForPropertyChange(Color newColor, boolean isForeground){ + if(newColor == null){ + throw new IllegalArgumentException("The inpur argument is null"); + } + if (isForeground && !newColor.equals(activeForeground) && !newColor.equals(inactiveForeground)) { + this.activeForeground = newColor; + getComponent().repaint(); + } + if (!isForeground && !newColor.equals(activeBackground) && !newColor.equals(inactiveBackground)) { + this.activeBackground = newColor; + getComponent().repaint(); + } + } + + protected void installMaterialDefault() { + this.activeBackground = UIManager.getColor("TextField.selectionBackground"); + this.activeForeground = UIManager.getColor("TextField.selectionForeground"); + this.inactiveBackground = UIManager.getColor("TextField.inactiveBackground"); + this.inactiveForeground = UIManager.getColor("TextField.inactiveForeground"); + getComponent().setFont(UIManager.getFont("TextField.font")); + getComponent().setSelectionColor(getComponent().hasFocus() && getComponent().isEnabled() ? activeBackground : inactiveBackground); + getComponent().setSelectedTextColor(getComponent().hasFocus() && getComponent().isEnabled() ? activeForeground : inactiveForeground); + getComponent().setForeground(getComponent().hasFocus() && getComponent().isEnabled() ? activeForeground : inactiveForeground); + getComponent().setBorder(UIManager.getBorder("TextField.border")); } + protected void changeColorOnFocus(boolean hasFocus) { + JTextField c = (JTextField) getComponent(); + if(c == null){ + return; + } + if(hasFocus && (activeBackground != null) && (activeForeground != null)){ + logicForChangeColorOnFocus(c, activeBackground, activeForeground); + } + + if(!hasFocus && (inactiveBackground != null) && (inactiveForeground != null)){ + logicForChangeColorOnFocus(c, inactiveBackground, inactiveForeground); + } + if(c.getGraphics() != null){ + c.paint(c.getGraphics()); + } + } } \ No newline at end of file diff --git a/src/main/java/mdlaf/components/textpane/MaterialTextPaneUI.java b/src/main/java/mdlaf/components/textpane/MaterialTextPaneUI.java index 85cd9ad..62fabed 100644 --- a/src/main/java/mdlaf/components/textpane/MaterialTextPaneUI.java +++ b/src/main/java/mdlaf/components/textpane/MaterialTextPaneUI.java @@ -1,21 +1,51 @@ +/* + * MIT License + * + * Copyright (c) 2018-2019 atharva washimkar, + * Copyright (c) 2019 Vincent Palazzo vincenzopalazzodev@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 + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package mdlaf.components.textpane; -import javax.swing.JComponent; +import javax.swing.*; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicTextPaneUI; /** * @author https://github.com/vincenzopalazzo */ - public class MaterialTextPaneUI extends BasicTextPaneUI { - public static ComponentUI createUI (JComponent c) { - return new MaterialTextPaneUI (); + + @SuppressWarnings({"MethodOverridesStaticMethodOfSuperclass", "UnusedDeclaration"}) + public static ComponentUI createUI(JComponent c) { + return new MaterialTextPaneUI(); } @Override - public void installUI (JComponent c) { - super.installUI (c); + public void installUI(JComponent c) { + super.installUI(c); + + c.setBackground(UIManager.getColor("TextPane.background")); + c.setForeground(UIManager.getColor("TextPane.foreground")); + c.setBorder(UIManager.getBorder("TextPane.border")); + c.setFont(UIManager.getFont("TextPane.font")); } } diff --git a/src/main/java/mdlaf/utils/MaterialBorders.java b/src/main/java/mdlaf/utils/MaterialBorders.java index 55ca9c1..7d58242 100644 --- a/src/main/java/mdlaf/utils/MaterialBorders.java +++ b/src/main/java/mdlaf/utils/MaterialBorders.java @@ -4,14 +4,18 @@ import javax.swing.BorderFactory; import javax.swing.border.Border; -import java.awt.Color; +import java.awt.*; public class MaterialBorders { public static final Border LIGHT_LINE_BORDER = BorderFactory.createLineBorder (MaterialColors.GRAY_200, 1); - - public static final Border LIGHT_SHADOW_BORDER = new DropShadowBorder (Color.BLACK, 0, 4, 0.3f, 12, true, true, true, true); - public static final Border DEFAULT_SHADOW_BORDER = new DropShadowBorder (Color.BLACK, 5, 5, 0.3f, 12, true, true, true, true); + public static final Border LIGHT_SHADOW_BORDER = + new DropShadowBorder (Color.BLACK, 0, 4, 0.3f, 12, + true, true, true, true); + public static final Border DEFAULT_SHADOW_BORDER = + new DropShadowBorder (Color.BLACK, 5, 5, 0.3f, 12, + true, true, true, true); private MaterialBorders () {} + } diff --git a/src/main/java/mdlaf/utils/MaterialColors.java b/src/main/java/mdlaf/utils/MaterialColors.java index 2222652..a85daa1 100644 --- a/src/main/java/mdlaf/utils/MaterialColors.java +++ b/src/main/java/mdlaf/utils/MaterialColors.java @@ -261,6 +261,31 @@ public class MaterialColors { public static final Color BLACK = new Color (0, 0, 0); public static final Color WHITE = new Color (255, 255, 255); + //Cosmo color + public static final Color DARKLY_STRONG_BLUE = new Color(40, 65, 91); + public static final Color DARKLY_BLUE = new Color(55, 90, 127); + public static final Color COSMO_STRONG_BLUE = new Color(25, 103, 190); + public static final Color COSMO_BLUE = new Color(39, 128, 227); + public static final Color COSMO_LIGTH_BLUE = new Color(195, 219, 247); + public static final Color DARKLY_RED = new Color(231, 76, 60); + public static final Color COSMO_RED = new Color(255, 0, 57); + public static final Color COSMO_LIGHT_RED = new Color(255, 184, 200); + public static final Color COSMO_PURPLE = new Color(153, 84, 187); + public static final Color COSMO_LIGHT_PURPLE = new Color(226, 207, 236); + public static final Color DARKLY_ORANGE = new Color(243, 156, 18); + public static final Color COSMO_ORANGE = new Color(255, 117, 24); + public static final Color COSMO_LIGHT_ORANGE = new Color(255, 216, 190); + public static final Color DARKLY_STRONG_GREEN = new Color(0, 112, 83); + public static final Color DARKLY_GREEN = new Color(0, 188, 140); + public static final Color COSMO_GREEN = new Color(61, 176, 23); + public static final Color COSMO_LIGHT_GREEN = new Color(201, 235, 190); + public static final Color COSMO_LIGTH_GRAY = new Color(248, 249, 250); + public static final Color COSMO_MEDIUM_GRAY = new Color(218, 218, 218); + public static final Color COSMO_STRONG_GRAY = new Color(199, 200, 200); + public static final Color COSMO_DARK_GRAY = new Color(199, 200, 200); + public static final Color DARKLY_GRAY = new Color(173, 181, 189); + public static final Color COSMO_BLACK = new Color(55, 58, 60); + private MaterialColors () {} public static Color bleach (Color color, float amount) { diff --git a/src/main/java/mdlaf/utils/MaterialImages.java b/src/main/java/mdlaf/utils/MaterialImages.java index e174145..27c8277 100644 --- a/src/main/java/mdlaf/utils/MaterialImages.java +++ b/src/main/java/mdlaf/utils/MaterialImages.java @@ -10,6 +10,7 @@ public class MaterialImages { public static final BufferedImage RIGHT_ARROW = loadImg ("/imgs/right_arrow.png"); public static final BufferedImage DOWN_ARROW = loadImg ("/imgs/down_arrow.png"); public static final BufferedImage UP_ARROW = loadImg ("/imgs/up_arrow.png"); + public static final BufferedImage LEFT_ARROW = loadImg ("/imgs/left_arrow.png"); public static final BufferedImage PAINTED_CHECKED_BOX = loadImg ("/imgs/painted_checked_box.png"); public static final BufferedImage OUTLINED_CHECKED_BOX = loadImg ("/imgs/outlined_checked_box.png"); public static final BufferedImage UNCHECKED_BOX = loadImg ("/imgs/unchecked_box.png"); diff --git a/src/main/resources/imgs/left_arrow.png b/src/main/resources/imgs/left_arrow.png new file mode 100755 index 0000000..77b9a21 Binary files /dev/null and b/src/main/resources/imgs/left_arrow.png differ