diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..43c4ed6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/nbproject/private/ diff --git a/README.md b/README.md index f22be01..dae09e6 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,9 @@ # SwingMaterialDesign A **Material Design** components for java swing. Trying to make java swing more beautiful and vivid. With *shadows* and *ripples*. +Image upload design, gradients and more! -I used **netbeans** for this project, so it's easy to work with WYSIWYG IDE. +I used **netbeans** for this project. ## Screenshots -![Java Swing Window](/resources/JavaSwingWindow.png) - -![Java Swing Button Ripples](/resources/JavaSwingButtonRipple.png) - -![Java Swing TextField](/resources/JavaSwingTextField.png) - -![Java Swing ComboBox](/resources/JavaSwingComboBox.png) - -![Java Swing FlatButton Ripples](/resources/JavaSwingFlatButtonRipple.png) +![Java Swing Window](/resources/swingmd.gif) diff --git a/build.xml b/build.xml index c38789a..71607e9 100644 --- a/build.xml +++ b/build.xml @@ -1,73 +1,73 @@ - - - - - - - - - - - Builds, tests, and runs the project SwingMaterialDesign. - - - + + + + + + + + + + + Builds, tests, and runs the project SwingMaterialDesign. + + + diff --git a/build/built-jar.properties b/build/built-jar.properties new file mode 100644 index 0000000..7b47b48 --- /dev/null +++ b/build/built-jar.properties @@ -0,0 +1,4 @@ +#Mon, 08 Feb 2021 17:00:00 -0300 + + +C\:\\Users\\Abner\\Documents\\IFSP\\BCC\\FerramentasI\\SwingMaterialDesign= diff --git a/build/classes/com/hq/swingmaterialdesign/MainView$1.class b/build/classes/com/hq/swingmaterialdesign/MainView$1.class new file mode 100644 index 0000000..160ce61 Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/MainView$1.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/MainView$2.class b/build/classes/com/hq/swingmaterialdesign/MainView$2.class new file mode 100644 index 0000000..213dbfe Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/MainView$2.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/MainView$3.class b/build/classes/com/hq/swingmaterialdesign/MainView$3.class new file mode 100644 index 0000000..bc3eada Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/MainView$3.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/MainView$4.class b/build/classes/com/hq/swingmaterialdesign/MainView$4.class new file mode 100644 index 0000000..28cafae Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/MainView$4.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/MainView$5.class b/build/classes/com/hq/swingmaterialdesign/MainView$5.class new file mode 100644 index 0000000..1e090c0 Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/MainView$5.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/MainView$6.class b/build/classes/com/hq/swingmaterialdesign/MainView$6.class new file mode 100644 index 0000000..caf24dd Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/MainView$6.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/MainView$7.class b/build/classes/com/hq/swingmaterialdesign/MainView$7.class new file mode 100644 index 0000000..ed8b579 Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/MainView$7.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/MainView.class b/build/classes/com/hq/swingmaterialdesign/MainView.class new file mode 100644 index 0000000..96f6a48 Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/MainView.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/images/profile.jpg b/build/classes/com/hq/swingmaterialdesign/images/profile.jpg new file mode 100644 index 0000000..539541b Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/images/profile.jpg differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/ElevationEffect$1.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/ElevationEffect$1.class new file mode 100644 index 0000000..6fbe6ea Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/ElevationEffect$1.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/ElevationEffect.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/ElevationEffect.class new file mode 100644 index 0000000..dff240d Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/ElevationEffect.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/FastGaussianBlur.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/FastGaussianBlur.class new file mode 100644 index 0000000..4e0a10b Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/FastGaussianBlur.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/MButton$1.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/MButton$1.class new file mode 100644 index 0000000..ab974e5 Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/MButton$1.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/MButton$2.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/MButton$2.class new file mode 100644 index 0000000..5d44f78 Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/MButton$2.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/MButton$Type.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/MButton$Type.class new file mode 100644 index 0000000..c2528cf Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/MButton$Type.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/MButton.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/MButton.class new file mode 100644 index 0000000..17b0b30 Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/MButton.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/MComboBox$1.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/MComboBox$1.class new file mode 100644 index 0000000..4510c1a Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/MComboBox$1.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/MComboBox$FieldRenderer.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/MComboBox$FieldRenderer.class new file mode 100644 index 0000000..816ec59 Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/MComboBox$FieldRenderer.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/MComboBox$Popup.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/MComboBox$Popup.class new file mode 100644 index 0000000..7f8f8aa Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/MComboBox$Popup.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/MComboBox$ScrollBar$1.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/MComboBox$ScrollBar$1.class new file mode 100644 index 0000000..e82c4fd Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/MComboBox$ScrollBar$1.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/MComboBox$ScrollBar.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/MComboBox$ScrollBar.class new file mode 100644 index 0000000..dd592f9 Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/MComboBox$ScrollBar.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/MComboBox.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/MComboBox.class new file mode 100644 index 0000000..9595913 Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/MComboBox.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/MGradientButton$1.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/MGradientButton$1.class new file mode 100644 index 0000000..2516cd1 Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/MGradientButton$1.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/MGradientButton$Type.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/MGradientButton$Type.class new file mode 100644 index 0000000..c8e9fe3 Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/MGradientButton$Type.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/MGradientButton.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/MGradientButton.class new file mode 100644 index 0000000..dbb6f3f Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/MGradientButton.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/MGradientPanel.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/MGradientPanel.class new file mode 100644 index 0000000..8260ded Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/MGradientPanel.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/MIconButton.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/MIconButton.class new file mode 100644 index 0000000..148d704 Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/MIconButton.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/MPanel.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/MPanel.class new file mode 100644 index 0000000..7b639ca Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/MPanel.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/MPasswordField$1.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/MPasswordField$1.class new file mode 100644 index 0000000..26752b4 Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/MPasswordField$1.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/MPasswordField.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/MPasswordField.class new file mode 100644 index 0000000..1907d32 Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/MPasswordField.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/MTextField$1.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/MTextField$1.class new file mode 100644 index 0000000..43d6fb7 Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/MTextField$1.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/MTextField.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/MTextField.class new file mode 100644 index 0000000..354fe74 Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/MTextField.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/MToggleButton$1.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/MToggleButton$1.class new file mode 100644 index 0000000..dd9e12a Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/MToggleButton$1.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/MToggleButton$2.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/MToggleButton$2.class new file mode 100644 index 0000000..4c9862b Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/MToggleButton$2.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/MToggleButton$Type.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/MToggleButton$Type.class new file mode 100644 index 0000000..6e90ce2 Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/MToggleButton$Type.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/MToggleButton.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/MToggleButton.class new file mode 100644 index 0000000..54ccbf7 Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/MToggleButton.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/MToggleButton_old$1.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/MToggleButton_old$1.class new file mode 100644 index 0000000..ff25a58 Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/MToggleButton_old$1.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/MToggleButton_old.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/MToggleButton_old.class new file mode 100644 index 0000000..e9a6e4e Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/MToggleButton_old.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/MaterialFloatingLabel$1.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/MaterialFloatingLabel$1.class new file mode 100644 index 0000000..7184c3e Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/MaterialFloatingLabel$1.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/MaterialFloatingLabel.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/MaterialFloatingLabel.class new file mode 100644 index 0000000..a33be16 Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/MaterialFloatingLabel.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/MaterialLine$1.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/MaterialLine$1.class new file mode 100644 index 0000000..952fe6e Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/MaterialLine$1.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/MaterialLine.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/MaterialLine.class new file mode 100644 index 0000000..0d196e3 Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/MaterialLine.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/MaterialShadow.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/MaterialShadow.class new file mode 100644 index 0000000..fe32147 Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/MaterialShadow.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/MaterialUtils.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/MaterialUtils.class new file mode 100644 index 0000000..55b2ceb Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/MaterialUtils.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/RippleEffect$1.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/RippleEffect$1.class new file mode 100644 index 0000000..a0a59ea Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/RippleEffect$1.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/RippleEffect$2.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/RippleEffect$2.class new file mode 100644 index 0000000..208db6d Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/RippleEffect$2.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/RippleEffect$RippleAnimation$1.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/RippleEffect$RippleAnimation$1.class new file mode 100644 index 0000000..3687fb4 Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/RippleEffect$RippleAnimation$1.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/RippleEffect$RippleAnimation.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/RippleEffect$RippleAnimation.class new file mode 100644 index 0000000..9250869 Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/RippleEffect$RippleAnimation.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/RippleEffect.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/RippleEffect.class new file mode 100644 index 0000000..7461491 Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/RippleEffect.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/animation/AnimationListener.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/animation/AnimationListener.class new file mode 100644 index 0000000..9a4156e Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/animation/AnimationListener.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/animation/Animator.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/animation/Animator.class new file mode 100644 index 0000000..43321cf Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/animation/Animator.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/resource/MaterialColor.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/resource/MaterialColor.class new file mode 100644 index 0000000..35cb2ee Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/resource/MaterialColor.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/resource/MaterialIcons.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/resource/MaterialIcons.class new file mode 100644 index 0000000..3986d8e Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/resource/MaterialIcons.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/resource/Nunito.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/resource/Nunito.class new file mode 100644 index 0000000..4f9c8e2 Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/resource/Nunito.class differ diff --git a/build/classes/com/hq/swingmaterialdesign/materialdesign/resource/Roboto.class b/build/classes/com/hq/swingmaterialdesign/materialdesign/resource/Roboto.class new file mode 100644 index 0000000..15e27b7 Binary files /dev/null and b/build/classes/com/hq/swingmaterialdesign/materialdesign/resource/Roboto.class differ diff --git a/build/classes/resources/fonts/MaterialIcons-Regular.ttf b/build/classes/resources/fonts/MaterialIcons-Regular.ttf new file mode 100644 index 0000000..7015564 Binary files /dev/null and b/build/classes/resources/fonts/MaterialIcons-Regular.ttf differ diff --git a/build/classes/resources/fonts/Nunito-Black.ttf b/build/classes/resources/fonts/Nunito-Black.ttf new file mode 100644 index 0000000..330a207 Binary files /dev/null and b/build/classes/resources/fonts/Nunito-Black.ttf differ diff --git a/build/classes/resources/fonts/Nunito-BlackItalic.ttf b/build/classes/resources/fonts/Nunito-BlackItalic.ttf new file mode 100644 index 0000000..2fe2ecf Binary files /dev/null and b/build/classes/resources/fonts/Nunito-BlackItalic.ttf differ diff --git a/build/classes/resources/fonts/Nunito-Bold.ttf b/build/classes/resources/fonts/Nunito-Bold.ttf new file mode 100644 index 0000000..99d0735 Binary files /dev/null and b/build/classes/resources/fonts/Nunito-Bold.ttf differ diff --git a/build/classes/resources/fonts/Nunito-BoldItalic.ttf b/build/classes/resources/fonts/Nunito-BoldItalic.ttf new file mode 100644 index 0000000..35d6d27 Binary files /dev/null and b/build/classes/resources/fonts/Nunito-BoldItalic.ttf differ diff --git a/build/classes/resources/fonts/Nunito-ExtraBold.ttf b/build/classes/resources/fonts/Nunito-ExtraBold.ttf new file mode 100644 index 0000000..993de65 Binary files /dev/null and b/build/classes/resources/fonts/Nunito-ExtraBold.ttf differ diff --git a/build/classes/resources/fonts/Nunito-ExtraBoldItalic.ttf b/build/classes/resources/fonts/Nunito-ExtraBoldItalic.ttf new file mode 100644 index 0000000..9d569fd Binary files /dev/null and b/build/classes/resources/fonts/Nunito-ExtraBoldItalic.ttf differ diff --git a/build/classes/resources/fonts/Nunito-ExtraLight.ttf b/build/classes/resources/fonts/Nunito-ExtraLight.ttf new file mode 100644 index 0000000..2b71830 Binary files /dev/null and b/build/classes/resources/fonts/Nunito-ExtraLight.ttf differ diff --git a/build/classes/resources/fonts/Nunito-ExtraLightItalic.ttf b/build/classes/resources/fonts/Nunito-ExtraLightItalic.ttf new file mode 100644 index 0000000..77bfabd Binary files /dev/null and b/build/classes/resources/fonts/Nunito-ExtraLightItalic.ttf differ diff --git a/build/classes/resources/fonts/Nunito-Light.ttf b/build/classes/resources/fonts/Nunito-Light.ttf new file mode 100644 index 0000000..54a9a90 Binary files /dev/null and b/build/classes/resources/fonts/Nunito-Light.ttf differ diff --git a/build/classes/resources/fonts/Nunito-LightItalic.ttf b/build/classes/resources/fonts/Nunito-LightItalic.ttf new file mode 100644 index 0000000..8dbb8dc Binary files /dev/null and b/build/classes/resources/fonts/Nunito-LightItalic.ttf differ diff --git a/build/classes/resources/fonts/Nunito-Regular.ttf b/build/classes/resources/fonts/Nunito-Regular.ttf new file mode 100644 index 0000000..fb9a17a Binary files /dev/null and b/build/classes/resources/fonts/Nunito-Regular.ttf differ diff --git a/build/classes/resources/fonts/Nunito-RegularItalic.ttf b/build/classes/resources/fonts/Nunito-RegularItalic.ttf new file mode 100644 index 0000000..5f88353 Binary files /dev/null and b/build/classes/resources/fonts/Nunito-RegularItalic.ttf differ diff --git a/build/classes/resources/fonts/Nunito-SemiBold.ttf b/build/classes/resources/fonts/Nunito-SemiBold.ttf new file mode 100644 index 0000000..bd39ecf Binary files /dev/null and b/build/classes/resources/fonts/Nunito-SemiBold.ttf differ diff --git a/build/classes/resources/fonts/Nunito-SemiBoldItalic.ttf b/build/classes/resources/fonts/Nunito-SemiBoldItalic.ttf new file mode 100644 index 0000000..d5d3dec Binary files /dev/null and b/build/classes/resources/fonts/Nunito-SemiBoldItalic.ttf differ diff --git a/build/classes/resources/fonts/Roboto-Black.ttf b/build/classes/resources/fonts/Roboto-Black.ttf new file mode 100644 index 0000000..cb905bc Binary files /dev/null and b/build/classes/resources/fonts/Roboto-Black.ttf differ diff --git a/build/classes/resources/fonts/Roboto-BlackItalic.ttf b/build/classes/resources/fonts/Roboto-BlackItalic.ttf new file mode 100644 index 0000000..3ebdc7d Binary files /dev/null and b/build/classes/resources/fonts/Roboto-BlackItalic.ttf differ diff --git a/build/classes/resources/fonts/Roboto-Bold.ttf b/build/classes/resources/fonts/Roboto-Bold.ttf new file mode 100644 index 0000000..68822ca Binary files /dev/null and b/build/classes/resources/fonts/Roboto-Bold.ttf differ diff --git a/build/classes/resources/fonts/Roboto-BoldItalic.ttf b/build/classes/resources/fonts/Roboto-BoldItalic.ttf new file mode 100644 index 0000000..aebf8eb Binary files /dev/null and b/build/classes/resources/fonts/Roboto-BoldItalic.ttf differ diff --git a/build/classes/resources/fonts/Roboto-Italic.ttf b/build/classes/resources/fonts/Roboto-Italic.ttf new file mode 100644 index 0000000..2041cbc Binary files /dev/null and b/build/classes/resources/fonts/Roboto-Italic.ttf differ diff --git a/build/classes/resources/fonts/Roboto-Light.ttf b/build/classes/resources/fonts/Roboto-Light.ttf new file mode 100644 index 0000000..aa45340 Binary files /dev/null and b/build/classes/resources/fonts/Roboto-Light.ttf differ diff --git a/build/classes/resources/fonts/Roboto-LightItalic.ttf b/build/classes/resources/fonts/Roboto-LightItalic.ttf new file mode 100644 index 0000000..a85444f Binary files /dev/null and b/build/classes/resources/fonts/Roboto-LightItalic.ttf differ diff --git a/build/classes/resources/fonts/Roboto-Medium.ttf b/build/classes/resources/fonts/Roboto-Medium.ttf new file mode 100644 index 0000000..a3c1a1f Binary files /dev/null and b/build/classes/resources/fonts/Roboto-Medium.ttf differ diff --git a/build/classes/resources/fonts/Roboto-MediumItalic.ttf b/build/classes/resources/fonts/Roboto-MediumItalic.ttf new file mode 100644 index 0000000..b828205 Binary files /dev/null and b/build/classes/resources/fonts/Roboto-MediumItalic.ttf differ diff --git a/build/classes/resources/fonts/Roboto-Regular.ttf b/build/classes/resources/fonts/Roboto-Regular.ttf new file mode 100644 index 0000000..0e58508 Binary files /dev/null and b/build/classes/resources/fonts/Roboto-Regular.ttf differ diff --git a/build/classes/resources/fonts/Roboto-Thin.ttf b/build/classes/resources/fonts/Roboto-Thin.ttf new file mode 100644 index 0000000..8779333 Binary files /dev/null and b/build/classes/resources/fonts/Roboto-Thin.ttf differ diff --git a/build/classes/resources/fonts/Roboto-ThinItalic.ttf b/build/classes/resources/fonts/Roboto-ThinItalic.ttf new file mode 100644 index 0000000..b79cb26 Binary files /dev/null and b/build/classes/resources/fonts/Roboto-ThinItalic.ttf differ diff --git a/dist/README.TXT b/dist/README.TXT new file mode 100644 index 0000000..455fa42 --- /dev/null +++ b/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "SwingMaterialDesign.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/dist/SwingMaterialDesign.jar b/dist/SwingMaterialDesign.jar new file mode 100644 index 0000000..026ab56 Binary files /dev/null and b/dist/SwingMaterialDesign.jar differ diff --git a/dist/lib/AbsoluteLayout.jar b/dist/lib/AbsoluteLayout.jar new file mode 100644 index 0000000..cbf5975 Binary files /dev/null and b/dist/lib/AbsoluteLayout.jar differ diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties index f658ea7..976fdc1 100644 --- a/nbproject/genfiles.properties +++ b/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=9d503843 -build.xml.script.CRC32=0f910fe8 -build.xml.stylesheet.CRC32=8064a381@1.80.1.48 -# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. -# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=9d503843 -nbproject/build-impl.xml.script.CRC32=c18d0385 -nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48 +build.xml.data.CRC32=9d503843 +build.xml.script.CRC32=0f910fe8 +build.xml.stylesheet.CRC32=f85dc8f2@1.90.1.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=9d503843 +nbproject/build-impl.xml.script.CRC32=c18d0385 +nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48 diff --git a/nbproject/project.properties b/nbproject/project.properties index 8f39006..3c2eca3 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,74 +1,87 @@ -annotation.processing.enabled=true -annotation.processing.enabled.in.editor=false -annotation.processing.processor.options= -annotation.processing.processors.list= -annotation.processing.run.all.processors=true -annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output -build.classes.dir=${build.dir}/classes -build.classes.excludes=**/*.java,**/*.form -# This directory is removed when the project is cleaned: -build.dir=build -build.generated.dir=${build.dir}/generated -build.generated.sources.dir=${build.dir}/generated-sources -# Only compile against the classpath explicitly listed here: -build.sysclasspath=ignore -build.test.classes.dir=${build.dir}/test/classes -build.test.results.dir=${build.dir}/test/results -# Uncomment to specify the preferred debugger connection transport: -#debug.transport=dt_socket -debug.classpath=\ - ${run.classpath} -debug.test.classpath=\ - ${run.test.classpath} -# Files in build.classes.dir which should be excluded from distribution jar -dist.archive.excludes= -# This directory is removed when the project is cleaned: -dist.dir=dist -dist.jar=${dist.dir}/SwingMaterialDesign.jar -dist.javadoc.dir=${dist.dir}/javadoc -excludes= -includes=** -jar.compress=false -javac.classpath= -# Space-separated list of extra javac options -javac.compilerargs= -javac.deprecation=false -javac.external.vm=true -javac.processorpath=\ - ${javac.classpath} -javac.source=1.8 -javac.target=1.8 -javac.test.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir} -javac.test.processorpath=\ - ${javac.test.classpath} -javadoc.additionalparam= -javadoc.author=false -javadoc.encoding=${source.encoding} -javadoc.noindex=false -javadoc.nonavbar=false -javadoc.notree=false -javadoc.private=false -javadoc.splitindex=true -javadoc.use=true -javadoc.version=false -javadoc.windowtitle= -main.class=com.hq.swingmaterialdesign.SwingMaterialDesign -manifest.file=manifest.mf -meta.inf.dir=${src.dir}/META-INF -mkdist.disabled=false -platform.active=default_platform -run.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir} -# Space-separated list of JVM arguments used when running the project. -# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. -# To set system properties for unit tests define test-sys-prop.name=value: -run.jvmargs= -run.test.classpath=\ - ${javac.test.classpath}:\ - ${build.test.classes.dir} -source.encoding=UTF-8 -src.dir=src -test.src.dir=test +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processor.options= +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.modulepath=\ + ${run.modulepath} +debug.test.classpath=\ + ${run.test.classpath} +debug.test.modulepath=\ + ${run.test.modulepath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/SwingMaterialDesign.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +includes=** +jar.compress=false +javac.classpath=\ + \# Space-separated list of extra javac options:\ + ${libs.absolutelayout.classpath} +javac.compilerargs= +javac.deprecation=false +javac.external.vm=true +javac.modulepath= +javac.processormodulepath= +javac.processorpath=\ + ${javac.classpath} +javac.source=1.8 +javac.target=1.8 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.modulepath=\ + ${javac.modulepath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=com.hq.swingmaterialdesign.MainView +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.modulepath=\ + ${javac.modulepath} +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +run.test.modulepath=\ + ${javac.test.modulepath} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/resources/swingmd.gif b/resources/swingmd.gif new file mode 100644 index 0000000..ca36745 Binary files /dev/null and b/resources/swingmd.gif differ diff --git a/src/com/hq/swingmaterialdesign/JFrame_Main.form b/src/com/hq/swingmaterialdesign/JFrame_Main.form deleted file mode 100644 index b822508..0000000 --- a/src/com/hq/swingmaterialdesign/JFrame_Main.form +++ /dev/null @@ -1,342 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/com/hq/swingmaterialdesign/JFrame_Main.java b/src/com/hq/swingmaterialdesign/JFrame_Main.java deleted file mode 100644 index 056f8f1..0000000 --- a/src/com/hq/swingmaterialdesign/JFrame_Main.java +++ /dev/null @@ -1,331 +0,0 @@ -package com.hq.swingmaterialdesign; - -import com.hq.swingmaterialdesign.materialdesign.MaterialButton; -import com.hq.swingmaterialdesign.materialdesign.MaterialPanel; -import com.hq.swingmaterialdesign.materialdesign.MaterialComboBox; -import com.hq.swingmaterialdesign.materialdesign.MaterialTextField; -import com.hq.swingmaterialdesign.materialdesign.resource.MaterialColor; -import com.hq.swingmaterialdesign.materialdesign.resource.MaterialIcons; -import com.hq.swingmaterialdesign.materialdesign.resource.Roboto; -import java.awt.event.MouseEvent; -import javax.swing.JFrame; -import javax.swing.JOptionPane; - -/** - * - * @author bilux (i.bilux@gmail.com) - */ -public class JFrame_Main extends javax.swing.JFrame { - - /** - * Creates new form JFrame_Main - */ - public JFrame_Main() { - initComponents(); - //jButton_Main1.setFont(MaterialIcons.ICON_FONT.deriveFont(20f)); - ((MaterialButton) jButton_Main).setType(MaterialButton.Type.FLAT); - ((MaterialTextField) jTextField1).setLabel("Swing Material Design Text Field"); - - String x = String.valueOf(MaterialIcons.EXIT_TO_APP); - this.setBackground(MaterialColor.TRANSPARENT); - } - - /** - * This method is called from within the constructor to initialize the form. - * WARNING: Do NOT modify this code. The content of this method is always - * regenerated by the Form Editor. - */ - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - jPanel_MainPanel = new MaterialPanel(); - jPanel_TitleBar = new javax.swing.JPanel(); - jButton_Close = new MaterialButton(); - jButton_Maximize = new MaterialButton(); - jButton_Minimize = new MaterialButton(); - jLabel1 = new javax.swing.JLabel(); - jPanel_Main = new MaterialPanel(); - jLabel2 = new javax.swing.JLabel(); - jComboBox1 = new MaterialComboBox<>(); - jTextField1 = new MaterialTextField(); - jButton_Main = new MaterialButton(); - jButton_Main1 = new MaterialButton(); - jToolBar_Status = new javax.swing.JToolBar(); - - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - setTitle("MobyDroid"); - setUndecorated(true); - - jPanel_TitleBar.setBackground(new java.awt.Color(153, 153, 153)); - jPanel_TitleBar.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() { - public void mouseDragged(java.awt.event.MouseEvent evt) { - jPanel_TitleBarMouseDragged(evt); - } - }); - jPanel_TitleBar.addMouseListener(new java.awt.event.MouseAdapter() { - public void mousePressed(java.awt.event.MouseEvent evt) { - jPanel_TitleBarMousePressed(evt); - } - public void mouseClicked(java.awt.event.MouseEvent evt) { - jPanel_TitleBarMouseClicked(evt); - } - }); - - jButton_Close.setBackground(new java.awt.Color(255, 51, 51)); - jButton_Close.setFont(MaterialIcons.ICON_FONT.deriveFont(20f)); - jButton_Close.setText(String.valueOf(MaterialIcons.CLOSE)); - jButton_Close.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); - jButton_Close.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton_CloseActionPerformed(evt); - } - }); - - jButton_Maximize.setBackground(new java.awt.Color(51, 153, 255)); - jButton_Maximize.setFont(MaterialIcons.ICON_FONT.deriveFont(20f)); - jButton_Maximize.setText(String.valueOf(MaterialIcons.FULLSCREEN)); - jButton_Maximize.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); - jButton_Maximize.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton_MaximizeActionPerformed(evt); - } - }); - - jButton_Minimize.setBackground(new java.awt.Color(255, 102, 0)); - jButton_Minimize.setFont(MaterialIcons.ICON_FONT.deriveFont(20f)); - jButton_Minimize.setText(String.valueOf(MaterialIcons.EXPAND_MORE)); - jButton_Minimize.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); - jButton_Minimize.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton_MinimizeActionPerformed(evt); - } - }); - - jLabel1.setFont(Roboto.BOLD.deriveFont(18f)); - jLabel1.setText("Swing Material Design"); - jLabel1.setToolTipText("MobyDroid"); - - javax.swing.GroupLayout jPanel_TitleBarLayout = new javax.swing.GroupLayout(jPanel_TitleBar); - jPanel_TitleBar.setLayout(jPanel_TitleBarLayout); - jPanel_TitleBarLayout.setHorizontalGroup( - jPanel_TitleBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel_TitleBarLayout.createSequentialGroup() - .addContainerGap() - .addComponent(jLabel1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 457, Short.MAX_VALUE) - .addComponent(jButton_Minimize, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(2, 2, 2) - .addComponent(jButton_Maximize, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(2, 2, 2) - .addComponent(jButton_Close, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(2, 2, 2)) - ); - jPanel_TitleBarLayout.setVerticalGroup( - jPanel_TitleBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel_TitleBarLayout.createSequentialGroup() - .addGap(2, 2, 2) - .addGroup(jPanel_TitleBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jButton_Minimize, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jButton_Maximize, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jButton_Close, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(2, 2, 2)) - ); - - jLabel2.setFont(Roboto.REGULAR.deriveFont(14f)); - jLabel2.setText("Material CheckBox :"); - jLabel2.setToolTipText("MobyDroid"); - - jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); - - jTextField1.setText("Swing Material Design"); - - javax.swing.GroupLayout jPanel_MainLayout = new javax.swing.GroupLayout(jPanel_Main); - jPanel_Main.setLayout(jPanel_MainLayout); - jPanel_MainLayout.setHorizontalGroup( - jPanel_MainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel_MainLayout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel_MainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jTextField1) - .addGroup(jPanel_MainLayout.createSequentialGroup() - .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 272, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(0, 0, Short.MAX_VALUE))) - .addContainerGap()) - ); - jPanel_MainLayout.setVerticalGroup( - jPanel_MainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel_MainLayout.createSequentialGroup() - .addGap(31, 31, 31) - .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(70, 70, 70) - .addGroup(jPanel_MainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addContainerGap(196, Short.MAX_VALUE)) - ); - - jButton_Main.setBackground(new java.awt.Color(51, 153, 255)); - jButton_Main.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N - jButton_Main.setText("Flat Button"); - jButton_Main.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); - jButton_Main.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton_MainActionPerformed(evt); - } - }); - - jButton_Main1.setBackground(new java.awt.Color(51, 153, 255)); - jButton_Main1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N - jButton_Main1.setText("Default Button"); - jButton_Main1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); - jButton_Main1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton_Main1ActionPerformed(evt); - } - }); - - jToolBar_Status.setFloatable(false); - jToolBar_Status.setRollover(true); - - javax.swing.GroupLayout jPanel_MainPanelLayout = new javax.swing.GroupLayout(jPanel_MainPanel); - jPanel_MainPanel.setLayout(jPanel_MainPanelLayout); - jPanel_MainPanelLayout.setHorizontalGroup( - jPanel_MainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel_MainPanelLayout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel_MainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jButton_Main1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jButton_Main, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addGap(18, 18, 18) - .addComponent(jPanel_Main, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - .addComponent(jPanel_TitleBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jToolBar_Status, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - ); - jPanel_MainPanelLayout.setVerticalGroup( - jPanel_MainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel_MainPanelLayout.createSequentialGroup() - .addComponent(jPanel_TitleBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel_MainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel_MainPanelLayout.createSequentialGroup() - .addGap(59, 59, 59) - .addComponent(jButton_Main, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(52, 52, 52) - .addComponent(jButton_Main1, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addComponent(jPanel_Main, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jToolBar_Status, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(0, 0, 0)) - ); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jPanel_MainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(0, 0, 0) - .addComponent(jPanel_MainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGap(0, 0, 0)) - ); - - pack(); - }// //GEN-END:initComponents - - private void jButton_MainActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_MainActionPerformed - // TODO add your handling code here: - }//GEN-LAST:event_jButton_MainActionPerformed - - private void jButton_CloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_CloseActionPerformed - //this.processWindowEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)); - exitHandle(); - }//GEN-LAST:event_jButton_CloseActionPerformed - - private void jButton_MaximizeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_MaximizeActionPerformed - maximizeHandle(); - }//GEN-LAST:event_jButton_MaximizeActionPerformed - - private void jButton_MinimizeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_MinimizeActionPerformed - this.setExtendedState(this.getExtendedState() | JFrame.ICONIFIED); - }//GEN-LAST:event_jButton_MinimizeActionPerformed - - private void jPanel_TitleBarMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel_TitleBarMouseDragged - int x = evt.getXOnScreen(); - int y = evt.getYOnScreen(); - // Move frame by the mouse delta - setLocation(getLocationOnScreen().x + x - lastX, getLocationOnScreen().y + y - lastY); - lastX = x; - lastY = y; - }//GEN-LAST:event_jPanel_TitleBarMouseDragged - - private void jPanel_TitleBarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel_TitleBarMouseClicked - if (evt.getButton() == MouseEvent.BUTTON1 && evt.getClickCount() == 2) { - maximizeHandle(); - } - }//GEN-LAST:event_jPanel_TitleBarMouseClicked - - private int lastX = 0; - private int lastY = 0; - private void jPanel_TitleBarMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel_TitleBarMousePressed - if (evt.getButton() == MouseEvent.BUTTON1 && (this.getExtendedState() & JFrame.MAXIMIZED_BOTH) != JFrame.MAXIMIZED_BOTH) { - lastX = evt.getXOnScreen(); - lastY = evt.getYOnScreen(); - } - }//GEN-LAST:event_jPanel_TitleBarMousePressed - - private void jButton_Main1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_Main1ActionPerformed - // TODO add your handling code here: - }//GEN-LAST:event_jButton_Main1ActionPerformed - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton jButton_Close; - private javax.swing.JButton jButton_Main; - private javax.swing.JButton jButton_Main1; - private javax.swing.JButton jButton_Maximize; - private javax.swing.JButton jButton_Minimize; - private javax.swing.JComboBox jComboBox1; - private javax.swing.JLabel jLabel1; - private javax.swing.JLabel jLabel2; - private javax.swing.JPanel jPanel_Main; - private javax.swing.JPanel jPanel_MainPanel; - private javax.swing.JPanel jPanel_TitleBar; - private javax.swing.JTextField jTextField1; - private javax.swing.JToolBar jToolBar_Status; - // End of variables declaration//GEN-END:variables - - /** - * - */ - private void exitHandle() { - // ask - Object[] options = {"Yes", "No"}; - int retStatus = JOptionPane.showOptionDialog(this, "Are you sure ?", "Exit", - JOptionPane.YES_NO_OPTION, - JOptionPane.QUESTION_MESSAGE, - null, //do not use a custom Icon - options, //the titles of buttons - options[1]); //default button title - if (retStatus == 0) { - System.exit(0); - } - } - - /** - * - */ - private void maximizeHandle() { - if ((this.getExtendedState() & JFrame.MAXIMIZED_BOTH) == JFrame.MAXIMIZED_BOTH) { - this.setExtendedState(this.getExtendedState() & ~JFrame.MAXIMIZED_BOTH); - } else { - this.setExtendedState(this.getExtendedState() | JFrame.MAXIMIZED_BOTH); - } - } -} diff --git a/src/com/hq/swingmaterialdesign/MainView.form b/src/com/hq/swingmaterialdesign/MainView.form new file mode 100644 index 0000000..3c6d5cb --- /dev/null +++ b/src/com/hq/swingmaterialdesign/MainView.form @@ -0,0 +1,360 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/hq/swingmaterialdesign/MainView.java b/src/com/hq/swingmaterialdesign/MainView.java new file mode 100644 index 0000000..e1ee96c --- /dev/null +++ b/src/com/hq/swingmaterialdesign/MainView.java @@ -0,0 +1,306 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.hq.swingmaterialdesign; + +import com.hq.swingmaterialdesign.materialdesign.resource.MaterialIcons; +import java.awt.Graphics; +import java.awt.Image; +import javax.swing.ImageIcon; + +/** + * + * @author abner + */ +public class MainView extends javax.swing.JFrame { + int xMouse, yMouse; + /** + * Creates new form MainView + */ + public MainView() { + initComponents(); + this.setLocationRelativeTo(null); + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jPanel1 = new javax.swing.JPanel(); + mPasswordField1 = new com.hq.swingmaterialdesign.materialdesign.MPasswordField(); + mButton1 = new com.hq.swingmaterialdesign.materialdesign.MButton(); + mTextField1 = new com.hq.swingmaterialdesign.materialdesign.MTextField(); + mButton2 = new com.hq.swingmaterialdesign.materialdesign.MButton(); + mComboBox1 = new com.hq.swingmaterialdesign.materialdesign.MComboBox(); + jPanel2 = new javax.swing.JPanel(); + mButton3 = new com.hq.swingmaterialdesign.materialdesign.MButton(); + jLabel1 = new javax.swing.JLabel(); + mGradientButton2 = new com.hq.swingmaterialdesign.materialdesign.MGradientButton(); + mGradientPanel1 = new com.hq.swingmaterialdesign.materialdesign.MGradientPanel(); + mFormattedTextField1 = new com.hq.swingmaterialdesign.materialdesign.MFormattedTextField(); + jPanel3 = new javax.swing.JPanel(); + mToggleButton1 = new com.hq.swingmaterialdesign.materialdesign.MToggleButton(); + mToggleButton2 = new com.hq.swingmaterialdesign.materialdesign.MToggleButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setBackground(new java.awt.Color(255, 255, 255)); + setUndecorated(true); + + jPanel1.setBackground(new java.awt.Color(255, 255, 255)); + jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); + + mPasswordField1.setEchoChar('\u25cf'); + mPasswordField1.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N + mPasswordField1.setLabel("Password"); + jPanel1.add(mPasswordField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(32, 135, 372, 60)); + + mButton1.setBackground(new java.awt.Color(204, 204, 204)); + mButton1.setBorder(null); + mButton1.setText("A simple button"); + mButton1.setBorderRadius(50); + mButton1.setFont(new java.awt.Font("Nunito Black", 0, 14)); // NOI18N + mButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + mButton1ActionPerformed(evt); + } + }); + jPanel1.add(mButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 340, 220, 50)); + + mTextField1.setLabel("Username"); + jPanel1.add(mTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(32, 69, 372, 60)); + + mButton2.setBackground(new java.awt.Color(51, 51, 51)); + mButton2.setBorder(null); + mButton2.setText("Another button"); + mButton2.setBorderRadius(50); + mButton2.setFont(new java.awt.Font("Nunito Black", 0, 14)); // NOI18N + mButton2.setType(com.hq.swingmaterialdesign.materialdesign.MButton.Type.FLAT); + mButton2.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + mButton2ActionPerformed(evt); + } + }); + jPanel1.add(mButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(360, 340, 220, 50)); + + mComboBox1.setForeground(new java.awt.Color(109, 109, 109)); + mComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Select gender", "Male", "Female", "Non binary" })); + mComboBox1.setAccent(new java.awt.Color(0, 120, 215)); + jPanel1.add(mComboBox1, new org.netbeans.lib.awtextra.AbsoluteConstraints(32, 206, 372, 51)); + + jPanel2.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() { + public void mouseDragged(java.awt.event.MouseEvent evt) { + jPanel2MouseDragged(evt); + } + }); + jPanel2.addMouseListener(new java.awt.event.MouseAdapter() { + public void mousePressed(java.awt.event.MouseEvent evt) { + jPanel2MousePressed(evt); + } + public void mouseReleased(java.awt.event.MouseEvent evt) { + jPanel2MouseReleased(evt); + } + }); + + mButton3.setText(String.valueOf(MaterialIcons.CLOSE)); + mButton3.setFont(MaterialIcons.ICON_FONT.deriveFont(20f)); + mButton3.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + mButton3ActionPerformed(evt); + } + }); + + jLabel1.setFont(new java.awt.Font("Nunito ExtraBold", 0, 14)); // NOI18N + jLabel1.setText("A modern material design form Swing"); + + javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); + jPanel2.setLayout(jPanel2Layout); + jPanel2Layout.setHorizontalGroup( + jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() + .addGap(27, 27, 27) + .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 288, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(mButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(12, 12, 12)) + ); + jPanel2Layout.setVerticalGroup( + jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel2Layout.createSequentialGroup() + .addGap(6, 6, 6) + .addComponent(mButton3, javax.swing.GroupLayout.DEFAULT_SIZE, 40, Short.MAX_VALUE) + .addGap(5, 5, 5)) + .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + ); + + jPanel1.add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 599, -1)); + + mGradientButton2.setForeground(new java.awt.Color(255, 255, 255)); + mGradientButton2.setText("A gradient button"); + mGradientButton2.setBorderRadius(50); + mGradientButton2.setFont(new java.awt.Font("Nunito ExtraBold", 0, 14)); // NOI18N + mGradientButton2.setType(com.hq.swingmaterialdesign.materialdesign.MGradientButton.Type.RAISED); + mGradientButton2.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + mGradientButton2ActionPerformed(evt); + } + }); + jPanel1.add(mGradientButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(360, 280, 220, 50)); + + mGradientPanel1.setBackground(new java.awt.Color(255, 255, 255)); + mGradientPanel1.setBorderRadius(120); + mGradientPanel1.setFillBackground(false); + mGradientPanel1.setFillImage(true); + + javax.swing.GroupLayout mGradientPanel1Layout = new javax.swing.GroupLayout(mGradientPanel1); + mGradientPanel1.setLayout(mGradientPanel1Layout); + mGradientPanel1Layout.setHorizontalGroup( + mGradientPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 120, Short.MAX_VALUE) + ); + mGradientPanel1Layout.setVerticalGroup( + mGradientPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 120, Short.MAX_VALUE) + ); + + jPanel1.add(mGradientPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(440, 70, 120, 120)); + + mFormattedTextField1.setText("mFormattedTextField1"); + jPanel1.add(mFormattedTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 270, 270, 60)); + + jPanel3.setBackground(new java.awt.Color(0, 102, 102)); + jPanel3.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); + + mToggleButton1.setForeground(new java.awt.Color(255, 255, 255)); + mToggleButton1.setText("Menu option 2"); + mToggleButton1.setBorderRadius(0); + mToggleButton1.setEndColor(new java.awt.Color(0, 102, 102)); + mToggleButton1.setFont(new java.awt.Font("Nunito SemiBold", 0, 16)); // NOI18N + mToggleButton1.setHoverEndColor(new java.awt.Color(0, 102, 102)); + mToggleButton1.setHoverStartColor(new java.awt.Color(0, 153, 153)); + mToggleButton1.setIndicatorThickness(4); + mToggleButton1.setSelectedColor(new java.awt.Color(0, 153, 153)); + mToggleButton1.setStartColor(new java.awt.Color(0, 102, 102)); + mToggleButton1.setType(com.hq.swingmaterialdesign.materialdesign.MToggleButton.Type.FLAT); + jPanel3.add(mToggleButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 190, 230, 54)); + + mToggleButton2.setForeground(new java.awt.Color(255, 255, 255)); + mToggleButton2.setText("menu option 1"); + mToggleButton2.setBorderRadius(0); + mToggleButton2.setEndColor(new java.awt.Color(0, 102, 102)); + mToggleButton2.setFont(new java.awt.Font("Nunito SemiBold", 0, 16)); // NOI18N + mToggleButton2.setHoverEndColor(new java.awt.Color(0, 102, 102)); + mToggleButton2.setHoverStartColor(new java.awt.Color(0, 153, 153)); + mToggleButton2.setIndicatorThickness(4); + mToggleButton2.setSelectedColor(new java.awt.Color(0, 153, 153)); + mToggleButton2.setStartColor(new java.awt.Color(0, 102, 102)); + mToggleButton2.setType(com.hq.swingmaterialdesign.materialdesign.MToggleButton.Type.FLAT); + jPanel3.add(mToggleButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 140, 230, 54)); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGap(0, 0, 0) + .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 414, Short.MAX_VALUE) + .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + ); + + pack(); + }// //GEN-END:initComponents + + private void mButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mButton3ActionPerformed + this.dispose(); + }//GEN-LAST:event_mButton3ActionPerformed + + private void jPanel2MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel2MousePressed + xMouse = evt.getX(); + yMouse = evt.getY(); + }//GEN-LAST:event_jPanel2MousePressed + + private void jPanel2MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel2MouseReleased + setOpacity((float) 1.0); + }//GEN-LAST:event_jPanel2MouseReleased + + private void jPanel2MouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel2MouseDragged + setLocation(evt.getXOnScreen() - xMouse, evt.getYOnScreen() - yMouse); + setOpacity((float) 0.9); + }//GEN-LAST:event_jPanel2MouseDragged + + private void mGradientButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mGradientButton2ActionPerformed + mToggleButton1.unselect(); + }//GEN-LAST:event_mGradientButton2ActionPerformed + + private void mButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mButton1ActionPerformed + mToggleButton1.unselect(); + }//GEN-LAST:event_mButton1ActionPerformed + + private void mButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mButton2ActionPerformed + mToggleButton1.unselect(); + }//GEN-LAST:event_mButton2ActionPerformed + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* Set the Nimbus look and feel */ + // + /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. + * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ClassNotFoundException ex) { + java.util.logging.Logger.getLogger(MainView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(MainView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(MainView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(MainView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + /* Create and display the form */ + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + new MainView().setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JLabel jLabel1; + private javax.swing.JPanel jPanel1; + private javax.swing.JPanel jPanel2; + private javax.swing.JPanel jPanel3; + private com.hq.swingmaterialdesign.materialdesign.MButton mButton1; + private com.hq.swingmaterialdesign.materialdesign.MButton mButton2; + private com.hq.swingmaterialdesign.materialdesign.MButton mButton3; + private com.hq.swingmaterialdesign.materialdesign.MComboBox mComboBox1; + private com.hq.swingmaterialdesign.materialdesign.MFormattedTextField mFormattedTextField1; + private com.hq.swingmaterialdesign.materialdesign.MGradientButton mGradientButton2; + private com.hq.swingmaterialdesign.materialdesign.MGradientPanel mGradientPanel1; + private com.hq.swingmaterialdesign.materialdesign.MPasswordField mPasswordField1; + private com.hq.swingmaterialdesign.materialdesign.MTextField mTextField1; + private com.hq.swingmaterialdesign.materialdesign.MToggleButton mToggleButton1; + private com.hq.swingmaterialdesign.materialdesign.MToggleButton mToggleButton2; + // End of variables declaration//GEN-END:variables +} diff --git a/src/com/hq/swingmaterialdesign/SwingMaterialDesign.java b/src/com/hq/swingmaterialdesign/SwingMaterialDesign.java deleted file mode 100644 index 9833e49..0000000 --- a/src/com/hq/swingmaterialdesign/SwingMaterialDesign.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.hq.swingmaterialdesign; - -/** - * - * @author bilux (i.bilux@gmail.com) - */ -public class SwingMaterialDesign { - - /** - * @param args the command line arguments - */ - public static void main(String[] args) { - // Set the Metal look and feel - // - try { - for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { - if ("Metal".equals(info.getName())) { - javax.swing.UIManager.setLookAndFeel(info.getClassName()); - break; - } - } - } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) { - //java.util.logging.Logger.getLogger(JDialog_AddProduct.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } - // - - // Create and display the form - JFrame_Main jFrame_Main = new JFrame_Main(); - - java.awt.EventQueue.invokeLater(() -> { - jFrame_Main.setVisible(true); - }); - } - -} diff --git a/src/com/hq/swingmaterialdesign/images/profile.jpg b/src/com/hq/swingmaterialdesign/images/profile.jpg new file mode 100644 index 0000000..539541b Binary files /dev/null and b/src/com/hq/swingmaterialdesign/images/profile.jpg differ diff --git a/src/com/hq/swingmaterialdesign/materialdesign/ElevationEffect.java b/src/com/hq/swingmaterialdesign/materialdesign/ElevationEffect.java index 275be25..0bbcddc 100644 --- a/src/com/hq/swingmaterialdesign/materialdesign/ElevationEffect.java +++ b/src/com/hq/swingmaterialdesign/materialdesign/ElevationEffect.java @@ -1,144 +1,144 @@ -package com.hq.swingmaterialdesign.materialdesign; - -import com.hq.swingmaterialdesign.materialdesign.animation.AnimationListener; -import com.hq.swingmaterialdesign.materialdesign.animation.Animator; -import javax.swing.*; -import java.awt.*; -import java.awt.geom.RoundRectangle2D; - -/** - * An elevation effect. - * - * @author bilux (i.bilux@gmail.com) - */ -public class ElevationEffect { - - protected final JComponent target; - protected final MaterialShadow shadow; - protected double level; - protected int borderRadius; - private final Animator animator; - private double startLevel; - private double targetLevel; - - private ElevationEffect(final JComponent component, int elevationLevel) { - target = component; - level = elevationLevel; - targetLevel = elevationLevel; - shadow = new MaterialShadow(); - animator = new Animator(new AnimationListener() { - @Override - public void onStart() { - - } - - @Override - public void onAnimation(double percent) { - level = startLevel + ((targetLevel - startLevel) * percent); - //System.out.println("level: " + level); - target.repaint(); - } - - @Override - public void onEnd() { - level = targetLevel; - target.repaint(); - } - - @Override - public void onStop() { - level = targetLevel; - target.repaint(); - } - }) - .setDelay(0) - .setDuration(500); - } - - /** - * Gets the elevation level. - * - * @return elevation level [0~5] - */ - public double getLevel() { - return level; - } - - /** - * Sets the elevation newLevel. - * - * @param elevationLevel elevation newLevel [0~5] - */ - public void setLevel(int elevationLevel) { - if (target.isShowing()) { - if (elevationLevel != level) { - animator.stop(); - startLevel = level; - targetLevel = elevationLevel; - animator.start(); - } - } else { - this.level = elevationLevel; - } - } - - /** - * Gets the current border radius of the component casting a shadow. This - * should be updated by the target component if such a property exists for - * it and is modified. - * - * @return the current border radius casted on the shadow, in pixels. - */ - public int getBorderRadius() { - return borderRadius; - } - - /** - * Sets the current border radius of the component casting a shadow. This - * should be updated by the target component if such a property exists for - * it and is modified. - * - * @param borderRadius the new border radius casted on the shadow, in - * pixels. - */ - public void setBorderRadius(int borderRadius) { - this.borderRadius = borderRadius; - } - - /** - * Paints this effect. - * - * @param g canvas - */ - public void paint(Graphics g) { - Graphics2D g2 = (Graphics2D) g; - g2.setBackground(target.getParent().getBackground()); - g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); - if (target instanceof MaterialButton && (((MaterialButton) target).getType() == MaterialButton.Type.FLAT)) { - g2.setColor(MaterialUtils.brighten(target.getBackground(), (int) (((66.0 / (1 + Math.exp(-2.0 * level))) - 33.0)))); - g2.fill(new RoundRectangle2D.Float(0, 0, target.getWidth(), target.getHeight(), borderRadius, borderRadius)); - } else { - g.drawImage(shadow.render(target.getWidth(), target.getHeight(), borderRadius, level), 0, 0, null); - } - } - - /** - * Creates an elevation effect for the given component. Each component is - * responsible of calling {@link #paint(Graphics)} in order to display the - * effect. For this to work, there should be an offset between the contents - * of the component and its actual bounds, these values can be found in - * {@link MaterialShadow}. - * - * @param target the target of the resulting {@code ElevationEffect} - * @param level the initial elevation level [0~5] - * @return an {@code ElevationEffect} object providing support for painting - * ripples - * @see MaterialShadow#OFFSET_TOP - * @see MaterialShadow#OFFSET_BOTTOM - * @see MaterialShadow#OFFSET_LEFT - * @see MaterialShadow#OFFSET_RIGHT - */ - public static ElevationEffect applyTo(JComponent target, int level) { - return new ElevationEffect(target, level); - } -} +package com.hq.swingmaterialdesign.materialdesign; + +import com.hq.swingmaterialdesign.materialdesign.animation.AnimationListener; +import com.hq.swingmaterialdesign.materialdesign.animation.Animator; +import javax.swing.*; +import java.awt.*; +import java.awt.geom.RoundRectangle2D; + +/** + * An elevation effect. + * + * @author bilux (i.bilux@gmail.com) + */ +public class ElevationEffect { + + protected final JComponent target; + protected final MaterialShadow shadow; + protected double level; + protected int borderRadius; + private final Animator animator; + private double startLevel; + private double targetLevel; + + private ElevationEffect(final JComponent component, int elevationLevel) { + target = component; + level = elevationLevel; + targetLevel = elevationLevel; + shadow = new MaterialShadow(); + animator = new Animator(new AnimationListener() { + @Override + public void onStart() { + + } + + @Override + public void onAnimation(double percent) { + level = startLevel + ((targetLevel - startLevel) * percent); + //System.out.println("level: " + level); + target.repaint(); + } + + @Override + public void onEnd() { + level = targetLevel; + target.repaint(); + } + + @Override + public void onStop() { + level = targetLevel; + target.repaint(); + } + }) + .setDelay(0) + .setDuration(1); + } + + /** + * Gets the elevation level. + * + * @return elevation level [0~5] + */ + public double getLevel() { + return level; + } + + /** + * Sets the elevation newLevel. + * + * @param elevationLevel elevation newLevel [0~5] + */ + public void setLevel(int elevationLevel) { + if (target.isShowing()) { + if (elevationLevel != level) { + animator.stop(); + startLevel = level; + targetLevel = elevationLevel; + animator.start(); + } + } else { + this.level = elevationLevel; + } + } + + /** + * Gets the current border radius of the component casting a shadow. This + * should be updated by the target component if such a property exists for + * it and is modified. + * + * @return the current border radius casted on the shadow, in pixels. + */ + public int getBorderRadius() { + return borderRadius; + } + + /** + * Sets the current border radius of the component casting a shadow. This + * should be updated by the target component if such a property exists for + * it and is modified. + * + * @param borderRadius the new border radius casted on the shadow, in + * pixels. + */ + public void setBorderRadius(int borderRadius) { + this.borderRadius = borderRadius; + } + + /** + * Paints this effect. + * + * @param g canvas + */ + public void paint(Graphics g) { + Graphics2D g2 = (Graphics2D) g; + g2.setBackground(target.getParent().getBackground()); + g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); + if (target instanceof MButton && (((MButton) target).getType() == MButton.Type.FLAT)) { + g2.setColor(MaterialUtils.brighten(target.getBackground(), (int) (((66.0 / (1 + Math.exp(-2.0 * level))) - 33.0)))); + g2.fill(new RoundRectangle2D.Float(0, 0, target.getWidth(), target.getHeight(), borderRadius, borderRadius)); + } else { + g.drawImage(shadow.render(target.getWidth(), target.getHeight(), borderRadius, level), 0, 0, null); + } + } + + /** + * Creates an elevation effect for the given component. Each component is + * responsible of calling {@link #paint(Graphics)} in order to display the + * effect. For this to work, there should be an offset between the contents + * of the component and its actual bounds, these values can be found in + * {@link MaterialShadow}. + * + * @param target the target of the resulting {@code ElevationEffect} + * @param level the initial elevation level [0~5] + * @return an {@code ElevationEffect} object providing support for painting + * ripples + * @see MaterialShadow#OFFSET_TOP + * @see MaterialShadow#OFFSET_BOTTOM + * @see MaterialShadow#OFFSET_LEFT + * @see MaterialShadow#OFFSET_RIGHT + */ + public static ElevationEffect applyTo(JComponent target, int level) { + return new ElevationEffect(target, level); + } +} diff --git a/src/com/hq/swingmaterialdesign/materialdesign/MaterialButton.java b/src/com/hq/swingmaterialdesign/materialdesign/MButton.java similarity index 92% rename from src/com/hq/swingmaterialdesign/materialdesign/MaterialButton.java rename to src/com/hq/swingmaterialdesign/materialdesign/MButton.java index 966bd5a..7edb309 100644 --- a/src/com/hq/swingmaterialdesign/materialdesign/MaterialButton.java +++ b/src/com/hq/swingmaterialdesign/materialdesign/MButton.java @@ -1,272 +1,274 @@ -package com.hq.swingmaterialdesign.materialdesign; - -import com.hq.swingmaterialdesign.materialdesign.resource.MaterialColor; -import java.awt.Color; -import java.awt.Cursor; -import java.awt.FontMetrics; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.RenderingHints; -import javax.swing.JButton; -import javax.swing.plaf.basic.BasicButtonUI; -import java.awt.event.FocusEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.geom.RoundRectangle2D; -import javax.swing.JComponent; - -/** - * A Material Design button. - * - * @author bilux (i.bilux@gmail.com) - */ -public class MaterialButton extends JButton { - - private RippleEffect ripple; - private ElevationEffect elevation; - private Type type = Type.DEFAULT; - private boolean isMousePressed = false; - private boolean isMouseOver = false; - private Color rippleColor = Color.WHITE; - private Cursor cursor = super.getCursor(); - private int borderRadius = 2; - - /** - * Creates a new button. - */ - public MaterialButton() { - ripple = RippleEffect.applyTo(this); - elevation = ElevationEffect.applyTo(this, 0); - setOpaque(false); - - addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(MouseEvent mouseEvent) { - isMousePressed = true; - elevation.setLevel(getElevation()); - } - - @Override - public void mouseReleased(MouseEvent mouseEvent) { - isMousePressed = false; - elevation.setLevel(getElevation()); - } - - @Override - public void mouseEntered(MouseEvent e) { - isMouseOver = true; - elevation.setLevel(getElevation()); - } - - @Override - public void mouseExited(MouseEvent e) { - isMouseOver = false; - elevation.setLevel(getElevation()); - } - }); - - setUI(new BasicButtonUI() { - @Override - public boolean contains(JComponent c, int x, int y) { - return x > MaterialShadow.OFFSET_LEFT && y > MaterialShadow.OFFSET_TOP - && x < getWidth() - MaterialShadow.OFFSET_RIGHT && y < getHeight() - MaterialShadow.OFFSET_BOTTOM; - } - }); - } - - /** - * Gets the type of this button. - * - * @return the type of this button - * @see Type - */ - public Type getType() { - return type; - } - - /** - * Sets the type of this button. - * - * @param type the type of this button - * @see Type - */ - public void setType(Type type) { - this.type = type; - repaint(); - } - - /** - * Sets the background color of this button. - *

