@ -1,6 +1,7 @@
package com.fr.design.mainframe ;
import com.fine.theme.icon.LazyIcon ;
import com.fine.theme.utils.FineUIUtils ;
import com.formdev.flatlaf.ui.FlatUIUtils ;
import com.fr.base.GraphHelper ;
import com.fr.base.svg.IconUtils ;
@ -27,17 +28,16 @@ import com.fr.report.report.TemplateReport;
import com.fr.report.worksheet.WorkSheet ;
import javax.swing.Icon ;
import javax.swing.JComponent ;
import javax.swing.JOptionPane ;
import javax.swing.JPanel ;
import javax.swing.JPopupMenu ;
import javax.swing.SwingUtilities ;
import javax.swing.UIManager ;
import java.awt.BasicStroke ;
import java.awt.BorderLayout ;
import java.awt.Color ;
import java.awt.Dimension ;
import java.awt.FontMetrics ;
import java.awt.BasicStroke ;
import java.awt.Graphics ;
import java.awt.Graphics2D ;
import java.awt.Point ;
@ -49,22 +49,26 @@ import java.awt.event.ComponentListener;
import java.awt.event.MouseEvent ;
import java.awt.event.MouseListener ;
import java.awt.event.MouseMotionListener ;
import java.awt.geom.Path2D ;
import java.awt.geom.RoundRectangle2D ;
import java.util.ArrayList ;
import java.util.List ;
import static com.fine.theme.utils.FineClientProperties.setStyle ;
/ * *
* NameTabPane of sheets
*
* @editor zhou
* @since 2012 - 3 - 26下午1 : 45 : 53
* @author zhou
* @since 11 . 0
* Created on 2012 - 3 - 26
* /
public class SheetNameTabPane extends JComponent implements MouseListener , MouseMotionListener , RemoveListener {
public class SheetNameTabPane extends JPanel implements MouseListener , MouseMotionListener , RemoveListener {
private static final Color BORDER_COLOR = UIManager . getColor ( "Center.ZoneBorderColor" ) ;
private static final Color BACKGROUND_COLOR = UIManager . getColor ( "Center.OuterShadowColor" ) ;
private static final Color SELECTED_COLOR = UIManager . getColor ( "South.SheetSelectedColor" ) ;
private static final Color FONT_COLOR = UIManager . getColor ( "DarkenedFontColor" ) ;
private Color borderColor = UIManager . getColor ( "Center.ZoneBorderColor" ) ;
private Color backgroundColor = UIManager . getColor ( "Center.OuterShadowColor" ) ;
private Color selectedColor = UIManager . getColor ( "South.SheetSelectedColor" ) ;
private Color fontColor = UIManager . getColor ( "DarkenedFontColor" ) ;
private static final Icon ADD_WORK_SHEET = new LazyIcon ( "add_worksheet" ) ;
protected static final Icon ADD_POLY_SHEET = new LazyIcon ( "add_polysheet" ) ;
@ -81,12 +85,12 @@ public class SheetNameTabPane extends JComponent implements MouseListener, Mouse
private static final int POLY_TOSHEET_LEFT = 30 ; // 添加poly按钮左侧距sheet面板右侧的距离
private static final int POLY_TOSHEET_RIGHT = 50 ; // 添加poly按钮右侧距sheet面板右侧的距离
private static final int ICON_SEP_DISTANCE = UIManager . getInt ( "South.SheetIconSepDistance" ) ;
private static final int SHEET_ICON_GAP = UIManager . getInt ( "South.SheetIconGap" ) ; // 每个sheet图标之间的距离
private static final int TOOLBAR_HEIGHT = UIManager . getInt ( "South.SheetBarHeight" ) ;
private static final int ADD_WIDTH_BY_SHEETNAME = UIManager . getInt ( "South.SheetAddWidth" ) ; //sheet名字的文本到图标边框的距离
private static final int TAB_BUTTON_GAP = UIManager . getInt ( "South.SheetTabButtonGap" ) ; // 两个添加按钮与其他组件预留的间隔
private static final int SHEET_TAB_RADIUS = UIManager . getInt ( "South.SheetTabRadius" ) ; // sheet标签栏圆角属性
private int iconSepDistance = UIManager . getInt ( "South.SheetIconSepDistance" ) ;
private int sheetIconGap = UIManager . getInt ( "South.SheetIconGap" ) ; // 每个sheet图标之间的距离
private int toolbarHeight = UIManager . getInt ( "South.SheetBarHeight" ) ;
private int addWidthBySheetname = UIManager . getInt ( "South.SheetAddWidth" ) ; //sheet名字的文本到图标边框的距离
private int tabButtonGap = UIManager . getInt ( "South.SheetTabButtonGap" ) ; // 两个添加按钮与其他组件预留的间隔
private int sheetTabRadius = UIManager . getInt ( "South.SheetTabRadius" ) ; // sheet标签栏圆角属性
/ * *
* 左移和右移按钮
@ -160,12 +164,12 @@ public class SheetNameTabPane extends JComponent implements MouseListener, Mouse
this . addMouseListener ( this ) ;
this . addMouseMotionListener ( this ) ;
this . setBorder ( null ) ;
this . setForeground ( FONT_COLOR ) ;
this . setBackground ( BACKGROUND_COLOR ) ;
this . setForeground ( fontColor ) ;
setStyle ( this , "LightGreyPanel" ) ;
leftButton = new UIButton ( LEFT_ICON ) {
@Override
public Dimension getPreferredSize ( ) {
return new Dimension ( super . getPreferredSize ( ) . width , TOOLBAR_HEIGHT ) ;
return new Dimension ( super . getPreferredSize ( ) . width , toolbarHeight ) ;
}
} ;
leftButton . set4ToolbarButton ( ) ;
@ -173,7 +177,7 @@ public class SheetNameTabPane extends JComponent implements MouseListener, Mouse
rightButton = new UIButton ( RIGHT_ICON ) {
@Override
public Dimension getPreferredSize ( ) {
return new Dimension ( super . getPreferredSize ( ) . width , TOOLBAR_HEIGHT ) ;
return new Dimension ( super . getPreferredSize ( ) . width , toolbarHeight ) ;
}
} ;
rightButton . set4ToolbarButton ( ) ;
@ -332,7 +336,6 @@ public class SheetNameTabPane extends JComponent implements MouseListener, Mouse
* /
@Override
public void paintComponent ( Graphics g ) {
super . paintComponent ( g ) ;
isAuthorityEditing = DesignerMode . isAuthorityEditing ( ) ;
showCount = 0 ;
// 开始画那些Tab.
@ -343,7 +346,7 @@ public class SheetNameTabPane extends JComponent implements MouseListener, Mouse
double textHeight = this . getSize ( ) . getHeight ( ) - 1 ;
widthArray = calculateWidthArray ( ) ;
int operationWidth = TAB_BUTTON_GAP + getAddWorkSheet ( ) . getIconWidth ( ) + ICON_SEP_DISTANCE + ADD_POLY_SHEET . getIconWidth ( ) ;
int operationWidth = tabButtonGap + getAddWorkSheet ( ) . getIconWidth ( ) + iconSepDistance + ADD_POLY_SHEET . getIconWidth ( ) ;
double maxWidth = getWidth ( ) - operationWidth - buttonPane . getWidth ( ) ; // 最大宽度
paintBackgroundAndLine ( g2d , textHeight , maxWidth , charWidth , textAscent ) ;
checkButton ( showCount < widthArray . length ) ;
@ -361,11 +364,18 @@ public class SheetNameTabPane extends JComponent implements MouseListener, Mouse
}
private void paintBackgroundAndLine ( Graphics2D g2d , double textHeight , double maxWidth , int charWidth , int textAscent ) {
int arc = FineUIUtils . getAndScaleInt ( "Center.arc" , 10 ) / 2 ;
Path2D roundedPath = FineUIUtils . createPartRoundRectangle ( 0 , 0 , this . getWidth ( ) , this . getHeight ( ) , 0 , 0 , 0 , arc ) ;
FlatUIUtils . setRenderingHints ( g2d ) ;
g2d . setColor ( getBackground ( ) ) ;
g2d . fill ( roundedPath ) ;
showCount = 0 ;
int addIconlocation = 0 ;
WorkBook workBook = reportComposite . getEditingWorkBook ( ) ;
int reportCount = workBook . getReportCount ( ) ;
double textX = SHEET_ICON_GAP ;
double textX = sheetIconGap ;
for ( int i = scrollIndex ; i < reportCount ; i + + ) {
lastOneIndex = i ;
TemplateReport templateReport = workBook . getTemplateReport ( i ) ;
@ -397,20 +407,20 @@ public class SheetNameTabPane extends JComponent implements MouseListener, Mouse
}
// 画两个添加sheet图标
iconLocation = isOvertakeWidth ? ( int ) ( maxWidth ) : addIconlocation + TAB_BUTTON_GAP ;
iconLocation = isOvertakeWidth ? ( int ) ( maxWidth ) : addIconlocation + tabButtonGap ;
paintAddButton ( g2d ) ;
}
protected void paintAddButton ( Graphics2D g2d ) {
getAddWorkSheet ( ) . paintIcon ( this , g2d , iconLocation , 3 ) ;
ADD_POLY_SHEET . paintIcon ( this , g2d , iconLocation + getAddWorkSheet ( ) . getIconWidth ( ) + ICON_SEP_DISTANCE , 3 ) ;
ADD_POLY_SHEET . paintIcon ( this , g2d , iconLocation + getAddWorkSheet ( ) . getIconWidth ( ) + iconSepDistance , 3 ) ;
}
private void paintTab ( Graphics2D g2d , double textHeight , double textX , String sheetName , int charWidth , int textAscent , int i , boolean isNeedPaintAuthority , boolean isSelected ) {
Color backgroundColor = isSelected ? SELECTED_COLOR : ( isNeedPaintAuthority ? UIConstants . AUTHORITY_SHEET_UNSELECTED : getBackground ( ) ) ;
Color backgroundColor = isSelected ? selectedColor : ( isNeedPaintAuthority ? UIConstants . AUTHORITY_SHEET_UNSELECTED : getBackground ( ) ) ;
g2d . setColor ( backgroundColor ) ;
// 绘制圆角矩形背景
@ -418,11 +428,11 @@ public class SheetNameTabPane extends JComponent implements MouseListener, Mouse
FlatUIUtils . setRenderingHints ( g2d ) ;
int width = widthArray [ i ] ;
int height = ( int ) textHeight + SHEET_TAB_RADIUS ;
RoundRectangle2D . Double backgroundRect = new RoundRectangle2D . Double ( textX , - 10 , width , height , SHEET_TAB_RADIUS , SHEET_TAB_RADIUS ) ;
int height = ( int ) textHeight + sheetTabRadius ;
RoundRectangle2D . Double backgroundRect = new RoundRectangle2D . Double ( textX , - 10 , width , height , sheetTabRadius , sheetTabRadius ) ;
g2d . fill ( backgroundRect ) ;
g2d . setColor ( BORDER_COLOR ) ;
g2d . setColor ( borderColor ) ;
g2d . setStroke ( new BasicStroke ( 1 ) ) ;
g2d . draw ( backgroundRect ) ;
}
@ -475,7 +485,7 @@ public class SheetNameTabPane extends JComponent implements MouseListener, Mouse
int [ ] widthArray = new int [ reportCount ] ;
for ( int i = 0 ; i < reportCount ; i + + ) {
String sheetName = workBook . getReportName ( i ) ;
widthArray [ i ] = fm . stringWidth ( sheetName ) + charWidth * 2 - 1 + ADD_WIDTH_BY_SHEETNAME ;
widthArray [ i ] = fm . stringWidth ( sheetName ) + charWidth * 2 - 1 + addWidthBySheetname ;
}
return widthArray ;
}
@ -595,7 +605,7 @@ public class SheetNameTabPane extends JComponent implements MouseListener, Mouse
this . setReleasedXY ( e . getX ( ) , e . getY ( ) ) ;
int width = 0 ;
for ( int w : widthArray ) {
width = width + w + SHEET_ICON_GAP ;
width = width + w + sheetIconGap ;
}
if ( isAuthorityEditing ) {
return ;
@ -759,7 +769,7 @@ public class SheetNameTabPane extends JComponent implements MouseListener, Mouse
widthArray = calculateWidthArray ( ) ;
int width = widthArray [ i ] ;
textX + = width + 1 ;
int operationWidth = TAB_BUTTON_GAP + getAddWorkSheet ( ) . getIconWidth ( ) + ICON_SEP_DISTANCE + ADD_POLY_SHEET . getIconWidth ( ) ;
int operationWidth = tabButtonGap + getAddWorkSheet ( ) . getIconWidth ( ) + iconSepDistance + ADD_POLY_SHEET . getIconWidth ( ) ;
double maxWidth = getWidth ( ) - operationWidth - buttonPane . getWidth ( ) ; // 最大宽度
if ( i < widthArray . length - 1 & & textX + widthArray [ i + 1 ] + 1 > maxWidth ) {
isOvertakeWidth = true ;