List of usage examples for javax.sound.sampled LineListener LineListener
LineListener
From source file:Main.java
public static void main(String[] argv) throws Exception { DataLine.Info info = null;// w w w . j a v a2 s.com Clip clip = (Clip) AudioSystem.getLine(info); clip.addLineListener(new LineListener() { public void update(LineEvent evt) { if (evt.getType() == LineEvent.Type.STOP) { } } }); }
From source file:ClipTest.java
public static void main(String[] args) throws Exception { // specify the sound to play // (assuming the sound can be played by the audio system) File soundFile = new File("../sounds/voice.wav"); AudioInputStream sound = AudioSystem.getAudioInputStream(soundFile); // load the sound into memory (a Clip) DataLine.Info info = new DataLine.Info(Clip.class, sound.getFormat()); Clip clip = (Clip) AudioSystem.getLine(info); clip.open(sound);// w w w . java 2s. c om // due to bug in Java Sound, explicitly exit the VM when // the sound has stopped. clip.addLineListener(new LineListener() { public void update(LineEvent event) { if (event.getType() == LineEvent.Type.STOP) { event.getLine().close(); System.exit(0); } } }); // play the sound clip clip.start(); }
From source file:fr.ritaly.dungeonmaster.audio.SoundSystem.java
private void play(final double angle, final double distance, final AudioClip clip) { if (clip == null) { throw new IllegalArgumentException("The given audio clip is null"); }//ww w .j a v a2 s. co m if (!isInitialized()) { // On ne lve pas d'erreur pour les tests unitaires return; } if (log.isDebugEnabled()) { log.debug("Submitting new task ..."); } executorService.execute(new Runnable() { @Override public void run() { final Sound sound = sounds.get(clip.getSound()); if (sound == null) { throw new IllegalArgumentException("Unsupported sound <" + clip + ">"); } try { final Clip clip2 = (Clip) AudioSystem .getLine(new DataLine.Info(Clip.class, sound.getAudioFormat())); clip2.addLineListener(new LineListener() { @Override public void update(LineEvent event) { if (event.getType().equals(LineEvent.Type.STOP)) { clip2.close(); } } }); clip2.open(sound.getAudioFormat(), sound.getData(), 0, sound.getData().length); final DecimalFormat decimalFormat = new DecimalFormat("###.#"); // Pan dans [-1, +1] final FloatControl pan = (FloatControl) clip2.getControl(FloatControl.Type.PAN); if (!Double.isNaN(angle)) { final float p = (float) Math.sin(angle); if ((0 <= angle) && (angle <= Math.PI)) { // Son sur la gauche, pan positif pan.setValue(p); } else { // Son sur la droite, pan ngatif pan.setValue(p); } if (log.isDebugEnabled()) { log.debug("Angle = " + decimalFormat.format((angle / Math.PI) * 180) + " / Pan = " + decimalFormat.format(p * 100)); } } else { pan.setValue(0); } final double attenuation = Utils.attenuation(distance); if (log.isDebugEnabled()) { log.debug("Distance = " + distance + " / Attenuation = " + decimalFormat.format((attenuation * 100)) + "%"); } if (distance != 0) { // Gain dans [-30, 0] final FloatControl gain = (FloatControl) clip2.getControl(FloatControl.Type.MASTER_GAIN); gain.setValue((float) attenuation * -30); } clip2.loop(0); } catch (LineUnavailableException e) { throw new RuntimeException(e); } } }); if (log.isDebugEnabled()) { log.debug("Task submitted"); } }
From source file:io.github.jeremgamer.editor.panels.MusicFrame.java
public MusicFrame(JFrame frame, final GeneralSave gs) { ArrayList<BufferedImage> icons = new ArrayList<BufferedImage>(); try {/*from w w w.j a v a 2 s. co m*/ icons.add(ImageIO.read(ImageGetter.class.getResource("icon16.png"))); icons.add(ImageIO.read(ImageGetter.class.getResource("icon32.png"))); icons.add(ImageIO.read(ImageGetter.class.getResource("icon64.png"))); icons.add(ImageIO.read(ImageGetter.class.getResource("icon128.png"))); } catch (IOException e1) { e1.printStackTrace(); } this.setIconImages((List<? extends Image>) icons); this.setTitle("Musique"); this.setSize(new Dimension(300, 225)); this.addWindowListener(new WindowListener() { @Override public void windowActivated(WindowEvent event) { } @Override public void windowClosed(WindowEvent event) { } @Override public void windowClosing(WindowEvent event) { try { gs.save(new File("projects/" + Editor.getProjectName() + "/general.rbd")); } catch (IOException e) { e.printStackTrace(); } if (clip != null) { clip.stop(); clip.close(); try { audioStream.close(); } catch (IOException e) { e.printStackTrace(); } } } @Override public void windowDeactivated(WindowEvent event) { } @Override public void windowDeiconified(WindowEvent event) { } @Override public void windowIconified(WindowEvent event) { } @Override public void windowOpened(WindowEvent event) { } }); this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); content.setLayout(new BoxLayout(content, BoxLayout.PAGE_AXIS)); this.setModal(true); this.setLocationRelativeTo(frame); JPanel properties = new JPanel(); properties.setBorder(BorderFactory.createTitledBorder("Lecture")); ButtonGroup bg = new ButtonGroup(); bg.add(one); bg.add(loop); one.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { JRadioButton rb = (JRadioButton) event.getSource(); if (rb.isSelected()) { gs.set("music.reading", 0); try { gs.save(new File("projects/" + Editor.getProjectName() + "/general.rbd")); } catch (IOException e) { e.printStackTrace(); } if (clip != null) { if (clip.isRunning()) clip.loop(0); } } } }); loop.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { JRadioButton rb = (JRadioButton) event.getSource(); if (rb.isSelected()) { gs.set("music.reading", 1); try { gs.save(new File("projects/" + Editor.getProjectName() + "/general.rbd")); } catch (IOException e) { e.printStackTrace(); } if (clip != null) { if (clip.isRunning()) clip.loop(Clip.LOOP_CONTINUOUSLY); } } } }); properties.add(one); properties.add(loop); if (gs.getInt("music.reading") == 0) { one.setSelected(true); } else { loop.setSelected(true); } volume.setMaximum(100); volume.setMinimum(0); volume.setValue(30); volume.setPaintTicks(true); volume.setPaintLabels(true); volume.setMinorTickSpacing(10); volume.setMajorTickSpacing(20); volume.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent event) { JSlider slider = (JSlider) event.getSource(); double value = slider.getValue(); gain = value / 100; dB = (float) (Math.log(gain) / Math.log(10.0) * 20.0); if (clip != null) gainControl.setValue(dB); gs.set("music.volume", (int) value); } }); volume.setValue(gs.getInt("music.volume")); properties.add(volume); properties.setPreferredSize(new Dimension(300, 125)); content.add(properties); JPanel browsePanel = new JPanel(); browsePanel.setBorder(BorderFactory.createTitledBorder("")); JButton browse = new JButton("Parcourir..."); if (new File("projects/" + Editor.getProjectName() + "/music.wav").exists()) { preview.setEnabled(false); browse.setText(""); try { browse.setIcon(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); } catch (IOException e) { e.printStackTrace(); } } browse.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { JButton button = (JButton) event.getSource(); if (new File("projects/" + Editor.getProjectName() + "/music.wav").exists()) { if (clip != null) { clip.stop(); clip.close(); try { audioStream.close(); } catch (IOException e) { e.printStackTrace(); } } name.setText(""); preview.setEnabled(false); button.setText("Parcourir..."); button.setIcon(null); new File("projects/" + Editor.getProjectName() + "/music.wav").delete(); gs.set("music.name", ""); } else { String path = null; JFileChooser chooser = new JFileChooser(Editor.lastPath); FileNameExtensionFilter filter = new FileNameExtensionFilter("Audio (WAV)", "wav"); chooser.setFileFilter(filter); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int option = chooser.showOpenDialog(null); if (option == JFileChooser.APPROVE_OPTION) { path = chooser.getSelectedFile().getAbsolutePath(); Editor.lastPath = chooser.getSelectedFile().getParent(); copyMusic(new File(path)); button.setText(""); try { button.setIcon( new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); } catch (IOException e) { e.printStackTrace(); } gs.set("music.name", new File(path).getName()); try { gs.save(new File("projects/" + Editor.getProjectName() + "/general.rbd")); } catch (IOException e) { e.printStackTrace(); } name.setText(new File(path).getName()); preview.setEnabled(true); } } } }); if (new File("projects/" + Editor.getProjectName() + "/music.wav").exists()) { preview.setEnabled(true); } else { preview.setEnabled(false); } preview.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { JToggleButton tb = (JToggleButton) event.getSource(); if (tb.isSelected()) { try { audioStream = AudioSystem.getAudioInputStream( new File("projects/" + Editor.getProjectName() + "/music.wav")); format = audioStream.getFormat(); info = new DataLine.Info(Clip.class, format); clip = (Clip) AudioSystem.getLine(info); clip.open(audioStream); clip.start(); gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); gainControl.setValue(dB); if (loop.isSelected()) { clip.loop(Clip.LOOP_CONTINUOUSLY); } else { clip.loop(0); } clip.addLineListener(new LineListener() { @Override public void update(LineEvent event) { Clip clip = (Clip) event.getSource(); if (!clip.isRunning()) { preview.setSelected(false); clip.stop(); clip.close(); try { audioStream.close(); } catch (IOException e) { e.printStackTrace(); } } } }); } catch (Exception exc) { exc.printStackTrace(); } } else { clip.stop(); clip.close(); try { audioStream.close(); } catch (IOException e) { e.printStackTrace(); } } } }); JPanel buttons = new JPanel(); buttons.setLayout(new BorderLayout()); buttons.add(browse, BorderLayout.WEST); buttons.add(preview, BorderLayout.EAST); browsePanel.setLayout(new BorderLayout()); browsePanel.add(buttons, BorderLayout.NORTH); browsePanel.add(name, BorderLayout.SOUTH); name.setPreferredSize(new Dimension(280, 25)); name.setText(gs.getString("music.name")); content.add(browsePanel); this.setContentPane(content); this.setVisible(true); }
From source file:ca.sqlpower.dao.SPPersisterListener.java
/** * Does the actual commit when the transaction count reaches 0. This ensures * the persist calls are contained in a transaction if a lone change comes * through. This also allows us to roll back changes if an exception comes * from the server./*from w w w . j a va 2 s . c om*/ * * @throws SPPersistenceException */ private void commit() throws SPPersistenceException { logger.debug("commit(): transactionCount = " + transactionCount); if (transactionCount == 1) { try { logger.debug("Calling commit..."); //If nothing actually changed in the transaction do not send //the begin and commit to reduce server traffic. if (objectsToRemove.isEmpty() && persistedObjects.isEmpty() && persistedProperties.isEmpty()) return; target.begin(); commitRemovals(); commitObjects(); commitProperties(); target.commit(); logger.debug("...commit completed."); if (logger.isDebugEnabled()) { try { final Clip clip = AudioSystem.getClip(); clip.open(AudioSystem .getAudioInputStream(getClass().getResource("/sounds/transaction_complete.wav"))); clip.addLineListener(new LineListener() { public void update(LineEvent event) { if (event.getType().equals(LineEvent.Type.STOP)) { logger.debug("Stopping sound"); clip.close(); } } }); clip.start(); } catch (Exception ex) { logger.debug("A transaction committed but we cannot play the commit sound.", ex); } } } catch (Throwable t) { logger.warn("Rolling back due to " + t, t); this.rollback(); if (t instanceof SPPersistenceException) throw (SPPersistenceException) t; if (t instanceof FriendlyRuntimeSPPersistenceException) throw (FriendlyRuntimeSPPersistenceException) t; throw new SPPersistenceException(null, t); } finally { clear(); this.transactionCount = 0; } } else { transactionCount--; } }
From source file:org.yccheok.jstock.gui.Utils.java
public static void playAlertSound() { new Thread(new Runnable() { @Override// w w w . ja v a 2 s. c o m public void run() { try { Clip clip = AudioSystem.getClip(); clip.addLineListener(new LineListener() { @Override public void update(LineEvent event) { if (event.getType() == LineEvent.Type.STOP) { event.getLine().close(); } } }); final InputStream audioSrc = Utils.class.getResourceAsStream("/assets/sounds/doorbell.wav"); // http://stackoverflow.com/questions/5529754/java-io-ioexception-mark-reset-not-supported // Add buffer for mark/reset support. final InputStream bufferedIn = new BufferedInputStream(audioSrc); AudioInputStream inputStream = AudioSystem.getAudioInputStream(bufferedIn); clip.open(inputStream); clip.start(); } catch (Exception e) { log.error(null, e); } } }).start(); }
From source file:tvbrowser.extras.reminderplugin.ReminderPlugin.java
/** * Plays a sound.//ww w . j a v a 2 s.c o m * * @param fileName * The file name of the sound to play. * @return The sound Object. */ public static Object playSound(final String fileName) { try { if (StringUtils.endsWithIgnoreCase(fileName, ".mid")) { final Sequencer sequencer = MidiSystem.getSequencer(); sequencer.open(); final InputStream midiFile = new FileInputStream(fileName); sequencer.setSequence(MidiSystem.getSequence(midiFile)); sequencer.start(); new Thread("Reminder MIDI sequencer") { @Override public void run() { setPriority(Thread.MIN_PRIORITY); while (sequencer.isRunning()) { try { Thread.sleep(100); } catch (Exception ee) { // ignore } } try { sequencer.close(); midiFile.close(); } catch (Exception ee) { // ignore } } }.start(); return sequencer; } else { final AudioInputStream ais = AudioSystem.getAudioInputStream(new File(fileName)); final AudioFormat format = ais.getFormat(); final DataLine.Info info = new DataLine.Info(SourceDataLine.class, format); if (AudioSystem.isLineSupported(info)) { final SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info); line.open(format); line.start(); new Thread("Reminder audio playing") { private boolean stopped; @Override public void run() { byte[] myData = new byte[1024 * format.getFrameSize()]; int numBytesToRead = myData.length; int numBytesRead = 0; int total = 0; int totalToRead = (int) (format.getFrameSize() * ais.getFrameLength()); stopped = false; line.addLineListener(new LineListener() { public void update(LineEvent event) { if (line != null && !line.isRunning()) { stopped = true; line.close(); try { ais.close(); } catch (Exception ee) { // ignore } } } }); try { while (total < totalToRead && !stopped) { numBytesRead = ais.read(myData, 0, numBytesToRead); if (numBytesRead == -1) { break; } total += numBytesRead; line.write(myData, 0, numBytesRead); } } catch (Exception e) { } line.drain(); line.stop(); } }.start(); return line; } else { URL url = new File(fileName).toURI().toURL(); AudioClip clip = Applet.newAudioClip(url); clip.play(); } } } catch (Exception e) { e.printStackTrace(); if ((new File(fileName)).isFile()) { URL url; try { url = new File(fileName).toURI().toURL(); AudioClip clip = Applet.newAudioClip(url); clip.play(); } catch (MalformedURLException e1) { } } else { String msg = mLocalizer.msg("error.1", "Error loading reminder sound file!\n({0})", fileName); JOptionPane.showMessageDialog(UiUtilities.getBestDialogParent(MainFrame.getInstance()), msg, Localizer.getLocalization(Localizer.I18N_ERROR), JOptionPane.ERROR_MESSAGE); } } return null; }
From source file:tvbrowser.extras.reminderplugin.ReminderSettingsTab.java
/** * Creates the settings panel for this tab. *///from w w w . ja v a 2 s. c o m public JPanel createSettingsPanel() { FormLayout layout = new FormLayout("5dlu,pref,5dlu,pref,pref:grow,3dlu,pref,3dlu,pref,5dlu", "pref,5dlu,pref,1dlu,pref,1dlu,pref,1dlu,pref,10dlu,pref,5dlu," + "pref,10dlu,pref,5dlu,pref,10dlu,pref,5dlu,pref,10dlu," + "pref,5dlu,pref,3dlu,pref,10dlu,pref,5dlu,pref"); layout.setColumnGroups(new int[][] { { 7, 9 } }); PanelBuilder pb = new PanelBuilder(layout, new ScrollableJPanel()); pb.setDefaultDialogBorder(); CellConstraints cc = new CellConstraints(); final String[] extArr = { ".wav", ".aif", ".rmf", ".au", ".mid" }; String soundFName = mSettings.getProperty("soundfile", "/"); String msg = mLocalizer.msg("soundFileFilter", "Sound file ({0})", "*" + StringUtils.join(extArr, ", *")); mReminderWindowChB = new JCheckBox(mLocalizer.msg("reminderWindow", "Reminder window"), mSettings.getProperty("usemsgbox", "false").equalsIgnoreCase("true")); mShowAlwaysOnTop = new JCheckBox(mLocalizer.msg("alwaysOnTop", "Show always on top"), mSettings.getProperty("alwaysOnTop", "true").equalsIgnoreCase("true")); mShowAlwaysOnTop.setEnabled(mReminderWindowChB.isSelected()); JPanel reminderWindowCfg = new JPanel(new FormLayout("12dlu,default:grow", "pref,1dlu,pref")); reminderWindowCfg.add(mReminderWindowChB, cc.xyw(1, 1, 2)); reminderWindowCfg.add(mShowAlwaysOnTop, cc.xy(2, 3)); mSoundFileChB = new FileCheckBox(mLocalizer.msg("playlingSound", "Play sound"), new File(soundFName), 0, false); JFileChooser soundChooser = new JFileChooser((String) null); soundChooser.setFileFilter(new ExtensionFileFilter(extArr, msg)); mSoundFileChB.setFileChooser(soundChooser); mSoundFileChB.setSelected(mSettings.getProperty("usesound", "false").equals("true")); mBeep = new JCheckBox(mLocalizer.msg("beep", "Speaker sound"), mSettings.getProperty("usebeep", "true").equalsIgnoreCase("true")); mExecFileStr = mSettings.getProperty("execfile", ""); mExecParamStr = mSettings.getProperty("execparam", ""); final JButton soundTestBt = new JButton(mLocalizer.msg("test", "Test")); mExecChB = new JCheckBox(mLocalizer.msg("executeProgram", "Execute program")); mExecChB.setSelected(mSettings.getProperty("useexec", "false").equals("true")); mExecFileDialogBtn = new JButton(mLocalizer.msg("executeConfig", "Configure")); mExecFileDialogBtn.setEnabled(mExecChB.isSelected()); mPluginLabel = new JLabel(); JButton choose = new JButton(mLocalizer.msg("selectPlugins", "Choose Plugins")); mClientPluginTargets = ReminderPlugin.getInstance().getClientPluginsTargets(); handlePluginSelection(); choose.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { Window parent = UiUtilities.getLastModalChildOf(MainFrame.getInstance()); PluginChooserDlg chooser = null; chooser = new PluginChooserDlg(parent, mClientPluginTargets, null, ReminderPluginProxy.getInstance()); chooser.setLocationRelativeTo(parent); chooser.setVisible(true); if (chooser.getReceiveTargets() != null) { mClientPluginTargets = chooser.getReceiveTargets(); } handlePluginSelection(); } catch (Exception ee) { ee.printStackTrace(); } } }); int autoCloseReminderTime = 10; try { String asString = mSettings.getProperty("autoCloseReminderTime", "10"); autoCloseReminderTime = Integer.parseInt(asString); if (autoCloseReminderTime == 0) { autoCloseReminderTime = 10; } } catch (Exception exc) { // ignore } mCloseOnEnd = new JRadioButton(mLocalizer.msg("autoCloseReminderAtProgramEnd", "Program end"), mSettings.getProperty("autoCloseBehaviour", "onEnd").equals("onEnd")); mCloseOnEnd.setEnabled(mReminderWindowChB.isSelected()); mCloseNever = new JRadioButton(mLocalizer.msg("autoCloseNever", "Never close"), mSettings.getProperty("autoCloseBehaviour", "onEnd").equals("never")); mCloseNever.setEnabled(mReminderWindowChB.isSelected()); mCloseOnTime = new JRadioButton(mLocalizer.ellipsisMsg("autoCloseAfterTime", "After time"), mSettings.getProperty("autoCloseBehaviour", "onEnd").equals("onTime")); mCloseOnTime.setEnabled(mReminderWindowChB.isSelected()); ButtonGroup bg = new ButtonGroup(); bg.add(mCloseOnEnd); bg.add(mCloseNever); bg.add(mCloseOnTime); mAutoCloseReminderTimeSp = new JSpinner( new SpinnerNumberModel(autoCloseReminderTime, autoCloseReminderTime < 5 ? 1 : 5, 600, 1)); mAutoCloseReminderTimeSp.setEnabled(mCloseOnTime.isSelected() && mReminderWindowChB.isSelected()); mShowTimeCounter = new JCheckBox(mLocalizer.msg("showTimeCounter", "Show time counter"), mSettings.getProperty("showTimeCounter", "false").compareTo("true") == 0); mShowTimeCounter.setEnabled(!mCloseNever.isSelected() && mReminderWindowChB.isSelected()); PanelBuilder autoClosePanel = new PanelBuilder( new FormLayout("12dlu,default,2dlu,default:grow", "pref,2dlu,pref,2dlu,pref,2dlu,pref,10dlu,pref")); autoClosePanel.add(mCloseOnEnd, cc.xyw(1, 1, 4)); autoClosePanel.add(mCloseNever, cc.xyw(1, 3, 4)); autoClosePanel.add(mCloseOnTime, cc.xyw(1, 5, 4)); autoClosePanel.add(mAutoCloseReminderTimeSp, cc.xy(2, 7)); final JLabel secondsLabel = autoClosePanel.addLabel(mLocalizer.msg("seconds", "seconds (0 = off)"), cc.xy(4, 7)); autoClosePanel.add(mShowTimeCounter, cc.xyw(1, 9, 4)); secondsLabel.setEnabled(mCloseOnTime.isSelected() && mReminderWindowChB.isSelected()); String defaultReminderEntryStr = (String) mSettings.get("defaultReminderEntry"); mDefaultReminderEntryList = new JComboBox(ReminderDialog.SMALL_REMIND_MSG_ARR); if (defaultReminderEntryStr != null) { try { int inx = Integer.parseInt(defaultReminderEntryStr); if (inx < ReminderDialog.SMALL_REMIND_MSG_ARR.length) { mDefaultReminderEntryList.setSelectedIndex(inx); } } catch (NumberFormatException e) { // ignore } } mShowTimeSelectionDlg = new JCheckBox( mLocalizer.msg("showTimeSelectionDialog", "Show time selection dialog")); mShowTimeSelectionDlg .setSelected(mSettings.getProperty("showTimeSelectionDialog", "true").compareTo("true") == 0); mShowRemovedDlg = new JCheckBox( mLocalizer.msg("showRemovedDialog", "Show removed reminders after data update")); mShowRemovedDlg.setSelected(mSettings.getProperty("showRemovedDialog", "true").compareTo("true") == 0); pb.addSeparator(mLocalizer.msg("remindBy", "Remind me by"), cc.xyw(1, 1, 10)); pb.add(reminderWindowCfg, cc.xyw(2, 3, 4)); pb.add(mSoundFileChB, cc.xyw(2, 5, 4)); pb.add(mSoundFileChB.getButton(), cc.xy(7, 5)); pb.add(soundTestBt, cc.xy(9, 5)); pb.add(mBeep, cc.xy(2, 7)); pb.add(mExecChB, cc.xyw(2, 9, 4)); pb.add(mExecFileDialogBtn, cc.xyw(7, 9, 3)); pb.addSeparator(mLocalizer.msg("sendToPlugin", "Send reminded program to"), cc.xyw(1, 11, 10)); pb.add(mPluginLabel, cc.xyw(2, 13, 4)); pb.add(choose, cc.xyw(7, 13, 3)); final JLabel c = (JLabel) pb .addSeparator(mLocalizer.msg("autoCloseReminder", "Automatically close reminder"), cc.xyw(1, 15, 10)) .getComponent(0); c.setEnabled(mReminderWindowChB.isSelected()); pb.add(autoClosePanel.getPanel(), cc.xyw(2, 17, 5)); JPanel reminderEntry = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0)); reminderEntry.add(mDefaultReminderEntryList); pb.addSeparator(mLocalizer.msg("defaltReminderEntry", "Default reminder time"), cc.xyw(1, 19, 10)); pb.add(reminderEntry, cc.xyw(2, 21, 4)); pb.addSeparator(mLocalizer.msg("miscSettings", "Misc settings"), cc.xyw(1, 23, 10)); pb.add(mShowTimeSelectionDlg, cc.xyw(2, 25, 7)); pb.add(mShowRemovedDlg, cc.xyw(2, 27, 7)); pb.addSeparator(DefaultMarkingPrioritySelectionPanel.getTitle(), cc.xyw(1, 29, 10)); pb.add(mMarkingsPanel = DefaultMarkingPrioritySelectionPanel .createPanel(ReminderPlugin.getInstance().getMarkPriority(), false, false), cc.xyw(2, 31, 9)); mReminderWindowChB.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { mShowAlwaysOnTop.setEnabled(e.getStateChange() == ItemEvent.SELECTED); c.setEnabled(e.getStateChange() == ItemEvent.SELECTED); secondsLabel.setEnabled(e.getStateChange() == ItemEvent.SELECTED && mCloseOnTime.isSelected()); mCloseOnEnd.setEnabled(e.getStateChange() == ItemEvent.SELECTED); mCloseNever.setEnabled(e.getStateChange() == ItemEvent.SELECTED); mCloseOnTime.setEnabled(e.getStateChange() == ItemEvent.SELECTED); mShowTimeCounter.setEnabled(e.getStateChange() == ItemEvent.SELECTED && !mCloseNever.isSelected()); mAutoCloseReminderTimeSp .setEnabled(e.getStateChange() == ItemEvent.SELECTED && mCloseOnTime.isSelected()); } }); soundTestBt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (evt.getActionCommand().compareTo(mLocalizer.msg("test", "Test")) == 0) { mTestSound = ReminderPlugin.playSound(mSoundFileChB.getTextField().getText()); if (mTestSound != null) { soundTestBt.setText(mLocalizer.msg("stop", "Stop")); } if (mTestSound != null) { if (mTestSound instanceof SourceDataLine) { ((SourceDataLine) mTestSound).addLineListener(new LineListener() { public void update(LineEvent event) { if (event.getType() == Type.CLOSE) { soundTestBt.setText(mLocalizer.msg("test", "Test")); } } }); } else if (mTestSound instanceof Sequencer) { new Thread("Test MIDI sound") { public void run() { setPriority(Thread.MIN_PRIORITY); while (((Sequencer) mTestSound).isRunning()) { try { Thread.sleep(100); } catch (Exception ee) { } } soundTestBt.setText(mLocalizer.msg("test", "Test")); } }.start(); } } } else if (mTestSound != null) { if (mTestSound instanceof SourceDataLine && ((SourceDataLine) mTestSound).isRunning()) { ((SourceDataLine) mTestSound).stop(); } else if (mTestSound instanceof Sequencer && ((Sequencer) mTestSound).isRunning()) { ((Sequencer) mTestSound).stop(); } } } }); mSoundFileChB.getCheckBox().addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { soundTestBt.setEnabled(mSoundFileChB.isSelected()); } }); mSoundFileChB.getTextField().addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent e) { String text = mSoundFileChB.getTextField().getText(); if ((new File(text)).isFile()) { boolean notFound = true; for (String extension : extArr) { if (StringUtils.endsWithIgnoreCase(text, extension)) { notFound = false; break; } } if (notFound) { soundTestBt.setEnabled(false); } else { soundTestBt.setEnabled(true); } } else { soundTestBt.setEnabled(false); } } }); mSoundFileChB.getTextField().getKeyListeners()[0].keyReleased(null); mExecChB.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { mExecFileDialogBtn.setEnabled(mExecChB.isSelected()); if (mExecFileDialogBtn.isEnabled()) { showFileSettingsDialog(); } } }); mExecFileDialogBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { showFileSettingsDialog(); } }); ItemListener autoCloseListener = new ItemListener() { public void itemStateChanged(ItemEvent e) { mAutoCloseReminderTimeSp.setEnabled(mCloseOnTime.isSelected()); secondsLabel.setEnabled(mCloseOnTime.isSelected()); mShowTimeCounter.setEnabled(mCloseOnTime.isSelected() || mCloseOnEnd.isSelected()); } }; mCloseOnEnd.addItemListener(autoCloseListener); mCloseOnTime.addItemListener(autoCloseListener); mCloseOnTime.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { mShowTimeCounter.setEnabled(e.getStateChange() == ItemEvent.SELECTED); } }); JScrollPane scrollPane = new JScrollPane(pb.getPanel()); scrollPane.setBorder(null); scrollPane.setViewportBorder(null); JPanel scrollPanel = new JPanel(new FormLayout("default:grow", "default")); scrollPanel.add(scrollPane, cc.xy(1, 1)); return scrollPanel; }