@ -1,39 +1,42 @@
package com.fr.design.foldablepane ;
package com.fr.design.foldablepane ;
import com.fine.theme.icon.LazyIcon ;
import com.fr.base.GraphHelper ;
import com.fr.base.GraphHelper ;
import com.fr.design.constants.UIConstants ;
import javax.swing.BorderFactory ;
import javax.swing.Icon ;
import javax.swing.JFrame ;
import javax.swing.JFrame ;
import javax.swing.JPanel ;
import javax.swing.JPanel ;
import javax.swing.UIManager ;
import java.awt.AlphaComposite ;
import java.awt.BorderLayout ;
import java.awt.BorderLayout ;
import java.awt.Color ;
import java.awt.Color ;
import java.awt.Dimension ;
import java.awt.Dimension ;
import java.awt.Font ;
import java.awt.FontMetrics ;
import java.awt.Graphics ;
import java.awt.Graphics ;
import java.awt.Graphics2D ;
import java.awt.Graphics2D ;
import java.awt.Image ;
import java.awt.Insets ;
/ * *
/ * *
* Created by MoMeak on 2017 / 7 / 5 .
* Created by MoMeak on 2017 / 7 / 5 .
* /
* /
public class HeaderPane extends JPanel {
public class HeaderPane extends JPanel {
private static final long serialVersionUID = 1L ;
private static final long serialVersionUID = 1L ;
private static final int TITLE_X = 5 ;
private static final int LEFT_X = 16 ;
private static final int LEFT_Y = 6 ;
private static final int NORMAL_FONTSIZE = 12 ;
private int headWidth ;
private int headWidth ;
private int headHeight ;
private int headHeight ;
private Color bgColor ;
private Color bgColor ;
private boolean isShow ;
private boolean isShow ;
private boolean isPressed = false ;
private boolean isPressed = false ;
private String title ;
private String title ;
private Image image ;
private int fontSize ;
private int fontSize ;
private final Icon triangleDown ;
private final Icon triangleRight ;
private final int hGap ;
public void setPressed ( boolean pressed ) {
public void setPressed ( boolean pressed ) {
this . isPressed = pressed ;
this . isPressed = pressed ;
}
}
public void setShow ( boolean isShow ) {
public void setShow ( boolean isShow ) {
this . isShow = isShow ;
this . isShow = isShow ;
}
}
@ -58,45 +61,44 @@ public class HeaderPane extends JPanel {
@Override
@Override
protected void paintComponent ( Graphics g ) {
protected void paintComponent ( Graphics g ) {
Graphics2D g2d = ( Graphics2D ) g . create ( ) ;
Graphics2D g2d = ( Graphics2D ) g . create ( ) ;
// g2d.setColor(isPressed ? UIConstants.POPUP_TITLE_BACKGROUND : UIConstants.COMPONENT_BACKGROUND_COLOR);
headWidth = this . getWidth ( ) ;
g2d . setColor ( getBackground ( ) ) ;
g2d . setColor ( getBackground ( ) ) ;
g2d . fillRect ( 0 , 0 , headWidth , headHeight ) ;
g2d . fillRect ( 0 , 0 , this . getWidth ( ) , this . getHeight ( ) ) ;
// g2d.setFont(new Font("SimSun", 0, fontSize));
g2d . setPaint ( getForeground ( ) ) ;
int iconY = ( this . getHeight ( ) - triangleDown . getIconHeight ( ) ) / 2 ;
int leftWdith = headWidth - LEFT_X ;
if ( this . isShow ) {
if ( this . isShow ) {
image = UIConstants . DRAG_DOWN_SELECTED_SMALL ;
triangleDown . paintIcon ( this , g2d , 0 , iconY ) ;
g2d . drawImage ( image , leftWdith , LEFT_Y , null ) ;
} else {
} else {
image = UIConstants . DRAG_LEFT_NORMAL_SMALL ;
triangleRight . paintIcon ( this , g2d , 0 , iconY ) ;
g2d . drawImage ( image , leftWdith , LEFT_Y , null ) ;
}
}
GraphHelper . drawString ( g2d , this . title , TITLE_X , headHeight - fontSize / 2 - 1 ) ;
g2d . setFont ( getFont ( ) ) ;
}
g2d . setPaint ( getForeground ( ) ) ;
g2d . setComposite ( AlphaComposite . SrcOver . derive ( ( float ) getForeground ( ) . getAlpha ( ) / 255 ) ) ;
@Override
FontMetrics metrics = g2d . getFontMetrics ( ) ;
public Dimension getPreferredSize ( ) {
int ascent = metrics . getAscent ( ) ;
return new Dimension ( this . getWidth ( ) , headHeight ) ;
int descent = metrics . getDescent ( ) ;
}
@Override
double titleY = ( double ) ( getHeight ( ) - ( ascent + descent ) ) / 2 + ascent ;
public Dimension getSize ( ) {
GraphHelper . drawString ( g2d , this . title , triangleDown . getIconWidth ( ) + this . hGap , titleY ) ;
return new Dimension ( this . getWidth ( ) , headHeight ) ;
g2d . dispose ( ) ;
}
}
public HeaderPane ( Color bgColor ) {
public HeaderPane ( Color bgColor ) {
this . bgColor = bgColor ;
this . isShow = true ;
this . isShow = true ;
triangleDown = new LazyIcon ( "triangle_down" ) ;
triangleRight = new LazyIcon ( "triangle_right" ) ;
this . hGap = UIManager . getInt ( "ExpandablePane.HeaderPane.hGap" ) ;
this . setPreferredSize ( new Dimension ( UIManager . getInt ( "HeaderPane.width" ) , UIManager . getInt ( "HeaderPane.height" ) ) ) ;
Insets insets = UIManager . getInsets ( "ExpandablePane.HeaderPane.borderInsets" ) ;
this . setForeground ( UIManager . getColor ( "color.text.highlight" ) ) ;
this . setFont ( getFont ( ) . deriveFont ( Font . BOLD ) ) ;
this . setBorder ( BorderFactory . createEmptyBorder ( insets . top , insets . left , insets . bottom , insets . right ) ) ;
}
}
public HeaderPane ( Color bgColor , String title , int headHeight ) {
public HeaderPane ( Color bgColor , String title , int headHeight ) {
this ( bgColor ) ;
this ( bgColor ) ;
this . title = title ;
this . title = title ;
this . headHeight = headHeight ;
this . fontSize = NORMAL_FONTSIZE ;
}
}
public static void main ( String [ ] args ) {
public static void main ( String [ ] args ) {