[new] Implement the tafser and translation functonalty

This commit is contained in:
Anas Elgarhy 2023-05-25 22:52:35 +03:00
parent f183a2d5e3
commit 48de076872
No known key found for this signature in database
GPG key ID: 0501802A1D496528
2 changed files with 141 additions and 60 deletions

View file

@ -1,6 +1,6 @@
<?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.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="2" 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="836" height="472"/>
@ -13,12 +13,12 @@
<grid id="94766" layout-manager="GridLayoutManager" row-count="2" column-count="6" 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"/>
<grid row="1" 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>
<grid id="9538f" layout-manager="GridLayoutManager" row-count="2" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="9538f" layout-manager="GridLayoutManager" row-count="3" column-count="4" 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="6" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@ -60,25 +60,74 @@
</component>
</children>
</grid>
<component id="69418" class="javax.swing.JButton" binding="previousButton">
<grid id="e3ffd" layout-manager="GridLayoutManager" row-count="1" column-count="4" same-size-horizontally="false" same-size-vertically="true" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="1" column="0" row-span="1" col-span="4" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="true"/>
</constraints>
<properties>
<text value="Previous"/>
<toolTipText value="Previous Aah"/>
</properties>
</component>
<component id="b465c" class="javax.swing.JButton" binding="nextButton" default-binding="true">
<properties/>
<border type="none"/>
<children>
<component id="c14dc" class="javax.swing.JLabel">
<constraints>
<grid row="0" 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="Tafser/Translation"/>
<verifyInputWhenFocusTarget value="false"/>
</properties>
</component>
<component id="1bfe0" class="javax.swing.JComboBox" binding="tafserAndTranslationComboBox">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="82c3f" class="javax.swing.JLabel">
<constraints>
<grid row="0" 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="Edition"/>
</properties>
</component>
<component id="3ac9d" class="javax.swing.JComboBox" binding="editionComboBox">
<constraints>
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
</children>
</grid>
<grid id="d5ada" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="2" column="0" row-span="1" col-span="4" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<hideActionText value="true"/>
<text value="Next"/>
<toolTipText value="Nexit ayah"/>
</properties>
</component>
<properties/>
<border type="none"/>
<children>
<component id="b465c" class="javax.swing.JButton" binding="nextButton" default-binding="true">
<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>
<hideActionText value="true"/>
<text value="Next"/>
<toolTipText value="Nexit ayah"/>
</properties>
</component>
<component id="69418" class="javax.swing.JButton" binding="previousButton">
<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="Previous"/>
<toolTipText value="Previous Aah"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
<component id="893ab" class="javax.swing.JCheckBox" binding="autoPlayCheckBox" default-binding="true">
@ -158,44 +207,6 @@
</scrollpane>
</children>
</grid>
<grid id="e3ffd" layout-manager="GridLayoutManager" row-count="1" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" 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>
<component id="c14dc" class="javax.swing.JLabel">
<constraints>
<grid row="0" 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="Label"/>
</properties>
</component>
<component id="1bfe0" class="javax.swing.JComboBox" binding="comboBox1" default-binding="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="82c3f" class="javax.swing.JLabel">
<constraints>
<grid row="0" 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="Label"/>
</properties>
</component>
<component id="3ac9d" class="javax.swing.JComboBox" binding="comboBox2" default-binding="true">
<constraints>
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
</children>
</grid>
</children>
</grid>
</form>

View file

