⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 actionloadlayout.java

📁 UML设计测试工具
💻 JAVA
字号:
/*
 * USE - UML based specification environment
 * Copyright (C) 1999-2004 Mark Richters, University of Bremen
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/* $ProjectHeader: use 2-3-0-release.1 Mon, 12 Sep 2005 20:18:33 +0200 green $ */

package org.tzi.use.gui.views.diagrams.event;

import java.awt.event.ActionEvent;
import java.io.File;
import java.io.PrintWriter;

import javax.swing.AbstractAction;
import javax.swing.JFileChooser;
import javax.swing.JPanel;

import org.tzi.use.graph.DirectedGraph;
import org.tzi.use.gui.util.ExtFileFilter;
import org.tzi.use.gui.views.diagrams.DiagramOptions;
import org.tzi.use.gui.views.diagrams.DiagramView;
import org.tzi.use.gui.views.diagrams.LayoutInfos;
import org.tzi.use.parser.xml.XMLParserAccess;
import org.tzi.use.parser.xml.XMLParserAccessImpl;
import org.tzi.use.util.Log;

/**
 * Loads the current layout from a file.
 * 
 * @version $ProjectVersion: 2-3-0-release.1 $
 * @author Fabian Gutsche
 */
public class ActionLoadLayout extends AbstractAction {
    private JFileChooser fChooser;
    private String fTitle = "";
    private String fAppendix = "";
    private DiagramView fDiagram;
    private PrintWriter fLog;
    private HideAdministration fHideAdmin;
    private DirectedGraph fGraph;


    private LayoutInfos fLayoutInfos;
    
    private DiagramOptions fOpt;
    
    public ActionLoadLayout( String title, String appendix, DiagramView diagram,
                             PrintWriter log, DiagramOptions opt, 
                             HideAdministration hideAdmin, DirectedGraph graph ) {
        super("Load layout...");
        fTitle = title;
        fAppendix = appendix;
        
        fDiagram = diagram;
        fLog = log;
        fOpt = opt;
        fHideAdmin = hideAdmin;
        fGraph = graph;
    }

    public ActionLoadLayout( String title, String appendix,
                             DiagramView diagram, PrintWriter log,
                             HideAdministration hideAdmin, DirectedGraph graph,
                             LayoutInfos layoutInfos ) {
        super("Load layout...");
        fTitle = title;
        fAppendix = appendix;
        fLayoutInfos = layoutInfos;
        fDiagram = diagram;
        fLog = log;
        fHideAdmin = hideAdmin;

        //        fGraph = graph;
    }
    
