Skip to content

Commit

Permalink
refactoring code and fix a bud mouse hover effect
Browse files Browse the repository at this point in the history
  • Loading branch information
vincenzopalazzo committed Mar 1, 2019
1 parent a12dcc9 commit 711b898
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 18 deletions.
22 changes: 12 additions & 10 deletions src/MaterialUISwingDemo.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import mdlaf.MaterialLookAndFeel;
import mdlaf.animation.MaterialUIMovement;
import mdlaf.utils.MaterialColors;
import mdlaf.utils.MaterialFontFactory;
import mdlaf.utils.MaterialImageFactory;
import org.jdesktop.swingx.JXTaskPane;
import top.gigabox.supportcomponent.toast.MaterialTost;
Expand All @@ -16,14 +15,12 @@ public class MaterialUISwingDemo {
private static long beforeUsedMem;

public MaterialUISwingDemo() {
beforeUsedMem=Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory();
beforeUsedMem = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
}



public static void main (String[] args) {
try {
UIManager.setLookAndFeel (new MaterialLookAndFeel ());
UIManager.setLookAndFeel(new MaterialLookAndFeel());
}
catch (UnsupportedLookAndFeelException e) {
e.printStackTrace ();
Expand Down Expand Up @@ -142,6 +139,10 @@ public void actionPerformed(ActionEvent e) {
button1.setForeground (Color.WHITE);
button2.setBackground (MaterialColors.LIGHT_BLUE_400);
button2.setForeground (Color.WHITE);

button1.addMouseListener(MaterialUIMovement.getMovement(button1, MaterialColors.LIGHT_BLUE_300));
button2.addMouseListener(MaterialUIMovement.getMovement(button2, MaterialColors.LIGHT_BLUE_300));

tb.add (button1);
tb.addSeparator ();
tb.add (button2);
Expand Down Expand Up @@ -207,7 +208,7 @@ public void actionPerformed(ActionEvent e) {
buttonTwoo.setAction(new ActionToastTest(pn));
buttonTwoo.setBackground(MaterialColors.PURPLE_600);
buttonTwoo.setForeground(MaterialColors.GRAY_100);
MaterialUIMovement.add(buttonTwoo, MaterialColors.PURPLE_300);
buttonTwoo.addMouseListener(MaterialUIMovement.getMovement(buttonTwoo, MaterialColors.PURPLE_300));
pn.add(buttonTwoo);

JButton bottoneConImmagine = new JButton();
Expand Down Expand Up @@ -246,16 +247,17 @@ public void actionPerformed(ActionEvent e) {

jxTaskPane.add(memoryOccupedNow);

//Setting defoult
//Test effect mouse over
//Setting default
JButton testButtonHoverOne = new JButton("Fly over me One");
testButtonHoverOne.setEnabled(false);
pn.add(testButtonHoverOne);

//ModSetting
JButton testButtonHoverTwo = new JButton("Fly over me Two");
testButtonHoverTwo.setBackground(MaterialColors.LIGHT_BLUE_500);
testButtonHoverTwo.setForeground(MaterialColors.WHITE);
MaterialUIMovement.add(testButtonHoverTwo, MaterialColors.LIGHT_BLUE_200);

testButtonHoverTwo.addMouseListener(MaterialUIMovement.getMovement(testButtonHoverTwo, MaterialColors.LIGHT_BLUE_200));
pn.add(testButtonHoverTwo);

pn.add(jxTaskPane);
Expand All @@ -268,4 +270,4 @@ public void actionPerformed(ActionEvent e) {
double megamemori = (lastUsedMem - beforeUsedMem) * 9.537 * Math.pow(10, -7);
memoryOccupedNow.setText("Memory occuped after update: " + megamemori + " MB");
}
}
}
8 changes: 8 additions & 0 deletions src/mdlaf/animation/MaterialUIMovement.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@ public static void add (JComponent c, Color fadeTo, int steps, int interval) {
public static void add (JComponent c, Color fadeTo) {
add (c, fadeTo, 5, 1000 / 30);
}

public static MaterialUITimer getMovement(JComponent c, Color fadeTo, int steps, int interval){
return new MaterialUITimer (c, fadeTo, steps, interval);
}

public static MaterialUITimer getMovement(JComponent c, Color fadeTo){
return getMovement(c, fadeTo, 5, 1000 / 30);
}
}
11 changes: 10 additions & 1 deletion src/mdlaf/animation/MaterialUITimer.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ private Color previousColor () {

@Override
public void mousePressed (MouseEvent me) {
if(!me.getComponent().isEnabled()){
return;
}
alpha = steps - 1;
forward = false;
timer.start ();
Expand All @@ -84,13 +87,19 @@ public void mouseClicked (MouseEvent me) {

@Override
public void mouseExited (MouseEvent me) {
if(!me.getComponent().isEnabled()){
return;
}
alpha = steps - 1;
forward = false;
timer.start ();
}

@Override
public void mouseEntered (MouseEvent me) {
if(!me.getComponent().isEnabled()){
return;
}
alpha = 0;
forward = true;
timer.start ();
Expand All @@ -111,4 +120,4 @@ public void actionPerformed (ActionEvent ae) {
timer.stop ();
}
}
}
}
5 changes: 1 addition & 4 deletions src/mdlaf/components/button/MaterialButtonUI.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package mdlaf.components.button;

import mdlaf.animation.MaterialUIMovement;
import mdlaf.animation.MaterialUITimer;
import mdlaf.utils.MaterialColors;
import mdlaf.utils.MaterialDrawingUtils;

import javax.swing.AbstractButton;
import javax.swing.JComponent;
import javax.swing.UIManager;
Expand All @@ -29,7 +26,7 @@ public void installUI(JComponent c) {
button.setForeground(UIManager.getColor("Button.foreground"));
button.setFont(UIManager.getFont("Button.font"));
button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
MaterialUIMovement.add(button, UIManager.getColor("Button.mouseHoverColor"));
button.addMouseListener(MaterialUIMovement.getMovement(button, UIManager.getColor("Button.mouseHoverColor")));
}

@Override
Expand Down
1 change: 1 addition & 0 deletions src/mdlaf/components/table/MaterialTableUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public void installUI (JComponent c) {

table.setDefaultRenderer (Object.class, new MaterialTableCellRenderer ());
table.setDefaultEditor (Object.class, new MaterialTableCellEditor ());
table.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}

@Override
Expand Down
5 changes: 2 additions & 3 deletions src/mdlaf/utils/MaterialFontFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ private MaterialFontFactory() {

private void loadOsPropries() throws IOException {
String os = System.getProperty("os.name", "generic").toLowerCase();
System.out.print(os);
String osSupport = isOsSupportted(os);
String osSupport = osSupportted(os);
if (osSupport != null) {
String pathProperties = "/resources/config/font-" + osSupport + ".properties";
properties.load(getClass().getResourceAsStream(pathProperties));
Expand All @@ -61,7 +60,7 @@ private void loadOsPropries() throws IOException {
properties.load(getClass().getResourceAsStream("/resources/config/font-linux.properties"));
}

private String isOsSupportted(String os) {
private String osSupportted(String os) {
for (int i = 0; i < SISTEM_SUPPORTED.length; i++) {
if (os.contains(SISTEM_SUPPORTED[i])) {
return SISTEM_SUPPORTED[i];
Expand Down

0 comments on commit 711b898

Please sign in to comment.