Skip to content

Commit 6823f3b

Browse files
authored
Merge pull request atarw#82 from vincenzopalazzo/workingonversion1.0
Create version 1.0 BETA
2 parents 31e6bb3 + fea9194 commit 6823f3b

21 files changed

+928
-534
lines changed

demo/Demo-Swing-set3.tar

7.29 MB
Binary file not shown.

src/main/java/mdlaf/MaterialLookAndFeel.java

Lines changed: 351 additions & 159 deletions
Large diffs are not rendered by default.

src/main/java/mdlaf/animation/MaterialUIStaticMovement.java

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2019 Vincent Palazzo vincenzopalazzodev@gmail.com
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
124
package mdlaf.animation;
225

326
import javax.swing.*;
@@ -24,16 +47,11 @@ public MaterialUIStaticMovement(Color before, Color after, Color strongOnClick)
2447

2548
@Override
2649
public void mouseClicked(MouseEvent e) {
27-
/*For effect click, need create a timer ?*/
28-
/* if(e == null){
29-
throw new IllegalArgumentException("MouseEvent null");
30-
}
31-
setColorComponent(e, after);*/
50+
// do nothing
3251
}
3352

3453
@Override
3554
public void mousePressed(MouseEvent e) {
36-
/*For effect click, need create a timer ?*/
3755
if(e == null){
3856
throw new IllegalArgumentException("MouseEvent null");
3957
}
@@ -42,7 +60,6 @@ public void mousePressed(MouseEvent e) {
4260

4361
@Override
4462
public void mouseReleased(MouseEvent e) {
45-
/*For effect click, need create a timer ?*/
4663
if(e == null){
4764
throw new IllegalArgumentException("MouseEvent null");
4865
}
@@ -65,7 +82,7 @@ public void mouseExited(MouseEvent e) {
6582
setColorComponent(e, before);
6683
}
6784

68-
/***
85+
/**
6986
* This is service method for recicle code
7087
*/
7188
private void setColorComponent(MouseEvent e, Color colorComponent){

src/main/java/mdlaf/animation/MaterialUITimer.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/*
22
* MIT License
33
*
4-
* Copyright (c) 2018 atharva washimkar, Vincent Palazzo
4+
* Copyright (c) 2018 atharva washimkar
5+
* Copyright (c) 2019 Vincent Palazzo vincenzopalazzodev@gmail.com
56
*
67
* Permission is hereby granted, free of charge, to any person obtaining a copy
78
* of this software and associated documentation files (the "Software"), to deal
@@ -27,7 +28,7 @@
2728
import java.awt.Color;
2829
import java.awt.event.*;
2930

30-
public class MaterialUITimer implements MouseListener, ActionListener, MouseMotionListener {
31+
class MaterialUITimer implements MouseListener, ActionListener, MouseMotionListener {
3132

3233
private Color from, to;
3334
private boolean forward;
@@ -60,7 +61,6 @@ protected MaterialUITimer(JComponent component, Color to, int steps, int interva
6061
this.steps = steps;
6162

6263
this.component = component;
63-
this.component.addMouseListener(this);
6464
timer = new Timer(interval, this);
6565
component.setBackground(from);
6666
}
@@ -90,6 +90,9 @@ public void mousePressed(MouseEvent me) {
9090
}
9191
alpha = steps - 1;
9292
forward = false;
93+
if(timer.isRunning()){
94+
timer.stop();
95+
}
9396
timer.start();
9497

9598
alpha = 0;
@@ -99,19 +102,22 @@ public void mousePressed(MouseEvent me) {
99102

100103
@Override
101104
public void mouseReleased(MouseEvent me) {
102-
105+
//do nothing
103106
}
104107

105108
@Override
106109
public void mouseClicked(MouseEvent me) {
107-
110+
//do nothing
108111
}
109112

110113
@Override
111114
public void mouseExited(MouseEvent me) {
112115
if (!me.getComponent().isEnabled()) {
113116
return;
114117
}
118+
if(timer.isRunning()){
119+
timer.stop();
120+
}
115121
alpha = steps - 1;
116122
forward = false;
117123
timer.start();
@@ -124,6 +130,9 @@ public void mouseEntered(MouseEvent me) {
124130
}
125131
alpha = 0;
126132
forward = true;
133+
if(timer.isRunning()){
134+
timer.stop();
135+
}
127136
timer.start();
128137
}
129138

@@ -138,7 +147,9 @@ public void actionPerformed(ActionEvent ae) {
138147
}
139148

140149
if (alpha == steps + 1 || alpha == -1) {
141-
timer.stop();
150+
if(timer.isRunning()){
151+
timer.stop();
152+
}
142153
}
143154
}
144155

src/main/java/mdlaf/components/button/MaterialButtonUI.java

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,64 @@
22

33
import mdlaf.animation.MaterialUIMovement;
44
import mdlaf.utils.MaterialDrawingUtils;
5-
import javax.swing.AbstractButton;
6-
import javax.swing.JComponent;
7-
import javax.swing.UIManager;
5+
6+
import javax.swing.*;
87
import javax.swing.plaf.ComponentUI;
9-
import javax.swing.plaf.basic.BasicButtonUI;
8+
import javax.swing.plaf.metal.MetalButtonUI;
109
import java.awt.*;
1110

1211
/**
1312
* @contributor https://github.com/vincenzopalazzo
1413
*/
15-
16-
public class MaterialButtonUI extends BasicButtonUI {
17-
14+
public class MaterialButtonUI extends MetalButtonUI {
1815
public static ComponentUI createUI(final JComponent c) {
1916
return new MaterialButtonUI();
2017
}
2118

19+
private Color foreground;
20+
private Color background;
21+
2222
@Override
2323
public void installUI(JComponent c) {
2424
super.installUI(c);
2525

2626
AbstractButton button = (AbstractButton) c;
2727
button.setOpaque(UIManager.getBoolean("Button.opaque"));
2828
button.setBorder(UIManager.getBorder("Button.border"));
29-
button.setBackground(UIManager.getColor("Button.background"));
30-
button.setForeground(UIManager.getColor("Button.foreground"));
29+
foreground = UIManager.getColor("Button.foreground");
30+
background = UIManager.getColor("Button.background");
31+
button.setBackground(background);
32+
button.setForeground(foreground);
3133
button.setFont(UIManager.getFont("Button.font"));
3234
button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
3335
button.addMouseListener(MaterialUIMovement.getMovement(button, UIManager.getColor("Button.mouseHoverColor")));
36+
button.setFocusable(UIManager.getBoolean("Button.focusable"));
3437
}
3538

3639
@Override
3740
public void paint(Graphics g, JComponent c) {
38-
AbstractButton b = (AbstractButton) c;
39-
g = MaterialDrawingUtils.getAliasedGraphics(g);
41+
JButton b = (JButton) c;
4042
if (b.isContentAreaFilled()) {
4143
paintBackground(MaterialDrawingUtils.getAliasedGraphics(g), b);
4244
}
45+
4346
super.paint(MaterialDrawingUtils.getAliasedGraphics(g), c);
4447
}
45-
//Fix to #73 border were pixeled, fixde by https://github.com/vincenzopalazzo
48+
4649
private void paintBackground(Graphics g, JComponent c) {
47-
//g.setColor(c.getBackground());
48-
//g.fillRoundRect(0, 0, c.getWidth(), c.getHeight(), 7, 7);
4950
Graphics2D graphics2D = (Graphics2D) g;
5051
graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
5152
g = graphics2D;
5253
g.setColor(c.getBackground());
5354
g.fillRoundRect(0, 0, c.getWidth(), c.getHeight(), 7, 7);
55+
56+
paintStateButton(c, g);
5457
}
5558

5659
@Override
57-
protected void paintButtonPressed(Graphics g, AbstractButton b) {
58-
super.paintButtonPressed(g, b);
60+
protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect, Rectangle textRect, Rectangle iconRect) {
61+
super.paintFocus(g, b, viewRect, textRect, iconRect);
62+
driveLine(g, (JButton) b);
5963
}
6064

6165
@Override
@@ -64,5 +68,25 @@ public void update(Graphics g, JComponent c) {
6468
c.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
6569
}
6670

71+
@Override
72+
protected void paintButtonPressed(Graphics g, AbstractButton b) {
73+
g.fillRoundRect(0, 0, b.getWidth(), b.getHeight(), 7, 7);
74+
}
75+
76+
protected void driveLine(Graphics g, JButton b){
77+
g.setColor(UIManager.getColor("Button[focus].color"));
78+
g.drawLine(20 , (b.getHeight() / 2) + 10, b.getWidth() - 20, (b.getHeight() / 2) + 10);
79+
}
80+
81+
protected void paintStateButton(JComponent component, Graphics graphics) {
82+
if(component == null){
83+
throw new IllegalArgumentException("Input null");
84+
}
85+
JButton b = (JButton) component;
86+
if(b.isDefaultButton()){
87+
driveLine(graphics, b);
88+
}
89+
}
90+
6791

6892
}

src/main/java/mdlaf/components/checkbox/MaterialCheckBoxUI.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22

33
import mdlaf.utils.MaterialDrawingUtils;
44

5-
import javax.swing.JCheckBox;
6-
import javax.swing.JComponent;
7-
import javax.swing.UIManager;
5+
import javax.swing.*;
86
import javax.swing.plaf.ComponentUI;
97
import javax.swing.plaf.basic.BasicCheckBoxUI;
108
import java.awt.*;
119

12-
//TODO cambio colore icone combo box
1310
public class MaterialCheckBoxUI extends BasicCheckBoxUI {
1411

1512
public static ComponentUI createUI (JComponent c) {
@@ -26,8 +23,7 @@ public void installUI (JComponent c) {
2623
checkBox.setForeground (UIManager.getColor ("CheckBox.foreground"));
2724
checkBox.setIcon (UIManager.getIcon ("CheckBox.icon"));
2825
checkBox.setSelectedIcon (UIManager.getIcon ("CheckBox.selectedIcon"));
29-
c.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
30-
26+
checkBox.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
3127
}
3228

3329
@Override

src/main/java/mdlaf/components/checkboxmenuitem/MaterialCheckBoxMenuItemUI.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
/**
1414
* @author https://github.com/vincenzopalazzo
1515
*/
16-
1716
public class MaterialCheckBoxMenuItemUI extends BasicCheckBoxMenuItemUI {
1817

1918
public static ComponentUI createUI (JComponent c) {
@@ -23,6 +22,11 @@ public static ComponentUI createUI (JComponent c) {
2322
@Override
2423
public void installUI (JComponent c) {
2524
super.installUI (c);
25+
26+
c.setBackground(UIManager.getColor("CheckBoxMenuItem.background"));
27+
c.setForeground(UIManager.getColor("CheckBoxMenuItem.foreground"));
28+
c.setBorder(UIManager.getBorder("CheckBoxMenuItem.border"));
29+
c.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
2630
}
2731

2832
@Override
@@ -33,7 +37,6 @@ public void paint (Graphics g, JComponent c) {
3337
@Override
3438
protected void paintMenuItem (Graphics g, JComponent c, Icon checkIcon, Icon arrowIcon, Color background, Color foreground, int defaultTextIconGap) {
3539
JCheckBoxMenuItem checkBoxMenuItem = (JCheckBoxMenuItem) c;
36-
c.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
3740
if (checkBoxMenuItem.isSelected ()) {
3841
super.paintMenuItem (MaterialDrawingUtils.getAliasedGraphics (g), checkBoxMenuItem, UIManager.getIcon ("CheckBoxMenuItem.selectedCheckIcon"), arrowIcon, background, foreground, defaultTextIconGap);
3942
return;

src/main/java/mdlaf/components/combobox/MaterialComboBoxRenderer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ public Component getListCellRendererComponent (JList list, Object value, int ind
1616
component.setBorder (BorderFactory.createEmptyBorder (5, 5, 5, 5));
1717
component.setForeground (UIManager.getColor ("ComboBox.foreground"));
1818
component.setBackground (isSelected || cellHasFocus ?
19-
UIManager.getColor ("ComboBox.selectedInDropDownBackground") :
20-
UIManager.getColor ("ComboBox.background"));
19+
UIManager.getColor("ComboBox.selectedInDropDownBackground") :
20+
UIManager.getColor("ComboBox.background"));
2121

2222
return component;
2323
}
2424

2525

26+
2627
}

src/main/java/mdlaf/components/combobox/MaterialComboBoxUI.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,12 @@
44
import mdlaf.utils.MaterialBorders;
55
import mdlaf.utils.MaterialDrawingUtils;
66
import mdlaf.utils.MaterialManagerListener;
7-
import javax.swing.Icon;
8-
import javax.swing.JButton;
9-
import javax.swing.JComboBox;
10-
import javax.swing.JComponent;
11-
import javax.swing.SwingConstants;
12-
import javax.swing.UIManager;
7+
8+
import javax.swing.*;
139
import javax.swing.plaf.ComponentUI;
1410
import javax.swing.plaf.basic.BasicArrowButton;
1511
import javax.swing.plaf.basic.BasicComboBoxUI;
16-
import java.awt.Cursor;
17-
import java.awt.Graphics;
12+
import java.awt.*;
1813

1914
/**
2015
* @contributor https://github.com/vincenzopalazzo
@@ -35,7 +30,6 @@ public void installUI (JComponent c) {
3530
comboBox.setForeground (UIManager.getColor ("ComboBox.foreground"));
3631
comboBox.setBorder (UIManager.getBorder ("ComboBox.border"));
3732
comboBox.setLightWeightPopupEnabled (true);
38-
comboBox.setRenderer (new MaterialComboBoxRenderer ());
3933
comboBox.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
4034
}
4135

@@ -64,5 +58,8 @@ public void paint (Graphics g, JComponent c) {
6458
super.paint (MaterialDrawingUtils.getAliasedGraphics (g), c);
6559
}
6660

67-
61+
@Override
62+
protected ListCellRenderer createRenderer() {
63+
return new MaterialComboBoxRenderer();
64+
}
6865
}

0 commit comments

Comments
 (0)