diff --git a/change.txt b/change.txt index f596e76..914f8f6 100644 --- a/change.txt +++ b/change.txt @@ -1,8 +1,3 @@ ## Fixing -- Fixed problem paint JLabel -- Fixed problem to JTable paint custom color into header -- Fixed problem into JTree background and foreground color -- Fixed problem into JTaskPane color background was strange -- Fixed position line into JTabbledPane -- Fixed color strange into JComboBox -- Fixed color disable text JCheckBox +- Added support to JSplitPane +- Fixed issue jToggleButton disabled diff --git a/libs/material-ui-swing-1.0[beta].jar b/libs/material-ui-swing-1.0[beta].jar index aa70153..055755b 100644 Binary files a/libs/material-ui-swing-1.0[beta].jar and b/libs/material-ui-swing-1.0[beta].jar differ diff --git a/src/MaterialUISwingDemo.java b/src/MaterialUISwingDemo.java index 4075887..25eb420 100644 --- a/src/MaterialUISwingDemo.java +++ b/src/MaterialUISwingDemo.java @@ -488,6 +488,10 @@ public void actionPerformed(ActionEvent e) { disabledCheckBox.setEnabled(false); panel4.add(disabledCheckBox); + JRadioButton radioDisabled = new JRadioButton("radio disabled"); + radioDisabled.setEnabled(false); + panel4.add(radioDisabled); + tp.addTab("Panel 4", panel4); frame.pack(); frame.setVisible(true); diff --git a/src/mdlaf/MaterialLookAndFeel.java b/src/mdlaf/MaterialLookAndFeel.java index 3b29e69..d2054de 100644 --- a/src/mdlaf/MaterialLookAndFeel.java +++ b/src/mdlaf/MaterialLookAndFeel.java @@ -49,6 +49,7 @@ import mdlaf.components.separator.MaterialSeparatorUI; import mdlaf.components.slider.MaterialSliderUI; import mdlaf.components.spinner.MaterialSpinnerUI; +import mdlaf.components.splitpane.MaterialSplitPaneUI; import mdlaf.components.tabbedpane.MaterialTabbedPaneUI; import mdlaf.components.table.MaterialTableHeaderUI; import mdlaf.components.table.MaterialTableUI; @@ -60,7 +61,6 @@ import mdlaf.components.toolbar.MaterialToolBarUI; import mdlaf.components.tooltip.MaterialToolTipUI; import mdlaf.components.tree.MaterialTreeUI; -import mdlaf.shadows.DropShadowBorder; import mdlaf.utils.*; import sun.awt.SunToolkit; @@ -116,6 +116,8 @@ public class MaterialLookAndFeel extends MetalLookAndFeel { private static final String editorPane = MaterialEditorPaneUI.class.getCanonicalName(); private static final String rootPane = MaterialRootPaneUI.class.getCanonicalName(); private static final String optionPaneUI = MaterialOptionPaneUI.class.getCanonicalName(); + //TODO not allineated this compoent with master + private static final String splitPaneUI = MaterialSplitPaneUI.class.getCanonicalName(); public MaterialLookAndFeel() { try { @@ -194,6 +196,7 @@ protected void initClassDefaults(UIDefaults table) { table.put("InternalFrameUI", internalFrameUI); table.put("RootPaneUI", rootPane); table.put("OptionPaneUI", optionPaneUI); + table.put("SplitPaneUI", splitPaneUI); // java swingx table.put("swingx/TaskPaneUI", taskPaneUI); @@ -284,6 +287,7 @@ protected void initComponentDefaults(UIDefaults table) { table.put("RadioButton.foreground", Color.BLACK); table.put("RadioButton.icon", new ImageIcon(MaterialImageFactory.getInstance().getImage(MaterialImageFactory.RADIO_BUTTON_BLACK_OFF))); table.put("RadioButton.selectedIcon", new ImageIcon(MaterialImageFactory.getInstance().getImage(MaterialImageFactory.RADIO_BUTTON_BLACK_ON))); + table.put("RadioButton.disabledText", MaterialColors.COSMO_STRONG_GRAY); table.put("Spinner.font", MaterialFontFactory.getInstance().getFont(MaterialFontFactory.REGULAR)); table.put("Spinner.background", Color.WHITE); @@ -312,15 +316,17 @@ protected void initComponentDefaults(UIDefaults table) { table.put("ScrollPane.font", MaterialFontFactory.getInstance().getFont(MaterialFontFactory.REGULAR)); table.put("Slider.font", MaterialFontFactory.getInstance().getFont(MaterialFontFactory.REGULAR)); - table.put("Slider.background", Color.WHITE); + table.put("Slider.background", MaterialColors.WHITE); table.put("Slider.foreground", MaterialColors.LIGHT_BLUE_400); - table.put("Slider.trackColor", Color.BLACK); + table.put("Slider.trackColor", MaterialColors.BLACK); + table.put("Slider[halo].color", MaterialColors.bleach (MaterialColors.LIGHT_BLUE_400, 0.5f)); //TODO new fix 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", MaterialColors.WHITE); table.put("SplitPane.dividerSize", 5); table.put("SplitPaneDivider.border", BorderFactory.createEmptyBorder()); + table.put("SplitPaneDivider.background",MaterialColors.WHITE); table.put("TabbedPane.font", MaterialFontFactory.getInstance().getFont(MaterialFontFactory.REGULAR)); table.put("TabbedPane.background", Color.WHITE); @@ -357,7 +363,9 @@ protected void initComponentDefaults(UIDefaults table) { table.put("ToggleButton.border", BorderFactory.createEmptyBorder()); table.put("ToggleButton.font", MaterialFontFactory.getInstance().getFont(MaterialFontFactory.REGULAR)); table.put("ToggleButton.background", MaterialColors.WHITE); + table.put("ToggleButton.select", MaterialColors.WHITE); table.put("ToggleButton.foreground", MaterialColors.BLACK); + table.put("ToggleButton.disabledText", MaterialColors.COSMO_STRONG_GRAY); table.put("ToggleButton.icon", new ImageIcon(MaterialImageFactory.getInstance().getImage(MaterialImageFactory.TOGGLE_BUTTON_BLACK_OFF))); table.put("ToggleButton.selectedIcon", new ImageIcon(MaterialImageFactory.getInstance().getImage(MaterialImageFactory.TOGGLE_BUTTON_BLACK_ON))); @@ -402,14 +410,14 @@ protected void initComponentDefaults(UIDefaults table) { table.put("TextPane.selectionBackground", MaterialColors.LIGHT_BLUE_200); table.put("TextPane.inactiveForeground", MaterialColors.GRAY_500); table.put("TextPane.font", MaterialFontFactory.getInstance().getFont(MaterialFontFactory.ITALIC)); - table.put("TextPane.focusInputMap", multilineInputMap); + //table.put("TextPane.focusInputMap", multilineInputMap); table.put("EditorPane.border", MaterialBorders.LIGHT_LINE_BORDER); table.put("EditorPane.background", MaterialColors.GRAY_50); table.put("EditorPane.selectionBackground", MaterialColors.LIGHT_BLUE_200); table.put("EditorPane.inactiveForeground", MaterialColors.GRAY_500); table.put("EditorPane.font", MaterialFontFactory.getInstance().getFont(MaterialFontFactory.REGULAR)); - table.put("EditorPane.focusInputMap", multilineInputMap); + //table.put("EditorPane.focusInputMap", multilineInputMap); table.put("Separator.background", MaterialColors.GRAY_300); table.put("Separator.foreground", MaterialColors.GRAY_300); @@ -425,7 +433,7 @@ protected void initComponentDefaults(UIDefaults table) { 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("TextField.focusInputMap", fieldInputMap); //deprecated table.put("PasswordField.background", MaterialColors.GRAY_100); table.put("PasswordField.foreground", MaterialColors.BLACK); @@ -434,7 +442,7 @@ protected void initComponentDefaults(UIDefaults table) { 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); + //table.put("PasswordField.focusInputMap", fieldInputMap); table.put("TitledBorder.border", MaterialBorders.LIGHT_LINE_BORDER); table.put("TitledBorder.font", MaterialFontFactory.getInstance().getFont(MaterialFontFactory.MEDIUM)); @@ -554,6 +562,7 @@ public static int getFocusAcceleratorKeyMask() { } /*Shortcut for filed input*/ + @Deprecated Object fieldInputMap = new UIDefaults.LazyInputMap(new Object[]{ "ctrl C", DefaultEditorKit.copyAction, "ctrl V", DefaultEditorKit.pasteAction, @@ -598,6 +607,7 @@ public static int getFocusAcceleratorKeyMask() { /*Shortcut for multiline input*/ + @Deprecated Object multilineInputMap = new UIDefaults.LazyInputMap(new Object[]{ "ctrl C", DefaultEditorKit.copyAction, "ctrl V", DefaultEditorKit.pasteAction, diff --git a/src/mdlaf/components/checkbox/MaterialCheckBoxUI.java b/src/mdlaf/components/checkbox/MaterialCheckBoxUI.java index c8db174..7d4a8b6 100644 --- a/src/mdlaf/components/checkbox/MaterialCheckBoxUI.java +++ b/src/mdlaf/components/checkbox/MaterialCheckBoxUI.java @@ -3,9 +3,7 @@ import mdlaf.utils.MaterialDrawingUtils; import javax.swing.*; import javax.swing.plaf.ComponentUI; -import javax.swing.plaf.basic.BasicCheckBoxUI; import javax.swing.plaf.metal.MetalCheckBoxUI; -import javax.swing.plaf.metal.MetalLabelUI; import java.awt.*; //TODO cambio colore icone combo box diff --git a/src/mdlaf/components/radiobutton/MaterialRadioButtonUI.java b/src/mdlaf/components/radiobutton/MaterialRadioButtonUI.java index 83150c0..93037c8 100644 --- a/src/mdlaf/components/radiobutton/MaterialRadioButtonUI.java +++ b/src/mdlaf/components/radiobutton/MaterialRadioButtonUI.java @@ -6,14 +6,14 @@ import javax.swing.JRadioButton; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; -import javax.swing.plaf.basic.BasicRadioButtonUI; +import javax.swing.plaf.metal.MetalRadioButtonUI; import java.awt.*; /* * Contributed by https://github.com/downToHell * */ //TODO cambio colore del radio button. -public class MaterialRadioButtonUI extends BasicRadioButtonUI { +public class MaterialRadioButtonUI extends MetalRadioButtonUI { public static ComponentUI createUI (JComponent c) { return new MaterialRadioButtonUI (); @@ -22,7 +22,6 @@ public static ComponentUI createUI (JComponent c) { @Override public void installUI (JComponent c) { super.installUI (c); - JRadioButton radioButton = (JRadioButton) c; radioButton.setFont (UIManager.getFont ("RadioButton.font")); radioButton.setBackground (UIManager.getColor ("RadioButton.background")); @@ -36,4 +35,9 @@ public void installUI (JComponent c) { public void paint (Graphics g, JComponent c) { super.paint (MaterialDrawingUtils.getAliasedGraphics (g), c); } + + @Override + protected void paintFocus(Graphics g, Rectangle t, Dimension d) { + //do nothing + } } \ No newline at end of file diff --git a/src/mdlaf/components/slider/MaterialSliderUI.java b/src/mdlaf/components/slider/MaterialSliderUI.java index 37f3d2d..3b97a51 100644 --- a/src/mdlaf/components/slider/MaterialSliderUI.java +++ b/src/mdlaf/components/slider/MaterialSliderUI.java @@ -61,7 +61,8 @@ public void paintThumb (Graphics g) { int cy = thumbRect.y + thumbRect.height / 2; if (isDragging ()) { - g.setColor (MaterialColors.bleach (slider.getForeground (), 0.5f)); + //g.setColor (MaterialColors.bleach (UIManager.getColor("Slider[halo].color"), 0.5f)); + g.setColor (UIManager.getColor("Slider[halo].color")); drawCircle (g, cx, cy, DRAG_THUMB_RADIUS); } diff --git a/src/mdlaf/components/splitpane/MaterialSplitPaneUI.java b/src/mdlaf/components/splitpane/MaterialSplitPaneUI.java new file mode 100644 index 0000000..15cc89a --- /dev/null +++ b/src/mdlaf/components/splitpane/MaterialSplitPaneUI.java @@ -0,0 +1,52 @@ +package mdlaf.components.splitpane; + +import javax.swing.*; +import javax.swing.plaf.ComponentUI; +import javax.swing.plaf.basic.BasicSplitPaneDivider; +import javax.swing.plaf.basic.BasicSplitPaneUI; +import javax.swing.plaf.metal.MetalSplitPaneUI; +import java.awt.*; +//TODO sincronize this component with master +/** + * @author https://github.com/vincenzopalazzo + */ +public class MaterialSplitPaneUI extends MetalSplitPaneUI { + + + @SuppressWarnings({"MethodOverridesStaticMethodOfSuperclass", "UnusedDeclaration"}) + public static ComponentUI createUI(JComponent c) { + return new MaterialSplitPaneUI(); + } + + @Override + public void installUI(JComponent c) { + super.installUI(c); + + this.divider.setBackground(UIManager.getColor("SplitPaneDivider.background")); + } + + @Override + public BasicSplitPaneDivider createDefaultDivider() { + return new MaterialSplitPaneDivider(this); + } + + protected class MaterialSplitPaneDivider extends BasicSplitPaneDivider{ + + /** + * Creates an instance of BasicSplitPaneDivider. Registers this + * instance for mouse events and mouse dragged events. + * + * @param ui + */ + public MaterialSplitPaneDivider(BasicSplitPaneUI ui) { + super(ui); + } + + @Override + public void paintAll(Graphics g) { + //g.setColor(UIManager.getColor("SplitPaneDivider.background")); + super.paintAll(g); + } + } + +} diff --git a/src/mdlaf/components/textfield/MaterialTextFieldUI.java b/src/mdlaf/components/textfield/MaterialTextFieldUI.java index 6ee910f..7f866cd 100644 --- a/src/mdlaf/components/textfield/MaterialTextFieldUI.java +++ b/src/mdlaf/components/textfield/MaterialTextFieldUI.java @@ -23,7 +23,10 @@ */ package mdlaf.components.textfield; +import mdlaf.utils.MaterialColors; import mdlaf.utils.MaterialDrawingUtils; +import sun.java2d.SunGraphics2D; + import javax.swing.*; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicTextFieldUI; @@ -40,6 +43,7 @@ public class MaterialTextFieldUI extends BasicTextFieldUI implements FocusListener, PropertyChangeListener { private boolean drawLine; + private Color background; private Color activeBackground; private Color activeForeground; private Color inactiveBackground; @@ -90,6 +94,7 @@ protected void uninstallListeners() { } private void installMyDefaults() { + this.background = UIManager.getColor("TextField.background"); this.activeBackground = UIManager.getColor("TextField.selectionBackground"); this.activeForeground = UIManager.getColor("TextField.selectionForeground"); this.inactiveBackground = UIManager.getColor("TextField.inactiveBackground"); @@ -117,19 +122,15 @@ public void focusLost(FocusEvent e) { changeColorOnFocus(false); } + /** + * Paint line when the component is focused + * @param g + */ @Override public void paintSafely(Graphics g) { - JTextField c = (JTextField) getComponent(); super.paintSafely(g); - 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); - } + paintLine(MaterialColors.LIGHT_BLUE_400, g); } @Override @@ -164,7 +165,7 @@ protected void logicForChangeColorOnFocus(JComponent component, Color background protected void logicForPropertyChange(Color newColor, boolean isForeground){ if(newColor == null){ - throw new IllegalArgumentException("The inpur argument is null"); + throw new IllegalArgumentException("The input argument is null"); } if (isForeground && !newColor.equals(activeForeground) && !newColor.equals(inactiveForeground)) { this.activeForeground = newColor; @@ -192,4 +193,20 @@ protected void changeColorOnFocus(boolean hasFocus) { c.paint(c.getGraphics()); } } + + protected void paintLine(Color color, Graphics graphics){ + if(color == null || graphics == null){ + throw new IllegalArgumentException("Color null"); + } + JTextField c = (JTextField) getComponent(); + + if (drawLine) { + int x = c.getInsets().left; + int y = c.getInsets().top; + int w = c.getWidth() - c.getInsets().left - c.getInsets().right; + graphics.setColor(c.getSelectionColor()); + + graphics.fillRect(x, c.getHeight() - y, w, 1); + } + } } \ No newline at end of file diff --git a/src/mdlaf/components/togglebutton/MaterialToggleButtonUI.java b/src/mdlaf/components/togglebutton/MaterialToggleButtonUI.java index e204714..9830e59 100644 --- a/src/mdlaf/components/togglebutton/MaterialToggleButtonUI.java +++ b/src/mdlaf/components/togglebutton/MaterialToggleButtonUI.java @@ -1,12 +1,12 @@ package mdlaf.components.togglebutton; import mdlaf.utils.MaterialDrawingUtils; +import sun.swing.SwingUtilities2; -import javax.swing.JComponent; -import javax.swing.JToggleButton; -import javax.swing.UIManager; +import javax.swing.*; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicToggleButtonUI; +import javax.swing.plaf.metal.MetalToggleButtonUI; import java.awt.*; /* @@ -15,29 +15,59 @@ //TODO cambio icone del togle button soprattutto il colore public class MaterialToggleButtonUI extends BasicToggleButtonUI { - public static ComponentUI createUI (JComponent c) { - return new MaterialToggleButtonUI (); - } - - @Override - public void installUI (JComponent c) { - super.installUI (c); - - JToggleButton toggleButton = (JToggleButton) c; - toggleButton.setBorder (UIManager.getBorder ("ToggleButton.border")); - toggleButton.setFont (UIManager.getFont ("ToggleButton.font")); - toggleButton.setBackground (UIManager.getColor ("ToggleButton.background")); - toggleButton.setForeground (UIManager.getColor ("ToggleButton.foreground")); - c.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - - if (toggleButton.getIcon () == null && toggleButton.getSelectedIcon () == null) { - toggleButton.setIcon (UIManager.getIcon ("ToggleButton.icon")); - toggleButton.setSelectedIcon (UIManager.getIcon ("ToggleButton.selectedIcon")); - } - } - - @Override - public void paint (Graphics g, JComponent c) { - super.paint (MaterialDrawingUtils.getAliasedGraphics (g), c); - } + public static ComponentUI createUI(JComponent c) { + return new MaterialToggleButtonUI(); + } + + @Override + public void installUI(JComponent c) { + super.installUI(c); + + JToggleButton toggleButton = (JToggleButton) c; + toggleButton.setBorder(UIManager.getBorder("ToggleButton.border")); + toggleButton.setFont(UIManager.getFont("ToggleButton.font")); + toggleButton.setBackground(UIManager.getColor("ToggleButton.background")); + toggleButton.setForeground(UIManager.getColor("ToggleButton.foreground")); + c.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + + if (toggleButton.getIcon() == null && toggleButton.getSelectedIcon() == null) { + toggleButton.setIcon(UIManager.getIcon("ToggleButton.icon")); + toggleButton.setSelectedIcon(UIManager.getIcon("ToggleButton.selectedIcon")); + } + } + + @Override + public void paint(Graphics g, JComponent c) { + super.paint(MaterialDrawingUtils.getAliasedGraphics(g), c); + } + + @Override + protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect, Rectangle textRect, Rectangle iconRect) { + //do nothing + } + + @Override + protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) { + AbstractButton b = (AbstractButton) c; + ButtonModel model = b.getModel(); + FontMetrics fm = SwingUtilities2.getFontMetrics(c, g); + int mnemonicIndex = b.getDisplayedMnemonicIndex(); + + /* Draw the Text */ + if (model.isEnabled()) { + /*** paint the text normally */ + g.setColor(b.getForeground()); + SwingUtilities2.drawStringUnderlineCharAt(c, g, text, mnemonicIndex, + textRect.x + getTextShiftOffset(), + textRect.y + fm.getAscent() + getTextShiftOffset()); + } else { + /*** paint the text disabled ***/ + g.setColor(UIManager.getColor("ToggleButton.disabledText").brighter()); + SwingUtilities2.drawStringUnderlineCharAt(c, g, text, mnemonicIndex, + textRect.x, textRect.y + fm.getAscent()); + g.setColor(UIManager.getColor("ToggleButton.disabledText").darker()); + SwingUtilities2.drawStringUnderlineCharAt(c, g, text, mnemonicIndex, + textRect.x - 1, textRect.y + fm.getAscent() - 1); + } + } }