@ -15,15 +15,38 @@ import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.utils.gui.GUICoreUtils ;
import com.fr.general.Inter ;
import javax.swing.* ;
import javax.swing.BorderFactory ;
import javax.swing.ButtonGroup ;
import javax.swing.JButton ;
import javax.swing.JFormattedTextField ;
import javax.swing.JFrame ;
import javax.swing.JPanel ;
import javax.swing.JPopupMenu ;
import javax.swing.JRadioButton ;
import javax.swing.JSeparator ;
import javax.swing.JSpinner ;
import javax.swing.SpinnerNumberModel ;
import javax.swing.event.ChangeEvent ;
import javax.swing.event.ChangeListener ;
import javax.swing.plaf.basic.BasicSliderUI ;
import javax.swing.text.BadLocationException ;
import javax.swing.text.DefaultFormatterFactory ;
import javax.swing.text.NumberFormatter ;
import java.awt.* ;
import java.awt.event.* ;
import java.awt.BorderLayout ;
import java.awt.Color ;
import java.awt.Component ;
import java.awt.Dimension ;
import java.awt.EventQueue ;
import java.awt.FlowLayout ;
import java.awt.Font ;
import java.awt.Graphics ;
import java.awt.Graphics2D ;
import java.awt.Point ;
import java.awt.Rectangle ;
import java.awt.event.ActionEvent ;
import java.awt.event.ActionListener ;
import java.awt.event.ItemEvent ;
import java.awt.event.ItemListener ;
import java.awt.event.MouseEvent ;
import java.math.BigDecimal ;
/ * *
@ -55,7 +78,6 @@ public class JSliderPane extends JPanel {
private static final Color BACK_COLOR = new Color ( 245 , 245 , 247 ) ;
public int showValue = 100 ;
public double resolutionTimes = 1 . 0 ;
private static JSliderPane THIS ;
private UITextField showVal ;
private JSpinner showValSpinner ;
private UISlider slider ;
@ -66,12 +88,14 @@ public class JSliderPane extends JPanel {
private UISliderButton showValButton ;
private UIRadioButton twoHundredButton ;
private UIRadioButton oneHundredButton ;
private UIRadioButton S evenFiveButton;
private UIRadioButton s evenFiveButton;
private UIRadioButton fiveTenButton ;
private UIRadioButton twoFiveButton ;
private UIRadioButton selfAdaptButton ;
private UIRadioButton customButton ;
//拖动条处理和button、直接输入不一样
/ * *
* 拖动条处理和button 、 直接输入不一样
* /
private boolean isButtonOrIsTxt = true ;
private PopupPane dialog ;
private int upButtonX ;
@ -95,7 +119,7 @@ public class JSliderPane extends JPanel {
initShowValButton ( ) ;
initUIRadioButton ( ) ;
initPane ( ) ;
JPanel panel = new JPanel ( new FlowLayout ( 1 , 0 , 0 ) ) ;
JPanel panel = new JPanel ( new FlowLayout ( FlowLayout . CENTER , 0 , 0 ) ) ;
panel . add ( downButton ) ;
panel . add ( slider ) ;
panel . add ( upButton ) ;
@ -105,12 +129,8 @@ public class JSliderPane extends JPanel {
}
public static final JSliderPane getInstance ( ) {
// if (THIS == null) {
// THIS = new JSliderPane();
// }
THIS = new JSliderPane ( ) ;
return THIS ;
public static JSliderPane getInstance ( ) {
return new JSliderPane ( ) ;
}
private void initSlider ( ) {
@ -174,7 +194,7 @@ public class JSliderPane extends JPanel {
private void initUIRadioButton ( ) {
twoHundredButton = new UIRadioButton ( "200%" ) ;
oneHundredButton = new UIRadioButton ( "100%" ) ;
S evenFiveButton = new UIRadioButton ( "75%" ) ;
s evenFiveButton = new UIRadioButton ( "75%" ) ;
fiveTenButton = new UIRadioButton ( "50%" ) ;
twoFiveButton = new UIRadioButton ( "25%" ) ;
selfAdaptButton = new UIRadioButton ( Inter . getLocText ( "FR-Designer_Scale_selfAdaptButton" ) ) ;
@ -183,7 +203,7 @@ public class JSliderPane extends JPanel {
customButton . setFont ( new Font ( "SimSun" , Font . PLAIN , FONT_SIZE ) ) ;
twoHundredButton . addItemListener ( radioButtonItemListener ) ;
oneHundredButton . addItemListener ( radioButtonItemListener ) ;
S evenFiveButton. addItemListener ( radioButtonItemListener ) ;
s evenFiveButton. addItemListener ( radioButtonItemListener ) ;
fiveTenButton . addItemListener ( radioButtonItemListener ) ;
twoFiveButton . addItemListener ( radioButtonItemListener ) ;
customButton . addItemListener ( new ItemListener ( ) {
@ -201,7 +221,7 @@ public class JSliderPane extends JPanel {
ButtonGroup bg = new ButtonGroup ( ) ; // 初始化按钮组
bg . add ( twoHundredButton ) ; // 加入按钮组
bg . add ( oneHundredButton ) ;
bg . add ( S evenFiveButton) ;
bg . add ( s evenFiveButton) ;
bg . add ( fiveTenButton ) ;
bg . add ( twoFiveButton ) ;
bg . add ( selfAdaptButton ) ;
@ -224,7 +244,7 @@ public class JSliderPane extends JPanel {
septPane . setBackground ( BACK_COLOR ) ;
twoHundredButton . setBackground ( BACK_COLOR ) ;
oneHundredButton . setBackground ( BACK_COLOR ) ;
S evenFiveButton. setBackground ( BACK_COLOR ) ;
s evenFiveButton. setBackground ( BACK_COLOR ) ;
fiveTenButton . setBackground ( BACK_COLOR ) ;
twoFiveButton . setBackground ( BACK_COLOR ) ;
selfAdaptButton . setBackground ( BACK_COLOR ) ;
@ -234,7 +254,7 @@ public class JSliderPane extends JPanel {
new Component [ ] { septPane , null } ,
new Component [ ] { twoHundredButton , null } ,
new Component [ ] { oneHundredButton , null } ,
new Component [ ] { S evenFiveButton, null } ,
new Component [ ] { s evenFiveButton, null } ,
new Component [ ] { fiveTenButton , null } ,
new Component [ ] { twoFiveButton , null } ,
new Component [ ] { selfAdaptButton , null } ,
@ -255,14 +275,14 @@ public class JSliderPane extends JPanel {
return spinnerPanel ;
}
ActionListener showValButtonActionListener = new ActionListener ( ) {
private ActionListener showValButtonActionListener = new ActionListener ( ) {
@Override
public void actionPerformed ( ActionEvent e ) {
popupDialog ( ) ;
}
} ;
ChangeListener showValSpinnerChangeListener = new ChangeListener ( ) {
private ChangeListener showValSpinnerChangeListener = new ChangeListener ( ) {
@Override
public void stateChanged ( ChangeEvent e ) {
int val = ( int ) ( ( UIBasicSpinner ) e . getSource ( ) ) . getValue ( ) ;
@ -285,7 +305,7 @@ public class JSliderPane extends JPanel {
//定义一个监听器,用于监听所有滑动条
ChangeListener listener = new ChangeListener ( ) {
private ChangeListener listener = new ChangeListener ( ) {
public void stateChanged ( ChangeEvent event ) {
//取出滑动条的值,并在文本中显示出来
if ( ! isButtonOrIsTxt ) {
@ -305,7 +325,7 @@ public class JSliderPane extends JPanel {
}
} ;
ItemListener radioButtonItemListener = new ItemListener ( ) {
private ItemListener radioButtonItemListener = new ItemListener ( ) {
@Override
public void itemStateChanged ( ItemEvent e ) {
JRadioButton temp = ( JRadioButton ) e . getSource ( ) ;
@ -321,7 +341,7 @@ public class JSliderPane extends JPanel {
slider . setValue ( ( int ) ( showValue + TWO_HUNDRED ) / SIX ) ;
} else if ( showValue < HUNDRED ) {
slider . setValue ( ( int ) ( ( showValue - TEN ) / ONEPOINTEIGHT ) ) ;
} else if ( showValue = = HUNDRED ) {
} else {
slider . setValue ( HALF_HUNDRED ) ;
}
}
@ -349,7 +369,7 @@ public class JSliderPane extends JPanel {
return b1 . divide ( b2 , scale ) . doubleValue ( ) ;
}
ActionListener buttonActionListener = new ActionListener ( ) {
private ActionListener buttonActionListener = new ActionListener ( ) {
@Override
public void actionPerformed ( ActionEvent e ) {
showValue = ( int ) showValSpinner . getValue ( ) ;
@ -386,7 +406,7 @@ public class JSliderPane extends JPanel {
} else if ( value < HALF_HUNDRED ) {
times = ( int ) Math . round ( ONEPOINTEIGHT * value + TEN ) ;
} else {
times = ( int ) ( SIX * value - TWO_HUNDRED ) ;
times = SIX * value - TWO_HUNDRED ;
}
}
@ -444,11 +464,9 @@ class JSliderPaneUI extends BasicSliderUI {
super ( b ) ;
}
/** */
/ * *
* 绘制指示物
* /
public void paintThumb ( Graphics g ) {
Rectangle knobBounds = thumbRect ;
int w = knobBounds . width ;
@ -460,7 +478,6 @@ class JSliderPaneUI extends BasicSliderUI {
g2d . fillRoundRect ( 0 , SIX , FOUR , 9 , 2 , 2 ) ;
}
/** */
/ * *
* 绘制刻度轨迹
* /