Skip to content

Commit 15c2d23

Browse files
add fix multiple
fix the issue atarw#58 and ultimate test for issue atarw#57
1 parent 133929e commit 15c2d23

17 files changed

+149
-85
lines changed

pom.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,30 @@
3535
<target>1.8</target>
3636
</configuration>
3737
</plugin>
38+
39+
<plugin>
40+
<artifactId>maven-assembly-plugin</artifactId>
41+
<configuration>
42+
<archive>
43+
<manifest>
44+
<mainClass>mdlaf.MaterialLookAndFeel</mainClass>
45+
</manifest>
46+
</archive>
47+
<descriptorRefs>
48+
<descriptorRef>jar-with-dependencies</descriptorRef>
49+
</descriptorRefs>
50+
</configuration>
51+
52+
<executions>
53+
<execution>
54+
<id>make-assembly</id> <!-- this is used for inheritance merges -->
55+
<phase>package</phase> <!-- bind to the packaging phase -->
56+
<goals>
57+
<goal>single</goal>
58+
</goals>
59+
</execution>
60+
</executions>
61+
</plugin>
3862
</plugins>
3963
<resources>
4064
<resource>

src/main/java/MaterialUISwingDemo.java

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public static void main (String[] args) {
6969
jRadioButtonMenuItem.setText ("prova RadioButtonMenuItem");
7070
menu1.add (jRadioButtonMenuItem);
7171
menu1.addSeparator ();
72+
7273
//TestCheckBoxMenuItem
7374
JCheckBoxMenuItem checkBoxMenuItem = new JCheckBoxMenuItem ();
7475
checkBoxMenuItem.setText ("test");
@@ -118,28 +119,31 @@ public static void main (String[] args) {
118119

119120
JToolBar tb = new JToolBar ("toolbar");
120121
JButton button1 = new JButton ("f");
121-
122-
button1.setAction (new AbstractAction () {
123-
@Override
124-
public void actionPerformed (ActionEvent e) {
125-
putValue (Action.NAME, "f");
126-
putValue (Action.SHORT_DESCRIPTION, "Test tool tip");
127-
128-
JDialog dialog = new JDialog ();
129-
JPanel jPanel = new JPanel ();
130-
jPanel.add (new JColorChooser ());
131-
dialog.setContentPane (jPanel);
132-
dialog.setLocationRelativeTo (null);
133-
dialog.setVisible (true);
134-
dialog.pack ();
135-
}
136-
});
137-
138122
JButton button2 = new JButton ("e");
139123
button1.setBackground (MaterialColors.LIGHT_BLUE_400);
140124
button1.setForeground (Color.WHITE);
141125
button2.setBackground (MaterialColors.LIGHT_BLUE_400);
142126
button2.setForeground (Color.WHITE);
127+
button1.addMouseListener(MaterialUIMovement.getMovement(button1, MaterialColors.LIGHT_BLUE_200));
128+
button2.addMouseListener(MaterialUIMovement.getMovement(button2, MaterialColors.LIGHT_BLUE_200));
129+
130+
button1.addActionListener (new AbstractAction () {
131+
@Override
132+
public void actionPerformed (ActionEvent e) {
133+
134+
putValue (Action.NAME, "f");
135+
136+
JDialog dialog = new JDialog ();
137+
JPanel jPanel = new JPanel ();
138+
jPanel.add (new JColorChooser ());
139+
dialog.setContentPane (jPanel);
140+
dialog.setLocationRelativeTo (null);
141+
dialog.pack ();
142+
dialog.setVisible (true);
143+
}
144+
});
145+
button1.setToolTipText("This is a tool tip");
146+
143147
tb.add (button1);
144148
tb.addSeparator ();
145149
tb.add (button2);
@@ -192,6 +196,20 @@ public void actionPerformed (ActionEvent e) {
192196
taskPane.setTitle("Material Look and fell");
193197
pn.add(taskPane);
194198

199+
//Test effect mouse over
200+
201+
//Setting defoult
202+
JButton testButtonHoverOne = new JButton("Fly over me One");
203+
testButtonHoverOne.setEnabled(false);
204+
pn.add(testButtonHoverOne);
205+
206+
//ModSetting
207+
JButton testButtonHoverTwo = new JButton("Fly over me Two");
208+
testButtonHoverTwo.setBackground(MaterialColors.LIGHT_BLUE_500);
209+
testButtonHoverTwo.setForeground(MaterialColors.WHITE);
210+
testButtonHoverTwo.addMouseListener(MaterialUIMovement.getMovement(testButtonHoverTwo, MaterialColors.LIGHT_BLUE_200));
211+
pn.add(testButtonHoverTwo);
212+
195213
// make everything visible to the world
196214
frame.pack ();
197215
frame.setVisible (true);

src/main/java/mdlaf/animation/MaterialUIMovement.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,12 @@ public static void add (JComponent c, Color fadeTo, int steps, int interval) {
1414
public static void add (JComponent c, Color fadeTo) {
1515
add (c, fadeTo, 5, 1000 / 30);
1616
}
17+
18+
public static MaterialUITimer getMovement (JComponent c, Color fadeTo, int steps, int interval) {
19+
return new MaterialUITimer (c, fadeTo, steps, interval);
20+
}
21+
22+
public static MaterialUITimer getMovement (JComponent c, Color fadeTo) {
23+
return getMovement (c, fadeTo, 5, 1000 / 30);
24+
}
1725
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ private Color previousColor () {
6262

6363
@Override
6464
public void mousePressed (MouseEvent me) {
65+
if(!me.getComponent().isEnabled()){
66+
return;
67+
}
6568
alpha = steps - 1;
6669
forward = false;
6770
timer.start ();
@@ -83,13 +86,19 @@ public void mouseClicked (MouseEvent me) {
8386

8487
@Override
8588
public void mouseExited (MouseEvent me) {
89+
if(!me.getComponent().isEnabled()){
90+
return;
91+
}
8692
alpha = steps - 1;
8793
forward = false;
8894
timer.start ();
8995
}
9096

9197
@Override
9298
public void mouseEntered (MouseEvent me) {
99+
if(!me.getComponent().isEnabled()){
100+
return;
101+
}
93102
alpha = 0;
94103
forward = true;
95104
timer.start ();

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

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package mdlaf.components.button;
22

33
import mdlaf.animation.MaterialUIMovement;
4-
import mdlaf.utils.MaterialColors;
54
import mdlaf.utils.MaterialDrawingUtils;
65

76
import javax.swing.AbstractButton;
@@ -10,8 +9,6 @@
109
import javax.swing.plaf.ComponentUI;
1110
import javax.swing.plaf.basic.BasicButtonUI;
1211
import java.awt.*;
13-
import java.awt.event.MouseAdapter;
14-
import java.awt.event.MouseEvent;
1512

1613
public class MaterialButtonUI extends BasicButtonUI {
1714

@@ -29,7 +26,9 @@ public void installUI (JComponent c) {
2926
button.setBackground (UIManager.getColor ("Button.background"));
3027
button.setForeground (UIManager.getColor ("Button.foreground"));
3128
button.setFont (UIManager.getFont ("Button.font"));
32-
button.addMouseListener(new EffectButton());
29+
if(UIManager.getBoolean("Button.mouseHoverEnable")){
30+
button.addMouseListener(MaterialUIMovement.getMovement(button, UIManager.getColor("Button.mouseHoverColor")));
31+
}
3332
button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
3433
}
3534

@@ -50,14 +49,4 @@ private void paintBackground (Graphics g, JComponent c) {
5049
g.fillRoundRect (0, 0, c.getWidth (), c.getHeight (), 7, 7);
5150
}
5251

53-
private class EffectButton extends MouseAdapter {
54-
55-
@Override
56-
public void mouseEntered(MouseEvent e) {
57-
JComponent component = (JComponent) e.getSource();
58-
if(UIManager.getBoolean("Button.mouseHoverEnable")){
59-
MaterialUIMovement.add(component, MaterialColors.bleach(UIManager.getColor("Button.mouseHoverColor"), (float) 0.1), 5, 1000 / 30);
60-
}
61-
}
62-
}
6352
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import javax.swing.UIManager;
88
import javax.swing.plaf.ComponentUI;
99
import javax.swing.plaf.basic.BasicCheckBoxUI;
10-
import java.awt.Graphics;
10+
import java.awt.*;
1111

1212
//TODO cambio colore icone combo box
1313
public class MaterialCheckBoxUI extends BasicCheckBoxUI {
@@ -26,6 +26,8 @@ public void installUI (JComponent c) {
2626
checkBox.setForeground (UIManager.getColor ("CheckBox.foreground"));
2727
checkBox.setIcon (UIManager.getIcon ("CheckBox.icon"));
2828
checkBox.setSelectedIcon (UIManager.getIcon ("CheckBox.selectedIcon"));
29+
c.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
30+
2931
}
3032

3133
@Override

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
import javax.swing.UIManager;
99
import javax.swing.plaf.ComponentUI;
1010
import javax.swing.plaf.basic.BasicCheckBoxMenuItemUI;
11-
import java.awt.Color;
12-
import java.awt.Graphics;
11+
import java.awt.*;
1312

1413
/**
1514
* @author https://github.com/vincenzopalazzo
@@ -34,6 +33,7 @@ public void paint (Graphics g, JComponent c) {
3433
@Override
3534
protected void paintMenuItem (Graphics g, JComponent c, Icon checkIcon, Icon arrowIcon, Color background, Color foreground, int defaultTextIconGap) {
3635
JCheckBoxMenuItem checkBoxMenuItem = (JCheckBoxMenuItem) c;
36+
c.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
3737
if (checkBoxMenuItem.isSelected ()) {
3838
super.paintMenuItem (MaterialDrawingUtils.getAliasedGraphics (g), checkBoxMenuItem, UIManager.getIcon ("CheckBoxMenuItem.selectedCheckIcon"), arrowIcon, background, foreground, defaultTextIconGap);
3939
return;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import javax.swing.plaf.ComponentUI;
1313
import javax.swing.plaf.basic.BasicArrowButton;
1414
import javax.swing.plaf.basic.BasicComboBoxUI;
15-
import java.awt.Graphics;
15+
import java.awt.*;
1616

1717
public class MaterialComboBoxUI extends BasicComboBoxUI {
1818

@@ -31,6 +31,7 @@ public void installUI (JComponent c) {
3131
comboBox.setBorder (UIManager.getBorder ("ComboBox.border"));
3232
comboBox.setLightWeightPopupEnabled (true);
3333
comboBox.setRenderer (new MaterialComboBoxRenderer ());
34+
c.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
3435
}
3536

3637
@Override

src/main/java/mdlaf/components/menubar/MaterialMenuBarUI.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import javax.swing.UIManager;
88
import javax.swing.plaf.ComponentUI;
99
import javax.swing.plaf.basic.BasicMenuBarUI;
10-
import java.awt.Graphics;
10+
import java.awt.*;
1111

1212
public class MaterialMenuBarUI extends BasicMenuBarUI {
1313

@@ -24,6 +24,7 @@ public void installUI (JComponent c) {
2424
menuBar.setBackground (UIManager.getColor ("MenuBar.background"));
2525
menuBar.setBorder (UIManager.getBorder ("MenuBar.border"));
2626
menuBar.setForeground (UIManager.getColor ("MenuBar.foreground"));
27+
c.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
2728
}
2829

2930
@Override

src/main/java/mdlaf/components/menuitem/MaterialMenuItemUI.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import javax.swing.UIManager;
99
import javax.swing.plaf.ComponentUI;
1010
import javax.swing.plaf.basic.BasicMenuItemUI;
11-
import java.awt.Graphics;
11+
import java.awt.*;
1212

1313
public class MaterialMenuItemUI extends BasicMenuItemUI {
1414

@@ -27,6 +27,7 @@ public void installUI (JComponent c) {
2727
menuItem.setHorizontalAlignment (SwingConstants.LEFT);
2828
menuItem.setVerticalAlignment (SwingConstants.CENTER);
2929
menuItem.setBorder (UIManager.getBorder ("MenuItem.border"));
30+
c.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
3031
}
3132

3233
@Override

0 commit comments

Comments
 (0)