diff --git a/src/MaterialUISwingDemo.java b/src/MaterialUISwingDemo.java index 1f84c67..95b847e 100644 --- a/src/MaterialUISwingDemo.java +++ b/src/MaterialUISwingDemo.java @@ -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; @@ -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 (); @@ -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); @@ -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(); @@ -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); @@ -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"); } -} \ No newline at end of file +} diff --git a/src/mdlaf/animation/MaterialUIMovement.java b/src/mdlaf/animation/MaterialUIMovement.java index 627aeff..12d6855 100644 --- a/src/mdlaf/animation/MaterialUIMovement.java +++ b/src/mdlaf/animation/MaterialUIMovement.java @@ -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); + } } diff --git a/src/mdlaf/animation/MaterialUITimer.java b/src/mdlaf/animation/MaterialUITimer.java index 8e93a00..995fc57 100644 --- a/src/mdlaf/animation/MaterialUITimer.java +++ b/src/mdlaf/animation/MaterialUITimer.java @@ -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 (); @@ -84,6 +87,9 @@ public void mouseClicked (MouseEvent me) { @Override public void mouseExited (MouseEvent me) { + if(!me.getComponent().isEnabled()){ + return; + } alpha = steps - 1; forward = false; timer.start (); @@ -91,6 +97,9 @@ public void mouseExited (MouseEvent me) { @Override public void mouseEntered (MouseEvent me) { + if(!me.getComponent().isEnabled()){ + return; + } alpha = 0; forward = true; timer.start (); @@ -111,4 +120,4 @@ public void actionPerformed (ActionEvent ae) { timer.stop (); } } -} \ No newline at end of file +} diff --git a/src/mdlaf/components/button/MaterialButtonUI.java b/src/mdlaf/components/button/MaterialButtonUI.java index 94e0c5d..0daf0e2 100644 --- a/src/mdlaf/components/button/MaterialButtonUI.java +++ b/src/mdlaf/components/button/MaterialButtonUI.java @@ -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; @@ -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 diff --git a/src/mdlaf/components/table/MaterialTableUI.java b/src/mdlaf/components/table/MaterialTableUI.java index 4696562..03aa22c 100644 --- a/src/mdlaf/components/table/MaterialTableUI.java +++ b/src/mdlaf/components/table/MaterialTableUI.java @@ -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 diff --git a/src/mdlaf/utils/MaterialFontFactory.java b/src/mdlaf/utils/MaterialFontFactory.java index b2246ef..8fe9678 100644 --- a/src/mdlaf/utils/MaterialFontFactory.java +++ b/src/mdlaf/utils/MaterialFontFactory.java @@ -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)); @@ -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];