Skip to content

Commit

Permalink
Add chapter name/link list window
Browse files Browse the repository at this point in the history
  • Loading branch information
Flameish committed May 21, 2020
1 parent c27a550 commit 4860ff7
Show file tree
Hide file tree
Showing 2 changed files with 223 additions and 0 deletions.
115 changes: 115 additions & 0 deletions src/gui/editChapterList.form
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="gui.editChapterList">
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="2" column-count="19" 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="741" height="521"/>
</constraints>
<properties>
<preferredSize width="750" height="500"/>
</properties>
<border type="none"/>
<children>
<scrollpane id="15503">
<constraints>
<grid row="0" column="0" row-span="1" col-span="19" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<verifyInputWhenFocusTarget value="false"/>
</properties>
<border type="none"/>
<children>
<grid id="278b8" layout-manager="GridLayoutManager" row-count="2" 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/>
<properties>
<verifyInputWhenFocusTarget value="true"/>
</properties>
<border type="none"/>
<children>
<component id="a6d4d" class="javax.swing.JLabel" binding="chapterNamesAreaLbl">
<constraints>
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Chapter names:"/>
</properties>
</component>
<component id="bd45e" class="javax.swing.JLabel" binding="chapterLinksAreaLbl">
<constraints>
<grid row="0" column="2" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Chapter links:"/>
</properties>
</component>
<scrollpane id="3908e">
<constraints>
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<verticalScrollBarPolicy value="20"/>
</properties>
<border type="none"/>
<children>
<component id="fb69e" class="javax.swing.JTextArea" binding="chapterNamesArea" custom-create="true">
<constraints/>
<properties>
<margin top="0" left="0" bottom="0" right="0"/>
</properties>
</component>
</children>
</scrollpane>
<scrollpane id="debe1">
<constraints>
<grid row="1" column="2" row-span="1" col-span="2" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="f9ca5" class="javax.swing.JTextArea" binding="chapterLinksArea" custom-create="true">
<constraints/>
<properties>
<margin top="0" left="0" bottom="0" right="0"/>
</properties>
</component>
</children>
</scrollpane>
</children>
</grid>
</children>
</scrollpane>
<hspacer id="61ec6">
<constraints>
<grid row="1" column="0" row-span="1" col-span="5" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<grid id="d411" 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="5" row-span="1" col-span="14" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="90614" class="javax.swing.JButton" binding="buttonSave">
<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="Save"/>
</properties>
</component>
<component id="1b7b9" class="javax.swing.JButton" binding="buttonClose">
<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="Close"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
</form>
108 changes: 108 additions & 0 deletions src/gui/editChapterList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package gui;

import grabber.Chapter;

import javax.swing.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class editChapterList extends JDialog {
private JPanel contentPane;
private JLabel chapterNamesAreaLbl;
private JLabel chapterLinksAreaLbl;
private JButton buttonSave;
private JButton buttonClose;
private JTextArea chapterNamesArea;
private JTextArea chapterLinksArea;
private static String currWindow;

public editChapterList() {
ImageIcon favicon = new ImageIcon(getClass().getResource("/files/images/favicon.png"));
setIconImage(favicon.getImage());
setContentPane(contentPane);
setModal(true);

buttonSave.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
// Remove empty lines from textAreas
chapterNamesArea.setText(chapterNamesArea.getText().replaceAll("(?m)^\\s+$", ""));
chapterLinksArea.setText(chapterLinksArea.getText().replaceAll("(?m)^\\s+$", ""));
List<String> chapterNames = new ArrayList<>(Arrays.asList(chapterNamesArea.getText().split("\\n")));
List<String> chapterLinks = new ArrayList<>(Arrays.asList(chapterLinksArea.getText().split("\\n")));
if(chapterNames.size() == chapterLinks.size()) {
if(currWindow.equals("auto")) {
autoChapterOrder.chapterListModel.clear();
for(int i = 0; i < chapterNames.size(); i++) {
autoChapterOrder.chapterListModel.addElement(new Chapter(chapterNames.get(i), chapterLinks.get(i)));
}
}
else {
GUI.manLinkListModel.clear();
for(int i = 0; i < chapterNames.size(); i++) {
GUI.manLinkListModel.addElement(new Chapter(chapterNames.get(i), chapterLinks.get(i)));
}
}
dispose();
} else {
JOptionPane.showMessageDialog(contentPane, "Lists are not the same length.", "Warning", JOptionPane.WARNING_MESSAGE);
}
}
});

buttonClose.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
onCancel();
}
});

// call onCancel() when cross is clicked
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
onCancel();
}
});

// call onCancel() on ESCAPE
contentPane.registerKeyboardAction(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onCancel();
}
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
}

private void onCancel() {
dispose();
}

public static void main(String window) {
currWindow = window;
editChapterList dialog = new editChapterList();
dialog.setTitle("Edit chapter list");
dialog.pack();
dialog.setLocationRelativeTo(null);
dialog.setVisible(true);
}

private void createUIComponents() {
chapterNamesArea = new JTextArea();
chapterLinksArea = new JTextArea();

if(currWindow.equals("auto")) {
for(int i = 0; i < autoChapterOrder.chapterListModel.size(); i++) {
chapterNamesArea.append(autoChapterOrder.chapterListModel.get(i).name + "\n");
chapterLinksArea.append(autoChapterOrder.chapterListModel.get(i).chapterURL + "\n");
}
} else {
for(int i = 0; i < GUI.manLinkListModel.size(); i++) {
chapterNamesArea.append(GUI.manLinkListModel.get(i).name + "\n");
chapterLinksArea.append(GUI.manLinkListModel.get(i).chapterURL + "\n");
}
}

}
}

0 comments on commit 4860ff7

Please sign in to comment.