diff --git a/designer_chart/src/com/fr/design/chart/report/MapCubeLayerPane.java b/designer_chart/src/com/fr/design/chart/report/MapCubeLayerPane.java index 461fe220a0..5d54f78530 100644 --- a/designer_chart/src/com/fr/design/chart/report/MapCubeLayerPane.java +++ b/designer_chart/src/com/fr/design/chart/report/MapCubeLayerPane.java @@ -1,10 +1,10 @@ package com.fr.design.chart.report; +import com.fr.base.MapSvgAttr; +import com.fr.base.MapSvgXMLHelper; import com.fr.base.MapXMLHelper; import com.fr.base.Utils; import com.fr.chart.base.ChartConstants; -import com.fr.chart.base.MapSvgAttr; -import com.fr.chart.base.MapSvgXMLHelper; import com.fr.chart.chartglyph.MapAttr; import com.fr.design.DesignerEnvManager; import com.fr.design.beans.BasicBeanPane; diff --git a/designer_chart/src/com/fr/design/chart/report/MapCubeSetDataPane.java b/designer_chart/src/com/fr/design/chart/report/MapCubeSetDataPane.java index 4c175500eb..3110e241b5 100644 --- a/designer_chart/src/com/fr/design/chart/report/MapCubeSetDataPane.java +++ b/designer_chart/src/com/fr/design/chart/report/MapCubeSetDataPane.java @@ -1,7 +1,7 @@ package com.fr.design.chart.report; +import com.fr.base.MapSvgXMLHelper; import com.fr.base.MapXMLHelper; -import com.fr.chart.base.MapSvgXMLHelper; import com.fr.design.beans.BasicBeanPane; import com.fr.design.editor.ValueEditorPane; import com.fr.design.editor.ValueEditorPaneFactory; diff --git a/designer_chart/src/com/fr/design/chart/series/PlotSeries/AbstrctMapAttrEditPane.java b/designer_chart/src/com/fr/design/chart/series/PlotSeries/AbstrctMapAttrEditPane.java index d2d61909bd..254dfaec1a 100644 --- a/designer_chart/src/com/fr/design/chart/series/PlotSeries/AbstrctMapAttrEditPane.java +++ b/designer_chart/src/com/fr/design/chart/series/PlotSeries/AbstrctMapAttrEditPane.java @@ -1,6 +1,6 @@ package com.fr.design.chart.series.PlotSeries; -import com.fr.chart.base.MapSvgAttr; +import com.fr.base.MapSvgAttr; /** * Created by IntelliJ IDEA. 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 d844631c05..49fa97eee4 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 @@ -1,9 +1,9 @@ package com.fr.design.chart.series.PlotSeries; import com.fr.base.FRContext; +import com.fr.base.MapSvgAttr; import com.fr.base.TableData; import com.fr.base.Utils; -import com.fr.chart.base.MapSvgAttr; import com.fr.data.impl.EmbeddedTableData; import com.fr.design.beans.BasicBeanPane; import com.fr.design.data.DesignTableDataManager; diff --git a/designer_chart/src/com/fr/design/chart/series/PlotSeries/MapDefiAreaNamePane.java b/designer_chart/src/com/fr/design/chart/series/PlotSeries/MapDefiAreaNamePane.java index ca8d3a67dd..0a3928ae45 100644 --- a/designer_chart/src/com/fr/design/chart/series/PlotSeries/MapDefiAreaNamePane.java +++ b/designer_chart/src/com/fr/design/chart/series/PlotSeries/MapDefiAreaNamePane.java @@ -1,8 +1,8 @@ package com.fr.design.chart.series.PlotSeries; +import com.fr.base.MapSvgAttr; +import com.fr.base.MapSvgXMLHelper; import com.fr.base.Utils; -import com.fr.chart.base.MapSvgAttr; -import com.fr.chart.base.MapSvgXMLHelper; import com.fr.design.beans.BasicBeanPane; import com.fr.design.data.tabledata.wrapper.TableDataWrapper; import com.fr.design.editor.ValueEditorPane; diff --git a/designer_chart/src/com/fr/design/chart/series/PlotSeries/MapGroupExtensionPane.java b/designer_chart/src/com/fr/design/chart/series/PlotSeries/MapGroupExtensionPane.java index f1f1b3deb3..74a8e687f5 100644 --- a/designer_chart/src/com/fr/design/chart/series/PlotSeries/MapGroupExtensionPane.java +++ b/designer_chart/src/com/fr/design/chart/series/PlotSeries/MapGroupExtensionPane.java @@ -1 +1 @@ -package com.fr.design.chart.series.PlotSeries; import com.fr.base.*; import com.fr.chart.base.MapSvgAttr; import com.fr.chart.base.MapSvgXMLHelper; import com.fr.chart.chartattr.MapPlot; import com.fr.chart.chartglyph.MapShapeValue; import com.fr.design.constants.UIConstants; import com.fr.design.DesignerEnvManager; import com.fr.design.event.ChangeEvent; import com.fr.design.event.ChangeListener; import com.fr.design.event.UIObserver; import com.fr.design.event.UIObserverListener; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerFrame; import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.DialogActionAdapter; import com.fr.general.ComparatorUtils; import com.fr.general.FRLogger; import com.fr.general.Inter; import com.fr.stable.CoreConstants; import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; import com.fr.stable.SvgProvider; import javax.swing.*; import javax.swing.event.ListSelectionEvent; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.geom.RoundRectangle2D; import java.util.ArrayList; /** * Created by IntelliJ IDEA. * Author : Richer * Version: 7.0.3 * Date: 12-12-29 * Time: 下午2:41 */ public class MapGroupExtensionPane extends BasicPane implements UIObserver { private static final String[] TYPE_NAMES = new String[]{ Inter.getLocText("FR-Chart-World_Map"), Inter.getLocText("FR-Chart-State_Map"), Inter.getLocText("FR-Chart-Province_Map"), Inter.getLocText("FR-Chart-Custom_Map")}; private static final int WORD = 0; private static final int NATION = 1; private static final int STATE = 2; private static final int USER = 3; private static final int OFFSET_X = 800; private static final int OFFSET_Y = 200; private UIGroupExtensionPane groupExtensionPane; private UIButton addButton; private JPopupMenu popupMenu; private ArrayList changeListeners = new ArrayList(); private boolean hasPopulated = false; @Override protected String title4PopupWindow() { return "Map"; } public MapGroupExtensionPane() { setLayout(new BorderLayout()); groupExtensionPane = new UIGroupExtensionPane(TYPE_NAMES){ /** * 新添加的数据的序号 * @param data 数据 */ protected void dealNewAddedDataIndex(Object data){ String newName = (String)data; MapSvgXMLHelper helper = MapSvgXMLHelper.getInstance(); if(helper.getNewMapAttr(newName) != null){ return; } MapSvgAttr attr = new MapSvgAttr(); attr.setFilePath(MapSvgXMLHelper.customMapPath() + CoreConstants.SEPARATOR + newName + ".svg"); helper.addNewSvgMaps(attr.getName(), attr); } /** * 一次鼠标的点击会有两次事件响应(按下和释放)。前者的事件属性中getValueIsAdjusting()=true,后者是false。 * 是否响应list值改变 * @return 鼠标按下时不响应,先响应mousePress事件,在鼠标释放是再响应list值改编的事件,并且点击删除不触发更新,并且populate后触发更新 */ protected boolean isRespondToValueChange(ListSelectionEvent e){ return !e.getValueIsAdjusting() && !this.isPressOnDelete() && hasPopulated; } }; groupExtensionPane.addSelectionChangeListener(new ChangeListener() { @Override public void fireChanged(ChangeEvent event) { fireStateChange(); } }); groupExtensionPane.addItemEditListener(new ChangeListener() { @Override public void fireChanged(ChangeEvent event) { doEdit(event); } }); groupExtensionPane.addDeleteListener(new ChangeListener() { @Override public void fireChanged(ChangeEvent event) { //这么写有点问题 String oldName = Utils.objectToString(groupExtensionPane.getSelectedObject()); saveMapInfo(oldName); } }); setPreferredSize(new Dimension(400, 210)); add(groupExtensionPane, BorderLayout.CENTER); addButton = new UIButton(BaseUtils.readIcon("/com/fr/design/images/buttonicon/add.png")) { @Override protected void paintBorder(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setStroke(UIConstants.BS); Shape shape = new RoundRectangle2D.Float(0.5f, 0.5f, getWidth() - 1, getHeight() - 1, UIConstants.ARC, UIConstants.ARC); g2d.setColor(UIConstants.LINE_COLOR); g2d.draw(shape); } }; addButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { popupMenu.show(MapGroupExtensionPane.this, addButton.getX() + 1, addButton.getY() + addButton.getHeight()); } }); add(addButton, BorderLayout.SOUTH); initPopupMenu(); } private void initPopupMenu() { popupMenu = new JPopupMenu() { @Override public Dimension getPreferredSize() { Dimension dimension = new Dimension(); dimension.height = super.getPreferredSize().height; dimension.width = addButton.getWidth() - 2; return dimension; } }; JMenuItem worldMap = new JMenuItem(TYPE_NAMES[WORD]); popupMenu.add(worldMap); worldMap.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { groupExtensionPane.addData(TYPE_NAMES[WORD], TYPE_NAMES[WORD], true); } }); JMenuItem countMap = new JMenuItem(TYPE_NAMES[NATION]); popupMenu.add(countMap); countMap.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { groupExtensionPane.addData(TYPE_NAMES[NATION], TYPE_NAMES[NATION], true); } }); JMenuItem proMap = new JMenuItem(TYPE_NAMES[STATE]); popupMenu.add(proMap); proMap.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { groupExtensionPane.addData(TYPE_NAMES[STATE], TYPE_NAMES[STATE], true); } }); JMenuItem menu = new JMenuItem(TYPE_NAMES[USER]); popupMenu.add(menu); menu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { groupExtensionPane.addData(TYPE_NAMES[USER], TYPE_NAMES[USER], true); } }); } private void doEdit(ChangeEvent e) { MouseEvent event = (MouseEvent) e.getSource(); JPopupMenu editPopMenu = new JPopupMenu(); final String oldName = Utils.objectToString(groupExtensionPane.getSelectedObject()); editPopMenu.add(createAreaItem(oldName)); editPopMenu.add(createMarkerItem(oldName)); editPopMenu.add(createLayerItem(oldName)); editPopMenu.add(createRenameItem()); editPopMenu.show(MapGroupExtensionPane.this, event.getXOnScreen() - OFFSET_X, event.getYOnScreen() - OFFSET_Y); } private void mapCheckBeforeEdit(String name){ if(MapSvgXMLHelper.getInstance().containsMapName(name) || MapSvgXMLHelper.getInstance().getNewMapAttr(name)!=null){ return; } MapSvgAttr attr = new MapSvgAttr(); attr.setFilePath(MapSvgXMLHelper.customMapPath() + CoreConstants.SEPARATOR + name + ".svg"); MapSvgXMLHelper.getInstance().addNewSvgMaps(name,attr); } private JMenuItem createAreaItem(final String oldName) { JMenuItem editFileItem = new JMenuItem(Inter.getLocText(new String[]{"Edit", "Image", "Filed"})); editFileItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { final MapCustomPane image = new MapCustomPane(); image.setImageSelectType(MapShapeValue.AREA); image.populateBean(oldName); image.setTypeNameAndMapName(groupExtensionPane.getSelectedType(), Utils.objectToString(groupExtensionPane.getSelectedObject())); mapCheckBeforeEdit(oldName); final Image oldImage = getMapImage(oldName); BasicDialog dialog = image.showMediumWindow(SwingUtilities.getWindowAncestor(MapGroupExtensionPane.this), new DialogActionAdapter() { public void doOk() { image.updateBean(); // 比较两个前后的名字是否相同, 是图片 如果图片不同, 则直接比较 Image newImage = getMapImage(oldName); if(!ComparatorUtils.equals(oldImage, newImage)) { fireStateChange(); } //versionID递增 MapSvgAttr old = MapSvgXMLHelper.getInstance().getMapAttr(oldName); if(old != null) { old.addVersionID(); } saveMapInfo(oldName); refresh(); } }); dialog.setVisible(true); } }); return editFileItem; } //根据地图的名字返回地图的图片 private Image getMapImage(String mapName) { if (MapSvgXMLHelper.getInstance().containsMapName(mapName)) { MapSvgAttr mapAttr = MapSvgXMLHelper.getInstance().getMapAttr(mapName); if(mapAttr == null) { return null; } return mapAttr.getMapImage(); } return null; } private JMenuItem createMarkerItem(final String oldName) { JMenuItem editMarkerItem = new JMenuItem(Inter.getLocText(new String[]{"Edit", "Image", "Marker"})); editMarkerItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { final MapCustomPane image = new MapCustomPane(); image.setImageSelectType(MapShapeValue.POINT); image.populateBean(oldName); mapCheckBeforeEdit(oldName); final Image oldImage = getMapImage(oldName); BasicDialog dialog = image.showMediumWindow(SwingUtilities.getWindowAncestor(image), new DialogActionAdapter() { public void doOk() { image.updateBean(); Image newImage = getMapImage(oldName); if(!ComparatorUtils.equals(oldImage, newImage)) { fireStateChange(); } //versionID递增 MapSvgAttr old = MapSvgXMLHelper.getInstance().getMapAttr(oldName); if(old != null) { old.addVersionID(); } saveMapInfo(oldName); refresh(); } }); dialog.setVisible(true); } }); return editMarkerItem; } private JMenuItem createLayerItem(final String oldName) { JMenuItem corrItem = new JMenuItem(Inter.getLocText(new String[]{"Filed", "Corresponding_Fields"})); corrItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { final MapDefiAreaNamePane namedPane = new MapDefiAreaNamePane(); namedPane.populateBean(oldName); mapCheckBeforeEdit(oldName); BasicDialog dialog = namedPane.showMediumWindow(SwingUtilities.getWindowAncestor(namedPane), new DialogActionAdapter() { public void doOk() { namedPane.updateBean();// 地图的名称 value对应情况 MapSvgAttr old = MapSvgXMLHelper.getInstance().getMapAttr(oldName); if(old != null) { old.addVersionID(); } saveMapInfo(oldName); } }); dialog.setVisible(true); refresh(); } }); return corrItem; } private void showRenameWaring(String newName){ JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), "\"" + newName + "\"" + Inter.getLocText("Utils-has_been_existed") + "!", Inter.getLocText("FR-Designer_Alert"), JOptionPane.WARNING_MESSAGE); } private JMenuItem createRenameItem() { JMenuItem renameItem = new JMenuItem(Inter.getLocText("FR-Chart-Map_Rename")); renameItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String newName = JOptionPane.showInputDialog(DesignerContext.getDesignerFrame().getContentPane(), Inter.getLocText("FR-Chart-Map_Rename"), groupExtensionPane.getSelectedObject()); if (StringUtils.isNotBlank(newName)) { String oldName = Utils.objectToString(groupExtensionPane.getSelectedObject()); if(ComparatorUtils.equals(oldName, newName)){ return; } //本地在看看临时的helper里面有没有 if(MapSvgXMLHelper.getInstance().getNewMapAttr(newName) != null){ showRenameWaring(newName); return; } try{//提醒名字已存在 if(FRContext.getCurrentEnv().fileExists(StableUtils.pathJoin( new String[]{MapSvgXMLHelper.relativeDefaultMapPath(),newName+SvgProvider.EXTENSION}))){ showRenameWaring(newName); return; } if(FRContext.getCurrentEnv().fileExists(StableUtils.pathJoin( new String[]{MapSvgXMLHelper.relativeCustomMapPath(), newName + SvgProvider.EXTENSION}))){ showRenameWaring(newName); return; } MapSvgAttr editingAttr = MapSvgXMLHelper.getInstance().getMapAttr(oldName); if(editingAttr == null){ editingAttr = MapSvgXMLHelper.getInstance().getNewMapAttr(oldName); } if( editingAttr == null) { return; } editingAttr.renameMap(newName); groupExtensionPane.setValueAtCurrentSelectIndex(newName); fireStateChange(); saveMapInfo(newName); FRContext.getCurrentEnv().deleteFile( StableUtils.pathJoin(new String[]{MapSvgXMLHelper.relativeDefaultMapPath(),oldName+SvgProvider.EXTENSION})); FRContext.getCurrentEnv().deleteFile( StableUtils.pathJoin(new String[]{MapSvgXMLHelper.relativeCustomMapPath(),oldName+SvgProvider.EXTENSION})); refresh(); }catch (Exception exp){ FRLogger.getLogger().error(exp.getMessage()); } } } }); return renameItem; } private void refresh() { this.validate(); this.repaint(); DesignerFrame frame = DesignerContext.getDesignerFrame(); if(frame != null) { frame.repaint();//kunsnat: 图表属性没变, 只是读取时 内容变化. } } //保存修改过的地图信息 private void saveMapInfo(final String mapName) { SwingWorker worker = new SwingWorker() { @Override protected Integer doInBackground() throws Exception { MapSvgAttr attr = MapSvgXMLHelper.getInstance().getMapAttr(mapName);// 只有在编辑地图时才需要储存相关数据 @kuns if(attr != null){ attr.writeBack(mapName); } return 0; } @Override protected void done() { FRLogger.getLogger().info(Inter.getLocText("FR-Chart-Map_Saved")); // 地图已经保存. } }; worker.execute(); DesignerEnvManager.addWorkers(worker); } private void fireStateChange() { for (int i = changeListeners.size(); i > 0; i--) { changeListeners.get(i - 1).stateChanged(new javax.swing.event.ChangeEvent(this)); } } /** * 更新地图属性 * @return 返回地图名称. */ public String updateBean(MapPlot plot) { if(!hasPopulated){ this.populateBean(plot); hasPopulated = true; } MapHelper helper = plot.isSvgMap() ? MapSvgXMLHelper.getInstance() : MapXMLHelper.getInstance(); helper.clearCateNames(); for (String type : TYPE_NAMES) { Object[] datas = groupExtensionPane.getData(type); for (Object name : datas) { helper.addCateNames(type, name); } } return Utils.objectToString(groupExtensionPane.getSelectedObject()); } /** * 更新地图名称 * @param mapPlot 地图 */ public void populateBean(MapPlot mapPlot) { hasPopulated = false; groupExtensionPane.clearData(); for (String type : TYPE_NAMES) { MapHelper helper = mapPlot.isSvgMap() ? MapSvgXMLHelper.getInstance() : MapXMLHelper.getInstance(); java.util.List list = helper.getNamesListWithCateName(type); for (Object name : list) { groupExtensionPane.addData(name, type); } } groupExtensionPane.setSelectedObject(mapPlot.getMapName()); hasPopulated = true; } /** * 给组件登记一个观察者监听事件 * * @param listener 观察者监听事件 */ public void registerChangeListener(final UIObserverListener listener) { changeListeners.add(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent e) { listener.doChange(); } }); } /** * 组件是否需要响应添加的观察者事件 * * @return 如果需要响应观察者事件则返回true,否则返回false */ public boolean shouldResponseChangeListener() { return true; } public void setEnabled(boolean isEnabled){ super.setEnabled(isEnabled); addButton.setEnabled(isEnabled); popupMenu.setEnabled(isEnabled); groupExtensionPane.setEnabled(isEnabled); } } \ No newline at end of file +package com.fr.design.chart.series.PlotSeries; import com.fr.base.*; import com.fr.chart.chartattr.MapPlot; import com.fr.chart.chartglyph.MapShapeValue; import com.fr.design.DesignerEnvManager; import com.fr.design.constants.UIConstants; import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.event.ChangeEvent; import com.fr.design.event.ChangeListener; import com.fr.design.event.UIObserver; import com.fr.design.event.UIObserverListener; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerFrame; import com.fr.general.ComparatorUtils; import com.fr.general.FRLogger; import com.fr.general.Inter; import com.fr.stable.CoreConstants; import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; import com.fr.stable.SvgProvider; import javax.swing.*; import javax.swing.event.ListSelectionEvent; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.geom.RoundRectangle2D; import java.util.ArrayList; /** * Created by IntelliJ IDEA. * Author : Richer * Version: 7.0.3 * Date: 12-12-29 * Time: 下午2:41 */ public class MapGroupExtensionPane extends BasicPane implements UIObserver { private static final String[] TYPE_NAMES = new String[]{ Inter.getLocText("FR-Chart-World_Map"), Inter.getLocText("FR-Chart-State_Map"), Inter.getLocText("FR-Chart-Province_Map"), Inter.getLocText("FR-Chart-Custom_Map")}; private static final int WORD = 0; private static final int NATION = 1; private static final int STATE = 2; private static final int USER = 3; private static final int OFFSET_X = 800; private static final int OFFSET_Y = 200; private UIGroupExtensionPane groupExtensionPane; private UIButton addButton; private JPopupMenu popupMenu; private ArrayList changeListeners = new ArrayList(); private boolean hasPopulated = false; @Override protected String title4PopupWindow() { return "Map"; } public MapGroupExtensionPane() { setLayout(new BorderLayout()); groupExtensionPane = new UIGroupExtensionPane(TYPE_NAMES){ /** * 新添加的数据的序号 * @param data 数据 */ protected void dealNewAddedDataIndex(Object data){ String newName = (String)data; MapSvgXMLHelper helper = MapSvgXMLHelper.getInstance(); if(helper.getNewMapAttr(newName) != null){ return; } MapSvgAttr attr = new MapSvgAttr(); attr.setFilePath(MapSvgXMLHelper.customMapPath() + CoreConstants.SEPARATOR + newName + ".svg"); helper.addNewSvgMaps(attr.getName(), attr); } /** * 一次鼠标的点击会有两次事件响应(按下和释放)。前者的事件属性中getValueIsAdjusting()=true,后者是false。 * 是否响应list值改变 * @return 鼠标按下时不响应,先响应mousePress事件,在鼠标释放是再响应list值改编的事件,并且点击删除不触发更新,并且populate后触发更新 */ protected boolean isRespondToValueChange(ListSelectionEvent e){ return !e.getValueIsAdjusting() && !this.isPressOnDelete() && hasPopulated; } }; groupExtensionPane.addSelectionChangeListener(new ChangeListener() { @Override public void fireChanged(ChangeEvent event) { fireStateChange(); } }); groupExtensionPane.addItemEditListener(new ChangeListener() { @Override public void fireChanged(ChangeEvent event) { doEdit(event); } }); groupExtensionPane.addDeleteListener(new ChangeListener() { @Override public void fireChanged(ChangeEvent event) { //这么写有点问题 String oldName = Utils.objectToString(groupExtensionPane.getSelectedObject()); saveMapInfo(oldName); } }); setPreferredSize(new Dimension(400, 210)); add(groupExtensionPane, BorderLayout.CENTER); addButton = new UIButton(BaseUtils.readIcon("/com/fr/design/images/buttonicon/add.png")) { @Override protected void paintBorder(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setStroke(UIConstants.BS); Shape shape = new RoundRectangle2D.Float(0.5f, 0.5f, getWidth() - 1, getHeight() - 1, UIConstants.ARC, UIConstants.ARC); g2d.setColor(UIConstants.LINE_COLOR); g2d.draw(shape); } }; addButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { popupMenu.show(MapGroupExtensionPane.this, addButton.getX() + 1, addButton.getY() + addButton.getHeight()); } }); add(addButton, BorderLayout.SOUTH); initPopupMenu(); } private void initPopupMenu() { popupMenu = new JPopupMenu() { @Override public Dimension getPreferredSize() { Dimension dimension = new Dimension(); dimension.height = super.getPreferredSize().height; dimension.width = addButton.getWidth() - 2; return dimension; } }; JMenuItem worldMap = new JMenuItem(TYPE_NAMES[WORD]); popupMenu.add(worldMap); worldMap.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { groupExtensionPane.addData(TYPE_NAMES[WORD], TYPE_NAMES[WORD], true); } }); JMenuItem countMap = new JMenuItem(TYPE_NAMES[NATION]); popupMenu.add(countMap); countMap.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { groupExtensionPane.addData(TYPE_NAMES[NATION], TYPE_NAMES[NATION], true); } }); JMenuItem proMap = new JMenuItem(TYPE_NAMES[STATE]); popupMenu.add(proMap); proMap.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { groupExtensionPane.addData(TYPE_NAMES[STATE], TYPE_NAMES[STATE], true); } }); JMenuItem menu = new JMenuItem(TYPE_NAMES[USER]); popupMenu.add(menu); menu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { groupExtensionPane.addData(TYPE_NAMES[USER], TYPE_NAMES[USER], true); } }); } private void doEdit(ChangeEvent e) { MouseEvent event = (MouseEvent) e.getSource(); JPopupMenu editPopMenu = new JPopupMenu(); final String oldName = Utils.objectToString(groupExtensionPane.getSelectedObject()); editPopMenu.add(createAreaItem(oldName)); editPopMenu.add(createMarkerItem(oldName)); editPopMenu.add(createLayerItem(oldName)); editPopMenu.add(createRenameItem()); editPopMenu.show(MapGroupExtensionPane.this, event.getXOnScreen() - OFFSET_X, event.getYOnScreen() - OFFSET_Y); } private void mapCheckBeforeEdit(String name){ if(MapSvgXMLHelper.getInstance().containsMapName(name) || MapSvgXMLHelper.getInstance().getNewMapAttr(name)!=null){ return; } MapSvgAttr attr = new MapSvgAttr(); attr.setFilePath(MapSvgXMLHelper.customMapPath() + CoreConstants.SEPARATOR + name + ".svg"); MapSvgXMLHelper.getInstance().addNewSvgMaps(name,attr); } private JMenuItem createAreaItem(final String oldName) { JMenuItem editFileItem = new JMenuItem(Inter.getLocText(new String[]{"Edit", "Image", "Filed"})); editFileItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { final MapCustomPane image = new MapCustomPane(); image.setImageSelectType(MapShapeValue.AREA); image.populateBean(oldName); image.setTypeNameAndMapName(groupExtensionPane.getSelectedType(), Utils.objectToString(groupExtensionPane.getSelectedObject())); mapCheckBeforeEdit(oldName); final Image oldImage = getMapImage(oldName); BasicDialog dialog = image.showMediumWindow(SwingUtilities.getWindowAncestor(MapGroupExtensionPane.this), new DialogActionAdapter() { public void doOk() { image.updateBean(); // 比较两个前后的名字是否相同, 是图片 如果图片不同, 则直接比较 Image newImage = getMapImage(oldName); if(!ComparatorUtils.equals(oldImage, newImage)) { fireStateChange(); } //versionID递增 MapSvgAttr old = MapSvgXMLHelper.getInstance().getMapAttr(oldName); if(old != null) { old.addVersionID(); } saveMapInfo(oldName); refresh(); } }); dialog.setVisible(true); } }); return editFileItem; } //根据地图的名字返回地图的图片 private Image getMapImage(String mapName) { if (MapSvgXMLHelper.getInstance().containsMapName(mapName)) { MapSvgAttr mapAttr = MapSvgXMLHelper.getInstance().getMapAttr(mapName); if(mapAttr == null) { return null; } return mapAttr.getMapImage(); } return null; } private JMenuItem createMarkerItem(final String oldName) { JMenuItem editMarkerItem = new JMenuItem(Inter.getLocText(new String[]{"Edit", "Image", "Marker"})); editMarkerItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { final MapCustomPane image = new MapCustomPane(); image.setImageSelectType(MapShapeValue.POINT); image.populateBean(oldName); mapCheckBeforeEdit(oldName); final Image oldImage = getMapImage(oldName); BasicDialog dialog = image.showMediumWindow(SwingUtilities.getWindowAncestor(image), new DialogActionAdapter() { public void doOk() { image.updateBean(); Image newImage = getMapImage(oldName); if(!ComparatorUtils.equals(oldImage, newImage)) { fireStateChange(); } //versionID递增 MapSvgAttr old = MapSvgXMLHelper.getInstance().getMapAttr(oldName); if(old != null) { old.addVersionID(); } saveMapInfo(oldName); refresh(); } }); dialog.setVisible(true); } }); return editMarkerItem; } private JMenuItem createLayerItem(final String oldName) { JMenuItem corrItem = new JMenuItem(Inter.getLocText(new String[]{"Filed", "Corresponding_Fields"})); corrItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { final MapDefiAreaNamePane namedPane = new MapDefiAreaNamePane(); namedPane.populateBean(oldName); mapCheckBeforeEdit(oldName); BasicDialog dialog = namedPane.showMediumWindow(SwingUtilities.getWindowAncestor(namedPane), new DialogActionAdapter() { public void doOk() { namedPane.updateBean();// 地图的名称 value对应情况 MapSvgAttr old = MapSvgXMLHelper.getInstance().getMapAttr(oldName); if(old != null) { old.addVersionID(); } saveMapInfo(oldName); } }); dialog.setVisible(true); refresh(); } }); return corrItem; } private void showRenameWaring(String newName){ JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), "\"" + newName + "\"" + Inter.getLocText("Utils-has_been_existed") + "!", Inter.getLocText("FR-Designer_Alert"), JOptionPane.WARNING_MESSAGE); } private JMenuItem createRenameItem() { JMenuItem renameItem = new JMenuItem(Inter.getLocText("FR-Chart-Map_Rename")); renameItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String newName = JOptionPane.showInputDialog(DesignerContext.getDesignerFrame().getContentPane(), Inter.getLocText("FR-Chart-Map_Rename"), groupExtensionPane.getSelectedObject()); if (StringUtils.isNotBlank(newName)) { String oldName = Utils.objectToString(groupExtensionPane.getSelectedObject()); if(ComparatorUtils.equals(oldName, newName)){ return; } //本地在看看临时的helper里面有没有 if(MapSvgXMLHelper.getInstance().getNewMapAttr(newName) != null){ showRenameWaring(newName); return; } try{//提醒名字已存在 if(FRContext.getCurrentEnv().fileExists(StableUtils.pathJoin( new String[]{MapSvgXMLHelper.relativeDefaultMapPath(),newName+SvgProvider.EXTENSION}))){ showRenameWaring(newName); return; } if(FRContext.getCurrentEnv().fileExists(StableUtils.pathJoin( new String[]{MapSvgXMLHelper.relativeCustomMapPath(), newName + SvgProvider.EXTENSION}))){ showRenameWaring(newName); return; } MapSvgAttr editingAttr = MapSvgXMLHelper.getInstance().getMapAttr(oldName); if(editingAttr == null){ editingAttr = MapSvgXMLHelper.getInstance().getNewMapAttr(oldName); } if( editingAttr == null) { return; } editingAttr.renameMap(newName); groupExtensionPane.setValueAtCurrentSelectIndex(newName); fireStateChange(); saveMapInfo(newName); FRContext.getCurrentEnv().deleteFile( StableUtils.pathJoin(new String[]{MapSvgXMLHelper.relativeDefaultMapPath(),oldName+SvgProvider.EXTENSION})); FRContext.getCurrentEnv().deleteFile( StableUtils.pathJoin(new String[]{MapSvgXMLHelper.relativeCustomMapPath(),oldName+SvgProvider.EXTENSION})); refresh(); }catch (Exception exp){ FRLogger.getLogger().error(exp.getMessage()); } } } }); return renameItem; } private void refresh() { this.validate(); this.repaint(); DesignerFrame frame = DesignerContext.getDesignerFrame(); if(frame != null) { frame.repaint();//kunsnat: 图表属性没变, 只是读取时 内容变化. } } //保存修改过的地图信息 private void saveMapInfo(final String mapName) { SwingWorker worker = new SwingWorker() { @Override protected Integer doInBackground() throws Exception { MapSvgAttr attr = MapSvgXMLHelper.getInstance().getMapAttr(mapName);// 只有在编辑地图时才需要储存相关数据 @kuns if(attr != null){ attr.writeBack(mapName); } return 0; } @Override protected void done() { FRLogger.getLogger().info(Inter.getLocText("FR-Chart-Map_Saved")); // 地图已经保存. } }; worker.execute(); DesignerEnvManager.addWorkers(worker); } private void fireStateChange() { for (int i = changeListeners.size(); i > 0; i--) { changeListeners.get(i - 1).stateChanged(new javax.swing.event.ChangeEvent(this)); } } /** * 更新地图属性 * @return 返回地图名称. */ public String updateBean(MapPlot plot) { if(!hasPopulated){ this.populateBean(plot); hasPopulated = true; } MapHelper helper = plot.isSvgMap() ? MapSvgXMLHelper.getInstance() : MapXMLHelper.getInstance(); helper.clearCateNames(); for (String type : TYPE_NAMES) { Object[] datas = groupExtensionPane.getData(type); for (Object name : datas) { helper.addCateNames(type, name); } } return Utils.objectToString(groupExtensionPane.getSelectedObject()); } /** * 更新地图名称 * @param mapPlot 地图 */ public void populateBean(MapPlot mapPlot) { hasPopulated = false; groupExtensionPane.clearData(); for (String type : TYPE_NAMES) { MapHelper helper = mapPlot.isSvgMap() ? MapSvgXMLHelper.getInstance() : MapXMLHelper.getInstance(); java.util.List list = helper.getNamesListWithCateName(type); for (Object name : list) { groupExtensionPane.addData(name, type); } } groupExtensionPane.setSelectedObject(mapPlot.getMapName()); hasPopulated = true; } /** * 给组件登记一个观察者监听事件 * * @param listener 观察者监听事件 */ public void registerChangeListener(final UIObserverListener listener) { changeListeners.add(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent e) { listener.doChange(); } }); } /** * 组件是否需要响应添加的观察者事件 * * @return 如果需要响应观察者事件则返回true,否则返回false */ public boolean shouldResponseChangeListener() { return true; } public void setEnabled(boolean isEnabled){ super.setEnabled(isEnabled); addButton.setEnabled(isEnabled); popupMenu.setEnabled(isEnabled); groupExtensionPane.setEnabled(isEnabled); } } \ No newline at end of file diff --git a/designer_chart/src/com/fr/design/chart/series/PlotSeries/MapImageEditPane.java b/designer_chart/src/com/fr/design/chart/series/PlotSeries/MapImageEditPane.java index 6f9c15c55f..4aff10c379 100644 --- a/designer_chart/src/com/fr/design/chart/series/PlotSeries/MapImageEditPane.java +++ b/designer_chart/src/com/fr/design/chart/series/PlotSeries/MapImageEditPane.java @@ -1,34 +1,13 @@ package com.fr.design.chart.series.PlotSeries; -import java.awt.AlphaComposite; -import java.awt.BasicStroke; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.Image; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.awt.event.MouseMotionListener; -import java.awt.geom.GeneralPath; -import java.util.*; - -import javax.swing.BoxLayout; -import javax.swing.DefaultListModel; -import javax.swing.JComponent; -import javax.swing.JList; -import javax.swing.JPanel; -import javax.swing.SwingUtilities; - -import com.fr.base.*; -import com.fr.chart.base.MapSvgAttr; -import com.fr.chart.base.MapSvgXMLHelper; +import com.fr.base.BaseUtils; +import com.fr.base.MapSvgAttr; +import com.fr.base.MapSvgXMLHelper; +import com.fr.base.Utils; import com.fr.chart.chartglyph.MapShapeValue; import com.fr.design.beans.BasicBeanPane; +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.icontainer.UIScrollPane; @@ -37,13 +16,23 @@ import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.itable.UISelectTable; import com.fr.design.gui.itable.UITableNoOptionUI; import com.fr.design.gui.itextfield.UITextField; -import com.fr.design.dialog.DialogActionAdapter; -import com.fr.design.dialog.UIDialog; +import com.fr.design.utils.gui.GUICoreUtils; import com.fr.general.ComparatorUtils; import com.fr.general.Inter; import com.fr.stable.CoreGraphHelper; import com.fr.stable.StringUtils; -import com.fr.design.utils.gui.GUICoreUtils; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import java.awt.geom.GeneralPath; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; /** * 地图 图片编辑界面 选中图片 编辑. 支持鼠标选中等事件 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..1e26f37b01 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.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 diff --git a/designer_chart/src/com/fr/design/mainframe/MapEditPane.java b/designer_chart/src/com/fr/design/mainframe/MapEditPane.java index 4c137afb7c..2950a4d1fd 100644 --- a/designer_chart/src/com/fr/design/mainframe/MapEditPane.java +++ b/designer_chart/src/com/fr/design/mainframe/MapEditPane.java @@ -1,7 +1,7 @@ package com.fr.design.mainframe; -import com.fr.chart.base.MapSvgAttr; -import com.fr.chart.base.MapSvgXMLHelper; +import com.fr.base.MapSvgAttr; +import com.fr.base.MapSvgXMLHelper; import com.fr.chart.chartglyph.MapShapeValue; import com.fr.design.beans.BasicBeanPane; import com.fr.design.chart.series.PlotSeries.AbstrctMapAttrEditPane;