@ -2,14 +2,20 @@ package com.anas.intellij.plugins.ayah.dialogs;
import com.anas.alqurancloudapi.Ayah;
import com.anas.alqurancloudapi.consts.Constants;
import com.anas.alqurancloudapi.consts.Surahs;
import com.anas.alqurancloudapi.edition.Edition;
import com.anas.alqurancloudapi.edition.EditionType;
import com.anas.intellij.plugins.ayah.audio.AudioPlayer;
import com.anas.intellij.plugins.ayah.audio.PlayerListener;
import com.anas.intellij.plugins.ayah.settings.userinterface.ReadableEdition;
import javax.swing.*;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.util.Arrays;
import java.util.Objects;
/**
* @author <a href="https://github.com/anas-elgarhy">Anas Elgarhy</a>
@ -28,8 +34,8 @@ public class AyahDetailsDialog extends JDialog implements PlayerListener {
private JButton nextButton;
private JCheckBox autoPlayCheckBox;
private JTextArea tafserTextArea;
private JComboBox comboBox1;
private JComboBox comboBox2;
private JComboBox<ReadableEdition> tafserAndTranslationComboBox;
private JComboBox<ReadableEdition> editionComboBox;
private boolean isPlaying;
private AudioPlayer audioPlayer;
private Ayah ayah;
@ -40,20 +46,53 @@ public class AyahDetailsDialog extends JDialog implements PlayerListener {
setContentPane(contentPane);
setModal(true);
setSize(500, 300);
setResizable(false);
// setResizable(false);
setLocationRelativeTo(null);
getRootPane().setDefaultButton(playButton);
updateAhaDetails();
try {
setupTheUI();
} catch (final IOException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(this, "Error while loading the ayah details",
"Error", JOptionPane.ERROR_MESSAGE);
}
addListeners();
}
private void setupTheUI() throws IOException {
updateAhaDetails();
previousButton.setEnabled(ayah.getNumber() != 1 && ayah.getSurah().getNumber() != 1);
nextButton.setEnabled(ayah.getNumber() != Constants.AYAHS_COUNT && ayah.getSurah().getNumber() != Constants.SURAS_COUNT);
final var tafserAndTranslationComboBoxModel = new DefaultComboBoxModel<ReadableEdition>();
final var editionComboBoxModel = new DefaultComboBoxModel<ReadableEdition>();
Arrays.stream(Edition.getEditions()).forEach(edition -> {
if (edition.getType() == EditionType.TAFSIR || edition.getType() == EditionType.TRANSLATION) {
tafserAndTranslationComboBoxModel.addElement(new ReadableEdition(edition));
} else {
editionComboBoxModel.addElement(new ReadableEdition(edition));
}
});
tafserAndTranslationComboBox.setModel(tafserAndTranslationComboBoxModel);
editionComboBox.setModel(editionComboBoxModel);
// Set the default selected item for the editionComboBox
editionComboBoxModel.setSelectedItem(new ReadableEdition(ayah.getEdition()));
}
private void updateAhaDetails() {
// Update the ayah details
ayahTextArea.setText(ayah.getText());
surahNameLabel.setText(ayah.getSurah().getName());
numberOfAyahInSuarhLabel.setText("آية رقم: " + ayah.getNumberInSurah());
ayahRevelationType.setText(ayah.getSurah().getRevelationType().getArabicName());
// Update the tafser or translation
updateTheTauserTextArea();
}
private void addListeners() {
@ -94,6 +133,24 @@ public class AyahDetailsDialog extends JDialog implements PlayerListener {
}
});
tafserAndTranslationComboBox.addActionListener(e -> {
updateTheTauserTextArea();
});
editionComboBox.addActionListener(e -> {
final var selectedEdition = ((ReadableEdition) Objects.requireNonNull(
editionComboBox.getSelectedItem())).getEdition();
try {
ayah = Ayah.getAyah(ayah.getNumber(), selectedEdition);
updateAhaDetails();
} catch (final IOException ioException) {
ioException.printStackTrace();
JOptionPane.showMessageDialog(this,
"Error while loading the ayah - check your internet connection",
"Error", JOptionPane.ERROR_MESSAGE);
}
});
buttonCancel.addActionListener(l -> close());
// call onCancel() when cross is clicked
@ -110,6 +167,19 @@ public class AyahDetailsDialog extends JDialog implements PlayerListener {
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
}
private void updateTheTauserTextArea() {
final var selectedEdition = ((ReadableEdition) Objects.requireNonNull(
tafserAndTranslationComboBox.getSelectedItem())).getEdition();
try {
tafserTextArea.setText(Ayah.getAyah(ayah.getNumber(), selectedEdition).getText());
} catch (final IOException ioException) {
ioException.printStackTrace();
JOptionPane.showMessageDialog(this,
"Error while loading the tafser - check your internet connection",
"Error", JOptionPane.ERROR_MESSAGE);
}
}
private void close() {
if (audioPlayer != null) {
audioPlayer.stop();