Java tutorial
/* * $Id: EditorActions.java,v 1.6 2009/12/08 19:52:50 gaudenz Exp $ * Copyright (c) 2001-2009, JGraph Ltd * * All rights reserved. * * See LICENSE file for license details. If you are unable to locate * this file please contact info (at) jgraph (dot) com. */ package com.mxgraph.examples.swing.editor; import it.sauronsoftware.ftp4j.FTPAbortedException; import it.sauronsoftware.ftp4j.FTPClient; import it.sauronsoftware.ftp4j.FTPDataTransferException; import it.sauronsoftware.ftp4j.FTPException; import it.sauronsoftware.ftp4j.FTPIllegalReplyException; import java.awt.BasicStroke; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Frame; import java.awt.GridBagLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.image.BufferedImage; import java.awt.print.PageFormat; import java.awt.print.Paper; import java.awt.print.PrinterException; import java.awt.print.PrinterJob; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyVetoException; import java.io.File; import java.io.IOException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Hashtable; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; import javax.imageio.ImageIO; import javax.swing.AbstractAction; import javax.swing.AbstractButton; import javax.swing.Action; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JCheckBoxMenuItem; import javax.swing.JColorChooser; import javax.swing.JDialog; import javax.swing.JEditorPane; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JInternalFrame; import javax.swing.JMenuItem; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JPasswordField; import javax.swing.JPopupMenu; import javax.swing.JOptionPane; import javax.swing.JSplitPane; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.SwingUtilities; import javax.swing.filechooser.FileFilter; import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.text.html.HTML; import javax.swing.text.html.HTMLDocument; import javax.swing.text.html.HTMLEditorKit; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.CategoryAxis; import org.jfree.chart.axis.DateAxis; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.PiePlot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.XYPlot; import org.w3c.dom.Document; import show.encodeelement.Task; import task.TaskTree; import com.mxgraph.analysis.mxDistanceCostFunction; import com.mxgraph.analysis.mxGraphAnalysis; import com.mxgraph.examples.swing.GraphEditor; import com.mxgraph.examples.swing.components.DynamicTree; import com.mxgraph.examples.swing.dialog.CellBoundsMsg; import com.mxgraph.examples.swing.dialog.MyInternalFrame; import com.mxgraph.examples.swing.editor.chen.CellConfigure; import com.mxgraph.examples.swing.editor.chen.CellEditor; import com.mxgraph.examples.swing.editor.chen.KeyComparator; import com.mxgraph.examples.swing.editor.chen.PropertiesHelper; import com.mxgraph.examples.swing.editor.chen.SaveDialog; import com.mxgraph.io.mxCodec; import com.mxgraph.model.mxCell; import com.mxgraph.model.mxGeometry; import com.mxgraph.model.mxGraphModel; import com.mxgraph.model.mxGraphModel.mxPageColorChange; import com.mxgraph.model.mxGraphModel.mxSelfAdaptiveChange; import com.mxgraph.model.mxIGraphModel; import com.mxgraph.swing.mxGraphComponent; import com.mxgraph.swing.mxGraphOutline; import com.mxgraph.swing.handler.mxConnectionHandler; import com.mxgraph.swing.util.mxGraphActions; import com.mxgraph.swing.util.mxGraphActions.PaintTableAction; import com.mxgraph.swing.view.mxCellEditor; import com.mxgraph.util.mxCellRenderer; import com.mxgraph.util.mxConstants; import com.mxgraph.util.mxResources; import com.mxgraph.util.mxUtils; import com.mxgraph.view.mxCellState; import com.mxgraph.view.mxGraph; import com.mxgraph.view.mxGraphView; import com.mxgraph.view.mxStylesheet; import com.mxgraph.yeli.dialog.NewFileDialog; import com.yeli.examples.senseor.ConfService; import edu.emory.mathcs.backport.java.util.Arrays; /** * @author Administrator * */ public class EditorActions { // public static class SaveShowAction extends AbstractAction implements Action { private static final long serialVersionUID = 1L; protected boolean showDialog; /** * */ public SaveShowAction(boolean showDialog) { // TODO Auto-generated constructor stub this.showDialog = showDialog; } @Override public void actionPerformed(ActionEvent e) { BasicGraphEditor editor = getEditor(e); editor.saveFile(showDialog); } } public static class SaveASAction extends AbstractAction implements Action { /** * */ protected boolean showDialog; /** * */ protected String lastDir = null; public SaveASAction(boolean showDialog) { // TODO Auto-generated constructor stub this.showDialog = showDialog; } @Override public void actionPerformed(ActionEvent e) { BasicGraphEditor editor = getEditor(e); MyInternalFrame frame = (MyInternalFrame) editor.getDesktop().getSelectedFrame(); if (frame == null) return; mxGraphComponent graphComponent = frame.getGraphComponent(); getCharInfo(graphComponent); mxGraph graph = graphComponent.getGraph(); FileFilter selectedFilter = null; FileFilter vmlFileFilter = new DefaultFileFilter(".html", "VML " + mxResources.get("file") + " (.html)"); String filename = null; String title = null; // if (showDialog /*|| editor.getCurrentFile() == null*/) { String wd; if (lastDir != null) { wd = lastDir; } else if (editor.getCurrentFile() != null) { wd = editor.getCurrentFile().getParent(); } else { wd = System.getProperty("user.dir"); } JFileChooser fc = new JFileChooser(wd); // Adds the default file format FileFilter defaultFilter = new DefaultFileFilter(".mxe", "mxGraph Editor " + mxResources.get("file") + " (.mxe)"); fc.addChoosableFileFilter(defaultFilter); // Adds special vector graphics formats and HTML fc.addChoosableFileFilter( new DefaultFileFilter(".svg", "SVG " + mxResources.get("file") + " (.svg)")); fc.addChoosableFileFilter(vmlFileFilter); fc.addChoosableFileFilter( new DefaultFileFilter(".html", "HTML " + mxResources.get("file") + " (.html)")); // Adds a filter for each supported image format Object[] imageFormats = ImageIO.getReaderFormatNames(); // Finds all distinct extensions HashSet<String> formats = new HashSet<String>(); for (int i = 0; i < imageFormats.length; i++) { String ext = imageFormats[i].toString().toLowerCase(); formats.add(ext); } imageFormats = formats.toArray(); for (int i = 0; i < imageFormats.length; i++) { String ext = imageFormats[i].toString(); fc.addChoosableFileFilter(new DefaultFileFilter("." + ext, ext.toUpperCase() + " " + mxResources.get("file") + " (." + ext + ")")); } // Adds filter that accepts all supported image formats fc.addChoosableFileFilter(new DefaultFileFilter.ImageFileFilter(mxResources.get("allImages"))); fc.setFileFilter(defaultFilter); int rc = fc.showDialog(null, mxResources.get("save")); if (rc != JFileChooser.APPROVE_OPTION) { return; } else { lastDir = fc.getSelectedFile().getParent(); } filename = fc.getSelectedFile().getAbsolutePath(); selectedFilter = fc.getFileFilter(); if (selectedFilter instanceof DefaultFileFilter) { String ext = ((DefaultFileFilter) selectedFilter).getExtension(); if (!filename.toLowerCase().endsWith(ext)) { filename += ext; } } if (new File(filename).exists() && JOptionPane.showConfirmDialog(graphComponent, mxResources.get("overwriteExistingFile")) != JOptionPane.YES_OPTION) { return; } // , if (!frame.getTitle().startsWith("")) { boolean isExist = false; JInternalFrame[] frames = editor.getDesktop().getAllFrames(); for (int i = 0; i < frames.length; i++) { MyInternalFrame f = (MyInternalFrame) frames[i]; if (filename.endsWith(f.getAbsolutePath())) { isExist = true; try { f.setSelected(true); if (!f.isMaximum()) { f.setMaximum(true); f.show(); } } catch (PropertyVetoException e1) { e1.printStackTrace(); } JOptionPane.showMessageDialog(f, filename + ""); return; } } } title = filename.substring(filename.lastIndexOf("\\") + 1); } else { filename = ((MyInternalFrame) editor.getDesktop().getSelectedFrame()).getAbsolutePath(); title = editor.getDesktop().getSelectedFrame().getTitle(); if (title.endsWith("*")) { title = title.substring(0, title.length() - 1); } } try { String ext = filename.substring(filename.lastIndexOf('.') + 1); if (ext.equalsIgnoreCase("svg")) { Color color = graphComponent.getBackground(); Document doc = mxCellRenderer.createSvgDocument(graph, null, 1, color, null); System.out.println(doc.getDocumentElement().getAttribute("xmlns")); System.out.println(mxUtils.getXml(doc.getDocumentElement())); mxUtils.writeFile(mxUtils.getXml(doc.getDocumentElement()), filename); } else if (selectedFilter == vmlFileFilter) { Document doc = mxCellRenderer.createVmlDocument(graph, null, 1, null, null); mxUtils.writeFile(mxUtils.getXml(doc.getDocumentElement()), filename); } else if (ext.equalsIgnoreCase("html")) { mxUtils.writeFile(mxUtils.getXml( mxCellRenderer.createHtmlDocument(graph, null, 1, null, null).getDocumentElement()), filename); } else if (ext.equalsIgnoreCase("mxe") || ext.equalsIgnoreCase("xml")) { //8.13 boolean changed = false; DynamicTree treePanel = editor.getTreePanel(); if (treePanel != null) { String workspace = treePanel.getWorkspace(); if (filename.length() >= workspace.length() && filename.substring(0, workspace.length()).equals(workspace) && !(new File(filename)).exists()) { changed = true; Map<String, Object> fileTableMap = CellConfigure.getTablesInDirectory(workspace); treePanel.clear(); treePanel.addWorkSpace(); editor.setFileTableMap(fileTableMap); } } // mxCodec codec = new mxCodec(); String xml = mxUtils.getXml(codec.encode(graph.getModel())); mxUtils.writeFile(xml, filename); frame.setModified(false); frame.setTitle(title); frame.setAbsolutePath(filename); frame.updateUI(); } else { Color bg = null; if ((!ext.equalsIgnoreCase("gif") && !ext.equalsIgnoreCase("png")) || JOptionPane.showConfirmDialog(graphComponent, mxResources.get("transparentBackground")) != JOptionPane.YES_OPTION) { bg = graphComponent.getBackground(); } BufferedImage image = mxCellRenderer.createBufferedImage(graph, null, 1, bg, graphComponent.isAntiAlias(), null, graphComponent.getCanvas()); if (image != null) { ImageIO.write(image, ext, new File(filename)); } else { JOptionPane.showMessageDialog(graphComponent, mxResources.get("noImageData")); } } } catch (Throwable ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(graphComponent, ex.toString(), mxResources.get("error"), JOptionPane.ERROR_MESSAGE); } //filenamelogMap Map<String, String> logMap = editor.getLogMap(); logMap.put(filename, editor.getNowTime()); } private void getCharInfo(mxGraphComponent graphComponent) { mxGraph graph = graphComponent.getGraph(); Object[] cells = graph.getChildCells(graph.getDefaultParent()); for (int i = 0; i < cells.length; i++) { mxCell cell = (mxCell) cells[i]; Map<String, Object> map = cell.getChartInfoMap(); ChartPanel chartPanel = cell.getChartPanel(); if (chartPanel != null) { JFreeChart chart = chartPanel.getChart(); if (cell.getStyle() != null && cell.getStyle().equals("barchart")) { CategoryPlot plot = (CategoryPlot) chart.getPlot(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); CategoryAxis domainAxis = plot.getDomainAxis(); // String title = chart.getTitle().getText(); String titleFont = chart.getTitle().getFont().getFontName(); int titleFontSize = chart.getTitle().getFont().getSize(); int titleFontStyle = chart.getTitle().getFont().getStyle(); int titleColor = ((Color) chart.getTitle().getPaint()).getRGB(); int chatBgroundColor = ((Color) chart.getBackgroundPaint()).getRGB(); /* String chartItemFont = chart.getLegend().getItemFont().getName(); int chartItemFontSize = chart.getLegend().getItemFont().getSize(); int chartItemFontStyle = chart.getLegend().getItemFont().getStyle(); int chartItemColor = ((Color)chart.getLegend().getItemPaint()).getRGB(); */ // String domainAxisLabel = domainAxis.getLabel(); String domainFont = domainAxis.getLabelFont().getName(); int domainFontSize = domainAxis.getLabelFont().getSize(); int domainFontStyle = domainAxis.getLabelFont().getStyle(); int domainColor = ((Color) domainAxis.getLabelPaint()).getRGB(); String domainTickLabelFont = domainAxis.getTickLabelFont().getName(); int domainTickLabelFontSize = domainAxis.getTickLabelFont().getSize(); int domainTickLabelFontStyle = domainAxis.getTickLabelFont().getStyle(); // String rangeAxisLabel = rangeAxis.getLabel(); String rangeFont = rangeAxis.getLabelFont().getName(); int rangeFontSize = rangeAxis.getLabelFont().getSize(); int rangeFontStyle = rangeAxis.getLabelFont().getStyle(); int rangeColor = ((Color) rangeAxis.getLabelPaint()).getRGB(); String rangeTickLabelFont = rangeAxis.getTickLabelFont().getName(); int rangeTickLabelFontSize = rangeAxis.getTickLabelFont().getSize(); int rangeTickLabelFontStyle = rangeAxis.getTickLabelFont().getStyle(); // int plotBgroundColor = ((Color) plot.getBackgroundPaint()).getRGB(); int plotOutlineColor = ((Color) plot.getOutlinePaint()).getRGB(); float plotOutlineWith = ((BasicStroke) plot.getOutlineStroke()).getLineWidth(); String plotOrientation = ((PlotOrientation) plot.getOrientation()).toString(); //== PlotOrientation.VERTICAL // plot.setOrientation(PlotOrientation.HORIZONTAL); //System.out.println(plotOutlineWith); // map.put("title", title); map.put("titleFont", titleFont); map.put("titleFontSize", titleFontSize); map.put("titleFontStyle", titleFontStyle); map.put("titleColor", titleColor); map.put("chatBgroundColor", chatBgroundColor); // map.put("domainAxisLabel", domainAxisLabel); map.put("domainFont", domainFont); map.put("domainFontSize", domainFontSize); map.put("domainFontStyle", domainFontStyle); map.put("domainColor", domainColor); map.put("domainTickLabelFont", domainTickLabelFont); map.put("domainTickLabelFontSize", domainTickLabelFontSize); map.put("domainTickLabelFontStyle", domainTickLabelFontStyle); // map.put("rangeAxisLabel", rangeAxisLabel); map.put("rangeFontSize", rangeFontSize); map.put("rangeFont", rangeFont); map.put("rangeFontStyle", rangeFontStyle); map.put("rangeColor", rangeColor); map.put("rangeTickLabelFont", rangeTickLabelFont); map.put("rangeTickLabelFontSize", rangeTickLabelFontSize); map.put("rangeTickLabelFontStyle", rangeTickLabelFontStyle); // map.put("plotBgroundColor", plotBgroundColor); map.put("plotOutlineColor", plotOutlineColor); map.put("plotOutlineWith", plotOutlineWith); map.put("plotOrientation", plotOrientation); } else if (cell.getStyle() != null && cell.getStyle().equals("piechart")) { PiePlot piePlot = (PiePlot) chart.getPlot();// // String title = chart.getTitle().getText(); String titleFont = chart.getTitle().getFont().getFontName(); int titleFontSize = chart.getTitle().getFont().getSize(); int titleFontStyle = chart.getTitle().getFont().getStyle(); int titleColor = ((Color) chart.getTitle().getPaint()).getRGB(); int chatBgroundColor = ((Color) chart.getBackgroundPaint()).getRGB(); // int plotBgroundColor = ((Color) piePlot.getBackgroundPaint()).getRGB(); int plotOutlineColor = ((Color) piePlot.getOutlinePaint()).getRGB(); float plotOutlineWith = ((BasicStroke) piePlot.getOutlineStroke()).getLineWidth(); // map.put("title", title); map.put("titleFont", titleFont); map.put("titleFontSize", titleFontSize); map.put("titleFontStyle", titleFontStyle); map.put("titleColor", titleColor); map.put("chatBgroundColor", chatBgroundColor); // map.put("plotBgroundColor", plotBgroundColor); map.put("plotOutlineColor", plotOutlineColor); map.put("plotOutlineWith", plotOutlineWith); } else if (cell.getStyle() != null && (cell.getStyle().equals("linechart") || cell.getStyle().equals("historylinechart"))) { XYPlot plot = (XYPlot) chart.getPlot(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); DateAxis domainAxis = (DateAxis) plot.getDomainAxis(); // String title = chart.getTitle().getText(); String titleFont = chart.getTitle().getFont().getFontName(); int titleFontSize = chart.getTitle().getFont().getSize(); int titleFontStyle = chart.getTitle().getFont().getStyle(); int titleColor = ((Color) chart.getTitle().getPaint()).getRGB(); int chatBgroundColor = ((Color) chart.getBackgroundPaint()).getRGB(); /* String chartItemFont = chart.getLegend().getItemFont().getName(); int chartItemFontSize = chart.getLegend().getItemFont().getSize(); int chartItemFontStyle = chart.getLegend().getItemFont().getStyle(); int chartItemColor = ((Color)chart.getLegend().getItemPaint()).getRGB(); */ // String domainAxisLabel = domainAxis.getLabel(); String domainFont = domainAxis.getLabelFont().getName(); int domainFontSize = domainAxis.getLabelFont().getSize(); int domainFontStyle = domainAxis.getLabelFont().getStyle(); int domainColor = ((Color) domainAxis.getLabelPaint()).getRGB(); String domainTickLabelFont = domainAxis.getTickLabelFont().getName(); int domainTickLabelFontSize = domainAxis.getTickLabelFont().getSize(); int domainTickLabelFontStyle = domainAxis.getTickLabelFont().getStyle(); // String rangeAxisLabel = rangeAxis.getLabel(); String rangeFont = rangeAxis.getLabelFont().getName(); int rangeFontSize = rangeAxis.getLabelFont().getSize(); int rangeFontStyle = rangeAxis.getLabelFont().getStyle(); int rangeColor = ((Color) rangeAxis.getLabelPaint()).getRGB(); String rangeTickLabelFont = rangeAxis.getTickLabelFont().getName(); int rangeTickLabelFontSize = rangeAxis.getTickLabelFont().getSize(); int rangeTickLabelFontStyle = rangeAxis.getTickLabelFont().getStyle(); // int plotBgroundColor = ((Color) plot.getBackgroundPaint()).getRGB(); int plotOutlineColor = ((Color) plot.getOutlinePaint()).getRGB(); float plotOutlineWith = ((BasicStroke) plot.getOutlineStroke()).getLineWidth(); String plotOrientation = ((PlotOrientation) plot.getOrientation()).toString(); //== PlotOrientation.VERTICAL // plot.setOrientation(PlotOrientation.HORIZONTAL); //System.out.println(plotOutlineWith); // map.put("title", title); map.put("titleFont", titleFont); map.put("titleFontSize", titleFontSize); map.put("titleFontStyle", titleFontStyle); map.put("titleColor", titleColor); map.put("chatBgroundColor", chatBgroundColor); // map.put("domainAxisLabel", domainAxisLabel); map.put("domainFont", domainFont); map.put("domainFontSize", domainFontSize); map.put("domainFontStyle", domainFontStyle); map.put("domainColor", domainColor); map.put("domainTickLabelFont", domainTickLabelFont); map.put("domainTickLabelFontSize", domainTickLabelFontSize); map.put("domainTickLabelFontStyle", domainTickLabelFontStyle); // map.put("rangeAxisLabel", rangeAxisLabel); map.put("rangeFontSize", rangeFontSize); map.put("rangeFont", rangeFont); map.put("rangeFontStyle", rangeFontStyle); map.put("rangeColor", rangeColor); map.put("rangeTickLabelFont", rangeTickLabelFont); map.put("rangeTickLabelFontSize", rangeTickLabelFontSize); map.put("rangeTickLabelFontStyle", rangeTickLabelFontStyle); // map.put("plotBgroundColor", plotBgroundColor); map.put("plotOutlineColor", plotOutlineColor); map.put("plotOutlineWith", plotOutlineWith); map.put("plotOrientation", plotOrientation); } } } } } public static final class SaveAllAction extends AbstractAction { /** * */ private static final long serialVersionUID = 3981665821266679043L; /** * */ protected boolean showDialog; /** * */ protected String lastDir = null; /** * */ public SaveAllAction(boolean showDialog) { this.showDialog = showDialog; } /** * */ public void actionPerformed(ActionEvent e) { BasicGraphEditor editor = getEditor(e); Map<String, String> logMap = editor.getLogMap(); JInternalFrame[] frames = editor.getDesktop().getAllFrames(); for (int j = 0; j < frames.length; j++) { MyInternalFrame frame = (MyInternalFrame) frames[j]; try { frame.setSelected(true); if (!frame.isMaximum()) { frame.setMaximum(true); frame.show(); } } catch (PropertyVetoException e1) { e1.printStackTrace(); } mxGraphComponent graphComponent = frame.getGraphComponent(); // } //----------------------------------------------------------------- // if (editor != null) // { // mxGraphComponent graphComponent = editor.getGraphComponent(); if (frame.getTitle().startsWith("")) showDialog = true; else showDialog = false; getCharInfo(graphComponent); mxGraph graph = graphComponent.getGraph(); FileFilter selectedFilter = null; FileFilter vmlFileFilter = new DefaultFileFilter(".html", "VML " + mxResources.get("file") + " (.html)"); String filename = null; String title = null; // if (showDialog /*|| editor.getCurrentFile() == null*/) { String wd; if (lastDir != null) { wd = lastDir; } else if (editor.getCurrentFile() != null) { wd = editor.getCurrentFile().getParent(); } else { wd = System.getProperty("user.dir"); } JFileChooser fc = new JFileChooser(wd); // Adds the default file format FileFilter defaultFilter = new DefaultFileFilter(".mxe", "mxGraph Editor " + mxResources.get("file") + " (.mxe)"); fc.addChoosableFileFilter(defaultFilter); // Adds special vector graphics formats and HTML fc.addChoosableFileFilter( new DefaultFileFilter(".svg", "SVG " + mxResources.get("file") + " (.svg)")); fc.addChoosableFileFilter(vmlFileFilter); fc.addChoosableFileFilter( new DefaultFileFilter(".html", "HTML " + mxResources.get("file") + " (.html)")); // Adds a filter for each supported image format Object[] imageFormats = ImageIO.getReaderFormatNames(); // Finds all distinct extensions HashSet<String> formats = new HashSet<String>(); for (int i = 0; i < imageFormats.length; i++) { String ext = imageFormats[i].toString().toLowerCase(); formats.add(ext); } imageFormats = formats.toArray(); for (int i = 0; i < imageFormats.length; i++) { String ext = imageFormats[i].toString(); fc.addChoosableFileFilter(new DefaultFileFilter("." + ext, ext.toUpperCase() + " " + mxResources.get("file") + " (." + ext + ")")); } // Adds filter that accepts all supported image formats fc.addChoosableFileFilter(new DefaultFileFilter.ImageFileFilter(mxResources.get("allImages"))); fc.setFileFilter(defaultFilter); int rc = fc.showDialog(null, mxResources.get("save")); if (rc != JFileChooser.APPROVE_OPTION) { return; } else { lastDir = fc.getSelectedFile().getParent(); } filename = fc.getSelectedFile().getAbsolutePath(); selectedFilter = fc.getFileFilter(); if (selectedFilter instanceof DefaultFileFilter) { String ext = ((DefaultFileFilter) selectedFilter).getExtension(); if (!filename.toLowerCase().endsWith(ext)) { filename += ext; } } if (new File(filename).exists() && JOptionPane.showConfirmDialog(graphComponent, mxResources.get("overwriteExistingFile")) != JOptionPane.YES_OPTION) { return; } // , if (!frame.getTitle().startsWith("")) { boolean isExist = false; //JInternalFrame[] frames = editor.getDesktop().getAllFrames(); for (int i = 0; i < frames.length; i++) { MyInternalFrame f = (MyInternalFrame) frames[i]; if (filename.endsWith(f.getAbsolutePath())) { isExist = true; try { f.setSelected(true); if (!f.isMaximum()) { f.setMaximum(true); f.show(); } } catch (PropertyVetoException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } JOptionPane.showMessageDialog(f, filename + ""); return; } } } title = filename.substring(filename.lastIndexOf("\\") + 1); } else { filename = ((MyInternalFrame) editor.getDesktop().getSelectedFrame()).getAbsolutePath(); title = editor.getDesktop().getSelectedFrame().getTitle(); if (title.endsWith("*")) { title = title.substring(0, title.length() - 1); } } try { String ext = filename.substring(filename.lastIndexOf('.') + 1); if (ext.equalsIgnoreCase("svg")) { Document doc = mxCellRenderer.createSvgDocument(graph, null, 1, null, null); mxUtils.writeFile(mxUtils.getXml(doc.getDocumentElement()), filename); } else if (selectedFilter == vmlFileFilter) { Document doc = mxCellRenderer.createVmlDocument(graph, null, 1, null, null); mxUtils.writeFile(mxUtils.getXml(doc.getDocumentElement()), filename); } else if (ext.equalsIgnoreCase("html")) { mxUtils.writeFile(mxUtils.getXml( mxCellRenderer.createHtmlDocument(graph, null, 1, null, null).getDocumentElement()), filename); } else if (ext.equalsIgnoreCase("mxe") || ext.equalsIgnoreCase("xml")) { //8.13 boolean changed = false; DynamicTree treePanel = editor.getTreePanel(); String workspace = treePanel.getWorkspace(); if (filename.length() >= workspace.length() && filename.substring(0, workspace.length()).equals(workspace) && !(new File(filename)).exists()) { changed = true; } // mxCodec codec = new mxCodec(); String xml = mxUtils.getXml(codec.encode(graph.getModel())); mxUtils.writeFile(xml, filename); frame.setModified(false); frame.setTitle(title); frame.setAbsolutePath(filename); frame.updateUI(); // editor.setModified(false); // editor.setCurrentFile(new File(filename)); if (changed) { Map<String, Object> fileTableMap = CellConfigure.getTablesInDirectory(workspace); treePanel.clear(); treePanel.addWorkSpace(); editor.setFileTableMap(fileTableMap); } /* //chen mxe // File tempfile= new File(filename); name= tempfile.getName().substring(0, tempfile.getName().indexOf(".")); DynamicTree treePanel = editor.getTreePanel(); SenseNode node= new SenseNode(name,filename); treePanel.addObject(node); //chen */ } else { Color bg = null; if ((!ext.equalsIgnoreCase("gif") && !ext.equalsIgnoreCase("png")) || JOptionPane.showConfirmDialog(graphComponent, mxResources.get("transparentBackground")) != JOptionPane.YES_OPTION) { bg = graphComponent.getBackground(); } BufferedImage image = mxCellRenderer.createBufferedImage(graph, null, 1, bg, graphComponent.isAntiAlias(), null, graphComponent.getCanvas()); if (image != null) { ImageIO.write(image, ext, new File(filename)); } else { JOptionPane.showMessageDialog(graphComponent, mxResources.get("noImageData")); } } } catch (Throwable ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(graphComponent, ex.toString(), mxResources.get("error"), JOptionPane.ERROR_MESSAGE); } //filenamelogMap logMap.put(filename, editor.getNowTime()); } } private void getCharInfo(mxGraphComponent graphComponent) { mxGraph graph = graphComponent.getGraph(); Object[] cells = graph.getChildCells(graph.getDefaultParent()); for (int i = 0; i < cells.length; i++) { mxCell cell = (mxCell) cells[i]; Map<String, Object> map = cell.getChartInfoMap(); ChartPanel chartPanel = cell.getChartPanel(); if (chartPanel != null) { JFreeChart chart = chartPanel.getChart(); if (cell.getStyle() != null && cell.getStyle().equals("barchart")) { CategoryPlot plot = (CategoryPlot) chart.getPlot(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); CategoryAxis domainAxis = plot.getDomainAxis(); // String title = chart.getTitle().getText(); String titleFont = chart.getTitle().getFont().getFontName(); int titleFontSize = chart.getTitle().getFont().getSize(); int titleFontStyle = chart.getTitle().getFont().getStyle(); int titleColor = ((Color) chart.getTitle().getPaint()).getRGB(); int chatBgroundColor = ((Color) chart.getBackgroundPaint()).getRGB(); /* String chartItemFont = chart.getLegend().getItemFont().getName(); int chartItemFontSize = chart.getLegend().getItemFont().getSize(); int chartItemFontStyle = chart.getLegend().getItemFont().getStyle(); int chartItemColor = ((Color)chart.getLegend().getItemPaint()).getRGB(); */ // String domainAxisLabel = domainAxis.getLabel(); String domainFont = domainAxis.getLabelFont().getName(); int domainFontSize = domainAxis.getLabelFont().getSize(); int domainFontStyle = domainAxis.getLabelFont().getStyle(); int domainColor = ((Color) domainAxis.getLabelPaint()).getRGB(); String domainTickLabelFont = domainAxis.getTickLabelFont().getName(); int domainTickLabelFontSize = domainAxis.getTickLabelFont().getSize(); int domainTickLabelFontStyle = domainAxis.getTickLabelFont().getStyle(); // String rangeAxisLabel = rangeAxis.getLabel(); String rangeFont = rangeAxis.getLabelFont().getName(); int rangeFontSize = rangeAxis.getLabelFont().getSize(); int rangeFontStyle = rangeAxis.getLabelFont().getStyle(); int rangeColor = ((Color) rangeAxis.getLabelPaint()).getRGB(); String rangeTickLabelFont = rangeAxis.getTickLabelFont().getName(); int rangeTickLabelFontSize = rangeAxis.getTickLabelFont().getSize(); int rangeTickLabelFontStyle = rangeAxis.getTickLabelFont().getStyle(); // int plotBgroundColor = ((Color) plot.getBackgroundPaint()).getRGB(); int plotOutlineColor = ((Color) plot.getOutlinePaint()).getRGB(); float plotOutlineWith = ((BasicStroke) plot.getOutlineStroke()).getLineWidth(); String plotOrientation = ((PlotOrientation) plot.getOrientation()).toString(); //== PlotOrientation.VERTICAL // plot.setOrientation(PlotOrientation.HORIZONTAL); //System.out.println(plotOutlineWith); // map.put("title", title); map.put("titleFont", titleFont); map.put("titleFontSize", titleFontSize); map.put("titleFontStyle", titleFontStyle); map.put("titleColor", titleColor); map.put("chatBgroundColor", chatBgroundColor); // map.put("domainAxisLabel", domainAxisLabel); map.put("domainFont", domainFont); map.put("domainFontSize", domainFontSize); map.put("domainFontStyle", domainFontStyle); map.put("domainColor", domainColor); map.put("domainTickLabelFont", domainTickLabelFont); map.put("domainTickLabelFontSize", domainTickLabelFontSize); map.put("domainTickLabelFontStyle", domainTickLabelFontStyle); // map.put("rangeAxisLabel", rangeAxisLabel); map.put("rangeFontSize", rangeFontSize); map.put("rangeFont", rangeFont); map.put("rangeFontStyle", rangeFontStyle); map.put("rangeColor", rangeColor); map.put("rangeTickLabelFont", rangeTickLabelFont); map.put("rangeTickLabelFontSize", rangeTickLabelFontSize); map.put("rangeTickLabelFontStyle", rangeTickLabelFontStyle); // map.put("plotBgroundColor", plotBgroundColor); map.put("plotOutlineColor", plotOutlineColor); map.put("plotOutlineWith", plotOutlineWith); map.put("plotOrientation", plotOrientation); } else if (cell.getStyle() != null && cell.getStyle().equals("piechart")) { PiePlot piePlot = (PiePlot) chart.getPlot();// // String title = chart.getTitle().getText(); String titleFont = chart.getTitle().getFont().getFontName(); int titleFontSize = chart.getTitle().getFont().getSize(); int titleFontStyle = chart.getTitle().getFont().getStyle(); int titleColor = ((Color) chart.getTitle().getPaint()).getRGB(); int chatBgroundColor = ((Color) chart.getBackgroundPaint()).getRGB(); // int plotBgroundColor = ((Color) piePlot.getBackgroundPaint()).getRGB(); int plotOutlineColor = ((Color) piePlot.getOutlinePaint()).getRGB(); float plotOutlineWith = ((BasicStroke) piePlot.getOutlineStroke()).getLineWidth(); // map.put("title", title); map.put("titleFont", titleFont); map.put("titleFontSize", titleFontSize); map.put("titleFontStyle", titleFontStyle); map.put("titleColor", titleColor); map.put("chatBgroundColor", chatBgroundColor); // map.put("plotBgroundColor", plotBgroundColor); map.put("plotOutlineColor", plotOutlineColor); map.put("plotOutlineWith", plotOutlineWith); } else if (cell.getStyle() != null && (cell.getStyle().equals("linechart") || cell.getStyle().equals("historylinechart"))) { XYPlot plot = (XYPlot) chart.getPlot(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); DateAxis domainAxis = (DateAxis) plot.getDomainAxis(); // String title = chart.getTitle().getText(); String titleFont = chart.getTitle().getFont().getFontName(); int titleFontSize = chart.getTitle().getFont().getSize(); int titleFontStyle = chart.getTitle().getFont().getStyle(); int titleColor = ((Color) chart.getTitle().getPaint()).getRGB(); int chatBgroundColor = ((Color) chart.getBackgroundPaint()).getRGB(); /* String chartItemFont = chart.getLegend().getItemFont().getName(); int chartItemFontSize = chart.getLegend().getItemFont().getSize(); int chartItemFontStyle = chart.getLegend().getItemFont().getStyle(); int chartItemColor = ((Color)chart.getLegend().getItemPaint()).getRGB(); */ // String domainAxisLabel = domainAxis.getLabel(); String domainFont = domainAxis.getLabelFont().getName(); int domainFontSize = domainAxis.getLabelFont().getSize(); int domainFontStyle = domainAxis.getLabelFont().getStyle(); int domainColor = ((Color) domainAxis.getLabelPaint()).getRGB(); String domainTickLabelFont = domainAxis.getTickLabelFont().getName(); int domainTickLabelFontSize = domainAxis.getTickLabelFont().getSize(); int domainTickLabelFontStyle = domainAxis.getTickLabelFont().getStyle(); // String rangeAxisLabel = rangeAxis.getLabel(); String rangeFont = rangeAxis.getLabelFont().getName(); int rangeFontSize = rangeAxis.getLabelFont().getSize(); int rangeFontStyle = rangeAxis.getLabelFont().getStyle(); int rangeColor = ((Color) rangeAxis.getLabelPaint()).getRGB(); String rangeTickLabelFont = rangeAxis.getTickLabelFont().getName(); int rangeTickLabelFontSize = rangeAxis.getTickLabelFont().getSize(); int rangeTickLabelFontStyle = rangeAxis.getTickLabelFont().getStyle(); // int plotBgroundColor = ((Color) plot.getBackgroundPaint()).getRGB(); int plotOutlineColor = ((Color) plot.getOutlinePaint()).getRGB(); float plotOutlineWith = ((BasicStroke) plot.getOutlineStroke()).getLineWidth(); String plotOrientation = ((PlotOrientation) plot.getOrientation()).toString(); //== PlotOrientation.VERTICAL // plot.setOrientation(PlotOrientation.HORIZONTAL); //System.out.println(plotOutlineWith); // map.put("title", title); map.put("titleFont", titleFont); map.put("titleFontSize", titleFontSize); map.put("titleFontStyle", titleFontStyle); map.put("titleColor", titleColor); map.put("chatBgroundColor", chatBgroundColor); // map.put("domainAxisLabel", domainAxisLabel); map.put("domainFont", domainFont); map.put("domainFontSize", domainFontSize); map.put("domainFontStyle", domainFontStyle); map.put("domainColor", domainColor); map.put("domainTickLabelFont", domainTickLabelFont); map.put("domainTickLabelFontSize", domainTickLabelFontSize); map.put("domainTickLabelFontStyle", domainTickLabelFontStyle); // map.put("rangeAxisLabel", rangeAxisLabel); map.put("rangeFontSize", rangeFontSize); map.put("rangeFont", rangeFont); map.put("rangeFontStyle", rangeFontStyle); map.put("rangeColor", rangeColor); map.put("rangeTickLabelFont", rangeTickLabelFont); map.put("rangeTickLabelFontSize", rangeTickLabelFontSize); map.put("rangeTickLabelFontStyle", rangeTickLabelFontStyle); // map.put("plotBgroundColor", plotBgroundColor); map.put("plotOutlineColor", plotOutlineColor); map.put("plotOutlineWith", plotOutlineWith); map.put("plotOrientation", plotOrientation); } } } } } public static final class RectAction extends AbstractAction { /** * */ private static final long serialVersionUID = 4883751070907867404L; @Override public void actionPerformed(ActionEvent e) { } } /** * * @param e * @return Returns the graph for the given action event. */ public static final BasicGraphEditor getEditor(ActionEvent e) { if (e.getSource() instanceof Component) { Component component = (Component) e.getSource(); while (component != null && !(component instanceof BasicGraphEditor)) { component = component.getParent(); if (component instanceof MyInternalFrame) { return ((MyInternalFrame) component).getEditor(); //break; } } return (BasicGraphEditor) component; } return null; } /** * */ @SuppressWarnings("serial") public static class ToggleRulersItem extends JCheckBoxMenuItem { /** * */ private BasicGraphEditor editor; public ToggleRulersItem(final BasicGraphEditor editor, String name) { super(name); this.editor = editor; setSelected(editor.isRulersEnable()); setAllFrames(editor.isRulersEnable()); addActionListener(new ActionListener() { /** * */ public void actionPerformed(ActionEvent e) { boolean isEnable = isSelected(); setAllFrames(isEnable); editor.setRulersEnable(isEnable); } }); } protected void setAllFrames(boolean isEnable) { JInternalFrame[] frames = editor.getDesktop().getAllFrames(); for (int i = 0; i < frames.length; i++) { MyInternalFrame f = (MyInternalFrame) frames[i]; mxGraphComponent graphComponent = f.getGraphComponent(); if (!isEnable) { graphComponent.setColumnHeader(null); graphComponent.setRowHeader(null); } else { graphComponent.setColumnHeaderView( new EditorRuler(graphComponent, EditorRuler.ORIENTATION_HORIZONTAL)); graphComponent .setRowHeaderView(new EditorRuler(graphComponent, EditorRuler.ORIENTATION_VERTICAL)); } } } } /** * */ @SuppressWarnings("serial") public static class ToggleGridItem extends JCheckBoxMenuItem { /** * */ private BasicGraphEditor editor; public ToggleGridItem(final BasicGraphEditor editor, String name) { super(name); this.editor = editor; setSelected(editor.isGridEnable()); setAllFrames(editor.isGridEnable()); addActionListener(new ActionListener() { /** * */ public void actionPerformed(ActionEvent e) { boolean isEnable = isSelected(); setAllFrames(isEnable); editor.setGridEnable(isEnable); } }); } protected void setAllFrames(boolean isEnable) { JInternalFrame[] frames = editor.getDesktop().getAllFrames(); for (int i = 0; i < frames.length; i++) { MyInternalFrame f = (MyInternalFrame) frames[i]; mxGraphComponent graphComponent = f.getGraphComponent(); mxGraph graph = graphComponent.getGraph(); graph.setGridEnabled(isEnable); graphComponent.setGridVisible(isEnable); graphComponent.repaint(); setSelected(isEnable); } } } /** * */ @SuppressWarnings("serial") public static class ToggleOutlineItem extends JCheckBoxMenuItem { /** * */ public ToggleOutlineItem(final BasicGraphEditor editor, String name) { super(name); setSelected(true); addActionListener(new ActionListener() { /** * */ public void actionPerformed(ActionEvent e) { final mxGraphOutline outline = editor.getGraphOutline(); outline.setVisible(!outline.isVisible()); outline.revalidate(); SwingUtilities.invokeLater(new Runnable() { /* * (non-Javadoc) * @see java.lang.Runnable#run() */ public void run() { if (outline.getParent() instanceof JSplitPane) { if (outline.isVisible()) { ((JSplitPane) outline.getParent()).setDividerLocation(editor.getHeight() - 300); ((JSplitPane) outline.getParent()).setDividerSize(6); } else { ((JSplitPane) outline.getParent()).setDividerSize(0); } } } }); } }); } } public static class ToggleIsHiddenItem extends JCheckBoxMenuItem { /** * */ private BasicGraphEditor editor; public ToggleIsHiddenItem(final BasicGraphEditor editor, String name) { super(name); this.editor = editor; MyInternalFrame frame = (MyInternalFrame) editor.getDesktop().getSelectedFrame(); if (frame != null) { mxGraphComponent graphComponent = frame.getGraphComponent(); mxGraphModel model = (mxGraphModel) graphComponent.getGraph().getModel(); //System.out.println(model.isSelfAdaptive()); Object[] cells = graphComponent.getGraph().getSelectionCells(); boolean result = false; if (cells != null && cells.length > 0) { model.beginUpdate(); try { if (!((mxCell) cells[0]).isHidden()) { setSelected(result); } else { result = true; for (int i = 1; i < cells.length; i++) { mxCell cell = (mxCell) cells[i]; if (!cell.isHidden()) { result = false; setSelected(result); break; } else { result = true; } } setSelected(result); } } finally { model.endUpdate(); } } //setSelectedFrame(model.isSelfAdaptive()); } addActionListener(new ActionListener() { /** * */ public void actionPerformed(ActionEvent e) { boolean isEnable = isSelected(); setSelected(isEnable); setSelectedFrame(isEnable); } }); } protected void setSelectedFrame(boolean isEnable) { MyInternalFrame frame = (MyInternalFrame) editor.getDesktop().getSelectedFrame(); mxGraphComponent graphComponent = frame.getGraphComponent(); mxGraphModel model = (mxGraphModel) graphComponent.getGraph().getModel(); mxGraph graph = graphComponent.getGraph(); Object[] cells = graph.getSelectionCells(); model.beginUpdate(); try { for (int j = 0; j < cells.length; j++) { ((mxCell) cells[j]).setHidden(isEnable); } } finally { model.endUpdate(); } } } public static class ToggleSelfAdaptiveItem extends JCheckBoxMenuItem { /** * */ private BasicGraphEditor editor; public ToggleSelfAdaptiveItem(final BasicGraphEditor editor, String name) { super(name); this.editor = editor; MyInternalFrame frame = (MyInternalFrame) editor.getDesktop().getSelectedFrame(); if (frame != null) { mxGraphComponent graphComponent = frame.getGraphComponent(); mxGraphModel model = (mxGraphModel) graphComponent.getGraph().getModel(); //System.out.println(model.isSelfAdaptive()); setSelected(model.isSelfAdaptive()); //setSelectedFrame(model.isSelfAdaptive()); } addActionListener(new ActionListener() { /** * */ public void actionPerformed(ActionEvent e) { boolean isEnable = isSelected(); //setSelected(isEnable); setSelectedFrame(isEnable); } }); } protected void setSelectedFrame(boolean isEnable) { MyInternalFrame frame = (MyInternalFrame) editor.getDesktop().getSelectedFrame(); mxGraphComponent graphComponent = frame.getGraphComponent(); mxGraphModel model = (mxGraphModel) graphComponent.getGraph().getModel(); model.setSelfAdaptive(isEnable); model.execute(new mxSelfAdaptiveChange(model, isEnable)); /*for(int i = 0; i<frames.length; i++) { MyInternalFrame f = (MyInternalFrame) frames[i]; mxGraphComponent graphComponent = f.getGraphComponent(); mxGraph graph = graphComponent.getGraph(); graph.setGridEnabled(isEnable); graphComponent.setGridVisible(isEnable); graphComponent.repaint(); setSelected(isEnable); }*/ } } /** * */ @SuppressWarnings("serial") public static class ExitAction extends AbstractAction { /** * */ public void actionPerformed(ActionEvent e) { BasicGraphEditor editor = getEditor(e); if (editor != null) { editor.exit(); } } } /** * */ @SuppressWarnings("serial") public static class StylesheetAction extends AbstractAction { /** * */ protected String stylesheet; /** * */ public StylesheetAction(String stylesheet) { this.stylesheet = stylesheet; } /** * */ public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof mxGraphComponent) { mxGraphComponent graphComponent = (mxGraphComponent) e.getSource(); mxGraph graph = graphComponent.getGraph(); mxCodec codec = new mxCodec(); Document doc = mxUtils.loadDocument(EditorActions.class.getResource(stylesheet).toString()); if (doc != null) { codec.decode(doc.getDocumentElement(), graph.getStylesheet()); graph.refresh(); } } } } /** * */ @SuppressWarnings("serial") public static class ZoomPolicyAction extends AbstractAction { /** * */ protected int zoomPolicy; /** * */ public ZoomPolicyAction(int zoomPolicy) { this.zoomPolicy = zoomPolicy; } /** * */ public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof mxGraphComponent) { mxGraphComponent graphComponent = (mxGraphComponent) e.getSource(); graphComponent.setPageVisible(true); graphComponent.setZoomPolicy(zoomPolicy); } } } /** * */ @SuppressWarnings("serial") public static class GridStyleAction extends AbstractAction { /** * */ protected int style; /** * */ public GridStyleAction(int style) { this.style = style; } /** * */ public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof mxGraphComponent) { mxGraphComponent graphComponent = (mxGraphComponent) e.getSource(); graphComponent.setGridStyle(style); graphComponent.repaint(); } } } /** * */ @SuppressWarnings("serial") public static class GridColorAction extends AbstractAction { /** * */ public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof mxGraphComponent) { mxGraphComponent graphComponent = (mxGraphComponent) e.getSource(); Color newColor = JColorChooser.showDialog(graphComponent, mxResources.get("gridColor"), graphComponent.getGridColor()); if (newColor != null) { graphComponent.setGridColor(newColor); graphComponent.repaint(); } } } } /** * */ @SuppressWarnings("serial") public static class ScaleAction extends AbstractAction { /** * */ protected double scale; /** * */ public ScaleAction(double scale) { this.scale = scale; } /** * */ public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof mxGraphComponent) { mxGraphComponent graphComponent = (mxGraphComponent) e.getSource(); double scale = this.scale; if (scale == 0) { String value = (String) JOptionPane.showInputDialog(graphComponent, mxResources.get("value"), mxResources.get("scale") + " (%)", JOptionPane.PLAIN_MESSAGE, null, null, ""); if (value != null) { scale = Double.parseDouble(value.replace("%", "")) / 100; } } if (scale > 0) { graphComponent.zoomTo(scale, graphComponent.isCenterZoom()); } } } } /** * */ @SuppressWarnings("serial") public static class PageSetupAction extends AbstractAction { /** * */ public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof mxGraphComponent) { mxGraphComponent graphComponent = (mxGraphComponent) e.getSource(); PrinterJob pj = PrinterJob.getPrinterJob(); /* PageFormat format = pj.pageDialog(graphComponent .getPageFormat());*/ PageFormat format = pj.pageDialog(graphComponent.getPageFormat()); if (format != null) { graphComponent.setPageFormat(format); graphComponent.getGraph().getModel() .setPageFormatStyle(new Integer(format.getOrientation()).toString()); graphComponent.zoomAndCenter(); } } } } /** * */ @SuppressWarnings("serial") public static class PrintAction extends AbstractAction { /** * */ public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof mxGraphComponent) { mxGraphComponent graphComponent = (mxGraphComponent) e.getSource(); PrinterJob pj = PrinterJob.getPrinterJob(); if (pj.printDialog()) { PageFormat pf = graphComponent.getPageFormat(); Paper paper = new Paper(); //xd add double oldwidth = paper.getWidth(); double oldheight = paper.getHeight(); paper.setSize(graphComponent.getPageBounds().getWidth(), graphComponent.getPageBounds().getHeight()); //xd add double margin = 36; paper.setImageableArea(margin, margin, paper.getWidth() - margin * 2, paper.getHeight() - margin * 2); pf.setPaper(paper); pj.setPrintable(graphComponent, pf); try { pj.print(); } catch (PrinterException e2) { System.out.println(e2); } finally { //xd add, paper.setSize(oldwidth, oldheight); pf.setPaper(paper); } } } } } public static class CellSaveAction extends AbstractAction implements Action { /** * */ protected boolean showDialog; /** * */ protected String lastDir = null; /** * */ mxGraphComponent graphComponent; public CellSaveAction(boolean showDialog) { this.showDialog = showDialog; } @Override public void actionPerformed(ActionEvent e) { BasicGraphEditor editor = getEditor(e); if (editor != null) { graphComponent = editor.getGraphComponent(); mxGraph graph = graphComponent.getGraph(); mxGraphView gView = graph.getView(); mxGraphModel gModel = (mxGraphModel) graph.getModel(); Map<String, Object> cellObjects = gModel.getCells(); Map<String, Object> temp = new Hashtable<String, Object>(); cellObjects.remove("0"); cellObjects.remove("1"); ArrayList<Entry<String, Object>> list = new ArrayList<Map.Entry<String, Object>>( cellObjects.entrySet()); Collections.sort(list, new KeyComparator());//key Iterator<Object> cells = cellObjects.values().iterator(); double minX = 0; double minY = 0; double maxW = 0; double maxH = 0; double maxWX = 0; double maxHY = 0; while (cells.hasNext()) { mxCell cell = (mxCell) cells.next(); mxCellState cellState = gView.getState(cell); double x = cellState.getX(); if (minX == 0) { minX = x; } else if (x < minX) { minX = x; } double y = cellState.getY(); if (minY == 0) { minY = y; } else if (y < minY) { minY = y; } double hy = cellState.getHeight() + y; if (maxHY == 0) { maxHY = hy; } else if (hy > maxHY) { maxHY = hy; } double wx = cellState.getWidth() + x; if (maxWX == 0) { maxWX = wx; } else if (wx > maxWX) { maxWX = wx; } } maxW = maxWX - minX; maxH = maxHY - minY; cells = cellObjects.values().iterator(); int cid = 9; while (cells.hasNext()) { mxCell cell = (mxCell) cells.next(); mxCellState cellState = gView.getState(cell); mxCellState st = gView.getState(cell); double x1 = (st.getX() - minX) / maxW; double y1 = (st.getY() - minY) / maxH; double h1 = st.getHeight() / maxH; double w1 = st.getWidth() / maxW; Map<String, Object> style = st.getStyle(); style.remove(""); style.put("x", x1); style.put("y", y1); style.put("height", h1); style.put("width", w1); //connect connectptID if (cell.getStyle() != null && cell.getStyle().equals("connect")) { style.put("connectptID", cid); cid++; } if (cell.getValue() != null) { style.put("textvalue", cell.getValue()); } if (cell.getStyle() != null && cell.getStyle().equals("straightwithoutarrow")) { style.put("p0x", (cellState.getAbsolutePoint(0).getX() - minX) / maxW); style.put("p0y", (cellState.getAbsolutePoint(0).getY() - minY) / maxH); style.put("p1x", (cellState.getAbsolutePoint(1).getX() - minX) / maxW); style.put("p1y", (cellState.getAbsolutePoint(1).getY() - minY) / maxH); } /* if(cell.getStyle() != null){ temp.put(cell.getStyle(), style); } else */ int key = 100 - (new Integer(cell.getId()).intValue()); Hashtable ts = (Hashtable) ((Hashtable) style).clone(); temp.put((new Integer(key)).toString(), ts); } /* * * */ if (editor.getCurrentFile() == null) { SaveDialog.createAndShowGUI(temp, graphComponent); } else { SaveDialog sd = new SaveDialog(temp, graphComponent); String filename = editor.getCurrentFile().getName(); String name = filename.substring(0, filename.indexOf(".")); // String type = null; // String num = null; mxCodec codecSheet = new mxCodec(); mxStylesheet sheet = new mxStylesheet(); Document docSheet = mxUtils .loadDocument(mxConstants.USERDIR + "/savefile/resources/basic-style.xml"); codecSheet.decode(docSheet.getDocumentElement(), sheet); Map<String, Map<String, Object>> styles = sheet.getStyles(); String num = styles.get(name).get("num").toString(); String type = styles.get(name).get("style").toString(); sd.xmlSave(temp, name, type, num); Object eObject = e.getSource(); //eObject is equal to graphComponent CellEditor.CustomGraphComponent ee = (CellEditor.CustomGraphComponent) eObject; ee.getFrame().dispose(); } /* }else if(flags.isEmpty()){ JOptionPane.showMessageDialog(null, "container"); } else if(flags.size()>1) { JOptionPane.showMessageDialog(null, "container"); } */ } } } /** * */ @SuppressWarnings("serial") public static class SaveAction extends AbstractAction { /** * */ protected boolean showDialog; /** * */ protected String lastDir = null; /** * */ public SaveAction(boolean showDialog) { this.showDialog = showDialog; } /** * */ public void actionPerformed(ActionEvent e) { BasicGraphEditor editor = getEditor(e); MyInternalFrame frame = (MyInternalFrame) editor.getDesktop().getSelectedFrame(); if (frame == null) return; if (frame.getTitle().startsWith("")) { showDialog = true; } else showDialog = false; mxGraphComponent graphComponent = frame.getGraphComponent(); getCharInfo(graphComponent); mxGraph graph = graphComponent.getGraph(); FileFilter selectedFilter = null; FileFilter vmlFileFilter = new DefaultFileFilter(".html", "VML " + mxResources.get("file") + " (.html)"); String filename = null; String title = null; if (showDialog /*|| editor.getCurrentFile() == null*/) { String wd; if (lastDir != null) { wd = lastDir; } else if (editor.getCurrentFile() != null) { wd = editor.getCurrentFile().getParent(); } else { wd = System.getProperty("user.dir"); } JFileChooser fc = new JFileChooser(wd); // Adds the default file format FileFilter defaultFilter = new DefaultFileFilter(".mxe", "mxGraph Editor " + mxResources.get("file") + " (.mxe)"); fc.addChoosableFileFilter(defaultFilter); // Adds special vector graphics formats and HTML fc.addChoosableFileFilter( new DefaultFileFilter(".svg", "SVG " + mxResources.get("file") + " (.svg)")); fc.addChoosableFileFilter(vmlFileFilter); fc.addChoosableFileFilter( new DefaultFileFilter(".html", "HTML " + mxResources.get("file") + " (.html)")); // Adds a filter for each supported image format Object[] imageFormats = ImageIO.getReaderFormatNames(); // Finds all distinct extensions HashSet<String> formats = new HashSet<String>(); for (int i = 0; i < imageFormats.length; i++) { String ext = imageFormats[i].toString().toLowerCase(); formats.add(ext); } imageFormats = formats.toArray(); for (int i = 0; i < imageFormats.length; i++) { String ext = imageFormats[i].toString(); fc.addChoosableFileFilter(new DefaultFileFilter("." + ext, ext.toUpperCase() + " " + mxResources.get("file") + " (." + ext + ")")); } // Adds filter that accepts all supported image formats fc.addChoosableFileFilter(new DefaultFileFilter.ImageFileFilter(mxResources.get("allImages"))); fc.setFileFilter(defaultFilter); int rc = fc.showDialog(null, mxResources.get("save")); if (rc != JFileChooser.APPROVE_OPTION) { return; } else { lastDir = fc.getSelectedFile().getParent(); } filename = fc.getSelectedFile().getAbsolutePath(); selectedFilter = fc.getFileFilter(); if (selectedFilter instanceof DefaultFileFilter) { String ext = ((DefaultFileFilter) selectedFilter).getExtension(); if (!filename.toLowerCase().endsWith(ext)) { filename += ext; } } if (new File(filename).exists() && JOptionPane.showConfirmDialog(graphComponent, mxResources.get("overwriteExistingFile")) != JOptionPane.YES_OPTION) { return; } // , if (!frame.getTitle().startsWith("")) { boolean isExist = false; JInternalFrame[] frames = editor.getDesktop().getAllFrames(); for (int i = 0; i < frames.length; i++) { MyInternalFrame f = (MyInternalFrame) frames[i]; if (filename.endsWith(f.getAbsolutePath())) { isExist = true; try { f.setSelected(true); if (!f.isMaximum()) { f.setMaximum(true); f.show(); } } catch (PropertyVetoException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } JOptionPane.showMessageDialog(f, filename + ""); return; } } } title = filename.substring(filename.lastIndexOf("\\") + 1); } else { filename = ((MyInternalFrame) editor.getDesktop().getSelectedFrame()).getAbsolutePath(); title = editor.getDesktop().getSelectedFrame().getTitle(); if (title.endsWith("*")) { title = title.substring(0, title.length() - 1); } } try { String ext = filename.substring(filename.lastIndexOf('.') + 1); if (ext.equalsIgnoreCase("svg")) { Document doc = mxCellRenderer.createSvgDocument(graph, null, 1, null, null); mxUtils.writeFile(mxUtils.getXml(doc.getDocumentElement()), filename); } else if (selectedFilter == vmlFileFilter) { Document doc = mxCellRenderer.createVmlDocument(graph, null, 1, null, null); mxUtils.writeFile(mxUtils.getXml(doc.getDocumentElement()), filename); } else if (ext.equalsIgnoreCase("html")) { mxUtils.writeFile(mxUtils.getXml( mxCellRenderer.createHtmlDocument(graph, null, 1, null, null).getDocumentElement()), filename); } else if (ext.equalsIgnoreCase("mxe") || ext.equalsIgnoreCase("xml")) { //8.13 boolean changed = false; DynamicTree treePanel = editor.getTreePanel(); if (treePanel != null) { String workspace = treePanel.getWorkspace(); if (filename.length() >= workspace.length() && filename.substring(0, workspace.length()).equals(workspace) && !(new File(filename)).exists()) { changed = true; Map<String, Object> fileTableMap = CellConfigure.getTablesInDirectory(workspace); treePanel.clear(); treePanel.addWorkSpace(); editor.setFileTableMap(fileTableMap); } } // mxCodec codec = new mxCodec(); String xml = mxUtils.getXml(codec.encode(graph.getModel())); mxUtils.writeFile(xml, filename); frame.setModified(false); frame.setTitle(title); frame.setAbsolutePath(filename); frame.updateUI(); // editor.setModified(false); // editor.setCurrentFile(new File(filename)); } else { Color bg = null; if ((!ext.equalsIgnoreCase("gif") && !ext.equalsIgnoreCase("png")) || JOptionPane.showConfirmDialog(graphComponent, mxResources.get("transparentBackground")) != JOptionPane.YES_OPTION) { bg = graphComponent.getBackground(); } BufferedImage image = mxCellRenderer.createBufferedImage(graph, null, 1, bg, graphComponent.isAntiAlias(), null, graphComponent.getCanvas()); if (image != null) { ImageIO.write(image, ext, new File(filename)); } else { JOptionPane.showMessageDialog(graphComponent, mxResources.get("noImageData")); } } } catch (Throwable ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(graphComponent, ex.toString(), mxResources.get("error"), JOptionPane.ERROR_MESSAGE); } //filenamelogMap Map<String, String> logMap = editor.getLogMap(); logMap.put(filename, editor.getNowTime()); } private void getCharInfo(mxGraphComponent graphComponent) { mxGraph graph = graphComponent.getGraph(); Object[] cells = graph.getChildCells(graph.getDefaultParent()); for (int i = 0; i < cells.length; i++) { mxCell cell = (mxCell) cells[i]; Map<String, Object> map = cell.getChartInfoMap(); ChartPanel chartPanel = cell.getChartPanel(); if (chartPanel != null) { JFreeChart chart = chartPanel.getChart(); if (cell.getStyle() != null && cell.getStyle().equals("barchart")) { CategoryPlot plot = (CategoryPlot) chart.getPlot(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); CategoryAxis domainAxis = plot.getDomainAxis(); // String title = chart.getTitle().getText(); String titleFont = chart.getTitle().getFont().getFontName(); int titleFontSize = chart.getTitle().getFont().getSize(); int titleFontStyle = chart.getTitle().getFont().getStyle(); int titleColor = ((Color) chart.getTitle().getPaint()).getRGB(); int chatBgroundColor = ((Color) chart.getBackgroundPaint()).getRGB(); /* String chartItemFont = chart.getLegend().getItemFont().getName(); int chartItemFontSize = chart.getLegend().getItemFont().getSize(); int chartItemFontStyle = chart.getLegend().getItemFont().getStyle(); int chartItemColor = ((Color)chart.getLegend().getItemPaint()).getRGB(); */ // String domainAxisLabel = domainAxis.getLabel(); String domainFont = domainAxis.getLabelFont().getName(); int domainFontSize = domainAxis.getLabelFont().getSize(); int domainFontStyle = domainAxis.getLabelFont().getStyle(); int domainColor = ((Color) domainAxis.getLabelPaint()).getRGB(); String domainTickLabelFont = domainAxis.getTickLabelFont().getName(); int domainTickLabelFontSize = domainAxis.getTickLabelFont().getSize(); int domainTickLabelFontStyle = domainAxis.getTickLabelFont().getStyle(); // String rangeAxisLabel = rangeAxis.getLabel(); String rangeFont = rangeAxis.getLabelFont().getName(); int rangeFontSize = rangeAxis.getLabelFont().getSize(); int rangeFontStyle = rangeAxis.getLabelFont().getStyle(); int rangeColor = ((Color) rangeAxis.getLabelPaint()).getRGB(); String rangeTickLabelFont = rangeAxis.getTickLabelFont().getName(); int rangeTickLabelFontSize = rangeAxis.getTickLabelFont().getSize(); int rangeTickLabelFontStyle = rangeAxis.getTickLabelFont().getStyle(); // int plotBgroundColor = ((Color) plot.getBackgroundPaint()).getRGB(); int plotOutlineColor = ((Color) plot.getOutlinePaint()).getRGB(); float plotOutlineWith = ((BasicStroke) plot.getOutlineStroke()).getLineWidth(); String plotOrientation = ((PlotOrientation) plot.getOrientation()).toString(); //== PlotOrientation.VERTICAL // plot.setOrientation(PlotOrientation.HORIZONTAL); //System.out.println(plotOutlineWith); // map.put("title", title); map.put("titleFont", titleFont); map.put("titleFontSize", titleFontSize); map.put("titleFontStyle", titleFontStyle); map.put("titleColor", titleColor); map.put("chatBgroundColor", chatBgroundColor); // map.put("domainAxisLabel", domainAxisLabel); map.put("domainFont", domainFont); map.put("domainFontSize", domainFontSize); map.put("domainFontStyle", domainFontStyle); map.put("domainColor", domainColor); map.put("domainTickLabelFont", domainTickLabelFont); map.put("domainTickLabelFontSize", domainTickLabelFontSize); map.put("domainTickLabelFontStyle", domainTickLabelFontStyle); // map.put("rangeAxisLabel", rangeAxisLabel); map.put("rangeFontSize", rangeFontSize); map.put("rangeFont", rangeFont); map.put("rangeFontStyle", rangeFontStyle); map.put("rangeColor", rangeColor); map.put("rangeTickLabelFont", rangeTickLabelFont); map.put("rangeTickLabelFontSize", rangeTickLabelFontSize); map.put("rangeTickLabelFontStyle", rangeTickLabelFontStyle); // map.put("plotBgroundColor", plotBgroundColor); map.put("plotOutlineColor", plotOutlineColor); map.put("plotOutlineWith", plotOutlineWith); map.put("plotOrientation", plotOrientation); } else if (cell.getStyle() != null && cell.getStyle().equals("piechart")) { PiePlot piePlot = (PiePlot) chart.getPlot();// // String title = chart.getTitle().getText(); String titleFont = chart.getTitle().getFont().getFontName(); int titleFontSize = chart.getTitle().getFont().getSize(); int titleFontStyle = chart.getTitle().getFont().getStyle(); int titleColor = ((Color) chart.getTitle().getPaint()).getRGB(); int chatBgroundColor = ((Color) chart.getBackgroundPaint()).getRGB(); // int plotBgroundColor = ((Color) piePlot.getBackgroundPaint()).getRGB(); int plotOutlineColor = ((Color) piePlot.getOutlinePaint()).getRGB(); float plotOutlineWith = ((BasicStroke) piePlot.getOutlineStroke()).getLineWidth(); // map.put("title", title); map.put("titleFont", titleFont); map.put("titleFontSize", titleFontSize); map.put("titleFontStyle", titleFontStyle); map.put("titleColor", titleColor); map.put("chatBgroundColor", chatBgroundColor); // map.put("plotBgroundColor", plotBgroundColor); map.put("plotOutlineColor", plotOutlineColor); map.put("plotOutlineWith", plotOutlineWith); } else if (cell.getStyle() != null && (cell.getStyle().equals("linechart") || cell.getStyle().equals("historylinechart"))) { XYPlot plot = (XYPlot) chart.getPlot(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); DateAxis domainAxis = (DateAxis) plot.getDomainAxis(); // String title = chart.getTitle().getText(); String titleFont = chart.getTitle().getFont().getFontName(); int titleFontSize = chart.getTitle().getFont().getSize(); int titleFontStyle = chart.getTitle().getFont().getStyle(); int titleColor = ((Color) chart.getTitle().getPaint()).getRGB(); int chatBgroundColor = ((Color) chart.getBackgroundPaint()).getRGB(); /* String chartItemFont = chart.getLegend().getItemFont().getName(); int chartItemFontSize = chart.getLegend().getItemFont().getSize(); int chartItemFontStyle = chart.getLegend().getItemFont().getStyle(); int chartItemColor = ((Color)chart.getLegend().getItemPaint()).getRGB(); */ // String domainAxisLabel = domainAxis.getLabel(); String domainFont = domainAxis.getLabelFont().getName(); int domainFontSize = domainAxis.getLabelFont().getSize(); int domainFontStyle = domainAxis.getLabelFont().getStyle(); int domainColor = ((Color) domainAxis.getLabelPaint()).getRGB(); String domainTickLabelFont = domainAxis.getTickLabelFont().getName(); int domainTickLabelFontSize = domainAxis.getTickLabelFont().getSize(); int domainTickLabelFontStyle = domainAxis.getTickLabelFont().getStyle(); // String rangeAxisLabel = rangeAxis.getLabel(); String rangeFont = rangeAxis.getLabelFont().getName(); int rangeFontSize = rangeAxis.getLabelFont().getSize(); int rangeFontStyle = rangeAxis.getLabelFont().getStyle(); int rangeColor = ((Color) rangeAxis.getLabelPaint()).getRGB(); String rangeTickLabelFont = rangeAxis.getTickLabelFont().getName(); int rangeTickLabelFontSize = rangeAxis.getTickLabelFont().getSize(); int rangeTickLabelFontStyle = rangeAxis.getTickLabelFont().getStyle(); // int plotBgroundColor = ((Color) plot.getBackgroundPaint()).getRGB(); int plotOutlineColor = ((Color) plot.getOutlinePaint()).getRGB(); float plotOutlineWith = ((BasicStroke) plot.getOutlineStroke()).getLineWidth(); String plotOrientation = ((PlotOrientation) plot.getOrientation()).toString(); //== PlotOrientation.VERTICAL // plot.setOrientation(PlotOrientation.HORIZONTAL); //System.out.println(plotOutlineWith); // map.put("title", title); map.put("titleFont", titleFont); map.put("titleFontSize", titleFontSize); map.put("titleFontStyle", titleFontStyle); map.put("titleColor", titleColor); map.put("chatBgroundColor", chatBgroundColor); // map.put("domainAxisLabel", domainAxisLabel); map.put("domainFont", domainFont); map.put("domainFontSize", domainFontSize); map.put("domainFontStyle", domainFontStyle); map.put("domainColor", domainColor); map.put("domainTickLabelFont", domainTickLabelFont); map.put("domainTickLabelFontSize", domainTickLabelFontSize); map.put("domainTickLabelFontStyle", domainTickLabelFontStyle); // map.put("rangeAxisLabel", rangeAxisLabel); map.put("rangeFontSize", rangeFontSize); map.put("rangeFont", rangeFont); map.put("rangeFontStyle", rangeFontStyle); map.put("rangeColor", rangeColor); map.put("rangeTickLabelFont", rangeTickLabelFont); map.put("rangeTickLabelFontSize", rangeTickLabelFontSize); map.put("rangeTickLabelFontStyle", rangeTickLabelFontStyle); // map.put("plotBgroundColor", plotBgroundColor); map.put("plotOutlineColor", plotOutlineColor); map.put("plotOutlineWith", plotOutlineWith); map.put("plotOrientation", plotOrientation); } } } } } /** * */ @SuppressWarnings("serial") public static class SelectShortestPathAction extends AbstractAction { /** * */ protected boolean directed; /** * */ public SelectShortestPathAction(boolean directed) { this.directed = directed; } /** * */ public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof mxGraphComponent) { mxGraphComponent graphComponent = (mxGraphComponent) e.getSource(); mxGraph graph = graphComponent.getGraph(); mxIGraphModel model = graph.getModel(); Object source = null; Object target = null; Object[] cells = graph.getSelectionCells(); for (int i = 0; i < cells.length; i++) { if (model.isVertex(cells[i])) { if (source == null) { source = cells[i]; } else if (target == null) { target = cells[i]; } } if (source != null && target != null) { break; } } if (source != null && target != null) { int steps = graph.getChildEdges(graph.getDefaultParent()).length; Object[] path = mxGraphAnalysis.getInstance().getShortestPath(graph, source, target, new mxDistanceCostFunction(), steps, directed); graph.setSelectionCells(path); } else { JOptionPane.showMessageDialog(graphComponent, mxResources.get("noSourceAndTargetSelected")); } } } } /** * */ @SuppressWarnings("serial") public static class SelectSpanningTreeAction extends AbstractAction { /** * */ protected boolean directed; /** * */ public SelectSpanningTreeAction(boolean directed) { this.directed = directed; } /** * */ public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof mxGraphComponent) { mxGraphComponent graphComponent = (mxGraphComponent) e.getSource(); mxGraph graph = graphComponent.getGraph(); mxIGraphModel model = graph.getModel(); Object parent = graph.getDefaultParent(); Object[] cells = graph.getSelectionCells(); for (int i = 0; i < cells.length; i++) { if (model.getChildCount(cells[i]) > 0) { parent = cells[i]; break; } } Object[] v = graph.getChildVertices(parent); Object[] mst = mxGraphAnalysis.getInstance().getMinimumSpanningTree(graph, v, new mxDistanceCostFunction(), directed); graph.setSelectionCells(mst); } } } /** * */ @SuppressWarnings("serial") public static class ToggleDirtyAction extends AbstractAction { /** * */ public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof mxGraphComponent) { mxGraphComponent graphComponent = (mxGraphComponent) e.getSource(); graphComponent.showDirtyRectangle = !graphComponent.showDirtyRectangle; } } } /** * */ @SuppressWarnings("serial") public static class ToggleImagePreviewAction extends AbstractAction { /** * */ public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof mxGraphComponent) { mxGraphComponent graphComponent = (mxGraphComponent) e.getSource(); graphComponent.getGraphHandler() .setImagePreview(!graphComponent.getGraphHandler().isImagePreview()); } } } /** * */ @SuppressWarnings("serial") public static class ToggleConnectModeAction extends AbstractAction { /** * */ public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof mxGraphComponent) { mxGraphComponent graphComponent = (mxGraphComponent) e.getSource(); mxConnectionHandler handler = graphComponent.getConnectionHandler(); handler.setHandleEnabled(!handler.isHandleEnabled()); } } } /** * */ @SuppressWarnings("serial") public static class ToggleCreateTargetItem extends JCheckBoxMenuItem { /** * */ public ToggleCreateTargetItem(final BasicGraphEditor editor, String name) { super(name); setSelected(true); addActionListener(new ActionListener() { /** * */ public void actionPerformed(ActionEvent e) { mxGraphComponent graphComponent = editor.getGraphComponent(); if (graphComponent != null) { mxConnectionHandler handler = graphComponent.getConnectionHandler(); handler.setCreateTarget(!handler.isCreateTarget()); setSelected(handler.isCreateTarget()); } } }); } } /** * */ @SuppressWarnings("serial") public static class PromptPropertyAction extends AbstractAction { /** * */ protected Object target; /** * */ protected String fieldname, message; /** * */ public PromptPropertyAction(Object target, String message) { this(target, message, message); } /** * */ public PromptPropertyAction(Object target, String message, String fieldname) { this.target = target; this.message = message; this.fieldname = fieldname; } /** * */ public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof Component) { try { Method getter = target.getClass().getMethod("get" + fieldname); Object current = getter.invoke(target); if (current instanceof Integer) { Method setter = target.getClass().getMethod("set" + fieldname, new Class[] { int.class }); String value = (String) JOptionPane.showInputDialog((Component) e.getSource(), "Value", message, JOptionPane.PLAIN_MESSAGE, null, null, current); if (value != null) { setter.invoke(target, Integer.parseInt(value)); } } } catch (Exception ex) { ex.printStackTrace(); } } // Repaints the graph component if (e.getSource() instanceof mxGraphComponent) { mxGraphComponent graphComponent = (mxGraphComponent) e.getSource(); graphComponent.repaint(); } } } /** * */ @SuppressWarnings("serial") public static class TogglePropertyItem extends JCheckBoxMenuItem { /** * */ public TogglePropertyItem(Object target, String name, String fieldname) { this(target, name, fieldname, false); } /** * */ public TogglePropertyItem(Object target, String name, String fieldname, boolean refresh) { this(target, name, fieldname, refresh, null); } /** * */ public TogglePropertyItem(final Object target, String name, final String fieldname, final boolean refresh, ActionListener listener) { super(name); // Since action listeners are processed last to first we add the given // listener here which means it will be processed after the one below if (listener != null) { addActionListener(listener); } addActionListener(new ActionListener() { /** * */ public void actionPerformed(ActionEvent e) { execute(target, fieldname, refresh); } }); PropertyChangeListener propertyChangeListener = new PropertyChangeListener() { /* * (non-Javadoc) * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) */ public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equalsIgnoreCase(fieldname)) { update(target, fieldname); } } }; if (target instanceof mxGraphComponent) { ((mxGraphComponent) target).addPropertyChangeListener(propertyChangeListener); } else if (target instanceof mxGraph) { ((mxGraph) target).addPropertyChangeListener(propertyChangeListener); } else if (target instanceof BasicGraphEditor) { /* MyInternalFrame f = (MyInternalFrame) ((BasicGraphEditor) target).getDesktop().getSelectedFrame(); if(f==null) System.out.println("null"); else System.out.println("not null"); Object t = f==null?((BasicGraphEditor) target).getGraphComponent().getGraph():f.getGraphComponent().getGraph(); ((mxGraph) t) .addPropertyChangeListener(propertyChangeListener); update(t, fieldname); */ ((BasicGraphEditor) target).addPropertyChangeListener(propertyChangeListener); } update(target, fieldname); } /** * */ public void update(Object target, String fieldname) { //chen if (target instanceof BasicGraphEditor) { /* MyInternalFrame f = (MyInternalFrame) ((BasicGraphEditor) target).getDesktop().getSelectedFrame(); if(f==null) System.out.println("null---"); else System.out.println("not null---"); Object t = f==null?((BasicGraphEditor) target).getGraphComponent().getGraph():f.getGraphComponent().getGraph(); update(((mxGraph) t), fieldname); */ JInternalFrame[] frames = ((BasicGraphEditor) target).getDesktop().getAllFrames(); for (int i = 0; i < frames.length; i++) { MyInternalFrame f = (MyInternalFrame) frames[i]; mxGraph g = f.getGraphComponent().getGraph(); update(g, fieldname); } // update(((BasicGraphEditor) target).getGraphComponent().getGraph(),fieldname); } else { try { Method getter = target.getClass().getMethod("is" + fieldname); Object current = getter.invoke(target); if (current instanceof Boolean) { setSelected(((Boolean) current).booleanValue()); } } catch (Exception e) { e.printStackTrace(); } } } /** * */ public void execute(Object target, String fieldname, boolean refresh) { //chen if (target instanceof BasicGraphEditor) { JInternalFrame[] frames = ((BasicGraphEditor) target).getDesktop().getAllFrames(); for (int i = 0; i < frames.length; i++) { MyInternalFrame f = (MyInternalFrame) frames[i]; mxGraph g = f.getGraphComponent().getGraph(); execute(g, fieldname, refresh); } // execute(((BasicGraphEditor) target).getGraphComponent().getGraph(), fieldname,refresh); } else { try { Method getter = target.getClass().getMethod("is" + fieldname); Method setter = target.getClass().getMethod("set" + fieldname, new Class[] { boolean.class }); Object current = getter.invoke(target); if (current instanceof Boolean) { boolean value = !((Boolean) current).booleanValue(); setter.invoke(target, value); setSelected(value); } if (refresh) { mxGraph graph = null; if (target instanceof mxGraph) { graph = (mxGraph) target; } else if (target instanceof mxGraphComponent) { graph = ((mxGraphComponent) target).getGraph(); } graph.refresh(); } } catch (Exception e) { e.printStackTrace(); } } } // } /** * */ @SuppressWarnings("serial") public static class HistoryAction extends AbstractAction { /** * */ protected boolean undo; /** * */ public HistoryAction(boolean undo) { this.undo = undo; } /** * */ public void actionPerformed(ActionEvent e) { BasicGraphEditor editor = getEditor(e); if (editor != null) { if (undo) { //editor.getUndoManager().undo(); ((MyInternalFrame) editor.getDesktop().getSelectedFrame()).getUndoManager().undo(); Task root = (Task) ((TaskTree) editor.getLevelPanel()).getRootNode().getTask(); ((TaskTree) editor.getLevelPanel()).updateTreeByChildren(root); } else { // editor.getUndoManager().redo(); ((MyInternalFrame) editor.getDesktop().getSelectedFrame()).getUndoManager().redo(); Task root = (Task) ((TaskTree) editor.getLevelPanel()).getRootNode().getTask(); ((TaskTree) editor.getLevelPanel()).updateTreeByChildren(root); } } } } /** * */ @SuppressWarnings("serial") public static class FontStyleAction extends AbstractAction { /** * */ protected boolean bold; /** * */ public FontStyleAction(boolean bold) { this.bold = bold; } /** * */ public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof mxGraphComponent) { mxGraphComponent graphComponent = (mxGraphComponent) e.getSource(); Component editorComponent = null; if (graphComponent.getCellEditor() instanceof mxCellEditor) { editorComponent = ((mxCellEditor) graphComponent.getCellEditor()).getEditor(); } if (editorComponent instanceof JEditorPane) { JEditorPane editorPane = (JEditorPane) editorComponent; int start = editorPane.getSelectionStart(); int ende = editorPane.getSelectionEnd(); String text = editorPane.getSelectedText(); if (text == null) { text = ""; } try { HTMLEditorKit editorKit = new HTMLEditorKit(); HTMLDocument document = (HTMLDocument) editorPane.getDocument(); document.remove(start, (ende - start)); editorKit.insertHTML(document, start, ((bold) ? "<b>" : "<i>") + text + ((bold) ? "</b>" : "</i>"), 0, 0, (bold) ? HTML.Tag.B : HTML.Tag.I); } catch (Exception ex) { ex.printStackTrace(); } editorPane.requestFocus(); editorPane.select(start, ende); } else { mxIGraphModel model = graphComponent.getGraph().getModel(); model.beginUpdate(); try { graphComponent.stopEditing(false); graphComponent.getGraph().toggleCellStyleFlags(mxConstants.STYLE_FONTSTYLE, (bold) ? mxConstants.FONT_BOLD : mxConstants.FONT_ITALIC); } finally { model.endUpdate(); } } } } } /** * */ @SuppressWarnings("serial") public static class WarningAction extends AbstractAction { /** * */ public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof mxGraphComponent) { mxGraphComponent graphComponent = (mxGraphComponent) e.getSource(); Object[] cells = graphComponent.getGraph().getSelectionCells(); if (cells != null && cells.length > 0) { String warning = JOptionPane.showInputDialog(mxResources.get("enterWarningMessage")); for (int i = 0; i < cells.length; i++) { graphComponent.setCellWarning(cells[i], warning); } } else { JOptionPane.showMessageDialog(graphComponent, mxResources.get("noCellSelected")); } } } } /** *a */ @SuppressWarnings("serial") public static class NewAction extends AbstractAction { /** * */ public void actionPerformed(ActionEvent e) { BasicGraphEditor editor = getEditor(e); if (editor != null) { mxGraph newGraph = new com.mxgraph.examples.swing.GraphEditor.CustomGraph(); newGraph.copyEditorGraph(editor.getGraphComponent().getGraph()); NewFileDialog.createAndShowGUI(newGraph, editor); // MyInternalFrame frame = new MyInternalFrame("",editor,editor.getGraphOutline()); /*frame.setGraphComponent( new com.mxgraph.examples.swing.GraphEditor.CustomGraphComponent(newGraph)); try { frame.setMaximum(true); } catch (PropertyVetoException e1) { e1.printStackTrace(); } frame.show(); frame.setVisible(true); //necessary as of 1.3 editor.getDesktop().add(frame); try { frame.setSelected(true); } catch (java.beans.PropertyVetoException exe) {}*/ /* if (!editor.isModified() || JOptionPane.showConfirmDialog(editor, mxResources .get("loseChanges")) == JOptionPane.YES_OPTION) { mxGraph graph = editor.getGraphComponent().getGraph(); // Check modified flag and display save dialog mxCell root = new mxCell(); root.insert(new mxCell()); graph.getModel().setRoot(root); editor.setModified(false); editor.setCurrentFile(null); editor.getGraphComponent().setBackgroundImage(new ImageIcon(mxConstants.USERDIR+"/savefile/hangImages/background.jpg")); } */ } } } /** *aa */ @SuppressWarnings("serial") public static class OpenAction extends AbstractAction { /** * */ protected String lastDir; /** * */ public void actionPerformed(ActionEvent e) { BasicGraphEditor editor = getEditor(e); if (editor != null) { mxGraph newGraph = new com.mxgraph.examples.swing.GraphEditor.CustomGraph(); newGraph.copyEditorGraph(editor.getGraphComponent().getGraph()); // mxGraphComponent newGraphComponent = new com.mxgraph.examples.swing.GraphEditor.CustomGraphComponent(newGraph); String wd = (lastDir != null) ? lastDir : System.getProperty("user.dir"); JFileChooser fc = new JFileChooser(wd); // Adds file filter for supported file format FileFilter defaultFilter = new DefaultFileFilter(".mxe", "mxGraph Editor " + mxResources.get("file") + " (.mxe)"); fc.addChoosableFileFilter(defaultFilter); int rc = fc.showDialog(null, mxResources.get("openFile")); if (rc == JFileChooser.APPROVE_OPTION) { String filetitle = fc.getSelectedFile().getAbsolutePath(); editor.openFile(filetitle, null); /* lastDir = fc.getSelectedFile().getParent(); JInternalFrame[] frames = editor.getDesktop().getAllFrames(); for(int i = 0; i<frames.length; i++) { MyInternalFrame frame = (MyInternalFrame) frames[i]; if(fc.getSelectedFile() .getAbsolutePath().equals(frame.getTitle())) { // int response = JOptionPane.showConfirmDialog(null, "", "Confirm",JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.NO_OPTION) { //frame editor.showFrame(frame, frame.getTitle()); return; }else if (response == JOptionPane.CLOSED_OPTION) { //do nothing return; } else if (response == JOptionPane.YES_OPTION) { // // frame.dispose(); } } } // try { Document document = mxUtils.parse(mxUtils .readFile(fc.getSelectedFile() .getAbsolutePath())); if(document == null) { JOptionPane.showMessageDialog(editor, ""+fc.getSelectedFile().getParent()+""); return; } mxCodec codec = new mxCodec(document); Element modelNode = document.getDocumentElement(); String backgroundImage = modelNode.getAttribute("backgroundImage"); codec.decode(modelNode, newGraph.getModel()); if(newGraph.getTaskModel() == null) newGraph.setTaskModel(new mxGraphModel()); Task tempRoot = (Task)((mxGraphModel)newGraph.getModel()).getTempRoot(); String filename = fc.getSelectedFile().getAbsolutePath(); tempRoot.setStyle(filename); if((tempRoot.getIdentifier() == null)||(tempRoot.getIdentifier().length() < 1)) tempRoot.setIdentifier(filename.substring(filename.lastIndexOf("\\") + 1, filename.lastIndexOf("."))); newGraph.getTaskModel().setRoot(tempRoot); newGraph.getTaskModel().addObserver((TaskTree)editor.getLevelPanel()); newGraph.getTaskModel().getTask_node_map().put(tempRoot, new Graph("")); newGraph.refresh(); newGraphComponent.setBackgroundImage(new ImageIcon(backgroundImage)); String pageFormatStyle = null; if(modelNode.hasAttribute("pageFormatStyle")) { pageFormatStyle = modelNode.getAttribute("pageFormatStyle"); newGraphComponent.getPageFormat().setOrientation(new Integer(pageFormatStyle).intValue()); } Object[] cells = newGraph.getChildCells(newGraph.getDefaultParent()); Map<String, ArrayList<String>> dbCells = newGraphComponent.getDbID_cellIDs(); dbCells.clear(); ArrayList<String> cellIDs; for(int i = 0; i<cells.length; i++) { mxCell cell = (mxCell)cells[i]; if(cell.getSourceID()!=null){ if(!dbCells.containsKey("idName")){ cellIDs = new ArrayList<String>(); cellIDs.add(cell.getId()); dbCells.put(cell.getSourceID(), cellIDs); } else { cellIDs = dbCells.get(cell.getSourceID()); cellIDs.add(cell.getId()); } } } // editor.setModified(false); // editor.setCurrentFile(fc.getSelectedFile()); newGraphComponent.zoomAndCenter(); } catch (IOException e1) { e1.printStackTrace(); } MyInternalFrame frame = new MyInternalFrame(fc.getSelectedFile() .getAbsolutePath(),editor,editor.getGraphOutline()); frame.setGraphComponent(newGraphComponent); frame.setVisible(true); //necessary as of 1.3 editor.getDesktop().add(frame); editor.showFrame(frame, fc.getSelectedFile().getAbsolutePath()); frame.setModified(false); //filenamelogMap Map<String, String> logMap = editor.getLogMap(); logMap.put(fc.getSelectedFile().getAbsolutePath(), editor.getNowTime());*/ } } } } /** * */ @SuppressWarnings("serial") public static class ToggleAction extends AbstractAction { /** * */ protected String key; /** * */ protected boolean defaultValue; /** * * @param key */ public ToggleAction(String key) { this(key, false); } /** * * @param key */ public ToggleAction(String key, boolean defaultValue) { this.key = key; this.defaultValue = defaultValue; } /** * */ public void actionPerformed(ActionEvent e) { mxGraph graph = mxGraphActions.getGraph(e); if (graph != null) { graph.toggleCellStyles(key, defaultValue); } } } /** * */ @SuppressWarnings("serial") public static class SetLabelPositionAction extends AbstractAction { /** * */ protected String labelPosition, alignment; /** * * @param key */ public SetLabelPositionAction(String labelPosition, String alignment) { this.labelPosition = labelPosition; this.alignment = alignment; } /** * */ public void actionPerformed(ActionEvent e) { mxGraph graph = mxGraphActions.getGraph(e); if (graph != null && !graph.isSelectionEmpty()) { graph.getModel().beginUpdate(); try { // Checks the orientation of the alignment to use the correct constants if (labelPosition.equals(mxConstants.ALIGN_LEFT) || labelPosition.equals(mxConstants.ALIGN_CENTER) || labelPosition.equals(mxConstants.ALIGN_RIGHT)) { graph.setCellStyles(mxConstants.STYLE_LABEL_POSITION, labelPosition); graph.setCellStyles(mxConstants.STYLE_ALIGN, alignment); } else { graph.setCellStyles(mxConstants.STYLE_VERTICAL_LABEL_POSITION, labelPosition); graph.setCellStyles(mxConstants.STYLE_VERTICAL_ALIGN, alignment); } } finally { graph.getModel().endUpdate(); } } } } /** * */ @SuppressWarnings("serial") public static class SetStyleAction extends AbstractAction { /** * */ protected String value; /** * * @param key */ public SetStyleAction(String value) { this.value = value; } /** * */ public void actionPerformed(ActionEvent e) { mxGraph graph = mxGraphActions.getGraph(e); if (graph != null && !graph.isSelectionEmpty()) { graph.setCellStyle(value); } } } /** * */ @SuppressWarnings("serial") public static class KeyValueAction extends AbstractAction { /** * */ protected String key, value; /** * * @param key */ public KeyValueAction(String key) { this(key, null); } /** * * @param key */ public KeyValueAction(String key, String value) { this.key = key; this.value = value; } /** * */ public void actionPerformed(ActionEvent e) { mxGraph graph = mxGraphActions.getGraph(e); if (graph != null && !graph.isSelectionEmpty()) { graph.setCellStyles(key, value); } } } /** * */ @SuppressWarnings("serial") public static class PromptValueAction extends AbstractAction { /** * */ protected String key, message; /** * * @param key */ public PromptValueAction(String key, String message) { this.key = key; this.message = message; } /** * */ public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof Component) { mxGraph graph = mxGraphActions.getGraph(e); if (graph != null && !graph.isSelectionEmpty()) { String value = (String) JOptionPane.showInputDialog((Component) e.getSource(), mxResources.get("value"), message, JOptionPane.PLAIN_MESSAGE, null, null, ""); if (value != null) { if (value.equals(mxConstants.NONE)) { value = null; } graph.setCellStyles(key, value); } } } } } /** * */ @SuppressWarnings("serial") public static class AlignCellsAction extends AbstractAction { /** * */ protected String align; /** * * @param key */ public AlignCellsAction(String align) { this.align = align; } /** * */ public void actionPerformed(ActionEvent e) { mxGraph graph = mxGraphActions.getGraph(e); if (graph != null && !graph.isSelectionEmpty()) { graph.alignCells(align); } } } /** * */ @SuppressWarnings("serial") public static class AutosizeAction extends AbstractAction { /** * */ public void actionPerformed(ActionEvent e) { mxGraph graph = mxGraphActions.getGraph(e); if (graph != null && !graph.isSelectionEmpty()) { graph.updateCellSize(graph.getSelectionCell()); } } } /** * */ @SuppressWarnings("serial") public static class ColorAction extends AbstractAction { /** * */ protected String name, key; /** * * @param key */ public ColorAction(String name, String key) { this.name = name; this.key = key; } /** * */ public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof mxGraphComponent) { mxGraphComponent graphComponent = (mxGraphComponent) e.getSource(); mxGraph graph = graphComponent.getGraph(); if (!graph.isSelectionEmpty()) { Color newColor = JColorChooser.showDialog(graphComponent, name, null); if (newColor != null) { graph.setCellStyles(key, mxUtils.hexString(newColor)); } } } } } /** * */ @SuppressWarnings("serial") public static class BackgroundImageAction extends AbstractAction { /** * */ public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof mxGraphComponent) { BasicGraphEditor editor = getEditor(e); mxGraphComponent graphComponent; if (editor.getDesktop().getSelectedFrame() != null) graphComponent = ((MyInternalFrame) editor.getDesktop().getSelectedFrame()).getGraphComponent(); else graphComponent = (mxGraphComponent) e.getSource(); // String wd = System.getProperty("user.dir"); JFileChooser fc = new JFileChooser(wd); // Adds file filter for supported file format FileFilter jpgFilter = new DefaultFileFilter(".jpg", "jpg" + mxResources.get("file") + " (.jpg)"); fc.addChoosableFileFilter(jpgFilter); FileFilter jpegFilter = new DefaultFileFilter(".jpeg", "jpeg" + mxResources.get("file") + " (.jpeg)"); fc.addChoosableFileFilter(jpegFilter); FileFilter gifFilter = new DefaultFileFilter(".gif", "gif" + mxResources.get("file") + " (.gif)"); fc.addChoosableFileFilter(gifFilter); int rc = fc.showDialog(null, mxResources.get("openFile")); String value = null; if (rc == JFileChooser.APPROVE_OPTION) { value = fc.getSelectedFile().getParent() + "\\" + fc.getSelectedFile().getName(); System.out.println("" + value); if (value.length() != 0 && (value.substring(value.lastIndexOf(".") + 1, value.length()).equals("jpg") || value.substring(value.lastIndexOf(".") + 1, value.length()).equals("jpeg") || value.substring(value.lastIndexOf(".") + 1, value.length()).equals("gif") || value.substring(value.lastIndexOf(".") + 1, value.length()).equals("bmp") || value.substring(value.lastIndexOf(".") + 1, value.length()).equals("JPG") || value.substring(value.lastIndexOf(".") + 1, value.length()).equals("JPEG") || value.substring(value.lastIndexOf(".") + 1, value.length()).equals("BMP"))) { graphComponent.setBackgroundImage(new ImageIcon(value)); } else { graphComponent.setBackgroundImage(null); // mxUtils.loadImage(value); } // Forces a repaint of the outline graphComponent.getGraph().repaint(); graphComponent.repaint(); } // /*String value= (String) JOptionPane.showInputDialog( graphComponent, mxResources.get("backgroundImage"), "URL", JOptionPane.PLAIN_MESSAGE, null, null, "f://1.jpg")*/; /* if (value != null) { if (value.length() == 0) { graphComponent.setBackgroundImage(null); } else { graphComponent.setBackgroundImage(new ImageIcon(value)); // mxUtils.loadImage(value); } // Forces a repaint of the outline graphComponent.getGraph().repaint(); } */ } } } /** * */ @SuppressWarnings("serial") public static class BackgroundAction extends AbstractAction { /** * */ public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof mxGraphComponent) { mxGraphComponent graphComponent = (mxGraphComponent) e.getSource(); Color newColor = JColorChooser.showDialog(graphComponent, mxResources.get("background"), null); if (newColor != null) { graphComponent.getViewport().setOpaque(false); graphComponent.setBackground(newColor); String color = mxUtils.Color2String(newColor); mxGraphModel model = (mxGraphModel) graphComponent.getGraph().getModel(); // model.setPageColor(newColor.getRGB()); model.execute(new mxPageColorChange(model, newColor)); } // Forces a repaint of the outline graphComponent.getGraph().repaint(); } } } /** * */ @SuppressWarnings("serial") public static class PageBackgroundAction extends AbstractAction { /** * */ public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof mxGraphComponent) { mxGraphComponent graphComponent = (mxGraphComponent) e.getSource(); Color newColor = JColorChooser.showDialog(graphComponent, mxResources.get("pageBackground"), null); if (newColor != null) { graphComponent.setPageBackgroundColor(newColor); } // Forces a repaint of the component graphComponent.repaint(); } } } /** * */ @SuppressWarnings("serial") public static class StyleAction extends AbstractAction { /** * */ public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof mxGraphComponent) { mxGraphComponent graphComponent = (mxGraphComponent) e.getSource(); mxGraph graph = graphComponent.getGraph(); String initial = graph.getModel().getStyle(graph.getSelectionCell()); String value = (String) JOptionPane.showInputDialog(graphComponent, mxResources.get("style"), mxResources.get("style"), JOptionPane.PLAIN_MESSAGE, null, null, initial); if (value != null) { graph.setCellStyle(value); } } } } public static class ConstantsAction extends AbstractAction { /** * */ private static final long serialVersionUID = -1295098354503820373L; private int i; public ConstantsAction(int i) { this.i = i; } public void actionPerformed(ActionEvent e) { mxConstants.paint = i; } } @SuppressWarnings("serial") public static class ManualsizeAction extends AbstractAction { public void actionPerformed(ActionEvent e) { mxGraph graph = mxGraphActions.getGraph(e); if (graph != null && !graph.isSelectionEmpty()) { // CellBoundsMsg boundsMsg = new CellBoundsMsg(new JDialog((JFrame) null, ""), graph); } } } public static final class SaveAllShowAction extends AbstractAction { private static final long serialVersionUID = 3981665821266679043L; protected boolean showDialog; public SaveAllShowAction(boolean showDialog) { this.showDialog = showDialog; } public void actionPerformed(ActionEvent e) { BasicGraphEditor editor = getEditor(e); JInternalFrame[] frames = editor.getDesktop().getAllFrames(); for (int j = 0; j < frames.length; j++) { MyInternalFrame frame = (MyInternalFrame) frames[j]; try { frame.setSelected(true); if (!frame.isMaximum()) { frame.setMaximum(true); frame.show(); } } catch (PropertyVetoException e1) { e1.printStackTrace(); } editor.saveFile(showDialog); } } } public static class SameBoundsAction extends AbstractAction { private static final long serialVersionUID = 1L; private boolean isWidth; private int sameflag; //1-1,0 public SameBoundsAction(boolean isWidth, int sameflag) { this.isWidth = isWidth; this.sameflag = sameflag; } public void actionPerformed(ActionEvent e) { mxGraph graph = mxGraphActions.getGraph(e); Object[] cells = graph.getSelectionCells(); if (cells.length > 1) { if (isWidth) { double result = ((mxCell) cells[0]).getGeometry().getWidth(); switch (sameflag) { case 1: result = getMaxWidth(cells); break; case 0: double maxtemp = getMaxWidth(cells); double mintemp = getMinWidth(cells); result = (maxtemp + mintemp) / 2; break; case -1: result = getMinWidth(cells); break; } for (int i = 0; i < cells.length; i++) { ((mxCell) cells[i]).getGeometry().setWidth(result); } } else { double result = ((mxCell) cells[0]).getGeometry().getHeight(); switch (sameflag) { case 1: result = getMaxHeight(cells); break; case 0: double maxtemp = getMaxHeight(cells); double mintemp = getMinHeight(cells); result = (maxtemp + mintemp) / 2; break; case -1: result = getMinHeight(cells); break; } for (int i = 0; i < cells.length; i++) { ((mxCell) cells[i]).getGeometry().setHeight(result); } } graph.refresh(); } } protected double getMaxWidth(Object[] cells) { double maxResult = ((mxCell) cells[0]).getGeometry().getWidth(); for (int i = 1; i < cells.length; i++) { double temp = ((mxCell) cells[i]).getGeometry().getWidth(); maxResult = Math.max(maxResult, temp); } return maxResult; } protected double getMaxHeight(Object[] cells) { double maxResult = ((mxCell) cells[0]).getGeometry().getHeight(); for (int i = 1; i < cells.length; i++) { double temp = ((mxCell) cells[i]).getGeometry().getHeight(); maxResult = Math.max(maxResult, temp); } return maxResult; } protected double getMinWidth(Object[] cells) { double minResult = ((mxCell) cells[0]).getGeometry().getWidth(); for (int i = 1; i < cells.length; i++) { double temp = ((mxCell) cells[i]).getGeometry().getWidth(); minResult = Math.min(minResult, temp); } return minResult; } protected double getMinHeight(Object[] cells) { double minResult = ((mxCell) cells[0]).getGeometry().getHeight(); for (int i = 1; i < cells.length; i++) { double temp = ((mxCell) cells[i]).getGeometry().getHeight(); minResult = Math.min(minResult, temp); } return minResult; } } public static class SplitAction extends AbstractAction { private static final long serialVersionUID = 1L; private boolean isVertical; public SplitAction(boolean isVertical) { this.isVertical = isVertical; } @Override public void actionPerformed(ActionEvent e) { mxGraph graph = mxGraphActions.getGraph(e); Object[] cells = graph.getSelectionCells(); Map<Double, Object> x_cell = new HashMap<Double, Object>(); double sumWidth = 0; Map<Double, Object> y_cell = new HashMap<Double, Object>(); double sumHeight = 0; double space = 0; if (isVertical) { // for (int i = 0; i < cells.length; i++) { y_cell.put(((mxCell) cells[i]).getGeometry().getY(), cells[i]); String style = ((mxCell) cells[i]).getStyle(); if (style != null && isRotation(style)) { sumHeight += ((mxCell) cells[i]).getGeometry().getWidth(); } else { sumHeight += ((mxCell) cells[i]).getGeometry().getHeight(); } } Object[] ylist = y_cell.keySet().toArray(); Arrays.sort(ylist); double lastHeight = ((mxCell) y_cell.get(ylist[ylist.length - 1])).getGeometry().getHeight(); double sumlength = (Double) ylist[ylist.length - 1] + lastHeight - (Double) ylist[0]; space = (sumlength - sumHeight) / (ylist.length - 1); double yposition = ((mxCell) cells[0]).getGeometry().getY(); for (int i = 0; i < cells.length; i++) { mxGeometry geo = ((mxCell) cells[i]).getGeometry(); geo.setY(yposition); yposition = yposition + geo.getHeight() + space; } } else { // for (int i = 0; i < cells.length; i++) { x_cell.put(((mxCell) cells[i]).getGeometry().getX(), cells[i]); String style = ((mxCell) cells[i]).getStyle(); if (style != null && isRotation(style)) sumWidth += ((mxCell) cells[i]).getGeometry().getHeight(); else sumWidth += ((mxCell) cells[i]).getGeometry().getWidth(); } Object[] xlist = x_cell.keySet().toArray(); Arrays.sort(xlist); double lastWidth = ((mxCell) x_cell.get(xlist[xlist.length - 1])).getGeometry().getWidth(); double sumlength = (Double) xlist[xlist.length - 1] + lastWidth - (Double) xlist[0]; space = (sumlength - sumWidth) / (xlist.length - 1); double xposition = ((mxCell) cells[0]).getGeometry().getX(); for (int i = 0; i < cells.length; i++) { mxGeometry geo = ((mxCell) cells[i]).getGeometry(); geo.setX(xposition); xposition = xposition + geo.getWidth() + space; } } graph.refresh(); } public boolean isRotation(String style) { if (style.contains("rotation")) { style = style.substring(style.indexOf("rotation")); if (style.contains(";")) style = style.substring(0, style.indexOf(";")); int rotate = Integer.parseInt(style.substring(style.indexOf("=") + 1)); if (rotate % 90 == 0) return true; } return false; } } public static class ImportImageAction extends AbstractAction { @Override public void actionPerformed(ActionEvent e) { EditorPalette imagesPalette = null; JMenuItem target = (JMenuItem) e.getSource(); imagesPalette = (EditorPalette) (((JPopupMenu) target.getParent()).getInvoker()); JFileChooser chooser = new JFileChooser(); chooser.setMultiSelectionEnabled(true); FileNameExtensionFilter filter = new FileNameExtensionFilter( "*.jpg;*.gif;*.bmp;*.jpeg;*.wbmp;*.png;*.tif;*.tiff", "jpg", "gif", "bmp", "jpeg", "wbmp", "png", "tif", "tiff"); chooser.setFileFilter(filter); int returnVal = chooser.showDialog(imagesPalette, ""); if (returnVal == JFileChooser.APPROVE_OPTION) { File[] files = chooser.getSelectedFiles(); for (int i = 0; i < files.length; i++) { // String oldPath = files[i].getAbsolutePath(); String imageLibDir = mxConstants.IMAGELIBDIR; String fileName = files[i].getName().substring(0, files[i].getName().lastIndexOf(".")); String filePath = null; if (imageLibDir.endsWith(File.separator)) filePath = imageLibDir + files[i].getName(); else filePath = imageLibDir + File.separator + files[i].getName(); // File myFile = new File(filePath); if (myFile.exists()) { JOptionPane.showMessageDialog(imagesPalette, ""); return; } // mxUtils.copyFile(oldPath, filePath); // //String style = "image;image=" + myFile.getAbsolutePath(); //String style = "image;image=" + "/jgraphx//" + files[i].getName(); //String style = "image;image=" + myFile.getPath(); //System.out.println("old filePath: "+filePath); String style = "image;image=/" + filePath.replace("\\", "/"); String fileType = filePath.substring(filePath.lastIndexOf(".") + 1, filePath.length()); if (fileType.equalsIgnoreCase("gif")) style = "image;image=" + filePath.replace("/", "\\"); //System.out.println("new filePath: "+filePath); imagesPalette.addTemplate(fileName, new ImageIcon(filePath), style, 50, 50, "", true); } imagesPalette.repaint(); } } } public static class DeleteImageAction extends AbstractAction { @Override public void actionPerformed(ActionEvent e) { JLabel entry = null; JMenuItem target = (JMenuItem) e.getSource(); entry = (JLabel) (((JPopupMenu) target.getParent()).getInvoker()); EditorPalette imagesPalette = (EditorPalette) entry.getParent(); // String name = entry.getText(); String path = mxConstants.IMAGELIBDIR; String filePath = null; if (path.endsWith(File.separator)) filePath = path + name; else filePath = path + File.separator + name; File file = new File(path); if (file.isDirectory()) { File[] files = file.listFiles(); for (int i = 0; (i < files.length) && (files[i] != null); i++) { String fpath = files[i].getAbsolutePath(); String fname = files[i].getName(); fname = fname.substring(0, fname.lastIndexOf(".")); // if (fname.equals(name)) { files[i].delete(); if (files[i].exists()) { // imagesPalette.remove(entry); try { Thread thread = Thread.currentThread(); thread.sleep(200); } catch (InterruptedException e1) { e1.printStackTrace(); } files[i].delete(); } else imagesPalette.remove(entry); if ((new File(fpath)).exists()) { // imagesPalette.add(entry); JOptionPane.showMessageDialog(null, ""); } imagesPalette.repaint(); break; } } } } } @SuppressWarnings("serial") public static class AddTableAction extends AbstractAction { final BasicGraphEditor editor; public AddTableAction(BasicGraphEditor editor) { // TODO Auto-generated constructor stub this.editor = editor; } @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub final JFrame f = new JFrame(""); Container container = f.getContentPane(); container.setLayout(new FlowLayout()); JButton b1 = new JButton(""); JButton b2 = new JButton(""); f.setVisible(true); final JLabel l1 = new JLabel(""); final JLabel l2 = new JLabel(""); final JTextField t1 = new JTextField(10); final JTextField t2 = new JTextField(10); container.add(l1); container.add(t1); container.add(l2); container.add(t2); container.add(b1); container.add(b2); b1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub f.dispose(); String rowstr = t1.getText(); String columnstr = t2.getText(); int row = Integer.parseInt(rowstr); int column = Integer.parseInt(columnstr); int num = row * column; mxCell[] table = new mxCell[num]; for (int i = 0; i < column; i++) { for (int j = 0; j < row; j++) { table[i * j] = new mxCell(null, new mxGeometry(60 + i * 60, 60 + j * 30, 60, 30), null); //mxCell cell = table[i*j]; table[i * j].setVertex(true); table[i * j].setVisible(true); editor.getGraphComponent().getGraph().addCell(table[i * j]); } } //mxCell cell = new mxCell(null, new mxGeometry(60,60,60,30),null); //cell.setVertex(true); //cell.setVisible(true); //editor.getGraphComponent().getGraph().addCell(cell); editor.getGraphComponent().getGraph().createGroupCell(table); } }); b2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub f.dispose(); } }); f.setSize(300, 100); //b1.addActionListener(mxGraphActions.getPaintTableAction(Integer.parseInt(t1.getText()),Integer.parseInt(t2.getText()))); f.setLocationRelativeTo(null); //PaintTableAction h = new PaintTableAction(Integer.parseInt(t1.getText()),Integer.parseInt(t2.getText())); } } public static class ChangeAngleAction extends AbstractAction { protected String message; /** * */ public ChangeAngleAction(String message) { this.message = message; } protected void resetArc() { mxConstants.ARC_ANGLE = 90; } /** * */ @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if (e.getSource() instanceof Component) { mxGraph graph = mxGraphActions.getGraph(e); if (graph != null && !graph.isSelectionEmpty()) { String value = (String) JOptionPane.showInputDialog((Component) e.getSource(), mxResources.get("value"), message, JOptionPane.PLAIN_MESSAGE, null, null, ""); if (value != null) { if (value.equals(mxConstants.NONE)) { value = null; } mxConstants.ARC_ANGLE = Integer.parseInt(value); graph.repaint(); //resetArc(); } } } // Repaints the graph component } } public static class ChangeMeterAction extends AbstractAction { /** * */ private static final long serialVersionUID = -6219261850383526660L; protected String message; /** * */ public ChangeMeterAction(String message) { this.message = message; } /** * */ @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if (e.getSource() instanceof Component) { mxGraph graph = mxGraphActions.getGraph(e); mxCell cell = (mxCell) graph.getSelectionCell(); if (graph != null && !graph.isSelectionEmpty()) { String value = (String) JOptionPane.showInputDialog((Component) e.getSource(), mxResources.get("value"), message, JOptionPane.PLAIN_MESSAGE, null, null, ""); if (value != null) { if (value.equals(mxConstants.NONE)) { value = null; } //mxConstants.METER_START = 180-(Integer.parseInt(value)/100)*270; //double temp = (double)(Math.round(Integer.parseInt(value)/100)/100.0); //resetMeter(); //double angle = Double.parseDouble(value)*2.7-45; //mxConstants.METER_ENDX = mxConstants.METER_CENTERX - Math.cos(angle*Math.PI/180)*mxConstants.METER_RADIUS; //mxConstants.METER_ENDY = mxConstants.METER_CENTERY - Math.sin(angle*Math.PI/180)*mxConstants.METER_RADIUS; if (cell.getStyle().equalsIgnoreCase("shape=continue")) { mxConstants.CONTINUE_NUM = value; } else if (cell.getStyle().equalsIgnoreCase("shape=levelContinue")) { mxConstants.LEVELCONTINUE_NUM = value; } else { mxConstants.METER_DISPLAY = Double.parseDouble(value); } //mxConstants.METER_EXTENT = 270-Double.parseDouble(value)*2.7; graph.refresh(); } } } // Repaints the graph component } } public static class ChangeThmeterAction extends AbstractAction { /** * */ private static final long serialVersionUID = -6219261850383526660L; protected String message; /** * */ public ChangeThmeterAction(String message) { this.message = message; } /** * */ @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if (e.getSource() instanceof Component) { mxGraph graph = mxGraphActions.getGraph(e); if (graph != null && !graph.isSelectionEmpty()) { String value = (String) JOptionPane.showInputDialog((Component) e.getSource(), mxResources.get("value"), message, JOptionPane.PLAIN_MESSAGE, null, null, ""); if (value != null) { if (value.equals(mxConstants.NONE)) { value = null; } mxConstants.THMETER_DISPLAY = Double.parseDouble(value); graph.refresh(); } } } // Repaints the graph component } } public static class UploadFileAction extends AbstractAction { /** * */ private static final long serialVersionUID = 1L; //private String path; private JFileChooser chooser = new JFileChooser(new File("../../products/KingforeDraw/"));; File file = null; // public void UploadFileAction(){ // path=PropertiesHelper.getProperties("../../config/KingforeDraw/configs.properties", "workspace")+"/"; // chooser = new JFileChooser(new File(path)); // } @Override public void actionPerformed(ActionEvent e) { chooser.setFileSelectionMode(JFileChooser.OPEN_DIALOG); //JTextField FTPField = new JTextField(); final JTextField passwordText = new JPasswordField(50); final JTextField FTPnameField = new JTextField(50); final JDialog paraDialog = new JDialog(); final JTextField FTPField = new JTextField(50); JButton FTPButton = new JButton(""); JButton submit = new JButton(""); final JLabel filename = new JLabel(""); //paraDialog.getContentPane().setLayout(new BorderLayout()); final JPanel paraPane = new JPanel(new FlowLayout()); //FTPButton.setName(""); //paraPane.add(new JLabel(chooser.getIcon(file))); FTPButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int rc = chooser.showDialog(null, null); file = chooser.getSelectedFile(); filename.setText(chooser.getSelectedFile().getAbsolutePath()); } }); submit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub FTPClient client = new FTPClient(); paraDialog.dispose(); try { //client.connect(FTPField.getText()); //client.login(FTPnameField.getText(), passwordText.getText()); client.connect(ConfService.getFtpIP()); client.login(ConfService.getFtpUser(), ConfService.getFtpPassword()); try { client.upload(file); } catch (FTPDataTransferException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (FTPAbortedException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } catch (IllegalStateException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (FTPIllegalReplyException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (FTPException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); paraPane.add(FTPButton); paraPane.add(submit); paraPane.add(filename); paraDialog.add(paraPane); paraDialog.setSize(new Dimension(400, 250)); paraDialog.setVisible(true); } } }