From 7004bab3f53a6094658974c59c20da7babd5fbfa Mon Sep 17 00:00:00 2001 From: mengao <283296419@qq.com> Date: Fri, 15 Sep 2017 10:05:58 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E6=94=B99.0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gui/itextfield/UISearchTextField.java | 2 +- .../PlotSeries/UIGroupExtensionPane.java | 2 +- .../series/PlotStyle/ChartSelectDemoPane.java | 43 ++++++++----------- .../chart/gui/type/AbstractChartTypePane.java | 6 +-- .../chart/gui/type/ChartImagePane.java | 28 ++++++++++-- .../chart/gui/type/GisMapPlotPane.java | 4 +- .../column/VanChartColumnSeriesPane.java | 4 +- .../VanChartFormatPaneWithCheckBox.java | 2 +- .../style/StructureNodeStylePane.java | 1 + 9 files changed, 55 insertions(+), 37 deletions(-) diff --git a/designer_base/src/com/fr/design/gui/itextfield/UISearchTextField.java b/designer_base/src/com/fr/design/gui/itextfield/UISearchTextField.java index 683477bd48..5da10afad0 100644 --- a/designer_base/src/com/fr/design/gui/itextfield/UISearchTextField.java +++ b/designer_base/src/com/fr/design/gui/itextfield/UISearchTextField.java @@ -1 +1 @@ -package com.fr.design.gui.itextfield; import com.fr.design.constants.UIConstants; import com.fr.design.gui.ilable.UILabel; import com.fr.general.Inter; import javax.swing.*; import javax.swing.text.Document; import java.awt.*; import java.awt.event.*; import java.awt.geom.RoundRectangle2D; /** * Created by IntelliJ IDEA. * Author : Richer * Version: 7.0.3 * Date: 13-1-4 * Time: 上午11:07 * 带图标的文本框,可以用作搜索等用途 */ public class UISearchTextField extends UITextField { private UILabel iconLabel = new UILabel(UIConstants.SEARCH_ICON); private UILabel clearLabel = new UILabel(UIConstants.CLEAR_ICON); private UILabel infoLabel = new UILabel(Inter.getLocText("Search")); private Dimension iconSize; private Dimension infoSize; private int iconPosition = SwingConstants.LEFT; private boolean showClearIcon = true; private CellRendererPane cellRendererPane = new CellRendererPane(); public UISearchTextField() { initTextField(); } public UISearchTextField(String text) { super(text); initTextField(); } public UISearchTextField(int columns) { super(columns); initTextField(); } public UISearchTextField(String text, int columns) { super(text, columns); initTextField(); } public UISearchTextField(Document doc, String text, int columns) { super(doc, text, columns); initTextField(); } private void initTextField() { iconLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); iconLabel.setToolTipText(Inter.getLocText("Search")); clearLabel.setToolTipText(Inter.getLocText("Clear")); clearLabel.setOpaque(false); iconSize = iconLabel.getPreferredSize(); infoSize = infoLabel.getPreferredSize(); infoLabel.setEnabled(false); this.addMouseListener(new MouseAdapter() { public void mouseExited(MouseEvent e) { setMouseComponent(null); } public void mouseClicked(MouseEvent e) { if (mouseCom == clearLabel) { setText(""); } else if (mouseCom == iconLabel) { handleIconClick(); } } }); this.addMouseMotionListener(new MouseMotionListener() { public void mouseMoved(MouseEvent e) { JComponent com = getComponentAtPoint(e.getPoint()); setMouseComponent(com); } public void mouseDragged(MouseEvent e) { } }); this.addFocusListener(new FocusListener() { public void focusLost(FocusEvent e) { repaint(); } public void focusGained(FocusEvent e) { repaint(); } }); } private void handleIconClick() { } public String getToolTipText(MouseEvent event) { event.getPoint(); if (mouseCom == null) { return null; } if (mouseCom == this) { return super.getToolTipText(event); } return mouseCom.getToolTipText(event); } private int iconGap = 3; public Insets getInsets() { Insets insets = super.getInsets(); if (iconPosition == SwingConstants.LEFT) { insets.left += iconSize.width + iconGap + 2; if (this.getText() != null && this.getText().length() != 0 && showClearIcon) { insets.right += iconSize.width + iconGap + 2; } else { insets.right += iconGap; } } else { insets.left += iconGap; if (this.getText() != null && this.getText().length() != 0 && showClearIcon) { insets.right += iconSize.width + iconGap + 2; } else { insets.right += iconGap; } } return insets; } private JComponent getComponentAtPoint(Point point) { int x = (int) point.getX(); int y = (int) point.getY(); if (!contains(x, y)) { return null; } if (iconPosition == SwingConstants.LEFT) { if (x < iconSize.width + iconGap + 2) { return iconLabel; } if (getText() != null && getText().length() != 0 && showClearIcon) { if (x > getWidth() - iconSize.width - iconGap) { return clearLabel; } } } else { if (this.getText() == null || this.getText().length() == 0) { if (x > getWidth() - iconSize.width - iconGap - 2) { return iconLabel; } } if (getText() != null && getText().length() != 0 && showClearIcon) { if (x > getWidth() - iconSize.width - iconGap - 2) { return clearLabel; } } } return this; } private JComponent mouseCom; private void setMouseComponent(JComponent com) { if (mouseCom == com) { return; } if (mouseCom != null && mouseCom instanceof UILabel) { mouseCom.setBorder(null); } mouseCom = com; if (mouseCom != null && mouseCom instanceof UILabel) { mouseCom.setBorder(BorderFactory.createLineBorder(Color.ORANGE, 1)); } this.repaint(); if (mouseCom == null || mouseCom == clearLabel) { setCursor(Cursor.getDefaultCursor()); return; } if (mouseCom == this) { setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR)); return; } if (mouseCom == iconLabel) { setCursor(iconLabel.getCursor()); } } protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; int y = (int) (this.getHeight() / 2.0 - iconSize.getHeight() / 2); if (iconPosition == SwingConstants.LEFT) { cellRendererPane.paintComponent(g2d, iconLabel, this, iconGap, y, iconSize.width, iconSize.height); if (this.getText() != null && this.getText().length() != 0 && showClearIcon) { cellRendererPane.paintComponent(g2d, clearLabel, this, this.getWidth() - iconSize.width - iconGap, y, iconSize.width, iconSize.height); } } else { if (this.getText() == null || this.getText().length() == 0) { cellRendererPane.paintComponent(g2d, iconLabel, this, this.getWidth() - iconSize.width - iconGap, y, iconSize.width, iconSize.height); } else { if (showClearIcon) { cellRendererPane.paintComponent(g2d, clearLabel, this, this.getWidth() - iconSize.width - iconGap, y, iconSize.width, iconSize.height); } } } if (!this.isFocusOwner()) { if (this.getText() == null || this.getText().length() == 0) { int x = iconGap + 2; if (iconPosition == SwingConstants.LEFT) { x = iconSize.width + iconGap + 2; } y = (int) (this.getHeight() / 2.0 - infoSize.getHeight() / 2); cellRendererPane.paintComponent(g2d, infoLabel, this, x, y, infoSize.width, infoSize.height); } } } public Dimension getPreferredSize() { Insets s = super.getInsets(); Insets t = this.getInsets(); Dimension preferredSize = super.getPreferredSize(); preferredSize.setSize(preferredSize.width - (t.left + t.right - s.left - s.right), preferredSize.height + 2); return preferredSize; } protected void paintBorder(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (this.isFocusOwner()) { g2d.setStroke(new BasicStroke(1.5f)); } else { g2d.setStroke(new BasicStroke(1f)); } RoundRectangle2D.Double rect = new RoundRectangle2D.Double(0, 0, this.getWidth() - 2, this.getHeight() - 2, 4, 4); g2d.setColor(new Color(0, 100, 100, 150)); g2d.draw(rect); } public int getIconPosition() { return iconPosition; } public void setIconPosition(int iconPosition) { this.iconPosition = iconPosition; this.invalidate(); this.repaint(); } public boolean isShowClearIcon() { return showClearIcon; } public void setShowClearIcon(boolean showClearIcon) { this.showClearIcon = showClearIcon; this.repaint(); } public static void main(String[] args) { JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT)); UISearchTextField comp = new UISearchTextField(20); p.add(comp); comp = new UISearchTextField(20); comp.setShowClearIcon(false); p.add(comp); comp = new UISearchTextField(20); comp.setIconPosition(SwingConstants.RIGHT); p.add(comp); comp = new UISearchTextField(20); comp.setShowClearIcon(false); comp.setIconPosition(SwingConstants.RIGHT); p.add(comp); p.add(new JTextField(20)); JFrame frame = new JFrame(); frame.setTitle("UITextField"); frame.setContentPane(p); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300, 200); frame.setLocationRelativeTo(null); frame.setVisible(true); } } \ No newline at end of file +package com.fr.design.gui.itextfield; import com.fr.design.constants.UIConstants; import com.fr.design.gui.ilable.UILabel; import com.fr.general.Inter; import javax.swing.*; import javax.swing.text.Document; import java.awt.*; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionListener; import java.awt.geom.RoundRectangle2D; /** * Created by IntelliJ IDEA. * Author : Richer * Version: 7.0.3 * Date: 13-1-4 * Time: 上午11:07 * 带图标的文本框,可以用作搜索等用途 */ public class UISearchTextField extends UITextField { private UILabel iconLabel = new UILabel(UIConstants.SEARCH_ICON); private UILabel clearLabel = new UILabel(UIConstants.CLEAR_ICON); private UILabel infoLabel = new UILabel(Inter.getLocText("Search")); private Dimension iconSize; private Dimension infoSize; private int iconPosition = SwingConstants.LEFT; private boolean showClearIcon = true; private CellRendererPane cellRendererPane = new CellRendererPane(); public UISearchTextField() { initTextField(); } public UISearchTextField(String text) { super(text); initTextField(); } public UISearchTextField(int columns) { super(columns); initTextField(); } public UISearchTextField(String text, int columns) { super(text, columns); initTextField(); } public UISearchTextField(Document doc, String text, int columns) { super(doc, text, columns); initTextField(); } private void initTextField() { iconLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); iconLabel.setToolTipText(Inter.getLocText("Search")); clearLabel.setToolTipText(Inter.getLocText("Clear")); clearLabel.setOpaque(false); iconSize = iconLabel.getPreferredSize(); infoSize = infoLabel.getPreferredSize(); infoLabel.setEnabled(false); this.addMouseListener(new MouseAdapter() { public void mouseExited(MouseEvent e) { setMouseComponent(null); } public void mouseClicked(MouseEvent e) { if (mouseCom == clearLabel) { setText(""); } else if (mouseCom == iconLabel) { handleIconClick(); } } }); this.addMouseMotionListener(new MouseMotionListener() { public void mouseMoved(MouseEvent e) { JComponent com = getComponentAtPoint(e.getPoint()); setMouseComponent(com); } public void mouseDragged(MouseEvent e) { } }); this.addFocusListener(new FocusListener() { public void focusLost(FocusEvent e) { repaint(); } public void focusGained(FocusEvent e) { repaint(); } }); } private void handleIconClick() { } public String getToolTipText(MouseEvent event) { event.getPoint(); if (mouseCom == null) { return null; } if (mouseCom == this) { return super.getToolTipText(event); } return mouseCom.getToolTipText(event); } private int iconGap = 3; public Insets getInsets() { Insets insets = super.getInsets(); if (iconPosition == SwingConstants.LEFT) { insets.left += iconSize.width + iconGap + 2; if (this.getText() != null && this.getText().length() != 0 && showClearIcon) { insets.right += iconSize.width + iconGap + 2; } else { insets.right += iconGap; } } else { insets.left += iconGap; if (this.getText() != null && this.getText().length() != 0 && showClearIcon) { insets.right += iconSize.width + iconGap + 2; } else { insets.right += iconGap; } } return insets; } private JComponent getComponentAtPoint(Point point) { int x = (int) point.getX(); int y = (int) point.getY(); if (!contains(x, y)) { return null; } if (iconPosition == SwingConstants.LEFT) { if (x < iconSize.width + iconGap + 2) { return iconLabel; } if (getText() != null && getText().length() != 0 && showClearIcon) { if (x > getWidth() - iconSize.width - iconGap) { return clearLabel; } } } else { if (this.getText() == null || this.getText().length() == 0) { if (x > getWidth() - iconSize.width - iconGap - 2) { return iconLabel; } } if (getText() != null && getText().length() != 0 && showClearIcon) { if (x > getWidth() - iconSize.width - iconGap - 2) { return clearLabel; } } } return this; } private JComponent mouseCom; private void setMouseComponent(JComponent com) { if (mouseCom == com) { return; } if (mouseCom != null && mouseCom instanceof UILabel) { mouseCom.setBorder(null); } mouseCom = com; if (mouseCom != null && mouseCom instanceof UILabel) { mouseCom.setBorder(BorderFactory.createLineBorder(Color.ORANGE, 1)); } this.repaint(); if (mouseCom == null || mouseCom == clearLabel) { setCursor(Cursor.getDefaultCursor()); return; } if (mouseCom == this) { setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR)); return; } if (mouseCom == iconLabel) { setCursor(iconLabel.getCursor()); } } protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; int y = (int) (this.getHeight() / 2.0 - iconSize.getHeight() / 2); if (iconPosition == SwingConstants.LEFT) { cellRendererPane.paintComponent(g2d, iconLabel, this, iconGap, y, iconSize.width, iconSize.height); if (this.getText() != null && this.getText().length() != 0 && showClearIcon) { cellRendererPane.paintComponent(g2d, clearLabel, this, this.getWidth() - iconSize.width - iconGap, y, iconSize.width, iconSize.height); } } else { if (this.getText() == null || this.getText().length() == 0) { cellRendererPane.paintComponent(g2d, iconLabel, this, this.getWidth() - iconSize.width - iconGap, y, iconSize.width, iconSize.height); } else { if (showClearIcon) { cellRendererPane.paintComponent(g2d, clearLabel, this, this.getWidth() - iconSize.width - iconGap, y, iconSize.width, iconSize.height); } } } if (!this.isFocusOwner()) { if (this.getText() == null || this.getText().length() == 0) { int x = iconGap + 2; if (iconPosition == SwingConstants.LEFT) { x = iconSize.width + iconGap + 2; } y = (int) (this.getHeight() / 2.0 - infoSize.getHeight() / 2); cellRendererPane.paintComponent(g2d, infoLabel, this, x, y, infoSize.width, infoSize.height); } } } public Dimension getPreferredSize() { Insets s = super.getInsets(); Insets t = this.getInsets(); Dimension preferredSize = super.getPreferredSize(); preferredSize.setSize(preferredSize.width - (t.left + t.right - s.left - s.right), preferredSize.height + 2); return preferredSize; } protected void paintBorder(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (this.isFocusOwner()) { g2d.setStroke(new BasicStroke(1.5f)); } else { g2d.setStroke(new BasicStroke(1f)); } RoundRectangle2D.Double rect = new RoundRectangle2D.Double(0, 0, this.getWidth() - 2, this.getHeight() - 2, 4, 4); g2d.setColor(UIConstants.SHADOW_GREY); g2d.draw(rect); } public int getIconPosition() { return iconPosition; } public void setIconPosition(int iconPosition) { this.iconPosition = iconPosition; this.invalidate(); this.repaint(); } public boolean isShowClearIcon() { return showClearIcon; } public void setShowClearIcon(boolean showClearIcon) { this.showClearIcon = showClearIcon; this.repaint(); } public static void main(String[] args) { JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT)); UISearchTextField comp = new UISearchTextField(20); p.add(comp); comp = new UISearchTextField(20); comp.setShowClearIcon(false); p.add(comp); comp = new UISearchTextField(20); comp.setIconPosition(SwingConstants.RIGHT); p.add(comp); comp = new UISearchTextField(20); comp.setShowClearIcon(false); comp.setIconPosition(SwingConstants.RIGHT); p.add(comp); p.add(new JTextField(20)); JFrame frame = new JFrame(); frame.setTitle("UITextField"); frame.setContentPane(p); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300, 200); frame.setLocationRelativeTo(null); frame.setVisible(true); } } \ No newline at end of file diff --git a/designer_chart/src/com/fr/design/chart/series/PlotSeries/UIGroupExtensionPane.java b/designer_chart/src/com/fr/design/chart/series/PlotSeries/UIGroupExtensionPane.java index 2ad670341c..35882131fc 100644 --- a/designer_chart/src/com/fr/design/chart/series/PlotSeries/UIGroupExtensionPane.java +++ b/designer_chart/src/com/fr/design/chart/series/PlotSeries/UIGroupExtensionPane.java @@ -1 +1 @@ -package com.fr.design.chart.series.PlotSeries; import com.fr.chart.base.MapSvgXMLHelper; import com.fr.design.constants.LayoutConstants; import com.fr.design.constants.UIConstants; import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.dialog.UIDialog; import com.fr.design.event.ChangeEvent; import com.fr.design.event.ChangeListener; import com.fr.design.gui.frpane.UIExtensionPane; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.ilable.BoldFontTextLabel; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.itextfield.UISearchTextField; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.mainframe.DesignerContext; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.general.ComparatorUtils; import com.fr.general.FRLogger; import com.fr.general.GeneralUtils; import com.fr.general.Inter; import com.fr.stable.ArrayUtils; import javax.swing.*; import javax.swing.border.Border; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; import java.util.ArrayList; import java.util.List; /** * Created by IntelliJ IDEA. * Author : Richer * Version: 7.0.3 * Date: 12-12-29 * Time: 上午11:14 * 可收缩的面板,只有两层 */ public class UIGroupExtensionPane extends BasicPane { public static final String EDIT = "edit"; public static final String DELETE = "delete"; private static final int BUTTONWIDTH = 16; private static final int DIALOG_WIDTH = 140; private static final int DIALOG_HEIGHT = 100; private UISearchTextField searchTextFiled; private JList[] contentViews; private Component[][] components; private String[] titles; private java.util.List selectionListeners = new ArrayList(); private java.util.List editListeners = new ArrayList(); private List deleteListeners = new ArrayList(); private boolean isPressOnDelete = false; // 是否点击在删除按钮上 @Override protected String title4PopupWindow() { return "group"; } public UIGroupExtensionPane(String[] titles) { this.titles = titles; if (ArrayUtils.isEmpty(titles)) { return; } initComponents(titles); } private void initComponents(String[] titles) { setBackground(null); searchTextFiled = initSearchTextField(); int count = titles.length; contentViews = new JList[count]; components = new Component[count + 1][]; double p = TableLayout.PREFERRED; double f = TableLayout.FILL; double[] rowSize = new double[count + 1]; double[] columnSize = {f}; for (int i = 0; i < count + 1; i++) { rowSize[i] = p; if (i == 0) { components[i] = new Component[]{searchTextFiled}; } else if (i > 0 && i < count + 1) { JList li = new JList(new DefaultListModel()); li.addListSelectionListener(listSelectionListener); li.addMouseListener(mouseListener); li.setCellRenderer(listCellRenderer); li.setBackground(null); contentViews[i - 1] = li; components[i] = new UIExtensionPane[]{new UIExtensionPane(titles[i - 1], li, false)}; } } JPanel centerPane = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, 0, 0); setLayout(new BorderLayout()); add(new UIScrollPane(centerPane), BorderLayout.CENTER); } private UISearchTextField initSearchTextField() { UISearchTextField searchTextFiled = new UISearchTextField() { public Dimension getPreferredSize() { return new Dimension(120, 22); } }; searchTextFiled.setIconPosition(SwingConstants.RIGHT); searchTextFiled.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { doFilter(); } @Override public void removeUpdate(DocumentEvent e) { doFilter(); } @Override public void changedUpdate(DocumentEvent e) { doFilter(); } }); return searchTextFiled; } /** * 返回index列表的数据 */ public Object[] getData(int index) { if (index < 0 || index > contentViews.length) { return ArrayUtils.EMPTY_OBJECT_ARRAY; } ListModel model = contentViews[index].getModel(); Object[] items = new Object[model.getSize()]; for (int i = 0, len = model.getSize(); i < len; i++) { items[i] = model.getElementAt(i); } return items; } /** * 返回对应Title的列表数组 */ public Object[] getData(String title) { int dataIndex = ArrayUtils.indexOf(titles, title); if (dataIndex != ArrayUtils.INDEX_NOT_FOUND) { return getData(dataIndex); } return ArrayUtils.EMPTY_OBJECT_ARRAY; } private void doFilter() { for (JList list : contentViews) { ListDataListener[] ls = ((DefaultListModel) list.getModel()).getListDataListeners(); for (ListDataListener l : ls) { l.contentsChanged(new ListDataEvent(l, ListDataEvent.CONTENTS_CHANGED, 0, list.getModel().getSize())); } } for (int i = 1, len = components.length; i < len; i++) { ((UIExtensionPane) components[i][0]).setExpand(true); } } /** * 获取选中的值 * * @return 选中的值 */ public Object getSelectedObject() { for (JList list : contentViews) { if (list.getSelectedValue() != null) { return list.getSelectedValue(); } } return null; } /** * 返回选中的类别 * @return 类别 */ public String getSelectedType(){ for (int i = 0, len = contentViews.length; i < len; i++) { if(contentViews[i].getSelectedValue() != null){ return titles[i]; } } return ""; } /** * 设置选中的数据 */ public void setSelectedObject(Object value) { for (int i = 0, len = contentViews.length; i < len; i++) { UIExtensionPane extensionPane = (UIExtensionPane) components[i + 1][0]; JList list = contentViews[i]; DefaultListModel model = (DefaultListModel) list.getModel(); extensionPane.setExpand(model.contains(value)); if (model.contains(value)) { list.setSelectedValue(value, true); } } } /** * 设置数据选中的序号. */ public void setValueAtCurrentSelectIndex(Object value) { for (JList list : contentViews) { if (list.getSelectedIndex() != -1) { ((DefaultListModel) list.getModel()).setElementAt(value, list.getSelectedIndex()); } } } /** * 根据索引来添加数据 * * @param data 要添加的数据 * @param index 要添加的数据向的索引 */ public void addData(Object data, int index) { addData(data, index, false); } /** * 根据索引来添加数据 * * @param data 要添加的数据 * @param index 要添加的数据向的索引 * @param checkRepeat 是否检查名字重复 */ public void addData(Object data, int index, boolean checkRepeat) { if (contentViews == null || index < 0 || index > contentViews.length - 1) { return; } JList list = contentViews[index]; DefaultListModel model = (DefaultListModel) list.getModel(); if (data instanceof String) { model.addElement(createUnrepeatedName(model, (String) data, checkRepeat)); } if (checkRepeat) { // 将添加类型以外的其他类型都收起来 for (int i = 1, len = components.length; i < len; i++) { ((UIExtensionPane) components[i][0]).setExpand(false); } ((UIExtensionPane) components[index + 1][0]).setExpand(true); int selectedIndex = list.getModel().getSize() - 1; list.setSelectedIndex(selectedIndex); dealNewAddedDataIndex(((DefaultListModel) list.getModel()).elementAt(selectedIndex)); } } /** * 新添加的数据的序号 * @param data 数据 */ protected void dealNewAddedDataIndex(Object data){ } /** * 根据标题来添加数据 * * @param data 要添加的数据 * @param title 要添加数据的项的标题文字 */ public void addData(Object data, String title) { addData(data, title, false); } /** * 根据标题来添加数据 * * @param data 要添加的数据 * @param title 要添加数据的项的标题文字 * @param checkRepeat 是否检查名字重复 */ public void addData(Object data, String title, boolean checkRepeat) { int addIndex = ArrayUtils.indexOf(titles, title); if (addIndex != ArrayUtils.INDEX_NOT_FOUND) { addData(data, addIndex, checkRepeat); } } /** * 清除所有的数据 */ public void clearData() { for (JList list : contentViews) { ((DefaultListModel) list.getModel()).clear(); } } private String createUnrepeatedName(DefaultListModel model, String name, boolean checkRepeat) { if (!checkRepeat) { return name; } int count = model.getSize(); int extra = 1; String newName = name + (count + extra); boolean hasRepeated = false; do { hasRepeated = false; newName = name + (count + extra); for (int i = 0; i < count; i++) { if (ComparatorUtils.equals(model.getElementAt(i), newName)) { hasRepeated = true; extra++; } } } while (hasRepeated); return name + (count + extra); } /** * 判断该控件是否应该有编辑操作 * * @param list 列表组件 * @return 如果有编辑操作则需要显示相应的图标 */ private boolean hasEditOperation(JList list) { return true; } private DefaultListCellRenderer listCellRenderer = new DefaultListCellRenderer() { public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JComponent c = (JComponent) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (!hasEditOperation(list)) { return c; } Border border = null; c.setBorder(border); UILabel editLabel = new UILabel(UIConstants.EDIT_ICON); UILabel deleteLabel = new UILabel(UIConstants.DELETE_ICON); JPanel editPane = GUICoreUtils.createFlowPane(new Component[]{editLabel, deleteLabel}, FlowLayout.LEFT, LayoutConstants.HGAP_LARGE); editPane.setBackground(isSelected ? c.getBackground() : null); editPane.setBorder(border); JPanel renderPane = GUICoreUtils.createBorderLayoutPane(c, BorderLayout.CENTER, editPane, BorderLayout.EAST); if (shouldFilter(value)) { renderPane.setPreferredSize(new Dimension(0, 0)); } return renderPane; } }; //事件发生的顺序是ListSelection、MousePressed、ListSelection、MouseReleased private ListSelectionListener listSelectionListener = new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { //在鼠标按下的时候的值改变事件,重置属性 if(e.getValueIsAdjusting()){ isPressOnDelete = false; } if(!isRespondToValueChange(e)){ return; } fireSelectionChangeListener(new ChangeEvent(e.getSource())); if (((JList) e.getSource()).getSelectedIndex() == -1) { return; } for (JList list : contentViews) { if (list.getSelectedIndex() != -1 && !ComparatorUtils.equals(list, e.getSource())) { try { list.setSelectedIndices(null); } catch (Exception ee) { } } } } }; /** * 是否响应list值改变 * @return 响应 */ protected boolean isRespondToValueChange(ListSelectionEvent e){ return true; } private boolean shouldFilter(Object value) { return !GeneralUtils.objectToString(value).toLowerCase().contains(searchTextFiled.getText().toLowerCase()); } private MouseListener mouseListener = new MouseAdapter() { /** * {@inheritDoc} */ @Override public void mousePressed(final MouseEvent e) { isPressOnDelete = false; final JList list = (JList) e.getSource(); Point point = e.getPoint(); final int index = list.locationToIndex(point); int width = list.getWidth(); if (hasEditOperation(list)) { // 删除按钮 if (point.x > width - (BUTTONWIDTH + LayoutConstants.HGAP_LARGE)) { BasicPane bp = new BasicPane() { protected String title4PopupWindow() { return ""; } }; isPressOnDelete = true; bp.setLayout(new BorderLayout()); bp.add(new BoldFontTextLabel(Inter.getLocText(new String[]{"Delete", "Chart-Map"}) + "?", SwingConstants.CENTER)); clearLastListSelection(list); final String selectedType = UIGroupExtensionPane.this.getSelectedType(); UIDialog dialog = bp.showUnsizedWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { public void doOk() { Object name = getSelectedObject(); ((DefaultListModel) list.getModel()).removeElementAt(index); MapSvgXMLHelper.getInstance().removeMapAttr(GeneralUtils.objectToString(name)); MapSvgXMLHelper.getInstance().removeCateNames(selectedType,GeneralUtils.objectToString(name)); fireDeleteListener(new ChangeEvent(e)); } }); dialog.setResizable(true); dialog.setSize(DIALOG_WIDTH, DIALOG_HEIGHT); dialog.setResizable(false); GUICoreUtils.centerWindow(dialog); dialog.setVisible(true); } // 编辑按钮 else if (point.x > width - (BUTTONWIDTH * 2 + 2 * LayoutConstants.HGAP_LARGE) && point.x < width - (BUTTONWIDTH + LayoutConstants.HGAP_LARGE)) { fireItemEditListener(new ChangeEvent(e)); } } } public void mouseReleased(MouseEvent e) { isPressOnDelete = false; } }; /** * 直接跨list点击删除按钮,要置之前list的选中项为空(因为删除操作不触发更新) * @param currentList 当前选中的list */ public void clearLastListSelection (JList currentList) { for (JList list : contentViews) { if (list.getSelectedIndex() != -1 && !ComparatorUtils.equals(list, currentList)) { try { list.setSelectedIndices(null); } catch (Exception e) { FRLogger.getLogger().error(e.getMessage()); } } } } /** * 是否点击在删除按钮上 * @return 是则返回true */ public boolean isPressOnDelete(){ return isPressOnDelete; } /** * 添加选中变化监听事件 * @param listener 监听 */ public void addSelectionChangeListener(ChangeListener listener) { selectionListeners.add(listener); } private void fireSelectionChangeListener(ChangeEvent e) { for (int i = selectionListeners.size(); i > 0; i--) { selectionListeners.get(i - 1).fireChanged(e); } } /** * 添加Item的监听事件 * @param listener 监听器 */ public void addItemEditListener(ChangeListener listener) { editListeners.add(listener); } private void fireItemEditListener(ChangeEvent e) { for (int i = editListeners.size(); i > 0; i--) { editListeners.get(i - 1).fireChanged(e); } } /** * 添加删除事件的监听事件 * @param listener 监听 */ public void addDeleteListener(ChangeListener listener) { deleteListeners.add(listener); } private void fireDeleteListener(ChangeEvent e) { for(int i = deleteListeners.size(); i > 0; i--) { deleteListeners.get(i - 1).fireChanged(e); } } public void setEnabled(boolean isEnabled){ super.setEnabled(isEnabled); if(searchTextFiled != null){ searchTextFiled.setEnabled(isEnabled); } if(this.components != null){ for(int i = 0; i < this.components.length; i++){ Component[] comp = this.components[i]; for(int j = 0; j < comp.length; j++){ comp[j].setEnabled(isEnabled); } } } } /** * 测试程序 * @param args 参数 */ public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container c = f.getContentPane(); c.setBackground(Color.WHITE); c.setLayout(new BoxLayout(c, BoxLayout.Y_AXIS)); final UIGroupExtensionPane g = new UIGroupExtensionPane(new String[]{"title1", "title2", "title3"}); c.add(g, BorderLayout.CENTER); JPanel pp = new JPanel(new FlowLayout()); c.add(pp, BorderLayout.SOUTH); UIButton test = new UIButton("add1"); test.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { g.addData("test111", 0); } }); pp.add(test); UIButton test2 = new UIButton("add2"); test2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { g.addData("test222", 1); } }); pp.add(test2); f.setSize(360, 500); f.setLocation(200, 100); f.setVisible(true); } } \ No newline at end of file +package com.fr.design.chart.series.PlotSeries; import com.fr.chart.base.MapSvgXMLHelper; import com.fr.design.constants.LayoutConstants; import com.fr.design.constants.UIConstants; import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.dialog.UIDialog; import com.fr.design.event.ChangeEvent; import com.fr.design.event.ChangeListener; import com.fr.design.gui.frpane.UIExtensionPane; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.ilable.BoldFontTextLabel; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.itextfield.UISearchTextField; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.mainframe.DesignerContext; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.general.ComparatorUtils; import com.fr.general.FRLogger; import com.fr.general.GeneralUtils; import com.fr.general.Inter; import com.fr.stable.ArrayUtils; import javax.swing.*; import javax.swing.border.Border; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import javax.swing.event.ListDataEvent; import javax.swing.event.ListDataListener; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.util.ArrayList; import java.util.List; /** * Created by IntelliJ IDEA. * Author : Richer * Version: 7.0.3 * Date: 12-12-29 * Time: 上午11:14 * 可收缩的面板,只有两层 */ public class UIGroupExtensionPane extends BasicPane { public static final String EDIT = "edit"; public static final String DELETE = "delete"; private static final int BUTTONWIDTH = 16; private static final int DIALOG_WIDTH = 140; private static final int DIALOG_HEIGHT = 100; private UISearchTextField searchTextFiled; private JList[] contentViews; private Component[][] components; private String[] titles; private java.util.List selectionListeners = new ArrayList(); private java.util.List editListeners = new ArrayList(); private List deleteListeners = new ArrayList(); private boolean isPressOnDelete = false; // 是否点击在删除按钮上 @Override protected String title4PopupWindow() { return "group"; } public UIGroupExtensionPane(String[] titles) { this.titles = titles; if (ArrayUtils.isEmpty(titles)) { return; } initComponents(titles); } private void initComponents(String[] titles) { setBackground(null); searchTextFiled = initSearchTextField(); int count = titles.length; contentViews = new JList[count]; components = new Component[count + 1][]; double p = TableLayout.PREFERRED; double f = TableLayout.FILL; double[] rowSize = new double[count + 1]; double[] columnSize = {f}; for (int i = 0; i < count + 1; i++) { rowSize[i] = p; if (i == 0) { components[i] = new Component[]{searchTextFiled}; } else if (i > 0 && i < count + 1) { JList li = new JList(new DefaultListModel()); li.addListSelectionListener(listSelectionListener); li.addMouseListener(mouseListener); li.setCellRenderer(listCellRenderer); li.setBackground(null); contentViews[i - 1] = li; components[i] = new UIExtensionPane[]{new UIExtensionPane(titles[i - 1], li, false)}; } } JPanel centerPane = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, 0, 0); setLayout(new BorderLayout()); add(new UIScrollPane(centerPane), BorderLayout.CENTER); } private UISearchTextField initSearchTextField() { UISearchTextField searchTextFiled = new UISearchTextField() { public Dimension getPreferredSize() { return new Dimension(120, 22); } }; searchTextFiled.setIconPosition(SwingConstants.RIGHT); searchTextFiled.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { doFilter(); } @Override public void removeUpdate(DocumentEvent e) { doFilter(); } @Override public void changedUpdate(DocumentEvent e) { doFilter(); } }); return searchTextFiled; } /** * 返回index列表的数据 */ public Object[] getData(int index) { if (index < 0 || index > contentViews.length) { return ArrayUtils.EMPTY_OBJECT_ARRAY; } ListModel model = contentViews[index].getModel(); Object[] items = new Object[model.getSize()]; for (int i = 0, len = model.getSize(); i < len; i++) { items[i] = model.getElementAt(i); } return items; } /** * 返回对应Title的列表数组 */ public Object[] getData(String title) { int dataIndex = ArrayUtils.indexOf(titles, title); if (dataIndex != ArrayUtils.INDEX_NOT_FOUND) { return getData(dataIndex); } return ArrayUtils.EMPTY_OBJECT_ARRAY; } private void doFilter() { for (JList list : contentViews) { ListDataListener[] ls = ((DefaultListModel) list.getModel()).getListDataListeners(); for (ListDataListener l : ls) { l.contentsChanged(new ListDataEvent(l, ListDataEvent.CONTENTS_CHANGED, 0, list.getModel().getSize())); } } for (int i = 1, len = components.length; i < len; i++) { ((UIExtensionPane) components[i][0]).setExpand(true); } } /** * 获取选中的值 * * @return 选中的值 */ public Object getSelectedObject() { for (JList list : contentViews) { if (list.getSelectedValue() != null) { return list.getSelectedValue(); } } return null; } /** * 返回选中的类别 * @return 类别 */ public String getSelectedType(){ for (int i = 0, len = contentViews.length; i < len; i++) { if(contentViews[i].getSelectedValue() != null){ return titles[i]; } } return ""; } /** * 设置选中的数据 */ public void setSelectedObject(Object value) { for (int i = 0, len = contentViews.length; i < len; i++) { UIExtensionPane extensionPane = (UIExtensionPane) components[i + 1][0]; JList list = contentViews[i]; DefaultListModel model = (DefaultListModel) list.getModel(); extensionPane.setExpand(model.contains(value)); if (model.contains(value)) { list.setSelectedValue(value, true); } } } /** * 设置数据选中的序号. */ public void setValueAtCurrentSelectIndex(Object value) { for (JList list : contentViews) { if (list.getSelectedIndex() != -1) { ((DefaultListModel) list.getModel()).setElementAt(value, list.getSelectedIndex()); } } } /** * 根据索引来添加数据 * * @param data 要添加的数据 * @param index 要添加的数据向的索引 */ public void addData(Object data, int index) { addData(data, index, false); } /** * 根据索引来添加数据 * * @param data 要添加的数据 * @param index 要添加的数据向的索引 * @param checkRepeat 是否检查名字重复 */ public void addData(Object data, int index, boolean checkRepeat) { if (contentViews == null || index < 0 || index > contentViews.length - 1) { return; } JList list = contentViews[index]; DefaultListModel model = (DefaultListModel) list.getModel(); if (data instanceof String) { model.addElement(createUnrepeatedName(model, (String) data, checkRepeat)); } if (checkRepeat) { // 将添加类型以外的其他类型都收起来 for (int i = 1, len = components.length; i < len; i++) { ((UIExtensionPane) components[i][0]).setExpand(false); } ((UIExtensionPane) components[index + 1][0]).setExpand(true); int selectedIndex = list.getModel().getSize() - 1; list.setSelectedIndex(selectedIndex); dealNewAddedDataIndex(((DefaultListModel) list.getModel()).elementAt(selectedIndex)); } } /** * 新添加的数据的序号 * @param data 数据 */ protected void dealNewAddedDataIndex(Object data){ } /** * 根据标题来添加数据 * * @param data 要添加的数据 * @param title 要添加数据的项的标题文字 */ public void addData(Object data, String title) { addData(data, title, false); } /** * 根据标题来添加数据 * * @param data 要添加的数据 * @param title 要添加数据的项的标题文字 * @param checkRepeat 是否检查名字重复 */ public void addData(Object data, String title, boolean checkRepeat) { int addIndex = ArrayUtils.indexOf(titles, title); if (addIndex != ArrayUtils.INDEX_NOT_FOUND) { addData(data, addIndex, checkRepeat); } } /** * 清除所有的数据 */ public void clearData() { for (JList list : contentViews) { ((DefaultListModel) list.getModel()).clear(); } } private String createUnrepeatedName(DefaultListModel model, String name, boolean checkRepeat) { if (!checkRepeat) { return name; } int count = model.getSize(); int extra = 1; String newName = name + (count + extra); boolean hasRepeated = false; do { hasRepeated = false; newName = name + (count + extra); for (int i = 0; i < count; i++) { if (ComparatorUtils.equals(model.getElementAt(i), newName)) { hasRepeated = true; extra++; } } } while (hasRepeated); return name + (count + extra); } /** * 判断该控件是否应该有编辑操作 * * @param list 列表组件 * @return 如果有编辑操作则需要显示相应的图标 */ private boolean hasEditOperation(JList list) { return true; } private DefaultListCellRenderer listCellRenderer = new DefaultListCellRenderer() { public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JComponent c = (JComponent) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (!hasEditOperation(list)) { return c; } Border border = null; c.setBorder(border); UILabel editLabel = new UILabel(UIConstants.EDIT_ICON); UILabel deleteLabel = new UILabel(UIConstants.DELETE_ICON); JPanel editPane = GUICoreUtils.createFlowPane(new Component[]{editLabel, deleteLabel}, FlowLayout.LEFT, LayoutConstants.HGAP_LARGE); editPane.setBackground(isSelected ? c.getBackground() : null); editPane.setBorder(border); JPanel renderPane = GUICoreUtils.createBorderLayoutPane(c, BorderLayout.CENTER, editPane, BorderLayout.EAST); renderPane.setPreferredSize(new Dimension((int) renderPane.getPreferredSize().getWidth(), 20)); if (shouldFilter(value)) { renderPane.setPreferredSize(new Dimension(0, 0)); } return renderPane; } }; //事件发生的顺序是ListSelection、MousePressed、ListSelection、MouseReleased private ListSelectionListener listSelectionListener = new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { //在鼠标按下的时候的值改变事件,重置属性 if(e.getValueIsAdjusting()){ isPressOnDelete = false; } if(!isRespondToValueChange(e)){ return; } fireSelectionChangeListener(new ChangeEvent(e.getSource())); if (((JList) e.getSource()).getSelectedIndex() == -1) { return; } for (JList list : contentViews) { if (list.getSelectedIndex() != -1 && !ComparatorUtils.equals(list, e.getSource())) { try { list.setSelectedIndices(null); } catch (Exception ee) { } } } } }; /** * 是否响应list值改变 * @return 响应 */ protected boolean isRespondToValueChange(ListSelectionEvent e){ return true; } private boolean shouldFilter(Object value) { return !GeneralUtils.objectToString(value).toLowerCase().contains(searchTextFiled.getText().toLowerCase()); } private MouseListener mouseListener = new MouseAdapter() { /** * {@inheritDoc} */ @Override public void mousePressed(final MouseEvent e) { isPressOnDelete = false; final JList list = (JList) e.getSource(); Point point = e.getPoint(); final int index = list.locationToIndex(point); int width = list.getWidth(); if (hasEditOperation(list)) { // 删除按钮 if (point.x > width - (BUTTONWIDTH + LayoutConstants.HGAP_LARGE)) { BasicPane bp = new BasicPane() { protected String title4PopupWindow() { return ""; } }; isPressOnDelete = true; bp.setLayout(new BorderLayout()); bp.add(new BoldFontTextLabel(Inter.getLocText(new String[]{"Delete", "Chart-Map"}) + "?", SwingConstants.CENTER)); clearLastListSelection(list); final String selectedType = UIGroupExtensionPane.this.getSelectedType(); UIDialog dialog = bp.showUnsizedWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { public void doOk() { Object name = getSelectedObject(); ((DefaultListModel) list.getModel()).removeElementAt(index); MapSvgXMLHelper.getInstance().removeMapAttr(GeneralUtils.objectToString(name)); MapSvgXMLHelper.getInstance().removeCateNames(selectedType,GeneralUtils.objectToString(name)); fireDeleteListener(new ChangeEvent(e)); } }); dialog.setResizable(true); dialog.setSize(DIALOG_WIDTH, DIALOG_HEIGHT); dialog.setResizable(false); GUICoreUtils.centerWindow(dialog); dialog.setVisible(true); } // 编辑按钮 else if (point.x > width - (BUTTONWIDTH * 2 + 2 * LayoutConstants.HGAP_LARGE) && point.x < width - (BUTTONWIDTH + LayoutConstants.HGAP_LARGE)) { fireItemEditListener(new ChangeEvent(e)); } } } public void mouseReleased(MouseEvent e) { isPressOnDelete = false; } }; /** * 直接跨list点击删除按钮,要置之前list的选中项为空(因为删除操作不触发更新) * @param currentList 当前选中的list */ public void clearLastListSelection (JList currentList) { for (JList list : contentViews) { if (list.getSelectedIndex() != -1 && !ComparatorUtils.equals(list, currentList)) { try { list.setSelectedIndices(null); } catch (Exception e) { FRLogger.getLogger().error(e.getMessage()); } } } } /** * 是否点击在删除按钮上 * @return 是则返回true */ public boolean isPressOnDelete(){ return isPressOnDelete; } /** * 添加选中变化监听事件 * @param listener 监听 */ public void addSelectionChangeListener(ChangeListener listener) { selectionListeners.add(listener); } private void fireSelectionChangeListener(ChangeEvent e) { for (int i = selectionListeners.size(); i > 0; i--) { selectionListeners.get(i - 1).fireChanged(e); } } /** * 添加Item的监听事件 * @param listener 监听器 */ public void addItemEditListener(ChangeListener listener) { editListeners.add(listener); } private void fireItemEditListener(ChangeEvent e) { for (int i = editListeners.size(); i > 0; i--) { editListeners.get(i - 1).fireChanged(e); } } /** * 添加删除事件的监听事件 * @param listener 监听 */ public void addDeleteListener(ChangeListener listener) { deleteListeners.add(listener); } private void fireDeleteListener(ChangeEvent e) { for(int i = deleteListeners.size(); i > 0; i--) { deleteListeners.get(i - 1).fireChanged(e); } } public void setEnabled(boolean isEnabled){ super.setEnabled(isEnabled); if(searchTextFiled != null){ searchTextFiled.setEnabled(isEnabled); } if(this.components != null){ for(int i = 0; i < this.components.length; i++){ Component[] comp = this.components[i]; for(int j = 0; j < comp.length; j++){ comp[j].setEnabled(isEnabled); } } } } /** * 测试程序 * @param args 参数 */ public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container c = f.getContentPane(); c.setBackground(Color.WHITE); c.setLayout(new BoxLayout(c, BoxLayout.Y_AXIS)); final UIGroupExtensionPane g = new UIGroupExtensionPane(new String[]{"title1", "title2", "title3"}); c.add(g, BorderLayout.CENTER); JPanel pp = new JPanel(new FlowLayout()); c.add(pp, BorderLayout.SOUTH); UIButton test = new UIButton("add1"); test.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { g.addData("test111", 0); } }); pp.add(test); UIButton test2 = new UIButton("add2"); test2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { g.addData("test222", 1); } }); pp.add(test2); f.setSize(360, 500); f.setLocation(200, 100); f.setVisible(true); } } \ No newline at end of file diff --git a/designer_chart/src/com/fr/design/chart/series/PlotStyle/ChartSelectDemoPane.java b/designer_chart/src/com/fr/design/chart/series/PlotStyle/ChartSelectDemoPane.java index 37d0758fc3..d5a4c87f99 100644 --- a/designer_chart/src/com/fr/design/chart/series/PlotStyle/ChartSelectDemoPane.java +++ b/designer_chart/src/com/fr/design/chart/series/PlotStyle/ChartSelectDemoPane.java @@ -1,19 +1,17 @@ package com.fr.design.chart.series.PlotStyle; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.util.ArrayList; - -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; - +import com.fr.design.dialog.BasicPane; import com.fr.design.event.UIObserver; import com.fr.design.event.UIObserverListener; -import com.fr.design.dialog.BasicPane; import com.fr.stable.ArrayUtils; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import java.awt.*; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.util.ArrayList; + /** * 图表选中demo的类. 用于 选中点击, 悬浮状态, 可以继承, 改变画的内容. * @author kunsnat E-mail:kunsnat@gmail.com @@ -27,7 +25,7 @@ public class ChartSelectDemoPane extends BasicPane implements UIObserver, MouseL // 所有统一参与的点击状态类. 相当于Group protected ChartSelectDemoPane[] demoList = new ChartSelectDemoPane[0]; - private boolean isRollOver; + protected boolean isRollOver; private ArrayList changeListeners = new ArrayList(); public void setDemoGroup(ChartSelectDemoPane[] demos) { @@ -56,7 +54,7 @@ public class ChartSelectDemoPane extends BasicPane implements UIObserver, MouseL fireStateChange(); for (int i = 0; i < ArrayUtils.getLength(demoList); i++) { - demoList[i].checkBackground(); + demoList[i].checkBorder(); demoList[i].repaint(); } } @@ -102,7 +100,7 @@ public class ChartSelectDemoPane extends BasicPane implements UIObserver, MouseL isRollOver = true; for (int i = 0; i < ArrayUtils.getLength(demoList); i++) { - demoList[i].checkBackground(); + demoList[i].checkBorder(); demoList[i].repaint(); } } @@ -126,7 +124,7 @@ public class ChartSelectDemoPane extends BasicPane implements UIObserver, MouseL } for (int i = 0; i < ArrayUtils.getLength(demoList); i++) { - demoList[i].checkBackground(); + demoList[i].checkBorder(); demoList[i].repaint(); } } @@ -158,16 +156,11 @@ public class ChartSelectDemoPane extends BasicPane implements UIObserver, MouseL return true; } - /** - * 修改背景颜色 - */ - public void checkBackground() { - if (!isRollOver && !isPressing) { - this.setBackground(null); - } else if(isRollOver && !isPressing){ - this.setBackground(new Color(182, 217, 253)); - } else { - this.setBackground(new Color(164, 192, 220)); - } + /** + * 修改边框颜色 + */ + public void checkBorder() { + this.setBorder(null); + } } \ No newline at end of file diff --git a/designer_chart/src/com/fr/design/mainframe/chart/gui/type/AbstractChartTypePane.java b/designer_chart/src/com/fr/design/mainframe/chart/gui/type/AbstractChartTypePane.java index 85b0dd2e2c..9aef3032f8 100644 --- a/designer_chart/src/com/fr/design/mainframe/chart/gui/type/AbstractChartTypePane.java +++ b/designer_chart/src/com/fr/design/mainframe/chart/gui/type/AbstractChartTypePane.java @@ -128,7 +128,7 @@ public abstract class AbstractChartTypePane extends FurtherBasicBeanPane{ int iconLen = iconPaths.length; int tipLen = tipNames.length; for(int i = 0, len = Math.min(iconLen, tipLen); i < len; i++) { - boolean isDrawRightLine = (i == len - 1 || (i + 1) % ONE_LINE_NUM == 0); + boolean isDrawRightLine = (i != len - 1 || (i + 1) % ONE_LINE_NUM != 0); ChartImagePane imagePane = new ChartImagePane(iconPaths[i], tipNames[i], isDrawRightLine); imagePane.isPressing = (i == 0); list.add(imagePane); @@ -208,13 +208,13 @@ public abstract class AbstractChartTypePane extends FurtherBasicBeanPane{ protected void checkDemosBackground() { if(this.styleList != null && !styleList.isEmpty()){ for(int i = 0; i < styleList.size(); i++) { - styleList.get(i).checkBackground(); + styleList.get(i).checkBorder(); styleList.get(i).repaint(); } } for(int i = 0; i < typeDemo.size(); i++) { - typeDemo.get(i).checkBackground(); + typeDemo.get(i).checkBorder(); typeDemo.get(i).repaint(); } } diff --git a/designer_chart/src/com/fr/design/mainframe/chart/gui/type/ChartImagePane.java b/designer_chart/src/com/fr/design/mainframe/chart/gui/type/ChartImagePane.java index 7b35b8d8dc..609ca91c34 100644 --- a/designer_chart/src/com/fr/design/mainframe/chart/gui/type/ChartImagePane.java +++ b/designer_chart/src/com/fr/design/mainframe/chart/gui/type/ChartImagePane.java @@ -11,6 +11,9 @@ import java.awt.event.MouseEvent; public class ChartImagePane extends ChartSelectDemoPane { private static final long serialVersionUID = -2785128245790568603L; + private static final int IMAGE_WIDTH = 58; + private static final int IMAGE_HIGTH = 50; + private static final Color ENTER_COLOR = new Color(216, 242, 253); private boolean isDrawRightLine = false; public boolean isDoubleClicked = false; @@ -21,8 +24,10 @@ public class ChartImagePane extends ChartSelectDemoPane { addMouseListener(this); this.setToolTipText(tipName); - this.setBorder(BorderFactory.createMatteBorder(1, 1, 1, isDrawRightLine ? 1 : 0, UIConstants.LINE_COLOR)); - } + this.setBorder(BorderFactory.createMatteBorder(0, 0, 0, isDrawRightLine ? 1 : 0, UIConstants.SELECT_TAB)); + this.setBackground(UIConstants.TOOLBARUI_BACKGROUND); + this.setPreferredSize(new Dimension(IMAGE_WIDTH, IMAGE_HIGTH)); + } public ChartImagePane(String fullIconPath, String tipName, boolean isDrawRightLine){ constructImagePane(fullIconPath, tipName, isDrawRightLine); @@ -38,7 +43,10 @@ public class ChartImagePane extends ChartSelectDemoPane { this.setToolTipText(tipName); - this.setBorder(BorderFactory.createMatteBorder(1, 1, 1, isDrawRightLine ? 1 : 0, UIConstants.LINE_COLOR)); + this.setBorder(BorderFactory.createMatteBorder(0, 0, 0, isDrawRightLine ? 1 : 0, UIConstants.SELECT_TAB)); + this.setBackground(UIConstants.TOOLBARUI_BACKGROUND); + this.setPreferredSize(new Dimension(IMAGE_WIDTH, IMAGE_HIGTH)); + } /** @@ -53,4 +61,18 @@ public class ChartImagePane extends ChartSelectDemoPane { } super.mouseClicked(e); } + + /** + * 修改边框颜色 + */ + public void checkBorder() { + if (!isRollOver && !isPressing) { + this.setBorder(BorderFactory.createMatteBorder(0, 0, 0, isDrawRightLine ? 1 : 0, UIConstants.SELECT_TAB)); + } else if (isRollOver && !isPressing) { + this.setBorder(BorderFactory.createMatteBorder(2, 2, 2, 2, ENTER_COLOR)); + } else { + this.setBorder(BorderFactory.createMatteBorder(2, 2, 2, 2, UIConstants.FLESH_BLUE)); + } + } + } \ No newline at end of file diff --git a/designer_chart/src/com/fr/design/mainframe/chart/gui/type/GisMapPlotPane.java b/designer_chart/src/com/fr/design/mainframe/chart/gui/type/GisMapPlotPane.java index af59eea8d3..e1368f4a7c 100644 --- a/designer_chart/src/com/fr/design/mainframe/chart/gui/type/GisMapPlotPane.java +++ b/designer_chart/src/com/fr/design/mainframe/chart/gui/type/GisMapPlotPane.java @@ -163,8 +163,8 @@ public class GisMapPlotPane extends AbstractChartTypePane{ styleList.get(BAIDU).isPressing =false; keyInput.setText(plot.getGoogleKey()); } - styleList.get(GOOGLE).checkBackground(); - styleList.get(BAIDU).checkBackground(); + styleList.get(GOOGLE).checkBorder(); + styleList.get(BAIDU).checkBorder(); } /** diff --git a/designer_chart/src/com/fr/plugin/chart/column/VanChartColumnSeriesPane.java b/designer_chart/src/com/fr/plugin/chart/column/VanChartColumnSeriesPane.java index 5c71fb77fa..c04711274f 100644 --- a/designer_chart/src/com/fr/plugin/chart/column/VanChartColumnSeriesPane.java +++ b/designer_chart/src/com/fr/plugin/chart/column/VanChartColumnSeriesPane.java @@ -122,7 +122,9 @@ public class VanChartColumnSeriesPane extends VanChartAbstractPlotSeriesPane { } private void checkColumnWidth() { - columnWidth.setVisible(isFixedWidth.getSelectedIndex() == 0); + boolean b = isFixedWidth.getSelectedIndex() == 0; + columnWidth.setVisible(b); + seriesGap.setEnabled(!b); } private void checkImagePane() { diff --git a/designer_chart/src/com/fr/plugin/chart/designer/component/format/VanChartFormatPaneWithCheckBox.java b/designer_chart/src/com/fr/plugin/chart/designer/component/format/VanChartFormatPaneWithCheckBox.java index 1ac6a7a271..df925f5cab 100644 --- a/designer_chart/src/com/fr/plugin/chart/designer/component/format/VanChartFormatPaneWithCheckBox.java +++ b/designer_chart/src/com/fr/plugin/chart/designer/component/format/VanChartFormatPaneWithCheckBox.java @@ -92,7 +92,7 @@ public abstract class VanChartFormatPaneWithCheckBox extends JPanel{ formatPane = createFormatPane(); } Point comPoint = formatButton.getLocationOnScreen(); - Point arrowPoint = new Point(comPoint.x, comPoint.y + formatButton.getHeight()); + Point arrowPoint = new Point(comPoint.x +formatButton.getWidth() - 25, comPoint.y + formatButton.getHeight()); UIBubbleFloatPane