📄 statusdialog.java
字号:
/* Copyright (C) 2003 Adam Olsen 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 1, 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. */package com.valhalla.jbother;import java.awt.*;import java.awt.event.*;import java.io.*;import java.util.*;import javax.swing.*;import com.valhalla.settings.*;import org.jivesoftware.smack.packet.Presence;/** * @author Anrdey Zakirov * @created April 12, 2005 * @version 0.2 * @since April 10, 2005 */public class StatusDialog extends JDialog{ private ResourceBundle resources = ResourceBundle.getBundle( "JBotherBundle", Locale.getDefault()); private JPanel main; private JButton okButton = new JButton(resources.getString("okButton")); private JButton changeNameButton = new JButton("Rename"); private JButton deleteButton = new JButton("Delete"); private JButton cancelButton = new JButton(resources.getString("cancelButton")); private JList statusList = new JList(); private StatusListModel model = new StatusListModel(); private JTextArea itemText = new JTextArea(5, 10); private JScrollPane itemScroll = new JScrollPane(itemText); private Presence.Mode mode = null; private StatusMessageProperties statusProps; private Hashtable modeHash = new Hashtable(); private String modeString; private String modeLocaleString; private String modeDescription; private JTextField priorityBox = new JTextField(5); /** *Constructor for the StatusDialog object * * @param mode Description of the Parameter */ public StatusDialog(Presence.Mode mode) { super(BuddyList.getInstance().getContainerFrame(), "", true); statusProps = new StatusMessageProperties(); statusList.setModel(model); this.mode = mode; main = (JPanel) getContentPane(); main.setBorder(BorderFactory.createTitledBorder(resources.getString("enterStatusMessage"))); String currentMessage = BuddyList.getInstance() .getCurrentStatusString(); GridBagLayout grid = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); main.setLayout(grid); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.gridy = 0; c.weighty = 0; c.weightx = 1.0; grid.setConstraints(statusList, c); modeString = mode.toString(); modeLocaleString = resources.getString(modeString); itemText.setWrapStyleWord( true ); itemText.setLineWrap( true ); modeDescription = resources.getString(modeString + ".description"); this.setTitle(resources.getString(mode.toString())); if(!statusProps.containsKey(modeString + "." + modeLocaleString)) { statusProps.put(modeString + "." + modeLocaleString, modeDescription); } StatusMessageProperties statusProps1 = (StatusMessageProperties) statusProps.clone(); String item = null; String key = null; String key2 = null; boolean justChecked = false; while(statusProps1.keys().hasMoreElements()) { item = null; key = (String) statusProps1.keys().nextElement(); item = (String) statusProps1.get(key); if(key.startsWith(mode.toString()) == true) { key2 = key.substring(modeString.length() + 1, key.length()); if(modeHash.containsKey(key2) == false) { model.addItem(key2); modeHash.put(key2, item); if(currentMessage.matches(item)) { justChecked = true; statusList.setSelectedValue(key2, true); itemText.setText(item); } } } statusProps1.remove(key); } if(!justChecked) { statusList.setSelectedIndex(0); itemText.setText((String) modeHash.get((String) statusList.getSelectedValue())); } JPanel status = new JPanel(); status.setLayout(new BorderLayout(5, 5)); status.add(new JScrollPane(statusList), BorderLayout.CENTER); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.Y_AXIS)); changeNameButton.setMaximumSize(new Dimension(100, 100)); deleteButton.setMaximumSize(new Dimension(100, 100)); buttonPanel.add(changeNameButton); buttonPanel.add(deleteButton); buttonPanel.add(Box.createVerticalGlue()); status.add(buttonPanel, BorderLayout.EAST); status.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); c.gridy++; grid.setConstraints(status, c); main.add(status); JPanel items = new JPanel(); items.setLayout(new BorderLayout()); JLabel newLabel = new JLabel(resources.getString("createNewStatusMessage")); newLabel.setBorder( BorderFactory.createEmptyBorder(0,0,5,0)); items.add(newLabel,BorderLayout.NORTH); items.add(itemScroll,BorderLayout.CENTER); items.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); c.gridy++; grid.setConstraints(items, c); main.add(items); JPanel buttons = new JPanel(); buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS)); buttons.add(Box.createHorizontalGlue()); buttons.add(okButton); buttons.add(cancelButton); buttons.add(Box.createHorizontalGlue()); buttons.setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5)); getRootPane().setDefaultButton(okButton); c.weightx = 0; c.fill = GridBagConstraints.NONE; String p = Settings.getInstance().getProperty("priority", "5"); JPanel priority = new JPanel(); priorityBox.setText(p); priority.setLayout( new BoxLayout(priority,BoxLayout.X_AXIS)); priority.add(Box.createHorizontalGlue()); priority.add(new JLabel(resources.getString("priority")+": ")); priority.add(priorityBox); priority.add(Box.createHorizontalGlue()); c.gridy++; grid.setConstraints(priority, c); main.add(priority); c.weightx = 1; c.gridy++; grid.setConstraints(buttons, c); main.add(buttons); addListeners(); pack(); setLocationRelativeTo(null); addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { cancelHandler(); } }); Dimension dim = getSize(); setSize(350, (int) dim.getHeight()); setResizable(false); setVisible(true); } /** * Adds a feature to the Listeners attribute of the StatusDialog object */ private void addListeners() { statusList.addMouseListener(new MouseClickListener()); okButton.addActionListener(new OKDialogListener()); cancelButton.addActionListener(new CancelDialogListener()); changeNameButton.addActionListener(new ChangeNameDialogListener()); deleteButton.addActionListener(new DeleteDialogListener()); } class MouseClickListener extends MouseAdapter { public void mouseClicked(MouseEvent e) { if( e.getClickCount() >= 2 ) okHandler(); else statusHandler(); } } /** * Description of the Class * * @author synic * @created April 12, 2005 */ class OKDialogListener implements ActionListener { /** * Description of the Method * * @param e Description of the Parameter */ public void actionPerformed(ActionEvent e) { okHandler(); } } /** * Description of the Class * * @author synic * @created April 12, 2005 */ class CancelDialogListener implements ActionListener { /** * Description of the Method * * @param e Description of the Parameter */ public void actionPerformed(ActionEvent e) { cancelHandler(); } } /** * Description of the Class * * @author synic * @created April 12, 2005 */ class DeleteDialogListener implements ActionListener { /** * Description of the Method * * @param e Description of the Parameter */ public void actionPerformed(ActionEvent e) { deleteHandler(); } } /** * Description of the Class * * @author synic * @created April 12, 2005 */ class ChangeNameDialogListener implements ActionListener { /** * Description of the Method * * @param e Description of the Parameter */ public void actionPerformed(ActionEvent e) { changeNameHandler();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -