Skip to content

Commit

Permalink
Added some fix
Browse files Browse the repository at this point in the history
- Added support to JSplitPane
- Fixed issue jToggleButton disabled
  • Loading branch information
vincenzopalazzo committed Jun 9, 2019
1 parent 5f56e98 commit 81fd013
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 58 deletions.
9 changes: 2 additions & 7 deletions change.txt
Original file line number Diff line number Diff line change
@@ -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
Binary file modified libs/material-ui-swing-1.0[beta].jar
Binary file not shown.
4 changes: 4 additions & 0 deletions src/MaterialUISwingDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 17 additions & 7 deletions src/mdlaf/MaterialLookAndFeel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)));

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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));
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions src/mdlaf/components/checkbox/MaterialCheckBoxUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions src/mdlaf/components/radiobutton/MaterialRadioButtonUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand All @@ -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"));
Expand All @@ -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
}
}
3 changes: 2 additions & 1 deletion src/mdlaf/components/slider/MaterialSliderUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
52 changes: 52 additions & 0 deletions src/mdlaf/components/splitpane/MaterialSplitPaneUI.java
Original file line number Diff line number Diff line change
@@ -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);
}
}

}
37 changes: 27 additions & 10 deletions src/mdlaf/components/textfield/MaterialTextFieldUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Loading

0 comments on commit 81fd013

Please sign in to comment.