    public void actionPerformed(ActionEvent e) {
        String path;
        // reuse chooser if possible
        if (fChooser == null) {
            path = System.getProperty("user.dir");
            fChooser = new JFileChooser(path);
            ExtFileFilter filter = new ExtFileFilter( fAppendix, fTitle );
            fChooser.addChoosableFileFilter(filter);
            fChooser.setDialogTitle("Load layout");
        }
        int returnVal = fChooser.showOpenDialog( new JPanel() );
        if (returnVal != JFileChooser.APPROVE_OPTION)
            return;

        path = fChooser.getCurrentDirectory().toString();
        File f = new File(path, fChooser.getSelectedFile().getName());
        Log.verbose("File " + f);

        //show all hidden nodes and edges. This is nesseccary, if 
        // nodes are hidden but a layout will be loaded which 
        // contains no hidden nodes or edges.
        if ( fHideAdmin != null ) {
            fHideAdmin.showAllHiddenElements();
        }
        
        fLog.println("Reading layout file " + f);
        XMLParserAccess xmlParser = new XMLParserAccessImpl( fLayoutInfos );
        xmlParser.loadXMLFile( f, true );
//        fLayoutInfos.getDiagram().deleteHiddenNodes();
        fDiagram.deleteHiddenElementsFromDiagram( fLayoutInfos.getHiddenNodes(),
                                                  fLayoutInfos.getHiddenEdges() );
        
//        System.out.println("xml: "+fLayoutInfos.getHiddenElementsXML());
        fDiagram.repaint();
        
//        Properties prop = new Properties();
//        InputStream in = null;
//        try {
//            in = new BufferedInputStream(new FileInputStream(f));
//            fLog.println("Reading layout file " + f);
//            prop.load(in);
//
//            // show all hidden nodes and edges. This is nesseccary, if 
//            // nodes are hidden but a layout will be loaded which 
//            // contains no hidden nodes or edges.
//            if ( fHideAdmin != null ) {
//                fHideAdmin.showAllHiddenElements();
//            }
//            
//            // set diagram options
//            setDiagramOptions( prop );
//
//            // load layout information of the nodes
//            Iterator nodeIterator = fGraph.iterator();
//            while (nodeIterator.hasNext()) {
//                NodeBase n = (NodeBase) nodeIterator.next();
//                n.loadPlacementInfo( prop, fLog, fDiagram, false );                
//            }
//            
//            // load layout information of the edges (EdgeProperties)
//            Iterator edgeIterator = fGraph.edgeIterator();
//            while (edgeIterator.hasNext()) {
//                EdgeBase edge = (EdgeBase) edgeIterator.next();
//                edge.loadPlacementInfo( prop, fLog );
//            }
//             
//            fDiagram.deleteHiddenNodes();
//            
//            fDiagram.repaint();
//        } catch (IOException ex) {
//            JOptionPane.showMessageDialog(new JPanel(), ex.getMessage(),
//                    "Error", JOptionPane.ERROR_MESSAGE);
//        } finally {
//            if (in != null)
//                try {
//                    in.close();
//                } catch (IOException ex) {
//                    // ignored
//                }
//        }
    }
    
    
        
    
//    public void actionPerformed(ActionEvent e) {
//        String path;
//        // reuse chooser if possible
//        if (fChooser == null) {
//            path = System.getProperty("user.dir");
//            fChooser = new JFileChooser(path);
//            ExtFileFilter filter = new ExtFileFilter( fAppendix, fTitle );
//            fChooser.addChoosableFileFilter(filter);
//            fChooser.setDialogTitle("Load layout");
//        }
//        int returnVal = fChooser.showOpenDialog( new JPanel() );
//        if (returnVal != JFileChooser.APPROVE_OPTION)
//            return;
//
//        path = fChooser.getCurrentDirectory().toString();
//        File f = new File(path, fChooser.getSelectedFile().getName());
//        Log.verbose("File " + f);
//
//        Properties prop = new Properties();
//        InputStream in = null;
//        try {
//            in = new BufferedInputStream(new FileInputStream(f));
//            fLog.println("Reading layout file " + f);
//            prop.load(in);
//
//            // show all hidden nodes and edges. This is nesseccary, if 
//            // nodes are hidden but a layout will be loaded which 
//            // contains no hidden nodes or edges.
//            if ( fHideAdmin != null ) {
//                fHideAdmin.showAllHiddenElements();
//            }
//            
//            // set diagram options
//            setDiagramOptions( prop );
//
//            // load layout information of the nodes
//            Iterator nodeIterator = fGraph.iterator();
//            while (nodeIterator.hasNext()) {
//                NodeBase n = (NodeBase) nodeIterator.next();
//                n.loadPlacementInfo( prop, fLog, fDiagram, false );                
//            }
//            
//            // load layout information of the edges (EdgeProperties)
//            Iterator edgeIterator = fGraph.edgeIterator();
//            while (edgeIterator.hasNext()) {
//                EdgeBase edge = (EdgeBase) edgeIterator.next();
//                edge.loadPlacementInfo( prop, fLog );
//            }
//             
//            fDiagram.deleteHiddenNodes();
//            
//            fDiagram.repaint();
//        } catch (IOException ex) {
//            JOptionPane.showMessageDialog(new JPanel(), ex.getMessage(),
//                    "Error", JOptionPane.ERROR_MESSAGE);
//        } finally {
//            if (in != null)
//                try {
//                    in.close();
//                } catch (IOException ex) {
//                    // ignored
//                }
//        }
//    }
//    
//    
//    private void setDiagramOptions( Properties prop ) {
//        String autoLayout = prop.getProperty("autoLayout");
//        String antiAliasing = prop.getProperty("antiAliasing");
//        String showAssocNames = prop.getProperty("showAssocNames");
//        String showMultiplicities = prop.getProperty("showMultiplicities");
//        String showRolenames = prop.getProperty("showRolename");
//        String showAttributes = prop.getProperty("showAttributes");
//        String showOperations = prop.getProperty("showOperations");
//
//        if ( autoLayout != null ) {
//            fOpt.setDoAutoLayout( Boolean.valueOf( autoLayout ).booleanValue() );
//        }
//        if ( antiAliasing != null ) {
//            fOpt.setDoAntiAliasing( Boolean.valueOf( antiAliasing ).booleanValue() );
//        }
//        if ( showAssocNames != null ) {
//            fOpt.setShowAssocNames( Boolean.valueOf( showAssocNames ).booleanValue() );
//        }
//        if ( showMultiplicities != null ) {
//            fOpt.setShowMutliplicities( Boolean.valueOf( showMultiplicities ).booleanValue() );
//        }
//        if ( showAttributes != null ) {
//            fOpt.setShowAttributes( Boolean.valueOf( showAttributes ).booleanValue() );
//        }
//        if ( showOperations != null ) {
//            fOpt.setShowOperations( Boolean.valueOf( showOperations ).booleanValue() );
//        }
//        if ( showRolenames != null ) {
//            fOpt.setShowRolenames( Boolean.valueOf( showRolenames ).booleanValue() );
//        }
//    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -