@ -2,13 +2,16 @@ package com.fr.design.mainframe.loghandler;
import com.fr.base.BaseUtils ;
import com.fr.design.gui.ibutton.UIButton ;
import com.fr.design.gui.ilable.UILabel ;
import com.fr.design.ui.util.UIUtil ;
import javax.swing.* ;
import java.awt.* ;
import java.awt.event.ActionListener ;
import java.awt.event.ItemEvent ;
import java.awt.event.ItemListener ;
import java.util.concurrent.atomic.AtomicBoolean ;
import static com.fr.design.i18n.Toolkit.i18nText ;
public class LogHandlerBar extends JPanel implements ItemSelectable {
@ -17,11 +20,16 @@ public class LogHandlerBar extends JPanel implements ItemSelectable {
private UIButton clear ;
private UIButton selectedall ;
private UIButton set ;
private UILabel normalLabel ;
private UILabel alertLabel ;
private UILabel seriouslyLabel ;
private String text ;
private int INFONUM = 0 ;
private int ERRORNUM = 0 ;
private int SERVERNUM = 0 ;
private static final int FLOW_LAYOUT_HGAP = 10 ;
private static final int FLOW_LAYOUT_VGAP = 5 ;
private boolean isWithSerious ;
@ -30,33 +38,53 @@ public class LogHandlerBar extends JPanel implements ItemSelectable {
}
public LogHandlerBar ( String text ) {
this . setLayout ( new CaptionLayout ( ) ) ;
this . setLayout ( new FlowLayout ( FlowLayout . RIGHT , FLOW_LAYOUT_HGAP , FLOW_LAYOUT_VGAP ) ) ;
this . setUI ( new LogHandlerBarUI ( ) ) ;
this . text = text ;
clear = new UIButton ( BaseUtils . readIcon ( "com/fr/design/images/log/clear.png" ) ) ;
clear . setMargin ( null ) ;
clear . setOpaque ( false ) ;
clear . setBorder ( BorderFactory . createEmptyBorder ( 0 , 0 , 0 , 0 ) ) ;
clear . setToolTipText ( com . fr . design . i18n . Toolkit . i18nText ( "Fine-Design_Basic_Clear_All" ) ) ;
clear . setToolTipText ( i18nText ( "Fine-Design_Basic_Clear_All" ) ) ;
selectedall = new UIButton ( BaseUtils . readIcon ( "com/fr/design/images/log/selectedall.png" ) ) ;
selectedall . setMargin ( null ) ;
selectedall . setOpaque ( false ) ;
selectedall . setBorder ( BorderFactory . createEmptyBorder ( 0 , 0 , 0 , 0 ) ) ;
selectedall . setToolTipText ( com . fr . design . i18n . Toolkit . i18nText ( "Fine-Design_Basic_Select_All" ) ) ;
selectedall . setToolTipText ( i18nText ( "Fine-Design_Basic_Select_All" ) ) ;
set = new UIButton ( BaseUtils . readIcon ( "com/fr/design/images/log/setting.png" ) ) ;
set . setMargin ( null ) ;
set . setOpaque ( false ) ;
set . setBorder ( BorderFactory . createEmptyBorder ( 0 , 0 , 0 , 0 ) ) ;
set . setToolTipText ( com . fr . design . i18n . Toolkit . i18nText ( "Fine-Design_Report_Set" ) ) ;
set . setToolTipText ( i18nText ( "Fine-Design_Report_Set" ) ) ;
normalLabel = new UILabel ( i18nText ( "Fine-Design_Basic_NNormal" ) + "(0)" ) ;
alertLabel = new UILabel ( i18nText ( "Fine-Design_Basic_Alert" ) + "(0)" ) ;
seriouslyLabel = new UILabel ( i18nText ( "Fine-Design_Basic_Seriously" ) + "(0)" ) ;
this . add ( normalLabel ) ;
this . add ( alertLabel ) ;
this . add ( seriouslyLabel ) ;
this . add ( clear ) ;
this . add ( selectedall ) ;
this . add ( set ) ;
}
/ * *
* 更新日志数量统计标签
* /
private void changeLabel ( ) {
UIUtil . invokeLaterIfNeeded ( new Runnable ( ) {
@Override
public void run ( ) {
normalLabel . setText ( i18nText ( "Fine-Design_Basic_NNormal" ) + '(' + getInfo ( ) + ')' ) ;
alertLabel . setText ( i18nText ( "Fine-Design_Basic_Alert" ) + '(' + getError ( ) + ')' ) ;
seriouslyLabel . setText ( i18nText ( "Fine-Design_Basic_Seriously" ) + '(' + getServer ( ) + ')' ) ;
}
} ) ;
}
public void clearMessage ( ) {
INFONUM = ERRORNUM = SERVERNUM = 0 ;
repaint ( ) ;
changeLabel ( ) ;
}
public boolean IsWithSerious ( ) {
@ -69,27 +97,17 @@ public class LogHandlerBar extends JPanel implements ItemSelectable {
public void infoAdd ( ) {
INFONUM + + ;
repaint ( ) ;
changeLabel ( ) ;
}
public void errorAdd ( ) {
ERRORNUM + + ;
timerPaint ( ) ;
changeLabel ( ) ;
}
public void serverAdd ( ) {
SERVERNUM + + ;
timerPaint ( ) ;
}
private AtomicBoolean painting = new AtomicBoolean ( false ) ;
public void timerPaint ( ) {
if ( ! painting . get ( ) ) {
painting . set ( true ) ;
repaint ( ) ;
painting . set ( false ) ;
}
changeLabel ( ) ;
}
public int getInfo ( ) {
@ -141,44 +159,4 @@ public class LogHandlerBar extends JPanel implements ItemSelectable {
public void addSetListener ( ActionListener l ) {
set . addActionListener ( l ) ;
}
private class CaptionLayout implements LayoutManager {
@Override
public void addLayoutComponent ( String name , Component comp ) {
}
@Override
public void removeLayoutComponent ( Component comp ) {
}
@Override
public Dimension preferredLayoutSize ( Container parent ) {
return new Dimension ( 120 , 24 ) ;
}
@Override
public Dimension minimumLayoutSize ( Container parent ) {
return new Dimension ( 0 , 0 ) ;
}
@Override
public void layoutContainer ( Container target ) {
Insets insets = target . getInsets ( ) ;
int top = insets . top ;
int right = target . getWidth ( ) - insets . right ;
clear . setBounds ( right - CLEAR_OFFSET , top + TOP_OFFSET , clear . getPreferredSize ( ) . width , clear . getPreferredSize ( ) . height ) ;
selectedall . setBounds ( right - SELECT_OFFSET , top + TOP_OFFSET , selectedall . getPreferredSize ( ) . width , selectedall . getPreferredSize ( ) . height ) ;
set . setBounds ( right - SET_OFFSET , top + TOP_OFFSET , set . getPreferredSize ( ) . width , set . getPreferredSize ( ) . height ) ;
}
private static final int CLEAR_OFFSET = 130 ;
private static final int TOP_OFFSET = 4 ;
private static final int SELECT_OFFSET = 100 ;
private static final int SET_OFFSET = 70 ;
}
}