📄 soundsettingspanel.java
字号:
package openicq.gui;import java.awt.BorderLayout;import java.awt.event.ActionEvent;import javax.swing.*;import javax.swing.border.Border;import openicq.Start;import openicq.data.Default;import openicq.data.Resource;import org.javalib.gui.SpringToolkit;import org.javalib.gui.model.SettingsDisplayPanel;import org.javalib.io.CryptFile;import org.javalib.io.CustomFileFilter;import org.javalib.util.TitledList;/** * The <code>SoundSettingsPanel</code> class contains a panel for the sound * settings. * @author Hansgeorg Schwibbe * @copyright 2004 */public class SoundSettingsPanel extends SettingsDisplayPanel{ private TitledList localized = SettingsDialog.localized; private JDialog parent; private JPanel globalPanel = new JPanel(); private JPanel localPanel = new JPanel(); protected JCheckBox jCheckBoxSoundsEnabled = new JCheckBox(); protected JCheckBox jCheckBoxStartupSound = new JCheckBox(); protected JTextField jTextFieldStartupSound = new JTextField(); protected JButton jButtonStartupSound = new JButton(); protected JCheckBox jCheckBoxIncomingSound = new JCheckBox(); protected JTextField jTextFieldIncomingSound = new JTextField(); protected JButton jButtonIncomingSound = new JButton(); protected JCheckBox jCheckBoxNotifySound = new JCheckBox(); protected JTextField jTextFieldNotifySound = new JTextField(); protected JButton jButtonNotifySound = new JButton(); protected JFileChooser soundFileChooser; protected CustomFileFilter soundFileFilter; /** * Initializes a new instance of the class <code>SoundSettingsPanel</code>. * @param parent the parent dialog */ public SoundSettingsPanel(JDialog parent) { Border innerBorder, outerBorder; String text, title, button; char shortkey; this.parent = parent; soundFileChooser = new JFileChooser(); title = ((String[]) localized.get("soundSettingsPanel"))[0]; soundFileChooser.setDialogTitle(title); button = ((String[]) localized.get("stdButtons"))[4]; soundFileChooser.setApproveButtonText(button); shortkey = ((char[]) localized.get("stdButtonsShortkeys"))[4]; soundFileChooser.setApproveButtonMnemonic(shortkey); text = ((String[]) localized.get("soundSettingsPanel"))[1]; soundFileFilter = new CustomFileFilter(text, new String[] { "wav" }); soundFileChooser.setFileFilter(soundFileFilter); text = ((String[]) localized.get("soundSettingsPanel"))[4]; jCheckBoxSoundsEnabled.setText(text); jCheckBoxSoundsEnabled.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { setComponentAccess(); } }); text = ((String[]) localized.get("soundSettingsPanel"))[5]; jCheckBoxStartupSound.setText(text); jCheckBoxStartupSound.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { setComponentAccess(); } }); text = ((String[]) localized.get("soundSettingsPanel"))[6]; jCheckBoxIncomingSound.setText(text); jCheckBoxIncomingSound.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { setComponentAccess(); } }); text = ((String[]) localized.get("soundSettingsPanel"))[7]; jCheckBoxNotifySound.setText(text); jCheckBoxNotifySound.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { setComponentAccess(); } }); text = ((String[]) localized.get("stdButtons"))[4]; jButtonStartupSound.setText(text); jButtonStartupSound.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { action_chooseStartupSound(); } }); text = ((String[]) localized.get("stdButtons"))[4]; jButtonIncomingSound.setText(text); jButtonIncomingSound.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { action_chooseIncomingUserSound(); } }); text = ((String[]) localized.get("stdButtons"))[4]; jButtonNotifySound.setText(text); jButtonNotifySound.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { action_chooseNotifySound(); } }); jTextFieldStartupSound.setEditable(false); jTextFieldIncomingSound.setEditable(false); jTextFieldNotifySound.setEditable(false); title = ((String[]) localized.get("soundSettingsPanel"))[2]; globalPanel.setBorder(BorderFactory.createTitledBorder(title)); globalPanel.setLayout(new SpringLayout()); globalPanel.add(jCheckBoxSoundsEnabled); SpringToolkit.makeCompactGrid(globalPanel, 1, 1, 5, 0, 5, 5); title = ((String[]) localized.get("soundSettingsPanel"))[3]; innerBorder = BorderFactory.createTitledBorder(title); outerBorder = BorderFactory.createEmptyBorder(0, 15, 47, 75); localPanel.setBorder(BorderFactory.createCompoundBorder(innerBorder, outerBorder)); localPanel.setLayout(new SpringLayout()); localPanel.add(jCheckBoxStartupSound); localPanel.add(jTextFieldStartupSound); localPanel.add(jButtonStartupSound); localPanel.add(jCheckBoxIncomingSound); localPanel.add(jTextFieldIncomingSound); localPanel.add(jButtonIncomingSound); localPanel.add(jCheckBoxNotifySound); localPanel.add(jTextFieldNotifySound); localPanel.add(jButtonNotifySound); SpringToolkit.makeCompactGrid(localPanel, 9, 1, 5, 0, 5, 5); setLayout(new BorderLayout()); innerBorder = BorderFactory.createLoweredBevelBorder(); outerBorder = BorderFactory.createEmptyBorder(10, 10, 10, 10); setBorder(BorderFactory.createCompoundBorder(innerBorder, outerBorder)); this.add(globalPanel, BorderLayout.NORTH); this.add(localPanel, BorderLayout.CENTER); } /** * Opens a new file chooser to choose the sound file for the incoming user * sound. */ private void action_chooseIncomingUserSound() { if (soundFileChooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) { this.jTextFieldIncomingSound.setText(soundFileChooser.getSelectedFile() .getAbsolutePath()); } } /** * Opens a new file chooser to choose the sound file for the notify sound. */ private void action_chooseNotifySound() { if (soundFileChooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) { this.jTextFieldNotifySound.setText(soundFileChooser.getSelectedFile() .getAbsolutePath()); } } /** * Opens a new file chooser to choose the sound file for the startup sound. */ private void action_chooseStartupSound() { if (soundFileChooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) { this.jTextFieldStartupSound.setText(soundFileChooser.getSelectedFile() .getAbsolutePath()); } } /** * (non-Javadoc) * @see org.javalib.gui.model.SettingsDisplayPanel#getContinueWithoutSavingMessage() */ public String getContinueWithoutSavingMessage() { return ((String[]) localized.get("warningMessages"))[0] + "\n" + ((String[]) localized.get("questionMessages"))[0]; } /** * (non-Javadoc) * @see org.javalib.gui.model.SettingsDisplayPanel#getContinueWithoutSavingTitle() */ public String getContinueWithoutSavingTitle() { return ((String[]) localized.get("messageTitles"))[2]; } /** * (non-Javadoc) * @see org.javalib.gui.model.SettingsDisplayPanel#getListIconPath() */ public String getListIconPath() { return Resource.ICON_SOURCE_SETTINGS[3]; } /** * (non-Javadoc) * @see org.javalib.gui.model.SettingsDisplayPanel#getListName() */ public String getListName() { return ((String[]) localized.get("settingsDialogList"))[3]; } /** * (non-Javadoc) * @see org.javalib.gui.model.SettingsDisplayPanel#getSaveButtonText() */ public String getSaveButtonText() { return ((String[]) localized.get("stdButtons"))[2] + " (" + ((String[]) localized.get("settingsDialogList"))[3] + ")"; } /** * (non-Javadoc) * @see org.javalib.gui.model.SettingsDisplayPanel#getSaveSettingsErrorTitle() */ public String getSaveSettingsErrorTitle() { return ((String[]) localized.get("messageTitles"))[0]; } /** * (non-Javadoc) * @see org.javalib.gui.model.SettingsDisplayPanel#hasChanged() */ public boolean hasChanged() { synchronized (Start.env) { if (Start.env.isSoundEnabled() != jCheckBoxSoundsEnabled.isSelected() || Start.env.getSoundFlags()[0] != jCheckBoxStartupSound.isSelected() || Start.env.getSoundFlags()[1] != jCheckBoxIncomingSound.isSelected() || Start.env.getSoundFlags()[2] != jCheckBoxNotifySound.isSelected() || !Start.env.getSoundFileNames()[0].equals(jTextFieldStartupSound.getText()) || !Start.env.getSoundFileNames()[1].equals(jTextFieldIncomingSound.getText()) || !Start.env.getSoundFileNames()[2].equals(jTextFieldNotifySound.getText())) { return true; } } return false; } /** * (non-Javadoc) * @see org.javalib.gui.model.SettingsDisplayPanel#loadSettings() */ public void loadSettings() { synchronized (Start.env) { this.jCheckBoxSoundsEnabled.setSelected(Start.env.isSoundEnabled()); this.jTextFieldStartupSound.setText(Start.env.getSoundFileNames()[0]); this.jCheckBoxStartupSound.setSelected(Start.env.getSoundFlags()[0]); this.jTextFieldIncomingSound.setText(Start.env.getSoundFileNames()[1]); this.jCheckBoxIncomingSound.setSelected(Start.env.getSoundFlags()[1]); this.jTextFieldNotifySound.setText(Start.env.getSoundFileNames()[2]); this.jCheckBoxNotifySound.setSelected(Start.env.getSoundFlags()[2]); this.setComponentAccess(); } } /** * (non-Javadoc) * @see org.javalib.gui.model.SettingsDisplayPanel#saveSettings() */ public void saveSettings() throws Exception { try { Object[] fileData = new Object[] { String.valueOf(this.jCheckBoxSoundsEnabled.isSelected()), String.valueOf(this.jCheckBoxStartupSound.isSelected()), String.valueOf(this.jCheckBoxIncomingSound.isSelected()), String.valueOf(this.jCheckBoxNotifySound.isSelected()), this.jTextFieldStartupSound.getText(), this.jTextFieldIncomingSound.getText(), this.jTextFieldNotifySound.getText() }; synchronized (Start.env) { String path = Default.FOLDER_NAME_HOME + "/" + Start.env.getOwnContact().getContactId() + "/" + Default.FILE_NAME_SOUND_DATA; CryptFile.write(path, fileData); Start.env.setSoundEnabled(this.jCheckBoxSoundsEnabled.isSelected()); boolean[] selected = new boolean[] { this.jCheckBoxStartupSound.isSelected(), this.jCheckBoxIncomingSound.isSelected(), this.jCheckBoxNotifySound.isSelected() }; String[] strings = new String[] { this.jTextFieldStartupSound.getText(), this.jTextFieldIncomingSound.getText(), this.jTextFieldNotifySound.getText() }; Start.env.setSoundFiles(strings, selected); } } catch (Exception ex) { String msg = ((String[]) localized.get("errorMessages"))[13]; throw new Exception(msg); } } /** * Sets the access to the components of this panel. */ void setComponentAccess() { if (!this.jCheckBoxSoundsEnabled.isSelected()) { this.jCheckBoxStartupSound.setEnabled(false); this.jCheckBoxIncomingSound.setEnabled(false); this.jCheckBoxNotifySound.setEnabled(false); this.jTextFieldStartupSound.setEnabled(false); this.jButtonStartupSound.setEnabled(false); this.jTextFieldIncomingSound.setEnabled(false); this.jButtonIncomingSound.setEnabled(false); this.jTextFieldNotifySound.setEnabled(false); this.jButtonNotifySound.setEnabled(false); } else { this.jCheckBoxStartupSound.setEnabled(true); this.jCheckBoxIncomingSound.setEnabled(true); this.jCheckBoxNotifySound.setEnabled(true); if (!this.jCheckBoxStartupSound.isSelected()) { this.jTextFieldStartupSound.setEnabled(false); this.jButtonStartupSound.setEnabled(false); } else { this.jTextFieldStartupSound.setEnabled(true); this.jButtonStartupSound.setEnabled(true); } if (!this.jCheckBoxIncomingSound.isSelected()) { this.jTextFieldIncomingSound.setEnabled(false); this.jButtonIncomingSound.setEnabled(false); } else { this.jTextFieldIncomingSound.setEnabled(true); this.jButtonIncomingSound.setEnabled(true); } if (!this.jCheckBoxNotifySound.isSelected()) { this.jTextFieldNotifySound.setEnabled(false); this.jButtonNotifySound.setEnabled(false); } else { this.jTextFieldNotifySound.setEnabled(true); this.jButtonNotifySound.setEnabled(true); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -