2022-08-20 13:34:33 +00:00
|
|
|
package com.anas.intellij.plugins.ayah.dialogs;
|
|
|
|
|
|
|
|
import com.anas.alqurancloudapi.Ayah;
|
2022-08-20 13:40:14 +00:00
|
|
|
import com.anas.intellij.plugins.ayah.audio.AudioPlayer;
|
|
|
|
import com.anas.intellij.plugins.ayah.settings.AyahSettingsState;
|
2022-08-20 13:34:33 +00:00
|
|
|
|
|
|
|
import javax.swing.*;
|
2022-08-20 13:40:14 +00:00
|
|
|
import java.awt.event.KeyEvent;
|
|
|
|
import java.awt.event.WindowAdapter;
|
|
|
|
import java.awt.event.WindowEvent;
|
|
|
|
|
|
|
|
public class AyahDetailsDialog extends JDialog {
|
|
|
|
private JPanel contentPane;
|
|
|
|
private JButton playButton;
|
|
|
|
private JButton buttonCancel;
|
|
|
|
private JTextArea ayahTextArea;
|
|
|
|
private JLabel surahNameLabel;
|
|
|
|
private JLabel numberOfAyahInSuarhLabel;
|
|
|
|
private JLabel ayahRevelationType;
|
|
|
|
|
|
|
|
public AyahDetailsDialog(final Ayah ayah) {
|
|
|
|
setContentPane(contentPane);
|
|
|
|
setModal(true);
|
2022-08-20 13:34:33 +00:00
|
|
|
setSize(500, 300);
|
2022-08-20 13:40:14 +00:00
|
|
|
setResizable(false);
|
|
|
|
setLocationRelativeTo(null);
|
|
|
|
getRootPane().setDefaultButton(playButton);
|
2022-08-20 13:34:33 +00:00
|
|
|
|
|
|
|
ayahTextArea.setText(ayah.getText());
|
2022-08-20 13:40:14 +00:00
|
|
|
surahNameLabel.setText(ayah.getSurah().getName());
|
|
|
|
numberOfAyahInSuarhLabel.setText("Number: " + ayah.getNumberInSurah());
|
|
|
|
ayahRevelationType.setText(ayah.getSurah().getRevelationType().getArabicName());
|
2022-08-20 13:34:33 +00:00
|
|
|
|
2022-08-20 13:40:14 +00:00
|
|
|
addListeners(ayah);
|
|
|
|
}
|
2022-08-20 13:34:33 +00:00
|
|
|
|
2022-08-20 13:40:14 +00:00
|
|
|
private void addListeners(final Ayah ayah) {
|
|
|
|
playButton.addActionListener(e ->
|
2022-08-21 08:26:46 +00:00
|
|
|
new AudioPlayer(ayah.getAudioUrl()).play());
|
2022-08-20 13:34:33 +00:00
|
|
|
|
2022-08-20 13:40:14 +00:00
|
|
|
buttonCancel.addActionListener(l -> dispose());
|
|
|
|
|
|
|
|
// call onCancel() when cross is clicked
|
|
|
|
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
|
|
|
addWindowListener(new WindowAdapter() {
|
|
|
|
public void windowClosing(WindowEvent e) {
|
|
|
|
dispose();
|
|
|
|
}
|
|
|
|
});
|
2022-08-20 13:34:33 +00:00
|
|
|
|
2022-08-20 13:40:14 +00:00
|
|
|
// call onCancel() on ESCAPE
|
|
|
|
contentPane.registerKeyboardAction(l -> dispose(),
|
|
|
|
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
|
|
|
|
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
2022-08-20 13:34:33 +00:00
|
|
|
}
|
|
|
|
}
|