From 73a01b1730612509dafb3ee0b16bde398f3b15ca Mon Sep 17 00:00:00 2001 From: MoMeak Date: Mon, 17 Jul 2017 09:09:14 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=BC=A9=E6=94=BE=E6=9D=A1panel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/mainframe/JSliderPane.java | 256 ++++++++++++++++++ .../series/PlotSeries/MapCustomPane.java | 4 +- 2 files changed, 258 insertions(+), 2 deletions(-) create mode 100644 designer_base/src/com/fr/design/mainframe/JSliderPane.java diff --git a/designer_base/src/com/fr/design/mainframe/JSliderPane.java b/designer_base/src/com/fr/design/mainframe/JSliderPane.java new file mode 100644 index 000000000..40808db99 --- /dev/null +++ b/designer_base/src/com/fr/design/mainframe/JSliderPane.java @@ -0,0 +1,256 @@ +package com.fr.design.mainframe; + +import com.fr.base.BaseUtils; +import com.fr.design.file.MutilTempalteTabPane; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.islider.UISlider; +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 javax.swing.*; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import javax.swing.plaf.basic.BasicSliderUI; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/** + * Created by MoMeak on 2017/7/13. + */ +public class JSliderPane extends JPanel { + + private final int KERNING = 2; + private static JSliderPane THIS; + private UITextField showVal; + private UISlider slider; + private int times; + private int sliderValue; + private UIButton downButton; + private UIButton upButton; + private int showValue; + //拖动条处理和button、直接输入不一样 + private boolean isButtonOrIsTxt = true; + + + public JSliderPane() { + this.setLayout(new BorderLayout()); + slider = new UISlider(0,100,50); + slider.setUI(new JSliderPaneUI(slider)); + slider.addChangeListener(listener); + + showVal = new UITextField(); + showVal.setText("100%"); + + showVal.getDocument().addDocumentListener(showValDocumentListener); + + downButton = new UIButton(BaseUtils.readIcon("com/fr/design/images/data/source/moveDown.png")); + upButton = new UIButton(BaseUtils.readIcon("com/fr/design/images/data/source/moveUp.png")); + downButton.setActionCommand("less"); + upButton.setActionCommand("more"); + downButton.addActionListener(buttonActionListener); + upButton.addActionListener(buttonActionListener); + +// double f = TableLayout.FILL; +// double p = TableLayout.PREFERRED; +// Component[][] components = new Component[][]{ +// new Component[]{downButton, slider, upButton, showVal}, +// }; +// double[] rowSize = {p}; +// double[] columnSize = {p,p,p,p}; +// JPanel panel = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); + + JPanel panel = new JPanel(new FlowLayout(1,1,0)); + + panel.add(downButton); + panel.add(slider); + panel.add(upButton); + panel.add(showVal); + +// JPanel panel = new JPanel(null); +// panel.add(downButton); +// panel.add(slider); +// panel.add(upButton); +// panel.add(showVal); +// downButton.setBounds(0,0,16,16); +// slider.setBounds(16+KERNING,0,160,16); +// upButton.setBounds(176+KERNING*2,0,16,16); +// showVal.setBounds(192+KERNING*3,0,40,16); + this.add(panel,BorderLayout.NORTH); + this.setBounds(0,0,260,16); + } + + public static final JSliderPane getInstance() { + if (THIS == null) { + THIS = new JSliderPane(); + } + return THIS; + } + + + + //定义一个监听器,用于监听所有滑动条 + ChangeListener listener = new ChangeListener() + { + public void stateChanged( ChangeEvent event) { + //取出滑动条的值,并在文本中显示出来 + if (!isButtonOrIsTxt){ + JSlider source = (JSlider) event.getSource(); + EventQueue.invokeLater(new Runnable() { + public void run() { + sliderValue = slider.getValue(); + getTimes(sliderValue); + showVal.setText(times + "%"); + } + }); + }else { + isButtonOrIsTxt = false; + } + } + }; + + DocumentListener showValDocumentListener = new DocumentListener() { + @Override + public void insertUpdate(DocumentEvent e) { + isButtonOrIsTxt = true; + refreshSlider(); + } + + @Override + public void removeUpdate(DocumentEvent e) { +// refreshSlider(); + } + + @Override + public void changedUpdate(DocumentEvent e) { +// refreshSlider(); + } + }; + + private void refreshSlider(){ + showValue = Integer.parseInt(showVal.getText().substring(0, showVal.getText().indexOf("%"))); + if (showValue >100){ + slider.setValue((int)(showValue+200)/6); + }else if (showValue <100){ + slider.setValue((int)((showValue-10)/1.8)); + }else if (showValue == 100){ + slider.setValue(50); + } + } + + ActionListener buttonActionListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + showValue = Integer.parseInt(showVal.getText().substring(0, showVal.getText().indexOf("%"))); + isButtonOrIsTxt = true; + if(e.getActionCommand().equals("less")){ + int newDownVal = showValue - 10; + if (newDownVal >= 10 ){ + showVal.setText(newDownVal + "%"); + }else { + showVal.setText(10 + "%"); + } + } + if(e.getActionCommand().equals("more")){ + int newUpVal = showValue + 10; + if (newUpVal <= 400 ){ + showVal.setText(newUpVal + "%"); + }else { + showVal.setText(400 + "%"); + } + } + isButtonOrIsTxt = true; + } + }; + + private void getTimes(int value){ + if (value == 50){ + times=100; + }else if (value < 50){ + times = (int) Math.round(1.8*value + 10); + }else { + times = (int) (6*value - 200); + } + } + + + public static void main(String[] args) + { + JFrame jf = new JFrame("test"); + jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + JPanel content = (JPanel)jf.getContentPane(); + content.setLayout(new BorderLayout()); + content.add(JSliderPane.getInstance(),BorderLayout.CENTER); + GUICoreUtils.centerWindow(jf); + jf.setSize(320, 80); + jf.setVisible(true); + + } +} + +class JSliderPaneUI extends BasicSliderUI { + + public JSliderPaneUI(UISlider b) { + super(b); + } + + /** */ + /** + * 绘制指示物 + */ + + public Dimension getThumbSize() { + Dimension size = new Dimension(); + + if ( slider.getOrientation() == JSlider.VERTICAL ) { + size.width = 11; + size.height = 16; + } + else { + size.width = 11; + size.height = 16; + } + + return size; + } + + public void paintThumb(Graphics g) { + Rectangle knobBounds = thumbRect; + int w = knobBounds.width; + int h = knobBounds.height; + + g.translate(knobBounds.x, knobBounds.y); + if ( slider.isEnabled() ) { + g.setColor(slider.getBackground()); + } + else { + g.setColor(slider.getBackground().darker()); + } + g.setColor(Color.darkGray); + g.fillRect(0, 1, w-6, h+1); + } + + /** */ + /** + * 绘制刻度轨迹 + */ + 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; + g.setColor(Color.lightGray); + g.drawLine(0, cy, cw+5, cy); + g.drawLine(5+cw/2, cy-4, 5+cw/2, cy+4); + } else { + super.paintTrack(g); + } + } + +} diff --git a/designer_chart/src/com/fr/design/chart/series/PlotSeries/MapCustomPane.java b/designer_chart/src/com/fr/design/chart/series/PlotSeries/MapCustomPane.java index d844631c0..21a778f1a 100644 --- a/designer_chart/src/com/fr/design/chart/series/PlotSeries/MapCustomPane.java +++ b/designer_chart/src/com/fr/design/chart/series/PlotSeries/MapCustomPane.java @@ -19,7 +19,7 @@ import com.fr.general.GeneralUtils; import com.fr.general.Inter; import com.fr.general.data.DataModel; import com.fr.stable.StringUtils; -import org.apache.batik.swing.svg.SVGFileFilter; +//import org.apache.batik.swing.svg.SVGFileFilter; import javax.swing.*; import java.awt.*; @@ -107,7 +107,7 @@ refreshAreaNameBox(); public void actionPerformed(ActionEvent evt) { JFileChooser svgFileChooser = new JFileChooser(); - svgFileChooser.addChoosableFileFilter(new SVGFileFilter()); +// svgFileChooser.addChoosableFileFilter(new SVGFileFilter()); if (StringUtils.isNotBlank(lastSelectPath)) { svgFileChooser.setSelectedFile(new File(lastSelectPath)); } From 37459e61bc4d6e717a22ce7509cb2be72ea8c319 Mon Sep 17 00:00:00 2001 From: MoMeak Date: Mon, 17 Jul 2017 09:15:17 +0800 Subject: [PATCH 2/2] =?UTF-8?q?rollback=E7=BC=96=E8=AF=91=E4=B8=8D?= =?UTF-8?q?=E9=80=9A=E8=BF=87=E7=9A=84=E6=B3=A8=E9=87=8A=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/chart/series/PlotSeries/MapCustomPane.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/designer_chart/src/com/fr/design/chart/series/PlotSeries/MapCustomPane.java b/designer_chart/src/com/fr/design/chart/series/PlotSeries/MapCustomPane.java index 21a778f1a..d844631c0 100644 --- a/designer_chart/src/com/fr/design/chart/series/PlotSeries/MapCustomPane.java +++ b/designer_chart/src/com/fr/design/chart/series/PlotSeries/MapCustomPane.java @@ -19,7 +19,7 @@ import com.fr.general.GeneralUtils; import com.fr.general.Inter; import com.fr.general.data.DataModel; import com.fr.stable.StringUtils; -//import org.apache.batik.swing.svg.SVGFileFilter; +import org.apache.batik.swing.svg.SVGFileFilter; import javax.swing.*; import java.awt.*; @@ -107,7 +107,7 @@ refreshAreaNameBox(); public void actionPerformed(ActionEvent evt) { JFileChooser svgFileChooser = new JFileChooser(); -// svgFileChooser.addChoosableFileFilter(new SVGFileFilter()); + svgFileChooser.addChoosableFileFilter(new SVGFileFilter()); if (StringUtils.isNotBlank(lastSelectPath)) { svgFileChooser.setSelectedFile(new File(lastSelectPath)); }