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

📄 bsmappubsubsaveconfirmdialog.java

📁 一款即时通讯软件
💻 JAVA
字号:
package edu.ou.kmi.buddyspace.plugins.maps.pubsub;

/*
 * BSMapPubsubSaveConfirmDialog.java
 *
 * Project: BuddySpace
 * (C) Copyright Knowledge Media Institute 2003
 *
 *
 * Created on 27 October 2003, 11:15
 */

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import java.beans.*; // Property change stuff
import java.util.*;

import org.jabber.jabberbeans.Extension.*;
import org.jabber.jabberbeans.util.*;

import edu.ou.kmi.buddyspace.gui.*;
import edu.ou.kmi.buddyspace.core.*;

import edu.ou.kmi.buddyspace.plugins.maps.xml.*;

/**
 * <code>BSMapPubsubSaveConfirmDialog</code> confirms which received pubsub
 * items should be saved.
 *
 * @author  Jiri Komzak, Knowledge Media Institute, Open University, United Kingdom
 */

public class BSMapPubsubSaveConfirmDialog extends JDialog {
    private JOptionPane optionPane;
    public Vector maps = null;
    public Vector oobs = null;
    public boolean selectedMaps[] = null;
    public boolean selectedOobs[] = null;
    
    /** Constructor */
    BSMapPubsubSaveConfirmDialog(Frame _parent, JID fromJID, String node, Vector _maps, Vector _oobs) {
        super(_parent, "Save pubsub maps", true);
        
        final Frame parent = _parent;
        maps = _maps;
        oobs = _oobs;
        
        String shortName = null;
        if (node != null && !"".equals(node)) {
            /*int lastSlashIndex = node.lastIndexOf('/');
            shortName = node.substring(lastSlashIndex+1);*/
            shortName = node;
        }
        else {
            shortName = (fromJID != null)? fromJID.toString() : "unknown";
        }
        //JLabel label = new JLabel("New images or maps have been published in .../" + shortName);
        JLabel label = new JLabel("New images or maps have been published in #" + shortName);
        JButton infoButton = new JButton("Help");
        final JID _fromJID = fromJID;
        final String _node = node;
        infoButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(BSMapPubsubSaveConfirmDialog.this, 
                      "The displayed images and maps have been published\n" +
                      ((_fromJID != null)? "on " + _fromJID.toString() : "") +
                      ((_node != null)? "\nin node " + _node : "") + ".\n\n" +
                      "Selected item(s) will be stored in the map directory\n" +
                      "and used the next time the relevant map is shown.",
                      "Details", 
                      JOptionPane.INFORMATION_MESSAGE);
            }
        });
        JPanel panel = new JPanel();
        panel.add(label);
        panel.add(new JPanel());
        panel.add(infoButton);
        
        if (_maps.size() > 0) {
            selectedMaps = new boolean[_maps.size()];
            for (int i=0; i<_maps.size(); i++) selectedMaps[i] = true;
        }
        final JList mapList = new JList(_maps);
        mapList.setCellRenderer(new BSMapPubsubSaveListCellRenderer());
        mapList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        mapList.addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                //Ignore extra messages.
                if (e.getValueIsAdjusting()) return;
                JList list = (JList)e.getSource();
                if (!list.isSelectionEmpty()) {
                    //selectedRow is selected
                    int selectedRow = list.getMinSelectionIndex();
                    list.clearSelection();
                    selectedMaps[selectedRow] = !selectedMaps[selectedRow];
                    mapList.invalidate();
                }
            }
        });
        JScrollPane mapListScrollPane = new JScrollPane(mapList);
        mapListScrollPane.setPreferredSize(new Dimension(250, 80));
        
        if (_oobs.size() > 0) {
            selectedOobs = new boolean[oobs.size()];
            for (int i=0; i<oobs.size(); i++) selectedOobs[i] = true;
        }
        final JList oobList = new JList(oobs);
        oobList.setCellRenderer(new BSMapPubsubSaveListCellRenderer());
        oobList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        oobList.addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                //Ignore extra messages.
                if (e.getValueIsAdjusting()) return;
                JList list = (JList)e.getSource();
                if (!list.isSelectionEmpty()) {
                    //selectedRow is selected
                    int selectedRow = list.getMinSelectionIndex();
                    list.clearSelection();
                    selectedOobs[selectedRow] = !selectedOobs[selectedRow];
                    oobList.invalidate();
                }
            }
        });
        JScrollPane oobListScrollPane = new JScrollPane(oobList);
        oobListScrollPane.setPreferredSize(new Dimension(250, 80));
        
        JLabel label2 = new JLabel("Selected item(s) will be used the next time"+
                                   " the relevant map is shown.");
        
        int fieldNum = 2 + ((_maps.size() > 0)? 2 : 0) + ((_oobs.size() > 0)? 2 : 0);
        Object[] fields = new Object[fieldNum];
        int i = 0;
        fields[i++] = panel;
        if (_maps.size() > 0) {
            fields[i++] = "Map files: ";
            fields[i++] = mapListScrollPane;
        }
        if (_oobs.size() > 0) {
            fields[i++] = "Other files: ";
            fields[i++] = oobListScrollPane;
        }
        fields[i++] = label2;
        /*Object[] fields = {label,
                           "Map files: ", mapListScrollPane,
                           "OOB files: ", oobListScrollPane,
                           label2};*/
        
        final String okButton = "Save Selected Images/Maps";
        final String cancelButton = "Cancel without saving anything";
        Object[] options = {okButton, cancelButton};

        optionPane = new JOptionPane(fields, 
                                     JOptionPane.PLAIN_MESSAGE,
                                     JOptionPane.OK_CANCEL_OPTION,
                                     null,
                                     options,
                                     options[0]);
        setContentPane(optionPane);
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);

        pack();
        setLocationRelativeTo(parent);
        
        // handles actions
        optionPane.addPropertyChangeListener(new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent e) {
                String prop = e.getPropertyName();
			
                if (isVisible() 
                    && (e.getSource() == optionPane)
                    && (prop.equals(JOptionPane.VALUE_PROPERTY) ||
                      prop.equals(JOptionPane.INPUT_VALUE_PROPERTY))) {
                    Object value = optionPane.getValue();

                    if (value == JOptionPane.UNINITIALIZED_VALUE) {
                        // ignore reset
                        return;
                    }

                    // Reset the JOptionPane's value.
                    // If you don't do this, then if the user
                    // presses the same button next time, no
                    // property change event will be fired.
                    optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);

                    if (value.equals(okButton)) {
                        if (maps != null) {
                            Vector tmpMaps = maps;
                            maps = new Vector();
                            for (int i=0; i<tmpMaps.size(); i++)
                                if (selectedMaps[i]) maps.add(tmpMaps.elementAt(i));
                        }
                        if (oobs != null) {
                            Vector tmpOobs = oobs;
                            oobs = new Vector();
                            for (int i=0; i<tmpOobs.size(); i++)
                                if (selectedOobs[i]) oobs.add(tmpOobs.elementAt(i));
                        }
                        setVisible(false);
                        return;
                    }
                    else if (value.equals(cancelButton)) {
                        maps = null;
                        oobs = null;
                        setVisible(false);
                    }
                }
            }
        });
    }
    
    
    public class BSMapPubsubSaveListCellRenderer extends JCheckBox 
                                   implements ListCellRenderer {
                                       
        protected Border noFocusBorder;

        /**
         * Constructor.
         */
        public BSMapPubsubSaveListCellRenderer() {
            super();
            if (noFocusBorder == null) {
                noFocusBorder = new EmptyBorder(1, 1, 1, 1);
            }
            setOpaque(true);
            setBorder(noFocusBorder);
        }
    
        public Component getListCellRendererComponent(
                JList list,
                Object value,            // value to display
                int index,               // cell index
                boolean isSelected,      // is the cell selected
                boolean cellHasFocus) {  // the list and the cell have the focus
        
            setComponentOrientation(list.getComponentOrientation());
            /*if (isSelected) {
                setBackground(list.getSelectionBackground());
                setForeground(list.getSelectionForeground());
            }
            else {*/
                setBackground(list.getBackground());
                setForeground(list.getForeground());
            //}

            if (value instanceof MapTag) {
                setText(((MapTag)value).getID());
                setSelected(selectedMaps[maps.indexOf(value)]);
            }
            else if (value instanceof OOB) {
                setText(((OOB)value).getDescription());
                setSelected(selectedOobs[oobs.indexOf(value)]);
            }
            
            setEnabled(list.isEnabled());
            setFont(list.getFont());
            setBorder((cellHasFocus) ? UIManager.getBorder("List.focusCellHighlightBorder") : noFocusBorder);
            
            return this;
        }
    }
}

⌨️ 快捷键说明

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