- * Keep on mind that setting a background color in a Material component like - * this will also set the foreground color to either white or black and the - * ripple color to a brighter or darker shade of the color, depending of how - * bright or dark is the chosen background color. If you want to use a - * custom foreground color and ripple color, ensure the background color has - * been set first. - *

- * NOTE: It is up to the look and feel to honor this property, some - * may choose to ignore it. To avoid any conflicts, using the - * - * Metal Look and Feel is recommended. - * - * @param bg - */ - @Override - public void setBackground(Color bg) { - super.setBackground(bg); - setForeground(MaterialUtils.isDark(bg) ? MaterialColor.WHITE : MaterialColor.BLACK); - setRippleColor(MaterialUtils.isDark(bg) ? MaterialColor.WHITE : MaterialUtils.darken(MaterialUtils.darken(bg))); - } - - /** - * Gets the ripple color. - * - * @return the ripple color - */ - public Color getRippleColor() { - return rippleColor; - } - - /** - * Sets the ripple color. You should only do this for flat buttons. - * - * @param rippleColor the ripple color - */ - public void setRippleColor(Color rippleColor) { - this.rippleColor = rippleColor; - } - - /** - * Gets the current border radius of this button. - * - * @return the current border radius of this button, in pixels. - */ - public int getBorderRadius() { - return borderRadius; - } - - /** - * Sets the border radius of this button. You can define a custom radius in - * order to get some rounded corners in your button, making it look like a - * pill or even a circular action button. - * - * @param borderRadius the new border radius of this button, in pixels. - */ - public void setBorderRadius(int borderRadius) { - this.borderRadius = borderRadius; - elevation.setBorderRadius(borderRadius); - } - - @Override - public void setEnabled(boolean b) { - super.setEnabled(b); - super.setCursor(b ? cursor : Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - } - - @Override - public void setCursor(Cursor cursor) { - super.setCursor(cursor); - this.cursor = cursor; - } - - @Override - protected void processFocusEvent(FocusEvent focusEvent) { - super.processFocusEvent(focusEvent); - } - - @Override - protected void processMouseEvent(MouseEvent mouseEvent) { - super.processMouseEvent(mouseEvent); - } - - private int getElevation() { - if (isMousePressed) { - return 2; - } else if (type == Type.RAISED || isMouseOver) { - return 1; - } else { - return 0; - } - } - - @Override - protected void paintComponent(Graphics g) { - Graphics2D g2 = (Graphics2D) g; - g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); - - if ((type != Type.FLAT) && isEnabled()) { - elevation.paint(g); - g2.translate(MaterialShadow.OFFSET_LEFT, MaterialShadow.OFFSET_TOP); - } - - int offset_lr; - int offset_td; - if (type == Type.FLAT) { - offset_td = 0; - offset_lr = 0; - } else { - offset_td = MaterialShadow.OFFSET_TOP + MaterialShadow.OFFSET_BOTTOM; - offset_lr = MaterialShadow.OFFSET_LEFT + MaterialShadow.OFFSET_RIGHT; - } - - if (isEnabled()) { - g2.setColor(getBackground()); - g2.fill(new RoundRectangle2D.Float(0, 0, getWidth() - offset_lr, getHeight() - offset_td, borderRadius, borderRadius)); - g2.setColor(new Color(rippleColor.getRed() / 255f, rippleColor.getBlue() / 255f, rippleColor.getBlue() / 255f, 0.12f)); - if (type == Type.FLAT) { - elevation.paint(g); - //g2.setColor(MaterialUtils.brighten(getBackground())); - //g2.fill(new RoundRectangle2D.Float(0, 0, getWidth() - offset_lr, getHeight() - offset_td, borderRadius, borderRadius)); - } - } else { - Color bg = getBackground(); - g2.setColor(new Color(bg.getRed() / 255f, bg.getGreen() / 255f, bg.getBlue() / 255f, 0.6f)); - g2.fill(new RoundRectangle2D.Float(0, 0, getWidth() - offset_lr, getHeight() - offset_td, borderRadius * 2, borderRadius * 2)); - } - - FontMetrics metrics = g.getFontMetrics(getFont()); - int x = (getWidth() - offset_lr - metrics.stringWidth(getText().toUpperCase())) / 2; - int y = (getHeight() - offset_td - metrics.getHeight()) / 2 + metrics.getAscent(); - g2.setFont(getFont()); - if (isEnabled()) { - g2.setColor(getForeground()); - } else { - Color fg = getForeground(); - g2.setColor(new Color(fg.getRed() / 255f, fg.getGreen() / 255f, fg.getBlue() / 255f, 0.6f)); - } - g2.drawString(getText().toUpperCase(), x, y); - - if (isEnabled()) { - g2.setClip(new RoundRectangle2D.Float(0, 0, getWidth() - offset_lr, getHeight() - offset_td, Math.max(borderRadius * 2 - 4, 0), Math.max(borderRadius * 2 - 4, 0))); - g2.setColor(rippleColor); - ripple.paint(g2); - } - } - - @Override - protected void paintBorder(Graphics g) { - //intentionally left blank - } - - /** - * Button types. - */ - public enum Type { - /** - * A default button. - */ - DEFAULT, - /** - * A raised button. Raised buttons have a shadow even if they are not - * focused. - */ - RAISED, - /** - * A flat button. Flat buttons don't have shadows and are typically - * transparent. - */ - FLAT - } -} +package com.hq.swingmaterialdesign.materialdesign; + +import com.hq.swingmaterialdesign.materialdesign.resource.MaterialColor; +import java.awt.Color; +import java.awt.Cursor; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import javax.swing.JButton; +import javax.swing.plaf.basic.BasicButtonUI; +import java.awt.event.FocusEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.geom.RoundRectangle2D; +import javax.swing.JComponent; + +/** + * A material design button. + * + * + * @author abner (abner.js05@gmail.com) + */ +public class MButton extends JButton { + + private RippleEffect ripple; + private ElevationEffect elevation; + private Type type = Type.DEFAULT; + private boolean isMousePressed = false; + private boolean isMouseOver = false; + private Color rippleColor = Color.WHITE; + private Cursor cursor = super.getCursor(); + private int borderRadius = 2; + + /** + * Creates a new button. + */ + public MButton() { + ripple = RippleEffect.applyTo(this); + elevation = ElevationEffect.applyTo(this, 0); + setOpaque(false); + setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + + addMouseListener(new MouseAdapter() { + @Override + public void mousePressed(MouseEvent mouseEvent) { + isMousePressed = true; + elevation.setLevel(getElevation()); + } + + @Override + public void mouseReleased(MouseEvent mouseEvent) { + isMousePressed = false; + elevation.setLevel(getElevation()); + } + + @Override + public void mouseEntered(MouseEvent e) { + isMouseOver = true; + elevation.setLevel(getElevation()); + } + + @Override + public void mouseExited(MouseEvent e) { + isMouseOver = false; + elevation.setLevel(getElevation()); + } + }); + + setUI(new BasicButtonUI() { + @Override + public boolean contains(JComponent c, int x, int y) { + return x > MaterialShadow.OFFSET_LEFT && y > MaterialShadow.OFFSET_TOP + && x < getWidth() - MaterialShadow.OFFSET_RIGHT && y < getHeight() - MaterialShadow.OFFSET_BOTTOM; + } + }); + } + + /** + * Gets the type of this button. + * + * @return the type of this button + * @see Type + */ + public Type getType() { + return type; + } + + /** + * Sets the type of this button. + * + * @param type the type of this button + * @see Type + */ + public void setType(Type type) { + this.type = type; + repaint(); + } + + /** + * Sets the background color of this button. + *

+ * Keep on mind that setting a background color in a Material component like + * this will also set the foreground color to either white or black and the + * ripple color to a brighter or darker shade of the color, depending of how + * bright or dark is the chosen background color. If you want to use a + * custom foreground color and ripple color, ensure the background color has + * been set first. + *

+ * NOTE: It is up to the look and feel to honor this property, some + * may choose to ignore it. To avoid any conflicts, using the + * + * Metal Look and Feel is recommended. + * + * @param bg + */ + @Override + public void setBackground(Color bg) { + super.setBackground(bg); + setForeground(MaterialUtils.isDark(bg) ? MaterialColor.WHITE : MaterialColor.BLACK); + setRippleColor(MaterialUtils.isDark(bg) ? MaterialColor.WHITE : MaterialUtils.darken(MaterialUtils.darken(bg))); + } + + /** + * Gets the ripple color. + * + * @return the ripple color + */ + public Color getRippleColor() { + return rippleColor; + } + + /** + * Sets the ripple color. You should only do this for flat buttons. + * + * @param rippleColor the ripple color + */ + public void setRippleColor(Color rippleColor) { + this.rippleColor = rippleColor; + } + + /** + * Gets the current border radius of this button. + * + * @return the current border radius of this button, in pixels. + */ + public int getBorderRadius() { + return borderRadius; + } + + /** + * Sets the border radius of this button. You can define a custom radius in + * order to get some rounded corners in your button, making it look like a + * pill or even a circular action button. + * + * @param borderRadius the new border radius of this button, in pixels. + */ + public void setBorderRadius(int borderRadius) { + this.borderRadius = borderRadius; + elevation.setBorderRadius(borderRadius); + } + + @Override + public void setEnabled(boolean b) { + super.setEnabled(b); + super.setCursor(b ? cursor : Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } + + @Override + public void setCursor(Cursor cursor) { + super.setCursor(cursor); + this.cursor = cursor; + } + + @Override + protected void processFocusEvent(FocusEvent focusEvent) { + super.processFocusEvent(focusEvent); + } + + @Override + protected void processMouseEvent(MouseEvent mouseEvent) { + super.processMouseEvent(mouseEvent); + } + + private int getElevation() { + if (isMousePressed) { + return 2; + } else if (type == Type.RAISED || isMouseOver) { + return 1; + } else { + return 0; + } + } + + @Override + protected void paintComponent(Graphics g) { + Graphics2D g2 = (Graphics2D) g; + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + + if ((type != Type.FLAT) && isEnabled()) { + elevation.paint(g); + g2.translate(MaterialShadow.OFFSET_LEFT, MaterialShadow.OFFSET_TOP); + } + + int offset_lr; + int offset_td; + if (type == Type.FLAT) { + offset_td = 0; + offset_lr = 0; + } else { + offset_td = MaterialShadow.OFFSET_TOP + MaterialShadow.OFFSET_BOTTOM; + offset_lr = MaterialShadow.OFFSET_LEFT + MaterialShadow.OFFSET_RIGHT; + } + + if (isEnabled()) { + g2.setColor(getBackground()); + g2.fill(new RoundRectangle2D.Float(0, 0, getWidth() - offset_lr, getHeight() - offset_td, borderRadius, borderRadius)); + g2.setColor(new Color(rippleColor.getRed() / 255f, rippleColor.getBlue() / 255f, rippleColor.getBlue() / 255f, 0.12f)); + if (type == Type.FLAT) { + elevation.paint(g); + //g2.setColor(MaterialUtils.brighten(getBackground())); + //g2.fill(new RoundRectangle2D.Float(0, 0, getWidth() - offset_lr, getHeight() - offset_td, borderRadius, borderRadius)); + } + } else { + Color bg = getBackground(); + g2.setColor(new Color(bg.getRed() / 255f, bg.getGreen() / 255f, bg.getBlue() / 255f, 0.6f)); + g2.fill(new RoundRectangle2D.Float(0, 0, getWidth() - offset_lr, getHeight() - offset_td, borderRadius * 2, borderRadius * 2)); + } + + FontMetrics metrics = g.getFontMetrics(getFont()); + int x = (getWidth() - offset_lr - metrics.stringWidth(getText().toUpperCase())) / 2; + int y = (getHeight() - offset_td - metrics.getHeight()) / 2 + metrics.getAscent(); + g2.setFont(getFont()); + if (isEnabled()) { + g2.setColor(getForeground()); + } else { + Color fg = getForeground(); + g2.setColor(new Color(fg.getRed() / 255f, fg.getGreen() / 255f, fg.getBlue() / 255f, 0.6f)); + } + g2.drawString(getText().toUpperCase(), x, y); + + if (isEnabled()) { + g2.setClip(new RoundRectangle2D.Float(0, 0, getWidth() - offset_lr, getHeight() - offset_td, Math.max(borderRadius - 6, 0), Math.max(borderRadius * 2 - 4, 0))); + g2.setColor(rippleColor); + ripple.paint(g2); + } + } + +// @Override +// protected void paintBorder(Graphics g) { +// //intentionally left blank +// } + + /** + * Button types. + */ + public enum Type { + /** + * A default button. + */ + DEFAULT, + /** + * A raised button. Raised buttons have a shadow even if they are not + * focused. + */ + RAISED, + /** + * A flat button. Flat buttons don't have shadows and are typically + * transparent. + */ + FLAT + } +} diff --git a/src/com/hq/swingmaterialdesign/materialdesign/MaterialComboBox.java b/src/com/hq/swingmaterialdesign/materialdesign/MComboBox.java similarity index 94% rename from src/com/hq/swingmaterialdesign/materialdesign/MaterialComboBox.java rename to src/com/hq/swingmaterialdesign/materialdesign/MComboBox.java index d620015..1d8e32f 100644 --- a/src/com/hq/swingmaterialdesign/materialdesign/MaterialComboBox.java +++ b/src/com/hq/swingmaterialdesign/materialdesign/MComboBox.java @@ -1,287 +1,287 @@ -package com.hq.swingmaterialdesign.materialdesign; - -import com.hq.swingmaterialdesign.materialdesign.resource.MaterialColor; -import static com.hq.swingmaterialdesign.materialdesign.MaterialTextField.HINT_OPACITY_MASK; -import static com.hq.swingmaterialdesign.materialdesign.MaterialTextField.LINE_OPACITY_MASK; -import com.hq.swingmaterialdesign.materialdesign.resource.Roboto; -import javax.swing.*; -import javax.swing.border.MatteBorder; -import javax.swing.plaf.basic.BasicComboBoxUI; -import javax.swing.plaf.basic.BasicComboPopup; -import javax.swing.plaf.basic.BasicScrollBarUI; -import javax.swing.plaf.basic.ComboPopup; -import java.awt.*; -import java.awt.event.FocusEvent; - -/** - * A Material Design combo box. - * - * - * @author bilux (i.bilux@gmail.com) - */ -public class MaterialComboBox extends JComboBox { - - private MaterialLine line = new MaterialLine(this); - private Color accentColor = MaterialColor.PINK_500; - private String hint = ""; - - public MaterialComboBox() { - setModel(new DefaultComboBoxModel<>()); - setRenderer(new FieldRenderer<>(this)); - setUI(new BasicComboBoxUI() { - @Override - protected ComboPopup createPopup() { - BasicComboPopup popupBox = new Popup(comboBox); - popupBox.getAccessibleContext().setAccessibleParent(comboBox); - return popupBox; - } - - @Override - protected JButton createArrowButton() { - JButton button = new javax.swing.plaf.basic.BasicArrowButton( - javax.swing.plaf.basic.BasicArrowButton.SOUTH, - MaterialColor.TRANSPARENT, - MaterialColor.TRANSPARENT, - MaterialColor.TRANSPARENT, - MaterialColor.TRANSPARENT); - button.setName("ComboBox.arrowButton"); - return button; - } - }); - setOpaque(false); - setBackground(MaterialColor.WHITE); - } - - /** - * Gets the color the label changes to when this {@code materialTextField} - * is focused. - * - * @return the {@code "Color"} currently in use for accent. The default - * value is {@link MaterialColor#PINK_500}. - */ - public Color getAccent() { - return accentColor; - } - - /** - * Sets the color the label changes to when this {@code materialTextField} - * is focused. The default value is {@link MaterialColor#PINK_500}. - * - * @param accentColor the {@code "Color"} that should be used for accent. - */ - public void setAccent(Color accentColor) { - this.accentColor = accentColor; - } - - /** - * Gets the hint text. The hint text is displayed when the list inside this - * combo box is empty or no element has been selected yet. - * - * @return hint text - */ - public String getHint() { - return hint; - } - - /** - * Sets the hint text. The hint text is displayed when the list inside this - * combo box is empty or no element has been selected yet. - * - * @param hint hint text - */ - public void setHint(String hint) { - this.hint = hint; - repaint(); - } - - @Override - protected void processFocusEvent(FocusEvent e) { - super.processFocusEvent(e); - line.update(); - } - - @Override - public void paint(Graphics g) { - Graphics2D g2 = (Graphics2D) g; - g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); - g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - - // paint text baground - g2.setColor(getBackground()); - g2.fillRect(0, 0, getWidth(), getHeight() - 4); - - // paint the selected item - g.setFont(Roboto.REGULAR.deriveFont(16f)); - g.setColor(getSelectedItem() == null ? MaterialUtils.applyAlphaMask(getForeground(), HINT_OPACITY_MASK) : getForeground()); - FontMetrics metrics = g.getFontMetrics(g.getFont()); - String text = getSelectedItem() != null ? getSelectedItem().toString() : (hint != null ? hint : ""); - g.drawString(text, 0, metrics.getAscent() + (getHeight() - metrics.getHeight()) / 2); - - // paint the Polygon < - if (isFocusOwner()) { - g2.setColor(accentColor); - } - g2.fillPolygon(new int[]{getWidth() - 5, getWidth() - 10, getWidth() - 15}, new int[]{getHeight() / 2 - 3, getHeight() / 2 + 3, getHeight() / 2 - 3}, 3); - - // paint line under text - g2.setColor(MaterialUtils.applyAlphaMask(getForeground(), LINE_OPACITY_MASK)); - g2.fillRect(0, getHeight() - 4, getWidth(), 1); - - // paint animated line under text - g2.setColor(accentColor); - g2.fillRect((int) ((getWidth() - line.getWidth()) / 2), getHeight() - 5, (int) line.getWidth(), 2); - } - - public static class FieldRenderer extends JComponent implements ListCellRenderer { - - private final MaterialComboBox comboBox; - private String text; - private boolean mouseOver = false; - private boolean selected = false; - - public FieldRenderer(MaterialComboBox comboBox) { - this.comboBox = comboBox; - } - - @Override - public Component getListCellRendererComponent(JList jList, Object o, int index, boolean isSelected, boolean cellHasFocus) { - text = o != null ? o.toString() : ""; - setSize(jList.getWidth(), 56); - setPreferredSize(new Dimension(jList.getWidth(), 32)); - setOpaque(true); - mouseOver = isSelected; - selected = comboBox.getSelectedIndex() == index; - return this; - } - - @Override - public void paint(Graphics g) { - super.paint(g); - Graphics2D g2 = (Graphics2D) g; - g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); - - if (mouseOver) { - g.setColor(MaterialUtils.isDark(comboBox.getBackground()) ? MaterialUtils.brighten(comboBox.getBackground()) : MaterialUtils.darken(comboBox.getBackground())); - } else { - g.setColor(comboBox.getBackground()); - } - g.fillRect(0, 0, getWidth(), getHeight()); - - g.setFont(Roboto.REGULAR.deriveFont(15f)); - if (selected) { - g2.setColor(comboBox.accentColor); - } else { - g2.setColor(comboBox.getForeground()); - } - FontMetrics metrics = g.getFontMetrics(g.getFont()); - g.drawString(text, 24, metrics.getAscent() + (getHeight() - metrics.getHeight()) / 2); - } - } - - public static class Popup extends BasicComboPopup { - - public Popup(JComboBox combo) { - super(combo); - setBackground(combo.getBackground()); - setOpaque(true); - setBorderPainted(false); - } - - @Override - protected JScrollPane createScroller() { - JScrollPane scrol = super.createScroller(); - scrol.setVerticalScrollBar(new ScrollBar(comboBox, Adjustable.VERTICAL)); - scrol.setBorder(new MatteBorder(16, 0, 16, 0, Color.WHITE)); - return scrol; - } - - @Override - protected Rectangle computePopupBounds(int px, int py, int pw, int ph) { - return super.computePopupBounds(px, py - 2, (int) Math.max(comboBox.getPreferredSize().getWidth(), pw), ph); - } - - @Override - public void paint(Graphics g) { - super.paint(g); - } - } - - public static class ScrollBar extends JScrollBar { - - public ScrollBar(final JComboBox comboBox, int orientation) { - super(orientation); - setPreferredSize(new Dimension(5, 100)); - - setUI(new BasicScrollBarUI() { - @Override - protected ScrollListener createScrollListener() { - setUnitIncrement(56); - setBlockIncrement(560); - return super.createScrollListener(); - } - - @Override - protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) { - g.setColor(comboBox.getBackground()); - g.fillRect(trackBounds.x, trackBounds.y, trackBounds.width, trackBounds.height); - } - - @Override - protected JButton createDecreaseButton(int orientation) { - JButton dummyButton = new JButton(); - dummyButton.setPreferredSize(new Dimension(0, 0)); - return dummyButton; - } - - @Override - protected JButton createIncreaseButton(int orientation) { - JButton dummyButton = new JButton(); - dummyButton.setPreferredSize(new Dimension(0, 0)); - return dummyButton; - } - - @Override - protected Dimension getMinimumThumbSize() { - return new Dimension(5, 50); - } - - @Override - protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) { - if (!thumbBounds.isEmpty() && this.scrollbar.isEnabled()) { - ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); - boolean isVertical = ScrollBar.this.getOrientation() - == Adjustable.VERTICAL; - g.setColor(MaterialColor.GREY_500); - g.fillRoundRect(thumbBounds.x, thumbBounds.y, - thumbBounds.width, thumbBounds.height, - isVertical ? thumbBounds.width : thumbBounds.height, - isVertical ? thumbBounds.width : thumbBounds.height); - } - } - - @Override - public void layoutContainer(Container scrollbarContainer) { - super.layoutContainer(scrollbarContainer); - incrButton.setBounds(0, 0, 0, 0); - decrButton.setBounds(0, 0, 0, 0); - } - }); - } - - @Override - public Component add(Component comp) { - if (comp != null) { - return super.add(comp); - } - return null; - } - - @Override - public void paint(Graphics g) { - g.setColor(Color.WHITE); - g.fillRect(0, 0, getWidth(), getHeight()); - super.paint(g); - } - } -} +package com.hq.swingmaterialdesign.materialdesign; + +import com.hq.swingmaterialdesign.materialdesign.resource.MaterialColor; +import static com.hq.swingmaterialdesign.materialdesign.MTextField.HINT_OPACITY_MASK; +import static com.hq.swingmaterialdesign.materialdesign.MTextField.LINE_OPACITY_MASK; +import com.hq.swingmaterialdesign.materialdesign.resource.Roboto; +import javax.swing.*; +import javax.swing.border.MatteBorder; +import javax.swing.plaf.basic.BasicComboBoxUI; +import javax.swing.plaf.basic.BasicComboPopup; +import javax.swing.plaf.basic.BasicScrollBarUI; +import javax.swing.plaf.basic.ComboPopup; +import java.awt.*; +import java.awt.event.FocusEvent; + +/** + * A Material Design combo box. + * + * + * @author bilux (i.bilux@gmail.com) + */ +public class MComboBox extends JComboBox { + + private MaterialLine line = new MaterialLine(this); + private Color accentColor = MaterialColor.PINK_500; + private String hint = ""; + + public MComboBox() { + setModel(new DefaultComboBoxModel<>()); + setRenderer(new FieldRenderer<>(this)); + setUI(new BasicComboBoxUI() { + @Override + protected ComboPopup createPopup() { + BasicComboPopup popupBox = new Popup(comboBox); + popupBox.getAccessibleContext().setAccessibleParent(comboBox); + return popupBox; + } + + @Override + protected JButton createArrowButton() { + JButton button = new javax.swing.plaf.basic.BasicArrowButton( + javax.swing.plaf.basic.BasicArrowButton.SOUTH, + MaterialColor.TRANSPARENT, + MaterialColor.TRANSPARENT, + MaterialColor.TRANSPARENT, + MaterialColor.TRANSPARENT); + button.setName("ComboBox.arrowButton"); + return button; + } + }); + setOpaque(false); + setBackground(MaterialColor.WHITE); + } + + /** + * Gets the color the label changes to when this {@code materialTextField} + * is focused. + * + * @return the {@code "Color"} currently in use for accent. The default + * value is {@link MaterialColor#PINK_500}. + */ + public Color getAccent() { + return accentColor; + } + + /** + * Sets the color the label changes to when this {@code materialTextField} + * is focused. The default value is {@link MaterialColor#PINK_500}. + * + * @param accentColor the {@code "Color"} that should be used for accent. + */ + public void setAccent(Color accentColor) { + this.accentColor = accentColor; + } + + /** + * Gets the hint text. The hint text is displayed when the list inside this + * combo box is empty or no element has been selected yet. + * + * @return hint text + */ + public String getHint() { + return hint; + } + + /** + * Sets the hint text. The hint text is displayed when the list inside this + * combo box is empty or no element has been selected yet. + * + * @param hint hint text + */ + public void setHint(String hint) { + this.hint = hint; + repaint(); + } + + @Override + protected void processFocusEvent(FocusEvent e) { + super.processFocusEvent(e); + line.update(); + } + + @Override + public void paint(Graphics g) { + Graphics2D g2 = (Graphics2D) g; + g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + + // paint text baground + g2.setColor(getBackground()); + g2.fillRect(0, 0, getWidth(), getHeight() - 4); + + // paint the selected item + g.setFont(Roboto.REGULAR.deriveFont(16f)); + g.setColor(getSelectedItem() == null ? MaterialUtils.applyAlphaMask(getForeground(), HINT_OPACITY_MASK) : getForeground()); + FontMetrics metrics = g.getFontMetrics(g.getFont()); + String text = getSelectedItem() != null ? getSelectedItem().toString() : (hint != null ? hint : ""); + g.drawString(text, 0, metrics.getAscent() + (getHeight() - metrics.getHeight()) / 2); + + // paint the Polygon < + if (isFocusOwner()) { + g2.setColor(accentColor); + } + g2.fillPolygon(new int[]{getWidth() - 5, getWidth() - 10, getWidth() - 15}, new int[]{getHeight() / 2 - 3, getHeight() / 2 + 3, getHeight() / 2 - 3}, 3); + + // paint line under text + g2.setColor(MaterialUtils.applyAlphaMask(getForeground(), LINE_OPACITY_MASK)); + g2.fillRect(0, getHeight() - 4, getWidth(), 1); + + // paint animated line under text + g2.setColor(accentColor); + g2.fillRect((int) ((getWidth() - line.getWidth()) / 2), getHeight() - 5, (int) line.getWidth(), 2); + } + + public static class FieldRenderer extends JComponent implements ListCellRenderer { + + private final MComboBox comboBox; + private String text; + private boolean mouseOver = false; + private boolean selected = false; + + public FieldRenderer(MComboBox comboBox) { + this.comboBox = comboBox; + } + + @Override + public Component getListCellRendererComponent(JList jList, Object o, int index, boolean isSelected, boolean cellHasFocus) { + text = o != null ? o.toString() : ""; + setSize(jList.getWidth(), 56); + setPreferredSize(new Dimension(jList.getWidth(), 32)); + setOpaque(true); + mouseOver = isSelected; + selected = comboBox.getSelectedIndex() == index; + return this; + } + + @Override + public void paint(Graphics g) { + super.paint(g); + Graphics2D g2 = (Graphics2D) g; + g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + + if (mouseOver) { + g.setColor(MaterialUtils.isDark(comboBox.getBackground()) ? MaterialUtils.brighten(comboBox.getBackground()) : MaterialUtils.darken(comboBox.getBackground())); + } else { + g.setColor(comboBox.getBackground()); + } + g.fillRect(0, 0, getWidth(), getHeight()); + + g.setFont(Roboto.REGULAR.deriveFont(15f)); + if (selected) { + g2.setColor(comboBox.accentColor); + } else { + g2.setColor(comboBox.getForeground()); + } + FontMetrics metrics = g.getFontMetrics(g.getFont()); + g.drawString(text, 24, metrics.getAscent() + (getHeight() - metrics.getHeight()) / 2); + } + } + + public static class Popup extends BasicComboPopup { + + public Popup(JComboBox combo) { + super(combo); + setBackground(combo.getBackground()); + setOpaque(true); + setBorderPainted(false); + } + + @Override + protected JScrollPane createScroller() { + JScrollPane scrol = super.createScroller(); + scrol.setVerticalScrollBar(new ScrollBar(comboBox, Adjustable.VERTICAL)); + scrol.setBorder(new MatteBorder(16, 0, 16, 0, Color.WHITE)); + return scrol; + } + + @Override + protected Rectangle computePopupBounds(int px, int py, int pw, int ph) { + return super.computePopupBounds(px, py - 2, (int) Math.max(comboBox.getPreferredSize().getWidth(), pw), ph); + } + + @Override + public void paint(Graphics g) { + super.paint(g); + } + } + + public static class ScrollBar extends JScrollBar { + + public ScrollBar(final JComboBox comboBox, int orientation) { + super(orientation); + setPreferredSize(new Dimension(5, 100)); + + setUI(new BasicScrollBarUI() { + @Override + protected ScrollListener createScrollListener() { + setUnitIncrement(56); + setBlockIncrement(560); + return super.createScrollListener(); + } + + @Override + protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) { + g.setColor(comboBox.getBackground()); + g.fillRect(trackBounds.x, trackBounds.y, trackBounds.width, trackBounds.height); + } + + @Override + protected JButton createDecreaseButton(int orientation) { + JButton dummyButton = new JButton(); + dummyButton.setPreferredSize(new Dimension(0, 0)); + return dummyButton; + } + + @Override + protected JButton createIncreaseButton(int orientation) { + JButton dummyButton = new JButton(); + dummyButton.setPreferredSize(new Dimension(0, 0)); + return dummyButton; + } + + @Override + protected Dimension getMinimumThumbSize() { + return new Dimension(5, 50); + } + + @Override + protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) { + if (!thumbBounds.isEmpty() && this.scrollbar.isEnabled()) { + ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + boolean isVertical = ScrollBar.this.getOrientation() + == Adjustable.VERTICAL; + g.setColor(MaterialColor.GREY_500); + g.fillRoundRect(thumbBounds.x, thumbBounds.y, + thumbBounds.width, thumbBounds.height, + isVertical ? thumbBounds.width : thumbBounds.height, + isVertical ? thumbBounds.width : thumbBounds.height); + } + } + + @Override + public void layoutContainer(Container scrollbarContainer) { + super.layoutContainer(scrollbarContainer); + incrButton.setBounds(0, 0, 0, 0); + decrButton.setBounds(0, 0, 0, 0); + } + }); + } + + @Override + public Component add(Component comp) { + if (comp != null) { + return super.add(comp); + } + return null; + } + + @Override + public void paint(Graphics g) { + g.setColor(Color.WHITE); + g.fillRect(0, 0, getWidth(), getHeight()); + super.paint(g); + } + } +} diff --git a/src/com/hq/swingmaterialdesign/materialdesign/MaterialTextField.java b/src/com/hq/swingmaterialdesign/materialdesign/MFormattedTextField.java similarity index 95% rename from src/com/hq/swingmaterialdesign/materialdesign/MaterialTextField.java rename to src/com/hq/swingmaterialdesign/materialdesign/MFormattedTextField.java index 55321b1..5e55532 100644 --- a/src/com/hq/swingmaterialdesign/materialdesign/MaterialTextField.java +++ b/src/com/hq/swingmaterialdesign/materialdesign/MFormattedTextField.java @@ -18,7 +18,7 @@ * * @author bilux (i.bilux@gmail.com) */ -public class MaterialTextField extends JTextField { +public class MFormattedTextField extends JFormattedTextField { public static final int HINT_OPACITY_MASK = 0x99000000; public static final int LINE_OPACITY_MASK = 0x66000000; @@ -32,7 +32,7 @@ public class MaterialTextField extends JTextField { * Default constructor for {@code MaterialTextField}. A default model is * created and the initial string is empty. */ - public MaterialTextField() { + public MFormattedTextField() { super(); setBorder(null); setFont(Roboto.REGULAR.deriveFont(16f)); @@ -43,7 +43,7 @@ public MaterialTextField() { setCaret(new DefaultCaret() { @Override protected synchronized void damage(Rectangle r) { - MaterialTextField.this.repaint(); //fix caret not being removed completely + MFormattedTextField.this.repaint(); //fix caret not being removed completely } }); getCaret().setBlinkRate(500); @@ -55,7 +55,7 @@ protected synchronized void damage(Rectangle r) { * * @param text An starting value for this text field */ - public MaterialTextField(String text) { + public MFormattedTextField(String text) { super.setText(text); } diff --git a/src/com/hq/swingmaterialdesign/materialdesign/MGradientButton.java b/src/com/hq/swingmaterialdesign/materialdesign/MGradientButton.java new file mode 100644 index 0000000..f3949d5 --- /dev/null +++ b/src/com/hq/swingmaterialdesign/materialdesign/MGradientButton.java @@ -0,0 +1,314 @@ +package com.hq.swingmaterialdesign.materialdesign; + +import java.awt.Color; +import java.awt.Cursor; +import java.awt.FontMetrics; +import java.awt.GradientPaint; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import javax.swing.JButton; +import java.awt.event.FocusEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.geom.RoundRectangle2D; + +/** + * A material design button. + * + * + * @author abner (abner.js05@gmail.com) + */ +public class MGradientButton extends JButton { + private RippleEffect ripple; + private ElevationEffect elevation; + private Type type = Type.DEFAULT; + private boolean isMousePressed = false; + private boolean isMouseOver = false; + private Color rippleColor = Color.WHITE; + private Cursor cursor = super.getCursor(); + private int borderRadius = 2; + public Color startColor = new Color(0, 153, 153); + public Color endColor = Color.GREEN; + public Color hoverStartColor = new Color(232, 37, 80); + public Color hoverEndColor = new Color(184, 27, 232); + + /** + * Creates a new button. + */ + public MGradientButton() { + ripple = RippleEffect.applyTo(this); + elevation = ElevationEffect.applyTo(this, 0); + setOpaque(false); + setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + + + addMouseListener(new MouseAdapter() { + @Override + public void mousePressed(MouseEvent mouseEvent) { + isMousePressed = true; + elevation.setLevel(getElevation()); + } + + @Override + public void mouseReleased(MouseEvent mouseEvent) { + isMousePressed = false; + elevation.setLevel(getElevation()); + } + + @Override + public void mouseEntered(MouseEvent e) { + isMouseOver = true; + elevation.setLevel(getElevation()); + } + + @Override + public void mouseExited(MouseEvent e) { + isMouseOver = false; + elevation.setLevel(getElevation()); + } + }); + + + } + + /** + * Gets the type of this button. + * + * @return the type of this button + * @see Type + */ + public Type getType() { + return type; + } + + /** + * Sets the type of this button. + * + * @param type the type of this button + * @see Type + */ + public void setType(Type type) { + this.type = type; + repaint(); + } + + /** + * Sets the background color of this button. + *

+ * Keep on mind that setting a background color in a Material component like + * this will also set the foreground color to either white or black and the + * ripple color to a brighter or darker shade of the color, depending of how + * bright or dark is the chosen background color. If you want to use a + * custom foreground color and ripple color, ensure the background color has + * been set first. + *

+ * NOTE: It is up to the look and feel to honor this property, some + * may choose to ignore it. To avoid any conflicts, using the + * + * Metal Look and Feel is recommended. + * + * @param bg + */ + @Override + public void setBackground(Color bg) { +// super.setBackground(bg); +// setForeground(MaterialUtils.isDark(bg) ? MaterialColor.WHITE : MaterialColor.BLACK); +// setRippleColor(MaterialUtils.isDark(bg) ? MaterialColor.WHITE : MaterialUtils.darken(MaterialUtils.darken(bg))); + } + + /** + * Gets the ripple color. + * + * @return the ripple color + */ + public Color getRippleColor() { + return rippleColor; + } + + /** + * Sets the ripple color. You should only do this for flat buttons. + * + * @param rippleColor the ripple color + */ + public void setRippleColor(Color rippleColor) { + this.rippleColor = rippleColor; + } + + public Color getStartColor() { + return startColor; + } + + public void setStartColor(Color startColor) { + this.startColor = startColor; + } + + public Color getEndColor() { + return endColor; + } + + public void setEndColor(Color endColor) { + this.endColor = endColor; + } + + public Color getHoverStartColor() { + return hoverStartColor; + } + + public void setHoverStartColor(Color hoverStartColor) { + this.hoverStartColor = hoverStartColor; + } + + public Color getHoverEndColor() { + return hoverEndColor; + } + + public void setHoverEndColor(Color hoverEndColor) { + this.hoverEndColor = hoverEndColor; + } + + + + + + /** + * Gets the current border radius of this button. + * + * @return the current border radius of this button, in pixels. + */ + public int getBorderRadius() { + return borderRadius; + } + + /** + * Sets the border radius of this button. You can define a custom radius in + * order to get some rounded corners in your button, making it look like a + * pill or even a circular action button. + * + * @param borderRadius the new border radius of this button, in pixels. + */ + public void setBorderRadius(int borderRadius) { + this.borderRadius = borderRadius; + elevation.setBorderRadius(borderRadius); + } + + @Override + public void setEnabled(boolean b) { + super.setEnabled(b); + super.setCursor(b ? cursor : Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } + + @Override + public void setCursor(Cursor cursor) { + super.setCursor(cursor); + this.cursor = cursor; + } + + @Override + protected void processFocusEvent(FocusEvent focusEvent) { + super.processFocusEvent(focusEvent); + } + + @Override + protected void processMouseEvent(MouseEvent mouseEvent) { + super.processMouseEvent(mouseEvent); + } + + private int getElevation() { + if (isMousePressed) { + return 2; + } else if (type == Type.RAISED || isMouseOver) { + return 1; + } else { + return 0; + } + } + + @Override + protected void paintComponent(Graphics g) { + Graphics2D g2 = (Graphics2D) g; + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + + if ((type != Type.FLAT) && isEnabled()) { + elevation.paint(g); + g2.translate(MaterialShadow.OFFSET_LEFT, MaterialShadow.OFFSET_TOP); + } + + int offset_lr; + int offset_td; + if (type == Type.FLAT) { + offset_td = 0; + offset_lr = 0; + } else { + offset_td = MaterialShadow.OFFSET_TOP + MaterialShadow.OFFSET_BOTTOM; + offset_lr = MaterialShadow.OFFSET_LEFT + MaterialShadow.OFFSET_RIGHT; + } + + if (isEnabled()) { + if(isMouseOver){ + GradientPaint gp = new GradientPaint(0, 0, hoverStartColor, 300, getHeight(), hoverEndColor); + g2.setPaint(gp); + } else { + GradientPaint gp = new GradientPaint(0, 0, startColor, 300, getHeight(), endColor); + g2.setPaint(gp); + } + + + g2.fill(new RoundRectangle2D.Float(0, 0, getWidth() - offset_lr, getHeight() - offset_td, borderRadius, borderRadius)); + g2.setColor(new Color(rippleColor.getRed() / 255f, rippleColor.getBlue() / 255f, rippleColor.getBlue() / 255f, 0.12f)); + if (type == Type.FLAT) { + elevation.paint(g); + //g2.setColor(MaterialUtils.brighten(getBackground())); + //g2.fill(new RoundRectangle2D.Float(0, 0, getWidth() - offset_lr, getHeight() - offset_td, borderRadius, borderRadius)); + } + } else { + GradientPaint gp = new GradientPaint(0, 0, startColor, 300, getHeight(), endColor); + g2.setPaint(gp); + g2.fill(new RoundRectangle2D.Float(0, 0, getWidth() - offset_lr, getHeight() - offset_td, borderRadius * 2, borderRadius * 2)); + } + + FontMetrics metrics = g.getFontMetrics(getFont()); + int x = (getWidth() - offset_lr - metrics.stringWidth(getText().toUpperCase())) / 2; + int y = (getHeight() - offset_td - metrics.getHeight()) / 2 + metrics.getAscent(); + g2.setFont(getFont()); + if (isEnabled()) { + g2.setColor(getForeground()); + } else { + Color fg = getForeground(); + g2.setColor(new Color(fg.getRed() / 255f, fg.getGreen() / 255f, fg.getBlue() / 255f, 0.6f)); + } + g2.drawString(getText().toUpperCase(), x, y); + + if (isEnabled()) { + g2.setClip(new RoundRectangle2D.Float(0, 0, getWidth() - offset_lr, getHeight() - offset_td, Math.max(borderRadius - 6, 0), Math.max(borderRadius * 2 - 4, 0))); + g2.setColor(rippleColor); + ripple.paint(g2); + } + } + + @Override + protected void paintBorder(Graphics g) { + //intentionally left blank + } + + /** + * Button types. + */ + public enum Type { + /** + * A default button. + */ + DEFAULT, + /** + * A raised button. Raised buttons have a shadow even if they are not + * focused. + */ + RAISED, + /** + * A flat button. Flat buttons don't have shadows and are typically + * transparent. + */ + FLAT + } +} diff --git a/src/com/hq/swingmaterialdesign/materialdesign/MGradientPanel.java b/src/com/hq/swingmaterialdesign/materialdesign/MGradientPanel.java new file mode 100644 index 0000000..30097a1 --- /dev/null +++ b/src/com/hq/swingmaterialdesign/materialdesign/MGradientPanel.java @@ -0,0 +1,236 @@ +package com.hq.swingmaterialdesign.materialdesign; + +import java.awt.Component; +import javax.swing.JRadioButton; +import javax.swing.JToolBar; +import javax.swing.JFormattedTextField; +import javax.swing.JPasswordField; +import javax.swing.JTextField; +import javax.swing.JCheckBox; +import javax.swing.JLabel; +import java.awt.GradientPaint; +import java.awt.Graphics; +import java.awt.event.MouseMotionListener; +import java.awt.geom.RoundRectangle2D; +import java.awt.RenderingHints; +import java.awt.AlphaComposite; +import java.awt.Graphics2D; +import java.awt.image.BufferedImage; +import java.awt.Dimension; +import java.awt.Image; +import javax.swing.ImageIcon; +import java.awt.Color; +import javax.swing.JPanel; + +public class MGradientPanel extends JPanel +{ + private Color startColor; + private Color endColor; + private boolean transparentControl; + private int gradientFocus; + private int borderRadius; + private boolean fillBackground; + private String imagePath; + private ImageIcon icon; + private Image image; + private boolean fillImage; + private boolean drawBorder; + private static Color backgroundColor; + + public String getImagePath() { + return this.imagePath; + } + + public void setImagePath(final String imagePath) { + this.imagePath = imagePath; + this.icon = new ImageIcon(this.getClass().getResource(this.imagePath)); + this.image = this.icon.getImage(); + } + + public ImageIcon getIcon() { + return this.icon; + } + + public void setIcon() { + this.icon = new ImageIcon(this.getClass().getResource(this.imagePath)); + } + + public Image getImage() { + return this.image; + } + + public void setImage(final Image image) { + this.image = image; + } + + public static Color getBackgroundColor() { + return MGradientPanel.backgroundColor; + } + + public void setBackgroundColor(final Color backgroundColor) { + MGradientPanel.backgroundColor = backgroundColor; + } + + public boolean isDrawBorder() { + return this.drawBorder; + } + + public void setDrawBorder(final boolean drawBorder) { + this.drawBorder = drawBorder; + } + + public boolean isFillImage() { + return this.fillImage; + } + + public void setFillImage(final boolean fillImage) { + this.fillImage = fillImage; + } + + public boolean isFillBackground() { + return this.fillBackground; + } + + public void setFillBackground(final boolean kFillBackground) { + this.fillBackground = kFillBackground; + } + + public int getBorderRadius() { + return this.borderRadius; + } + + public void setBorderRadius(final int kBorderRadius) { + this.borderRadius = kBorderRadius; + } + + public Color getStartColor() { + return this.startColor; + } + + public void setStartColor(final Color kStartColor) { + this.startColor = kStartColor; + } + + public Color getEndColor() { + return this.endColor; + } + + public void setEndColor(final Color kEndColor) { + this.endColor = kEndColor; + } + + public boolean isTransparentControls() { + return this.transparentControl; + } + + public void setTransparentControls(final boolean kTransparentControls) { + this.transparentControl = kTransparentControls; + } + + public int getGradientFocus() { + return this.gradientFocus; + } + + public void setGradientFocus(final int kGradientFocus) { + this.gradientFocus = kGradientFocus; + } + + public MGradientPanel() { + this.startColor = Color.MAGENTA; + this.endColor = Color.BLUE; + this.transparentControl = true; + this.gradientFocus = 500; + this.borderRadius = 10; + this.fillBackground = true; + this.imagePath = "/com/hq/swingmaterialdesign/images/profile.jpg"; + this.icon = new ImageIcon(this.getClass().getResource(this.imagePath)); + this.image = this.icon.getImage(); + this.fillImage = false; + this.drawBorder = false; + this.setPreferredSize(new Dimension(50, 50)); + if (this.transparentControl) { + this.setBg(true); + } + else { + this.setBg(false); + } + } + + public static BufferedImage toBufferedImage(final Image img) { + if (img instanceof BufferedImage) { + return (BufferedImage)img; + } + final BufferedImage bimage = new BufferedImage(img.getWidth(null), img.getHeight(null), 2); + final Graphics2D bGr = bimage.createGraphics(); + bGr.drawImage(img, 0, 0, null); + bGr.dispose(); + return bimage; + } + + public static BufferedImage makeRoundedCorner(final BufferedImage image, final int cornerRadius) { + final int w = image.getWidth(); + final int h = image.getHeight(); + final BufferedImage output = new BufferedImage(w, h, 2); + final Graphics2D g2 = output.createGraphics(); + g2.setComposite(AlphaComposite.Src); + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2.setColor(getBackgroundColor()); + g2.fill(new RoundRectangle2D.Float(0.0f, 0.0f, (float)w, (float)h, (float)cornerRadius, (float)cornerRadius)); + g2.setComposite(AlphaComposite.SrcAtop); + g2.drawImage(image, 0, 0, null); + g2.dispose(); + return output; + } + + @Override + public synchronized void addMouseMotionListener(final MouseMotionListener l) { + super.addMouseMotionListener(l); + } + + @Override + protected void paintComponent(final Graphics g) { + super.paintComponent(g); + final Graphics2D g2d = (Graphics2D)g; + g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + final int w = this.getWidth(); + final int h = this.getHeight(); + final Dimension arcs = new Dimension(this.borderRadius, this.borderRadius); + if (this.isFillImage()) { + g2d.setComposite(AlphaComposite.SrcAtop); + g2d.drawImage(this.image = makeRoundedCorner(toBufferedImage(this.image), this.borderRadius), 0, 0, this.getWidth(), this.getHeight(), this); + } + else { + final GradientPaint gp = new GradientPaint(0.0f, 0.0f, this.startColor, (float)this.gradientFocus, (float)h, this.endColor); + g2d.setPaint(gp); + } + if (this.fillBackground && !this.fillImage) { + g2d.fillRoundRect(0, 0, w - 1, h - 1, arcs.width, arcs.height); + } + if (!this.fillImage) { + g2d.drawRoundRect(0, 0, w - 1, h - 1, arcs.width, arcs.height); + g2d.fillRoundRect(0, 0, w - 1, h - 1, arcs.width, arcs.height); + } + else if (this.drawBorder) { + g2d.drawRoundRect(0, 0, w - 1, h - 1, arcs.width, arcs.height); + } + } + + private void setBg(final boolean isOpaque) { + final Component[] components2; + final Component[] components = components2 = this.getComponents(); + for (final Component component : components2) { + ((JLabel)component).setOpaque(isOpaque); + ((JCheckBox)component).setOpaque(isOpaque); + ((JTextField)component).setOpaque(isOpaque); + ((JPasswordField)component).setOpaque(isOpaque); + ((JFormattedTextField)component).setOpaque(isOpaque); + ((JToolBar)component).setOpaque(isOpaque); + ((JRadioButton)component).setOpaque(isOpaque); + } + } + + static { + MGradientPanel.backgroundColor = Color.WHITE; + } +} \ No newline at end of file diff --git a/src/com/hq/swingmaterialdesign/materialdesign/MaterialIconButton.java b/src/com/hq/swingmaterialdesign/materialdesign/MIconButton.java similarity index 92% rename from src/com/hq/swingmaterialdesign/materialdesign/MaterialIconButton.java rename to src/com/hq/swingmaterialdesign/materialdesign/MIconButton.java index 54b965d..cfe45da 100644 --- a/src/com/hq/swingmaterialdesign/materialdesign/MaterialIconButton.java +++ b/src/com/hq/swingmaterialdesign/materialdesign/MIconButton.java @@ -1,73 +1,74 @@ -package com.hq.swingmaterialdesign.materialdesign; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.FocusEvent; -import java.awt.event.MouseEvent; - -/** - * - * @author bilux (i.bilux@gmail.com) - */ -public class MaterialIconButton extends JButton { - - private final RippleEffect ripple; - - /** - * Creates a new button. - */ - public MaterialIconButton() { - ripple = RippleEffect.applyFixedTo(this); - setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - setOpaque(false); - setBackground(new Color(0, 0, 0, 0)); - } - - @Override - public void setIcon(Icon icon) { - super.setIcon(icon); - repaint(); - } - - @Override - public void setEnabled(boolean b) { - super.setEnabled(b); - repaint(); - } - - @Override - protected void processFocusEvent(FocusEvent focusEvent) { - super.processFocusEvent(focusEvent); - repaint(); - } - - @Override - protected void processMouseEvent(MouseEvent mouseEvent) { - super.processMouseEvent(mouseEvent); - repaint(); - } - - @Override - protected void paintComponent(Graphics g) { - Graphics2D g2 = (Graphics2D) g; - g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); - - if (isEnabled()) { - if (getIcon() != null) { - getIcon().paintIcon(this, g2, 12, 12); - } - g2.setColor(getForeground()); - ripple.paint(g2); - } else if (getIcon() != null) { - AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f); - g2.setComposite(ac); - getIcon().paintIcon(this, g2, 12, 12); - } - } - - @Override - protected void paintBorder(Graphics g) { - //intentionally left blank - } -} +package com.hq.swingmaterialdesign.materialdesign; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.FocusEvent; +import java.awt.event.MouseEvent; + +/** + * + * @author bilux (i.bilux@gmail.com) + */ +public class MIconButton extends JButton { + + private final RippleEffect ripple; + + /** + * Creates a new button. + */ + public MIconButton() { + ripple = RippleEffect.applyFixedTo(this); + setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + + setOpaque(false); + setBackground(new Color(0, 0, 0, 0)); + } + + @Override + public void setIcon(Icon icon) { + super.setIcon(icon); + repaint(); + } + + @Override + public void setEnabled(boolean b) { + super.setEnabled(b); + repaint(); + } + + @Override + protected void processFocusEvent(FocusEvent focusEvent) { + super.processFocusEvent(focusEvent); + repaint(); + } + + @Override + protected void processMouseEvent(MouseEvent mouseEvent) { + super.processMouseEvent(mouseEvent); + repaint(); + } + + @Override + protected void paintComponent(Graphics g) { + Graphics2D g2 = (Graphics2D) g; + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + + if (isEnabled()) { + if (getIcon() != null) { + getIcon().paintIcon(this, g2, 12, 12); + } + g2.setColor(getForeground()); + ripple.paint(g2); + } else if (getIcon() != null) { + AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f); + g2.setComposite(ac); + getIcon().paintIcon(this, g2, 12, 12); + } + } + + @Override + protected void paintBorder(Graphics g) { + //intentionally left blank + } +} diff --git a/src/com/hq/swingmaterialdesign/materialdesign/MaterialPanel.java b/src/com/hq/swingmaterialdesign/materialdesign/MPanel.java similarity index 96% rename from src/com/hq/swingmaterialdesign/materialdesign/MaterialPanel.java rename to src/com/hq/swingmaterialdesign/materialdesign/MPanel.java index 1fa38fb..a23ad39 100644 --- a/src/com/hq/swingmaterialdesign/materialdesign/MaterialPanel.java +++ b/src/com/hq/swingmaterialdesign/materialdesign/MPanel.java @@ -1,98 +1,98 @@ -package com.hq.swingmaterialdesign.materialdesign; - -import com.hq.swingmaterialdesign.materialdesign.resource.MaterialColor; -import javax.swing.*; -import javax.swing.border.EmptyBorder; -import java.awt.*; - -/** - * A JPanel customized for Material components. What makes these panels special - * is the possibility of assigning them an elevation level. Elevation can help - * distinguishing elements inside a Material-based GUI, and any changes done to - * them result in nicely animated transitions, helping to achieve that Material - * flow. - * - * However, there is a catch: shadows are kinda expensive to compute, as Java2D - * relies on the CPU for anything other than images, so having a lot of elements - * with a given elevation (and thus, a shadow) can reduce performance when these - * elevations change due to the triggered animations. - * - * Letting the components suggest a prefered size based on their contents is - * still under development, so it is not advised to use your favorite - * {@link LayoutManager} inside a {@code MaterialPanel} unless you set the - * prefered, minimum and maximum size of each component by yourself. Currently, - * the prefereable approach to follow is overriding {@link #doLayout()} and - * taking care of any arrangements by yourself. - * - * @author bilux (i.bilux@gmail.com) - */ -public class MaterialPanel extends JPanel { - - private final ElevationEffect elevation; - - /** - * Creates a new {@code MaterialPanel}. These panels cast a shadow below - * them, although technically it is painted inside its borders. If you don't - * need a shadow to be casted from this panel, use a {@link JPanel} instead. - */ - public MaterialPanel() { - elevation = ElevationEffect.applyTo(this, 1); - setBorder(new EmptyBorder(MaterialShadow.OFFSET_TOP, MaterialShadow.OFFSET_LEFT, MaterialShadow.OFFSET_BOTTOM, MaterialShadow.OFFSET_RIGHT)); - } - - /** - * Gets the elevation level of this panel. Changes in elevation trigger an - * animated transition if the component is currently visible, so it is - * incorrect to assume the returned value will reflect how the resulting - * shadow looks right now. - * - * @return elevation level [0~5] - * @see ElevationEffect - */ - public double getElevation() { - return elevation.getLevel(); - } - - /** - * Sets the elevation level of this panel. Changes in elevation trigger an - * animated transition if the component is currently visible, so it will - * take a little while for the resulting shadow to reflect the level once it - * is set. - * - * @param elevation elevation level [0~5] - * @see ElevationEffect - */ - public void setElevation(int elevation) { - this.elevation.setLevel(elevation); - } - - /** - * Sets the background color of this panel. Keep on mind that setting a - * background color in a Material component like this will also set the - * foreground color to either white or black, depending of how bright or - * dark is the chosen background color. - *

- * NOTE: It is up to the look and feel to honor this property, some - * may choose to ignore it. To avoid any conflicts, using the - * - * Metal Look and Feel is recommended. - * - * @param bg the desired background Color - */ - @Override - public void setBackground(Color bg) { - super.setBackground(bg); - setForeground(MaterialUtils.isDark(bg) ? MaterialColor.WHITE : MaterialColor.DARK_BLACK); - } - - @Override - protected void paintComponent(Graphics g) { - Graphics2D g2 = (Graphics2D) g; - elevation.paint(g); - g.setClip(MaterialShadow.OFFSET_LEFT, MaterialShadow.OFFSET_TOP, - getWidth() - MaterialShadow.OFFSET_LEFT - MaterialShadow.OFFSET_RIGHT, - getHeight() - MaterialShadow.OFFSET_TOP - MaterialShadow.OFFSET_BOTTOM); - super.paintComponent(g2); - g.setClip(null); - } -} +package com.hq.swingmaterialdesign.materialdesign; + +import com.hq.swingmaterialdesign.materialdesign.resource.MaterialColor; +import javax.swing.*; +import javax.swing.border.EmptyBorder; +import java.awt.*; + +/** + * A JPanel customized for Material components. What makes these panels special + * is the possibility of assigning them an elevation level. Elevation can help + * distinguishing elements inside a Material-based GUI, and any changes done to + * them result in nicely animated transitions, helping to achieve that Material + * flow. + * + * However, there is a catch: shadows are kinda expensive to compute, as Java2D + * relies on the CPU for anything other than images, so having a lot of elements + * with a given elevation (and thus, a shadow) can reduce performance when these + * elevations change due to the triggered animations. + * + * Letting the components suggest a prefered size based on their contents is + * still under development, so it is not advised to use your favorite + * {@link LayoutManager} inside a {@code MaterialPanel} unless you set the + * prefered, minimum and maximum size of each component by yourself. Currently, + * the prefereable approach to follow is overriding {@link #doLayout()} and + * taking care of any arrangements by yourself. + * + * @author bilux (i.bilux@gmail.com) + */ +public class MPanel extends JPanel { + + private final ElevationEffect elevation; + + /** + * Creates a new {@code MaterialPanel}. These panels cast a shadow below + * them, although technically it is painted inside its borders. If you don't + * need a shadow to be casted from this panel, use a {@link JPanel} instead. + */ + public MPanel() { + elevation = ElevationEffect.applyTo(this, 1); + setBorder(new EmptyBorder(MaterialShadow.OFFSET_TOP, MaterialShadow.OFFSET_LEFT, MaterialShadow.OFFSET_BOTTOM, MaterialShadow.OFFSET_RIGHT)); + } + + /** + * Gets the elevation level of this panel. Changes in elevation trigger an + * animated transition if the component is currently visible, so it is + * incorrect to assume the returned value will reflect how the resulting + * shadow looks right now. + * + * @return elevation level [0~5] + * @see ElevationEffect + */ + public double getElevation() { + return elevation.getLevel(); + } + + /** + * Sets the elevation level of this panel. Changes in elevation trigger an + * animated transition if the component is currently visible, so it will + * take a little while for the resulting shadow to reflect the level once it + * is set. + * + * @param elevation elevation level [0~5] + * @see ElevationEffect + */ + public void setElevation(int elevation) { + this.elevation.setLevel(elevation); + } + + /** + * Sets the background color of this panel. Keep on mind that setting a + * background color in a Material component like this will also set the + * foreground color to either white or black, depending of how bright or + * dark is the chosen background color. + *

+ * NOTE: It is up to the look and feel to honor this property, some + * may choose to ignore it. To avoid any conflicts, using the + * + * Metal Look and Feel is recommended. + * + * @param bg the desired background Color + */ + @Override + public void setBackground(Color bg) { + super.setBackground(bg); + setForeground(MaterialUtils.isDark(bg) ? MaterialColor.WHITE : MaterialColor.DARK_BLACK); + } + + @Override + protected void paintComponent(Graphics g) { + Graphics2D g2 = (Graphics2D) g; + elevation.paint(g); + g.setClip(MaterialShadow.OFFSET_LEFT, MaterialShadow.OFFSET_TOP, + getWidth() - MaterialShadow.OFFSET_LEFT - MaterialShadow.OFFSET_RIGHT, + getHeight() - MaterialShadow.OFFSET_TOP - MaterialShadow.OFFSET_BOTTOM); + super.paintComponent(g2); + g.setClip(null); + } +} diff --git a/src/com/hq/swingmaterialdesign/materialdesign/MPasswordField.java b/src/com/hq/swingmaterialdesign/materialdesign/MPasswordField.java new file mode 100644 index 0000000..c844dd0 --- /dev/null +++ b/src/com/hq/swingmaterialdesign/materialdesign/MPasswordField.java @@ -0,0 +1,172 @@ +package com.hq.swingmaterialdesign.materialdesign; + +import com.hq.swingmaterialdesign.materialdesign.resource.MaterialColor; +import com.hq.swingmaterialdesign.materialdesign.resource.Roboto; + +import javax.swing.*; +import javax.swing.text.DefaultCaret; +import java.awt.*; +import java.awt.event.FocusEvent; +import java.awt.event.KeyEvent; + +/** + * A material design password text field + * + * + * @author abner (abner.js05@gmail.com) + */ +public class MPasswordField extends JPasswordField { + + public static final int HINT_OPACITY_MASK = 0x99000000; + public static final int LINE_OPACITY_MASK = 0x66000000; + + private final MaterialFloatingLabel hintLabel = new MaterialFloatingLabel(this); + private final MaterialLine line = new MaterialLine(this); + + private Color accentColor = MaterialColor.CYAN_500; + + /** + * Default constructor for {@code MaterialTextField}. A default model is + * created and the initial string is empty. + */ + public MPasswordField() { + super(); + setBorder(null); + setFont(Roboto.REGULAR.deriveFont(16f)); + hintLabel.setText(""); + setOpaque(false); + setBackground(MaterialColor.WHITE); + + setCaret(new DefaultCaret() { + @Override + protected synchronized void damage(Rectangle r) { + MPasswordField.this.repaint(); //fix caret not being removed completely + } + }); + getCaret().setBlinkRate(500); + } + + /** + * Default constructor for {@code MaterialTextField}. A default model is + * created and the initial string is the one provided. + * + * @param text An starting value for this text field + */ + public MPasswordField(String text) { + super.setText(text); + } + + + + /** + * Gets the label text. The label will float above any contents input into + * this text field. + * + * @return the text being used in the textfield label + */ + public String getLabel() { + return hintLabel.getText(); + } + + /** + * Sets the label text. The label text is displayed when this textfield is + * empty. + * + * + * @param label the text to use in the floating label + */ + public void setLabel(String label) { + hintLabel.setText(label); + repaint(); + } + + /** + * Gets the color the label changes to when this {@code materialTextField} + * is focused. + * + * @return the {@code "Color"} currently in use for accent. The default + * value is {@link MaterialColor#CYAN_300}. + */ + public Color getAccent() { + return accentColor; + } + + /** + * Sets the color the label changes to when this {@code materialTextField} + * is focused. The default value is {@link MaterialColor#CYAN_300}. + * + * @param accentColor the {@code "Color"} that should be used for accent. + */ + public void setAccent(Color accentColor) { + this.accentColor = accentColor; + hintLabel.setAccent(accentColor); + } + + @Override + public void setForeground(Color fg) { + super.setForeground(fg); + if (hintLabel != null) { + hintLabel.updateForeground(); + } + } + + @Override + public void setText(String string) { + super.setText(string); + hintLabel.update(); + line.update(); + } + + @Override + protected void processFocusEvent(FocusEvent e) { + super.processFocusEvent(e); + hintLabel.update(); + line.update(); + } + + @Override + protected void processKeyEvent(KeyEvent e) { + super.processKeyEvent(e); + hintLabel.update(); + line.update(); + } + + @Override + protected void paintComponent(Graphics g) { + Graphics2D g2 = (Graphics2D) g; + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + + // paint text baground + g2.setColor(getBackground()); + g2.fillRect(0, (getHeight() / 2) - 4, getWidth(), getHeight() / 2); + + g2.translate(0, 9); + super.paintComponent(g); + g2.translate(0, -9); + + // hint label in text + if (!getLabel().isEmpty() && getText().isEmpty() && (getLabel().isEmpty() || isFocusOwner())) { + g.setFont(Roboto.REGULAR.deriveFont(16f)); + g2.setColor(MaterialUtils.applyAlphaMask(getForeground(), HINT_OPACITY_MASK)); + FontMetrics metrics = g.getFontMetrics(g.getFont()); + g.drawString(getLabel(), 0, metrics.getAscent() + getHeight() / 2); + } + + // paint hint label + hintLabel.paint(g2); + + // paint line under text + g2.setColor(MaterialUtils.applyAlphaMask(getForeground(), LINE_OPACITY_MASK)); + g2.fillRect(0, getHeight() - 4, getWidth(), 1); + + // paint animated line under text + g2.setColor(accentColor); + g2.fillRect((int) ((getWidth() - line.getWidth()) / 2), getHeight() - 5, (int) line.getWidth(), 2); + } + + @Override + protected void paintBorder(Graphics g) { + //intentionally left blank + } +} diff --git a/src/com/hq/swingmaterialdesign/materialdesign/MTextField.java b/src/com/hq/swingmaterialdesign/materialdesign/MTextField.java new file mode 100644 index 0000000..780f8a1 --- /dev/null +++ b/src/com/hq/swingmaterialdesign/materialdesign/MTextField.java @@ -0,0 +1,173 @@ +package com.hq.swingmaterialdesign.materialdesign; + +import com.hq.swingmaterialdesign.materialdesign.resource.MaterialColor; +import com.hq.swingmaterialdesign.materialdesign.resource.Roboto; + +import javax.swing.*; +import javax.swing.text.DefaultCaret; +import java.awt.*; +import java.awt.event.FocusEvent; +import java.awt.event.KeyEvent; + +/** + * A Material Design single-line text field is the basic way of getting user + * input. It includes a descriptive label that appears as a placeholder and then + * floats above the text field as content is written. You can also set a hint + * for it to appear below the label when the text field is empty. + * + * + * @author bilux (i.bilux@gmail.com) + */ +public class MTextField extends JTextField { + + public static final int HINT_OPACITY_MASK = 0x99000000; + public static final int LINE_OPACITY_MASK = 0x66000000; + + private final MaterialFloatingLabel hintLabel = new MaterialFloatingLabel(this); + private final MaterialLine line = new MaterialLine(this); + + private Color accentColor = MaterialColor.CYAN_500; + + /** + * Default constructor for {@code MaterialTextField}. A default model is + * created and the initial string is empty. + */ + public MTextField() { + super(); + setBorder(null); + setFont(Roboto.REGULAR.deriveFont(16f)); + hintLabel.setText(""); + setOpaque(false); + setBackground(MaterialColor.WHITE); + + setCaret(new DefaultCaret() { + @Override + protected synchronized void damage(Rectangle r) { + MTextField.this.repaint(); //fix caret not being removed completely + } + }); + getCaret().setBlinkRate(500); + } + + /** + * Default constructor for {@code MaterialTextField}. A default model is + * created and the initial string is the one provided. + * + * @param text An starting value for this text field + */ + public MTextField(String text) { + super.setText(text); + } + + /** + * Gets the label text. The label will float above any contents input into + * this text field. + * + * @return the text being used in the textfield label + */ + public String getLabel() { + return hintLabel.getText(); + } + + /** + * Sets the label text. The label text is displayed when this textfield is + * empty. + * + * + * @param label the text to use in the floating label + */ + public void setLabel(String label) { + hintLabel.setText(label); + repaint(); + } + + /** + * Gets the color the label changes to when this {@code materialTextField} + * is focused. + * + * @return the {@code "Color"} currently in use for accent. The default + * value is {@link MaterialColor#CYAN_300}. + */ + public Color getAccent() { + return accentColor; + } + + /** + * Sets the color the label changes to when this {@code materialTextField} + * is focused. The default value is {@link MaterialColor#CYAN_300}. + * + * @param accentColor the {@code "Color"} that should be used for accent. + */ + public void setAccent(Color accentColor) { + this.accentColor = accentColor; + hintLabel.setAccent(accentColor); + } + + @Override + public void setForeground(Color fg) { + super.setForeground(fg); + if (hintLabel != null) { + hintLabel.updateForeground(); + } + } + + @Override + public void setText(String string) { + super.setText(string); + hintLabel.update(); + line.update(); + } + + @Override + protected void processFocusEvent(FocusEvent e) { + super.processFocusEvent(e); + hintLabel.update(); + line.update(); + } + + @Override + protected void processKeyEvent(KeyEvent e) { + super.processKeyEvent(e); + hintLabel.update(); + line.update(); + } + + @Override + protected void paintComponent(Graphics g) { + Graphics2D g2 = (Graphics2D) g; + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + + // paint text baground + g2.setColor(getBackground()); + g2.fillRect(0, (getHeight() / 2) - 4, getWidth(), getHeight() / 2); + + g2.translate(0, 9); + super.paintComponent(g); + g2.translate(0, -9); + + // hint label in text + if (!getLabel().isEmpty() && getText().isEmpty() && (getLabel().isEmpty() || isFocusOwner())) { + g.setFont(Roboto.REGULAR.deriveFont(16f)); + g2.setColor(MaterialUtils.applyAlphaMask(getForeground(), HINT_OPACITY_MASK)); + FontMetrics metrics = g.getFontMetrics(g.getFont()); + g.drawString(getLabel(), 0, metrics.getAscent() + getHeight() / 2); + } + + // paint hint label + hintLabel.paint(g2); + + // paint line under text + g2.setColor(MaterialUtils.applyAlphaMask(getForeground(), LINE_OPACITY_MASK)); + g2.fillRect(0, getHeight() - 4, getWidth(), 1); + + // paint animated line under text + g2.setColor(accentColor); + g2.fillRect((int) ((getWidth() - line.getWidth()) / 2), getHeight() - 5, (int) line.getWidth(), 2); + } + + @Override + protected void paintBorder(Graphics g) { + //intentionally left blank + } +} diff --git a/src/com/hq/swingmaterialdesign/materialdesign/MToggleButton.java b/src/com/hq/swingmaterialdesign/materialdesign/MToggleButton.java new file mode 100644 index 0000000..6b63932 --- /dev/null +++ b/src/com/hq/swingmaterialdesign/materialdesign/MToggleButton.java @@ -0,0 +1,391 @@ +package com.hq.swingmaterialdesign.materialdesign; + +import com.hq.swingmaterialdesign.materialdesign.resource.MaterialColor; +import java.awt.Color; +import java.awt.Component; +import java.awt.Cursor; +import java.awt.FontMetrics; +import java.awt.GradientPaint; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import javax.swing.JButton; +import javax.swing.plaf.basic.BasicButtonUI; +import java.awt.event.FocusEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.geom.RoundRectangle2D; +import javax.swing.BorderFactory; +import javax.swing.JComponent; + +/** + * A material design button. + * + * + * @author abner (abner.js05@gmail.com) + */ +public class MToggleButton extends JButton { + + private RippleEffect ripple; + private Type type = Type.DEFAULT; + private boolean isMousePressed = false; + private boolean isMouseOver = false; + private Color rippleColor = Color.WHITE; + private Cursor cursor = super.getCursor(); + private int borderRadius = 2; + private Color startColor = new Color(0, 153, 153); + private Color endColor = Color.GREEN; + private Color hoverStartColor = new Color(255, 0, 255); + private Color hoverEndColor = Color.green; + private int indicatorThickness = 2; + private Color indicatorColor = Color.white; + private Color selectedColor = Color.green; + private boolean allowTab = true; + + /** + * Creates a new button. + */ + public MToggleButton() { + ripple = RippleEffect.applyTo(this); + setOpaque(false); + setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + + addMouseListener(new MouseAdapter() { + @Override + public void mousePressed(MouseEvent mouseEvent) { + isMousePressed = true; + getStyle(); + } + + @Override + public void mouseReleased(MouseEvent mouseEvent) { + isMousePressed = false; + } + + @Override + public void mouseEntered(MouseEvent e) { + isMouseOver = true; + } + + @Override + public void mouseExited(MouseEvent e) { + isMouseOver = false; + } + }); + + setUI(new BasicButtonUI() { + @Override + public boolean contains(JComponent c, int x, int y) { + return x > MaterialShadow.OFFSET_LEFT && y > MaterialShadow.OFFSET_TOP + && x < getWidth() - MaterialShadow.OFFSET_RIGHT && y < getHeight() - MaterialShadow.OFFSET_BOTTOM; + } + }); + } + + /** + * Gets the type of this button. + * + * @return the type of this button + * @see Type + */ + public Type getType() { + return type; + } + + /** + * Sets the type of this button. + * + * @param type the type of this button + * @see Type + */ + public void setType(Type type) { + this.type = type; + repaint(); + } + + /** + * Sets the background color of this button. + *

+ * Keep on mind that setting a background color in a Material component like + * this will also set the foreground color to either white or black and the + * ripple color to a brighter or darker shade of the color, depending of how + * bright or dark is the chosen background color. If you want to use a + * custom foreground color and ripple color, ensure the background color has + * been set first. + *

+ * NOTE: It is up to the look and feel to honor this property, some + * may choose to ignore it. To avoid any conflicts, using the + * + * Metal Look and Feel is recommended. + * + * @param bg + */ + @Override + public void setBackground(Color bg) { + super.setBackground(bg); + setForeground(MaterialUtils.isDark(bg) ? MaterialColor.WHITE : MaterialColor.BLACK); + setRippleColor(MaterialUtils.isDark(bg) ? MaterialColor.WHITE : MaterialUtils.darken(MaterialUtils.darken(bg))); + } + + /** + * Gets the ripple color. + * + * @return the ripple color + */ + public Color getRippleColor() { + return rippleColor; + } + + /** + * Sets the ripple color. You should only do this for flat buttons. + * + * @param rippleColor the ripple color + */ + public void setRippleColor(Color rippleColor) { + this.rippleColor = rippleColor; + } + + /** + * Gets the current border radius of this button. + * + * @return the current border radius of this button, in pixels. + */ + public int getBorderRadius() { + return borderRadius; + } + + /** + * Sets the border radius of this button. You can define a custom radius in + * order to get some rounded corners in your button, making it look like a + * pill or even a circular action button. + * + * @param borderRadius the new border radius of this button, in pixels. + */ + public void setBorderRadius(int borderRadius) { + this.borderRadius = borderRadius; + } + + @Override + public void setEnabled(boolean b) { + super.setEnabled(b); + super.setCursor(b ? cursor : Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } + + @Override + public void setCursor(Cursor cursor) { + super.setCursor(cursor); + this.cursor = cursor; + } + + public Color getSelectedColor() { + return selectedColor; + } + + public void setSelectedColor(Color selectedColor) { + this.selectedColor = selectedColor; + } + + public int getIndicatorThickness() { + return indicatorThickness; + } + + public void setIndicatorThickness(int indicatorThickness) { + this.indicatorThickness = indicatorThickness; + } + + public Color getIndicatorColor() { + return indicatorColor; + } + + public void setIndicatorColor(Color indicatorColor) { + this.indicatorColor = indicatorColor; + } + + public Color getStartColor() { + return startColor; + } + + public void setStartColor(Color startColor) { + this.startColor = startColor; + } + + public boolean isAllowTab() { + return allowTab; + } + + public void setAllowTab(boolean allowTab) { + this.allowTab = allowTab; + } + + public Color getEndColor() { + return endColor; + } + + public void setEndColor(Color endColor) { + this.endColor = endColor; + } + + public void select() { + this.setSelected(true); + this.setBorder(BorderFactory.createMatteBorder(0, this.indicatorThickness, 0, 0, this.indicatorColor)); + this.repaint(); + } + + public void unselect(){ + this.setSelected(false); + this.setBorder(BorderFactory.createEmptyBorder()); + } + + public Color getHoverStartColor() { + return hoverStartColor; + } + + public void setHoverStartColor(Color hoverStartColor) { + this.hoverStartColor = hoverStartColor; + } + + public Color getHoverEndColor() { + return hoverEndColor; + } + + public void setHoverEndColor(Color hoverEndColor) { + this.hoverEndColor = hoverEndColor; + } + + @Override + protected void processFocusEvent(FocusEvent focusEvent) { + super.processFocusEvent(focusEvent); + } + + @Override + protected void processMouseEvent(MouseEvent mouseEvent) { + super.processMouseEvent(mouseEvent); + } + + private void getStyle() { + if (isMousePressed) { + + if (isAllowTab()) { + Component[] comp = getParent().getComponents(); + for (int i = 0; i < comp.length; i++) { + if (comp[i] instanceof MToggleButton) { + + ((MToggleButton) comp[i]).setSelected(false); + ((MToggleButton) comp[i]).setBorder(BorderFactory.createEmptyBorder()); + } + } + this.setBorder(BorderFactory.createMatteBorder(0, indicatorThickness, 0, 0, indicatorColor)); + this.setSelected(true); + } + + } else { + this.setBorder(BorderFactory.createEmptyBorder()); + this.setSelected(false); + } + } + + private int getElevation() { + if (isMousePressed) { + this.setBorder(BorderFactory.createMatteBorder(0, indicatorThickness, 0, 0, indicatorColor)); + this.setSelected(true); + return 2; + } else if (type == Type.RAISED || isMouseOver) { + return 1; + } else { + return 0; + } + } + + @Override + protected void paintComponent(Graphics g) { + Graphics2D g2 = (Graphics2D) g; + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + + if ((type != Type.FLAT) && isEnabled()) { + g2.translate(MaterialShadow.OFFSET_LEFT, MaterialShadow.OFFSET_TOP); + } + + int offset_lr; + int offset_td; + if (type == Type.FLAT) { + offset_td = 0; + offset_lr = 0; + } else { + offset_td = MaterialShadow.OFFSET_TOP + MaterialShadow.OFFSET_BOTTOM; + offset_lr = MaterialShadow.OFFSET_LEFT + MaterialShadow.OFFSET_RIGHT; + } + + if (isEnabled()) { + GradientPaint gp = new GradientPaint(0, 0, startColor, 300, getHeight(), endColor); + g2.setPaint(gp); + if (isMouseOver) { + gp = new GradientPaint(0, 0, hoverStartColor, 300, getHeight(), hoverEndColor); + g2.setPaint(gp); + } else { + gp = new GradientPaint(0, 0, startColor, 300, getHeight(), endColor); + g2.setPaint(gp); + } + + g2.fill(new RoundRectangle2D.Float(0, 0, getWidth() - offset_lr, getHeight() - offset_td, borderRadius, borderRadius)); + if (type == Type.FLAT) { + //g2.setColor(MaterialUtils.brighten(getBackground())); + //g2.fill(new RoundRectangle2D.Float(0, 0, getWidth() - offset_lr, getHeight() - offset_td, borderRadius, borderRadius)); + } + + } else { + Color bg = getBackground(); + g2.setColor(new Color(bg.getRed() / 255f, bg.getGreen() / 255f, bg.getBlue() / 255f, 0.6f)); + + g2.fill(new RoundRectangle2D.Float(0, 0, getWidth() - offset_lr, getHeight() - offset_td, borderRadius * 2, borderRadius * 2)); + } + + if (isSelected()) { + g2.setPaint(selectedColor); + g2.fillRoundRect(0, 0, getWidth(), getHeight(), borderRadius, borderRadius); + } + + FontMetrics metrics = g.getFontMetrics(getFont()); + int x = (getWidth() - offset_lr - metrics.stringWidth(getText().toUpperCase())) / 2; + int y = (getHeight() - offset_td - metrics.getHeight()) / 2 + metrics.getAscent(); + g2.setFont(getFont()); + if (isEnabled()) { + g2.setColor(getForeground()); + + } else { + Color fg = getForeground(); + g2.setColor(new Color(fg.getRed() / 255f, fg.getGreen() / 255f, fg.getBlue() / 255f, 0.6f)); + } + g2.drawString(getText().toUpperCase(), x, y); + + if (isEnabled()) { + g2.setClip(new RoundRectangle2D.Float(0, 0, getWidth() - offset_lr, getHeight() - offset_td, Math.max(borderRadius - 6, 0), Math.max(borderRadius * 2 - 4, 0))); + g2.setColor(rippleColor); + ripple.paint(g2); + } + } + +// @Override +// protected void paintBorder(Graphics g) { +// //intentionally left blank +// } + /** + * Button types. + */ + public enum Type { + /** + * A default button. + */ + DEFAULT, + /** + * A raised button. Raised buttons have a shadow even if they are not + * focused. + */ + RAISED, + /** + * A flat button. Flat buttons don't have shadows and are typically + * transparent. + */ + FLAT + } +} diff --git a/src/com/hq/swingmaterialdesign/materialdesign/MToggleButton_old.java b/src/com/hq/swingmaterialdesign/materialdesign/MToggleButton_old.java new file mode 100644 index 0000000..c231103 --- /dev/null +++ b/src/com/hq/swingmaterialdesign/materialdesign/MToggleButton_old.java @@ -0,0 +1,310 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.hq.swingmaterialdesign.materialdesign; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.GradientPaint; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Rectangle; +import java.awt.RenderingHints; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.font.FontRenderContext; +import java.awt.geom.Rectangle2D; +import javax.swing.BorderFactory; +import javax.swing.JButton; + +/** + * + * @auauthor oXCToo + */ +public class MToggleButton_old extends JButton { + + public Color kBackGroundColor = Color.magenta; + public Color kStartColor = new Color(0, 153, 153); + public Color kEndColor = Color.GREEN; + public Color kHoverStartColor = new Color(255, 0, 255); + public Color kHoverEndColor = Color.green; + public Color kHoverColor = Color.white; + public boolean kAllowGradient = true; + public int kBorderRadius = 10; + private boolean mouseExited = false; + private boolean mouseEntered = false; + private boolean mousePressed = false; + private boolean mouseReleased = false; + public boolean kFillButton = true; + public Color kSelectedColor = Color.magenta; + public Color kPressedColor = Color.LIGHT_GRAY; + public int kIndicatorThickness = 2; + public Color kIndicatorColor = Color.white; + public boolean kAllowTab = true; + + public boolean iskAllowTab() { + return kAllowTab; + } + + public void setkAllowTab(boolean kAllowTab) { + this.kAllowTab = kAllowTab; + } + + public int getkIndicatorThickness() { + return kIndicatorThickness; + } + + public void setkIndicatorThickness(int kIndicatorThickness) { + this.kIndicatorThickness = kIndicatorThickness; + + } + + public Color getkIndicatorColor() { + return kIndicatorColor; + } + + public void setkIndicatorColor(Color kIndicatorColor) { + this.kIndicatorColor = kIndicatorColor; + } + + public Color getkPressedColor() { + return kPressedColor; + } + + public void setkPressedColor(Color kPressedColor) { + this.kPressedColor = kPressedColor; + } + + public Color getkSelectedColor() { + return kSelectedColor; + } + + public void setkSelectedColor(Color kSelectedColor) { + this.kSelectedColor = kSelectedColor; + } + + + public Color getkBackGroundColor() { + return kBackGroundColor; + } + + public void setkBackGroundColor(Color kBackGroundColor) { + this.kBackGroundColor = kBackGroundColor; + } + + public Color getkStartColor() { + return kStartColor; + } + + public void setkStartColor(Color kStartColor) { + this.kStartColor = kStartColor; + } + + public Color getkEndColor() { + return kEndColor; + } + + public void setkEndColor(Color kEndColor) { + this.kEndColor = kEndColor; + } + + public Color getkHoverStartColor() { + return kHoverStartColor; + } + + public void setkHoverStartColor(Color kHoverStartColor) { + this.kHoverStartColor = kHoverStartColor; + } + + public Color getkHoverEndColor() { + return kHoverEndColor; + } + + public void setkHoverEndColor(Color kHoverEndColor) { + this.kHoverEndColor = kHoverEndColor; + } + + public Color getkHoverColor() { + return kHoverColor; + } + + public void setkHoverColor(Color kHoverColor) { + this.kHoverColor = kHoverColor; + } + + public boolean iskAllowGradient() { + return kAllowGradient; + } + + public void setkAllowGradient(boolean kAllowGradient) { + this.kAllowGradient = kAllowGradient; + } + + public int getkBorderRadius() { + return kBorderRadius; + } + + public void setkBorderRadius(int kBorderRadius) { + this.kBorderRadius = kBorderRadius; + } + + public boolean iskFillButton() { + return kFillButton; + } + + public void setkFillButton(boolean kFillButton) { + this.kFillButton = kFillButton; + } + + public MToggleButton_old() { + + this.setPreferredSize(new Dimension(185, 45)); + this.setForeground(Color.white); + + MouseAdapter mouseAdapter = new MouseAdapter() { + @Override + public void mouseEntered(MouseEvent me) { + if (contains(me.getX(), me.getY())) { + mouseEntered = true; + repaint(); + } + } + + @Override + public void mouseExited(MouseEvent me) { + mouseExited = false; + mouseEntered = false; + repaint(); + } + + @Override + public void mouseReleased(MouseEvent e) { + mousePressed = false; + mouseReleased = true; + } + + @Override + public void mousePressed(MouseEvent e) { + mousePressed = true; + mouseReleased = false; + } + + }; + addMouseListener(mouseAdapter); + } + + @Override + protected void paintComponent(Graphics g) { + + Graphics2D g2 = (Graphics2D) g.create(); + + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + + if (mousePressed == true) { + g2.setPaint(kPressedColor); + if (iskAllowTab()) { + Component[] comp = getParent().getComponents(); + for (int i = 0; i < comp.length; i++) { + if (comp[i] instanceof MToggleButton_old) { + + ((MToggleButton_old) comp[i]).setSelected(false); + ((MToggleButton_old) comp[i]).setBorder(BorderFactory.createMatteBorder(0, 0, 0, 0, kIndicatorColor)); + } + } + this.setBorder(BorderFactory.createMatteBorder(0, kIndicatorThickness, 0, 0, kIndicatorColor)); + this.setSelected(true); + } + + } else { + GradientPaint gp = new GradientPaint(0, 0, kStartColor, 300, getHeight(), kEndColor); + g2.setPaint(gp); + if (mouseEntered) { + gp = new GradientPaint(0, 0, kHoverStartColor, 300, getHeight(), kHoverEndColor); + g2.setPaint(gp); + } else if (mouseExited) { + gp = new GradientPaint(0, 0, kStartColor, 300, getHeight(), kEndColor); + g2.setPaint(gp); + } + } + // g2.fillRect(0, 0, getWidth(), getHeight()); + if (isSelected()) { + g2.setPaint(kSelectedColor); + } + if (kFillButton == true) { + g2.fillRoundRect(0, 0, getWidth(), getHeight(), kBorderRadius, kBorderRadius); + } + g2.drawRoundRect(0, 0, getWidth() - 1, getHeight() - 1, kBorderRadius, kBorderRadius); + // The drawString(string) must be put after the setPaint(gradient) + g2.setPaint(Color.BLACK); + centerString(g, new Rectangle(getWidth(), getHeight()), getText(), getFont()); + + // draw account +// try { +// getIcon().paintIcon(this, g2, getHeight()/2, 4); +// } catch (Exception e) { +// } + drawIcons(g, new Rectangle(0, 0, getWidth(), getHeight())); + + + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + //dispose + g2.dispose(); + + } + + public void centerString(Graphics g, Rectangle r, String s, + Font font) { + FontRenderContext frc + = new FontRenderContext(null, true, true); + + Rectangle2D r2D = font.getStringBounds(s, frc); + int rWidth = (int) Math.round(r2D.getWidth()); + int rHeight = (int) Math.round(r2D.getHeight()); + int rX = (int) Math.round(r2D.getX()); + int rY = (int) Math.round(r2D.getY()); + + int a = (r.width / 2) - (rWidth / 2) - rX; + int b = (r.height / 2) - (rHeight / 2) - rY; + + g.setFont(font); + g.drawString(s, r.x + a, r.y + b); + } + + public void drawIcons(Graphics g, Rectangle r) { + + try { + FontRenderContext frc + = new FontRenderContext(null, true, true); + + Rectangle2D r2D = getFont().getStringBounds(getText(), frc); + int rWidth = (int) Math.round(r2D.getWidth()); + int rHeight = (int) Math.round(r2D.getHeight()); + int rX = (int) Math.round(r2D.getX()); + int rY = (int) Math.round(r2D.getY()); + + int a = (r.width / 2) - (rWidth / 2) - rX; + int b = (r.height / 2) - (rHeight / 2) - rY; + + getIcon().paintIcon(this, g, getIconTextGap(), (getHeight() / 3)); + +// if (getIcon().getIconHeight() > getHeight() / 2) { +// int zoomLevel = 10; +// int newImageWidth = getIcon().getIconWidth() * zoomLevel; +// int newImageHeight = getIcon().getIconHeight() * zoomLevel; +// BufferedImage resizedImage = new BufferedImage(newImageWidth, newImageHeight, 0); +// resizedImage.createGraphics(); +// g.drawImage((Image) getIcon(), 0, 0, newImageWidth, newImageHeight, null); +// +// } + } catch (Exception e) { + } + + } + +} diff --git a/src/com/hq/swingmaterialdesign/materialdesign/MaterialFloatingLabel.java b/src/com/hq/swingmaterialdesign/materialdesign/MaterialFloatingLabel.java index cf7d11e..fe971bb 100644 --- a/src/com/hq/swingmaterialdesign/materialdesign/MaterialFloatingLabel.java +++ b/src/com/hq/swingmaterialdesign/materialdesign/MaterialFloatingLabel.java @@ -1,102 +1,102 @@ -package com.hq.swingmaterialdesign.materialdesign; - -import com.hq.swingmaterialdesign.materialdesign.resource.MaterialColor; -import com.hq.swingmaterialdesign.materialdesign.resource.Roboto; -import com.hq.swingmaterialdesign.materialdesign.animation.AnimationListener; -import com.hq.swingmaterialdesign.materialdesign.animation.Animator; - -import javax.swing.*; -import java.awt.*; - -/** - * A floating label of a text field. - * - * @author bilux (i.bilux@gmail.com) - */ -public class MaterialFloatingLabel { - - public static final int HINT_OPACITY_MASK = 0x99000000; - - private final JTextField target; - private final Animator animator; - private Color color; - private String text; - private Color accentColor = MaterialColor.CYAN_500; - private double fontCrement; - private double targetFontSize; - private double fontSize; - - MaterialFloatingLabel(JTextField target) { - this.target = target; - targetFontSize = fontSize = 16d; - color = MaterialUtils.applyAlphaMask(target.getForeground(), HINT_OPACITY_MASK); - animator = new Animator(new AnimationListener() { - @Override - public void onStart() { - - } - - @Override - public void onAnimation(double percent) { - fontSize += fontCrement; - target.repaint(); - } - - @Override - public void onEnd() { - fontSize = targetFontSize; - target.repaint(); - } - - @Override - public void onStop() { - fontSize = targetFontSize; - target.repaint(); - } - }) - .setDelay(0) - .setDuration(100); - } - - void update() { - animator.stop(); - targetFontSize = target.isFocusOwner() ? 12d : 16d; - if (fontSize != targetFontSize) { - fontCrement = +(double) (targetFontSize - fontSize) / 100; - animator.start(); - } - - if (target.isFocusOwner()) { - color = accentColor; - } else { - color = MaterialUtils.applyAlphaMask(target.getForeground(), HINT_OPACITY_MASK); - } - } - - public void updateForeground() { - color = (MaterialUtils.applyAlphaMask(target.getForeground(), HINT_OPACITY_MASK)); - } - - public Color getAccent() { - return accentColor; - } - - public void setAccent(Color accentColor) { - this.accentColor = accentColor; - } - - String getText() { - return text; - } - - void setText(String text) { - this.text = text; - } - - void paint(Graphics2D g) { - g.setFont(Roboto.REGULAR.deriveFont((float) fontSize)); - g.setColor(color); - FontMetrics metrics = g.getFontMetrics(g.getFont()); - g.drawString(getText(), 0, metrics.getAscent() + 0); - } -} +package com.hq.swingmaterialdesign.materialdesign; + +import com.hq.swingmaterialdesign.materialdesign.resource.MaterialColor; +import com.hq.swingmaterialdesign.materialdesign.resource.Roboto; +import com.hq.swingmaterialdesign.materialdesign.animation.AnimationListener; +import com.hq.swingmaterialdesign.materialdesign.animation.Animator; + +import javax.swing.*; +import java.awt.*; + +/** + * A floating label of a text field. + * + * @author bilux (i.bilux@gmail.com) + */ +public class MaterialFloatingLabel { + + public static final int HINT_OPACITY_MASK = 0x99000000; + + private final JTextField target; + private final Animator animator; + private Color color; + private String text; + private Color accentColor = MaterialColor.CYAN_500; + private double fontCrement; + private double targetFontSize; + private double fontSize; + + MaterialFloatingLabel(JTextField target) { + this.target = target; + targetFontSize = fontSize = 16d; + color = MaterialUtils.applyAlphaMask(target.getForeground(), HINT_OPACITY_MASK); + animator = new Animator(new AnimationListener() { + @Override + public void onStart() { + + } + + @Override + public void onAnimation(double percent) { + fontSize += fontCrement; + target.repaint(); + } + + @Override + public void onEnd() { + fontSize = targetFontSize; + target.repaint(); + } + + @Override + public void onStop() { + fontSize = targetFontSize; + target.repaint(); + } + }) + .setDelay(0) + .setDuration(100); + } + + void update() { + animator.stop(); + targetFontSize = target.isFocusOwner() ? 12d : 16d; + if (fontSize != targetFontSize) { + fontCrement = +(double) (targetFontSize - fontSize) / 100; + animator.start(); + } + + if (target.isFocusOwner()) { + color = accentColor; + } else { + color = MaterialUtils.applyAlphaMask(target.getForeground(), HINT_OPACITY_MASK); + } + } + + public void updateForeground() { + color = (MaterialUtils.applyAlphaMask(target.getForeground(), HINT_OPACITY_MASK)); + } + + public Color getAccent() { + return accentColor; + } + + public void setAccent(Color accentColor) { + this.accentColor = accentColor; + } + + String getText() { + return text; + } + + void setText(String text) { + this.text = text; + } + + void paint(Graphics2D g) { + g.setFont(Roboto.REGULAR.deriveFont((float) fontSize)); + g.setColor(color); + FontMetrics metrics = g.getFontMetrics(g.getFont()); + g.drawString(getText(), 0, metrics.getAscent() + 0); + } +} diff --git a/src/com/hq/swingmaterialdesign/materialdesign/RippleEffect.java b/src/com/hq/swingmaterialdesign/materialdesign/RippleEffect.java index a884d6b..b7eeab5 100644 --- a/src/com/hq/swingmaterialdesign/materialdesign/RippleEffect.java +++ b/src/com/hq/swingmaterialdesign/materialdesign/RippleEffect.java @@ -1,168 +1,172 @@ -package com.hq.swingmaterialdesign.materialdesign; - -import com.hq.swingmaterialdesign.materialdesign.animation.AnimationListener; -import com.hq.swingmaterialdesign.materialdesign.animation.Animator; -import javax.swing.*; -import java.awt.*; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; - -/** - * A {@code RippleEffect} is applied into certain components, like buttons and - * certain list elements. Basically, is that wave of color that appears when you - * click stuff. - * - * @author bilux (i.bilux@gmail.com) - */ -public class RippleEffect { - - private final JComponent target; - private final RippleAnimation ripple = new RippleAnimation(); - - private RippleEffect(final JComponent component) { - this.target = component; - } - - /** - * Paints this effect. Each component is responsible of calling {@link - * #paint(Graphics)} in order to display the effect. Here's an example of - * how the ripple effect can be used: - * - * @param g canvas - */ - public void paint(Graphics g) { - if (ripple.isRippling()) { - Graphics2D g2 = (Graphics2D) g; - float rippleOpacity = (float) ripple.getRippleOpacity(); - Point rippleCenter = ripple.getRippleCenter(); - int rippleRadius = (int) ripple.getRippleRadius(); - Color fg = g2.getColor(); - g2.setColor(new Color(fg.getRed() / 255f, fg.getGreen() / 255f, fg.getBlue() / 255f, rippleOpacity)); - g2.fillOval(rippleCenter.x - rippleRadius, rippleCenter.y - rippleRadius, 2 * rippleRadius, 2 * rippleRadius); - } - } - - /** - * Adds a ripple at the given point. - * - * @param point point to add the ripple at - * @param maxRadius the maximum radius of the ripple - */ - private void addRipple(Point point, int maxRadius) { - ripple.setRipple(point, maxRadius); - ripple.start(); - } - - /** - * Creates a ripple effect for the given component. Each component is - * responsible of calling {@link #paint(Graphics)} in order to display the - * effect. Here's an example of how the ripple effect can be used: - * - * @param target target component - * @return ripple effect for that component - * @see MaterialButton for an example of how the ripple effect is used - */ - public static RippleEffect applyTo(final JComponent target) { - final RippleEffect rippleEffect = new RippleEffect(target); - target.addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(MouseEvent e) { - rippleEffect.addRipple(e.getPoint(), target.getWidth()); - } - }); - return rippleEffect; - } - - /** - * Creates a ripple effect for the given component that is limited to the - * component's size and will always start in the center. Each component is - * responsible of calling {@link #paint(Graphics)} in order to display the - * effect. Here's an example of how the ripple effect can be used: - * - * @param target target component - * @return ripple effect for that component - * @see MaterialButton for an example of how the ripple effect is used - */ - public static RippleEffect applyFixedTo(final JComponent target) { - final RippleEffect rippleEffect = new RippleEffect(target); - target.addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(MouseEvent e) { - rippleEffect.addRipple(new Point(24, 24), target.getWidth() / 2); - } - }); - return rippleEffect; - } - - /** - * A ripple animation (one ripple circle after one click). - */ - private class RippleAnimation { - - private final Animator animator; - private Point rippleCenter; - private int maxRadius; - private double rippleRadius; - private double targetRippleRadius; - private double rippleRadiusCrement; - private double rippleOpacity; - - private RippleAnimation() { - animator = new Animator(new AnimationListener() { - @Override - public void onStart() { - rippleRadius = 0; - targetRippleRadius = maxRadius; - rippleRadiusCrement = +(double) (targetRippleRadius - rippleRadius); - rippleOpacity = 0.5; - } - - @Override - public void onAnimation(double percent) { - rippleRadius = rippleRadiusCrement * percent * percent; - rippleOpacity = 0.5 * Math.sin(3.0 * percent * percent); - target.repaint(); - } - - @Override - public void onEnd() { - rippleRadius = 0; - target.repaint(); - } - - @Override - public void onStop() { - rippleRadius = 0; - target.repaint(); - } - }) - .setDelay(0) - .setDuration(999); - } - - void start() { - animator.start(); - } - - public void setRipple(Point rippleCenter, int maxRadius) { - this.rippleCenter = rippleCenter; - this.maxRadius = maxRadius; - } - - public double getRippleOpacity() { - return rippleOpacity; - } - - public Point getRippleCenter() { - return rippleCenter; - } - - public double getRippleRadius() { - return rippleRadius; - } - - public boolean isRippling() { - return animator.isRunning(); - } - } -} +package com.hq.swingmaterialdesign.materialdesign; + +import com.hq.swingmaterialdesign.materialdesign.animation.AnimationListener; +import com.hq.swingmaterialdesign.materialdesign.animation.Animator; +import javax.swing.*; +import java.awt.*; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +/** + * A {@code RippleEffect} is applied into certain components, like buttons and + * certain list elements. Basically, is that wave of color that appears when you + * click stuff. + * + * @author bilux (i.bilux@gmail.com) + */ +public class RippleEffect { + + private final JComponent target; + private final RippleAnimation ripple = new RippleAnimation(); + + private RippleEffect(final JComponent component) { + this.target = component; + } + + /** + * Paints this effect. Each component is responsible of calling {@link + * #paint(Graphics)} in order to display the effect. Here's an example of + * how the ripple effect can be used: + * + * @param g canvas + */ + public void paint(Graphics g) { + if (ripple.isRippling()) { + Graphics2D g2 = (Graphics2D) g; + float rippleOpacity = (float) ripple.getRippleOpacity(); + Point rippleCenter = ripple.getRippleCenter(); + int rippleRadius = (int) ripple.getRippleRadius(); + Color fg = g2.getColor(); + try { + g2.setColor(new Color(fg.getRed() / 255f, fg.getGreen() / 255f, fg.getBlue() / 255f, rippleOpacity)); + } catch (Exception e) { + // + } + g2.fillOval(rippleCenter.x - rippleRadius, rippleCenter.y - rippleRadius, 2 * rippleRadius, 2 * rippleRadius); + } + } + + /** + * Adds a ripple at the given point. + * + * @param point point to add the ripple at + * @param maxRadius the maximum radius of the ripple + */ + private void addRipple(Point point, int maxRadius) { + ripple.setRipple(point, maxRadius); + ripple.start(); + } + + /** + * Creates a ripple effect for the given component. Each component is + * responsible of calling {@link #paint(Graphics)} in order to display the + * effect. Here's an example of how the ripple effect can be used: + * + * @param target target component + * @return ripple effect for that component + * @see MaterialButton for an example of how the ripple effect is used + */ + public static RippleEffect applyTo(final JComponent target) { + final RippleEffect rippleEffect = new RippleEffect(target); + target.addMouseListener(new MouseAdapter() { + @Override + public void mousePressed(MouseEvent e) { + rippleEffect.addRipple(e.getPoint(), target.getWidth()); + } + }); + return rippleEffect; + } + + /** + * Creates a ripple effect for the given component that is limited to the + * component's size and will always start in the center. Each component is + * responsible of calling {@link #paint(Graphics)} in order to display the + * effect. Here's an example of how the ripple effect can be used: + * + * @param target target component + * @return ripple effect for that component + * @see MaterialButton for an example of how the ripple effect is used + */ + public static RippleEffect applyFixedTo(final JComponent target) { + final RippleEffect rippleEffect = new RippleEffect(target); + target.addMouseListener(new MouseAdapter() { + @Override + public void mousePressed(MouseEvent e) { + rippleEffect.addRipple(new Point(24, 24), target.getWidth() / 2); + } + }); + return rippleEffect; + } + + /** + * A ripple animation (one ripple circle after one click). + */ + private class RippleAnimation { + + private final Animator animator; + private Point rippleCenter; + private int maxRadius; + private double rippleRadius; + private double targetRippleRadius; + private double rippleRadiusCrement; + private double rippleOpacity; + + private RippleAnimation() { + animator = new Animator(new AnimationListener() { + @Override + public void onStart() { + rippleRadius = 0; + targetRippleRadius = maxRadius; + rippleRadiusCrement = +(double) (targetRippleRadius - rippleRadius); + rippleOpacity = 0.5; + } + + @Override + public void onAnimation(double percent) { + rippleRadius = rippleRadiusCrement * percent * percent; + rippleOpacity = 0.5 * Math.sin(3.0 * percent * percent); + target.repaint(); + } + + @Override + public void onEnd() { + rippleRadius = 0; + target.repaint(); + } + + @Override + public void onStop() { + rippleRadius = 0; + target.repaint(); + } + }) + .setDelay(0) + .setDuration(999); + } + + void start() { + animator.start(); + } + + public void setRipple(Point rippleCenter, int maxRadius) { + this.rippleCenter = rippleCenter; + this.maxRadius = maxRadius; + } + + public double getRippleOpacity() { + return rippleOpacity; + } + + public Point getRippleCenter() { + return rippleCenter; + } + + public double getRippleRadius() { + return rippleRadius; + } + + public boolean isRippling() { + return animator.isRunning(); + } + } +} diff --git a/src/com/hq/swingmaterialdesign/materialdesign/animation/Animator.java b/src/com/hq/swingmaterialdesign/materialdesign/animation/Animator.java index 9395241..85982f6 100644 --- a/src/com/hq/swingmaterialdesign/materialdesign/animation/Animator.java +++ b/src/com/hq/swingmaterialdesign/materialdesign/animation/Animator.java @@ -1,67 +1,71 @@ -package com.hq.swingmaterialdesign.materialdesign.animation; - -import javax.swing.*; - -/** - * - * @author bilux (i.bilux@gmail.com) - */ -public class Animator { - - private final AnimationListener animationListener; - private Timer animatorTimer; - - private int duration; - private int takenTime; - private long startTime; - - public Animator(AnimationListener listener) { - this.animationListener = listener; - - animatorTimer = new Timer(1, e -> { - takenTime = (int) (System.currentTimeMillis() - startTime); - animationListener.onAnimation((double) takenTime / duration); - if (takenTime >= duration) { - SwingUtilities.invokeLater(() -> { - animatorTimer.stop(); - animationListener.onEnd(); - }); - } - }); - animatorTimer.setCoalesce(true); - } - - public Animator setDelay(int delay) { - animatorTimer.setInitialDelay(delay); - return this; - } - - public Animator setDuration(int duration) { - this.duration = duration; - return this; - } - - public int getDuration() { - return duration; - } - - public void start() { - animatorTimer.stop(); - animationListener.onStart(); - startTime = System.currentTimeMillis(); - - animatorTimer.start(); - } - - public Animator stop() { - if (animatorTimer != null && animatorTimer.isRunning()) { - animationListener.onStop(); - animatorTimer.stop(); - } - return this; - } - - public boolean isRunning() { - return animatorTimer != null && animatorTimer.isRunning(); - } -} +package com.hq.swingmaterialdesign.materialdesign.animation; + +import javax.swing.*; + +/** + * + * @author bilux (i.bilux@gmail.com) + */ +public class Animator { + + private final AnimationListener animationListener; + private Timer animatorTimer; + + private int duration; + private int takenTime; + private long startTime; + + public Animator(AnimationListener listener) { + this.animationListener = listener; + + animatorTimer = new Timer(1, e -> { + takenTime = (int) (System.currentTimeMillis() - startTime); + try { + animationListener.onAnimation((double) takenTime / duration * 2); + } catch (java.lang.IllegalArgumentException except) { + System.out.println("Tá certo fio, confia"); + } + if (takenTime >= (duration / 2)) { + SwingUtilities.invokeLater(() -> { + animatorTimer.stop(); + animationListener.onEnd(); + }); + } + }); + animatorTimer.setCoalesce(true); + } + + public Animator setDelay(int delay) { + animatorTimer.setInitialDelay(delay); + return this; + } + + public Animator setDuration(int duration) { + this.duration = duration; + return this; + } + + public int getDuration() { + return duration; + } + + public void start() { + animatorTimer.stop(); + animationListener.onStart(); + startTime = System.currentTimeMillis(); + + animatorTimer.start(); + } + + public Animator stop() { + if (animatorTimer != null && animatorTimer.isRunning()) { + animationListener.onStop(); + animatorTimer.stop(); + } + return this; + } + + public boolean isRunning() { + return animatorTimer != null && animatorTimer.isRunning(); + } +} diff --git a/src/com/hq/swingmaterialdesign/materialdesign/resource/Nunito.java b/src/com/hq/swingmaterialdesign/materialdesign/resource/Nunito.java new file mode 100644 index 0000000..036f070 --- /dev/null +++ b/src/com/hq/swingmaterialdesign/materialdesign/resource/Nunito.java @@ -0,0 +1,37 @@ +package com.hq.swingmaterialdesign.materialdesign.resource; + +import java.awt.*; +import java.io.IOException; +import java.io.InputStream; + +/** + * The Nunito font. + * + * + * @author abner (abner.js05@gmail.com) + */ +public class Nunito { + + public static final Font BLACK = loadFont("Nunito-Black.ttf").deriveFont(Font.BOLD); + public static final Font BLACK_ITALIC = loadFont("Nunito-BlackItalic.ttf").deriveFont(Font.BOLD | Font.ITALIC); + public static final Font BOLD = loadFont("Nunito-Bold.ttf").deriveFont(Font.BOLD); + public static final Font BOLD_ITALIC = loadFont("Nunito-BoldItalic.ttf").deriveFont(Font.BOLD | Font.ITALIC); + public static final Font EXTRA_BOLD = loadFont("Nunito-ExtraBold.ttf").deriveFont(Font.BOLD); + public static final Font EXTRA_BOLD_ITALIC = loadFont("Nunito-ExtraBoldItalic.ttf").deriveFont(Font.ITALIC); + public static final Font EXTRA_LIGHT = loadFont("Nunito-ExtraLight.ttf").deriveFont(Font.PLAIN); + public static final Font EXTRA_LIGHT_ITALIC = loadFont("Nunito-ExtraLightItalic.ttf").deriveFont(Font.ITALIC); + public static final Font LIGHT = loadFont("Nunito-Light.ttf").deriveFont(Font.PLAIN); + public static final Font LIGHT_ITALIC = loadFont("Nunito-LightItalic.ttf").deriveFont(Font.ITALIC); + public static final Font REGULAR = loadFont("Nunito-Regular.ttf").deriveFont(Font.PLAIN); + public static final Font REGULAR_ITALIC = loadFont("Nunito-RegularItalic.ttf").deriveFont(Font.ITALIC); + public static final Font SEMI_BOLD = loadFont("Roboto-SemiBold.ttf").deriveFont(Font.PLAIN); + public static final Font SEMI_BOLD_ITALIC = loadFont("Roboto-SemiBoldItalic.ttf").deriveFont(Font.ITALIC); + + private static Font loadFont(String resourceName) { + try (InputStream inputStream = Nunito.class.getResourceAsStream("/resources/fonts/" + resourceName)) { + return Font.createFont(Font.TRUETYPE_FONT, inputStream); + } catch (IOException | FontFormatException e) { + throw new RuntimeException("Could not load " + resourceName, e); + } + } +} diff --git a/src/resources/fonts/Nunito-Black.ttf b/src/resources/fonts/Nunito-Black.ttf new file mode 100644 index 0000000..330a207 Binary files /dev/null and b/src/resources/fonts/Nunito-Black.ttf differ diff --git a/src/resources/fonts/Nunito-BlackItalic.ttf b/src/resources/fonts/Nunito-BlackItalic.ttf new file mode 100644 index 0000000..2fe2ecf Binary files /dev/null and b/src/resources/fonts/Nunito-BlackItalic.ttf differ diff --git a/src/resources/fonts/Nunito-Bold.ttf b/src/resources/fonts/Nunito-Bold.ttf new file mode 100644 index 0000000..99d0735 Binary files /dev/null and b/src/resources/fonts/Nunito-Bold.ttf differ diff --git a/src/resources/fonts/Nunito-BoldItalic.ttf b/src/resources/fonts/Nunito-BoldItalic.ttf new file mode 100644 index 0000000..35d6d27 Binary files /dev/null and b/src/resources/fonts/Nunito-BoldItalic.ttf differ diff --git a/src/resources/fonts/Nunito-ExtraBold.ttf b/src/resources/fonts/Nunito-ExtraBold.ttf new file mode 100644 index 0000000..993de65 Binary files /dev/null and b/src/resources/fonts/Nunito-ExtraBold.ttf differ diff --git a/src/resources/fonts/Nunito-ExtraBoldItalic.ttf b/src/resources/fonts/Nunito-ExtraBoldItalic.ttf new file mode 100644 index 0000000..9d569fd Binary files /dev/null and b/src/resources/fonts/Nunito-ExtraBoldItalic.ttf differ diff --git a/src/resources/fonts/Nunito-ExtraLight.ttf b/src/resources/fonts/Nunito-ExtraLight.ttf new file mode 100644 index 0000000..2b71830 Binary files /dev/null and b/src/resources/fonts/Nunito-ExtraLight.ttf differ diff --git a/src/resources/fonts/Nunito-ExtraLightItalic.ttf b/src/resources/fonts/Nunito-ExtraLightItalic.ttf new file mode 100644 index 0000000..77bfabd Binary files /dev/null and b/src/resources/fonts/Nunito-ExtraLightItalic.ttf differ diff --git a/src/resources/fonts/Nunito-Light.ttf b/src/resources/fonts/Nunito-Light.ttf new file mode 100644 index 0000000..54a9a90 Binary files /dev/null and b/src/resources/fonts/Nunito-Light.ttf differ diff --git a/src/resources/fonts/Nunito-LightItalic.ttf b/src/resources/fonts/Nunito-LightItalic.ttf new file mode 100644 index 0000000..8dbb8dc Binary files /dev/null and b/src/resources/fonts/Nunito-LightItalic.ttf differ diff --git a/src/resources/fonts/Nunito-Regular.ttf b/src/resources/fonts/Nunito-Regular.ttf new file mode 100644 index 0000000..fb9a17a Binary files /dev/null and b/src/resources/fonts/Nunito-Regular.ttf differ diff --git a/src/resources/fonts/Nunito-RegularItalic.ttf b/src/resources/fonts/Nunito-RegularItalic.ttf new file mode 100644 index 0000000..5f88353 Binary files /dev/null and b/src/resources/fonts/Nunito-RegularItalic.ttf differ diff --git a/src/resources/fonts/Nunito-SemiBold.ttf b/src/resources/fonts/Nunito-SemiBold.ttf new file mode 100644 index 0000000..bd39ecf Binary files /dev/null and b/src/resources/fonts/Nunito-SemiBold.ttf differ diff --git a/src/resources/fonts/Nunito-SemiBoldItalic.ttf b/src/resources/fonts/Nunito-SemiBoldItalic.ttf new file mode 100644 index 0000000..d5d3dec Binary files /dev/null and b/src/resources/fonts/Nunito-SemiBoldItalic.ttf differ