|
|
@ -1,45 +1,34 @@ |
|
|
|
package com.fr.design.mainframe; |
|
|
|
package com.fr.design.mainframe; |
|
|
|
|
|
|
|
|
|
|
|
import com.fr.base.BaseUtils; |
|
|
|
import com.fr.base.BaseUtils; |
|
|
|
import com.fr.design.constants.LayoutConstants; |
|
|
|
|
|
|
|
import com.fr.design.gui.ibutton.UIButton; |
|
|
|
import com.fr.design.gui.ibutton.UIButton; |
|
|
|
import com.fr.design.gui.ibutton.UIRadioButton; |
|
|
|
|
|
|
|
import com.fr.design.gui.ibutton.UISliderButton; |
|
|
|
|
|
|
|
import com.fr.design.gui.ilable.UILabel; |
|
|
|
import com.fr.design.gui.ilable.UILabel; |
|
|
|
import com.fr.design.gui.islider.UISlider; |
|
|
|
import com.fr.design.gui.islider.UISlider; |
|
|
|
import com.fr.design.gui.ispinner.UIBasicSpinner; |
|
|
|
import com.fr.design.gui.itextfield.UINumberField; |
|
|
|
import com.fr.design.gui.itextfield.UITextField; |
|
|
|
|
|
|
|
import com.fr.design.layout.TableLayout; |
|
|
|
|
|
|
|
import com.fr.design.layout.TableLayoutHelper; |
|
|
|
|
|
|
|
import com.fr.design.utils.gui.GUICoreUtils; |
|
|
|
import com.fr.design.utils.gui.GUICoreUtils; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.BorderFactory; |
|
|
|
import javax.swing.BorderFactory; |
|
|
|
import javax.swing.ButtonGroup; |
|
|
|
|
|
|
|
import javax.swing.JFormattedTextField; |
|
|
|
|
|
|
|
import javax.swing.JFrame; |
|
|
|
import javax.swing.JFrame; |
|
|
|
import javax.swing.JPanel; |
|
|
|
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.ChangeEvent; |
|
|
|
import javax.swing.event.ChangeListener; |
|
|
|
import javax.swing.event.ChangeListener; |
|
|
|
import javax.swing.text.DefaultFormatterFactory; |
|
|
|
import javax.swing.plaf.basic.BasicSliderUI; |
|
|
|
import javax.swing.text.NumberFormatter; |
|
|
|
|
|
|
|
import java.awt.BorderLayout; |
|
|
|
import java.awt.BorderLayout; |
|
|
|
import java.awt.Color; |
|
|
|
import java.awt.Color; |
|
|
|
import java.awt.Component; |
|
|
|
|
|
|
|
import java.awt.Dimension; |
|
|
|
import java.awt.Dimension; |
|
|
|
import java.awt.EventQueue; |
|
|
|
import java.awt.EventQueue; |
|
|
|
import java.awt.FlowLayout; |
|
|
|
import java.awt.FlowLayout; |
|
|
|
import java.awt.Font; |
|
|
|
import java.awt.Graphics; |
|
|
|
|
|
|
|
import java.awt.Graphics2D; |
|
|
|
|
|
|
|
import java.awt.Image; |
|
|
|
import java.awt.Point; |
|
|
|
import java.awt.Point; |
|
|
|
|
|
|
|
import java.awt.Rectangle; |
|
|
|
import java.awt.event.ActionEvent; |
|
|
|
import java.awt.event.ActionEvent; |
|
|
|
import java.awt.event.ActionListener; |
|
|
|
import java.awt.event.ActionListener; |
|
|
|
import java.awt.event.ItemEvent; |
|
|
|
import java.awt.event.FocusEvent; |
|
|
|
import java.awt.event.ItemListener; |
|
|
|
import java.awt.event.FocusListener; |
|
|
|
|
|
|
|
import java.awt.event.KeyEvent; |
|
|
|
|
|
|
|
import java.awt.event.KeyListener; |
|
|
|
import java.awt.event.MouseEvent; |
|
|
|
import java.awt.event.MouseEvent; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.math.BigDecimal; |
|
|
|
|
|
|
|
|
|
|
@ -47,76 +36,44 @@ import java.math.BigDecimal; |
|
|
|
* Created by MoMeak on 2017/7/13. |
|
|
|
* Created by MoMeak on 2017/7/13. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class JFormSliderPane extends JPanel { |
|
|
|
public class JFormSliderPane extends JPanel { |
|
|
|
|
|
|
|
public static final Image APPFIT_V0 = BaseUtils.readImage("com/fr/design/images/control/icon_thumb_normal.png"); |
|
|
|
|
|
|
|
|
|
|
|
private static final double ONEPOINTEIGHT = 1.8; |
|
|
|
private static final double ONEPOINTEIGHT = 1.8; |
|
|
|
private static final int SIX = 6; |
|
|
|
private static final int SIX = 6; |
|
|
|
private static final int TEN = 10; |
|
|
|
private static final int TEN = 10; |
|
|
|
private static final int ONE_EIGHT = 18; |
|
|
|
|
|
|
|
private static final int FONT_SIZE = 12; |
|
|
|
|
|
|
|
private static final int SPINNER_WIDTH = 45; |
|
|
|
|
|
|
|
private static final int SPINNER_HEIGHT = 20; |
|
|
|
|
|
|
|
private static final int HALF_HUNDRED = 50; |
|
|
|
private static final int HALF_HUNDRED = 50; |
|
|
|
private static final int HUNDRED = 100; |
|
|
|
private static final int HUNDRED = 100; |
|
|
|
private static final int TWO_HUNDRED = 200; |
|
|
|
private static final int TWO_HUNDRED = 200; |
|
|
|
private static final int THREE_HUNDRED = 300; |
|
|
|
|
|
|
|
private static final int FOUR_HUNDRED = 400; |
|
|
|
private static final int FOUR_HUNDRED = 400; |
|
|
|
private static final int DIALOG_WIDTH = 157; |
|
|
|
private static final int SHOWVALBUTTON_WIDTH = 35; |
|
|
|
private static final int DIALOG_HEIGHT = 172; |
|
|
|
|
|
|
|
private static final int SLIDER_WIDTH = 220; |
|
|
|
|
|
|
|
private static final int SLIDER_HEIGHT = 20; |
|
|
|
|
|
|
|
private static final int SHOWVALBUTTON_WIDTH = 40; |
|
|
|
|
|
|
|
private static final int SHOWVALBUTTON_HEIGHTH = 20; |
|
|
|
private static final int SHOWVALBUTTON_HEIGHTH = 20; |
|
|
|
private static final int SLIDER_GAP = 5; |
|
|
|
private static final String SUFFIX = "%"; |
|
|
|
private static final int TOOLTIP_Y = 30; |
|
|
|
private static final int TOOLTIP_Y = 30; |
|
|
|
private static final Color BACK_COLOR = new Color(245, 245, 247); |
|
|
|
private static final Color BACK_COLOR = new Color(245, 245, 247); |
|
|
|
public int showValue = 100; |
|
|
|
public int showValue = 100; |
|
|
|
public double resolutionTimes = 1.0; |
|
|
|
private UINumberField showValField; |
|
|
|
private UITextField showVal; |
|
|
|
|
|
|
|
private JSpinner showValSpinner; |
|
|
|
|
|
|
|
private UISlider slider; |
|
|
|
private UISlider slider; |
|
|
|
private int times; |
|
|
|
private int times; |
|
|
|
private int sliderValue; |
|
|
|
private int sliderValue; |
|
|
|
private UIButton downButton; |
|
|
|
private UIButton downButton; |
|
|
|
private UIButton upButton; |
|
|
|
private UIButton upButton; |
|
|
|
private UISliderButton showValButton; |
|
|
|
|
|
|
|
private UIRadioButton twoHundredButton; |
|
|
|
|
|
|
|
private UIRadioButton oneHundredButton; |
|
|
|
|
|
|
|
private UIRadioButton sevenFiveButton; |
|
|
|
|
|
|
|
private UIRadioButton fiveTenButton; |
|
|
|
|
|
|
|
private UIRadioButton twoFiveButton; |
|
|
|
|
|
|
|
private UIRadioButton selfAdaptButton; |
|
|
|
|
|
|
|
private UIRadioButton customButton; |
|
|
|
|
|
|
|
//拖动条处理和button、直接输入不一样
|
|
|
|
//拖动条处理和button、直接输入不一样
|
|
|
|
private boolean isButtonOrIsTxt = true; |
|
|
|
private boolean isButtonOrIsTxt = true; |
|
|
|
//是否选中指定的几个缩放等级,避免触发不必要的事件
|
|
|
|
|
|
|
|
private boolean selectSpecified = false; |
|
|
|
|
|
|
|
private FormPopupPane dialog; |
|
|
|
|
|
|
|
private int upButtonX; |
|
|
|
|
|
|
|
private JPanel dialogContentPanel; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public JFormSliderPane() { |
|
|
|
public JFormSliderPane() { |
|
|
|
this.setLayout(new BorderLayout()); |
|
|
|
this.setLayout(new BorderLayout()); |
|
|
|
initSlider(); |
|
|
|
initSlider(); |
|
|
|
initShowValSpinner(); |
|
|
|
|
|
|
|
//MoMeak:控制只能输入10-400
|
|
|
|
|
|
|
|
JSpinner.NumberEditor editor = new JSpinner.NumberEditor(showValSpinner, "0"); |
|
|
|
|
|
|
|
showValSpinner.setEditor(editor); |
|
|
|
|
|
|
|
JFormattedTextField textField = ((JSpinner.NumberEditor) showValSpinner.getEditor()).getTextField(); |
|
|
|
|
|
|
|
textField.setEditable(true); |
|
|
|
|
|
|
|
DefaultFormatterFactory factory = (DefaultFormatterFactory) textField.getFormatterFactory(); |
|
|
|
|
|
|
|
NumberFormatter formatter = (NumberFormatter) factory.getDefaultFormatter(); |
|
|
|
|
|
|
|
formatter.setAllowsInvalid(false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
initDownUpButton(); |
|
|
|
initDownUpButton(); |
|
|
|
initShowValButton(); |
|
|
|
initShowValField(); |
|
|
|
initUIRadioButton(); |
|
|
|
|
|
|
|
initPane(); |
|
|
|
|
|
|
|
JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0)); |
|
|
|
JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0)); |
|
|
|
panel.add(downButton); |
|
|
|
panel.add(downButton); |
|
|
|
panel.add(slider); |
|
|
|
panel.add(slider); |
|
|
|
panel.add(upButton); |
|
|
|
panel.add(upButton); |
|
|
|
panel.add(showValButton); |
|
|
|
panel.add(showValField); |
|
|
|
|
|
|
|
UILabel uiLabel = new UILabel(SUFFIX); |
|
|
|
|
|
|
|
uiLabel.setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 4)); |
|
|
|
|
|
|
|
panel.add(uiLabel); |
|
|
|
panel.setBackground(BACK_COLOR); |
|
|
|
panel.setBackground(BACK_COLOR); |
|
|
|
this.add(panel, BorderLayout.NORTH); |
|
|
|
this.add(panel, BorderLayout.NORTH); |
|
|
|
} |
|
|
|
} |
|
|
@ -131,6 +88,7 @@ public class JFormSliderPane extends JPanel { |
|
|
|
return new Point(event.getX(), event.getY() - TOOLTIP_Y); |
|
|
|
return new Point(event.getX(), event.getY() - TOOLTIP_Y); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
slider.setValue(HALF_HUNDRED); |
|
|
|
slider.setUI(new JSliderPaneUI(slider)); |
|
|
|
slider.setUI(new JSliderPaneUI(slider)); |
|
|
|
slider.addChangeListener(listener); |
|
|
|
slider.addChangeListener(listener); |
|
|
|
slider.setPreferredSize(new Dimension(220, 20)); |
|
|
|
slider.setPreferredSize(new Dimension(220, 20)); |
|
|
@ -139,16 +97,6 @@ public class JFormSliderPane extends JPanel { |
|
|
|
slider.setToolTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Scale_Slider")); |
|
|
|
slider.setToolTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Scale_Slider")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void initShowValSpinner() { |
|
|
|
|
|
|
|
showValSpinner = new UIBasicSpinner(new SpinnerNumberModel(HUNDRED, 0, FOUR_HUNDRED, 1)) { |
|
|
|
|
|
|
|
public Point getToolTipLocation(MouseEvent event) { |
|
|
|
|
|
|
|
return new Point(event.getX(), event.getY() - TOOLTIP_Y); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
showValSpinner.setEnabled(true); |
|
|
|
|
|
|
|
showValSpinner.addChangeListener(showValSpinnerChangeListener); |
|
|
|
|
|
|
|
showValSpinner.setPreferredSize(new Dimension(SPINNER_WIDTH, SPINNER_HEIGHT)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void initDownUpButton() { |
|
|
|
private void initDownUpButton() { |
|
|
|
downButton = new UIButton(BaseUtils.readIcon("com/fr/design/images/data/source/normalDown20.png"), BaseUtils.readIcon("com/fr/design/images/data/source/hoverDown20.png"), BaseUtils.readIcon("com/fr/design/images/data/source/hoverDown20.png")) { |
|
|
|
downButton = new UIButton(BaseUtils.readIcon("com/fr/design/images/data/source/normalDown20.png"), BaseUtils.readIcon("com/fr/design/images/data/source/hoverDown20.png"), BaseUtils.readIcon("com/fr/design/images/data/source/hoverDown20.png")) { |
|
|
@ -173,142 +121,78 @@ public class JFormSliderPane extends JPanel { |
|
|
|
upButton.addActionListener(buttonActionListener); |
|
|
|
upButton.addActionListener(buttonActionListener); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void initShowValButton() { |
|
|
|
private void initShowValField() { |
|
|
|
showValButton = new UISliderButton(showValSpinner.getValue() + "%"); |
|
|
|
showValField = new UINumberField(); |
|
|
|
showValButton.setBackground(BACK_COLOR); |
|
|
|
showValField.setValue(showValue); |
|
|
|
showValButton.setBorderPainted(false); |
|
|
|
showValField.setPreferredSize(new Dimension(SHOWVALBUTTON_WIDTH, SHOWVALBUTTON_HEIGHTH)); |
|
|
|
showValButton.setPreferredSize(new Dimension(SHOWVALBUTTON_WIDTH, SHOWVALBUTTON_HEIGHTH)); |
|
|
|
showValField.addKeyListener(new KeyListener() { |
|
|
|
showValButton.addActionListener(showValButtonActionListener); |
|
|
|
@Override |
|
|
|
showValButton.setToolTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Scale_Grade")); |
|
|
|
public void keyTyped(KeyEvent e) { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void initUIRadioButton() { |
|
|
|
|
|
|
|
twoHundredButton = new UIRadioButton("200%"); |
|
|
|
|
|
|
|
oneHundredButton = new UIRadioButton("100%"); |
|
|
|
|
|
|
|
sevenFiveButton = new UIRadioButton("75%"); |
|
|
|
|
|
|
|
fiveTenButton = new UIRadioButton("50%"); |
|
|
|
|
|
|
|
twoFiveButton = new UIRadioButton("25%"); |
|
|
|
|
|
|
|
selfAdaptButton = new UIRadioButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Scale_Self_Adapt_Button")); |
|
|
|
|
|
|
|
selfAdaptButton.setFont(new Font("SimSun", Font.PLAIN, FONT_SIZE)); |
|
|
|
|
|
|
|
customButton = new UIRadioButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Scale_Custom_Button")); |
|
|
|
|
|
|
|
customButton.setFont(new Font("SimSun", Font.PLAIN, FONT_SIZE)); |
|
|
|
|
|
|
|
twoHundredButton.addItemListener(radioButtonItemListener); |
|
|
|
|
|
|
|
oneHundredButton.addItemListener(radioButtonItemListener); |
|
|
|
|
|
|
|
sevenFiveButton.addItemListener(radioButtonItemListener); |
|
|
|
|
|
|
|
fiveTenButton.addItemListener(radioButtonItemListener); |
|
|
|
|
|
|
|
twoFiveButton.addItemListener(radioButtonItemListener); |
|
|
|
|
|
|
|
customButton.addItemListener(new ItemListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void itemStateChanged(ItemEvent e) { |
|
|
|
public void keyPressed(KeyEvent e) { |
|
|
|
JRadioButton temp = (JRadioButton) e.getSource(); |
|
|
|
|
|
|
|
if (temp.isSelected()) { |
|
|
|
} |
|
|
|
JFormattedTextField textField = ((JSpinner.NumberEditor) showValSpinner.getEditor()).getTextField(); |
|
|
|
|
|
|
|
textField.requestFocus(); |
|
|
|
@Override |
|
|
|
textField.selectAll(); |
|
|
|
public void keyReleased(KeyEvent evt) { |
|
|
|
|
|
|
|
int code = evt.getKeyCode(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (code == KeyEvent.VK_ENTER) { |
|
|
|
|
|
|
|
showValFieldChange((int) showValField.getValue()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
showValField.addFocusListener(new FocusListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void focusGained(FocusEvent e) { |
|
|
|
|
|
|
|
|
|
|
|
ButtonGroup bg = new ButtonGroup();// 初始化按钮组
|
|
|
|
} |
|
|
|
bg.add(twoHundredButton);// 加入按钮组
|
|
|
|
|
|
|
|
bg.add(oneHundredButton); |
|
|
|
|
|
|
|
bg.add(sevenFiveButton); |
|
|
|
|
|
|
|
bg.add(fiveTenButton); |
|
|
|
|
|
|
|
bg.add(twoFiveButton); |
|
|
|
|
|
|
|
bg.add(selfAdaptButton); |
|
|
|
|
|
|
|
bg.add(customButton); |
|
|
|
|
|
|
|
customButton.setSelected(true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void initPane() { |
|
|
|
@Override |
|
|
|
double p = TableLayout.PREFERRED; |
|
|
|
public void focusLost(FocusEvent e) { |
|
|
|
double f = TableLayout.FILL; |
|
|
|
showValFieldChange((int) showValField.getValue()); |
|
|
|
double[] columnSize = {p, f}; |
|
|
|
} |
|
|
|
double[] rowSize = {p, p, p, p, p, p, p, p}; |
|
|
|
}); |
|
|
|
UILabel upLabel = new UILabel(" " + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Scale_EnlargeOrReduce")); |
|
|
|
|
|
|
|
upLabel.setOpaque(false); |
|
|
|
|
|
|
|
JPanel septPane = new JPanel(new BorderLayout()); |
|
|
|
|
|
|
|
JSeparator sept = new JSeparator(); |
|
|
|
|
|
|
|
sept.setBackground(new Color(232, 232, 233)); |
|
|
|
|
|
|
|
septPane.add(sept, BorderLayout.NORTH); |
|
|
|
|
|
|
|
septPane.setBorder(BorderFactory.createEmptyBorder(2, 5, 1, 10)); |
|
|
|
|
|
|
|
septPane.setBackground(BACK_COLOR); |
|
|
|
|
|
|
|
twoHundredButton.setBackground(BACK_COLOR); |
|
|
|
|
|
|
|
oneHundredButton.setBackground(BACK_COLOR); |
|
|
|
|
|
|
|
sevenFiveButton.setBackground(BACK_COLOR); |
|
|
|
|
|
|
|
fiveTenButton.setBackground(BACK_COLOR); |
|
|
|
|
|
|
|
twoFiveButton.setBackground(BACK_COLOR); |
|
|
|
|
|
|
|
// selfAdaptButton.setBackground(BACK_COLOR);
|
|
|
|
|
|
|
|
customButton.setBackground(BACK_COLOR); |
|
|
|
|
|
|
|
Component[][] components = new Component[][]{ |
|
|
|
|
|
|
|
new Component[]{upLabel, null}, |
|
|
|
|
|
|
|
new Component[]{septPane, null}, |
|
|
|
|
|
|
|
new Component[]{twoHundredButton, null}, |
|
|
|
|
|
|
|
new Component[]{oneHundredButton, null}, |
|
|
|
|
|
|
|
new Component[]{sevenFiveButton, null}, |
|
|
|
|
|
|
|
new Component[]{fiveTenButton, null}, |
|
|
|
|
|
|
|
new Component[]{twoFiveButton, null}, |
|
|
|
|
|
|
|
new Component[]{customButton, createSpinnerPanel()} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
dialogContentPanel = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, LayoutConstants.VGAP_MEDIUM, 0); |
|
|
|
|
|
|
|
dialogContentPanel.setBackground(BACK_COLOR); |
|
|
|
|
|
|
|
dialogContentPanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private JPanel createSpinnerPanel() { |
|
|
|
|
|
|
|
JPanel spinnerPanel = new JPanel(new FlowLayout()); |
|
|
|
|
|
|
|
spinnerPanel.add(showValSpinner); |
|
|
|
private void showValFieldChange(int value) { |
|
|
|
UILabel percent = new UILabel("%"); |
|
|
|
isButtonOrIsTxt = true; |
|
|
|
percent.setFont(new Font("SimSun", Font.PLAIN, FONT_SIZE)); |
|
|
|
showValue = getPreferredValue(value); |
|
|
|
spinnerPanel.add(percent); |
|
|
|
refreshShowValueFieldText(); |
|
|
|
spinnerPanel.setBackground(BACK_COLOR); |
|
|
|
refreshSlider(); |
|
|
|
return spinnerPanel; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private ActionListener showValButtonActionListener = new ActionListener() { |
|
|
|
private int getPreferredValue(int value){ |
|
|
|
@Override |
|
|
|
if (value > FOUR_HUNDRED) { |
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
value = FOUR_HUNDRED; |
|
|
|
popupDialog(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
if (value < TEN) { |
|
|
|
|
|
|
|
value = TEN; |
|
|
|
private ChangeListener showValSpinnerChangeListener = new ChangeListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void stateChanged(ChangeEvent e) { |
|
|
|
|
|
|
|
int val = (int) ((UIBasicSpinner) e.getSource()).getValue(); |
|
|
|
|
|
|
|
isButtonOrIsTxt = true; |
|
|
|
|
|
|
|
resolutionTimes = divide(showValue, 100, 2); |
|
|
|
|
|
|
|
if (val > FOUR_HUNDRED) { |
|
|
|
|
|
|
|
showValSpinner.setValue(FOUR_HUNDRED); |
|
|
|
|
|
|
|
val = FOUR_HUNDRED; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (val < TEN) { |
|
|
|
|
|
|
|
showValSpinner.setValue(TEN); |
|
|
|
|
|
|
|
val = TEN; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
refreshSlider(val); |
|
|
|
|
|
|
|
refreshBottun(val); |
|
|
|
|
|
|
|
JFormattedTextField textField = ((JSpinner.NumberEditor) showValSpinner.getEditor()).getTextField(); |
|
|
|
|
|
|
|
textField.setCaretPosition(showValSpinner.getValue().toString().length()); |
|
|
|
|
|
|
|
if (!selectSpecified) { |
|
|
|
|
|
|
|
customButton.setSelected(true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
return value; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void refreshShowValueFieldText(){ |
|
|
|
|
|
|
|
showValField.setValue(showValue); |
|
|
|
|
|
|
|
setAdjustButtonStatus(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//定义一个监听器,用于监听所有滑动条
|
|
|
|
//定义一个监听器,用于监听所有滑动条
|
|
|
|
private ChangeListener listener = new ChangeListener() { |
|
|
|
private ChangeListener listener = new ChangeListener() { |
|
|
|
public void stateChanged(ChangeEvent event) { |
|
|
|
public void stateChanged(ChangeEvent event) { |
|
|
|
//取出滑动条的值,并在文本中显示出来
|
|
|
|
//取出滑动条的值,并在文本中显示出来
|
|
|
|
if (!isButtonOrIsTxt) { |
|
|
|
if (!isButtonOrIsTxt) { |
|
|
|
customButton.setSelected(true); |
|
|
|
|
|
|
|
EventQueue.invokeLater(new Runnable() { |
|
|
|
EventQueue.invokeLater(new Runnable() { |
|
|
|
public void run() { |
|
|
|
public void run() { |
|
|
|
sliderValue = slider.getValue(); |
|
|
|
sliderValue = slider.getValue(); |
|
|
|
getTimes(sliderValue); |
|
|
|
getTimes(sliderValue); |
|
|
|
showValue = times; |
|
|
|
showValue = times; |
|
|
|
showValSpinner.setValue(times); |
|
|
|
refreshShowValueFieldText(); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -317,41 +201,28 @@ public class JFormSliderPane extends JPanel { |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
private ItemListener radioButtonItemListener = new ItemListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void itemStateChanged(ItemEvent e) { |
|
|
|
|
|
|
|
JRadioButton temp = (JRadioButton) e.getSource(); |
|
|
|
|
|
|
|
if (temp.isSelected()) { |
|
|
|
|
|
|
|
selectSpecified = true; |
|
|
|
|
|
|
|
showValSpinner.setValue(Integer.valueOf(temp.getText().substring(0, temp.getText().indexOf("%")))); |
|
|
|
|
|
|
|
selectSpecified = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void refreshSlider(int val) { |
|
|
|
private void refreshSlider() { |
|
|
|
showValue = val; |
|
|
|
slider.setValue(calSliderValue(showValue)); |
|
|
|
if (showValue > HUNDRED) { |
|
|
|
|
|
|
|
slider.setValue((int) (showValue + TWO_HUNDRED) / SIX); |
|
|
|
|
|
|
|
} else if (showValue < HUNDRED) { |
|
|
|
|
|
|
|
slider.setValue((int) ((showValue - TEN) / ONEPOINTEIGHT)); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
slider.setValue(HALF_HUNDRED); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void setAdjustButtonStatus(){ |
|
|
|
private void refreshBottun(int val) { |
|
|
|
this.downButton.setEnabled(this.showValue > TEN); |
|
|
|
showValButton.setText(val + "%"); |
|
|
|
this.upButton.setEnabled(this.showValue < FOUR_HUNDRED); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public double getResolutionTimes() { |
|
|
|
private int calSliderValue(int value) { |
|
|
|
return this.resolutionTimes; |
|
|
|
int result; |
|
|
|
|
|
|
|
if (value > HUNDRED) { |
|
|
|
|
|
|
|
result = (value + TWO_HUNDRED) / SIX; |
|
|
|
|
|
|
|
} else if (value < HUNDRED) { |
|
|
|
|
|
|
|
result = (int) ((value - TEN) / ONEPOINTEIGHT); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
result = HALF_HUNDRED; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public int getshowValue() { |
|
|
|
|
|
|
|
return this.showValue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static double divide(double v1, double v2, int scale) { |
|
|
|
public static double divide(double v1, double v2, int scale) { |
|
|
|
BigDecimal b1 = new BigDecimal(Double.toString(v1)); |
|
|
|
BigDecimal b1 = new BigDecimal(Double.toString(v1)); |
|
|
@ -362,30 +233,28 @@ public class JFormSliderPane extends JPanel { |
|
|
|
private ActionListener buttonActionListener = new ActionListener() { |
|
|
|
private ActionListener buttonActionListener = new ActionListener() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
showValue = (int) showValSpinner.getValue(); |
|
|
|
|
|
|
|
isButtonOrIsTxt = true; |
|
|
|
isButtonOrIsTxt = true; |
|
|
|
if ("less".equals(e.getActionCommand())) { |
|
|
|
if ("less".equals(e.getActionCommand())) { |
|
|
|
int newDownVal = showValue - TEN; |
|
|
|
int newDownVal = showValue - TEN; |
|
|
|
if (newDownVal >= TEN) { |
|
|
|
if (newDownVal >= TEN) { |
|
|
|
showValue = newDownVal; |
|
|
|
showValue = newDownVal; |
|
|
|
showValSpinner.setValue(newDownVal); |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
showValue = newDownVal; |
|
|
|
showValue = TEN; |
|
|
|
showValSpinner.setValue(TEN); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
refreshShowValueFieldText(); |
|
|
|
|
|
|
|
refreshSlider(); |
|
|
|
} |
|
|
|
} |
|
|
|
if ("more".equals(e.getActionCommand())) { |
|
|
|
if ("more".equals(e.getActionCommand())) { |
|
|
|
int newUpVal = showValue + TEN; |
|
|
|
int newUpVal = showValue + TEN; |
|
|
|
if (newUpVal <= FOUR_HUNDRED) { |
|
|
|
if (newUpVal <= FOUR_HUNDRED) { |
|
|
|
showValue = newUpVal; |
|
|
|
showValue = newUpVal; |
|
|
|
showValSpinner.setValue(newUpVal); |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
showValue = newUpVal; |
|
|
|
showValue = FOUR_HUNDRED; |
|
|
|
showValSpinner.setValue(FOUR_HUNDRED); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
refreshShowValueFieldText(); |
|
|
|
|
|
|
|
refreshSlider(); |
|
|
|
} |
|
|
|
} |
|
|
|
isButtonOrIsTxt = true; |
|
|
|
isButtonOrIsTxt = true; |
|
|
|
customButton.setSelected(true); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -396,35 +265,72 @@ public class JFormSliderPane extends JPanel { |
|
|
|
} else if (value < HALF_HUNDRED) { |
|
|
|
} else if (value < HALF_HUNDRED) { |
|
|
|
times = (int) Math.round(ONEPOINTEIGHT * value + TEN); |
|
|
|
times = (int) Math.round(ONEPOINTEIGHT * value + TEN); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
times = (int) (SIX * value - TWO_HUNDRED); |
|
|
|
times = SIX * value - TWO_HUNDRED; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public JSpinner getShowVal() { |
|
|
|
public int getShowValue() { |
|
|
|
return this.showValSpinner; |
|
|
|
return this.showValue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public UIRadioButton getSelfAdaptButton() { |
|
|
|
public void setShowValue(int value) { |
|
|
|
return this.selfAdaptButton; |
|
|
|
showValFieldChange(value); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void popupDialog() { |
|
|
|
|
|
|
|
Point btnCoords = upButton.getLocationOnScreen(); |
|
|
|
public void addValueChangeListener(ChangeListener changeListener){ |
|
|
|
if (dialog == null) { |
|
|
|
this.slider.addChangeListener(changeListener); |
|
|
|
dialog = new FormPopupPane(upButton, dialogContentPanel); |
|
|
|
} |
|
|
|
if (upButtonX == 0) { |
|
|
|
|
|
|
|
upButtonX = btnCoords.x; |
|
|
|
class JSliderPaneUI extends BasicSliderUI { |
|
|
|
GUICoreUtils.showPopupMenu(dialog, upButton, -DIALOG_WIDTH + upButton.getWidth() + SHOWVALBUTTON_WIDTH, -DIALOG_HEIGHT); |
|
|
|
|
|
|
|
} |
|
|
|
private static final int THUMB_XOFFSET = 8; |
|
|
|
} else { |
|
|
|
private static final int THUMB_YOFFSET = 3; |
|
|
|
if (upButtonX == 0) { |
|
|
|
private static final int FOUR = 4; |
|
|
|
upButtonX = btnCoords.x; |
|
|
|
private static final int FIVE = 5; |
|
|
|
GUICoreUtils.showPopupMenu(dialog, upButton, -DIALOG_WIDTH + upButton.getWidth() + SHOWVALBUTTON_WIDTH, -DIALOG_HEIGHT); |
|
|
|
private static final int SIX = 6; |
|
|
|
|
|
|
|
private static final int MID_X_SHIFT = 2; // 中点标记的水平位置偏移
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public JSliderPaneUI(UISlider b) { |
|
|
|
|
|
|
|
super(b); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 绘制指示物 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public void paintThumb(Graphics g) { |
|
|
|
|
|
|
|
Rectangle knobBounds = thumbRect; |
|
|
|
|
|
|
|
Graphics2D g2d = (Graphics2D) g; |
|
|
|
|
|
|
|
g2d.drawImage(APPFIT_V0, knobBounds.x - THUMB_XOFFSET, knobBounds.y + THUMB_YOFFSET, null); |
|
|
|
|
|
|
|
g2d.dispose(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 绘制刻度轨迹 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public void paintTrack(Graphics g) { |
|
|
|
|
|
|
|
int cy, cw; |
|
|
|
|
|
|
|
Rectangle trackBounds = trackRect; |
|
|
|
|
|
|
|
if (slider.getOrientation() == UISlider.HORIZONTAL) { |
|
|
|
|
|
|
|
Graphics2D g2 = (Graphics2D) g; |
|
|
|
|
|
|
|
cy = (trackBounds.height / 2); |
|
|
|
|
|
|
|
cw = trackBounds.width; |
|
|
|
|
|
|
|
g2.setPaint(BACK_COLOR); |
|
|
|
|
|
|
|
g2.fillRect(0, -cy, cw + 10, cy * 4); |
|
|
|
|
|
|
|
g.setColor(new Color(216, 216, 216)); |
|
|
|
|
|
|
|
g.drawLine(0, cy, cw + 3, cy); |
|
|
|
|
|
|
|
g.drawLine(MID_X_SHIFT + cw / 2, cy - FOUR, MID_X_SHIFT + cw / 2, cy + FOUR); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
GUICoreUtils.showPopupMenu(dialog, upButton, -DIALOG_WIDTH + upButton.getWidth() + SHOWVALBUTTON_WIDTH, -DIALOG_HEIGHT); |
|
|
|
super.paintTrack(g); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setThumbLocation(int x, int y) { |
|
|
|
|
|
|
|
super.setThumbLocation(x, y); |
|
|
|
|
|
|
|
slider.repaint(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
public static void main(String[] args) { |
|
|
@ -440,16 +346,3 @@ public class JFormSliderPane extends JPanel { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FormPopupPane extends JPopupMenu { |
|
|
|
|
|
|
|
private static final int DIALOG_WIDTH = 157; |
|
|
|
|
|
|
|
private static final int DIALOG_HEIGHT = 172; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FormPopupPane(UIButton b, JPanel dialogContentPanel) { |
|
|
|
|
|
|
|
this.add(dialogContentPanel, BorderLayout.CENTER); |
|
|
|
|
|
|
|
this.setPreferredSize(new Dimension(DIALOG_WIDTH, DIALOG_HEIGHT)); |
|
|
|
|
|
|
|
this.setBackground(new Color(245, 245, 247)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|