├── Component.PNG ├── FlatSwing.jar ├── src └── com │ └── mommoo │ ├── resource │ ├── img │ │ ├── cat.png │ │ ├── dog.png │ │ ├── pig.png │ │ ├── check.png │ │ ├── frog.png │ │ ├── girin.png │ │ ├── left.png │ │ ├── lion.png │ │ ├── panda.png │ │ ├── right.png │ │ ├── sheep.png │ │ ├── test.png │ │ ├── tiger.png │ │ ├── write.png │ │ └── big_image.jpg │ └── font │ │ ├── NanumGothic.ttf │ │ └── NanumGothicBold.ttf │ ├── flat │ ├── image │ │ ├── ImageAlignment.java │ │ ├── ImageOption.java │ │ └── FlatImagePanel.java │ ├── layout │ │ ├── linear │ │ │ ├── Orientation.java │ │ │ ├── Alignment.java │ │ │ ├── constraints │ │ │ │ ├── LinearSpace.java │ │ │ │ └── LinearConstraints.java │ │ │ ├── LinearLayoutProperty.java │ │ │ ├── ConstraintsFinder.java │ │ │ └── Example.java │ │ └── exception │ │ │ └── MismatchException.java │ ├── frame │ │ ├── listener │ │ │ ├── OnExitListener.java │ │ │ ├── OnMinimizeListener.java │ │ │ └── OnSizeChangeListener.java │ │ ├── popup │ │ │ └── OnItemClickListener.java │ │ ├── FrameLocation.java │ │ ├── titlebar │ │ │ ├── navigation │ │ │ │ ├── listener │ │ │ │ │ ├── FocusLostListener.java │ │ │ │ │ ├── FocusGainListener.java │ │ │ │ │ ├── NavigationControlListener.java │ │ │ │ │ └── MouseFocusAnimationListener.java │ │ │ │ ├── button │ │ │ │ │ ├── ViewModel.java │ │ │ │ │ ├── NavigationButtonType.java │ │ │ │ │ ├── SizeNavigationButton.java │ │ │ │ │ ├── MiniMumNavigationButton.java │ │ │ │ │ ├── ExitNavigationButton.java │ │ │ │ │ ├── NavigationButtonFactory.java │ │ │ │ │ ├── NavigationButton.java │ │ │ │ │ └── NavigationButtonModel.java │ │ │ │ └── controller │ │ │ │ │ └── NavigationControlPanel.java │ │ │ └── TitleLabel.java │ │ ├── colorpicker │ │ │ ├── GuideView.java │ │ │ ├── HSB.java │ │ │ ├── ColorConfirmView.java │ │ │ ├── ColorApplyView.java │ │ │ ├── HSB_View.java │ │ │ └── ColorInfoView.java │ │ ├── dialog │ │ │ ├── DialogComponentInfo.java │ │ │ └── DialogButtonInfo.java │ │ ├── FlatColorPicker.java │ │ ├── CommonJFrame.java │ │ ├── CommonTitleBar.java │ │ ├── ShadowPaintHandler.java │ │ └── FlatPopUpList.java │ ├── list │ │ ├── model │ │ │ ├── onComputeScroll.java │ │ │ └── SelectionModel.java │ │ ├── listener │ │ │ ├── FlatScrollListener.java │ │ │ ├── OnDragListener.java │ │ │ └── OnSelectionListener.java │ │ ├── MouseEventFactory.java │ │ ├── CompIndexList.java │ │ └── SelectionRange.java │ ├── component │ │ ├── pager │ │ │ ├── FlatTabAlignment.java │ │ │ ├── OnPageEventListener.java │ │ │ ├── OnPageSelectedListener.java │ │ │ ├── FlatAnimator.java │ │ │ ├── FlatPageColor.java │ │ │ ├── FlatTabIndicator.java │ │ │ ├── FlatPageSlider.java │ │ │ ├── FlatTabPanel.java │ │ │ └── FlatPage.java │ │ ├── OnLayoutListener.java │ │ ├── OnClickListener.java │ │ ├── OnPaintListener.java │ │ ├── OnPositionClickListener.java │ │ ├── MouseClickAdapter.java │ │ ├── seekbar │ │ │ ├── FlatSeekBarColor.java │ │ │ └── FlatSeekBarHandle.java │ │ ├── FlatMouseAdapter.java │ │ └── PaddingWrapPanel.java │ ├── text │ │ ├── textarea │ │ │ ├── alignment │ │ │ │ ├── FlatVerticalAlignment.java │ │ │ │ └── FlatHorizontalAlignment.java │ │ │ ├── AutoResizeModel.java │ │ │ ├── EditorListener.java │ │ │ ├── ContentsBounds.java │ │ │ ├── FlatCaret.java │ │ │ └── FlatWrapEditorKit.java │ │ ├── textfield │ │ │ ├── format │ │ │ │ ├── FlatTextFormat.java │ │ │ │ └── FormattedDocument.java │ │ │ ├── NormalTextField.java │ │ │ ├── PasswordTextField.java │ │ │ ├── TextFieldProxy.java │ │ │ └── FlatGuideTextPanel.java │ │ └── label │ │ │ └── FlatLabel.java │ ├── button │ │ ├── ButtonViewModel.java │ │ ├── ripple │ │ │ ├── RippleModel.java │ │ │ └── RippleEffect.java │ │ ├── ButtonEventRepository.java │ │ └── FlatAreaMouseLocation.java │ ├── border │ │ └── FlatEmptyBorder.java │ ├── select │ │ ├── HoverColorChangeListener.java │ │ ├── CheckBox.java │ │ └── FlatCheckBox.java │ └── utils │ │ └── FlatColor.java │ ├── animation │ ├── timeInterpolator │ │ ├── LinearTimeInterpolator.java │ │ ├── AccelerateInterpolator.java │ │ ├── AnticipateInterpolator.java │ │ ├── OvershootInterpolator.java │ │ └── TimeInterpolator.java │ ├── AnimationListener.java │ └── AnimationAdapter.java │ ├── util │ ├── ComponentUtils.java │ ├── CursorType.java │ ├── ColorManager.java │ ├── ImageUtils.java │ ├── KeyManager.java │ ├── FontManager.java │ ├── ScreenManager.java │ ├── ImageManager.java │ ├── FastGaussianBlur.java │ ├── StringUtils.java │ └── RXTextUtilities.java │ └── helper │ └── ClassUtils.java ├── .idea ├── encodings.xml ├── libraries │ └── src.xml ├── vcs.xml ├── modules.xml ├── misc.xml └── artifacts │ └── FlatSwing_jar.xml ├── FlatSwing.iml ├── LICENSE └── README.md /Component.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mommoo/FlatSwing/HEAD/Component.PNG -------------------------------------------------------------------------------- /FlatSwing.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mommoo/FlatSwing/HEAD/FlatSwing.jar -------------------------------------------------------------------------------- /src/com/mommoo/resource/img/cat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mommoo/FlatSwing/HEAD/src/com/mommoo/resource/img/cat.png -------------------------------------------------------------------------------- /src/com/mommoo/resource/img/dog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mommoo/FlatSwing/HEAD/src/com/mommoo/resource/img/dog.png -------------------------------------------------------------------------------- /src/com/mommoo/resource/img/pig.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mommoo/FlatSwing/HEAD/src/com/mommoo/resource/img/pig.png -------------------------------------------------------------------------------- /src/com/mommoo/resource/img/check.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mommoo/FlatSwing/HEAD/src/com/mommoo/resource/img/check.png -------------------------------------------------------------------------------- /src/com/mommoo/resource/img/frog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mommoo/FlatSwing/HEAD/src/com/mommoo/resource/img/frog.png -------------------------------------------------------------------------------- /src/com/mommoo/resource/img/girin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mommoo/FlatSwing/HEAD/src/com/mommoo/resource/img/girin.png -------------------------------------------------------------------------------- /src/com/mommoo/resource/img/left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mommoo/FlatSwing/HEAD/src/com/mommoo/resource/img/left.png -------------------------------------------------------------------------------- /src/com/mommoo/resource/img/lion.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mommoo/FlatSwing/HEAD/src/com/mommoo/resource/img/lion.png -------------------------------------------------------------------------------- /src/com/mommoo/resource/img/panda.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mommoo/FlatSwing/HEAD/src/com/mommoo/resource/img/panda.png -------------------------------------------------------------------------------- /src/com/mommoo/resource/img/right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mommoo/FlatSwing/HEAD/src/com/mommoo/resource/img/right.png -------------------------------------------------------------------------------- /src/com/mommoo/resource/img/sheep.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mommoo/FlatSwing/HEAD/src/com/mommoo/resource/img/sheep.png -------------------------------------------------------------------------------- /src/com/mommoo/resource/img/test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mommoo/FlatSwing/HEAD/src/com/mommoo/resource/img/test.png -------------------------------------------------------------------------------- /src/com/mommoo/resource/img/tiger.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mommoo/FlatSwing/HEAD/src/com/mommoo/resource/img/tiger.png -------------------------------------------------------------------------------- /src/com/mommoo/resource/img/write.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mommoo/FlatSwing/HEAD/src/com/mommoo/resource/img/write.png -------------------------------------------------------------------------------- /src/com/mommoo/resource/img/big_image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mommoo/FlatSwing/HEAD/src/com/mommoo/resource/img/big_image.jpg -------------------------------------------------------------------------------- /src/com/mommoo/resource/font/NanumGothic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mommoo/FlatSwing/HEAD/src/com/mommoo/resource/font/NanumGothic.ttf -------------------------------------------------------------------------------- /src/com/mommoo/resource/font/NanumGothicBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mommoo/FlatSwing/HEAD/src/com/mommoo/resource/font/NanumGothicBold.ttf -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/image/ImageAlignment.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.image; 2 | 3 | public enum ImageAlignment { 4 | START, 5 | CENTER, 6 | END 7 | } 8 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/layout/linear/Orientation.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.layout.linear; 2 | 3 | public enum Orientation { 4 | VERTICAL, 5 | HORIZONTAL; 6 | } 7 | -------------------------------------------------------------------------------- /.idea/libraries/src.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/frame/listener/OnExitListener.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.frame.listener; 2 | 3 | public interface OnExitListener { 4 | public void onExit(); 5 | } 6 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/layout/linear/Alignment.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.layout.linear; 2 | 3 | public enum Alignment { 4 | START, 5 | CENTER, 6 | END; 7 | } 8 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/list/model/onComputeScroll.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.list.model; 2 | 3 | public interface onComputeScroll { 4 | public void onScrollWhenPainting(); 5 | } 6 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/component/pager/FlatTabAlignment.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.component.pager; 2 | 3 | public enum FlatTabAlignment { 4 | START, 5 | CENTER, 6 | END; 7 | } 8 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/component/pager/OnPageEventListener.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.component.pager; 2 | 3 | public interface OnPageEventListener { 4 | public void onSelected(); 5 | } 6 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/frame/listener/OnMinimizeListener.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.frame.listener; 2 | 3 | public interface OnMinimizeListener { 4 | public void onMinimize(); 5 | } 6 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/list/listener/FlatScrollListener.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.list.listener; 2 | 3 | public interface FlatScrollListener { 4 | public void onDrag(int scrollSensitivity); 5 | } 6 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/component/OnLayoutListener.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.component; 2 | 3 | public interface OnLayoutListener { 4 | public void onLayout(int availableWidth, int availableHeight); 5 | } 6 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/component/OnClickListener.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.component; 2 | 3 | import java.awt.*; 4 | 5 | public interface OnClickListener { 6 | public void onClick(Component component); 7 | } 8 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/frame/popup/OnItemClickListener.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.frame.popup; 2 | 3 | public interface OnItemClickListener { 4 | public void onItemClick(int position, String message); 5 | } 6 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/text/textarea/alignment/FlatVerticalAlignment.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.text.textarea.alignment; 2 | 3 | public enum FlatVerticalAlignment { 4 | TOP, 5 | CENTER, 6 | BOTTOM 7 | } 8 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/component/OnPaintListener.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.component; 2 | 3 | import java.awt.*; 4 | 5 | public interface OnPaintListener { 6 | public void onPaint(Graphics2D graphics2D); 7 | } 8 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/frame/FrameLocation.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.frame; 2 | 3 | public enum FrameLocation{ 4 | NONE, 5 | CENTER_AT_SCREEN, 6 | CENTER_AT_COMPONENT, 7 | RELATIVE_AT_COMPONENT; 8 | } 9 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/frame/titlebar/navigation/listener/FocusLostListener.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.frame.titlebar.navigation.listener; 2 | 3 | public interface FocusLostListener { 4 | public void lost(); 5 | } 6 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/list/model/SelectionModel.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.list.model; 2 | 3 | public interface SelectionModel { 4 | public int getItemSize(); 5 | public boolean isSingleSelectionMode(); 6 | } 7 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/button/ButtonViewModel.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.button; 2 | 3 | public interface ButtonViewModel { 4 | public void repaint(); 5 | public int getWidth(); 6 | public int getHeight(); 7 | } 8 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/image/ImageOption.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.image; 2 | 3 | public enum ImageOption{ 4 | MATCH_PARENT, 5 | MATCH_WIDTH_KEEP_RATIO, 6 | MATCH_HEIGHT_KEEP_RATIO, 7 | BASIC_IMAGE_SIZE 8 | } 9 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/component/pager/OnPageSelectedListener.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.component.pager; 2 | 3 | @FunctionalInterface 4 | public interface OnPageSelectedListener { 5 | public void onPageSelected(int index); 6 | } 7 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/frame/titlebar/navigation/button/ViewModel.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.frame.titlebar.navigation.button; 2 | 3 | public interface ViewModel { 4 | public int getWidth(); 5 | public int getHeight(); 6 | } 7 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/component/OnPositionClickListener.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.component; 2 | 3 | import java.awt.*; 4 | 5 | public interface OnPositionClickListener { 6 | public void onClick(int position, Component target); 7 | } 8 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/text/textfield/format/FlatTextFormat.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.text.textfield.format; 2 | 3 | public enum FlatTextFormat { 4 | NUMBER_DECIMAL, 5 | TEXT, 6 | HEX_COLOR, 7 | SPECIAL_CHARACTER; 8 | } 9 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/frame/listener/OnSizeChangeListener.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.frame.listener; 2 | 3 | import java.awt.*; 4 | 5 | public interface OnSizeChangeListener { 6 | public void onSizeChanged(Dimension size, Point location); 7 | } 8 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/frame/titlebar/navigation/listener/FocusGainListener.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.frame.titlebar.navigation.listener; 2 | 3 | /** 4 | * Created by mommoo on 2017-07-13. 5 | */ 6 | public interface FocusGainListener { 7 | public void gain(); 8 | } 9 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/layout/linear/constraints/LinearSpace.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.layout.linear.constraints; 2 | 3 | public enum LinearSpace implements Cloneable{ 4 | WRAP_CONTENT, 5 | WRAP_CENTER_CONTENT, 6 | WRAP_END_CONTENT, 7 | MATCH_PARENT; 8 | } 9 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/com/mommoo/animation/timeInterpolator/LinearTimeInterpolator.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.animation.timeInterpolator; 2 | 3 | public class LinearTimeInterpolator extends TimeInterpolator{ 4 | @Override 5 | public double getFactor(double percent) { 6 | return percent; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/frame/titlebar/navigation/button/NavigationButtonType.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.frame.titlebar.navigation.button; 2 | 3 | /** 4 | * Created by mommoo on 2017-07-13. 5 | */ 6 | public enum NavigationButtonType { 7 | MINI, 8 | SIZE, 9 | EXIT; 10 | } 11 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/layout/exception/MismatchException.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.layout.exception; 2 | 3 | public class MismatchException extends Exception{ 4 | public MismatchException() { 5 | super("Sum of component's weight isn't bigger than layout weightSum"); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/layout/linear/LinearLayoutProperty.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.layout.linear; 2 | 3 | interface LinearLayoutProperty { 4 | public Orientation getOrientation(); 5 | public Alignment getAlignment(); 6 | public int getGap(); 7 | public int getWeightSum(); 8 | } 9 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/list/listener/OnDragListener.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.list.listener; 2 | 3 | import java.awt.*; 4 | import java.util.List; 5 | 6 | public interface OnDragListener { 7 | public void onDrag(int beginIndex, int endIndex, List selectionList); 8 | } 9 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/text/textarea/AutoResizeModel.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.text.textarea; 2 | 3 | import java.awt.*; 4 | 5 | public interface AutoResizeModel { 6 | public String getText(); 7 | public FontMetrics getFontMetrics(); 8 | public float getLineSpacing(); 9 | } 10 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/com/mommoo/animation/timeInterpolator/AccelerateInterpolator.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.animation.timeInterpolator; 2 | 3 | public class AccelerateInterpolator extends TimeInterpolator{ 4 | @Override 5 | public double getFactor(double percent) { 6 | return Math.pow(percent, 3); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/com/mommoo/animation/AnimationListener.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.animation; 2 | 3 | import java.util.List; 4 | 5 | public interface AnimationListener { 6 | public void onStart(); 7 | public void onAnimation(List resultList); 8 | public void onStop(); 9 | public void onEnd(); 10 | } 11 | -------------------------------------------------------------------------------- /.idea/artifacts/FlatSwing_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | $PROJECT_DIR$/out/artifacts/FlatSwing_jar 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/list/listener/OnSelectionListener.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.list.listener; 2 | 3 | import java.awt.*; 4 | import java.util.List; 5 | 6 | @FunctionalInterface 7 | public interface OnSelectionListener{ 8 | public void onSelection(int beginIndex, int endIndex, List selectionList); 9 | } 10 | -------------------------------------------------------------------------------- /src/com/mommoo/animation/timeInterpolator/AnticipateInterpolator.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.animation.timeInterpolator; 2 | 3 | public class AnticipateInterpolator extends TimeInterpolator{ 4 | private static final float TENSION = 2.0f; 5 | 6 | @Override 7 | public double getFactor(double percent) { 8 | return percent * percent * ((TENSION + 1) * percent - TENSION); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/component/pager/FlatAnimator.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.component.pager; 2 | 3 | import com.mommoo.animation.Animator; 4 | import com.mommoo.animation.timeInterpolator.AccelerateInterpolator; 5 | 6 | abstract class FlatAnimator extends Animator { 7 | FlatAnimator(){ 8 | setTimeInterpolator(new AccelerateInterpolator()); 9 | setDuration(150); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/frame/titlebar/navigation/listener/NavigationControlListener.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.frame.titlebar.navigation.listener; 2 | 3 | 4 | import com.mommoo.flat.frame.titlebar.navigation.button.NavigationButtonType; 5 | 6 | /** 7 | * Created by mommoo on 2017-07-13. 8 | */ 9 | public interface NavigationControlListener { 10 | public void onNavigationClick(NavigationButtonType buttonType); 11 | } 12 | -------------------------------------------------------------------------------- /src/com/mommoo/animation/timeInterpolator/OvershootInterpolator.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.animation.timeInterpolator; 2 | 3 | public class OvershootInterpolator extends TimeInterpolator{ 4 | private static final float TENSION = 2.0f; 5 | @Override 6 | public double getFactor(double percent) { 7 | percent -= 1.0f; 8 | return percent * percent * ((TENSION + 1) * percent + TENSION) + 1.0f; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/button/ripple/RippleModel.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.button.ripple; 2 | 3 | import java.awt.*; 4 | import java.awt.event.ActionEvent; 5 | import java.util.List; 6 | import java.util.function.Consumer; 7 | 8 | public interface RippleModel { 9 | public boolean isOnEventLaterEffect(); 10 | public int getRippleDuration(); 11 | public int getRippleHoldDuration(); 12 | public Color getRippleColor(); 13 | public float getRippleColorOpacity(); 14 | } 15 | -------------------------------------------------------------------------------- /src/com/mommoo/animation/AnimationAdapter.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.animation; 2 | 3 | import java.util.List; 4 | 5 | public class AnimationAdapter implements AnimationListener{ 6 | @Override 7 | public void onStart() { 8 | 9 | } 10 | 11 | @Override 12 | public void onAnimation(List resultList) { 13 | 14 | } 15 | 16 | @Override 17 | public void onStop() { 18 | 19 | } 20 | 21 | @Override 22 | public void onEnd() { 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/com/mommoo/util/ComponentUtils.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.util; 2 | 3 | import java.awt.*; 4 | 5 | public class ComponentUtils { 6 | private ComponentUtils(){ 7 | 8 | } 9 | 10 | public static Dimension getAvailableSize(Container comp){ 11 | Insets insets = comp.getInsets(); 12 | return new ComputableDimension(comp.getSize()) 13 | .subDimension(insets.left, insets.top) 14 | .subDimension(insets.right, insets.bottom); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/text/textarea/EditorListener.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.text.textarea; 2 | 3 | import com.mommoo.flat.text.textarea.alignment.FlatVerticalAlignment; 4 | 5 | import java.awt.*; 6 | import java.util.function.IntConsumer; 7 | 8 | public interface EditorListener { 9 | public FlatVerticalAlignment getVerticalAlignment(); 10 | public boolean isLineWrap(); 11 | public boolean isWrapStyleWord(); 12 | public int getViewHeight(); 13 | public int getContentsHeight(); 14 | } 15 | -------------------------------------------------------------------------------- /FlatSwing.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/border/FlatEmptyBorder.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.border; 2 | 3 | import javax.swing.border.EmptyBorder; 4 | import java.awt.*; 5 | 6 | public class FlatEmptyBorder extends EmptyBorder{ 7 | public FlatEmptyBorder(int top, int left, int bottom, int right) { 8 | super(top, left, bottom, right); 9 | } 10 | 11 | public FlatEmptyBorder(Insets borderInsets) { 12 | super(borderInsets); 13 | } 14 | 15 | public FlatEmptyBorder(int padding){ 16 | super(padding, padding, padding, padding); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/com/mommoo/util/CursorType.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.util; 2 | 3 | import java.awt.*; 4 | 5 | public enum CursorType { 6 | DEFAULT, 7 | HAND; 8 | 9 | private static final Cursor DEFAULT_CURSOR = new Cursor(Cursor.DEFAULT_CURSOR); 10 | private static final Cursor HAND_CURSOR = new Cursor(Cursor.HAND_CURSOR); 11 | 12 | public Cursor getCursor(){ 13 | 14 | switch(this) { 15 | case DEFAULT : return DEFAULT_CURSOR; 16 | case HAND : return HAND_CURSOR; 17 | } 18 | 19 | return DEFAULT_CURSOR; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/com/mommoo/animation/timeInterpolator/TimeInterpolator.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.animation.timeInterpolator; 2 | 3 | public abstract class TimeInterpolator { 4 | private double targetDelta; 5 | 6 | public abstract double getFactor(double percent); 7 | 8 | public double getTargetDelta() { 9 | return targetDelta; 10 | } 11 | 12 | public void setTargetDelta(double targetDelta) { 13 | this.targetDelta = targetDelta; 14 | } 15 | 16 | public double getValue(double percent){ 17 | return targetDelta * getFactor(percent); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/button/ButtonEventRepository.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.button; 2 | 3 | import java.awt.event.ActionEvent; 4 | import java.util.*; 5 | import java.util.function.Consumer; 6 | 7 | class ButtonEventRepository { 8 | private Map> eventMap = new HashMap<>(); 9 | 10 | void addEvent(Object key, Consumer event){ 11 | eventMap.put(key, event); 12 | } 13 | 14 | void removeEvent(Object objectKey){ 15 | eventMap.remove(objectKey); 16 | } 17 | 18 | List> getEventList() { 19 | return Collections.unmodifiableList(new ArrayList<>(eventMap.values())); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/com/mommoo/util/ColorManager.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.util; 2 | 3 | import java.awt.*; 4 | 5 | /** 6 | * Created by mommoo on 2017-07-13. 7 | */ 8 | public class ColorManager { 9 | private ColorManager(){} 10 | 11 | private static Color DEFAULT_COLOR = Color.decode("#ffffff"); 12 | private static Color COLOR_ACCENT = Color.decode("#E91E63"); 13 | 14 | public static Color getTransParentColor(){ 15 | return new Color(0.0f, 0.0f, 0.0f, 0.0f); 16 | } 17 | 18 | public static Color getFlatComponentDefaultColor(){ 19 | return DEFAULT_COLOR; 20 | } 21 | 22 | public static Color getColorAccent(){ 23 | return COLOR_ACCENT; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/frame/titlebar/navigation/button/SizeNavigationButton.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.frame.titlebar.navigation.button; 2 | 3 | import java.awt.*; 4 | 5 | /** 6 | * Created by mommoo on 2017-07-10. 7 | */ 8 | public class SizeNavigationButton extends NavigationButton { 9 | 10 | SizeNavigationButton() { 11 | super(); 12 | } 13 | 14 | @Override 15 | protected void paintShape(int STANDARD_RECT_SIZE, Graphics2D GRAPHICS_2D) { 16 | final int START_X = (getWidth() - STANDARD_RECT_SIZE)/2; 17 | final int START_Y = (getHeight() - STANDARD_RECT_SIZE)/2; 18 | GRAPHICS_2D.drawRect(START_X, START_Y, STANDARD_RECT_SIZE, STANDARD_RECT_SIZE); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/frame/titlebar/navigation/button/MiniMumNavigationButton.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.frame.titlebar.navigation.button; 2 | 3 | import java.awt.*; 4 | 5 | /** 6 | * Created by mommoo on 2017-07-10. 7 | */ 8 | public class MiniMumNavigationButton extends NavigationButton { 9 | 10 | MiniMumNavigationButton() { 11 | super(); 12 | } 13 | 14 | @Override 15 | protected void paintShape(int STANDARD_RECT_SIZE, Graphics2D GRAPHICS_2D) { 16 | final int START_X = (getWidth() - STANDARD_RECT_SIZE)/2; 17 | final int START_Y = ((getHeight() - STANDARD_RECT_SIZE)/2) + STANDARD_RECT_SIZE; 18 | GRAPHICS_2D.drawLine(START_X,START_Y,START_X+STANDARD_RECT_SIZE,START_Y); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/list/MouseEventFactory.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.list; 2 | 3 | import java.awt.*; 4 | import java.awt.event.MouseEvent; 5 | 6 | class MouseEventFactory{ 7 | static MouseEvent createMouseEvent(Component source, int id, AWTEvent event){ 8 | MouseEvent mouseEvent = (MouseEvent) event; 9 | Point point = MouseInfo.getPointerInfo().getLocation(); 10 | return new MouseEvent(source, 11 | id, 12 | System.currentTimeMillis(), 13 | mouseEvent.getModifiers(), 14 | point.x, 15 | point.y, 16 | mouseEvent.getClickCount(), 17 | mouseEvent.isPopupTrigger(), 18 | mouseEvent.getButton()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/frame/titlebar/TitleLabel.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.frame.titlebar; 2 | 3 | import com.mommoo.util.FontManager; 4 | import com.mommoo.util.ScreenManager; 5 | 6 | import javax.swing.*; 7 | import java.awt.*; 8 | 9 | /** 10 | * Created by mommoo on 2017-07-13. 11 | */ 12 | public class TitleLabel extends JLabel { 13 | private static final int TITLE_TEXT_LEFT_PADDING = ScreenManager.getInstance().dip2px(4); 14 | 15 | public TitleLabel(int fontSize){ 16 | setHorizontalAlignment(JLabel.LEFT); 17 | setVerticalAlignment(JLabel.CENTER); 18 | setOpaque(false); 19 | setFont(FontManager.getNanumGothicFont(Font.PLAIN, fontSize)); 20 | setBorder(BorderFactory.createEmptyBorder(0,TITLE_TEXT_LEFT_PADDING,0,0)); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/button/FlatAreaMouseLocation.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.button; 2 | 3 | import java.awt.*; 4 | 5 | class FlatAreaMouseLocation { 6 | 7 | private FlatAreaMouseLocation(){} 8 | 9 | static Point getLocation(Component component){ 10 | Point mouseLocation = MouseInfo.getPointerInfo().getLocation(); 11 | Point compLocation = component.getLocationOnScreen(); 12 | Dimension compDimension = component.getSize(); 13 | 14 | int minX = 0; 15 | int maxX = compDimension.width; 16 | int minY = 0; 17 | int maxY = compDimension.height; 18 | 19 | int relativeX = mouseLocation.x - compLocation.x; 20 | int relativeY = mouseLocation.y - compLocation.y; 21 | 22 | return new Point(Math.max(minX, (Math.min(maxX, relativeX))), Math.max(minY, (Math.min(maxY, relativeY)))); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/component/pager/FlatPageColor.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.component.pager; 2 | 3 | import com.mommoo.util.ColorManager; 4 | 5 | import java.awt.*; 6 | 7 | public class FlatPageColor { 8 | private static final FlatPageColor DEFAULT_PAGER_COLOR = new FlatPageColor(ColorManager.getColorAccent(), Color.BLACK); 9 | private final Color focusInColor; 10 | private final Color focusOutColor; 11 | 12 | public FlatPageColor(Color focusInColor, Color focusOutColor){ 13 | this.focusInColor = focusInColor; 14 | this.focusOutColor = focusOutColor; 15 | } 16 | 17 | static FlatPageColor getDefaultFlatPagerColor(){ 18 | return DEFAULT_PAGER_COLOR; 19 | } 20 | 21 | public Color getFocusInColor() { 22 | return focusInColor; 23 | } 24 | 25 | public Color getFocusOutColor() { 26 | return focusOutColor; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/frame/titlebar/navigation/button/ExitNavigationButton.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.frame.titlebar.navigation.button; 2 | 3 | import java.awt.*; 4 | 5 | /** 6 | * Created by mommoo on 2017-07-10. 7 | */ 8 | public class ExitNavigationButton extends NavigationButton { 9 | 10 | ExitNavigationButton() { 11 | super(); 12 | } 13 | 14 | @Override 15 | protected void paintShape(int STANDARD_RECT_SIZE, Graphics2D GRAPHICS_2D) { 16 | final int LEFT_TOP_X = (getWidth() - STANDARD_RECT_SIZE)/2; 17 | final int LEFT_TOP_Y = (getHeight() - STANDARD_RECT_SIZE)/2; 18 | GRAPHICS_2D.drawLine(LEFT_TOP_X,LEFT_TOP_Y,LEFT_TOP_X+STANDARD_RECT_SIZE,LEFT_TOP_Y+STANDARD_RECT_SIZE); 19 | 20 | final int RIGHT_TOP_X = LEFT_TOP_X + STANDARD_RECT_SIZE; 21 | final int RIGHT_TOP_Y = LEFT_TOP_Y; 22 | GRAPHICS_2D.drawLine(RIGHT_TOP_X,RIGHT_TOP_Y, LEFT_TOP_X, LEFT_TOP_Y+STANDARD_RECT_SIZE); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/layout/linear/ConstraintsFinder.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.layout.linear; 2 | 3 | import com.mommoo.flat.layout.linear.constraints.LinearConstraints; 4 | 5 | import java.awt.*; 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | public class ConstraintsFinder { 10 | private final Map FINDER = new HashMap<>(); 11 | 12 | public void put (Component component, LinearConstraints constraints) { 13 | FINDER.put(component, constraints); 14 | } 15 | 16 | public void remove (Component component) { 17 | FINDER.remove(component); 18 | } 19 | 20 | public LinearConstraints find (Component component) { 21 | return FINDER.getOrDefault(component, new LinearConstraints()); 22 | } 23 | 24 | public int getWeightSum(){ 25 | return FINDER.keySet() 26 | .stream() 27 | .mapToInt(component -> FINDER.get(component).getWeight()) 28 | .sum(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/frame/colorpicker/GuideView.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.frame.colorpicker; 2 | 3 | import com.mommoo.flat.text.label.FlatLabel; 4 | import com.mommoo.flat.text.textarea.alignment.FlatVerticalAlignment; 5 | import com.mommoo.util.ColorManager; 6 | import com.mommoo.util.FontManager; 7 | import com.mommoo.util.ScreenManager; 8 | 9 | import javax.swing.border.Border; 10 | import javax.swing.border.EmptyBorder; 11 | import java.awt.*; 12 | 13 | class GuideView extends FlatLabel { 14 | private static final ScreenManager SCREEN = ScreenManager.getInstance(); 15 | private static final Font FONT = FontManager.getNanumGothicBoldFont(SCREEN.dip2px(8)); 16 | private static final Border PADDING_BORDER = new EmptyBorder(SCREEN.dip2px(4),0,SCREEN.dip2px(2),0); 17 | 18 | GuideView(String guideText){ 19 | setVerticalAlignment(FlatVerticalAlignment.CENTER); 20 | setText(guideText.toUpperCase()); 21 | setFont(FONT); 22 | setBorder(PADDING_BORDER); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/com/mommoo/util/ImageUtils.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.util; 2 | 3 | import javax.swing.*; 4 | import java.awt.*; 5 | import java.awt.image.BufferedImage; 6 | 7 | public class ImageUtils { 8 | private ImageUtils(){ 9 | 10 | } 11 | 12 | public static BufferedImage toBufferedImage(Image image){ 13 | return toBufferedImage(image, false); 14 | } 15 | 16 | public static BufferedImage toBufferedImage(Image image, boolean antialias){ 17 | ImageIcon imageIcon = new ImageIcon(image); 18 | BufferedImage bufferedImage = new BufferedImage(imageIcon.getIconWidth(), imageIcon.getIconHeight(), BufferedImage.TYPE_4BYTE_ABGR); 19 | 20 | if (antialias){ 21 | ((Graphics2D)bufferedImage.getGraphics()).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 22 | } 23 | 24 | bufferedImage.getGraphics().drawImage(image,0,0,null); 25 | bufferedImage.getGraphics().dispose(); 26 | return bufferedImage; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/component/MouseClickAdapter.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.component; 2 | 3 | import java.awt.*; 4 | import java.awt.event.MouseAdapter; 5 | import java.awt.event.MouseEvent; 6 | 7 | public class MouseClickAdapter extends FlatMouseAdapter{ 8 | private final OnClickListener onClickListener; 9 | private Component source; 10 | 11 | public MouseClickAdapter(OnClickListener onClickListener){ 12 | this.onClickListener = onClickListener; 13 | } 14 | 15 | public MouseClickAdapter(Component source, OnClickListener onClickListener){ 16 | this(onClickListener); 17 | this.source = source; 18 | } 19 | 20 | public OnClickListener getOnClickListener() { 21 | return onClickListener; 22 | } 23 | 24 | @Override 25 | public void mouseReleased(MouseEvent e) { 26 | super.mouseReleased(e); 27 | if (source == null) source = e.getComponent(); 28 | if (isMouseClicked()){ 29 | onClickListener.onClick(source); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Mommoo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/component/seekbar/FlatSeekBarColor.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.component.seekbar; 2 | 3 | import com.mommoo.util.ColorManager; 4 | 5 | import java.awt.*; 6 | 7 | class FlatSeekBarColor { 8 | private Color backgroundSeekBarColor = Color.GRAY; 9 | private Color frontSeekBarColor = ColorManager.getColorAccent(); 10 | private Color seekBarHandleColor = ColorManager.getColorAccent().darker(); 11 | 12 | Color getBackgroundSeekBarColor() { 13 | return backgroundSeekBarColor; 14 | } 15 | 16 | void setBackgroundSeekBarColor(Color backgroundSeekBarColor) { 17 | this.backgroundSeekBarColor = backgroundSeekBarColor; 18 | } 19 | 20 | Color getFrontSeekBarColor() { 21 | return frontSeekBarColor; 22 | } 23 | 24 | void setFrontSeekBarColor(Color frontSeekBarColor) { 25 | this.frontSeekBarColor = frontSeekBarColor; 26 | } 27 | 28 | Color getSeekBarHandleColor() { 29 | return seekBarHandleColor; 30 | } 31 | 32 | void setSeekBarHandleColor(Color seekBarHandleColor) { 33 | this.seekBarHandleColor = seekBarHandleColor; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/frame/titlebar/navigation/button/NavigationButtonFactory.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.frame.titlebar.navigation.button; 2 | 3 | import java.awt.*; 4 | 5 | /** 6 | * Created by mommoo on 2017-07-13. 7 | */ 8 | public class NavigationButtonFactory { 9 | 10 | private NavigationButtonFactory(){} 11 | 12 | private static NavigationButton createNavigationButton(NavigationButtonType type){ 13 | switch(type){ 14 | case MINI : return new MiniMumNavigationButton(); 15 | case SIZE : return new SizeNavigationButton(); 16 | case EXIT : return new ExitNavigationButton(); 17 | default : return null; 18 | } 19 | } 20 | 21 | public static NavigationButton[] createNavigationButtonArray(){ 22 | NavigationButtonType[] buttonTypes = NavigationButtonType.values(); 23 | NavigationButton[] buttonArray = new NavigationButton[buttonTypes.length]; 24 | for (int i = 0 ; i < buttonTypes.length ; i++){ 25 | buttonArray[i] = NavigationButtonFactory.createNavigationButton(buttonTypes[i]); 26 | } 27 | return buttonArray; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/com/mommoo/util/KeyManager.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.util; 2 | 3 | import javax.swing.*; 4 | import java.awt.*; 5 | import java.awt.event.ActionEvent; 6 | import java.awt.event.KeyAdapter; 7 | import java.awt.event.KeyEvent; 8 | 9 | public class KeyManager { 10 | private static final String ENTER_KEY = "enter"; 11 | 12 | public interface KeyEventListener{ 13 | public void execute(); 14 | } 15 | 16 | 17 | public static void addEnterKeyListener(Component comp, final KeyEventListener listener){ 18 | comp.addKeyListener(new KeyAdapter(){ 19 | @Override 20 | public void keyReleased(KeyEvent e) { 21 | if(e.getKeyChar()==KeyEvent.VK_ENTER){ 22 | listener.execute(); 23 | } 24 | } 25 | }); 26 | } 27 | 28 | public static void addEnterKeyListener(JFrame rootFrame, final KeyEventListener listener){ 29 | final JRootPane ROOT_PANE = rootFrame.getRootPane(); 30 | ROOT_PANE.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke((char)KeyEvent.VK_ENTER),ENTER_KEY); 31 | ROOT_PANE.getActionMap().put(ENTER_KEY, new AbstractAction() { 32 | 33 | @Override 34 | public void actionPerformed(ActionEvent e) { 35 | if (listener != null) listener.execute(); 36 | } 37 | }); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/text/textarea/ContentsBounds.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.text.textarea; 2 | 3 | import java.awt.*; 4 | 5 | class ContentsBounds { 6 | private final int contentsWidth; 7 | private final int contentsHeight; 8 | private final int lineCount; 9 | 10 | ContentsBounds(int contentsWidth, int contentsHeight, int lineCount){ 11 | this.contentsWidth = contentsWidth; 12 | this.contentsHeight = contentsHeight; 13 | this.lineCount = lineCount; 14 | } 15 | 16 | public ContentsBounds(Dimension dimension, int lineCount){ 17 | this(dimension.width, dimension.height, lineCount); 18 | } 19 | 20 | int getContentsWidth(){ 21 | return contentsWidth; 22 | } 23 | 24 | int getContentsHeight(){ 25 | return contentsHeight; 26 | } 27 | 28 | Dimension getDimension(){ 29 | return new Dimension(contentsWidth, contentsHeight); 30 | } 31 | 32 | int getLineCount(){ 33 | return lineCount; 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | return "contentsWidth : " + contentsWidth +"\n"+ 39 | "contentsHeight : " + contentsHeight +"\n"+ 40 | "lineCount : " + lineCount; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/text/textarea/alignment/FlatHorizontalAlignment.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.text.textarea.alignment; 2 | 3 | public enum FlatHorizontalAlignment { 4 | /** 5 | * A possible value for paragraph alignment. This 6 | * specifies that the text is aligned to the left 7 | * indent and extra whitespace should be placed on 8 | * the right. 9 | */ 10 | LEFT, 11 | /** 12 | * A possible value for paragraph alignment. This 13 | * specifies that the text is aligned to the center 14 | * and extra whitespace should be placed equally on 15 | * the left and right. 16 | */ 17 | CENTER, 18 | 19 | /** 20 | * A possible value for paragraph alignment. This 21 | * specifies that the text is aligned to the right 22 | * indent and extra whitespace should be placed on 23 | * the left. 24 | */ 25 | RIGHT, 26 | 27 | /** 28 | * A possible value for paragraph alignment. This 29 | * specifies that extra whitespace should be spread 30 | * out through the rows of the paragraph with the 31 | * text lined up with the left and right indent 32 | * except on the last line which should be aligned 33 | * to the left. 34 | */ 35 | JUSTIFIED; 36 | } 37 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/frame/dialog/DialogComponentInfo.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.frame.dialog; 2 | 3 | import com.mommoo.util.FontManager; 4 | 5 | import java.awt.*; 6 | 7 | public class DialogComponentInfo { 8 | private static final Font DEFAULT_FONT = FontManager.getNanumGothicFont(Font.PLAIN,12); 9 | private String text = "text"; 10 | private Color textColor = Color.BLACK; 11 | private Color backgroundColor = Color.WHITE; 12 | private Font textFont = DEFAULT_FONT; 13 | 14 | public DialogComponentInfo setText(String text){ 15 | this.text = text; 16 | return this; 17 | } 18 | 19 | public DialogComponentInfo setTextFont(Font textFont){ 20 | this.textFont = textFont; 21 | return this; 22 | } 23 | 24 | public String getText(){ 25 | return text; 26 | } 27 | 28 | public Font getTextFont(){ 29 | return textFont; 30 | } 31 | 32 | public Color getTextColor(){ 33 | return textColor; 34 | } 35 | 36 | public DialogComponentInfo setTextColor(Color color){ 37 | this.textColor = color; 38 | return this; 39 | } 40 | 41 | public DialogComponentInfo setBackgroundColor(Color color){ 42 | this.backgroundColor = color; 43 | return this; 44 | } 45 | 46 | public Color getBackgroundColor(){ 47 | return this.backgroundColor; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/com/mommoo/util/FontManager.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.util; 2 | 3 | import java.awt.*; 4 | import java.awt.font.TextAttribute; 5 | import java.io.File; 6 | import java.io.InputStream; 7 | import java.nio.file.FileSystem; 8 | import java.util.Collections; 9 | 10 | public class FontManager { 11 | private FontManager(){} 12 | 13 | public static Font getDefaultFont(int style, int fontSize){ 14 | return new Font("sansSerif",style,fontSize); 15 | } 16 | 17 | public static Font getNanumGothicFont(int style, int fontSize){ 18 | try { 19 | InputStream is =FontManager.class.getResourceAsStream("/com/mommoo/resource/font/NanumGothic.ttf"); 20 | Font font = Font.createFont(Font.TRUETYPE_FONT, is); 21 | return font.deriveFont(style, fontSize); 22 | } catch (Exception e) { e.printStackTrace(); } 23 | 24 | return getDefaultFont(style, fontSize); 25 | } 26 | 27 | public static Font getNanumGothicBoldFont(int fontSize){ 28 | try { 29 | InputStream is =FontManager.class.getResourceAsStream("/com/mommoo/resource/font/NanumGothicBold.ttf"); 30 | Font font = Font.createFont(Font.TRUETYPE_FONT, is); 31 | return font.deriveFont(Font.BOLD, fontSize); 32 | } catch (Exception e) { e.printStackTrace(); } 33 | 34 | return getDefaultFont(Font.BOLD, fontSize); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/frame/colorpicker/HSB.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.frame.colorpicker; 2 | 3 | import com.mommoo.flat.utils.FlatColor; 4 | 5 | import java.awt.*; 6 | 7 | public class HSB { 8 | private final int hue; 9 | private final int saturation; 10 | private final int brightness; 11 | 12 | public HSB(int hue, int saturation, int brightness){ 13 | this.hue = hue; 14 | this.saturation = saturation; 15 | this.brightness = brightness; 16 | } 17 | 18 | public HSB(Color color){ 19 | float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null); 20 | this.hue = (int)(hsb[0] * 360f); 21 | this.saturation = (int)(hsb[1] * 100f); 22 | this.brightness = (int)(hsb[2] * 100f); 23 | } 24 | 25 | public int getHue() { 26 | return hue; 27 | } 28 | 29 | public int getSaturation() { 30 | return saturation; 31 | } 32 | 33 | public int getBrightness() { 34 | return brightness; 35 | } 36 | 37 | public HSB changeHue(int hue){ 38 | return new HSB(hue, getSaturation(), getBrightness()); 39 | } 40 | 41 | public Color getColor(){ 42 | return FlatColor.convertHSBtoRGB(getHue(), getSaturation(), getBrightness()); 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return getHue()+"/"+getSaturation()+"/"+getBrightness(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/text/textfield/NormalTextField.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.text.textfield; 2 | 3 | import javax.swing.*; 4 | import java.awt.*; 5 | 6 | /** 7 | * Created by mommoo on 2017-07-14. 8 | */ 9 | public class NormalTextField extends TextFieldProxy { 10 | 11 | NormalTextField() { 12 | bind(new JTextField(){ 13 | private boolean once; 14 | 15 | @Override 16 | public void paint(Graphics g) { 17 | if (!once){ 18 | once = true; 19 | setProperForegroundColor(); 20 | } 21 | super.paint(g); 22 | } 23 | 24 | private void setProperForegroundColor() { 25 | if (isHintFirst) { 26 | setForeground(hintForeground); 27 | } else { 28 | setForeground(originalForegroundColor); 29 | } 30 | } 31 | }); 32 | } 33 | 34 | @Override 35 | void setNormalText(String text) { 36 | getTextField().setText(text); 37 | getTextField().setForeground(this.originalForegroundColor == null ? getTextField().getForeground() : this.originalForegroundColor); 38 | } 39 | 40 | @Override 41 | void setHintText() { 42 | getTextField().setText(getHint()); 43 | this.originalForegroundColor = getTextField().getForeground(); 44 | getTextField().setForeground(hintForeground); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FlatSwing 2 | A beautiful Java Swing-Library made of flat design 3 | 4 | # ScreenShot 5 | 6 |
7 | 8 |
9 | 10 | # Example Project 11 | [![scheduler](https://img.youtube.com/vi/TxoaR8zoADw/0.jpg)](https://www.youtube.com/watch?v=TxoaR8zoADw) 12 | 13 | # License 14 | 15 | MIT License 16 | 17 | Copyright (c) 2018 Mommoo 18 | 19 | Permission is hereby granted, free of charge, to any person obtaining a copy 20 | of this software and associated documentation files (the "Software"), to deal 21 | in the Software without restriction, including without limitation the rights 22 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 23 | copies of the Software, and to permit persons to whom the Software is 24 | furnished to do so, subject to the following conditions: 25 | 26 | The above copyright notice and this permission notice shall be included in all 27 | copies or substantial portions of the Software. 28 | 29 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 30 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 31 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 32 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 33 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 34 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 35 | SOFTWARE. 36 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/layout/linear/constraints/LinearConstraints.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.layout.linear.constraints; 2 | 3 | public class LinearConstraints implements Cloneable{ 4 | private int weight = 0; 5 | private LinearSpace linearSpace = LinearSpace.WRAP_CONTENT; 6 | 7 | public LinearConstraints(){ } 8 | 9 | public LinearConstraints(int weight){ 10 | this.weight = weight; 11 | } 12 | 13 | public LinearConstraints(LinearSpace linearSpace){ 14 | this.linearSpace = linearSpace; 15 | } 16 | 17 | public LinearConstraints(int weight, LinearSpace linearSpace){ 18 | this.weight = weight; 19 | this.linearSpace = linearSpace; 20 | } 21 | 22 | public LinearConstraints setWeight(int weight){ 23 | this.weight = weight; 24 | return this; 25 | } 26 | 27 | public int getWeight(){ 28 | return weight; 29 | } 30 | 31 | public LinearConstraints setLinearSpace(LinearSpace linearSpace){ 32 | this.linearSpace = linearSpace; 33 | return this; 34 | } 35 | 36 | public LinearSpace getLinearSpace(){ 37 | return linearSpace; 38 | } 39 | 40 | @Override 41 | public LinearConstraints clone() { 42 | try { 43 | return (LinearConstraints)super.clone(); 44 | } catch (CloneNotSupportedException e) { 45 | e.printStackTrace(); 46 | return this; 47 | } 48 | } 49 | 50 | @Override 51 | public String toString() { 52 | return "[weight] : " + weight+"\n" + 53 | "[LinearSpace] : " + linearSpace; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/list/CompIndexList.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.list; 2 | 3 | import java.awt.*; 4 | import java.util.*; 5 | import java.util.List; 6 | 7 | class CompIndexList{ 8 | private ArrayList compList = new ArrayList<>(); 9 | private Map indexMapper = new HashMap<>(); 10 | 11 | private void pushOneByOne(int index){ 12 | for (int i = index ,size = getSize(); i < size; i++){ 13 | indexMapper.put(compList.get(i), i); 14 | } 15 | } 16 | 17 | void addComp(T comp){ 18 | compList.add(comp); 19 | indexMapper.put(comp, getSize() - 1); 20 | } 21 | 22 | void addComp(T comp, int index){ 23 | compList.add(index, comp); 24 | indexMapper.put(comp,getSize()-1); 25 | pushOneByOne(index); 26 | } 27 | 28 | void addAllComp(List compList){ 29 | compList.forEach(this::addComp); 30 | } 31 | 32 | void removeComp(int index){ 33 | indexMapper.remove(compList.get(index)); 34 | compList.remove(index); 35 | pushOneByOne(index); 36 | } 37 | 38 | void removeAll(){ 39 | for (T component : compList){ 40 | indexMapper.remove(component); 41 | } 42 | 43 | compList.clear(); 44 | } 45 | 46 | int getIndex(T comp){ 47 | return indexMapper.get(comp); 48 | } 49 | 50 | T peek(int index){ 51 | return compList.get(index); 52 | } 53 | 54 | int getSize(){ 55 | return compList.size(); 56 | } 57 | 58 | List getList(){ 59 | return Collections.unmodifiableList(compList); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/select/HoverColorChangeListener.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.select; 2 | 3 | import com.mommoo.flat.utils.FlatColor; 4 | 5 | import java.awt.*; 6 | import java.awt.event.MouseAdapter; 7 | import java.awt.event.MouseEvent; 8 | 9 | public class HoverColorChangeListener extends MouseAdapter { 10 | private static final Cursor HAND_CURSOR = new Cursor(Cursor.HAND_CURSOR); 11 | private static final Cursor DEFAULT_CURSOR = new Cursor(Cursor.DEFAULT_CURSOR); 12 | private Color originalBackgroundColor; 13 | private Color focusGainColor; 14 | private Color pressedColor; 15 | 16 | private void initColor(Component component){ 17 | originalBackgroundColor = component.getBackground(); 18 | focusGainColor = FlatColor.darker(originalBackgroundColor, 0.9); 19 | pressedColor = FlatColor.darker(focusGainColor, 0.9); 20 | } 21 | 22 | @Override 23 | public void mousePressed(MouseEvent e) { 24 | super.mousePressed(e); 25 | e.getComponent().setBackground(pressedColor); 26 | } 27 | 28 | @Override 29 | public void mouseEntered(MouseEvent e) { 30 | super.mouseEntered(e); 31 | if (originalBackgroundColor == null) { 32 | initColor(e.getComponent()); 33 | } 34 | e.getComponent().setBackground(focusGainColor); 35 | e.getComponent().setCursor(HAND_CURSOR); 36 | } 37 | 38 | @Override 39 | public void mouseExited(MouseEvent e) { 40 | super.mouseExited(e); 41 | e.getComponent().setBackground(originalBackgroundColor); 42 | e.getComponent().setCursor(DEFAULT_CURSOR); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/frame/dialog/DialogButtonInfo.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.frame.dialog; 2 | 3 | import com.mommoo.flat.component.OnClickListener; 4 | 5 | import java.awt.*; 6 | 7 | public class DialogButtonInfo extends DialogComponentInfo{ 8 | private OnClickListener onClickListener = component -> {}; 9 | private boolean isExit, isEndAnimation; 10 | 11 | public OnClickListener getOnClickListener() { 12 | return onClickListener; 13 | } 14 | 15 | @Override 16 | public DialogButtonInfo setText(String text) { 17 | super.setText(text); 18 | return this; 19 | } 20 | 21 | @Override 22 | public DialogButtonInfo setTextFont(Font textFont) { 23 | super.setTextFont(textFont); 24 | return this; 25 | } 26 | 27 | @Override 28 | public DialogButtonInfo setTextColor(Color color) { 29 | super.setTextColor(color); 30 | return this; 31 | } 32 | 33 | @Override 34 | public DialogButtonInfo setBackgroundColor(Color color) { 35 | super.setBackgroundColor(color); 36 | return this; 37 | } 38 | 39 | public DialogButtonInfo setOnClickListener(OnClickListener onClickListener){ 40 | if (onClickListener == null) return this; 41 | this.onClickListener = onClickListener; 42 | return this; 43 | } 44 | 45 | public DialogButtonInfo setExitOption(boolean isExit, boolean isEndAnimation){ 46 | this.isExit = isExit; 47 | this.isEndAnimation = this.isExit && isEndAnimation; 48 | return this; 49 | } 50 | 51 | public boolean isExit(){ 52 | return isExit; 53 | } 54 | 55 | public boolean isEndAnimation(){ 56 | return isEndAnimation; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/com/mommoo/util/ScreenManager.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.util; 2 | 3 | import java.awt.*; 4 | 5 | public class ScreenManager { 6 | private int screenWidth; 7 | private int screenHeight; 8 | private int windowWidth; 9 | private int windowHeight; 10 | 11 | private static final ScreenManager INSTANCE = new ScreenManager(); 12 | 13 | private ScreenManager(){ 14 | readyToGetAccurateResolution(); 15 | initScreenSize(); 16 | initWindowSize(); 17 | } 18 | 19 | /* To synchronize screen resolution */ 20 | private static void readyToGetAccurateResolution(){ 21 | /* At several graphics environments , sometimes JFrame graphics shutdown because of transparent background color 22 | * This vm options prevent shutdown graphics */ 23 | System.setProperty("sun.java2d.opengl","true"); 24 | Toolkit.getDefaultToolkit().getScreenResolution(); 25 | } 26 | 27 | private void initScreenSize(){ 28 | Dimension res = Toolkit.getDefaultToolkit().getScreenSize(); 29 | screenWidth = res.width; 30 | screenHeight = res.height; 31 | } 32 | 33 | private void initWindowSize(){ 34 | Rectangle winSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds(); 35 | windowWidth = winSize.width; 36 | windowHeight = winSize.height; 37 | } 38 | 39 | public static ScreenManager getInstance(){ 40 | return INSTANCE; 41 | } 42 | 43 | public int getScreenWidth(){ 44 | return screenWidth; 45 | } 46 | 47 | public int getScreenHeight(){ 48 | return screenHeight; 49 | } 50 | 51 | public int getWindowWidth(){ 52 | return windowWidth; 53 | } 54 | 55 | public int getWindowHeight(){ 56 | return windowHeight; 57 | } 58 | 59 | public int dip2px(int px){ 60 | return px*screenWidth/1000; 61 | } 62 | 63 | public int px2dip(int dip){ 64 | return dip/screenWidth/1000; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/text/textarea/FlatCaret.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.text.textarea; 2 | 3 | import javax.swing.*; 4 | import javax.swing.text.DefaultCaret; 5 | import javax.swing.text.JTextComponent; 6 | import javax.swing.text.Position; 7 | import java.awt.*; 8 | import java.awt.event.MouseEvent; 9 | 10 | class FlatCaret extends DefaultCaret{ 11 | private static final int BLINK_RATE = 500; 12 | 13 | private Component cacheComp; 14 | private FontMetrics cacheMetrics; 15 | 16 | private int cursorWidth = 2; 17 | 18 | FlatCaret(){ 19 | setBlinkRate(BLINK_RATE); 20 | setUpdatePolicy(ALWAYS_UPDATE); 21 | } 22 | 23 | int getCursorWidth(){ 24 | return cursorWidth; 25 | } 26 | 27 | void setCursorWidth(int cursorWidth){ 28 | this.cursorWidth = cursorWidth; 29 | } 30 | 31 | @Override 32 | public void paint(Graphics g) { 33 | Graphics2D graphics2D = (Graphics2D)g; 34 | graphics2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.0f)); 35 | super.paint(g); 36 | graphics2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f)); 37 | 38 | JTextComponent comp = getComponent(); 39 | 40 | if (comp == null || !isVisible()) return; 41 | 42 | if (cacheComp != comp){ 43 | cacheComp = comp; 44 | cacheMetrics = cacheComp.getFontMetrics(cacheComp.getFont()); 45 | } 46 | 47 | Rectangle r = null; 48 | try { 49 | r = comp.modelToView(getDot()); 50 | } catch (Exception e) { 51 | return; 52 | } 53 | // set cursorHeight; 54 | r.height = cacheMetrics.getHeight(); 55 | g.setColor(comp.getCaretColor()); 56 | g.fillRect(r.x , r.y, cursorWidth, r.height); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/text/textfield/PasswordTextField.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.text.textfield; 2 | 3 | import javax.swing.*; 4 | import java.awt.*; 5 | 6 | /** 7 | * Created by mommoo on 2017-07-14. 8 | */ 9 | public class PasswordTextField extends TextFieldProxy { 10 | private final JPasswordField passwordField; 11 | private final char PASS_WORD_ECHO_CHAR; 12 | 13 | PasswordTextField() { 14 | bind(new JPasswordField(){ 15 | private boolean once; 16 | 17 | @Override 18 | public void paint(Graphics g) { 19 | if (!once){ 20 | once = true; 21 | setProperForegroundColor(); 22 | } 23 | super.paint(g); 24 | } 25 | 26 | private void setProperForegroundColor(){ 27 | if (isHintFirst){ 28 | setForeground(hintForeground); 29 | } else { 30 | setForeground(originalForegroundColor); 31 | } 32 | } 33 | }); 34 | this.passwordField = (JPasswordField)getTextField(); 35 | this.PASS_WORD_ECHO_CHAR = this.passwordField.getEchoChar(); 36 | } 37 | 38 | @Override 39 | void setNormalText(String text) { 40 | passwordField.setForeground(this.originalForegroundColor == null ? passwordField.getForeground() : this.originalForegroundColor); 41 | passwordField.setEchoChar(PASS_WORD_ECHO_CHAR); 42 | this.passwordField.setText(text); 43 | } 44 | 45 | @Override 46 | void setHintText() { 47 | this.originalForegroundColor = passwordField.getForeground(); 48 | passwordField.setForeground(hintForeground); 49 | passwordField.setEchoChar((char)0); 50 | this.passwordField.setText(getHint()); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/component/seekbar/FlatSeekBarHandle.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.component.seekbar; 2 | 3 | import com.mommoo.util.ColorManager; 4 | 5 | import java.awt.*; 6 | import java.awt.geom.Ellipse2D; 7 | 8 | class FlatSeekBarHandle extends Component { 9 | private Ellipse2D.Double HANDLE_SHAPE = new Ellipse2D.Double(); 10 | private Color seekBarHandleColor = ColorManager.getColorAccent(); 11 | private boolean isGrab; 12 | 13 | @Override 14 | public void paint(Graphics g) { 15 | double w = getWidth(); 16 | double h = getHeight(); 17 | 18 | Graphics2D graphics2D = (Graphics2D)g; 19 | 20 | if (isGrab){ 21 | drawOuterShape(graphics2D, 0, 0, w); 22 | } 23 | 24 | drawInnerShape(graphics2D, w/4d, h/4d, w/2d); 25 | } 26 | 27 | private void drawOuterShape(Graphics2D graphics2D, double x, double y, double size){ 28 | graphics2D.setColor(getSeekBarHandleAlphaColor()); 29 | HANDLE_SHAPE.setFrame(x, y, size, size); 30 | graphics2D.fill(HANDLE_SHAPE); 31 | } 32 | 33 | private void drawInnerShape(Graphics2D graphics2D, double x, double y, double size){ 34 | graphics2D.setColor(seekBarHandleColor); 35 | HANDLE_SHAPE.setFrame(x, y, size, size); 36 | graphics2D.fill(HANDLE_SHAPE); 37 | } 38 | 39 | private Color getSeekBarHandleAlphaColor(){ 40 | Color lighterColor = seekBarHandleColor.brighter(); 41 | int r = lighterColor.getRed(); 42 | int g = lighterColor.getGreen(); 43 | int b = lighterColor.getBlue(); 44 | return new Color(r,g,b,160); 45 | } 46 | 47 | void setSeekBarHandleColor(Color seekBarHandleColor){ 48 | this.seekBarHandleColor = seekBarHandleColor; 49 | } 50 | 51 | void grab(){ 52 | isGrab = true; 53 | } 54 | 55 | void unGrab(){ 56 | isGrab = false; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/com/mommoo/util/ImageManager.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.util; 2 | 3 | import java.awt.*; 4 | 5 | /** 6 | * Created by mommoo on 2017-07-14. 7 | */ 8 | public class ImageManager { 9 | public static final Image TEST = Toolkit.getDefaultToolkit().getImage(ImageManager.class.getResource("/com/mommoo/resource/img/test.png")); 10 | public static final Image WRITE = Toolkit.getDefaultToolkit().getImage(ImageManager.class.getResource("/com/mommoo/resource/img/write.png")); 11 | public static final Image CHECK = Toolkit.getDefaultToolkit().getImage(ImageManager.class.getResource("/com/mommoo/resource/img/check.png")); 12 | public static final Image PANDA = Toolkit.getDefaultToolkit().getImage(ImageManager.class.getResource("/com/mommoo/resource/img/panda.png")); 13 | public static final Image GIRIN = Toolkit.getDefaultToolkit().getImage(ImageManager.class.getResource("/com/mommoo/resource/img/girin.png")); 14 | public static final Image LION = Toolkit.getDefaultToolkit().getImage(ImageManager.class.getResource("/com/mommoo/resource/img/lion.png")); 15 | public static final Image TIGER = Toolkit.getDefaultToolkit().getImage(ImageManager.class.getResource("/com/mommoo/resource/img/tiger.png")); 16 | public static final Image DOG = Toolkit.getDefaultToolkit().getImage(ImageManager.class.getResource("/com/mommoo/resource/img/dog.png")); 17 | public static final Image FROG = Toolkit.getDefaultToolkit().getImage(ImageManager.class.getResource("/com/mommoo/resource/img/frog.png")); 18 | public static final Image SHEEP = Toolkit.getDefaultToolkit().getImage(ImageManager.class.getResource("/com/mommoo/resource/img/sheep.png")); 19 | public static final Image CAT = Toolkit.getDefaultToolkit().getImage(ImageManager.class.getResource("/com/mommoo/resource/img/cat.png")); 20 | public static final Image PIG = Toolkit.getDefaultToolkit().getImage(ImageManager.class.getResource("/com/mommoo/resource/img/pig.png")); 21 | public static final Image BIG_IMAGE = Toolkit.getDefaultToolkit().getImage(ImageManager.class.getResource("/com/mommoo/resource/img/big_image.jpg")); 22 | } 23 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/button/ripple/RippleEffect.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.button.ripple; 2 | 3 | import java.awt.*; 4 | 5 | public class RippleEffect implements RippleModel { 6 | private int rippleHoldDuration = 250; 7 | private int rippleDuration = 400; 8 | private float rippleColorOpacity = 0.5f; 9 | private Color rippleColor = new Color(241, 241, 240); 10 | private boolean onEventLaterEffect = true; 11 | private boolean rippleDrawOverBorder = true; 12 | 13 | @Override 14 | public int getRippleHoldDuration() { 15 | return rippleHoldDuration; 16 | } 17 | 18 | public RippleEffect setRippleHoldDuration(int rippleHoldDuration) { 19 | this.rippleHoldDuration = rippleHoldDuration; 20 | return this; 21 | } 22 | 23 | @Override 24 | public int getRippleDuration() { 25 | return rippleDuration; 26 | } 27 | 28 | public RippleEffect setRippleDuration(int rippleDuration) { 29 | this.rippleDuration = rippleDuration; 30 | return this; 31 | } 32 | 33 | public float getRippleColorOpacity() { 34 | return rippleColorOpacity; 35 | } 36 | 37 | public RippleEffect setRippleColorOpacity(float rippleColorOpacity) { 38 | this.rippleColorOpacity = rippleColorOpacity; 39 | return this; 40 | } 41 | 42 | public Color getRippleColor() { 43 | return rippleColor; 44 | } 45 | 46 | public RippleEffect setRippleColor(Color rippleColor) { 47 | this.rippleColor = rippleColor; 48 | return this; 49 | } 50 | 51 | @Override 52 | public boolean isOnEventLaterEffect() { 53 | return onEventLaterEffect; 54 | } 55 | 56 | public RippleEffect setOnEventLaterEffect(boolean onEventLaterEffect) { 57 | this.onEventLaterEffect = onEventLaterEffect; 58 | return this; 59 | } 60 | 61 | public boolean isRippleDrawOverBorder() { 62 | return rippleDrawOverBorder; 63 | } 64 | 65 | public RippleEffect setRippleDrawOverBorder(boolean rippleDrawOverBorder) { 66 | this.rippleDrawOverBorder = rippleDrawOverBorder; 67 | return this; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/component/FlatMouseAdapter.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.component; 2 | 3 | import java.awt.event.MouseAdapter; 4 | import java.awt.event.MouseEvent; 5 | import java.awt.event.MouseWheelEvent; 6 | 7 | public class FlatMouseAdapter extends MouseAdapter{ 8 | private boolean isMouseClicked; 9 | private boolean isMousePressed; 10 | private boolean isMouseEntered; 11 | private boolean isMouseDragging; 12 | private boolean isMouseMoved; 13 | private MouseEvent mouseEvent; 14 | 15 | @Override 16 | public void mouseClicked(MouseEvent e) { 17 | this.mouseEvent = e; 18 | } 19 | 20 | @Override 21 | public void mousePressed(MouseEvent e) { 22 | this.mouseEvent = e; 23 | isMouseClicked = false; 24 | isMousePressed = true; 25 | } 26 | 27 | @Override 28 | public void mouseReleased(MouseEvent e) { 29 | this.mouseEvent = e; 30 | isMouseClicked = isMousePressed && isMouseEntered && e.getComponent().isEnabled(); 31 | isMousePressed = false; 32 | } 33 | 34 | @Override 35 | public void mouseEntered(MouseEvent e) { 36 | this.mouseEvent = e; 37 | isMouseEntered = true; 38 | } 39 | 40 | @Override 41 | public void mouseExited(MouseEvent e) { 42 | this.mouseEvent = e; 43 | isMouseEntered = false; 44 | } 45 | 46 | @Override 47 | public void mouseWheelMoved(MouseWheelEvent e) { 48 | this.mouseEvent = e; 49 | } 50 | 51 | @Override 52 | public void mouseDragged(MouseEvent e) { 53 | this.mouseEvent = e; 54 | isMouseDragging = true; 55 | isMouseMoved = false; 56 | } 57 | 58 | @Override 59 | public void mouseMoved(MouseEvent e) { 60 | this.mouseEvent = e; 61 | isMouseDragging = false; 62 | isMouseMoved = true; 63 | } 64 | 65 | protected final boolean isMouseClicked() { 66 | return isMouseClicked; 67 | } 68 | 69 | protected final boolean isMouseEntered() { 70 | return isMouseEntered; 71 | } 72 | 73 | protected final boolean isMouseMoved() { 74 | return isMouseMoved; 75 | } 76 | 77 | protected final boolean isMousePressed() { 78 | return isMousePressed; 79 | } 80 | 81 | protected final boolean isMouseDragging() { 82 | return isMouseDragging; 83 | } 84 | 85 | protected final MouseEvent getMouseEvent() { 86 | return mouseEvent; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/frame/colorpicker/ColorConfirmView.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.frame.colorpicker; 2 | 3 | import com.mommoo.flat.button.FlatButton; 4 | import com.mommoo.flat.component.FlatPanel; 5 | import com.mommoo.flat.layout.linear.Alignment; 6 | import com.mommoo.flat.layout.linear.LinearLayout; 7 | import com.mommoo.flat.layout.linear.constraints.LinearConstraints; 8 | import com.mommoo.flat.layout.linear.constraints.LinearSpace; 9 | import com.mommoo.util.FontManager; 10 | import com.mommoo.util.ScreenManager; 11 | 12 | import java.awt.*; 13 | 14 | class ColorConfirmView extends FlatPanel { 15 | private static final ScreenManager SCREEN = ScreenManager.getInstance(); 16 | private static final Font BUTTON_FONT = FontManager.getNanumGothicBoldFont(SCREEN.dip2px(8)); 17 | 18 | private Runnable onConfirmListener = () -> {}; 19 | private Runnable onCancelListener = () -> {}; 20 | 21 | ColorConfirmView(){ 22 | setLayout(new LinearLayout(SCREEN.dip2px(6), Alignment.CENTER)); 23 | add(createConfirmButton(), new LinearConstraints(1, LinearSpace.MATCH_PARENT),"confirmButton"); 24 | add(createCancelButton() , new LinearConstraints(1, LinearSpace.MATCH_PARENT),"cancelButton"); 25 | } 26 | 27 | ColorConfirmView setOnConfirmListener(Runnable onConfirmListener){ 28 | this.onConfirmListener = onConfirmListener; 29 | return this; 30 | } 31 | 32 | ColorConfirmView setOnCancelListener(Runnable onCancelListener){ 33 | this.onCancelListener = onCancelListener; 34 | return this; 35 | } 36 | 37 | void setUiColor(Color uiColor){ 38 | getComponent(0).setBackground(uiColor); 39 | getComponent(1).setBackground(uiColor); 40 | } 41 | 42 | private FlatButton createCommonButton(String buttonText){ 43 | FlatButton commonButton = new FlatButton(buttonText.toUpperCase()); 44 | commonButton.setFont(BUTTON_FONT); 45 | commonButton.setPreferredSize(new Dimension(SCREEN.dip2px(50), SCREEN.dip2px(30))); 46 | return commonButton; 47 | } 48 | 49 | private Component createConfirmButton(){ 50 | FlatButton confirmButton = createCommonButton("confirm"); 51 | confirmButton.setOnClickListener(comp -> onConfirmListener.run()); 52 | return confirmButton; 53 | } 54 | 55 | private Component createCancelButton(){ 56 | FlatButton cancelButton = createCommonButton("cancel"); 57 | cancelButton.setOnClickListener(comp -> onCancelListener.run()); 58 | return cancelButton; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/frame/titlebar/navigation/button/NavigationButton.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.frame.titlebar.navigation.button; 2 | 3 | import com.mommoo.flat.component.FlatPanel; 4 | import com.mommoo.flat.component.OnClickListener; 5 | 6 | import javax.swing.*; 7 | import java.awt.*; 8 | 9 | public abstract class NavigationButton extends FlatPanel implements ViewModel { 10 | private static final long serialVersionUID = 1L; 11 | private static final BasicStroke BASIC_STROKE = new BasicStroke(2.0f); 12 | private static final Cursor HAND_CURSOR = new Cursor(Cursor.HAND_CURSOR); 13 | 14 | private Color buttonIconColor = Color.BLACK; 15 | 16 | private NavigationButtonModel buttonModel = new NavigationButtonModel(this); 17 | 18 | private boolean block; 19 | 20 | NavigationButton() { 21 | setCursor(HAND_CURSOR); 22 | addMouseListener(buttonModel.getHoverAnimListener()); 23 | } 24 | 25 | @Override 26 | protected void postDraw(Graphics2D graphics2D, int availableWidth, int availableHeight) { 27 | if (!block) buttonModel.paint(graphics2D); 28 | graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 29 | graphics2D.setColor(buttonIconColor); 30 | graphics2D.setStroke(BASIC_STROKE); 31 | final int STANDARD_RECT_SIZE = 7 * availableHeight / 20; 32 | paintShape(STANDARD_RECT_SIZE, graphics2D); 33 | } 34 | 35 | @Override 36 | public void setOnClickListener(OnClickListener onClickListener) { 37 | super.setOnClickListener(component -> { 38 | block = true; 39 | repaint(); 40 | onClickListener.onClick(component); 41 | SwingUtilities.invokeLater(()-> block = false); 42 | }); 43 | } 44 | 45 | public Color getButtonIconColor() { 46 | return this.buttonIconColor; 47 | } 48 | 49 | public void setButtonIconColor(Color color) { 50 | this.buttonIconColor = color; 51 | repaint(); 52 | } 53 | 54 | public void setHoverColor(Color hoverColor) { 55 | this.buttonModel.setHoverColor(hoverColor); 56 | } 57 | 58 | public void setHoverInListener(Runnable hoverInListener) { 59 | this.buttonModel.setHoverInListener(hoverInListener); 60 | } 61 | 62 | public void setHoverOutListener(Runnable hoverOutListener) { 63 | this.buttonModel.setHoverOutListener(hoverOutListener); 64 | } 65 | 66 | protected abstract void paintShape(final int STANDARD_RECT_SIZE, final Graphics2D GRAPHICS_2D); 67 | } 68 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/component/pager/FlatTabIndicator.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.component.pager; 2 | 3 | import com.mommoo.animation.AnimationAdapter; 4 | import com.mommoo.util.ScreenManager; 5 | 6 | import javax.swing.*; 7 | import java.awt.*; 8 | import java.util.List; 9 | 10 | class FlatTabIndicator extends JPanel { 11 | private static final ScreenManager SCREEN = ScreenManager.getInstance(); 12 | private final Rectangle BOUNDS = new Rectangle(); 13 | private IndicatorAnimator ANIMATOR = new IndicatorAnimator(); 14 | private Color indicatorColor = FlatPageColor.getDefaultFlatPagerColor().getFocusInColor(); 15 | 16 | FlatTabIndicator(){ 17 | setOpaque(false); 18 | setPreferredSize(new Dimension(SCREEN.dip2px(1), SCREEN.dip2px(3))); 19 | } 20 | 21 | void setFlatPageColor(FlatPageColor flatPageColor){ 22 | indicatorColor = flatPageColor.getFocusInColor(); 23 | repaint(); 24 | } 25 | 26 | @Override 27 | public void paint(Graphics g) { 28 | super.paint(g); 29 | Graphics2D graphics2D = (Graphics2D)g; 30 | graphics2D.setColor(indicatorColor); 31 | graphics2D.fill(BOUNDS); 32 | } 33 | 34 | void setOffsetBounds(Rectangle bounds){ 35 | BOUNDS.setBounds(bounds); 36 | repaint(); 37 | } 38 | 39 | void indicate(Rectangle bounds, boolean isAnimation){ 40 | if (isAnimation){ 41 | ANIMATOR 42 | .stop() 43 | .start(bounds.x - BOUNDS.x, bounds.width - BOUNDS.width); 44 | } else{ 45 | BOUNDS.setBounds(bounds); 46 | repaint(); 47 | } 48 | 49 | } 50 | 51 | FlatAnimator getAnimator(){ 52 | return ANIMATOR; 53 | } 54 | 55 | private class IndicatorAnimator extends FlatAnimator { 56 | private IndicatorAnimator(){ 57 | setAnimationListener(new AnimationAdapter(){ 58 | private final Rectangle previousBounds = new Rectangle(); 59 | 60 | @Override 61 | public void onStart() { 62 | previousBounds.setBounds(BOUNDS); 63 | } 64 | 65 | @Override 66 | public void onAnimation(List resultList) { 67 | int x = resultList.get(0).intValue(); 68 | int w = resultList.get(1).intValue(); 69 | BOUNDS.x = previousBounds.x + x; 70 | BOUNDS.width = previousBounds.width + w; 71 | repaint(); 72 | } 73 | }); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/text/label/FlatLabel.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.text.label; 2 | 3 | import com.mommoo.flat.frame.FlatFrame; 4 | import com.mommoo.flat.layout.linear.LinearLayout; 5 | import com.mommoo.flat.layout.linear.Orientation; 6 | import com.mommoo.flat.text.textarea.FlatTextArea; 7 | import com.mommoo.flat.text.textarea.alignment.FlatHorizontalAlignment; 8 | import com.mommoo.flat.text.textarea.alignment.FlatVerticalAlignment; 9 | import com.mommoo.util.FontManager; 10 | 11 | import javax.swing.text.StyledDocument; 12 | import java.awt.*; 13 | 14 | /** 15 | * FlatLabel is very convenient component. 16 | * If text length over the label width, line jump automatically 17 | */ 18 | 19 | public class FlatLabel extends FlatTextArea { 20 | 21 | public FlatLabel(){ 22 | init(); 23 | } 24 | 25 | public FlatLabel(String text){ 26 | init(); 27 | setText(text); 28 | } 29 | 30 | public FlatLabel(StyledDocument doc) { 31 | super(doc); 32 | init(); 33 | } 34 | 35 | public static void main(String[] args){ 36 | FlatFrame flatFrame = new FlatFrame(); 37 | flatFrame.setWindowExit(true); 38 | flatFrame.setTitle("FlatLabel Test"); 39 | flatFrame.setLocationOnScreenCenter(); 40 | 41 | // FlatLabel flatLabel = new FlatLabel("A Beautiful Label!!\n This is automatically line jump if string width longer than label width. You just use it well!"); 42 | FlatLabel flatLabel = new FlatLabel("Test"); 43 | flatLabel.setHorizontalAlignment(FlatHorizontalAlignment.CENTER); 44 | flatLabel.setVerticalAlignment(FlatVerticalAlignment.CENTER); 45 | flatLabel.setFont(FontManager.getNanumGothicFont(Font.BOLD, 50)); 46 | flatLabel.setOnClickListener(component -> System.out.println(((FlatLabel) component).getText())); 47 | // flatLabel.setLineSpacing(0.7f); 48 | flatLabel.setPreferredSize(new Dimension(200,200)); 49 | flatFrame.setSize(500, 700); 50 | flatFrame.getContainer().setLayout(new LinearLayout(Orientation.HORIZONTAL)); 51 | flatFrame.getContainer().add(flatLabel);//, new LinearConstraints().setWeight(1).setLinearSpace(LinearSpace.MATCH_PARENT)); 52 | 53 | flatLabel.setOpaque(true); 54 | flatLabel.setBackground(Color.RED); 55 | flatFrame.show(); 56 | flatLabel.select(0,2); 57 | flatLabel.replaceSelection("가나다라"); 58 | } 59 | 60 | private void init(){ 61 | setEnableSelection(false); 62 | } 63 | 64 | @Override 65 | public boolean isEditable() { 66 | return false; 67 | } 68 | 69 | public boolean isEnableSelection(){ 70 | return isFocusable(); 71 | } 72 | 73 | public void setEnableSelection(boolean enableSelection){ 74 | setFocusable(enableSelection); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/component/PaddingWrapPanel.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.component; 2 | 3 | import com.mommoo.util.ScreenManager; 4 | 5 | import javax.swing.*; 6 | import javax.swing.border.Border; 7 | import javax.swing.border.EmptyBorder; 8 | import java.awt.*; 9 | 10 | public class PaddingWrapPanel extends JPanel { 11 | private static final int DEFAULT_PADDING = ScreenManager.getInstance().dip2px(6); 12 | public PaddingWrapPanel(){ 13 | this(DEFAULT_PADDING); 14 | } 15 | 16 | public PaddingWrapPanel(int padding){ 17 | this(padding, padding, padding, padding); 18 | } 19 | 20 | public PaddingWrapPanel(int topBottom, int leftRight){ 21 | this(topBottom, leftRight, topBottom, leftRight); 22 | } 23 | 24 | public PaddingWrapPanel(int top, int left, int bottom, int right){ 25 | super(new BorderLayout()); 26 | setOpaque(false); 27 | setPadding(top, left, bottom, right); 28 | } 29 | 30 | @Override 31 | public void setBorder(Border border) { 32 | 33 | } 34 | 35 | @Override 36 | public boolean isOpaque() { 37 | return false; 38 | } 39 | 40 | public void setPadding(int padding){ 41 | setPadding(padding, padding, padding, padding); 42 | } 43 | 44 | public void setPadding(int topBottom, int leftRight){ 45 | setPadding(topBottom, leftRight, topBottom, leftRight); 46 | } 47 | 48 | public void setPadding(int top, int left, int bottom, int right){ 49 | super.setBorder(new EmptyBorder(top, left, bottom, right)); 50 | } 51 | 52 | @Override 53 | public Component add(Component comp) { 54 | return super.add(comp); 55 | } 56 | 57 | @Override 58 | public Component add(String name, Component comp) { 59 | invokeException(); 60 | return super.add(comp); 61 | } 62 | 63 | @Override 64 | public Component add(Component comp, int index) { 65 | invokeException(); 66 | return super.add(comp, index); 67 | } 68 | 69 | @Override 70 | public void add(Component comp, Object constraints) { 71 | invokeException(); 72 | super.add(comp); 73 | } 74 | 75 | @Override 76 | public void add(Component comp, Object constraints, int index) { 77 | invokeException(); 78 | super.add(comp, index); 79 | } 80 | 81 | private void invokeException(){ 82 | try { 83 | throw new IllegalAccessException("this method not supported, try use 'add(Component comp)' method"); 84 | } catch (IllegalAccessException e) { 85 | e.printStackTrace(); 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/text/textfield/TextFieldProxy.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.text.textfield; 2 | 3 | import com.mommoo.flat.text.textfield.format.FlatTextFormat; 4 | import com.mommoo.flat.text.textfield.format.FormattedDocument; 5 | import com.mommoo.util.ColorManager; 6 | 7 | import javax.swing.*; 8 | import java.awt.*; 9 | import java.util.List; 10 | 11 | abstract class TextFieldProxy { 12 | boolean isHintFirst; 13 | Color hintForeground = ColorManager.getFlatComponentDefaultColor(); 14 | Color originalForegroundColor; 15 | private JTextField targetTextField; 16 | private String hint = ""; 17 | 18 | private FormattedDocument formattedDocument = new FormattedDocument(); 19 | 20 | TextFieldProxy(){ } 21 | 22 | void bind(JTextField textField){ 23 | this.targetTextField = decorateTextField(textField); 24 | this.originalForegroundColor = this.targetTextField.getForeground(); 25 | } 26 | 27 | 28 | private JTextField decorateTextField(JTextField textField){ 29 | textField.setBorder(BorderFactory.createEmptyBorder(0, 0,0, 0)); 30 | textField.setOpaque(false); 31 | textField.setDocument(formattedDocument); 32 | return textField; 33 | } 34 | 35 | 36 | boolean isHintAppeared(){ 37 | boolean isEqualsHintText = getHint().equals(getText()); 38 | boolean isEqualsForegroundColor = getHintForeground() == getTextField().getForeground(); 39 | return isEqualsHintText && isEqualsForegroundColor; 40 | } 41 | 42 | void setHint(String hint){ 43 | formattedDocument.setHintStatus(true); 44 | this.hint = hint; 45 | this.isHintFirst = true; 46 | setHintText(); 47 | formattedDocument.setHintStatus(false); 48 | } 49 | 50 | void setText(String text){ 51 | formattedDocument.setHintStatus(false); 52 | this.isHintFirst = false; 53 | setNormalText(text); 54 | } 55 | 56 | void setLimitTextLength(int limitTextLength) { 57 | formattedDocument.setLimitTextLength(limitTextLength); 58 | } 59 | 60 | int getLimitTextLength() { 61 | return formattedDocument.getLimitTextLength(); 62 | } 63 | 64 | void clear(){ 65 | setNormalText(""); 66 | setHint(this.hint); 67 | } 68 | 69 | String getHint(){ 70 | return this.hint; 71 | } 72 | 73 | Color getHintForeground(){ 74 | return this.hintForeground; 75 | } 76 | 77 | void setHintForeground(Color hintColor){ 78 | this.hintForeground = hintColor; 79 | } 80 | 81 | abstract void setHintText(); 82 | 83 | abstract void setNormalText(String text); 84 | 85 | String getText(){ 86 | return this.targetTextField.getText(); 87 | } 88 | 89 | JTextField getTextField(){ 90 | return this.targetTextField; 91 | } 92 | 93 | List getFormatList(){ 94 | return ((FormattedDocument)this.targetTextField.getDocument()).getFormatList(); 95 | } 96 | 97 | void setFormat(FlatTextFormat... formats){ 98 | ((FormattedDocument)this.targetTextField.getDocument()).setFormat(formats); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/list/SelectionRange.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.list; 2 | 3 | import com.mommoo.flat.list.model.SelectionModel; 4 | 5 | class SelectionRange { 6 | private static final int INVALID_INDEX = -1; 7 | private final SelectionModel SELECTION_MODEL; 8 | private int beginIndex = INVALID_INDEX; 9 | private int endIndex = INVALID_INDEX; 10 | 11 | SelectionRange(SelectionModel model){ 12 | SELECTION_MODEL = model; 13 | } 14 | 15 | void saveRange(int index1, int index2){ 16 | this.beginIndex = Math.max(INVALID_INDEX, Math.min(index1, index2)); 17 | this.endIndex = Math.max(INVALID_INDEX, Math.max(index1, index2)); 18 | } 19 | 20 | int getBeginIndex(){ 21 | return this.beginIndex; 22 | } 23 | 24 | int getEndIndex(){ 25 | return this.endIndex; 26 | } 27 | 28 | int[] getRange(){ 29 | return new int[]{this.beginIndex, this.endIndex}; 30 | } 31 | 32 | void setInValidRange(){ 33 | this.beginIndex = this.endIndex = INVALID_INDEX; 34 | } 35 | 36 | boolean isValid(){ 37 | return this.beginIndex != INVALID_INDEX && this.endIndex != INVALID_INDEX; 38 | } 39 | 40 | void inspectValidSelection(int removedIndex){ 41 | switch(whatIndexDirection(removedIndex)){ 42 | case DOWN_WARD : 43 | inspectValidIndex(); 44 | return; 45 | 46 | case BETWEEN : 47 | if (SELECTION_MODEL.isSingleSelectionMode()){ 48 | setInValidRange(); 49 | } else { 50 | this.endIndex--; 51 | inspectValidIndex(); 52 | } 53 | 54 | return; 55 | 56 | case UP_WARD : 57 | this.beginIndex--; 58 | this.endIndex--; 59 | inspectValidIndex(); 60 | 61 | return; 62 | } 63 | 64 | } 65 | 66 | private void inspectValidIndex(){ 67 | if (!isValidIndex()) { 68 | setInValidRange(); 69 | } 70 | } 71 | 72 | private boolean isValidIndex(){ 73 | int itemSize = SELECTION_MODEL.getItemSize(); 74 | boolean isInItemSize = 0 <= beginIndex && beginIndex < itemSize && endIndex < itemSize && 0 <= endIndex; 75 | boolean isValid = beginIndex != INVALID_INDEX && endIndex != INVALID_INDEX && endIndex >= beginIndex; 76 | return isInItemSize && isValid; 77 | } 78 | 79 | private IndexDirection whatIndexDirection(int index){ 80 | if (beginIndex > index && index < endIndex){ 81 | return IndexDirection.UP_WARD; 82 | } 83 | 84 | else if (beginIndex <= index && index <= endIndex){ 85 | return IndexDirection.BETWEEN; 86 | } 87 | 88 | else { 89 | return IndexDirection.DOWN_WARD; 90 | } 91 | } 92 | 93 | @Override 94 | public String toString() { 95 | return "beginIndex : " + beginIndex + " , endIndex : " + endIndex; 96 | } 97 | 98 | private enum IndexDirection{ 99 | UP_WARD, 100 | BETWEEN, 101 | DOWN_WARD 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/text/textfield/format/FormattedDocument.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.text.textfield.format; 2 | 3 | import com.mommoo.flat.text.textfield.FlatTextField; 4 | import com.mommoo.util.StringUtils; 5 | 6 | import javax.swing.text.AttributeSet; 7 | import javax.swing.text.BadLocationException; 8 | import javax.swing.text.PlainDocument; 9 | import java.util.*; 10 | 11 | public class FormattedDocument extends PlainDocument{ 12 | private Set formatSet = new HashSet<>(); 13 | private boolean isHintStatus; 14 | private StringBuilder stringBuilder = new StringBuilder(); 15 | private int limitTextLength = FlatTextField.NONE_LIMIT_TEXT_LENGTH; 16 | 17 | public List getFormatList() { 18 | return new ArrayList<>(formatSet); 19 | } 20 | 21 | public void setFormat(FlatTextFormat... formats){ 22 | formatSet.addAll(Arrays.asList(formats)); 23 | } 24 | 25 | public void setHintStatus(boolean hintStatus){ 26 | this.isHintStatus = hintStatus; 27 | } 28 | 29 | @Override 30 | public void insertString(int offs, String string, AttributeSet a) throws BadLocationException { 31 | if (limitTextLength > FlatTextField.NONE_LIMIT_TEXT_LENGTH && getLength() + string.length() > limitTextLength) { 32 | string = string.substring(0, limitTextLength - getLength()); 33 | } 34 | 35 | if (isHintStatus) { 36 | super.insertString(offs, string, a); 37 | return; 38 | } 39 | 40 | stringBuilder.delete(0, stringBuilder.length()); 41 | 42 | for (char c : string.toCharArray()){ 43 | appendTextFitFormat(c); 44 | } 45 | 46 | super.insertString(offs, stringBuilder.toString(), a); 47 | } 48 | 49 | public void setLimitTextLength(int limitTextLength) { 50 | this.limitTextLength = limitTextLength; 51 | } 52 | 53 | public int getLimitTextLength() { 54 | return this.limitTextLength; 55 | } 56 | 57 | private void appendTextFitFormat(char c){ 58 | if (formatSet.size() == 0){ 59 | stringBuilder.append(c); 60 | return; 61 | } 62 | 63 | for (FlatTextFormat format : formatSet){ 64 | if (format == FlatTextFormat.NUMBER_DECIMAL){ 65 | 66 | if (StringUtils.isNumberChar(c)) { 67 | stringBuilder.append(c); 68 | return ; 69 | } 70 | 71 | } else if (format == FlatTextFormat.TEXT){ 72 | 73 | if (!StringUtils.isNumberChar(c) && !StringUtils.isSpecialChar(c)) { 74 | stringBuilder.append(c); 75 | return ; 76 | } 77 | 78 | } else if (format == FlatTextFormat.SPECIAL_CHARACTER){ 79 | 80 | if (StringUtils.isSpecialChar(c)) { 81 | stringBuilder.append(c); 82 | return ; 83 | } 84 | 85 | } else if (format == FlatTextFormat.HEX_COLOR){ 86 | 87 | if (StringUtils.isHexColorChar(c)){ 88 | stringBuilder.append(c); 89 | return; 90 | } 91 | 92 | } else{ 93 | stringBuilder.append(c); 94 | } 95 | } 96 | 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/com/mommoo/helper/ClassUtils.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.helper; 2 | 3 | import java.lang.reflect.Array; 4 | import java.lang.reflect.GenericArrayType; 5 | import java.lang.reflect.ParameterizedType; 6 | import java.lang.reflect.Type; 7 | 8 | public class ClassUtils { 9 | private static final String TYPE_NAME_PREFIX = "class "; 10 | 11 | public static Class getReclusiveGenericClass(Class clazz, int index) { 12 | Class targetClass = clazz; 13 | while (targetClass != null) { 14 | Class genericClass = getGenericClass(targetClass, index); 15 | if (genericClass != null) { 16 | return genericClass; 17 | } 18 | targetClass = targetClass.getSuperclass(); 19 | } 20 | return null; 21 | } 22 | 23 | public static Class getGenericClass(Class clazz, int index) { 24 | Type types[] = getParameterizedTypes(clazz); 25 | if ((types != null) && (types.length > index)) { 26 | try { 27 | return getClass(types[index]); 28 | } catch (Exception e) { 29 | e.printStackTrace(); 30 | } 31 | } 32 | return null; 33 | } 34 | 35 | static public Type[] getParameterizedTypes(Class target) { 36 | Type[] types = getGenericType(target); 37 | if (types.length > 0 && types[0] instanceof ParameterizedType) { 38 | return ((ParameterizedType) types[0]).getActualTypeArguments(); 39 | } 40 | return null; 41 | } 42 | 43 | static public Class getClass(Type type) throws ClassNotFoundException { 44 | if (type instanceof Class) { 45 | return (Class) type; 46 | } else if (type instanceof ParameterizedType) { 47 | return getClass(((ParameterizedType) type).getRawType()); 48 | } else if (type instanceof GenericArrayType) { 49 | Type componentType = ((GenericArrayType) type).getGenericComponentType(); 50 | Class componentClass = getClass(componentType); 51 | if (componentClass != null) { 52 | return Array.newInstance(componentClass, 0).getClass(); 53 | } 54 | } 55 | String className = getClassName(type); 56 | if (className == null || className.isEmpty()) { 57 | return null; 58 | } 59 | return Class.forName(className); 60 | } 61 | 62 | static public String getClassName(Type type) { 63 | if (type == null) { 64 | return ""; 65 | } 66 | String className = type.toString(); 67 | if (className.startsWith(TYPE_NAME_PREFIX)) { 68 | className = className.substring(TYPE_NAME_PREFIX.length()); 69 | } 70 | return className; 71 | } 72 | 73 | static public Type[] getGenericType(Class target) { 74 | if (target == null) { 75 | return new Type[0]; 76 | } 77 | Type[] types = target.getGenericInterfaces(); 78 | if (types.length > 0) { 79 | return types; 80 | } 81 | Type type = target.getGenericSuperclass(); 82 | if (type != null) { 83 | if (type instanceof ParameterizedType) { 84 | return new Type[]{type}; 85 | } 86 | } 87 | return new Type[0]; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/frame/FlatColorPicker.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.frame; 2 | 3 | import com.mommoo.flat.frame.colorpicker.FlatColorPickerView; 4 | import com.mommoo.util.ScreenManager; 5 | 6 | import java.awt.*; 7 | import java.util.function.Consumer; 8 | 9 | public class FlatColorPicker { 10 | private static final ScreenManager SCREEN = ScreenManager.getInstance(); 11 | private final FlatFrame PICKER_FRAME = new FlatFrame(); 12 | 13 | public FlatColorPicker(){ 14 | this(Orientation.VERTICAL); 15 | } 16 | 17 | public FlatColorPicker(Orientation orientation){ 18 | FlatColorPickerView flatColorPickerView = new FlatColorPickerView(); 19 | flatColorPickerView.setPreferredSize(orientation.getDimension()); 20 | PICKER_FRAME.getContainer().setLayout(new FlowLayout()); 21 | PICKER_FRAME.getContainer().add(flatColorPickerView); 22 | PICKER_FRAME.pack(); 23 | } 24 | 25 | public static void main(String[] args){ 26 | FlatColorPicker flatColorPicker = new FlatColorPicker(Orientation.HORIZONTAL); 27 | flatColorPicker.setLocationOnScreenCenter(); 28 | flatColorPicker.setTitle("FlatColorPicker"); 29 | // flatColorPicker.setOnColorChangeListener(System.out::println); 30 | // flatColorPicker.setOnConfirmListener(System.out::println); 31 | flatColorPicker.show(); 32 | } 33 | 34 | private FlatColorPickerView getView(){ 35 | return (FlatColorPickerView) PICKER_FRAME.getContainer().getComponent(0); 36 | } 37 | 38 | public void setLocation(int x, int y){ 39 | PICKER_FRAME.setLocation(x, y); 40 | } 41 | 42 | public Point getLocation(){ 43 | return PICKER_FRAME.getLocation(); 44 | } 45 | 46 | public void setLocation(Point point){ 47 | PICKER_FRAME.setLocation(point); 48 | } 49 | 50 | public void setLocationOnScreenCenter(){ 51 | PICKER_FRAME.setLocationOnScreenCenter(); 52 | } 53 | 54 | public void setOnColorChangeListener(Consumer onColorChangeListener){ 55 | getView().setOnColorChangeListener(onColorChangeListener); 56 | } 57 | 58 | public void setOnConfirmListener(Consumer onConfirmListener){ 59 | getView().setOnConfirmListener(onConfirmListener); 60 | } 61 | 62 | public void setOnCancelListener(Runnable onCancelListener){ 63 | getView().setOnCancelListener(onCancelListener); 64 | } 65 | 66 | public String getTitle(){ 67 | return PICKER_FRAME.getTitle(); 68 | } 69 | 70 | public void setTitle(String title){ 71 | PICKER_FRAME.setTitle(title); 72 | } 73 | 74 | public Color getTitleBarColor(){ 75 | return PICKER_FRAME.getTitleBarColor(); 76 | } 77 | 78 | public void setTitleBarColor(Color color){ 79 | PICKER_FRAME.setTitleBarColor(color); 80 | } 81 | 82 | public Color getUiColor(){ 83 | return getView().getUiColor(); 84 | } 85 | 86 | public void setUiColor(Color color){ 87 | getView().setUiColor(color); 88 | } 89 | 90 | public void show(){ 91 | PICKER_FRAME.show(); 92 | } 93 | 94 | public void hide(){ 95 | PICKER_FRAME.hide(); 96 | } 97 | 98 | public enum Orientation{ 99 | HORIZONTAL(SCREEN.dip2px(340), SCREEN.dip2px(160)), 100 | VERTICAL(SCREEN.dip2px(180), SCREEN.dip2px(290)); 101 | 102 | private final Dimension DIMENSION; 103 | 104 | private Orientation(int width, int height){ 105 | this.DIMENSION = new Dimension(width, height); 106 | } 107 | 108 | private Dimension getDimension(){ 109 | return this.DIMENSION; 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/frame/titlebar/navigation/controller/NavigationControlPanel.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.frame.titlebar.navigation.controller; 2 | 3 | 4 | import com.mommoo.flat.frame.titlebar.navigation.button.NavigationButton; 5 | import com.mommoo.flat.frame.titlebar.navigation.button.NavigationButtonFactory; 6 | import com.mommoo.flat.frame.titlebar.navigation.button.NavigationButtonType; 7 | import com.mommoo.flat.frame.titlebar.navigation.listener.NavigationControlListener; 8 | import com.mommoo.util.ScreenManager; 9 | 10 | import javax.swing.*; 11 | import java.awt.*; 12 | 13 | /** 14 | * Created by mommoo on 2017-07-10. 15 | */ 16 | public class NavigationControlPanel extends JPanel { 17 | private static final ScreenManager SCREEN_MANAGER = ScreenManager.getInstance(); 18 | private static final int GAP = SCREEN_MANAGER.dip2px(5); 19 | 20 | private final NavigationButton[] NAVIGATION_BTN_ARRAY = NavigationButtonFactory.createNavigationButtonArray(); 21 | 22 | public NavigationControlPanel(int titleBarHeight) { 23 | setLayout(new GridLayout(0, NAVIGATION_BTN_ARRAY.length, GAP, GAP)); 24 | setMinimumSize(getMinimumPanelDimen(titleBarHeight)); 25 | addNavigationButtons(getButtonDimen(titleBarHeight)); 26 | setTransparent(); 27 | } 28 | 29 | private Dimension getButtonDimen(int titleBarHeight){ 30 | return new Dimension((int)(titleBarHeight*1.5), titleBarHeight); 31 | } 32 | 33 | private Dimension getMinimumPanelDimen(int titleBarHeight){ 34 | return new Dimension((getButtonDimen(titleBarHeight).width * NAVIGATION_BTN_ARRAY.length) + (GAP * (NAVIGATION_BTN_ARRAY.length - 1)), -1); 35 | } 36 | 37 | private void addNavigationButtons(Dimension buttonDimen) { 38 | for (Component comp : NAVIGATION_BTN_ARRAY) { 39 | comp.setPreferredSize(buttonDimen); 40 | comp.setMinimumSize(buttonDimen); 41 | add(comp); 42 | } 43 | } 44 | 45 | private void setTransparent() { 46 | setOpaque(false); 47 | } 48 | 49 | private int findArrayIndexExitButton(){ 50 | return NavigationButtonType.EXIT.ordinal(); 51 | } 52 | 53 | private void setExitButtonColor(){ 54 | int index = findArrayIndexExitButton(); 55 | NAVIGATION_BTN_ARRAY[index].setHoverColor(Color.RED.darker()); 56 | final Color originalMenuIconColor = NAVIGATION_BTN_ARRAY[index].getButtonIconColor(); 57 | NAVIGATION_BTN_ARRAY[index].setHoverInListener(()-> NAVIGATION_BTN_ARRAY[index].setButtonIconColor(Color.WHITE)); 58 | NAVIGATION_BTN_ARRAY[index].setHoverOutListener(()-> NAVIGATION_BTN_ARRAY[index].setButtonIconColor(originalMenuIconColor)); 59 | } 60 | 61 | public void setButtonColor(Color color){ 62 | for (NavigationButton navigationButton : NAVIGATION_BTN_ARRAY){ 63 | navigationButton.setBackground(color); 64 | navigationButton.setHoverColor(color.darker()); 65 | } 66 | 67 | setExitButtonColor(); 68 | } 69 | 70 | public void setButtonIconColor(Color color){ 71 | for (NavigationButton navigationButton : NAVIGATION_BTN_ARRAY){ 72 | navigationButton.setButtonIconColor(color); 73 | } 74 | } 75 | 76 | public Color getButtonIconColor(){ 77 | return NAVIGATION_BTN_ARRAY[0].getButtonIconColor(); 78 | } 79 | 80 | public void setOnControlListener(NavigationControlListener controlListener) { 81 | NavigationButtonType[] buttonTypes = NavigationButtonType.values(); 82 | 83 | for (int i = 0 , size = NAVIGATION_BTN_ARRAY.length ; i < size ; i++){ 84 | NavigationButtonType buttonType = buttonTypes[i]; 85 | NAVIGATION_BTN_ARRAY[i].setOnClickListener(component -> controlListener.onNavigationClick(buttonType)); 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/frame/titlebar/navigation/button/NavigationButtonModel.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.frame.titlebar.navigation.button; 2 | 3 | import com.mommoo.animation.AnimationAdapter; 4 | import com.mommoo.animation.Animator; 5 | import com.mommoo.animation.timeInterpolator.AccelerateInterpolator; 6 | import com.mommoo.flat.component.FlatMouseAdapter; 7 | 8 | import java.awt.*; 9 | import java.awt.event.MouseEvent; 10 | import java.util.List; 11 | 12 | class NavigationButtonModel { 13 | private final ViewModel viewModel; 14 | private float alpha = 0.0f; 15 | private Color hoverColor = Color.LIGHT_GRAY; 16 | 17 | private Runnable hoverInListener = ()->{}; 18 | private Runnable hoverOutListener = ()->{}; 19 | 20 | NavigationButtonModel(ViewModel viewModel){ 21 | this.viewModel = viewModel; 22 | } 23 | 24 | public void setHoverColor(Color hoverColor){ 25 | this.hoverColor = hoverColor; 26 | } 27 | 28 | void paint(Graphics2D graphics2D){ 29 | graphics2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); 30 | graphics2D.setColor(hoverColor); 31 | graphics2D.fillRect(0, 0, viewModel.getWidth(), viewModel.getHeight()); 32 | graphics2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); 33 | } 34 | 35 | HoverAnimListener getHoverAnimListener(){ 36 | return new HoverAnimListener(); 37 | } 38 | 39 | void setHoverInListener(Runnable hoverInListener){ 40 | this.hoverInListener = hoverInListener; 41 | } 42 | 43 | void setHoverOutListener(Runnable hoverOutListener){ 44 | this.hoverOutListener = hoverOutListener; 45 | } 46 | 47 | class HoverAnimListener extends FlatMouseAdapter { 48 | private static final int HOVER_IN_DURATION = 100; 49 | private static final int HOVER_OUT_DURATION = 100; 50 | 51 | private final Animator animator = new Animator().setTimeInterpolator(new AccelerateInterpolator()); 52 | 53 | @Override 54 | public void mouseEntered(MouseEvent e) { 55 | super.mouseEntered(e); 56 | animator 57 | .stop() 58 | .setDuration(HOVER_IN_DURATION) 59 | .setAnimationListener(new AnimationAdapter(){ 60 | @Override 61 | public void onAnimation(List resultList) { 62 | alpha = Math.max(resultList.get(0).floatValue(), 1.0f); 63 | e.getComponent().repaint(); 64 | } 65 | 66 | @Override 67 | public void onStop() { 68 | hoverInListener.run(); 69 | } 70 | 71 | @Override 72 | public void onEnd() { 73 | hoverInListener.run(); 74 | } 75 | }) 76 | .start(1.0d); 77 | } 78 | 79 | @Override 80 | public void mouseExited(MouseEvent e) { 81 | super.mouseExited(e); 82 | animator 83 | .stop() 84 | .setDuration(HOVER_OUT_DURATION) 85 | .setAnimationListener(new AnimationAdapter(){ 86 | private float previousAlpha = alpha; 87 | 88 | @Override 89 | public void onAnimation(List resultList) { 90 | alpha = Math.max(0.0f,previousAlpha - resultList.get(0).floatValue()); 91 | e.getComponent().repaint(); 92 | } 93 | 94 | @Override 95 | public void onStop() { 96 | hoverOutListener.run(); 97 | } 98 | 99 | @Override 100 | public void onEnd() { 101 | hoverOutListener.run(); 102 | } 103 | }) 104 | .start(alpha); 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/utils/FlatColor.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.utils; 2 | 3 | import java.awt.*; 4 | 5 | public class FlatColor { 6 | private FlatColor(){}; 7 | 8 | public static Color darker(Color color, double factor){ 9 | return new Color(Math.max((int)(color.getRed() * factor), 0), 10 | Math.max((int)(color.getGreen() * factor), 0), 11 | Math.max((int)(color.getBlue() * factor), 0), 12 | color.getAlpha()); 13 | } 14 | 15 | public static Color brighter(Color color, double factor){ 16 | int r = color.getRed(); 17 | int g = color.getGreen(); 18 | int b = color.getBlue(); 19 | int alpha = color.getAlpha(); 20 | 21 | int i = (int)(1.0/(1.0 - factor)); 22 | if ( r == 0 && g == 0 && b == 0) { 23 | return new Color(i, i, i, alpha); 24 | } 25 | if ( r > 0 && r < i ) r = i; 26 | if ( g > 0 && g < i ) g = i; 27 | if ( b > 0 && b < i ) b = i; 28 | 29 | return new Color(Math.min((int)(r / factor), 255), 30 | Math.min((int)(g / factor), 255), 31 | Math.min((int)(b / factor), 255), 32 | alpha); 33 | } 34 | 35 | public static Color convertHueToRGB(int hue){ 36 | 37 | if(hue <0 ) return null; 38 | 39 | float r = 0.0f; 40 | float g = 0.0f; 41 | float b = 0.0f; 42 | float sub = 4.250f; 43 | 44 | float ratio = hue - 60*(hue/60); 45 | if(ratio % 60 ==0) ratio += 60; 46 | if (hue == 0){ 47 | r = 255.0f; 48 | }else if (hue>0 && hue<=60){ 49 | r = 255.0f; 50 | g = sub*ratio; 51 | b = 0.0f; 52 | }else if (hue>60 && hue<=120){ 53 | r = 255.0f - sub*ratio; 54 | g = 255.0f; 55 | b = 0.0f; 56 | }else if (hue>120 && hue<=180){ 57 | r = 0f; 58 | g = 255.0f; 59 | b = sub*ratio; 60 | }else if (hue>180 && hue <= 240){ 61 | r = 0f; 62 | g = 255.0f - sub*ratio; 63 | b = 255.0f; 64 | }else if (hue>240 && hue <= 300){ 65 | r = sub*ratio; 66 | g = 0.0f; 67 | b = 255.0f; 68 | }else if (hue>300 && hue<=360){ 69 | r = 255.0f; 70 | g = 0.0f; 71 | b = 255.0f - sub*ratio; 72 | } 73 | 74 | return new Color((int)r,(int)g,(int)b); 75 | } 76 | 77 | 78 | /** 79 | * @param h 80 | * 0-360 81 | * @param s 82 | * 0-100 83 | * @param b 84 | * 0-100 85 | * @return color in hex string 86 | */ 87 | public static Color convertHSBtoRGB(float h, float s, float b) { 88 | 89 | float R, G, B; 90 | 91 | h /= 360f; 92 | s /= 100f; 93 | b /= 100f; 94 | 95 | if (s == 0) 96 | { 97 | R = b * 255; 98 | G = b * 255; 99 | B = b * 255; 100 | } else { 101 | float var_h = h * 6; 102 | if (var_h == 6) 103 | var_h = 0; // H must be < 1 104 | int var_i = (int) Math.floor((double) var_h); // Or ... var_i = 105 | // floor( var_h ) 106 | float var_1 = b * (1 - s); 107 | float var_2 = b * (1 - s * (var_h - var_i)); 108 | float var_3 = b * (1 - s * (1 - (var_h - var_i))); 109 | 110 | float var_r; 111 | float var_g; 112 | float var_b; 113 | if (var_i == 0) { 114 | var_r = b; 115 | var_g = var_3; 116 | var_b = var_1; 117 | } else if (var_i == 1) { 118 | var_r = var_2; 119 | var_g = b; 120 | var_b = var_1; 121 | } else if (var_i == 2) { 122 | var_r = var_1; 123 | var_g = b; 124 | var_b = var_3; 125 | } else if (var_i == 3) { 126 | var_r = var_1; 127 | var_g = var_2; 128 | var_b = b; 129 | } else if (var_i == 4) { 130 | var_r = var_3; 131 | var_g = var_1; 132 | var_b = b; 133 | } else { 134 | var_r = b; 135 | var_g = var_1; 136 | var_b = var_2; 137 | } 138 | 139 | R = var_r * 255; // RGB results from 0 to 255 140 | G = var_g * 255; 141 | B = var_b * 255; 142 | } 143 | return new Color(Math.round(R),Math.round(G),Math.round(B)); 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/frame/colorpicker/ColorApplyView.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.frame.colorpicker; 2 | 3 | import com.mommoo.flat.border.FlatEmptyBorder; 4 | import com.mommoo.flat.button.FlatButton; 5 | import com.mommoo.flat.frame.FlatDialog; 6 | import com.mommoo.flat.layout.linear.LinearLayout; 7 | import com.mommoo.flat.layout.linear.Orientation; 8 | import com.mommoo.flat.layout.linear.constraints.LinearConstraints; 9 | import com.mommoo.flat.layout.linear.constraints.LinearSpace; 10 | import com.mommoo.flat.text.label.FlatLabel; 11 | import com.mommoo.flat.text.textarea.alignment.FlatHorizontalAlignment; 12 | import com.mommoo.flat.text.textarea.alignment.FlatVerticalAlignment; 13 | import com.mommoo.flat.text.textfield.FlatTextField; 14 | import com.mommoo.flat.text.textfield.format.FlatTextFormat; 15 | import com.mommoo.util.ComputableDimension; 16 | import com.mommoo.util.FontManager; 17 | import com.mommoo.util.ScreenManager; 18 | 19 | import javax.swing.*; 20 | import java.awt.*; 21 | import java.util.function.Consumer; 22 | 23 | class ColorApplyView extends JPanel { 24 | private static final ScreenManager SCREEN = ScreenManager.getInstance(); 25 | private static final Font BUTTON_FONT = FontManager.getNanumGothicFont(Font.PLAIN, SCREEN.dip2px(6)); 26 | private static final Font FONT = FontManager.getNanumGothicFont(Font.PLAIN, SCREEN.dip2px(10)); 27 | 28 | private Consumer onColorApplyListener = hsb -> {}; 29 | 30 | ColorApplyView() { 31 | setOpaque(false); 32 | setLayout(new LinearLayout(Orientation.VERTICAL, 0)); 33 | add(new GuideView("apply"), new LinearConstraints(LinearSpace.MATCH_PARENT)); 34 | add(new ApplyPanel(), new LinearConstraints(1, LinearSpace.MATCH_PARENT)); 35 | } 36 | 37 | void setUiColor(Color uiColor){ 38 | ((FlatTextField)getApplyPanel().getComponent(1)).setFocusGainedColor(uiColor); 39 | getApplyPanel().getComponent(2).setBackground(uiColor); 40 | } 41 | 42 | void setOnColorApplyListener(Consumer onColorApplyListener){ 43 | this.onColorApplyListener = onColorApplyListener; 44 | } 45 | 46 | private Container getApplyPanel(){ 47 | return (Container)getComponent(1); 48 | } 49 | 50 | private class ApplyPanel extends JPanel{ 51 | 52 | private ApplyPanel(){ 53 | setOpaque(false); 54 | setLayout(new LinearLayout(0)); 55 | add(createPrefixLabel(), new LinearConstraints(LinearSpace.MATCH_PARENT)); 56 | add(createColorTextField(), new LinearConstraints(1, LinearSpace.MATCH_PARENT)); 57 | add(createApplyButton(), new LinearConstraints(LinearSpace.MATCH_PARENT)); 58 | } 59 | 60 | private Component createPrefixLabel(){ 61 | FlatLabel prefixLabel = new FlatLabel("#"); 62 | prefixLabel.setFont(FONT); 63 | prefixLabel.setVerticalAlignment(FlatVerticalAlignment.CENTER); 64 | prefixLabel.setHorizontalAlignment(FlatHorizontalAlignment.CENTER); 65 | return prefixLabel; 66 | } 67 | 68 | private Component createColorTextField(){ 69 | FlatTextField colorTextField = new FlatTextField(false); 70 | colorTextField.setFont(FONT); 71 | colorTextField.setFormat(FlatTextFormat.HEX_COLOR); 72 | colorTextField.setOpaque(false); 73 | colorTextField.setHint("ex) 68ceef"); 74 | colorTextField.setHorizontalTextFieldAlignment(JTextField.CENTER); 75 | return colorTextField; 76 | } 77 | 78 | private Component createApplyButton(){ 79 | FlatButton applyButton = new FlatButton("APPLY"); 80 | applyButton.setFont(BUTTON_FONT); 81 | applyButton.setPreferredSize(new ComputableDimension(applyButton.getPreferredSize()).addDimension(SCREEN.dip2px(10))); 82 | applyButton.setOnClickListener(comp-> { 83 | 84 | String hexCodeText = ((FlatTextField)getComponent(1)).getText(); 85 | if (hexCodeText.length() != 6){ 86 | new FlatDialog 87 | .Builder() 88 | .setTitle("Format Error") 89 | .setLocationCenterTo(SwingUtilities.getWindowAncestor(applyButton)) 90 | .setContent("You have to keep the six digits") 91 | .build() 92 | .show(); 93 | 94 | return; 95 | } 96 | 97 | onColorApplyListener.accept(new HSB(Color.decode("#"+hexCodeText))); 98 | }); 99 | return applyButton; 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/select/CheckBox.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.select; 2 | 3 | import com.mommoo.flat.component.FlatPanel; 4 | import com.mommoo.flat.component.MouseClickAdapter; 5 | import com.mommoo.flat.component.OnClickListener; 6 | import com.mommoo.flat.image.FlatImagePanel; 7 | import com.mommoo.flat.image.ImageOption; 8 | import com.mommoo.util.ImageManager; 9 | import com.mommoo.util.ImageUtils; 10 | import com.mommoo.util.ScreenManager; 11 | 12 | import javax.swing.*; 13 | import java.awt.*; 14 | import java.awt.image.BufferedImage; 15 | import java.util.HashMap; 16 | import java.util.Map; 17 | 18 | class CheckBox extends FlatPanel{ 19 | private static final ScreenManager screenManager = ScreenManager.getInstance(); 20 | private static final Dimension CHECK_BOX_DIMENSION = new Dimension(screenManager.dip2px(15), screenManager.dip2px(15)); 21 | private static final Map checkMap = new HashMap<>(); 22 | private static final Cursor HAND_CURSOR = new Cursor(Cursor.HAND_CURSOR); 23 | 24 | private MouseClickAdapter userMouseClickAdapter; 25 | 26 | private Color checkColor = Color.BLACK; 27 | private Color checkBoxColor = Color.BLACK; 28 | 29 | CheckBox(){ 30 | setCheckBoxColor(checkBoxColor); 31 | setLayout(new BorderLayout()); 32 | super.setOnClickListener(comp-> getComponent(0).setVisible(!getComponent(0).isVisible())); 33 | add(new FlatImagePanel(ImageManager.CHECK,ImageOption.MATCH_PARENT)); 34 | getCheckImageView().setVisible(false); 35 | setCursor(HAND_CURSOR); 36 | } 37 | 38 | private static BufferedImage getColorCheckImage(Color color){ 39 | if (checkMap.get(color) == null){ 40 | checkMap.put(color, createNewColorCheckImage(color)); 41 | } 42 | 43 | return checkMap.get(color); 44 | } 45 | 46 | private static BufferedImage createNewColorCheckImage(Color color) { 47 | BufferedImage bufferedImage = ImageUtils.toBufferedImage(ImageManager.CHECK, true); 48 | int width = bufferedImage.getWidth(); 49 | int height = bufferedImage.getHeight(); 50 | 51 | BufferedImage newColorCheckImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); 52 | 53 | for (int x = 0; x < width; x++) { 54 | for (int y = 0; y < height; y++) { 55 | 56 | int rgba = bufferedImage.getRGB(x, y); 57 | boolean isTrans = (rgba & 0xff000000) == 0; 58 | 59 | if (isTrans) { 60 | newColorCheckImage.setRGB(x, y, (color.getRGB()&0x00ffffff)); 61 | } else { 62 | newColorCheckImage.setRGB(x, y, color.getRGB()); 63 | } 64 | } 65 | } 66 | 67 | return newColorCheckImage; 68 | } 69 | 70 | Color getCheckColor(){ 71 | return this.checkColor; 72 | } 73 | 74 | void setCheckColor(Color checkColor){ 75 | this.checkColor = checkColor; 76 | getCheckImageView().setImage(getColorCheckImage(checkColor), ImageOption.MATCH_PARENT); 77 | } 78 | 79 | Color getCheckBoxColor(){ 80 | return this.checkBoxColor; 81 | } 82 | 83 | void setCheckBoxColor(Color checkBoxColor){ 84 | setBorder(BorderFactory.createLineBorder(checkBoxColor, 1)); 85 | } 86 | 87 | void doClick(Component source){ 88 | getOnClickListener().onClick(source); 89 | if (this.userMouseClickAdapter != null) this.userMouseClickAdapter.getOnClickListener().onClick(source); 90 | } 91 | 92 | void setOnClickListener(Component source, OnClickListener onClickListener){ 93 | removeOnClickListener(); 94 | addMouseListener(userMouseClickAdapter = new MouseClickAdapter(source, onClickListener)); 95 | } 96 | 97 | @Override 98 | public void removeOnClickListener() { 99 | if (userMouseClickAdapter != null) { 100 | removeMouseListener(userMouseClickAdapter); 101 | } 102 | } 103 | 104 | boolean isChecked(){ 105 | return getComponent(0).isVisible(); 106 | } 107 | 108 | void setChecked(boolean check){ 109 | getCheckImageView().setVisible(check); 110 | } 111 | 112 | private FlatImagePanel getCheckImageView(){ 113 | return (FlatImagePanel) getComponent(0); 114 | } 115 | 116 | @Override 117 | public Dimension getMaximumSize() { 118 | return CHECK_BOX_DIMENSION; 119 | } 120 | 121 | @Override 122 | public Dimension getPreferredSize() { 123 | return CHECK_BOX_DIMENSION; 124 | } 125 | 126 | @Override 127 | public Dimension getMinimumSize() { 128 | return CHECK_BOX_DIMENSION; 129 | } 130 | } 131 | 132 | -------------------------------------------------------------------------------- /src/com/mommoo/util/FastGaussianBlur.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.util; 2 | 3 | import java.awt.image.BufferedImage; 4 | 5 | public class FastGaussianBlur { 6 | public static void blur(BufferedImage image, final double radius, int n) { 7 | final int w = image.getWidth(); 8 | final int h = image.getHeight(); 9 | final int[] pixels = new int[w * h]; 10 | image.getRGB(0, 0, w, h, pixels, 0, w); 11 | int[][] channels = new int[4][]; 12 | int[] red = new int[w*h]; 13 | for (int channel = 0; channel <= 3; channel++) { 14 | int[] blurRed = new int[w * h]; 15 | for (int i = 0; i < w * h; i++) { 16 | red[i] = (pixels[i] >> (channel * 8)) & 0xff; 17 | } 18 | gaussBlur_4(red, blurRed, w, h, radius, n); 19 | channels[channel] = blurRed; 20 | } 21 | 22 | for (int i = 0; i < w * h; i++) { 23 | pixels[i] = channels[0][i] | channels[1][i] << 8 | channels[2][i] << 16 | channels[3][i] << 24; 24 | } 25 | 26 | image.setRGB(0, 0, w, h, pixels, 0, w); 27 | } 28 | 29 | private static int[] boxesForGauss(double sigma, int n) {// standard deviation, number of boxes 30 | double wIdeal = Math.sqrt((12 * sigma * sigma / n) + 1); // Ideal averaging filter width 31 | int wl = (int) Math.floor(wIdeal); 32 | if (wl % 2 == 0) { 33 | wl--; 34 | } 35 | int wu = wl + 2; 36 | 37 | double mIdeal = (12 * sigma * sigma - n * wl * wl - 4 * n * wl - 3 * n) / (-4 * wl - 4); 38 | int m = (int) Math.round(mIdeal); 39 | 40 | int[] sizes = new int[n]; 41 | for (int i = 0; i < n; i++) { 42 | sizes[i] = i < m ? wl : wu; 43 | } 44 | return sizes; 45 | } 46 | 47 | private static void gaussBlur_4(int[] scl, int[] tcl, int w, int h, double r, int n) { 48 | int[] bxs = boxesForGauss(r, n); 49 | boxBlur_4(scl, tcl, w, h, (bxs[0] - 1) / 2); 50 | boxBlur_4(tcl, scl, w, h, (bxs[1] - 1) / 2); 51 | boxBlur_4(scl, tcl, w, h, (bxs[2] - 1) / 2); 52 | } 53 | 54 | private static void boxBlur_4(int[] scl, int[] tcl, int w, int h, double r) { 55 | System.arraycopy(scl, 0, tcl, 0, scl.length); 56 | boxBlurH_4(tcl, scl, w, h, r); 57 | boxBlurT_4(scl, tcl, w, h, r); 58 | } 59 | 60 | private static void boxBlurH_4(int[] scl, int[] tcl, int w, int h, double r) { 61 | double iarr = 1.0 / (r + r + 1); 62 | for (int i = 0; i < h; i++) { 63 | int ti = i * w; 64 | int li = ti; 65 | int ri = (int) (ti + r); 66 | int fv = scl[ti]; 67 | int lv = scl[ti + w - 1]; 68 | double val = (r + 1) * fv; 69 | for (int j = 0; j < r; j++) { 70 | val += scl[ti + j]; 71 | } 72 | for (int j = 0; j <= r; j++) { 73 | val += scl[ri++] - fv; 74 | tcl[ti++] = (int) Math.round(val * iarr); 75 | } 76 | for (int j = (int) (r + 1); j < w - r; j++) { 77 | val += scl[ri++] - scl[li++]; 78 | tcl[ti++] = (int) Math.round(val * iarr); 79 | } 80 | for (int j = (int) (w - r); j < w; j++) { 81 | val += lv - scl[li++]; 82 | tcl[ti++] = (int) Math.round(val * iarr); 83 | } 84 | } 85 | } 86 | 87 | private static void boxBlurT_4(int[] scl, int[] tcl, int w, int h, double r) { 88 | double iarr = 1.0 / (r + r + 1); 89 | for (int i = 0; i < w; i++) { 90 | int ti = i; 91 | int li = ti; 92 | int ri = (int) (ti + r * w); 93 | int fv = scl[ti]; 94 | int lv = scl[ti + w * (h - 1)]; 95 | double val = (r + 1) * fv; 96 | for (int j = 0; j < r; j++) { 97 | val += scl[ti + j * w]; 98 | } 99 | for (int j = 0; j <= r; j++) { 100 | val += scl[ri] - fv; 101 | tcl[ti] = (int) Math.round(val * iarr); 102 | ri += w; 103 | ti += w; 104 | } 105 | for (int j = (int) (r + 1); j < h - r; j++) { 106 | val += scl[ri] - scl[li]; 107 | tcl[ti] = (int) Math.round(val * iarr); 108 | li += w; 109 | ri += w; 110 | ti += w; 111 | } 112 | for (int j = (int) (h - r); j < h; j++) { 113 | val += lv - scl[li]; 114 | tcl[ti] = (int) Math.round(val * iarr); 115 | li += w; 116 | ti += w; 117 | } 118 | } 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/com/mommoo/util/StringUtils.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.util; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | import java.util.stream.Collectors; 7 | 8 | public class StringUtils { 9 | private StringUtils() { 10 | } 11 | 12 | public static final int indexOfAny(String string, String[] keys) { 13 | return indexOfAny(string, keys, 0); 14 | } 15 | 16 | public static final int lastIndexOfAny(String string, String[] keys){ 17 | return lastIndexOfAny(string, keys, string.length()); 18 | } 19 | 20 | public static final int indexOfAny(String string, String[] keys, int fromIndex) { 21 | 22 | List indexList = 23 | Arrays.stream(keys) 24 | .map(key -> string.indexOf(key, fromIndex)) 25 | .filter(index -> index != -1) 26 | .sorted() 27 | .collect(Collectors.toList()); 28 | 29 | return indexList.size() == 0 ? -1 : indexList.get(0); 30 | } 31 | 32 | public static final int lastIndexOfAny(String string, String[] keys, int fromIndex) { 33 | List indexList = 34 | Arrays.stream(keys) 35 | .map(key -> string.lastIndexOf(key, fromIndex)) 36 | .filter(index -> index != -1) 37 | .sorted() 38 | .collect(Collectors.toList()); 39 | 40 | return indexList.size() == 0 ? -1 : indexList.get(indexList.size() - 1); 41 | } 42 | 43 | public static final int[] indexAndKeyOfAny(String string, String[] keys, int fromIndex){ 44 | int index = indexOfAny(string, keys, fromIndex); 45 | 46 | if (index != -1){ 47 | for (int keyIndex = 0 , size = keys.length ; keyIndex < size ; keyIndex++){ 48 | String key = keys[keyIndex]; 49 | if(key.equals(string.substring(index, index + key.length()))){ 50 | return new int[]{index, keyIndex}; 51 | } 52 | } 53 | } 54 | 55 | return new int[]{-1, -1}; 56 | 57 | } 58 | 59 | public static final List splitOfAny(String string, String[] keys){ 60 | List resultList = new ArrayList<>(); 61 | 62 | int fromIndex = 0; 63 | while (true){ 64 | int[] indexAndKey = indexAndKeyOfAny(string, keys, fromIndex); 65 | int index = indexAndKey[0]; 66 | int keyIndex = indexAndKey[1]; 67 | 68 | if (index == -1) { 69 | resultList.add(string.substring(fromIndex, string.length())); 70 | break; 71 | } 72 | 73 | resultList.add(string.substring(fromIndex, index)); 74 | 75 | fromIndex = index + keys[keyIndex].length(); 76 | } 77 | 78 | return resultList; 79 | } 80 | 81 | public static boolean isNumber(String string){ 82 | try{ 83 | Integer.parseInt(string); 84 | return true; 85 | }catch(Exception e){ 86 | return false; 87 | } 88 | } 89 | 90 | /** 91 | * ASCII Table 0 ~ 9 92 | * 48 ~ 57 93 | */ 94 | public static boolean isNumberChar(char c){ 95 | int asciiCode = (int)c; 96 | return asciiCode <= 57 && asciiCode >= 48; 97 | } 98 | 99 | 100 | /** 101 | * ASCII Table's special characters 102 | * (space) range : 32 103 | * ! " # $ % & ' ( ) * + , - . / range : 33 ~ 47 104 | * : ; < = > ? @ range : 58 ~ 64 105 | * [ \ ] ^ _ ` range : 91 ~ 96 106 | * { | } ~ range : 123 ~ 126 107 | * 108 | */ 109 | public static boolean isSpecialChar(char c){ 110 | int asciiCode = (int)c; 111 | return (32 <= asciiCode && asciiCode <= 47) || 112 | (58 <= asciiCode && asciiCode <= 64) || 113 | (91 <= asciiCode && asciiCode <= 96) || 114 | (123 <= asciiCode && asciiCode <= 126); 115 | } 116 | 117 | /** 118 | * ASCII Table's hex color characters 119 | * A ~ F range : 65 ~ 70 120 | * a ~ f range : 97 ~ 102 121 | */ 122 | public static boolean isHexColorChar(char c){ 123 | int asciiCode = (int)c; 124 | return isNumberChar(c) || 125 | (65 <= asciiCode && asciiCode <= 70) || 126 | (97 <= asciiCode && asciiCode <= 102); 127 | } 128 | 129 | public static void main(String[] args) { 130 | System.out.println("20170131".matches("2017.?1.?1")); 131 | System.out.println("TODO_20179111".matches("TODO_2017.1.1")); 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/text/textfield/FlatGuideTextPanel.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.text.textfield; 2 | 3 | import com.mommoo.flat.component.FlatPanel; 4 | import com.mommoo.flat.frame.FlatFrame; 5 | import com.mommoo.flat.text.label.FlatLabel; 6 | import com.mommoo.flat.layout.linear.LinearLayout; 7 | import com.mommoo.flat.layout.linear.Orientation; 8 | import com.mommoo.flat.layout.linear.constraints.LinearConstraints; 9 | import com.mommoo.flat.layout.linear.constraints.LinearSpace; 10 | import com.mommoo.util.FontManager; 11 | import com.mommoo.util.ImageManager; 12 | import com.mommoo.util.ScreenManager; 13 | 14 | import javax.swing.*; 15 | import java.awt.*; 16 | import java.awt.event.FocusEvent; 17 | import java.awt.event.FocusListener; 18 | import java.awt.font.TextAttribute; 19 | import java.util.HashMap; 20 | import java.util.Map; 21 | 22 | public class FlatGuideTextPanel extends FlatPanel { 23 | private static final ScreenManager SCREEN = ScreenManager.getInstance(); 24 | private static final Font DEFAULT_FONT = FontManager.getNanumGothicFont(Font.BOLD, SCREEN.dip2px(8)).deriveFont(getAttribute()); 25 | 26 | public FlatGuideTextPanel(FlatTextField flatTextField){ 27 | setOpaque(true); 28 | setLayout(new LinearLayout(Orientation.VERTICAL, 0)); 29 | setBackground(flatTextField.getBackground()); 30 | 31 | add(createGuideLabel(), new LinearConstraints().setLinearSpace(LinearSpace.MATCH_PARENT)); 32 | add(flatTextField, new LinearConstraints().setLinearSpace(LinearSpace.MATCH_PARENT)); 33 | 34 | addTextFieldFocusListener(flatTextField); 35 | } 36 | 37 | public static void main(String[] args){ 38 | FlatFrame flatFrame = new FlatFrame(); 39 | flatFrame.setTitle("Beautiful FlatGuideTextPanel"); 40 | flatFrame.setSize(500,500); 41 | flatFrame.setLocationOnScreenCenter(); 42 | 43 | FlatTextField flatTextField = new FlatTextField(false); 44 | flatTextField.setHint("hint"); 45 | flatTextField.setIconImage(ImageManager.CHECK); 46 | 47 | FlatGuideTextPanel flatGuideTextPanel = new FlatGuideTextPanel(flatTextField); 48 | flatGuideTextPanel.setGuideText("good".toUpperCase()); 49 | 50 | FlatTextField flatTextField2 = new FlatTextField(false); 51 | flatTextField2.setHint("hint2"); 52 | 53 | FlatGuideTextPanel flatGuideTextPanel2 = new FlatGuideTextPanel(flatTextField2); 54 | flatGuideTextPanel2.setGuideText("good".toUpperCase()); 55 | 56 | flatFrame.getContainer().setLayout(new LinearLayout(Orientation.VERTICAL)); 57 | flatFrame.getContainer().add(flatGuideTextPanel); 58 | flatFrame.getContainer().add(flatGuideTextPanel2); 59 | flatFrame.setResizable(true); 60 | 61 | flatFrame.show(); 62 | 63 | } 64 | 65 | private Component createGuideLabel(){ 66 | FlatLabel guideLabel = new FlatLabel(); 67 | guideLabel.setBorder(BorderFactory.createEmptyBorder(10,0,10,0)); 68 | guideLabel.setFont(DEFAULT_FONT); 69 | guideLabel.setOpaque(false); 70 | return guideLabel; 71 | } 72 | 73 | private static Map getAttribute(){ 74 | Map attributes = new HashMap<>(); 75 | attributes.put(TextAttribute.TRACKING, 0.1); 76 | return attributes; 77 | } 78 | 79 | private FlatLabel getGuideLabel(){ 80 | return (FlatLabel) getComponent(0); 81 | } 82 | 83 | public FlatTextField getTextField(){ 84 | return (FlatTextField) getComponent(1); 85 | } 86 | 87 | private void addTextFieldFocusListener(FlatTextField flatTextField){ 88 | flatTextField 89 | .getTextField() 90 | .addFocusListener(new FocusListener() { 91 | private Color previousForegroundColor = flatTextField.getForeground(); 92 | 93 | @Override 94 | public void focusGained(FocusEvent e) { 95 | getGuideLabel().setForeground(flatTextField.getFocusGainedColor()); 96 | } 97 | 98 | @Override 99 | public void focusLost(FocusEvent e) { 100 | getGuideLabel().setForeground(previousForegroundColor); 101 | } 102 | }); 103 | } 104 | 105 | public String getGuideText(){ 106 | return getGuideLabel().getText(); 107 | } 108 | 109 | public void setGuideText(String text){ 110 | getGuideLabel().setText(text); 111 | } 112 | 113 | public Font getGuideFont(){ 114 | return getGuideLabel().getFont(); 115 | } 116 | 117 | public void setGuideFont(Font font){ 118 | getGuideLabel().setFont(font); 119 | } 120 | 121 | public Color getGuideForeground(){ 122 | return getGuideLabel().getForeground(); 123 | } 124 | 125 | public void setGuideForeground(Color color){ 126 | getGuideLabel().setForeground(color); 127 | } 128 | 129 | @Override 130 | public void setBackground(Color bg) { 131 | super.setBackground(bg); 132 | if(getComponentCount() > 1) getTextField().setBackground(bg); 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/frame/CommonJFrame.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.frame; 2 | 3 | import com.mommoo.flat.border.FlatShadowBorder; 4 | import com.mommoo.helper.ComponentResizer; 5 | import com.mommoo.util.ColorManager; 6 | import com.mommoo.util.ComputableDimension; 7 | import com.mommoo.util.ScreenManager; 8 | import sun.awt.SunToolkit; 9 | 10 | import javax.swing.*; 11 | import javax.swing.border.LineBorder; 12 | import java.awt.*; 13 | 14 | final class CommonJFrame extends JFrame { 15 | private static final int SHADOW_WIDTH = ScreenManager.getInstance().dip2px(20); 16 | private final ComponentResizer COMPONENT_RE_SIZER = createComponentResizer(); 17 | 18 | CommonJFrame() { 19 | setUndecorated(true); 20 | setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 21 | setBackground(ColorManager.getTransParentColor()); 22 | setShadowPane(); 23 | setContentPane(createContentPane()); 24 | setBorderLine(Color.GRAY, 1); 25 | } 26 | 27 | private static JPanel createContentPane() { 28 | JPanel contentPane = new JPanel(new BorderLayout()); 29 | contentPane.setOpaque(true); 30 | contentPane.setBackground(Color.WHITE); 31 | return contentPane; 32 | } 33 | 34 | public static void main(String args[]) { 35 | SwingUtilities.invokeLater(() -> { 36 | CommonJFrame jf = new CommonJFrame(); 37 | jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 38 | jf.setSize(500, 500); 39 | jf.setLocation(300, 300); 40 | jf.setLayout(new FlowLayout()); 41 | jf.setResizable(true); 42 | jf.setShadowWidth(10); 43 | jf.getContentPane().add(new JButton("BUTTON")); 44 | jf.setVisible(true); 45 | }); 46 | } 47 | 48 | private ComponentResizer createComponentResizer() { 49 | ComponentResizer componentResizer = new ComponentResizer(); 50 | componentResizer.setMinimumSize(new Dimension(40, 40)); 51 | componentResizer.setDragInsets(new Insets(9, 9, 9, 9)); 52 | componentResizer.setEnableChangeSize(new Dimension(40,40)); 53 | return componentResizer; 54 | } 55 | 56 | private void setShadowPane() { 57 | JPanel shadowPane = new JPanel(new BorderLayout()); 58 | shadowPane.setOpaque(false); 59 | shadowPane.setBackground(Color.WHITE); 60 | shadowPane.setBorder(new FlatShadowBorder(SHADOW_WIDTH)); 61 | super.setContentPane(shadowPane); 62 | } 63 | 64 | private void setBorderLine(Color color, int thickness){ 65 | ((JPanel)getContentPane()).setBorder(BorderFactory.createLineBorder(color, thickness)); 66 | } 67 | 68 | @Override 69 | public Container getContentPane() { 70 | return (Container) getShadowPane().getComponent(0); 71 | } 72 | 73 | @Override 74 | public void setContentPane(Container contentPane) { 75 | getShadowPane().add(contentPane, BorderLayout.CENTER, 0); 76 | } 77 | 78 | private JPanel getShadowPane() { 79 | return (JPanel) super.getContentPane(); 80 | } 81 | 82 | @Override 83 | public void setResizable(boolean reSizable) { 84 | super.setResizable(reSizable); 85 | if (reSizable) COMPONENT_RE_SIZER.registerComponent(this); 86 | else COMPONENT_RE_SIZER.deregisterComponent(this); 87 | } 88 | 89 | ComputableDimension getAvailableDimension(){ 90 | Insets insets = getShadowPane().getInsets(); 91 | return new ComputableDimension(getSize()) 92 | .setMinimumSize(0,0) 93 | .subDimension(insets.left, insets.top) 94 | .subDimension(insets.right, insets.bottom); 95 | } 96 | 97 | Color getBorderColor() { 98 | JPanel borderPanel = (JPanel) getContentPane(); 99 | LineBorder lineBorder = (LineBorder)borderPanel.getBorder(); 100 | return lineBorder.getLineColor(); 101 | } 102 | 103 | void setBorderColor(Color color) { 104 | JPanel borderPanel = (JPanel) getContentPane(); 105 | LineBorder lineBorder = (LineBorder)borderPanel.getBorder(); 106 | setBorderLine(color, lineBorder.getThickness()); 107 | } 108 | 109 | int getBorderStrokeWidth() { 110 | JPanel borderPanel = (JPanel) getContentPane(); 111 | LineBorder lineBorder = (LineBorder)borderPanel.getBorder(); 112 | return lineBorder.getThickness(); 113 | } 114 | 115 | void setBorderStrokeWidth(int borderWidth) { 116 | JPanel borderPanel = (JPanel) getContentPane(); 117 | LineBorder lineBorder = (LineBorder)borderPanel.getBorder(); 118 | setBorderLine(lineBorder.getLineColor(), borderWidth); 119 | } 120 | 121 | int getShadowWidth() { 122 | return ((FlatShadowBorder)getShadowPane().getBorder()).getShadowWidth(); 123 | } 124 | 125 | void setShadowWidth(int shadowWidth) { 126 | if (shadowWidth < 0) shadowWidth = 0; 127 | getShadowPane().setBorder(new FlatShadowBorder(shadowWidth)); 128 | } 129 | 130 | Insets getShadowInsets(){ 131 | return getShadowPane().getBorder().getBorderInsets(getShadowPane()); 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/component/pager/FlatPageSlider.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.component.pager; 2 | 3 | import com.mommoo.animation.AnimationAdapter; 4 | 5 | import javax.swing.*; 6 | import java.awt.*; 7 | import java.awt.image.BufferedImage; 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | import java.util.Set; 11 | import java.util.TreeSet; 12 | 13 | class FlatPageSlider extends JPanel { 14 | private final SlideAnimator SLIDE_ANIMATOR = new SlideAnimator(); 15 | private int offsets = 0; 16 | private boolean needToArrange = true; 17 | private final Set screenOffLoadIndex = new TreeSet<>(); 18 | 19 | private List onPageSelectedListenerList = new ArrayList<>(); 20 | 21 | FlatPageSlider(){ 22 | setOpaque(false); 23 | setLayout(null); 24 | } 25 | 26 | private void executeScreenOffLoad(int pageIndex){ 27 | if(screenOffLoadIndex.contains(pageIndex)) { 28 | BufferedImage screenOffBuffer = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB); 29 | Graphics graphics = screenOffBuffer.createGraphics(); 30 | getComponent(pageIndex).paintAll(graphics); 31 | graphics.dispose(); 32 | } 33 | } 34 | 35 | @Override 36 | public void paint(Graphics g) { 37 | if (needToArrange){ 38 | for (int i = 0, size = getComponentCount(); i < size ; i ++){ 39 | int x = getWidth() * (i - offsets); 40 | getComponent(i).setBounds(x, 0, getWidth(), getHeight()); 41 | executeScreenOffLoad(i); 42 | } 43 | needToArrange = false; 44 | 45 | } 46 | super.paint(g); 47 | } 48 | 49 | void addPage(Component pageView){ 50 | add(pageView); 51 | needToArrange = true; 52 | repaint(); 53 | } 54 | 55 | void removePage(int index){ 56 | remove(index); 57 | needToArrange = true; 58 | repaint(); 59 | } 60 | 61 | void setOffset(int offsets){ 62 | this.offsets = offsets; 63 | } 64 | 65 | void slide(int pageIndex, boolean isAnimation){ 66 | if (isAnimation){ 67 | SLIDE_ANIMATOR 68 | .setOnFinishListener(()-> this.offsets = pageIndex) 69 | .stop() 70 | // have to moving distance of component0 71 | .start(- getWidth() * pageIndex + Math.abs(getComponent(0).getX())); 72 | } else { 73 | for (int i = 0, size = getComponentCount(); i < size ; i ++){ 74 | getComponent(i).setLocation((- pageIndex * getWidth()) + (getWidth() * i),0); 75 | } 76 | repaint(); 77 | this.offsets = pageIndex; 78 | } 79 | } 80 | 81 | void addOnPageSelectedListener(OnPageSelectedListener onPageSelectedListener){ 82 | this.onPageSelectedListenerList.add(onPageSelectedListener); 83 | } 84 | 85 | void setOnPageSelectedListener(int index, OnPageSelectedListener onPageSelectedListener){ 86 | this.onPageSelectedListenerList.set(index, onPageSelectedListener); 87 | } 88 | 89 | void setScreenOffLoadIndex(int index){ 90 | screenOffLoadIndex.add(index); 91 | } 92 | 93 | OnPageSelectedListener getOnPageSelectedListener(int index){ 94 | return this.onPageSelectedListenerList.get(index); 95 | } 96 | 97 | FlatAnimator getAnimator(){ 98 | return SLIDE_ANIMATOR; 99 | } 100 | 101 | private class SlideAnimator extends FlatAnimator { 102 | 103 | private Runnable onFinishListener = () -> {}; 104 | 105 | private SlideAnimator(){ 106 | setAnimationListener(new AnimationAdapter(){ 107 | private int previousX; 108 | 109 | @Override 110 | public void onStart() { 111 | if (getComponentCount() > 0){ 112 | previousX = getComponent(0).getX(); 113 | } 114 | } 115 | 116 | @Override 117 | public void onAnimation(List resultList) { 118 | int x = resultList.get(0).intValue(); 119 | 120 | Component firstComp = getComponent(0); 121 | firstComp.setLocation(previousX + x, 0); 122 | 123 | for (int i = 1, size = getComponentCount(); i < size ; i ++){ 124 | getComponent(i).setLocation((firstComp.getX() + (getWidth() * i)),0); 125 | } 126 | repaint(); 127 | } 128 | 129 | @Override 130 | public void onEnd() { 131 | onFinishListener.run(); 132 | for (OnPageSelectedListener onPageSelectedListener : onPageSelectedListenerList){ 133 | onPageSelectedListener.onPageSelected(offsets); 134 | } 135 | } 136 | }); 137 | } 138 | 139 | public SlideAnimator setOnFinishListener(Runnable onFinishListener){ 140 | this.onFinishListener = onFinishListener; 141 | return this; 142 | } 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /src/com/mommoo/util/RXTextUtilities.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.util; 2 | 3 | import java.awt.*; 4 | import javax.swing.*; 5 | import javax.swing.text.*; 6 | 7 | /* 8 | * A collection of static methods that provide added functionality for 9 | * text components (most notably, JTextArea and JTextPane) 10 | * 11 | * See also: javax.swing.text.Utilities 12 | */ 13 | public class RXTextUtilities 14 | { 15 | /* 16 | * Attempt to center the line containing the caret at the center of the 17 | * scroll pane. 18 | * 19 | * @param component the text component in the sroll pane 20 | */ 21 | public static void centerLineInScrollPane(JTextComponent component) 22 | { 23 | Container container = SwingUtilities.getAncestorOfClass(JViewport.class, component); 24 | 25 | if (container == null) return; 26 | 27 | try 28 | { 29 | Rectangle r = component.modelToView(component.getCaretPosition()); 30 | JViewport viewport = (JViewport)container; 31 | int extentHeight = viewport.getExtentSize().height; 32 | int viewHeight = viewport.getViewSize().height; 33 | 34 | int y = Math.max(0, r.y - ((extentHeight - r.height) / 2)); 35 | y = Math.min(y, viewHeight - extentHeight); 36 | 37 | viewport.setViewPosition(new Point(0, y)); 38 | } 39 | catch(BadLocationException ble) {} 40 | } 41 | 42 | /* 43 | * Return the column number at the Caret position. 44 | * 45 | * The column returned will only make sense when using a 46 | * Monospaced font. 47 | */ 48 | public static int getColumnAtCaret(JTextComponent component) 49 | { 50 | // Since we assume a monospaced font we can use the width of a single 51 | // character to represent the width of each character 52 | 53 | FontMetrics fm = component.getFontMetrics( component.getFont() ); 54 | int characterWidth = fm.stringWidth( "0" ); 55 | int column = 0; 56 | 57 | try 58 | { 59 | Rectangle r = component.modelToView( component.getCaretPosition() ); 60 | int width = r.x - component.getInsets().left; 61 | column = width / characterWidth; 62 | } 63 | catch(BadLocationException ble) {} 64 | 65 | return column + 1; 66 | } 67 | 68 | /* 69 | * Return the line number at the Caret position. 70 | */ 71 | public static int getLineAtCaret(JTextComponent component) 72 | { 73 | int caretPosition = component.getCaretPosition(); 74 | Element root = component.getDocument().getDefaultRootElement(); 75 | 76 | return root.getElementIndex( caretPosition ) + 1; 77 | } 78 | 79 | /* 80 | * Return the number of lines of text in the Document 81 | */ 82 | public static int getLines(JTextComponent component) 83 | { 84 | Element root = component.getDocument().getDefaultRootElement(); 85 | return root.getElementCount(); 86 | } 87 | 88 | /* 89 | * Position the caret at the start of a line. 90 | */ 91 | public static void gotoStartOfLine(JTextComponent component, int line) 92 | { 93 | Element root = component.getDocument().getDefaultRootElement(); 94 | line = Math.max(line, 1); 95 | line = Math.min(line, root.getElementCount()); 96 | int startOfLineOffset = root.getElement( line - 1 ).getStartOffset(); 97 | component.setCaretPosition( startOfLineOffset ); 98 | } 99 | 100 | /* 101 | * Position the caret on the first word of a line. 102 | */ 103 | public static void gotoFirstWordOnLine(final JTextComponent component, int line) 104 | { 105 | gotoStartOfLine(component, line); 106 | 107 | // The following will position the caret at the start of the first word 108 | 109 | try 110 | { 111 | int position = component.getCaretPosition(); 112 | String first = component.getDocument().getText(position, 1); 113 | 114 | if (Character.isWhitespace(first.charAt(0))) 115 | { 116 | component.setCaretPosition(Utilities.getNextWord(component, position)); 117 | } 118 | } 119 | catch(Exception e) {} 120 | } 121 | 122 | /* 123 | * Return the number of lines of text, including wrapped lines. 124 | */ 125 | public static int getWrappedLines(JTextArea component) 126 | { 127 | View view = component.getUI().getRootView(component).getView(0); 128 | int preferredHeight = (int)view.getPreferredSpan(View.Y_AXIS); 129 | int lineHeight = component.getFontMetrics( component.getFont() ).getHeight(); 130 | return preferredHeight / lineHeight; 131 | } 132 | 133 | /* 134 | * Return the number of lines of text, including wrapped lines. 135 | */ 136 | public static int getWrappedLines(JTextComponent component) 137 | { 138 | int lines = 0; 139 | 140 | View view = component.getUI().getRootView(component).getView(0); 141 | 142 | int paragraphs = view.getViewCount(); 143 | 144 | for (int i = 0; i < paragraphs; i++) 145 | { 146 | lines += view.getView(i).getViewCount(); 147 | } 148 | 149 | return lines; 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/layout/linear/Example.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.layout.linear; 2 | 3 | import com.mommoo.flat.component.FlatPanel; 4 | import com.mommoo.flat.frame.FlatFrame; 5 | import com.mommoo.flat.image.FlatImagePanel; 6 | import com.mommoo.flat.image.ImageOption; 7 | import com.mommoo.flat.layout.linear.constraints.LinearConstraints; 8 | import com.mommoo.flat.layout.linear.constraints.LinearSpace; 9 | import com.mommoo.flat.text.label.FlatLabel; 10 | import com.mommoo.flat.text.textarea.alignment.FlatHorizontalAlignment; 11 | import com.mommoo.util.FontManager; 12 | import com.mommoo.util.ImageManager; 13 | import com.mommoo.util.ScreenManager; 14 | 15 | import javax.swing.*; 16 | import javax.swing.border.EmptyBorder; 17 | import java.awt.*; 18 | 19 | public class Example { 20 | 21 | public static void main(String[] args){ 22 | FlatFrame frame = new FlatFrame(); 23 | frame.setSize(500,500 + FlatFrame.getTitleBarHeight()); 24 | frame.setResizable(true); 25 | frame.setTitle("Flat layout test example"); 26 | frame.setLocationOnScreenCenter(); 27 | frame.getContainer().add(new LinearLayoutPanel4()); 28 | frame.show(); 29 | } 30 | 31 | private static class LinearLayoutPanel4 extends JPanel { 32 | private LinearLayoutPanel4() { 33 | setLayout(new LinearLayout(Orientation.VERTICAL, Alignment.CENTER)); 34 | add(new JButton("버튼")); 35 | add(new JButton("버튼")); 36 | add(new JButton("버튼")); 37 | } 38 | } 39 | 40 | private static class LinearLayoutPanel extends JPanel { 41 | private LinearLayout linearLayout; 42 | private LinearLayoutPanel(){ 43 | setBorder(BorderFactory.createEmptyBorder(20,20,20,20)); 44 | setLinearLayout(); 45 | addComponent(); 46 | } 47 | 48 | private void setLinearLayout(){ 49 | linearLayout = new LinearLayout(Orientation.VERTICAL, 1); 50 | setLayout(linearLayout); 51 | } 52 | 53 | private void addComponent(){ 54 | add(createColorRect(Color.RED, "FIRST"), new LinearConstraints().setWeight(349).setLinearSpace(LinearSpace.MATCH_PARENT)); 55 | add(createColorRect(Color.GREEN, "SECOND"), new LinearConstraints().setWeight(316).setLinearSpace(LinearSpace.MATCH_PARENT)); 56 | add(createColorRect(Color.YELLOW, "THIRD"), new LinearConstraints().setWeight(441).setLinearSpace(LinearSpace.MATCH_PARENT)); 57 | } 58 | } 59 | 60 | private static class LinearLayoutPanel2 extends JPanel{ 61 | private LinearLayoutPanel2(){ 62 | setBorder(BorderFactory.createEmptyBorder(20,20,20,20)); 63 | setLinearLayout(); 64 | LinearConstraints linearConstraints = new LinearConstraints(); 65 | add(createRowPanel(Color.RED, Color.WHITE, Color.BLUE), linearConstraints.setWeight(1).setLinearSpace(LinearSpace.MATCH_PARENT)); 66 | add(createRowPanel(Color.PINK, Color.GRAY, Color.YELLOW), linearConstraints.setWeight(1).setLinearSpace(LinearSpace.MATCH_PARENT)); 67 | add(createRowPanel(Color.GREEN, Color.ORANGE, Color.MAGENTA), linearConstraints.setWeight(1).setLinearSpace(LinearSpace.MATCH_PARENT)); 68 | } 69 | 70 | private void setLinearLayout(){ 71 | LinearLayout linearLayout = new LinearLayout(); 72 | linearLayout.setOrientation(Orientation.VERTICAL); 73 | linearLayout.setGap(15); 74 | setLayout(linearLayout); 75 | } 76 | 77 | private JPanel createRowPanel(Color color1, Color color2, Color color3){ 78 | JPanel panel = new JPanel(); 79 | panel.setLayout(new LinearLayout(15)); 80 | LinearConstraints linearConstraints = new LinearConstraints(); 81 | panel.add(createColorRect(color1,""), linearConstraints.setWeight(1).setLinearSpace(LinearSpace.MATCH_PARENT)); 82 | panel.add(createColorRect(color2,""), linearConstraints.setWeight(1).setLinearSpace(LinearSpace.MATCH_PARENT)); 83 | panel.add(createColorRect(color3,""), linearConstraints.setWeight(1).setLinearSpace(LinearSpace.MATCH_PARENT)); 84 | return panel; 85 | } 86 | } 87 | 88 | private static JComponent createColorRect(Color color, String text){ 89 | JLabel label = new JLabel(text,SwingConstants.CENTER); 90 | label.setOpaque(true); 91 | label.setFont(label.getFont().deriveFont(Font.BOLD, 40.0f)); 92 | label.setBackground(color); 93 | label.setPreferredSize(new Dimension(100,100)); 94 | return label; 95 | } 96 | 97 | private static class LinearLayoutPanel3 extends JPanel{ 98 | private LinearLayoutPanel3(){ 99 | Component comp = new FlatImagePanel(ImageManager.LION, ImageOption.MATCH_PARENT); 100 | comp.setPreferredSize(new Dimension(100,100)); 101 | setLayout(new LinearLayout(Orientation.VERTICAL, 30, Alignment.CENTER)); 102 | setBorder(new EmptyBorder(30,30,30,30)); 103 | add(createColorRect(Color.RED, "1"), new LinearConstraints(LinearSpace.WRAP_CENTER_CONTENT)); 104 | add(comp, new LinearConstraints(LinearSpace.WRAP_CENTER_CONTENT)); 105 | add(createColorRect(Color.BLUE, "2"), new LinearConstraints(LinearSpace.WRAP_CENTER_CONTENT)); 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/text/textarea/FlatWrapEditorKit.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.text.textarea; 2 | 3 | import javax.swing.text.*; 4 | 5 | class FlatWrapEditorKit extends StyledEditorKit { 6 | private ViewFactory defaultFactory = new WrapColumnFactory(); 7 | private EditorListener editorListener; 8 | 9 | public ViewFactory getViewFactory() { 10 | return defaultFactory; 11 | } 12 | 13 | FlatWrapEditorKit(EditorListener editorListener) { 14 | this.editorListener = editorListener; 15 | } 16 | 17 | 18 | private class WrapColumnFactory implements ViewFactory { 19 | public View create(Element elem) { 20 | if (elem.getName() == null) { 21 | return new LabelView(elem); 22 | } 23 | 24 | switch (elem.getName()) { 25 | case AbstractDocument.ContentElementName: 26 | return new WrapLabelView(elem); 27 | 28 | case AbstractDocument.ParagraphElementName: 29 | return new NoWrapParagraphView(elem); 30 | 31 | case AbstractDocument.SectionElementName: 32 | return new CenteredBoxView(elem, View.Y_AXIS); 33 | 34 | case StyleConstants.ComponentElementName: 35 | return new ComponentView(elem); 36 | 37 | case StyleConstants.IconElementName: 38 | return new IconView(elem); 39 | 40 | default: 41 | return new LabelView(elem); 42 | } 43 | } 44 | } 45 | 46 | private class WrapLabelView extends LabelView { 47 | private WrapLabelView(Element elem) { 48 | super(elem); 49 | } 50 | 51 | @Override 52 | public View breakView(int axis, int p0, float pos, float len) { 53 | if (editorListener.isWrapStyleWord()) { 54 | return super.breakView(axis, p0, pos, len); 55 | } else { 56 | if (axis == View.X_AXIS) { 57 | checkPainter(); 58 | int p1 = getGlyphPainter().getBoundedPosition(this, p0, pos, len); 59 | 60 | if (p0 == getStartOffset() && p1 == getEndOffset()) { 61 | 62 | return this; 63 | } 64 | 65 | return createFragment(p0, p1); 66 | } 67 | return this; 68 | } 69 | } 70 | 71 | @Override 72 | public int getBreakWeight(int axis, float pos, float len) { 73 | if (editorListener.isWrapStyleWord()) { 74 | return super.getBreakWeight(axis, pos, len); 75 | } else { 76 | if (axis == View.X_AXIS) { 77 | checkPainter(); 78 | int p0 = getStartOffset(); 79 | int p1 = getGlyphPainter().getBoundedPosition(this, p0, pos, len); 80 | 81 | if (p1 == p0) { 82 | return View.BadBreakWeight; 83 | } 84 | return View.GoodBreakWeight; 85 | } 86 | return View.GoodBreakWeight; 87 | } 88 | 89 | 90 | } 91 | 92 | @Override 93 | public float getMinimumSpan(int axis) { 94 | if (editorListener.isLineWrap()) { 95 | switch (axis) { 96 | case View.X_AXIS: 97 | return 0f; 98 | case View.Y_AXIS: 99 | return super.getMinimumSpan(axis); 100 | default: 101 | throw new IllegalArgumentException("Invalid axis: " + axis); 102 | } 103 | } else { 104 | return super.getMinimumSpan(axis); 105 | } 106 | 107 | } 108 | } 109 | 110 | private class CenteredBoxView extends BoxView { 111 | private CenteredBoxView(Element elem, int axis) { 112 | super(elem, axis); 113 | } 114 | 115 | @Override 116 | protected void layoutMajorAxis(int targetSpan, int axis, int[] offsets, int[] spans) { 117 | super.layoutMajorAxis(targetSpan, axis, offsets, spans); 118 | int offset = 0; 119 | switch (editorListener.getVerticalAlignment()) { 120 | case TOP: 121 | return; 122 | 123 | case CENTER: 124 | offset = (editorListener.getViewHeight() - editorListener.getContentsHeight()) / 2; 125 | break; 126 | 127 | case BOTTOM: 128 | offset = (editorListener.getViewHeight() - editorListener.getContentsHeight()); 129 | break; 130 | } 131 | 132 | for (int i = 0; i < offsets.length; i++) { 133 | offsets[i] += offset; 134 | } 135 | } 136 | } 137 | 138 | private class NoWrapParagraphView extends ParagraphView { 139 | private NoWrapParagraphView(Element elem) { 140 | super(elem); 141 | } 142 | 143 | @Override 144 | public float getMinimumSpan(int axis) { 145 | if (editorListener.isLineWrap()) { 146 | return super.getMinimumSpan(axis); 147 | } else return super.getPreferredSpan(axis); 148 | } 149 | } 150 | } 151 | 152 | 153 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/frame/CommonTitleBar.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.frame; 2 | 3 | import com.mommoo.animation.AnimationAdapter; 4 | import com.mommoo.animation.Animator; 5 | import com.mommoo.animation.timeInterpolator.AccelerateInterpolator; 6 | import com.mommoo.flat.component.FlatPanel; 7 | import com.mommoo.flat.component.OnClickListener; 8 | import com.mommoo.flat.frame.titlebar.TitleLabel; 9 | import com.mommoo.flat.frame.titlebar.navigation.controller.NavigationControlPanel; 10 | import com.mommoo.flat.frame.titlebar.navigation.listener.NavigationControlListener; 11 | import com.mommoo.flat.image.FlatImagePanel; 12 | import com.mommoo.flat.image.ImageOption; 13 | import com.mommoo.flat.layout.linear.LinearLayout; 14 | import com.mommoo.flat.layout.linear.constraints.LinearConstraints; 15 | import com.mommoo.flat.layout.linear.constraints.LinearSpace; 16 | import com.mommoo.util.CursorType; 17 | import com.mommoo.util.ImageManager; 18 | 19 | import javax.swing.*; 20 | import java.awt.*; 21 | import java.util.List; 22 | 23 | class CommonTitleBar extends FlatPanel { 24 | private static final int TITLE_BAR_HEIGHT = 50; 25 | private static final int TITLE_BAR_SIDE_PADDING = 10; 26 | private static final int TITLE_TEXT_FONT_SIZE = TITLE_BAR_HEIGHT/3; 27 | 28 | private final TitleLabel TITLE_LABEL = new TitleLabel(TITLE_TEXT_FONT_SIZE); 29 | private final NavigationControlPanel controlPanel = new NavigationControlPanel(3*TITLE_BAR_HEIGHT/5); 30 | 31 | private FlatImagePanel mainIcon = createMainIcon(); 32 | 33 | CommonTitleBar() { 34 | setLayout(new LinearLayout(15)); 35 | setBorder(BorderFactory.createEmptyBorder(0, TITLE_BAR_SIDE_PADDING,0,TITLE_BAR_SIDE_PADDING)); 36 | setOpaque(true); 37 | setBackground(Color.LIGHT_GRAY); 38 | add(TITLE_LABEL, new LinearConstraints().setWeight(1).setLinearSpace(LinearSpace.MATCH_PARENT)); 39 | add(controlPanel, new LinearConstraints().setLinearSpace(LinearSpace.WRAP_CENTER_CONTENT)); 40 | } 41 | 42 | public static void main(String[] args){ 43 | SwingUtilities.invokeLater(()->{ 44 | FlatFrame f = new FlatFrame(); 45 | f.setSize(300,300); 46 | f.setProcessIconImage(ImageManager.TEST); 47 | f.setEnableSizeButton(true); 48 | f.setShadowWidth(20); 49 | f.setResizable(true); 50 | f.setTitle("A Beautiful Frame. You can customizing you want!"); 51 | f.setLocationOnScreenCenter(); 52 | f.show(); 53 | }); 54 | } 55 | 56 | private FlatImagePanel createMainIcon(){ 57 | Dimension mainIconDimen = new Dimension(3*TITLE_BAR_HEIGHT/5, 3*TITLE_BAR_HEIGHT/5); 58 | FlatImagePanel mainIcon = new FlatImagePanel(); 59 | mainIcon.setPreferredSize(mainIconDimen); 60 | return mainIcon; 61 | } 62 | 63 | void setTitle(String title){ 64 | TITLE_LABEL.setText(title); 65 | } 66 | 67 | String getTitle(){ 68 | return TITLE_LABEL.getText(); 69 | } 70 | 71 | void removeIconImage(){ 72 | if (isComponentContained(mainIcon)) remove(mainIcon); 73 | } 74 | 75 | @Override 76 | public void setBackground(Color color){ 77 | super.setBackground(color); 78 | if (mainIcon != null) mainIcon.setBackground(color); 79 | if (controlPanel != null) controlPanel.setButtonColor(color); 80 | } 81 | 82 | void setButtonIconColor(Color color){ 83 | controlPanel.setButtonIconColor(color); 84 | } 85 | 86 | Color getButtonIconColor(){ 87 | return controlPanel.getButtonIconColor(); 88 | } 89 | 90 | void setTitleColor(Color color){ 91 | TITLE_LABEL.setForeground(color); 92 | } 93 | 94 | Color getTitleColor(){ 95 | return TITLE_LABEL.getForeground(); 96 | } 97 | 98 | Font getTitleFont(){ 99 | return TITLE_LABEL.getFont(); 100 | } 101 | 102 | void setTitleFont(Font font) { 103 | TITLE_LABEL.setFont(font); 104 | } 105 | 106 | void removeControlPanel(){ 107 | remove(controlPanel); 108 | } 109 | 110 | void setControlListener(NavigationControlListener controlListener){ 111 | controlPanel.setOnControlListener(controlListener); 112 | } 113 | 114 | @Override 115 | public Dimension getPreferredSize() { 116 | return new Dimension(super.getPreferredSize().width , TITLE_BAR_HEIGHT); 117 | } 118 | 119 | @Override 120 | public Dimension getMinimumSize() { 121 | return getPreferredSize(); 122 | } 123 | 124 | @Override 125 | public Dimension getMaximumSize() { 126 | return getPreferredSize(); 127 | } 128 | 129 | public static int getTitleBarHeight(){ 130 | return TITLE_BAR_HEIGHT; 131 | } 132 | 133 | void setIconImage(Image image){ 134 | mainIcon.setImage(image, ImageOption.MATCH_PARENT); 135 | 136 | if (isComponentContained(mainIcon)){ 137 | mainIcon.revalidate(); 138 | mainIcon.repaint(); 139 | }else { 140 | add(mainIcon, new LinearConstraints().setLinearSpace(LinearSpace.WRAP_CENTER_CONTENT), 0); 141 | } 142 | } 143 | 144 | void removeOnIconClickListener(){ 145 | mainIcon.setCursor(CursorType.DEFAULT.getCursor()); 146 | mainIcon.removeOnClickListener(); 147 | } 148 | 149 | OnClickListener getOnIconClickListener(){ 150 | return mainIcon.getOnClickListener(); 151 | } 152 | 153 | void setOnIconClickListener(OnClickListener onIconClickListener){ 154 | mainIcon.setCursor(CursorType.HAND.getCursor()); 155 | mainIcon.setOnClickListener(onIconClickListener); 156 | } 157 | 158 | Color getIconBackgroundColor(){ 159 | return mainIcon.getBackground(); 160 | } 161 | 162 | void setIconBackgroundColor(Color backgroundColor){ 163 | mainIcon.setOpaque(true); 164 | mainIcon.setBackground(backgroundColor); 165 | } 166 | } -------------------------------------------------------------------------------- /src/com/mommoo/flat/frame/colorpicker/HSB_View.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.frame.colorpicker; 2 | 3 | import com.mommoo.flat.component.FlatMouseAdapter; 4 | 5 | import javax.swing.*; 6 | import javax.swing.border.LineBorder; 7 | import java.awt.*; 8 | import java.awt.event.MouseAdapter; 9 | import java.awt.event.MouseEvent; 10 | import java.awt.geom.Rectangle2D; 11 | import java.awt.image.BufferedImage; 12 | import java.util.function.Consumer; 13 | 14 | import static com.mommoo.flat.utils.FlatColor.convertHSBtoRGB; 15 | 16 | public class HSB_View extends JPanel { 17 | private static final Cursor HAND_CURSOR = new Cursor(Cursor.HAND_CURSOR); 18 | private static final BasicStroke STROKE = new BasicStroke(1.5f); 19 | private BufferedImage cacheImage; 20 | 21 | private HSB hsb = new HSB(0, 0, 0); 22 | 23 | private boolean needToDraw; 24 | private boolean isAutoPoint; 25 | private boolean once; 26 | 27 | private float mouseX, mouseY; 28 | 29 | private Consumer onHSBChangeListener = hsb -> { }; 30 | 31 | public HSB_View() { 32 | setBorder(new LineBorder(Color.BLACK, 1)); 33 | setOpaque(false); 34 | setCursor(HAND_CURSOR); 35 | MouseAdapter mouseEventHandler = new HSB_RectMouseEvent(); 36 | addMouseListener(mouseEventHandler); 37 | addMouseMotionListener(mouseEventHandler); 38 | } 39 | 40 | @Override 41 | public void paint(Graphics g) { 42 | super.paint(g); 43 | final Graphics2D G_2D = (Graphics2D) g; 44 | final int SIZE = Math.min(getWidth(), getHeight()); 45 | final int RADIUS = Math.max(2, SIZE / 30); 46 | 47 | boolean isNeedToReDraw = needToDraw || cacheImage == null || cacheImage.getWidth() != SIZE; 48 | 49 | drawHsbRect(isNeedToReDraw, G_2D, SIZE); 50 | needToDraw = false; 51 | 52 | G_2D.setStroke(STROKE); 53 | 54 | float mouseX = Math.min(SIZE, Math.max(0, this.mouseX)); 55 | float mouseY = Math.min(SIZE, Math.max(0, this.mouseY)); 56 | 57 | if (isAutoPoint){ 58 | mouseX = (hsb.getSaturation() * SIZE ) / 100f; 59 | mouseY = ((100 - hsb.getBrightness()) * SIZE)/100f; 60 | this.mouseX = mouseX; 61 | this.mouseY = mouseY; 62 | isAutoPoint = false; 63 | } 64 | 65 | /* Decide mouse circle pointer color */ 66 | G_2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 67 | G_2D.setColor(hsb.getBrightness() <= 40 ? Color.WHITE : Color.BLACK); 68 | 69 | /* Draw mouse area and Draw mouse point using circle*/ 70 | G_2D.drawOval(Math.round(mouseX - RADIUS), Math.round(mouseY - RADIUS), RADIUS * 2, RADIUS * 2); 71 | 72 | 73 | /* Data changed by user manipulation are setting*/ 74 | int saturation = Math.min((int) (mouseX * 100 / SIZE), 100); 75 | int brightness = Math.max(100 - (int) (mouseY * 100 / SIZE), 0); 76 | hsb = new HSB(hsb.getHue(), saturation, brightness); 77 | 78 | if (!once){ 79 | once = true; 80 | } else { 81 | onHSBChangeListener.accept(hsb); 82 | } 83 | } 84 | 85 | public void setOnHSBChangeListener(Consumer onHSBChangeListener) { 86 | this.onHSBChangeListener = onHSBChangeListener; 87 | } 88 | 89 | private void drawHsbRect(boolean reDraw, Graphics2D graphics2D, int size) { 90 | 91 | if (reDraw) { 92 | cacheImage = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB); 93 | Graphics2D graphics = (Graphics2D) cacheImage.getGraphics(); 94 | 95 | Rectangle2D.Double RECT = new Rectangle.Double(); 96 | for (int row = 0; row < size; row++) { 97 | for (int col = 0; col < size; col++) { 98 | float s = col * 100f / size; 99 | float b = 100f - (row * 100f / size); 100 | graphics.setColor(convertHSBtoRGB(hsb.getHue(), s, b)); 101 | RECT.setRect(col, row, 1, 1); 102 | graphics.fill(RECT); 103 | } 104 | } 105 | 106 | graphics.dispose(); 107 | } 108 | 109 | graphics2D.drawImage(cacheImage, 0, 0, null); 110 | } 111 | 112 | public void setHue(int hue) { 113 | if (hsb.getHue() != hue){ 114 | this.hsb = this.hsb.changeHue(hue); 115 | needToDraw = true; 116 | repaint(); 117 | } 118 | 119 | } 120 | 121 | public void setHSB(HSB hsb){ 122 | this.hsb = hsb; 123 | needToDraw = true; 124 | isAutoPoint = true; 125 | repaint(); 126 | } 127 | 128 | 129 | @Override 130 | public String toString() { 131 | return "HSB_View"; 132 | } 133 | 134 | private class HSB_RectMouseEvent extends FlatMouseAdapter { 135 | 136 | @Override 137 | public void mousePressed(MouseEvent e) { 138 | super.mousePressed(e); 139 | mouseX = e.getX(); 140 | mouseY = e.getY(); 141 | repaint(); 142 | } 143 | 144 | @Override 145 | public void mouseDragged(MouseEvent e) { 146 | super.mouseDragged(e); 147 | if (isMousePressed()) { 148 | mouseX = e.getX(); 149 | mouseY = e.getY(); 150 | repaint(); 151 | } 152 | } 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/image/FlatImagePanel.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.image; 2 | 3 | import com.mommoo.example.ExampleFactory; 4 | import com.mommoo.flat.component.FlatPanel; 5 | 6 | import javax.swing.*; 7 | import java.awt.*; 8 | 9 | /** 10 | * Created by mommoo on 2017-07-09. 11 | */ 12 | public class FlatImagePanel extends FlatPanel { 13 | private Image image; 14 | private Image resizedImage; 15 | private ImageOption option = ImageOption.BASIC_IMAGE_SIZE; 16 | private ImageAlignment horizontalAlignment = ImageAlignment.START; 17 | private ImageAlignment verticalAlignment = ImageAlignment.START; 18 | 19 | private MediaTracker mediaTracker = new MediaTracker(this); 20 | 21 | private boolean reDraw = true; 22 | 23 | public FlatImagePanel() { } 24 | 25 | public FlatImagePanel(Image image) { 26 | setImage(image, ImageOption.BASIC_IMAGE_SIZE); 27 | } 28 | 29 | public FlatImagePanel(Image image, ImageOption option) { 30 | setImage(image, option); 31 | } 32 | 33 | public static void main(String[] args) { 34 | ExampleFactory.FlatImagePanelExample.example3(); 35 | } 36 | 37 | public FlatImagePanel setImage(Image image, ImageOption option) { 38 | this.image = image; 39 | this.option = option; 40 | reDraw(); 41 | return this; 42 | } 43 | 44 | public Image getImage() { 45 | return image; 46 | } 47 | 48 | public FlatImagePanel setImage(Image image) { 49 | this.image = image; 50 | reDraw(); 51 | return this; 52 | } 53 | 54 | public void reDraw() { 55 | reDraw = true; 56 | repaint(); 57 | } 58 | 59 | public void setHorizontalAlignment(ImageAlignment horizontalAlignment) { 60 | this.horizontalAlignment = horizontalAlignment; 61 | repaint(); 62 | } 63 | 64 | public void setVerticalAlignment(ImageAlignment verticalAlignment) { 65 | this.verticalAlignment = verticalAlignment; 66 | repaint(); 67 | } 68 | 69 | @Override 70 | protected boolean isPaintingOrigin() { 71 | return true; 72 | } 73 | 74 | @Override 75 | public void paint(Graphics g) { 76 | super.paint(g); 77 | 78 | if (image == null) return; 79 | 80 | Graphics2D g2d = (Graphics2D) g; 81 | g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 82 | g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); 83 | 84 | Insets insets = getInsets(); 85 | 86 | Image image = this.image; 87 | 88 | int availableWidth = getWidth() - insets.left - insets.right; 89 | int availableHeight = getHeight() - insets.top - insets.bottom; 90 | 91 | if (option == ImageOption.BASIC_IMAGE_SIZE) { 92 | 93 | } else { 94 | 95 | int resizedWidth = 0; 96 | int resizedHeight = 0; 97 | 98 | if (option == ImageOption.MATCH_PARENT) { 99 | 100 | resizedWidth = availableWidth; 101 | resizedHeight = availableHeight; 102 | 103 | } else if (option == ImageOption.MATCH_WIDTH_KEEP_RATIO) { 104 | 105 | resizedWidth = availableWidth; 106 | resizedHeight = -1; 107 | 108 | } else if (option == ImageOption.MATCH_HEIGHT_KEEP_RATIO) { 109 | 110 | resizedWidth = -1; 111 | resizedHeight = availableHeight; 112 | 113 | } 114 | 115 | if (reDraw) { 116 | resizedImage = getSyncScaledImage(this.image, resizedWidth, resizedHeight); 117 | reDraw = false; 118 | } 119 | 120 | image = resizedImage; 121 | } 122 | 123 | int imageX = insets.left; 124 | int imageY = insets.top; 125 | 126 | Dimension imageDimension = getImageDimension(image); 127 | 128 | switch(horizontalAlignment) { 129 | case CENTER: 130 | imageX += ( availableWidth - imageDimension.width) / 2; 131 | break; 132 | 133 | case END: 134 | imageX += availableWidth - imageDimension.width; 135 | break; 136 | } 137 | 138 | switch(verticalAlignment) { 139 | case CENTER: 140 | imageY += ( availableHeight - imageDimension.height ) / 2; 141 | break; 142 | 143 | case END: 144 | imageY += availableHeight - imageDimension.height; 145 | } 146 | 147 | g2d.clipRect(insets.left, insets.top, availableWidth, availableHeight); 148 | g2d.drawImage(image, imageX, imageY, null); 149 | } 150 | 151 | private Image getSyncScaledImage(Image image, int width, int height) { 152 | Image resizedImage = image.getScaledInstance(width, height, Image.SCALE_SMOOTH); 153 | mediaTracker.addImage(resizedImage, 0); 154 | 155 | try { 156 | mediaTracker.waitForID(0); 157 | } catch (InterruptedException e) { 158 | e.printStackTrace(); 159 | } 160 | 161 | mediaTracker.removeImage(resizedImage); 162 | return resizedImage; 163 | } 164 | 165 | private Dimension getImageDimension(Image image) { 166 | ImageIcon imageIcon = new ImageIcon(image); 167 | return new Dimension(imageIcon.getIconWidth(), imageIcon.getIconHeight()); 168 | } 169 | } 170 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/frame/titlebar/navigation/listener/MouseFocusAnimationListener.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.frame.titlebar.navigation.listener; 2 | 3 | import java.awt.*; 4 | import java.awt.event.MouseAdapter; 5 | import java.awt.event.MouseEvent; 6 | 7 | public class MouseFocusAnimationListener extends MouseAdapter{ 8 | private static final int FOCUS_GAIN_ANIMATION_TIME = 200; 9 | private static final int FOCUS_LOST_ANIMATION_TIME = 100; 10 | 11 | private Color focusGainColor, focusLostColor; 12 | private BackgroundAnimWorker focusGainWorker, focusLostWorker; 13 | 14 | private boolean isMouseExited; 15 | 16 | private FocusGainListener focusGainListener = ()->{}; 17 | 18 | public MouseFocusAnimationListener(Component targetComponent, Color focusGainColor, Color focusLostColor){ 19 | focusGainWorker = new BackgroundAnimWorker(targetComponent, FOCUS_GAIN_ANIMATION_TIME); 20 | focusLostWorker = new BackgroundAnimWorker(targetComponent, FOCUS_LOST_ANIMATION_TIME); 21 | setFocusAnimColor(focusGainColor, focusLostColor); 22 | } 23 | 24 | private void createColorCacheArray(float[] focusGainColorRGB, float[] focusLostColorRGB){ 25 | float subR = focusGainColorRGB[0] - focusLostColorRGB[0]; 26 | float subG = focusGainColorRGB[1] - focusLostColorRGB[1]; 27 | float subB = focusGainColorRGB[2] - focusLostColorRGB[2]; 28 | 29 | Color[] focusGainColorArray = new Color[100]; 30 | Color[] focusLostColorArray = new Color[100]; 31 | 32 | for (int i = 0 ; i <100 ; i++){ 33 | focusGainColorArray[i] = new Color(focusGainColorRGB[0], focusGainColorRGB[1], focusGainColorRGB[2],0.01f * i); 34 | int ratio = 100 - i ; 35 | focusLostColorArray[i] = new Color( 36 | focusGainColorRGB[0] - (subR/ratio), 37 | focusGainColorRGB[1] - (subG/ratio), 38 | focusGainColorRGB[2] - (subB/ratio)); 39 | } 40 | 41 | focusGainWorker.setColorCacheArray(focusGainColorArray); 42 | focusLostWorker.setColorCacheArray(focusLostColorArray); 43 | } 44 | 45 | public void setFocusAnimColor(Color focusGainColor, Color focusLostColor){ 46 | this.focusGainColor = focusGainColor; 47 | this.focusLostColor = focusLostColor; 48 | 49 | float[] focusGainColorRGB = new float[3]; 50 | float[] focusLostColorRGB = new float[3]; 51 | 52 | focusGainColor.getRGBColorComponents(focusGainColorRGB); 53 | focusLostColor.getRGBColorComponents(focusLostColorRGB); 54 | 55 | createColorCacheArray(focusGainColorRGB, focusLostColorRGB); 56 | } 57 | 58 | public void setFocusGainListener(FocusGainListener focusGainListener){ 59 | this.focusGainListener = focusGainListener; 60 | } 61 | 62 | public void setFocusLostListener(FocusLostListener focusLostListener){ 63 | this.focusLostWorker.setCallback(focusLostListener::lost); 64 | } 65 | 66 | @Override 67 | public void mousePressed(MouseEvent e) { 68 | super.mousePressed(e); 69 | e.getComponent().setBackground(focusGainColor.darker()); 70 | } 71 | 72 | @Override 73 | public void mouseReleased(MouseEvent e) { 74 | super.mouseReleased(e); 75 | if (!isMouseExited) e.getComponent().setBackground(focusLostColor.darker()); 76 | } 77 | 78 | @Override 79 | public void mouseEntered(MouseEvent e) { 80 | super.mouseEntered(e); 81 | isMouseExited = false; 82 | focusGainListener.gain(); 83 | focusLostWorker.stop(); 84 | focusGainWorker.start(); 85 | } 86 | 87 | @Override 88 | public void mouseExited(MouseEvent e) { 89 | super.mouseExited(e); 90 | isMouseExited = true; 91 | focusGainWorker.stop(); 92 | focusLostWorker.start(); 93 | } 94 | 95 | private class BackgroundAnimWorker{ 96 | private Component targetComponent; 97 | private int animationDuration; 98 | private Color[] colorCacheArray; 99 | private boolean workerStop; 100 | private Runnable callback = ()->{}; 101 | 102 | private BackgroundAnimWorker(Component targetComponent, int animationDuration){ 103 | this.targetComponent = targetComponent; 104 | this.animationDuration = animationDuration; 105 | } 106 | 107 | private void setColorCacheArray(Color[] colorCacheArray){ 108 | this.colorCacheArray = colorCacheArray; 109 | } 110 | 111 | private void setCallback(Runnable callback){ 112 | this.callback = callback; 113 | } 114 | 115 | private void start(){ 116 | workerStop = false; 117 | 118 | final int COLOR_RANGE = colorCacheArray.length; 119 | 120 | new Thread(()->{ 121 | 122 | for (Color color : colorCacheArray){ 123 | 124 | if (workerStop) break; 125 | 126 | threadSleep(animationDuration /COLOR_RANGE); 127 | 128 | targetComponent.setBackground(color); 129 | } 130 | 131 | this.callback.run(); 132 | }).start(); 133 | } 134 | 135 | private void stop(){ 136 | workerStop = true; 137 | } 138 | 139 | private void threadSleep(int sleepMilliTime){ 140 | try { 141 | Thread.sleep(sleepMilliTime); 142 | } catch (InterruptedException e) {} 143 | } 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/frame/colorpicker/ColorInfoView.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.frame.colorpicker; 2 | 3 | import com.mommoo.flat.component.FlatPanel; 4 | import com.mommoo.flat.layout.linear.LinearLayout; 5 | import com.mommoo.flat.layout.linear.Orientation; 6 | import com.mommoo.flat.layout.linear.constraints.LinearConstraints; 7 | import com.mommoo.flat.layout.linear.constraints.LinearSpace; 8 | import com.mommoo.flat.text.label.FlatLabel; 9 | import com.mommoo.flat.text.textarea.alignment.FlatHorizontalAlignment; 10 | import com.mommoo.flat.text.textarea.alignment.FlatVerticalAlignment; 11 | import com.mommoo.util.ComputableDimension; 12 | import com.mommoo.util.FontManager; 13 | import com.mommoo.util.ScreenManager; 14 | 15 | import javax.swing.*; 16 | import javax.swing.border.LineBorder; 17 | import java.awt.*; 18 | 19 | public class ColorInfoView extends FlatPanel { 20 | private static final ScreenManager SCREEN = ScreenManager.getInstance(); 21 | private static final Font GUIDE_FONT = FontManager.getNanumGothicBoldFont(SCREEN.dip2px(10)); 22 | 23 | public ColorInfoView() { 24 | setLayout(new LinearLayout(Orientation.VERTICAL, 0)); 25 | add(new GuideView("information"), new LinearConstraints(LinearSpace.MATCH_PARENT)); 26 | add(new HSB_InfoView(), new LinearConstraints(1, LinearSpace.MATCH_PARENT), "hsbView"); 27 | } 28 | 29 | 30 | public void setHSB(HSB hsb){ 31 | ((HSB_InfoView)getComponent("hsbView")).setHSB(hsb); 32 | } 33 | 34 | 35 | private class HSB_InfoView extends FlatPanel { 36 | private HSB_InfoView(){ 37 | setLayout(new LinearLayout(Orientation.HORIZONTAL, 0)); 38 | add(createColorView()); 39 | add(createInfoView(), new LinearConstraints(1, LinearSpace.MATCH_PARENT)); 40 | } 41 | 42 | private Component createColorView(){ 43 | JPanel colorView = new JPanel(); 44 | colorView.setBorder(new LineBorder(Color.BLACK, 1)); 45 | colorView.setOpaque(true); 46 | colorView.setBackground(Color.RED); 47 | 48 | setOnLayoutListener((availableWidth, availableHeight) -> { 49 | int size = Math.min(availableWidth, availableHeight); 50 | colorView.setPreferredSize(new ComputableDimension(size)); 51 | doLayout(); 52 | removeOnLayoutListener(); 53 | }); 54 | 55 | return colorView; 56 | } 57 | 58 | private Component createInfoView(){ 59 | FlatPanel infoView = new FlatPanel(new LinearLayout(Orientation.VERTICAL, 0)); 60 | infoView.add(new LineView("H","S","B"), new LinearConstraints(1, LinearSpace.MATCH_PARENT)); 61 | infoView.add(new LineView("R","G","B"), new LinearConstraints(1, LinearSpace.MATCH_PARENT)); 62 | return infoView; 63 | } 64 | 65 | private void setHSB(HSB hsb){ 66 | Component colorView = getComponent(0); 67 | colorView.setBackground(hsb.getColor()); 68 | 69 | JPanel infoView = (JPanel)getComponent(1); 70 | 71 | LineView HSB_View = (LineView) infoView.getComponent(0); 72 | HSB_View.setValue(0, Integer.toString(hsb.getHue())); 73 | HSB_View.setValue(1, Integer.toString(hsb.getSaturation())); 74 | HSB_View.setValue(2, Integer.toString(hsb.getBrightness())); 75 | 76 | LineView RGB_View = (LineView) infoView.getComponent(1); 77 | RGB_View.setValue(0, Integer.toString(hsb.getColor().getRed())); 78 | RGB_View.setValue(1, Integer.toString(hsb.getColor().getGreen())); 79 | RGB_View.setValue(2, Integer.toString(hsb.getColor().getBlue())); 80 | } 81 | 82 | private class LineView extends FlatPanel{ 83 | private LineView(String... guideTexts){ 84 | setLayout(new LinearLayout(0)); 85 | for (String guideText : guideTexts){ 86 | add(new GuideLabel(guideText), new LinearConstraints(1, LinearSpace.MATCH_PARENT)); 87 | } 88 | } 89 | 90 | private void setValue(int index, String valueText){ 91 | ((GuideLabel)getComponent(index)).setValue(valueText); 92 | } 93 | } 94 | 95 | private class GuideLabel extends JPanel { 96 | private GuideLabel(String guideText){ 97 | setLayout(new LinearLayout(0)); 98 | add(createGuideLabel(guideText), new LinearConstraints(1, LinearSpace.MATCH_PARENT)); 99 | add(createCommonLabel(), new LinearConstraints(1, LinearSpace.MATCH_PARENT)); 100 | } 101 | 102 | private FlatLabel createCommonLabel(){ 103 | FlatLabel flatLabel = new FlatLabel(); 104 | flatLabel.setText("g"); 105 | flatLabel.setHorizontalAlignment(FlatHorizontalAlignment.CENTER); 106 | flatLabel.setVerticalAlignment(FlatVerticalAlignment.CENTER); 107 | return flatLabel; 108 | } 109 | 110 | private Component createGuideLabel(String guideText){ 111 | FlatLabel guideLabel = createCommonLabel(); 112 | guideLabel.setText(guideText); 113 | guideLabel.setFont(GUIDE_FONT); 114 | return guideLabel; 115 | } 116 | 117 | private void setValue(String value){ 118 | ((FlatLabel)getComponent(1)).setText(value); 119 | } 120 | } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/component/pager/FlatTabPanel.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.component.pager; 2 | 3 | import com.mommoo.flat.border.FlatEmptyBorder; 4 | import com.mommoo.flat.component.FlatPanel; 5 | import com.mommoo.flat.layout.linear.Alignment; 6 | import com.mommoo.flat.layout.linear.LinearLayout; 7 | import com.mommoo.flat.layout.linear.constraints.LinearConstraints; 8 | import com.mommoo.flat.layout.linear.constraints.LinearSpace; 9 | import com.mommoo.flat.text.label.FlatLabel; 10 | import com.mommoo.util.FontManager; 11 | import com.mommoo.util.ScreenManager; 12 | 13 | import javax.swing.border.Border; 14 | import java.awt.*; 15 | 16 | class FlatTabPanel extends FlatPanel { 17 | private static final ScreenManager SCREEN = ScreenManager.getInstance(); 18 | private FlatPageColor flatPageColor = FlatPageColor.getDefaultFlatPagerColor(); 19 | private int offset = 0; 20 | 21 | FlatTabPanel(){ 22 | setLayout(new LinearLayout(SCREEN.dip2px(2))); 23 | setOnLayoutListener(((availableWidth, availableHeight) -> { 24 | if (getComponentCount() > 0){ 25 | ((FlatTabView)getComponent(offset)).focusIn(); 26 | removeOnLayoutListener(); 27 | } 28 | })); 29 | } 30 | 31 | void setFlatPageColor(FlatPageColor pagerColor){ 32 | this.flatPageColor = pagerColor; 33 | for (Component comp : getComponents()){ 34 | FlatTabView tabView = (FlatTabView)comp; 35 | tabView.setFlatPageColor(pagerColor); 36 | tabView.validateFocus(); 37 | } 38 | } 39 | 40 | void addTab(String tabText, OnTabClickListener onTabClickListener){ 41 | add(createTabView(tabText, onTabClickListener), new LinearConstraints(LinearSpace.MATCH_PARENT)); 42 | } 43 | 44 | private FlatTabView createTabView(String tabText, OnTabClickListener onTabClickListener){ 45 | final int index = getComponentCount(); 46 | 47 | FlatTabView tabView = new FlatTabView(tabText); 48 | tabView.setFlatPageColor(flatPageColor); 49 | tabView.setOnClickListener(component -> { 50 | focusOutAll(); 51 | tabView.focusIn(); 52 | onTabClickListener.onTabClick(index); 53 | }); 54 | 55 | return tabView; 56 | } 57 | 58 | int getTabIndex(String tabText){ 59 | for (int i = 0, size = getComponentCount(); i < size ; i ++){ 60 | if (getTabText(i).equals(tabText)){ 61 | return i; 62 | } 63 | } 64 | 65 | return -1; 66 | } 67 | 68 | String getTabText(int index){ 69 | return ((FlatTabView) getComponent(index)).getText(); 70 | } 71 | 72 | void removeTab(int index){ 73 | remove(index); 74 | } 75 | 76 | void setTabAlignment(FlatTabAlignment alignment){ 77 | LinearLayout linearLayout = (LinearLayout) getLayout(); 78 | switch(alignment){ 79 | case START : 80 | linearLayout.setAlignment(Alignment.START); 81 | break; 82 | case CENTER : 83 | linearLayout.setAlignment(Alignment.CENTER); 84 | break; 85 | case END : 86 | linearLayout.setAlignment(Alignment.END); 87 | break; 88 | } 89 | 90 | doLayout(); 91 | } 92 | 93 | void focusIn(int index){ 94 | focusOutAll(); 95 | ((FlatTabView)getComponent(index)).focusIn(); 96 | } 97 | 98 | void setOffset(int offset){ 99 | this.offset = offset; 100 | } 101 | 102 | private void focusOutAll(){ 103 | for (Component comp : getComponents()){ 104 | ((FlatTabView) comp).focusOut(); 105 | } 106 | } 107 | 108 | interface OnTabClickListener{ 109 | public void onTabClick(int position); 110 | } 111 | 112 | private static class FlatTabView extends FlatLabel { 113 | private static final int FONT_SIZE = SCREEN.dip2px(8); 114 | private static final Font TAB_LABEL_PLAIN_FONT = FontManager.getNanumGothicFont(Font.PLAIN, FONT_SIZE); 115 | private static final Font TAB_LABEL_BOLD_FONT = FontManager.getNanumGothicFont(Font.BOLD, FONT_SIZE); 116 | private static final Border PADDING_BORDER = new FlatEmptyBorder(SCREEN.dip2px(6)); 117 | 118 | private boolean isFocus; 119 | private FlatPageColor flatPageColor = FlatPageColor.getDefaultFlatPagerColor(); 120 | 121 | private FlatTabView(String text){ 122 | setText(text); 123 | setBorder(PADDING_BORDER); 124 | setCursor(new Cursor(Cursor.HAND_CURSOR)); 125 | focusIn(); 126 | fixWidth(getPreferredSize().width); 127 | focusOut(); 128 | 129 | } 130 | 131 | private void setFlatPageColor(FlatPageColor flatPageColor){ 132 | this.flatPageColor = flatPageColor; 133 | } 134 | 135 | private void focusIn(){ 136 | this.isFocus = true; 137 | setFont(TAB_LABEL_BOLD_FONT); 138 | setForeground(flatPageColor.getFocusInColor()); 139 | } 140 | 141 | private void focusOut(){ 142 | this.isFocus = false; 143 | setFont(TAB_LABEL_PLAIN_FONT); 144 | setForeground(flatPageColor.getFocusOutColor()); 145 | } 146 | 147 | private boolean isFocusing(){ 148 | return isFocus; 149 | } 150 | 151 | private void validateFocus(){ 152 | if (isFocusing()) { 153 | focusIn(); 154 | } else { 155 | focusOut(); 156 | } 157 | } 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/select/FlatCheckBox.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.select; 2 | 3 | import com.mommoo.flat.component.FlatPanel; 4 | import com.mommoo.flat.component.OnClickListener; 5 | import com.mommoo.flat.frame.FlatFrame; 6 | import com.mommoo.flat.layout.linear.Orientation; 7 | import com.mommoo.flat.layout.linear.constraints.LinearConstraints; 8 | import com.mommoo.flat.layout.linear.constraints.LinearSpace; 9 | import com.mommoo.flat.text.label.FlatLabel; 10 | import com.mommoo.flat.layout.linear.LinearLayout; 11 | import com.mommoo.util.ScreenManager; 12 | 13 | import java.awt.*; 14 | 15 | public class FlatCheckBox extends FlatPanel { 16 | private static final int GAP = ScreenManager.getInstance().dip2px(3); 17 | private boolean isAnchor; 18 | 19 | public FlatCheckBox(){ 20 | super.setLayout(new LinearLayout(GAP)); 21 | setBackground(Color.WHITE); 22 | add(new CheckBox(), new LinearConstraints(LinearSpace.WRAP_CENTER_CONTENT), "checkBox"); 23 | add(createGuideTextLabel(), new LinearConstraints(LinearSpace.WRAP_CENTER_CONTENT), "guideLabel"); 24 | } 25 | 26 | public FlatCheckBox(String guideText){ 27 | this(); 28 | setGuideText(guideText); 29 | } 30 | 31 | public FlatCheckBox(String guideText, boolean isAnchor){ 32 | this(); 33 | setGuideText(guideText); 34 | setAnchored(isAnchor); 35 | } 36 | 37 | private Component createGuideTextLabel(){ 38 | FlatLabel guideTextLabel = new FlatLabel(); 39 | guideTextLabel.setOpaque(false); 40 | return guideTextLabel; 41 | } 42 | 43 | private CheckBox getCheckBox(){ 44 | return (CheckBox)getComponent("checkBox"); 45 | } 46 | 47 | private FlatLabel getGuideTextLabel(){ 48 | return (FlatLabel) getComponent("guideLabel"); 49 | } 50 | 51 | public static void main(String[] args){ 52 | FlatCheckBox flatCheckBox = new FlatCheckBox("Beautiful Check Box1"); 53 | flatCheckBox.setAnchored(true); 54 | flatCheckBox.setChecked(true); 55 | flatCheckBox.setCheckBoxLineColor(Color.BLUE); 56 | flatCheckBox.setCheckColor(Color.BLUE); 57 | 58 | FlatCheckBox flatCheckBox2 = new FlatCheckBox("Beautiful Check Box2"); 59 | flatCheckBox2.setGap(20); 60 | flatCheckBox2.setCheckBoxLineColor(Color.BLUE); 61 | flatCheckBox2.setCheckColor(Color.BLUE); 62 | flatCheckBox2.setEnabled(false); 63 | 64 | FlatFrame flatFrame = new FlatFrame(); 65 | flatFrame.setTitle("FlatCheckBox Test"); 66 | flatFrame.setSize(500,300); 67 | flatFrame.setLocationOnScreenCenter(); 68 | flatFrame.getContainer().setLayout(new LinearLayout(Orientation.VERTICAL)); 69 | flatFrame.getContainer().add(flatCheckBox); 70 | flatFrame.getContainer().add(flatCheckBox2); 71 | // flatFrame.getContainer().setBorder(BorderFactory.createEmptyBorder(100,100,100,100)); 72 | flatFrame.show(); 73 | } 74 | 75 | @Override 76 | public void paint(Graphics g) { 77 | super.paint(g); 78 | if (!isEnabled()){ 79 | g.setColor(Color.BLACK); 80 | g.drawLine(0, getHeight()/2, getWidth(), getHeight()/2); 81 | } 82 | } 83 | 84 | @Override 85 | public void setEnabled(boolean enabled) { 86 | super.setEnabled(enabled); 87 | getCheckBox().setEnabled(enabled); 88 | getGuideTextLabel().setEnabled(enabled); 89 | } 90 | 91 | @Override 92 | public LayoutManager getLayout(){ 93 | return null; 94 | } 95 | 96 | @Override 97 | public void setLayout(LayoutManager layout){ } 98 | 99 | public int getGap(){ 100 | return ((LinearLayout)super.getLayout()).getGap(); 101 | } 102 | 103 | public String getText(){ 104 | return getGuideTextLabel().getText(); 105 | } 106 | 107 | public Color getTextColor(){ 108 | return getGuideTextLabel().getForeground(); 109 | } 110 | 111 | public void setTextColor(Color color){ 112 | getGuideTextLabel().setForeground(color); 113 | } 114 | 115 | public String getGuideText(){ 116 | return getGuideTextLabel().getText(); 117 | } 118 | 119 | public void setGuideText(String guideText){ 120 | getGuideTextLabel().setText(guideText); 121 | } 122 | 123 | @Override 124 | public void setFont(Font font){ 125 | super.setFont(font); 126 | if (getGuideTextLabel() != null) getGuideTextLabel().setFont(font); 127 | } 128 | 129 | public void setAnchored(boolean isAnchored){ 130 | this.isAnchor = isAnchored; 131 | getGuideTextLabel().setCursor(isAnchored ? new Cursor(Cursor.HAND_CURSOR) : new Cursor(Cursor.DEFAULT_CURSOR)); 132 | 133 | if (isAnchored){ 134 | getGuideTextLabel().setOnClickListener(comp -> getCheckBox().doClick(this)); 135 | } else { 136 | getGuideTextLabel().removeOnClickListener(); 137 | } 138 | 139 | } 140 | 141 | public boolean isAnchor(){ 142 | return this.isAnchor; 143 | } 144 | 145 | public boolean isChecked(){ 146 | return getCheckBox().isChecked(); 147 | } 148 | 149 | public void setChecked(boolean check){ 150 | getCheckBox().setChecked(check); 151 | } 152 | 153 | public void setGap(int gap){ 154 | ((LinearLayout)super.getLayout()).setGap(gap); 155 | } 156 | 157 | public Color getCheckColor(){ 158 | return getCheckBox().getCheckColor(); 159 | } 160 | 161 | public void setCheckColor(Color color){ 162 | getCheckBox().setCheckColor(color); 163 | } 164 | 165 | public Color getCheckBoxLineColor(){ 166 | return getCheckBox().getCheckBoxColor(); 167 | } 168 | 169 | public void setCheckBoxLineColor(Color boxLineColor){ 170 | getCheckBox().setCheckBoxColor(boxLineColor); 171 | } 172 | 173 | @Override 174 | public void setOnClickListener(OnClickListener onClickListener) { 175 | super.setOnClickListener(onClickListener); 176 | getCheckBox().setOnClickListener(this, getOnClickListener()); 177 | } 178 | 179 | @Override 180 | public void removeOnClickListener() { 181 | super.removeOnClickListener(); 182 | getCheckBox().removeOnClickListener(); 183 | } 184 | } -------------------------------------------------------------------------------- /src/com/mommoo/flat/component/pager/FlatPage.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.component.pager; 2 | 3 | import com.mommoo.flat.text.label.FlatLabel; 4 | import com.mommoo.flat.text.textarea.alignment.FlatHorizontalAlignment; 5 | import com.mommoo.flat.text.textarea.alignment.FlatVerticalAlignment; 6 | import com.mommoo.util.FastGaussianBlur; 7 | 8 | import javax.swing.*; 9 | import java.awt.*; 10 | import java.awt.event.MouseAdapter; 11 | import java.awt.event.MouseEvent; 12 | import java.awt.event.MouseListener; 13 | 14 | import java.awt.image.BufferedImage; 15 | import java.awt.image.BufferedImageOp; 16 | import java.awt.image.ConvolveOp; 17 | import java.awt.image.Kernel; 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | public class FlatPage{ 22 | private Viewport viewport = new Viewport(); 23 | private List pageEventList = new ArrayList<>(); 24 | 25 | public JPanel getView(){ 26 | return viewport.getView(); 27 | } 28 | 29 | public FlatPage(){ 30 | 31 | } 32 | 33 | public FlatPage(JPanel view){ 34 | this(); 35 | setView(view); 36 | } 37 | 38 | public FlatPage setView(JPanel view){ 39 | viewport.setView(view); 40 | return this; 41 | } 42 | 43 | Component getViewport(){ 44 | return viewport; 45 | } 46 | 47 | List getPageEventList(){ 48 | return pageEventList; 49 | } 50 | 51 | public boolean isEnable(){ 52 | return !viewport.isGlassPaneVisible(); 53 | } 54 | 55 | public FlatPage setEnable(boolean enable){ 56 | viewport.setGlassPaneVisible(!enable); 57 | return this; 58 | } 59 | 60 | public String getDisableGuideText(){ 61 | return viewport.getGuideLabel().getText(); 62 | } 63 | 64 | public FlatPage setDisableGuideText(String disableGuideText){ 65 | viewport.getGuideLabel().setText(disableGuideText); 66 | return this; 67 | } 68 | 69 | public Font getDisableGuideTextFont(){ 70 | return viewport.getGuideLabel().getFont(); 71 | } 72 | 73 | public FlatPage setDisableGuideTextFont(Font guideTextFont){ 74 | viewport.getGuideLabel().setFont(guideTextFont); 75 | return this; 76 | } 77 | 78 | public FlatPage setDisableGuideTextColor(Color textColor){ 79 | return this; 80 | } 81 | 82 | protected FlatPage addOnPageEventListener(OnPageEventListener onPageEventListener){ 83 | pageEventList.add(onPageEventListener); 84 | return this; 85 | } 86 | 87 | protected FlatPage removeOnPageEventListener(int index){ 88 | pageEventList.remove(index); 89 | return this; 90 | } 91 | 92 | protected OnPageEventListener getPageEventListener(int index){ 93 | return pageEventList.get(index); 94 | } 95 | 96 | private static class Viewport extends JLayeredPane{ 97 | private static final Integer GLASS_PANE_DEPTH = 300; 98 | private static final Integer CONTENT_DEPTH = 100; 99 | 100 | private Viewport(){ 101 | setLayout(null); 102 | add(new ViewportGlassPane(), GLASS_PANE_DEPTH); 103 | add(new JPanel(), CONTENT_DEPTH); 104 | setGlassPaneVisible(false); 105 | } 106 | 107 | @Override 108 | public void paint(Graphics g) { 109 | for (Component comp : getComponents()){ 110 | comp.setBounds(0,0,getWidth(),getHeight()); 111 | comp.doLayout(); 112 | comp.revalidate(); 113 | } 114 | super.paint(g); 115 | } 116 | 117 | private JPanel getView(){ 118 | return (JPanel) getComponent(1); 119 | } 120 | 121 | private void setView(JPanel panel){ 122 | remove(1); 123 | add(panel, CONTENT_DEPTH); 124 | } 125 | 126 | private boolean isGlassPaneVisible(){ 127 | return getComponent(0).isVisible(); 128 | } 129 | 130 | private void setGlassPaneVisible(boolean visible){ 131 | getComponent(0).setVisible(visible); 132 | } 133 | 134 | private FlatLabel getGuideLabel(){ 135 | return ((FlatLabel)((JPanel)getComponent(0)).getComponent(0)); 136 | } 137 | 138 | private static class ViewportGlassPane extends JPanel{ 139 | private static final Color GLASS_COLOR = new Color(255,255,255, 170); 140 | 141 | private ViewportGlassPane(){ 142 | setOpaque(false); 143 | setLayout(new BorderLayout()); 144 | add(createGuideLabel()); 145 | addMouseListener(createMouseBubbleEventBlocker()); 146 | } 147 | 148 | private Component createGuideLabel(){ 149 | FlatLabel guideLabel = new FlatLabel(); 150 | guideLabel.setOpaque(false); 151 | guideLabel.setHorizontalAlignment(FlatHorizontalAlignment.CENTER); 152 | guideLabel.setVerticalAlignment(FlatVerticalAlignment.CENTER); 153 | return guideLabel; 154 | } 155 | 156 | @Override 157 | public void paint(Graphics g) { 158 | g.setColor(GLASS_COLOR); 159 | g.fillRect(0,0,getWidth(), getHeight()); 160 | super.paint(g); 161 | 162 | } 163 | 164 | private MouseListener createMouseBubbleEventBlocker(){ 165 | return new MouseAdapter(){ 166 | @Override 167 | public void mousePressed(MouseEvent e) { 168 | e.consume(); 169 | } 170 | }; 171 | } 172 | } 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/frame/ShadowPaintHandler.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.frame; 2 | 3 | import com.sun.prism.j2d.paint.MultipleGradientPaint; 4 | import com.sun.prism.j2d.paint.RadialGradientPaint; 5 | 6 | import java.awt.*; 7 | import java.awt.geom.Arc2D; 8 | import java.awt.geom.Ellipse2D; 9 | import java.awt.geom.Rectangle2D; 10 | 11 | class ShadowPaintHandler { 12 | private static final float[] DIST = { 0.0f, 1.0f }; 13 | private static final Color[] COLORS = { new Color(0f,0f,0f,0.8f), new Color(0f,0f,0f,0f) }; 14 | // private static final Color[] COLORS = { new Color(152, 152, 152), new Color(100, 100, 100,0) }; 15 | private int width, height, shadowDip; 16 | private Drawer TOP_LEFT_DRAWER; 17 | private Drawer TOP_RIGHT_DRAWER; 18 | private Drawer BOTTOM_LEFT_DRAWER; 19 | private Drawer BOTTOM_RIGHT_DRAWER; 20 | private Drawer TOP_DRAWER; 21 | private Drawer LEFT_DRAWER; 22 | private Drawer RIGHT_DRAWER; 23 | private Drawer BOTTOM_DRAWER; 24 | 25 | void changePaint(int width, int height, int shadowDip){ 26 | 27 | if (this.width == width && this.height == height && this.shadowDip == shadowDip){ 28 | return ; 29 | } 30 | 31 | setData(width, height, shadowDip); 32 | TOP_LEFT_DRAWER = createTopLeftDrawer(); 33 | TOP_RIGHT_DRAWER = createTopRightDrawer(); 34 | BOTTOM_LEFT_DRAWER = createBottomLeftDrawer(); 35 | BOTTOM_RIGHT_DRAWER = createBottomRightDrawer(); 36 | TOP_DRAWER = createTopDrawer(); 37 | LEFT_DRAWER = createLeftDrawer(); 38 | RIGHT_DRAWER = createRightDrawer(); 39 | BOTTOM_DRAWER = createBottomDrawer(); 40 | } 41 | 42 | private void setData(int width, int height, int shadowDip){ 43 | this.width = width; 44 | this.height = height; 45 | this.shadowDip = shadowDip; 46 | } 47 | 48 | private Drawer createTopLeftDrawer(){ 49 | Shape topLeftCornerShape = new Arc2D.Float(0,0, shadowDip * 2 , shadowDip * 2 ,90, 90, Arc2D.PIE); 50 | Paint topLeftPaint = new RadialGradientPaint(shadowDip ,shadowDip ,shadowDip , DIST, COLORS, MultipleGradientPaint.CycleMethod.NO_CYCLE); 51 | return new Drawer(topLeftCornerShape, topLeftPaint); 52 | } 53 | 54 | private Drawer createTopRightDrawer(){ 55 | Shape topRightCornerShape = new Arc2D.Float(width - (shadowDip * 2),0, shadowDip * 2 , shadowDip * 2 ,90, -90, Arc2D.PIE); 56 | Paint topRightPaint = new RadialGradientPaint(width - shadowDip, shadowDip, shadowDip, DIST, COLORS, MultipleGradientPaint.CycleMethod.NO_CYCLE); 57 | return new Drawer(topRightCornerShape, topRightPaint); 58 | } 59 | 60 | private Drawer createBottomLeftDrawer(){ 61 | Shape bottomLeftShape = new Arc2D.Float(0, height - (shadowDip * 2) , shadowDip * 2 , shadowDip * 2 , 180, 90, Arc2D.PIE); 62 | Paint bottomLeftPaint = new RadialGradientPaint(shadowDip ,height- shadowDip, shadowDip , DIST, COLORS, MultipleGradientPaint.CycleMethod.NO_CYCLE); 63 | return new Drawer(bottomLeftShape, bottomLeftPaint); 64 | } 65 | 66 | private Drawer createBottomRightDrawer(){ 67 | Shape bottomRightShape = new Arc2D.Float(width - (shadowDip * 2) , height - (shadowDip * 2), shadowDip * 2, shadowDip * 2, 270, 90, Arc2D.PIE); 68 | Paint bottomRightPaint = new RadialGradientPaint(width - shadowDip, height - shadowDip, shadowDip, DIST, COLORS, MultipleGradientPaint.CycleMethod.NO_CYCLE);; 69 | return new Drawer(bottomRightShape, bottomRightPaint); 70 | } 71 | 72 | private Drawer createTopDrawer(){ 73 | Shape topShape = new Rectangle2D.Float(shadowDip, 0, width - (shadowDip * 2), shadowDip/2); 74 | Paint topPaint = new GradientPaint(shadowDip, shadowDip/2, COLORS[0], shadowDip, 0, COLORS[1]); 75 | return new Drawer(topShape, topPaint); 76 | } 77 | 78 | private Drawer createLeftDrawer(){ 79 | Shape leftShape = new Rectangle2D.Float(0, shadowDip, shadowDip, height - ( shadowDip * 2)); 80 | Paint leftPaint = new GradientPaint(shadowDip, shadowDip, COLORS[0], 0, shadowDip, COLORS[1]); 81 | return new Drawer(leftShape, leftPaint); 82 | } 83 | 84 | private Drawer createRightDrawer(){ 85 | Shape rightShape = new Rectangle2D.Float(width - shadowDip, shadowDip, shadowDip, height - ( shadowDip * 2)); 86 | Paint rightPaint = new GradientPaint(width - shadowDip, shadowDip, COLORS[0], width, shadowDip, COLORS[1]); 87 | return new Drawer(rightShape, rightPaint); 88 | } 89 | 90 | private Drawer createBottomDrawer(){ 91 | Shape bottomShape = new Rectangle2D.Float(shadowDip, height - shadowDip, width - (shadowDip * 2), shadowDip); 92 | Paint bottomPaint = new GradientPaint(shadowDip, height - shadowDip, COLORS[0], shadowDip, height, COLORS[1]); 93 | return new Drawer(bottomShape, bottomPaint); 94 | } 95 | 96 | public Drawer getTopLeftDrawer(){ 97 | return TOP_LEFT_DRAWER; 98 | } 99 | 100 | public Drawer getTopRightDrawer(){ 101 | return TOP_RIGHT_DRAWER; 102 | } 103 | 104 | public Drawer getBottomLeftDrawer(){ 105 | return BOTTOM_LEFT_DRAWER; 106 | } 107 | 108 | public Drawer getBottomRightDrawer(){ 109 | return BOTTOM_RIGHT_DRAWER; 110 | } 111 | 112 | public Drawer getTopDrawer(){ 113 | return TOP_DRAWER; 114 | } 115 | 116 | public Drawer getLeftDrawer(){ 117 | return LEFT_DRAWER; 118 | } 119 | 120 | public Drawer getRightDrawer(){ 121 | return RIGHT_DRAWER; 122 | } 123 | 124 | public Drawer getBottomDrawer(){ 125 | return BOTTOM_DRAWER; 126 | } 127 | 128 | public class Drawer{ 129 | private final Shape shape; 130 | private final Paint paint; 131 | 132 | public Drawer(Shape shape, Paint paint){ 133 | this.shape = shape; 134 | this.paint = paint; 135 | } 136 | 137 | public Shape getShape() { 138 | return shape; 139 | } 140 | 141 | public Paint getPaint() { 142 | return paint; 143 | } 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /src/com/mommoo/flat/frame/FlatPopUpList.java: -------------------------------------------------------------------------------- 1 | package com.mommoo.flat.frame; 2 | 3 | import com.mommoo.flat.frame.popup.OnItemClickListener; 4 | import com.mommoo.flat.list.FlatListView; 5 | import com.mommoo.flat.text.label.FlatLabel; 6 | import com.mommoo.util.FontManager; 7 | import com.mommoo.util.ScreenManager; 8 | 9 | import javax.swing.*; 10 | import java.awt.*; 11 | import java.awt.event.WindowAdapter; 12 | import java.awt.event.WindowEvent; 13 | 14 | public class FlatPopUpList { 15 | private static final ScreenManager screenManager = ScreenManager.getInstance(); 16 | private static final int PADDING = screenManager.dip2px(10); 17 | 18 | private final CommonJFrame FRAME = new CommonJFrame(); 19 | private OnItemClickListener onItemClickListener = (index, message)->{}; 20 | private FlatListView listView = new FlatListView<>(); 21 | 22 | private boolean isDisposeAfterSelection; 23 | 24 | private Font menuFont = FontManager.getNanumGothicFont(Font.PLAIN, screenManager.dip2px(8)); 25 | 26 | public FlatPopUpList(){ 27 | initFrame(); 28 | initContentPane(); 29 | initListView(); 30 | setDisposeAfterSelection(true); 31 | setFocusLostDispose(); 32 | getContentPane().add(listView.getComponent()); 33 | } 34 | 35 | private void initFrame(){ 36 | FRAME.setType(Window.Type.UTILITY); 37 | FRAME.setShadowWidth(3); 38 | FRAME.setAlwaysOnTop(true); 39 | FRAME.setCursor(new Cursor(Cursor.HAND_CURSOR)); 40 | } 41 | 42 | private void initContentPane(){ 43 | JPanel contentPane = getContentPane(); 44 | contentPane.setLayout(new BorderLayout()); 45 | contentPane.setOpaque(true); 46 | } 47 | 48 | public static void main(String[] args){ 49 | FlatPopUpList popUpList = new FlatPopUpList(); 50 | for (int i = 1; i < 6 ; i++){ 51 | popUpList.addMenu("Item " + i); 52 | } 53 | popUpList.addMenu("Very Long Menu Text"); 54 | popUpList.setFocusLostDispose(); 55 | popUpList.setOnItemClickListener((position, message) -> { 56 | System.out.println(message); 57 | }); 58 | 59 | FlatFrame frame = new FlatFrame(); 60 | frame.setSize(500,500); 61 | frame.setLocationOnScreenCenter(); 62 | JButton button = new JButton("클릭"); 63 | button.addActionListener(e -> popUpList.show(MouseInfo.getPointerInfo().getLocation())); 64 | frame.getContainer().add(button); 65 | frame.show(); 66 | } 67 | 68 | private JPanel getContentPane(){ 69 | return (JPanel)FRAME.getContentPane(); 70 | } 71 | 72 | private FlatLabel createLabel(String text){ 73 | FlatLabel flatLabel = new FlatLabel(text); 74 | flatLabel.setFont(menuFont); 75 | flatLabel.setBorder(BorderFactory.createEmptyBorder(PADDING/2,PADDING,PADDING/2,PADDING)); 76 | return flatLabel; 77 | } 78 | 79 | private Dimension getProperSize(){ 80 | int width = 0; 81 | int height = 0; 82 | 83 | for (FlatLabel comp : listView.getItems()){ 84 | Dimension dimension = comp.getPreferredSize(); 85 | width = Math.max(dimension.width, width); 86 | height += dimension.height; 87 | } 88 | 89 | return new Dimension(width, height); 90 | } 91 | 92 | private Point getProperLocation(Dimension properSize, int originX, int originY){ 93 | if (screenManager.getScreenWidth() < originX + properSize.width) { 94 | originX -= properSize.width; 95 | } 96 | 97 | if (screenManager.getWindowHeight() < originY + properSize.height){ 98 | originY -= properSize.height; 99 | } 100 | 101 | return new Point(originX, originY); 102 | } 103 | 104 | public void addMenu(String menuTxt){ 105 | listView.addItem(createLabel(menuTxt)); 106 | } 107 | 108 | public void setOnItemClickListener(OnItemClickListener onItemClickListener){ 109 | this.onItemClickListener = onItemClickListener; 110 | } 111 | 112 | public void show(Point point){ 113 | show(point.x, point.y); 114 | } 115 | 116 | public void show(int x, int y){ 117 | Dimension properSize = getProperSize(); 118 | listView.getComponent().setPreferredSize(properSize); 119 | FRAME.pack(); 120 | FRAME.setLocation(getProperLocation(properSize, x, y)); 121 | FRAME.setVisible(true); 122 | } 123 | 124 | public void setFocusLostDispose(){ 125 | FRAME.addWindowFocusListener(new WindowAdapter() { 126 | @Override 127 | public void windowLostFocus(WindowEvent e) { 128 | dispose(); 129 | } 130 | }); 131 | } 132 | 133 | private void initListView(){ 134 | listView.setTrace(true); 135 | listView.setSingleSelectionMode(true); 136 | listView.setOnSelectionListener(((beginIndex, endIndex, selectionList) -> { 137 | onItemClickListener.onItemClick(beginIndex, selectionList.get(0).getText()); 138 | if (isDisposeAfterSelection) dispose(); 139 | })); 140 | } 141 | 142 | public void dispose(){ 143 | FRAME.dispose(); 144 | } 145 | 146 | public void setDisposeAfterSelection(boolean isDisposeAfterSelection){ 147 | this.isDisposeAfterSelection = isDisposeAfterSelection; 148 | } 149 | 150 | public void select(int index){ 151 | listView.select(index, index); 152 | } 153 | 154 | public void deSelect(){ 155 | listView.deSelect(); 156 | } 157 | 158 | public Color getSelectionColor(){ 159 | return this.listView.getSelectionColor(); 160 | } 161 | 162 | public void setSelectionColor(Color color) { 163 | this.listView.setSelectionColor(color); 164 | } 165 | 166 | public void setMenuText(int index, String menuTxt){ 167 | this.listView.getItem(index).setText(menuTxt); 168 | } 169 | 170 | public String getMenuText(int index) { 171 | return this.listView.getItem(index).getText(); 172 | } 173 | 174 | public Font getMenuFont() { 175 | return this.menuFont; 176 | } 177 | 178 | public void setMenuFont(Font font) { 179 | this.menuFont = font; 180 | this.listView.getItems().forEach(item -> item.setFont(font)); 181 | } 182 | } 183 | --------------------------------------------------------------------------------