mirror of
https://github.com/anas-elgarhy/Ayah-intellij.git
synced 2024-08-15 00:43:43 +00:00
Improve the code yoooooo 🥰
This commit is contained in:
parent
7cda03f2db
commit
1fc6c282c8
4 changed files with 43 additions and 104 deletions
|
@ -3,7 +3,6 @@ package com.anas.intellij.plugins.ayah;
|
||||||
import com.anas.alqurancloudapi.Ayah;
|
import com.anas.alqurancloudapi.Ayah;
|
||||||
import com.anas.intellij.plugins.ayah.audio.AudioPlayer;
|
import com.anas.intellij.plugins.ayah.audio.AudioPlayer;
|
||||||
import com.anas.intellij.plugins.ayah.dialogs.AyahDetailsDialog;
|
import com.anas.intellij.plugins.ayah.dialogs.AyahDetailsDialog;
|
||||||
import com.anas.intellij.plugins.ayah.dialogs.AyahDialog;
|
|
||||||
import com.anas.intellij.plugins.ayah.settings.AyahSettingsState;
|
import com.anas.intellij.plugins.ayah.settings.AyahSettingsState;
|
||||||
import com.intellij.notification.Notification;
|
import com.intellij.notification.Notification;
|
||||||
import com.intellij.notification.NotificationType;
|
import com.intellij.notification.NotificationType;
|
||||||
|
@ -64,7 +63,7 @@ public class NotificationTimerTask extends TimerTask {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(@NotNull final AnActionEvent e) {
|
public void actionPerformed(@NotNull final AnActionEvent e) {
|
||||||
LOGGER.info("Details action performed");
|
LOGGER.info("Details action performed");
|
||||||
new AyahDialog(randomAyah).setVisible(true);
|
new AyahDetailsDialog(randomAyah).setVisible(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.anas.intellij.plugins.ayah.dialogs.AyahDialog">
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.anas.intellij.plugins.ayah.dialogs.AyahDetailsDialog">
|
||||||
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
<margin top="10" left="10" bottom="10" right="10"/>
|
<margin top="10" left="10" bottom="10" right="10"/>
|
||||||
<constraints>
|
<constraints>
|
|
@ -1,62 +1,56 @@
|
||||||
package com.anas.intellij.plugins.ayah.dialogs;
|
package com.anas.intellij.plugins.ayah.dialogs;
|
||||||
|
|
||||||
import com.anas.alqurancloudapi.Ayah;
|
import com.anas.alqurancloudapi.Ayah;
|
||||||
import com.anas.intellij.plugins.ayah.settings.PanelBuilder;
|
import com.anas.intellij.plugins.ayah.audio.AudioPlayer;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.anas.intellij.plugins.ayah.settings.AyahSettingsState;
|
||||||
import com.intellij.openapi.ui.DialogWrapper;
|
|
||||||
import com.intellij.ui.components.JBLabel;
|
|
||||||
import com.intellij.ui.components.JBTextArea;
|
|
||||||
import net.miginfocom.swing.MigLayout;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
import java.awt.event.WindowAdapter;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
|
||||||
/**
|
public class AyahDetailsDialog extends JDialog {
|
||||||
* @author: <a href="https://github.com/anas-elgarhy">Anas Elgarhy</a>
|
private JPanel contentPane;
|
||||||
* @date: 8/20/22
|
private JButton playButton;
|
||||||
*/
|
private JButton buttonCancel;
|
||||||
public class AyahDetailsDialog extends DialogWrapper {
|
private JTextArea ayahTextArea;
|
||||||
private final JBTextArea ayahTextArea;
|
private JLabel surahNameLabel;
|
||||||
private JBLabel surahNameLabel;
|
private JLabel numberOfAyahInSuarhLabel;
|
||||||
private JBLabel numberOfAyahInSurahLabel;
|
private JLabel ayahRevelationType;
|
||||||
private JBLabel tanzelLabel;
|
|
||||||
private final JButton playButton;
|
|
||||||
|
|
||||||
{
|
public AyahDetailsDialog(final Ayah ayah) {
|
||||||
ayahTextArea = new JBTextArea();
|
setContentPane(contentPane);
|
||||||
playButton = new JButton("Play");
|
setModal(true);
|
||||||
}
|
|
||||||
public AyahDetailsDialog(final Project project, final Ayah ayah) {
|
|
||||||
super(project, false);
|
|
||||||
setTitle("Ayah Details");
|
|
||||||
initializeDataFiles(ayah);
|
|
||||||
setSize(500, 300);
|
setSize(500, 300);
|
||||||
setModal(false);
|
setResizable(false);
|
||||||
setOKButtonText("");
|
setLocationRelativeTo(null);
|
||||||
init();
|
getRootPane().setDefaultButton(playButton);
|
||||||
}
|
|
||||||
|
|
||||||
private void initializeDataFiles(final Ayah ayah) {
|
|
||||||
ayahTextArea.setText(ayah.getText());
|
ayahTextArea.setText(ayah.getText());
|
||||||
ayahTextArea.setEditable(false);
|
surahNameLabel.setText(ayah.getSurah().getName());
|
||||||
|
numberOfAyahInSuarhLabel.setText("Number: " + ayah.getNumberInSurah());
|
||||||
final var surah = ayah.getSurah();
|
ayahRevelationType.setText(ayah.getSurah().getRevelationType().getArabicName());
|
||||||
surahNameLabel = new JBLabel(surah.getName());
|
|
||||||
tanzelLabel = new JBLabel(surah.getRevelationType().getArabicName() + " " + surah.getRevelationType().toString());
|
|
||||||
|
|
||||||
numberOfAyahInSurahLabel = new JBLabel("Number: " + ayah.getNumberInSurah());
|
|
||||||
|
|
||||||
|
addListeners(ayah);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void addListeners(final Ayah ayah) {
|
||||||
protected @Nullable JComponent createCenterPanel() {
|
playButton.addActionListener(e ->
|
||||||
return new PanelBuilder()
|
new AudioPlayer(AyahSettingsState.getInstance().getVolume(), ayah.getAudioUrl()).play());
|
||||||
.setLayout(new MigLayout("fill"))
|
|
||||||
.addComponent(ayahTextArea, "grow, push, span")
|
buttonCancel.addActionListener(l -> dispose());
|
||||||
.addComponent(surahNameLabel, "grow, push")
|
|
||||||
.addComponent(numberOfAyahInSurahLabel, "grow, push")
|
// call onCancel() when cross is clicked
|
||||||
.addComponent(tanzelLabel, "grow, push, wrap")
|
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
||||||
.addComponent(playButton, "grow, push")
|
addWindowListener(new WindowAdapter() {
|
||||||
.build();
|
public void windowClosing(WindowEvent e) {
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// call onCancel() on ESCAPE
|
||||||
|
contentPane.registerKeyboardAction(l -> dispose(),
|
||||||
|
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
|
||||||
|
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,54 +0,0 @@
|
||||||
package com.anas.intellij.plugins.ayah.dialogs;
|
|
||||||
|
|
||||||
import com.anas.alqurancloudapi.Ayah;
|
|
||||||
import com.anas.intellij.plugins.ayah.audio.AudioPlayer;
|
|
||||||
import com.anas.intellij.plugins.ayah.settings.AyahSettingsState;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.awt.event.*;
|
|
||||||
|
|
||||||
public class AyahDialog extends JDialog {
|
|
||||||
private JPanel contentPane;
|
|
||||||
private JButton playButton;
|
|
||||||
private JButton buttonCancel;
|
|
||||||
private JTextArea ayahTextArea;
|
|
||||||
private JLabel surahNameLabel;
|
|
||||||
private JLabel numberOfAyahInSuarhLabel;
|
|
||||||
private JLabel ayahRevelationType;
|
|
||||||
|
|
||||||
public AyahDialog(final Ayah ayah) {
|
|
||||||
setContentPane(contentPane);
|
|
||||||
setModal(true);
|
|
||||||
setSize(500, 300);
|
|
||||||
setResizable(false);
|
|
||||||
setLocationRelativeTo(null);
|
|
||||||
getRootPane().setDefaultButton(playButton);
|
|
||||||
|
|
||||||
ayahTextArea.setText(ayah.getText());
|
|
||||||
surahNameLabel.setText(ayah.getSurah().getName());
|
|
||||||
numberOfAyahInSuarhLabel.setText("Number: " + ayah.getNumberInSurah());
|
|
||||||
ayahRevelationType.setText(ayah.getSurah().getRevelationType().getArabicName());
|
|
||||||
|
|
||||||
addListeners(ayah);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addListeners(final Ayah ayah) {
|
|
||||||
playButton.addActionListener(e ->
|
|
||||||
new AudioPlayer(AyahSettingsState.getInstance().getVolume(), ayah.getAudioUrl()).play());
|
|
||||||
|
|
||||||
buttonCancel.addActionListener(l -> dispose());
|
|
||||||
|
|
||||||
// call onCancel() when cross is clicked
|
|
||||||
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
|
||||||
addWindowListener(new WindowAdapter() {
|
|
||||||
public void windowClosing(WindowEvent e) {
|
|
||||||
dispose();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// call onCancel() on ESCAPE
|
|
||||||
contentPane.registerKeyboardAction(l -> dispose(),
|
|
||||||
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
|
|
||||||
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue