mirror of
https://github.com/anas-elgarhy/Ayah-intellij.git
synced 2024-08-15 00:43:43 +00:00
Create ayah details dialog 🥰
This commit is contained in:
parent
f178da091f
commit
7cda03f2db
4 changed files with 231 additions and 1 deletions
|
@ -2,6 +2,8 @@ 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.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;
|
||||||
|
@ -62,7 +64,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 AyahDetailsDialog(project, randomAyah).show();
|
new AyahDialog(randomAyah).setVisible(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
package com.anas.intellij.plugins.ayah.dialogs;
|
||||||
|
|
||||||
|
import com.anas.alqurancloudapi.Ayah;
|
||||||
|
import com.anas.intellij.plugins.ayah.settings.PanelBuilder;
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
|
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.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: <a href="https://github.com/anas-elgarhy">Anas Elgarhy</a>
|
||||||
|
* @date: 8/20/22
|
||||||
|
*/
|
||||||
|
public class AyahDetailsDialog extends DialogWrapper {
|
||||||
|
private final JBTextArea ayahTextArea;
|
||||||
|
private JBLabel surahNameLabel;
|
||||||
|
private JBLabel numberOfAyahInSurahLabel;
|
||||||
|
private JBLabel tanzelLabel;
|
||||||
|
private final JButton playButton;
|
||||||
|
|
||||||
|
{
|
||||||
|
ayahTextArea = new JBTextArea();
|
||||||
|
playButton = new JButton("Play");
|
||||||
|
}
|
||||||
|
public AyahDetailsDialog(final Project project, final Ayah ayah) {
|
||||||
|
super(project, false);
|
||||||
|
setTitle("Ayah Details");
|
||||||
|
initializeDataFiles(ayah);
|
||||||
|
setSize(500, 300);
|
||||||
|
setModal(false);
|
||||||
|
setOKButtonText("");
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initializeDataFiles(final Ayah ayah) {
|
||||||
|
ayahTextArea.setText(ayah.getText());
|
||||||
|
ayahTextArea.setEditable(false);
|
||||||
|
|
||||||
|
final var surah = ayah.getSurah();
|
||||||
|
surahNameLabel = new JBLabel(surah.getName());
|
||||||
|
tanzelLabel = new JBLabel(surah.getRevelationType().getArabicName() + " " + surah.getRevelationType().toString());
|
||||||
|
|
||||||
|
numberOfAyahInSurahLabel = new JBLabel("Number: " + ayah.getNumberInSurah());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected @Nullable JComponent createCenterPanel() {
|
||||||
|
return new PanelBuilder()
|
||||||
|
.setLayout(new MigLayout("fill"))
|
||||||
|
.addComponent(ayahTextArea, "grow, push, span")
|
||||||
|
.addComponent(surahNameLabel, "grow, push")
|
||||||
|
.addComponent(numberOfAyahInSurahLabel, "grow, push")
|
||||||
|
.addComponent(tanzelLabel, "grow, push, wrap")
|
||||||
|
.addComponent(playButton, "grow, push")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,112 @@
|
||||||
|
<?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">
|
||||||
|
<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"/>
|
||||||
|
<constraints>
|
||||||
|
<xy x="48" y="54" width="577" height="355"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<maximumSize width="500" height="300"/>
|
||||||
|
</properties>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<grid id="94766" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="0" row-span="1" col-span="3" vsize-policy="1" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<hspacer id="98af6">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
<grid id="9538f" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="true" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<component id="5723f" class="javax.swing.JButton" binding="buttonCancel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Cancel"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<component id="e7465" class="javax.swing.JButton" binding="playButton">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Play"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<grid id="e3588" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<hspacer id="22af1">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
</hspacer>
|
||||||
|
<scrollpane id="ac9ae">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<component id="47ef9" class="javax.swing.JTextArea" binding="ayahTextArea">
|
||||||
|
<constraints/>
|
||||||
|
<properties>
|
||||||
|
<editable value="false"/>
|
||||||
|
<lineWrap value="true"/>
|
||||||
|
<wrapStyleWord value="true"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</scrollpane>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<component id="5e7c2" class="javax.swing.JLabel" binding="surahNameLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="سُورَةُ الصَّافَّاتِ"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="d6a80" class="javax.swing.JLabel" binding="numberOfAyahInSuarhLabel">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="1"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="9e6a9" class="javax.swing.JLabel" binding="ayahRevelationType">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="مكية"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</form>
|
|
@ -0,0 +1,54 @@
|
||||||
|
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…
Reference in a new issue