Skip to content

Commit e626e95

Browse files
authored
Merge pull request #76 from vincenzopalazzo/fixsomeissue
Fixed some issue
2 parents 1af7bd8 + d6c0306 commit e626e95

10 files changed

+325
-207
lines changed

src/main/java/MaterialUISwingDemo.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public void actionPerformed (ActionEvent e) {
188188
class InfoMessage extends AbstractAction{
189189

190190
public InfoMessage() {
191-
putValue(Action.NAME, "Info option pane");
191+
putValue(Action.NAME, "Info option panel");
192192
}
193193

194194
@Override
@@ -208,7 +208,7 @@ public void actionPerformed(ActionEvent e) {
208208
class ErrorMassage extends AbstractAction{
209209

210210
public ErrorMassage() {
211-
putValue(Action.NAME, "Error option pane");
211+
putValue(Action.NAME, "Error option panel");
212212
}
213213

214214
@Override
@@ -228,7 +228,7 @@ public void actionPerformed(ActionEvent e) {
228228
class QuesuionMessage extends AbstractAction{
229229

230230
public QuesuionMessage() {
231-
putValue(Action.NAME, "Info question pane");
231+
putValue(Action.NAME, "Info question panel");
232232
}
233233

234234
@Override
@@ -242,12 +242,13 @@ public void actionPerformed(ActionEvent e) {
242242
buttonQuestion.setAction(new QuesuionMessage());
243243

244244
JButton buttonWarning = new JButton();
245+
buttonWarning.setOpaque(false);
245246
buttonWarning.setBackground(MaterialColors.YELLOW_800);
246247
buttonWarning.addMouseListener(MaterialUIMovement.getMovement(buttonWarning, MaterialColors.YELLOW_500));
247248
class WarningMessage extends AbstractAction {
248249

249250
public WarningMessage() {
250-
putValue(Action.NAME, "Info warning pane");
251+
putValue(Action.NAME, "Info warning panel");
251252
}
252253

253254
@Override

src/main/java/mdlaf/MaterialLookAndFeel.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,13 @@ protected void initComponentDefaults (UIDefaults table) {
158158
table.put ("CheckBox.foreground", Color.BLACK);
159159
table.put ("CheckBox.icon", new ImageIcon (MaterialImages.UNCHECKED_BOX));
160160
table.put ("CheckBox.selectedIcon", new ImageIcon (MaterialImages.PAINTED_CHECKED_BOX));
161-
162161
table.put ("ComboBox.font", MaterialFonts.REGULAR);
163162
table.put ("ComboBox.background", Color.WHITE);
164163
table.put ("ComboBox.foreground", Color.BLACK);
165164
table.put ("ComboBox.border", BorderFactory.createCompoundBorder (MaterialBorders.LIGHT_LINE_BORDER, BorderFactory.createEmptyBorder (0, 5, 0, 0)));
166165
table.put ("ComboBox.buttonBackground", MaterialColors.GRAY_300);
167-
table.put ("ComboBox.selectionBackground", Color.WHITE);
168-
table.put ("ComboBox.selectionForeground", Color.BLACK);
166+
table.put ("ComboBox.selectionBackground", MaterialColors.GRAY_300);
167+
table.put ("ComboBox.selectionForeground", MaterialColors.BLACK);
169168
table.put ("ComboBox.selectedInDropDownBackground", MaterialColors.GRAY_200);
170169
table.put("ComboBox.mouseHoverColor", MaterialColors.GRAY_400);
171170
table.put("ComboBox.mouseHoverEnabled", true);
@@ -184,6 +183,8 @@ protected void initComponentDefaults (UIDefaults table) {
184183
table.put ("Menu.selectionForeground", Color.BLACK);
185184
table.put ("Menu.disabledForeground", new Color (0, 0, 0, 100));
186185
table.put ("Menu.menuPopupOffsetY", 3);
186+
table.put("Menu[MouseOver].enable", true); //TODO testing
187+
//TODO refactoinh and using the convensioni Component[Action].ohYeah
187188

188189
table.put ("MenuBar.font", MaterialFonts.BOLD);
189190
table.put ("MenuBar.background", Color.WHITE);
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,154 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2018 atharva washimkar, Vincent Palazzo
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

3-
import javax.swing.JComponent;
4-
import javax.swing.Timer;
26+
import javax.swing.*;
527
import java.awt.Color;
6-
import java.awt.event.ActionEvent;
7-
import java.awt.event.ActionListener;
8-
import java.awt.event.MouseEvent;
9-
import java.awt.event.MouseListener;
10-
11-
public class MaterialUITimer implements MouseListener, ActionListener {
12-
13-
private Color from, to;
14-
private boolean forward;
15-
private int alpha, steps;
16-
private int[] forwardDeltas, backwardDeltas;
17-
18-
private JComponent component;
19-
private Timer timer;
20-
21-
protected MaterialUITimer (JComponent component, Color to, int steps, int interval) {
22-
this.from = component.getBackground ();
23-
this.to = to;
24-
25-
this.forwardDeltas = new int[4];
26-
this.backwardDeltas = new int[4];
27-
28-
forwardDeltas[0] = (from.getRed () - to.getRed ()) / steps;
29-
forwardDeltas[1] = (from.getGreen () - to.getGreen ()) / steps;
30-
forwardDeltas[2] = (from.getBlue () - to.getBlue ()) / steps;
31-
forwardDeltas[3] = (from.getAlpha () - to.getAlpha ()) / steps;
32-
33-
backwardDeltas[0] = (to.getRed () - from.getRed ()) / steps;
34-
backwardDeltas[1] = (to.getGreen () - from.getGreen ()) / steps;
35-
backwardDeltas[2] = (to.getBlue () - from.getBlue ()) / steps;
36-
backwardDeltas[3] = (to.getAlpha () - from.getAlpha ()) / steps;
37-
38-
this.steps = steps;
39-
40-
this.component = component;
41-
this.component.addMouseListener (this);
42-
timer = new Timer (interval, this);
43-
}
44-
45-
private Color nextColor () {
46-
int rValue = from.getRed () - alpha * forwardDeltas[0];
47-
int gValue = from.getGreen () - alpha * forwardDeltas[1];
48-
int bValue = from.getBlue () - alpha * forwardDeltas[2];
49-
int aValue = from.getAlpha () - alpha * forwardDeltas[3];
50-
51-
return new Color (rValue, gValue, bValue, aValue);
52-
}
53-
54-
private Color previousColor () {
55-
int rValue = to.getRed () - (steps - alpha) * backwardDeltas[0];
56-
int gValue = to.getGreen () - (steps - alpha) * backwardDeltas[1];
57-
int bValue = to.getBlue () - (steps - alpha) * backwardDeltas[2];
58-
int aValue = to.getAlpha () - (steps - alpha) * backwardDeltas[3];
59-
60-
return new Color (rValue, gValue, bValue, aValue);
61-
}
62-
63-
@Override
64-
public void mousePressed (MouseEvent me) {
65-
if(!me.getComponent().isEnabled()){
66-
return;
67-
}
68-
alpha = steps - 1;
69-
forward = false;
70-
timer.start ();
71-
72-
alpha = 0;
73-
forward = true;
74-
timer.start ();
75-
}
76-
77-
@Override
78-
public void mouseReleased (MouseEvent me) {
79-
80-
}
81-
82-
@Override
83-
public void mouseClicked (MouseEvent me) {
84-
85-
}
86-
87-
@Override
88-
public void mouseExited (MouseEvent me) {
89-
if(!me.getComponent().isEnabled()){
90-
return;
91-
}
92-
alpha = steps - 1;
93-
forward = false;
94-
timer.start ();
95-
}
96-
97-
@Override
98-
public void mouseEntered (MouseEvent me) {
99-
if(!me.getComponent().isEnabled()){
100-
return;
101-
}
102-
alpha = 0;
103-
forward = true;
104-
timer.start ();
105-
}
106-
107-
@Override
108-
public void actionPerformed (ActionEvent ae) {
109-
if (forward) {
110-
component.setBackground (nextColor ());
111-
++alpha;
112-
}
113-
else {
114-
component.setBackground (previousColor ());
115-
--alpha;
116-
}
117-
118-
if (alpha == steps + 1 || alpha == -1) {
119-
timer.stop ();
120-
}
121-
}
122-
}
28+
import java.awt.event.*;
29+
30+
public class MaterialUITimer implements MouseListener, ActionListener, MouseMotionListener {
31+
32+
private Color from, to;
33+
private boolean forward;
34+
private int alpha, steps;
35+
private int[] forwardDeltas, backwardDeltas;
36+
37+
private JComponent component;
38+
private Timer timer;
39+
40+
protected MaterialUITimer(JComponent component, Color to, int steps, int interval) {
41+
if (component == null || !component.isEnabled()) {
42+
return;
43+
}
44+
this.from = component.getBackground();
45+
this.to = to;
46+
47+
this.forwardDeltas = new int[4];
48+
this.backwardDeltas = new int[4];
49+
50+
forwardDeltas[0] = (from.getRed() - to.getRed()) / steps;
51+
forwardDeltas[1] = (from.getGreen() - to.getGreen()) / steps;
52+
forwardDeltas[2] = (from.getBlue() - to.getBlue()) / steps;
53+
forwardDeltas[3] = (from.getAlpha() - to.getAlpha()) / steps;
54+
55+
backwardDeltas[0] = (to.getRed() - from.getRed()) / steps;
56+
backwardDeltas[1] = (to.getGreen() - from.getGreen()) / steps;
57+
backwardDeltas[2] = (to.getBlue() - from.getBlue()) / steps;
58+
backwardDeltas[3] = (to.getAlpha() - from.getAlpha()) / steps;
59+
60+
this.steps = steps;
61+
62+
this.component = component;
63+
this.component.addMouseListener(this);
64+
timer = new Timer(interval, this);
65+
component.setBackground(from);
66+
}
67+
68+
private Color nextColor() {
69+
int rValue = from.getRed() - alpha * forwardDeltas[0];
70+
int gValue = from.getGreen() - alpha * forwardDeltas[1];
71+
int bValue = from.getBlue() - alpha * forwardDeltas[2];
72+
int aValue = from.getAlpha() - alpha * forwardDeltas[3];
73+
74+
return new Color(rValue, gValue, bValue, aValue);
75+
}
76+
77+
private Color previousColor() {
78+
int rValue = to.getRed() - (steps - alpha) * backwardDeltas[0];
79+
int gValue = to.getGreen() - (steps - alpha) * backwardDeltas[1];
80+
int bValue = to.getBlue() - (steps - alpha) * backwardDeltas[2];
81+
int aValue = to.getAlpha() - (steps - alpha) * backwardDeltas[3];
82+
83+
return new Color(rValue, gValue, bValue, aValue);
84+
}
85+
86+
@Override
87+
public void mousePressed(MouseEvent me) {
88+
if (!me.getComponent().isEnabled()) {
89+
return;
90+
}
91+
alpha = steps - 1;
92+
forward = false;
93+
timer.start();
94+
95+
alpha = 0;
96+
forward = true;
97+
timer.start();
98+
}
99+
100+
@Override
101+
public void mouseReleased(MouseEvent me) {
102+
103+
}
104+
105+
@Override
106+
public void mouseClicked(MouseEvent me) {
107+
108+
}
109+
110+
@Override
111+
public void mouseExited(MouseEvent me) {
112+
if (!me.getComponent().isEnabled()) {
113+
return;
114+
}
115+
alpha = steps - 1;
116+
forward = false;
117+
timer.start();
118+
}
119+
120+
@Override
121+
public void mouseEntered(MouseEvent me) {
122+
if (!me.getComponent().isEnabled()) {
123+
return;
124+
}
125+
alpha = 0;
126+
forward = true;
127+
timer.start();
128+
}
129+
130+
@Override
131+
public void actionPerformed(ActionEvent ae) {
132+
if (forward) {
133+
component.setBackground(nextColor());
134+
++alpha;
135+
} else {
136+
component.setBackground(previousColor());
137+
--alpha;
138+
}
139+
140+
if (alpha == steps + 1 || alpha == -1) {
141+
timer.stop();
142+
}
143+
}
144+
145+
@Override
146+
public void mouseDragged(MouseEvent e) {
147+
//do nothing this is util only implements interface MouseMotions
148+
}
149+
150+
@Override
151+
public void mouseMoved(MouseEvent e) {
152+
//do nothing this is util only implements interface MouseMotions
153+
}
154+
}

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,16 @@ public void paint (Graphics g, JComponent c) {
3838
g = MaterialDrawingUtils.getAliasedGraphics (g);
3939

4040
if (b.isContentAreaFilled ()) {
41-
paintBackground (g, b);
41+
paintBackground (MaterialDrawingUtils.getAliasedGraphics(g), b);
4242
}
4343

44-
super.paint (g, c);
44+
super.paint (MaterialDrawingUtils.getAliasedGraphics(g), c);
4545
}
4646

4747
private void paintBackground (Graphics g, JComponent c) {
48+
g = MaterialDrawingUtils.getAliasedGraphics(g);
4849
g.setColor (c.getBackground ());
49-
g.fillRoundRect (0, 0, c.getWidth (), c.getHeight (), 7, 7);
50+
g.fillRect (0, 0, c.getWidth (), c.getHeight());
5051
}
5152

52-
}
53+
}

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ 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
}
24+
25+
2426
}

0 commit comments

Comments
 (0)