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

📄 bsmapeditwindow.java

📁 一款即时通讯软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package edu.ou.kmi.buddyspace.plugins.maps.editor;

/*
 * BSMapEditWindow.java
 *
 * Project: BuddySpace
 * (C) Copyright Knowledge Media Institute 2002
 *
 *
 * Created on 13 December 2002, 14:46
 */

//import java.util.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;

import org.jabber.jabberbeans.util.*;

import edu.ou.kmi.buddyspace.core.*;
import edu.ou.kmi.buddyspace.gui.*;
import edu.ou.kmi.buddyspace.utils.*;
import edu.ou.kmi.buddyspace.plugins.maps.xml.*;
import edu.ou.kmi.buddyspace.plugins.maps.core.*;
import edu.ou.kmi.buddyspace.plugins.maps.gui.*;

/**
 * <code>BSMapEditWindow</code> provides map editing window GUI.
 * It contains <code>BSMapEditView</code> which is the actual map view and several
 * control components. All communication is done through 
 * <code>BSMapWinManager</code>.
 *
 * @author  Jiri Komzak, Knowledge Media Institute, Open University, United Kingdom
 */
public class BSMapEditWindow extends DockableWindow 
                             implements ActionListener, ItemListener {
                          
    static final String TEMP_DIR = "temp";
    
    private JPanel mainPanel;
    
    private BSMapEditView mapView = null;
    //private JPanel mapPanel = null;
    //private JPanel helpPanel = null;
    //private JScrollPane mapScrollPane = null;
    private JPanel buttonPanel = null;
    
    private JButton closeButton = null;
    private JButton saveButton = null;
    private JButton saveAsButton = null;

    private JButton dockButton;
    private JComboBox layersComboBox = null;
    /*private JButton addBuddyButton;
    private JButton setImgButton;
    private JButton setLayerButton;
    private JButton addMapButton;*/
    private JButton addLayerButton;
    private JButton refreshButton;
    private JPanel checkBoxesPanel;
    
    private boolean dontSetLayer = false;
    
    /** Constructor */
    public BSMapEditWindow(Window parent, BSMapWinManager winMan, String title,
                    Image icon, MapTag map, String mapID, String originID,
                    String mapPath, BSRosterBean rosterBean, boolean docked) {
                   
        super(originID + "/" + mapID, title, icon, docked, winMan);
        
        saveMapAs(originID, mapID, TEMP_DIR, mapID);
        mapView = new BSMapEditView(this, map, mapID, TEMP_DIR, mapPath, rosterBean);
        setTitle(TEMP_DIR + "/" + mapID);
        
        initComponents();
        
        if (!docked)
            frame.pack();
    }
    
    protected void initComponents() {
        mainPanel = new JPanel(new BorderLayout());
        mainPanel.add(mapView, BorderLayout.CENTER);
        
        //JPanel topPanel = new JPanel(new GridBagLayout());
        
        JPanel checkBoxesPanel = new JPanel();
        
        Icon icon = new ImageIcon(ClassLoader.getSystemResource(!docked?
                                "images/dock.gif" : "images/float.gif"));
        dockButton = new JButton(icon);
        dockButton.setToolTipText(docked? "Float" : "Dock");
        dockButton.addActionListener(this);
        checkBoxesPanel.add(dockButton);
        if (!OSVersion.isJava1Point4orHigher())
            dockButton.setEnabled(false);
        
        layersComboBox = new JComboBox();
        initLayersComboBox();
        layersComboBox.addItemListener(this);
        checkBoxesPanel.add(layersComboBox);
        
        /*addBuddyButton = new JButton("Add buddy");
        addBuddyButton.addActionListener(this);
        checkBoxesPanel.add(addBuddyButton);
        
        setImgButton = new JButton("Set bitmap");
        setImgButton.addActionListener(this);
        checkBoxesPanel.add(setImgButton);
        
        setLayerButton = new JButton("Set layer");
        setLayerButton.addActionListener(this);
        checkBoxesPanel.add(setLayerButton);
        
        addMapButton = new JButton("Add inset map");
        addMapButton.addActionListener(this);
        checkBoxesPanel.add(addMapButton);*/
        
        addLayerButton = new JButton("Add layer");
        addLayerButton.addActionListener(this);
        checkBoxesPanel.add(addLayerButton);
        
        refreshButton = new JButton("Refresh");
        refreshButton.addActionListener(this);
        checkBoxesPanel.add(refreshButton);
        
        mainPanel.add(checkBoxesPanel, BorderLayout.NORTH);
        
        buttonPanel = new JPanel();
        
        saveButton = new JButton();
        saveButton.setText("Save");
        saveButton.addActionListener(this);
        buttonPanel.add(saveButton);
        
        saveAsButton = new JButton();
        saveAsButton.setText("Save as");
        saveAsButton.addActionListener(this);
        buttonPanel.add(saveAsButton);
        
        closeButton = new JButton();
        closeButton.setText("Close");
        closeButton.addActionListener(this);
        buttonPanel.add(closeButton);
        
        mainPanel.add(buttonPanel, BorderLayout.SOUTH);
        
        setLayout(new BorderLayout());
        add(mainPanel, BorderLayout.CENTER);
    }
    
    public void initLayersComboBox() {
        layersComboBox.removeAllItems();
        Enumeration layersEnum = mapView.getLayers();
        while (layersEnum.hasMoreElements()) {
            LayerTag layer = (LayerTag) layersEnum.nextElement();
            String layerName = layer.getID();
            layersComboBox.addItem(layerName);
        }
    }
    
    /** Sets presence bean */
    public void setPresenceBean(BSPresenceBean presenceBean) {
        /*if (mapView != null)
            mapView.setPresenceBean(presenceBean);*/
    }
    
    /** Handles actions from GUI controls */
    public void actionPerformed(java.awt.event.ActionEvent evt) {
        if (evt.getSource() == closeButton) {
            winMan.closeWindow(this);
        }
        else if (evt.getSource() == saveButton) {
            ((BSMapWinManager)winMan).saveMap(mapView.getOriginID(), mapView.getMapID(),
                           mapView.getOriginID(), mapView.getMapID());
        }
        
        else if (evt.getSource() == saveAsButton) {
            
            JFileChooser fileChooser = new JFileChooser(mapView.getMapPath());
            fileChooser.setFileFilter(new BSMapFilter());
            fileChooser.setDialogTitle("Save map");
        
            if (JFileChooser.APPROVE_OPTION != 
                fileChooser.showSaveDialog(docked? ((BSMapWinManager)winMan).mainFrame : frame))
                return;
                
            File mapFile = fileChooser.getSelectedFile().getAbsoluteFile();
            String mapPath = mapFile.getAbsolutePath();
            if (!mapPath.endsWith(".ygf")) {
                mapPath = mapPath + ".ygf";
                mapFile = new File(mapPath);
            }
            String mapName = mapFile.getName();
            String mapOrigin = mapFile.getParentFile().getName();
            
            saveMapAs(mapView.getOriginID(), mapView.getMapID(),
                           mapOrigin, mapName);
            
            mapView.setMapID(mapName);
            mapView.setOriginID(mapOrigin);
            this.setTitle(mapOrigin + "/" + mapName);
        }
        
        else if (evt.getSource() == dockButton) {
            if (winMan != null) {
                winMan.setWindowDocked(this, !docked);
                Icon icon = new ImageIcon(ClassLoader.getSystemResource(!docked?
                                "images/dock.gif" : "images/float.gif"));
                dockButton.setIcon(icon);
                dockButton.setToolTipText(docked? "Float" : "Dock");
                winMan.selectWindow(this);
            }
        }
        
        /*else if (evt.getSource() == addBuddyButton) {
            if (!mapView.isSelectedLayerEditable()) {
                JOptionPane.showMessageDialog(docked? winMan.mainFrame : frame,
                        "Cannot change referenced map", 
                        "Add buddy error", 
                        JOptionPane.ERROR_MESSAGE);
                return;
            }
            addBuddy();
        }
        
        else if (evt.getSource() == setImgButton) {
            setImg();
        }
        
        else if (evt.getSource() == setLayerButton) {
            setLayer();
        }
        
        else if (evt.getSource() == addMapButton) {
            addLayer();
        }*/
        
        else if (evt.getSource() == addLayerButton) {
            addLayer();
        }
        
        else if (evt.getSource() == refreshButton) {
            mapView.refresh();
        }
    }
    
    public void addBuddy() {

⌨️ 快捷键说明

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