Code Sketch
Bixuu
Category: Programming
import java.awt.{BorderLayout, Color, Dimension, FlowLayout, Font, GridLayout, Insets}
import java.awt.event.{ActionEvent, ActionListener}
import java.io.{File, PrintWriter}
import java.nio.charset.StandardCharsets
import java.nio.file.Files
import javax.swing._
import javax.swing.border.EmptyBorder
import javax.swing.event.{DocumentEvent, DocumentListener, ListSelectionEvent, ListSelectionListener}
import javax.swing.filechooser.FileNameExtensionFilter
import scala.collection.mutable.ArrayBuffer
import scala.io.Source
object BixuuStoryLibraryUltra {
case class Chapter(title: String, body: String)
case class StoryPart(title: String, partLabel: String, chapters: Vector[Chapter], guideOnly: Boolean)
private def ch(title: String, body: String): Chapter = Chapter(title, body)
private def part(title: String, label: String, guideOnly: Boolean, chapters: Chapter*): StoryPart =
StoryPart(title, label, chapters.toVector, guideOnly)
// Roman Hindi display helper: English words and punctuation remain unchanged.
private val romanConsonants: Map[Char, String] = Map(
'?' -> "k", '?' -> "kh", '?' -> "g", '?' -> "gh", '?' -> "ng",
'?' -> "ch", '?' -> "chh", '?' -> "j", '?' -> "jh", '?' -> "ny",
'?' -> "t", '?' -> "th", '?' -> "d", '?' -> "dh", '?' -> "n",
'?' -> "t", '?' -> "th", '?' -> "d", '?' -> "dh", '?' -> "n",
'?' -> "p", '?' -> "ph", '?' -> "b", '?' -> "bh", '?' -> "m",
'?' -> "y", '?' -> "r", '?' -> "l", '?' -> "v", '?' -> "sh",
'?' -> "sh", '?' -> "s", '?' -> "h", '?' -> "l"
)
private val romanIndependentVowels: Map[Char, String] = Map(
'?' -> "a", '?' -> "aa", '?' -> "i", '?' -> "ee", '?' -> "u",
'?' -> "oo", '?' -> "ri", '?' -> "e", '?' -> "ai", '?' -> "o", '?' -> "au"
)
private val romanMatras: Map[Char, String] = Map(
'?' -> "aa", '?' -> "i", '?' -> "ee", '?' -> "u", '?' -> "oo",
'?' -> "ri", '?' -> "e", '?' -> "ai", '?' -> "o", '?' -> "au"
)
private def toHinglish(input: String): String = {
val out = new java.lang.StringBuilder
var i = 0
var lastInherentA = -1
while (i < input.length) {
val c = input.charAt(i)
if (romanConsonants.contains(c)) {
out.append(romanConsonants(c))
if (i + 1 < input.length && romanMatras.contains(input.charAt(i + 1))) {
out.append(romanMatras(input.charAt(i + 1)))
i += 1
lastInherentA = -1
} else if (i + 1 < input.length && input.charAt(i + 1) == '?') {
i += 1
lastInherentA = -1
} else {
out.append('a')
lastInherentA = out.length - 1
}
} else if (romanIndependentVowels.contains(c)) {
out.append(romanIndependentVowels(c))
lastInherentA = -1
} else {
c match {
case '?' | '?' => out.append('n'); lastInherentA = -1
case '?' => out.append('h'); lastInherentA = -1
case '?' => ()
case '?' =>
if (lastInherentA == out.length - 1 && lastInherentA >= 0) out.deleteCharAt(lastInherentA)
out.append('.')
lastInherentA = -1
case d if d >= '?' && d <= '?' =>
out.append(('0' + (d - '?')).toChar)
lastInherentA = -1
case ch if Character.isWhitespace(ch) || ch == '.' || ch == ',' || ch == ';' || ch == ':' || ch == '!' || ch == '?' || ch == '(' || ch == ')' || ch == '-' || ch == '\'' || ch == '"' =>
if (lastInherentA == out.length - 1 && lastInherentA >= 0) out.deleteCharAt(lastInherentA)
out.append(ch)
lastInherentA = -1
case other => out.append(other); lastInherentA = -1
}
}
i += 1
}
if (lastInherentA == out.length - 1 && lastInherentA >= 0) out.deleteCharAt(lastInherentA)
out.toString
}
private val storyCatalog: Vector[StoryPart] = Vector(
part("BIXUU HARRY POTTER", "PART 1", true,
ch("????? ?????? ?? ?????", "?? Harry Potter ???????? ?? ?? ???? ?????? reading guide ??, ??? ??????? ?? ??? ?? ?????? ????? ?? ??? ?? ????? ?????? ?? ??? ????? ?? ?????? ?? ???? ??? ???? ?? ?? ?????? ??? ???? ?? ?? ??? ?????? ?? ????? ??? ????? ?? ?????? ?????? ??? ??????, ?????, ???? ?? ???? ????? ????? ???? ???? ??? ????\n\n????? ??? ????? ??? ?? fantasy ????? ??? ??? ?? ?????? ??? ?? ??????? ??? ???? ???"),
ch("?????? ?? ???", "?? guide ??? ?????? ?? ????? ?? ?????????? ???? ???? ??? ??? ????? ???? ??????? ??? ??? ??-????? ?? ??? ????? ???, ??????? ?? ????? ??? ?? ????? ???????? ?? ????? ???? ???? ????? ????? ?? ?????? ???? ?? ?? ????, ????, ????? ?? ????????????? ????? ?? ???? ???? ???\n\n?? ??? ?????? ?? ??????? ?? ??????? ????? ????, ????? ???? ?????? ??????? ?? ????????? ????? ???"),
ch("??? 1 ?? ????? ???? ?????", "?????, ?????, ????? ?? ???? ?? fantasy guide ?? ????? ????? ???? ???? ?? ?? ?????? ??? ?????? ???? ??? ???? ?????, ???? ????? ?? ?????? ?? ????? ????? ???? ?????? ???? ???\n\n???? ????? ????? ?? ??? ???? ??? ????? ?? TXT ??? IMPORT MY TXT ??? ?? ?????? Reader chapter headings ?? ??????? ???-??? ?????? ????????")),
part("BIXUU HARRY POTTER", "PART 2", true,
ch("????? ?? ?????", "?? ??? 2 ?? ??? ????????? ?????? guide ??, ??? Harry Potter ?????? ?? chapter text ????? ?? ???? ?? fantasy ????? ??? ?????? ?????, ?????? ?????? ?? ????? ?? ??????? ???? ????? ?????????? ???? ???? ???? ?? ??????? ?? ????? ???? ?? ???????? ??? ???????? ? ??????? ????? ?? ????? ???"),
ch("???? ????? ?? ????", "?????-??? ??? ??? ???? ????? ???? ????? ??? ??? ????? ???? ??? ???? ??, ????? ???? ???? ?????? ?? ???? ????? ?? ?????? ???? ?? ???? ??? ????? ????? ????? ?? ???-??? ????????? ?? ????? ???? ?? ???? ????"),
ch("????? ?????", "?? guide ?? ?????? ????????, ?????????? ?? ??????? ??? ?? ??? ????? ?? ?????? ???? ??? ???? ?????? ????? ?? ???? ?????? ????? ?? ??? TXT ???? ????; ?? ???? ??? ??? ???? ?? ?? ?? ???? ???")),
part("BIXUU HARRY POTTER", "PART 3", true,
ch("???? ?? ???????", "?? ??? 3 ?? ???? reading guide ??? fantasy ???????? ??? ???? ?? ??????? ??????? ?? ????? ??? ??? ?? ???? ??? ??????, ?????? ????? ?? ????? ???? ???? ????? ?? ??? ?? ???????? ???? ????"),
ch("?????? ?? ???", "???? ????? ?? ????? ?? ??? ????? ?? ?????? ??? ???? ???? ????? ??? ??????? ?? ????? ????? ???? ???? ????; ?????? ??? ??????? ?????? ?? ???????? ?? ????? ???? ????? ???"),
ch("???? ?? ??? ???", "?? ??? ??????? ?? ???? ?? chapter-by-chapter ????????? ???? ??? ?? ???? ?????? ?????? ?? ????????? ????? ??? ???? ????? ?? ???????? ?????? ????? ?? ??? ??? TXT ????? ???? ?????")),
part("BIXUU HARRY POTTER", "PART 4", true,
ch("???? ??????", "??? 4 ?? ??? ?? ????????? ?????? guide ??? fantasy ???????? ??? ???? ????????? ??????? ?? ??????, ????? ?? ?????? ?????? ?? ????? ???? ??????????? ?? ???? ??? ?? ??? ?????? ?? ????? ?? ???????? ???? ????? ???? ???"),
ch("???? ??? ??????", "?? ????? ???? ??, ?? ???-????? ?????? ???? ?? ???????? ????? ?? ???? ???? ?????????? ??? ???? ?? ???? ???? ?? ?????? ????, ????? ??? ??? ?? ??? ?????????? ???? ???"),
ch("???? ?? ???", "?? reading guide ??? ?????????, ?????????? ?? ?????????? ?? ????? ???? ??? ??? ?? ??? ????? ?? ????? ?? ????? ???? ???")),
part("BIXUU HARRY POTTER", "PART 5", true,
ch("???? ?? ???????", "??? 5 ?? ?? ???? guide ??????? ?? ???? ??? ??????????? ???? ?? ??????? ?? ???????? ??? ???? ???? ??? ????? ?? ???? ???; ?????, ?????? ????? ?? ?????? ?? ??? ???? ????? ??????? ?? ????? ???"),
ch("????? ???? ??????", "?? ????? ?????? ????? ?? ???? ?????, ??? ????? ?? ??????? ??? ??? ??? ???? ?? ???? ???? ??? ????? ?? ??? ??????? ?? ???? ????? ???? ????? ????? ???? ???"),
ch("????? ?????", "?? guide ??? Harry Potter ??? ?? ??? ???? ????? ???? ?????? ?? ?????? ?????? ????? ???? ???? ???? ??? ????? ???? ???? ??? ?????? ?????? ??????")),
part("BIXUU HARRY POTTER", "PART 6", true,
ch("?????? ??????? ?? ??????", "??? 6 ?? ????????? ????? ???? ?? ???????, ????? ?? ????? ?????? ?? ????? ?? ??? ???? ??????? ?? ?????? ?? ????? ?? ??? ???? ??????? ???? ????, ???? ?????? ?? ????? ????? ???"),
ch("????? ?? ?????", "?? ??????? ????? ???? ???? ????? ??????? ?? ?? ???? ????? ?? ?? ??? ?? ????? ????, ???? ????? ?? ???-?? ??? ?????????? ?? ??????"),
ch("?????", "?? ???? ?? ???? ?????? guide ??, ? ?? ??? ??????? ?? ?????? ?? ???????? ?? ???????? ???????? ?????? ?? ??? ?????? ??? ???? ?????")),
part("BIXUU HARRY POTTER", "PART 7", true,
ch("????? ??????", "??? 7 ?? ??? ?? ????????? guide ?????, ???? ?? ???????? ?? ?????????? ?? ???????? ??? ???? fantasy ???????? ?? ????? ????? ???? ?? ???? ?? ????? ?? ??? ?? ????? ???? ???"),
ch("?????? ?? ??????", "???? ??? ??? ??????, ????? ?? ?????? ????? ?? ??? ????? ??? ??? ???? ???? ???? ?? ????? ?????? ?? ???? ???? ??? ?? ???? ??? ????? ?????????? ???"),
ch("???????? ?? ?????", "?? ??? Harry Potter ?????? ?? ???? ??? ???? ?? ?? ? ?? ???? ??????? chapter-by-chapter ??????? ???? ?????? ????? ?? ??? ???? ??? ????? TXT ?? ??? ??? ???? ?????")),
part("BIXUU MONA LISA", "PART 1", false,
ch("???????? ???????", "?? ???????? ????? ?? ????? ???? ???? ????? ????? ???? ???? ????? ?? ???? ??????? ????? ???? Mona Lisa ?? ????? Leonardo da Vinci ?? ????? ??? ???? ?????? ???? ????? ????, ????? ????? ?? ??? ?????, ????? ?? ??? ????? ???? ???? ????? ?? ???\n\n????? ?? ????? ?? ????? ?? ????? ????? ???? ????? ?? ???? ??: ?? ??? ??? ?? ?????? ????? ???? ???"),
ch("?????? ?? ???", "Leonardo da Vinci ??????, ????????? ?? ???????? ?????? ??? ?????????? ??? ??? ???????? ?? ???? ?????, ????, ??????? ?? ?????? ?? ???? ????? ?? ????? ?? ????? ??? Mona Lisa ??? ??????? ??? ?? ?????????? ?????? ???\n\n???? ?? ?? ??????? ???-?????? ?? ??? ????? ???"),
ch("????? ?? ???? ?????", "????? ????? ??? ????? ?? ????, ????? ?? ??????, ?????? ?? ????? ?? ???? ?? landscape ?? ????? ???? ?????? ?? ????? ????? ?? ?????? ??????? ?? ????? ???? ????? ?? ????? ?????? ????? ?? ???? ???? ??? ???????? ???-?????? ?? ?????? ?? ??? ?????")),
part("BIXUU MONA LISA", "PART 2", false,
ch("?????? ?? ??? ?????????", "Mona Lisa ?? ?????? ?? ???? ?????? ???? ???? ??????? ??? ?? ?? ??? ?????????, ???-?????? ?? ???????? ???????? ?? ???? ????????? ?? ?? ??????? ???? ??????? ?? ????? ???? ???? ?? ????, ????? ???? ?????? ?? ???-???? ?? ?? ???? ???? ???"),
ch("????? ???? ????", "????? ?? ???? ??? ?? ???????? ?? ?????? ??????? ???? ????? ?? ???????? ???? ???????? ???? ???? ????? ????? ???? ????? ??: ?? ??? ?? ?????? ???? ??? ????????? ?? ???-????????? ???? ????? ????"),
ch("??? ?? ???", "??? ?? ????? ?? ??? ?????, ?????? ?? ???? ????? ????? ??? ?? ?? ????? ???-??? ????? ?? ??? ??? ?? ???? ??? ??? ??? ?? ???????? ???")),
part("BIXUU TITANIC", "PART 1", false,
ch("???? ?? ?????", "RMS Titanic ???? ??? ?? ????? ?????? ???? ??? ?????? 1912 ??? ?? ???? ???? ?????? ?? ?????? ?? ?????? ??? ???-??? ????? ?? ??????? ???????????? ?? ?? ?????? ?? ???? ?? ?? ????? ???? ??? Titanic ?? ?????? ?????, ?????? ?? ?????? ??????????? ?? ????? ???"),
ch("??????? ??????", "???? ??????? ?????? ??? ????, ????, ????? ?? ??????? ?? ???? ????? ???? ??? ???? ?? ?????? ??? ???? ????? ?? ?????????? ???????? ????? ???? ???? Titanic ?? ????? ???? ??? ?????? ?? ?? ???? ?????? ?????????? ?? ??? ????? ???????-???????? ?? ?????? ???"),
ch("????????? ?? ??????", "???? ?? ????????? ?? ????? ?? ???? ???? ??? ????????, ???? ?? ?????? ?? ???????????? ???? ?? ??????? ?????? ?? ?????? ??? ?? ???? ???? ?????? ????? ??? ?? ????????? ?? ??????????? ?? ??????? ?? ?? ????? ???? ??????")),
part("BIXUU TITANIC", "PART 2", false,
ch("???????? ?? ????", "14?15 ?????? 1912 ?? ??? Titanic ?????? ???????? ??? ?????? ?? ?????? ?? ??? ??? ???? ?? ???? ??????? ?????? ??? ?? ?? ??? ????-????????, ???????? lifeboats ?? ????????? ????? ?? ?????? ?? ?????? ?? ??? ????? ????? ????"),
ch("????? ?? ?????", "?? ???? ??? ???? ????? ?? ??? ?? ?? ???????? ?? ???? ??? ????? ?????? ?? ???????????? ??? ???? ?????????? ???????? ?? ?????? ??????? ??? ?????????, ???? ?? ?? ???? ??? ??? ???? ????? ?? ???????? ?????? ???? ?? ??? ????? ?? ?????? ????"),
ch("??????? ?? ???? ???", "Titanic ?? ??? ??????? ??????? ??????, lifeboat ????????, ????? ?? ????????? ?? ???? ????? ???? ???? ?????????? ?? ????? ???? ?????? ?? ???? ??? ???? ?????? ??? ????? ?? ???")),
part("BIXUU TITANIC", "PART 3", false,
ch("??? ?? ??????", "Titanic ?? ????? ?? ?? ??????, ???????????, ???????? ?? ??????? ??? ??? ?? ???? ??? ???? ?? ???? ?????? ?? ????? ??? ?? ?? ???????? ??? ???????? ????? ?? ??? ????? ????"),
ch("????? ?? ??????", "??????? ?????? ?? ??????? ?? ???? ???, ????? ????? ???????? ????? ?? ?????? ????? ?? ?? ???? ???? ???? ???? ?? ??? ????? ?? ??? ????? ?? ??? ????????? ???????? ????? ?? ??????"),
ch("??????????? ?????", "?? ???? ?? ??? ???? ?? ???? ????? ????? ?? ?? ?? ???????? ????? ?? ?????? ???? ?? ???????, ?????? ??? ???? ???? ?? ????? ?? ??????")),
part("BIXUU PENNYWISE / IT", "PART 1", true,
ch("????? ?? ?????", "?? IT / Pennywise ??? ?? ???????? horror ????? ?? ??? ????, non-graphic ?????? reading guide ??? ?? ??? ??????? ?? ????? ?? ????? ???? ??? ????? ?? ?????? ?????? ??? ??, ???? ?? ?????, ?????? ?? ???? ????? ?? ????? ???? ????? ????"),
ch("?? ?? ??????", "Horror fiction ????? ?????? ????? ?? ???? ???? ???? ???? ?????? ?? ????? ???? ??? ???? ?? ??? ???? ?? ?? ?? ????? ??? ???????, ?????, ?????? ??? ?? ??????? ?? ????? ?? ???? ???? ???? ??????? ???? graphic ????? ???"),
ch("????? ?? ??????", "???????? ?? ?? ???????? ???? ?? ??????? ? ?????? ????? ?? ???????? ???? ??? ??????? ?? ???????, ?????? ?? ??-????? ?? ????? ???? ?? ?????? ??????")),
part("BIXUU PENNYWISE / IT", "PART 2", true,
ch("?????? ????? ?? ?????", "?? ??? ?? ???? guide ????? ?? ?????? ??????? ?? ?????? ?? ???????? ??? Horror ???????? ??? ??? ??? ?? ???? ??????? ?? ?????? ???? ??? ???? ???? ??? ?? ???? ????????? ?????? ?? ????? ???"),
ch("???? ?? ????", "???? ?????? ????? ?? ????? ????? ???? ?? ???? ??? ???????? ????? ??-????? ?? ??? ????? ?? ???-??? ??????? ?????? ????? ??? ??? ???? ????"),
ch("??? ?? ???????", "???? ??????? ??????? ????? ?? ??? ????, ???? ???, ????? ?? ????? ???? ???? ????? ???? ?? guide ??? ?????? ?? ??????? ?? ??????? ?? ??????? ???? ???")),
part("BIXUU PENNYWISE / IT", "PART 3", true,
ch("????? ?? ?????", "?? ??? 3 ?? ???? non-graphic guide ??? Horror ??? ?? ??? ??? ???? ?? ??? ???? ?? ?? ??????? ?? ???? ?? ?? ???? ???? ?? ??-????? ?? ????? ???? ?????"),
ch("???? ?? ????", "???? ?? ???? ????? ?????? ???? ??? ??? ??? ?? ??? ??????, ???????? ?????? ???? ?? ??????? ?? ??? ???? ?? ???? ???"),
ch("????? ?? ????", "?? original chapter text ?? ????? ?????? ???? ??? ??? ???? ??? ??? ??? ?? ??????? ???? TXT ??? ??, IMPORT MY TXT ?? ??? ???? ??? ???? ????")),
part("BIXUU PENITENTIARY", "PART 1", false,
ch("?????? ?????", "??? ?? ?????? ?? ?????? penitentiary ????? ??, ???? ?? ??? ???? ??? ?? ???? ??? ??? ?? ???? ??? ???? ???? ??; ????? ?? ?????? ????????? ????? ?? ????? ??? ???? archivist ??? ?? ?????? ??????? ????????? ???? ?? ??? ?????"),
ch("???? ?? ?????", "??????? ??? ??? ??? ?? ?????? ???? ???? ?? ?? ??? ??? ???? ????? ???? ?? ??? ???? ??? ??? ??? ????? ??? ????? ?? ??? ?????? ??? ??? ?? ??????? ??????? ???? ?? ?????? ?? ????? ?? ?????? ?? ???? ???? ??? ????? ?? ???? ???? ???"),
ch("??? ???? ?? ?????", "????? ?? ????????? ?? ???? ?? ???? ???? ?????? ??? ??? ???? ??? ????? ????, ????? ?????? ???? ?? ????? ?? ??????? ?? ?????? ???????? ??? ????? ?? ???? ?? ???? ?? ?????? ??????-?????? ?? ??? ??? ???? ???? ???")),
part("BIXUU PENITENTIARY", "PART 2", false,
ch("?????? ?? ????", "?????? ??? ?? ??????????? ?? ???????? ?? ????? ??? ????????? ???? ??? ??? ??-????? ?? ??? ?? ??? ??? ?? ?? ???? ?? ????? ?? ?????? ??? ?? ???? ?? ????????? ?? ??? ???????? ???? ?????"),
ch("?????? ?????", "?????? ???? ?? ????? ???? ????? ?? ????? ???? ??? ?? ?? ??????-????? ??, ???? ?? ???????? ?? ??? ??? ?? ????? ?? ???????? ???? ??? ????? ?? ?????? ?? ??????? ???-??? ?????? ?????? ?? ????? ??? ???? ????"),
ch("?? ??????", "????? ?? ???????? ????????? ??? ???? ???? ??? ?? ?????? ?? ?????? ????? ???? ???? ??? ???? ???????? ?????? ??? ????? ??? ??? ?? ????? ?? ??? ???? ?? ??? ?? ???")),
part("BIXUU UNKNOWN STORY", "PART 1", false,
ch("??? ??? ?? ??????", "?????? ????? ??? ?? ???? ?????? ?? ???? ????? ????? ?? ??? ?? ?????????? ?? ???? ???? ???? ??? ??? ?? ?? ?????? ???? ???? ??? ?? ???? ??? ?? ????? ?? ???? ?? ??? ?????? ????? ???? ???"),
ch("???? ?????", "?????? ?? ???? ?? ???? ???? ????? ??? ????? ????? ????? ????? ????? ?? ????? ?? ??? ???????? ???? ??? ?? ???? ????? ???? ?? ?????? ?? ????? ?? ???? ????? ?? ????? ?????? ?? ?????? ????? ??? ?????"),
ch("???? ??????", "????? ?? ?????? ??? ???? ??????????? ?? ????????? ???? ?? ???? ?????? ??? ????? ?? ???? ????????? ?? ?????? ??? ?????? ?? ???? ???? ????? ???? ???")),
part("BIXUU UNKNOWN STORY", "PART 2", false,
ch("????? ?? ?????", "????? ????? ??? ??? ????? ?? ?????? ?? ??? ??? ??? ???? ?? ?????? ?? ??? ?? ????? ???? ???? ???????? ?? ???? ???? ????? ????? ?????? ???? ?? ???? ?? ?? ????? ?? ??? ???"),
ch("???? ??? ?????", "???? ?? ??? ?????? ?????? ?? ???? ??????-?????? ?? ????? ????? ???? ????? ?? ????? ?? ??? ?? ???-????? ?? ????????? ????? ?? ???? ???? ???"),
ch("????? ?????", "????? ?? ????? ????? ???? ????? ???? ??? ????? ??? ???? ?? ????? ?????? ????: '???? ??? ???????? ?????? ???, ???? ????? ???????' ????? ????????? ?? ?? ?? ?????")),
part("BIXUU UNKNOWN STORY", "PART 3", false,
ch("????????? ?? ????", "?????? ????????? ??? ???? ?? ???? ???? ???? ?? ????? ?? ????? ?? ??? ???? ??? ?? ????? ??? ?? ???? ???? ??? ??? ???????????????? ?? ????? ?? ?? ????? ?? ???? ????????? ?????-???? ?? ???? ???"),
ch("????? ?? ?????", "???? ?? ???? ????? ???? ?? ??? ???? ??? ????? ????? ?? ???? ????????, ???????? ?? ?????? ????? ??? ?? ????? ????? ?? ???? ?????? ?? ??? ????? ??? ???"),
ch("????? ???? ??", "??? ?? ???? ?? ??? ?????????? ?? ????????? ??? ???????? ???? ???????? ?? ??? ?????-???? ???? ???? ???? ?? ??????? ???? ????? ??? ???? ??? ????? ?? ???? ???? ????? ????? ?? ???? ????? ????")),
part("BIXUU ANIMAL STORY", "SPECIAL STORY", false,
ch("???? ?? ???", "???-??? ???? ??? ????? ?????, ???? ???? ?? ???? ???? ???? ??? ?? ????? ??? ???? ??? ?? ???? ?? ???? ???? ??? ????? ?????? ??? ???? ?? ??????? ???? ?? ???? ??? ??? ???????"),
ch("????? ??????", "???? ?? ?????? ?? ???? ?? ?????? ????? ???? ??? ???? ?? ?????? ?? ???? ?????? ?????, ????? ?? ???? ?????? ???? ?? ???? ?? ???? ???? ????? ?? ???? ?????? ???? ?? ????? ?? ??? ???? ???? ????, ????? ???? ?????? ???? ???"),
ch("??? ??? ???? ???", "??? ????? ??? ??? ???? ??? ??? ?? ????? ???? ??????? ?? ?????? ?? ???? ???? ?? ?? ???? ?? ??? ?? ????? ?? ?????? ???? ???? ????? ???? ?? ???? ?? ??????? ?? ????? ????? ???? ??????"),
ch("?????? ?? ????", "?? ???? ??? ????? ??? ?? ?????? ???? ???? ???? ?????? ?? ?? ????, ???? ?? ??????? ?? ?????? ???? ?????? ???? ????? ?? ???, '???? ????? ?? ??; ??? ???????? ???? ?? ???? ?????????? ???'")),
part("BIXUU ANIMATED STORY", "CREATE & READ", false,
ch("?? ?? ????? ???? ????", "?? ??? ???? ???? animated story ??????? ?? ??? ??? ???? WRITE YOUR STORY ??? ?? ?????? ?? ???? ????? ?????? ?? ?????, ???, ????? ?? ??? ??? ??? ???? ???? ???? ??? ????? TXT ???? ?? ??? ??? ??? ?? ?? ???? ?? ?? ??? ??? IMPORT MY TXT ?? ??? ???? ?? ???? ???"),
ch("????? ?? ?????", "?? ????? ???? ????? ??? ??????, ??????, ????? ?? ?????? ?? ???? ??? ?????? ??? ????? ?? ??? ?????? ??? ??? ???? ?? ?????? ?????? ????? ???? ???? ???, ???? ????? ??? ????? ??? ??? ??? ?????? ?? ??? ???????"),
ch("???? ???? ?????", "Bixuu Animated Story ??? ?? fantasy, comedy, nature, mystery ?? space adventure ???? ???? original ???????? ??? ???? ???? ???? ?????? ????? ?? ????? ?? ???? text copy ???? ?? ???? ???? ????? ?? ???? ????? ??????"))
)
private val bg = new Color(8, 12, 27)
private val panel = new Color(18, 25, 48)
private val panel2 = new Color(24, 34, 63)
private val cyan = new Color(91, 229, 235)
private val purple = new Color(166, 126, 255)
private val white = new Color(239, 244, 255)
private val muted = new Color(174, 190, 220)
private class MainWindow extends JFrame("BIXUU STORY LIBRARY ? HINDI READER") {
private val extraBooks = ArrayBuffer[StoryPart]()
private var visibleBooks: Vector[StoryPart] = storyCatalog
private var currentBook: StoryPart = storyCatalog.head
private var currentChapter: Int = 0
private val bookModel = new DefaultListModel[String]()
private val chapterModel = new DefaultListModel[String]()
private val bookList = new JList[String](bookModel)
private val chapterList = new JList[String](chapterModel)
private val searchField = new JTextField()
private val reader = new JTextArea()
private val languageBox = new JComboBox[String](Array("HINGLISH (Tum / Hum)", "HINDI (????????)"))
private val bookHeading = new JLabel("BIXUU STORY LIBRARY")
private val chapterHeading = new JLabel("CHAPTER 1")
private val status = new JLabel(" READY ? SELECT A STORY TO BEGIN")
private val pageCount = new JLabel("STORIES: " + storyCatalog.length)
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE)
setMinimumSize(new Dimension(1000, 680))
setSize(1280, 820)
getContentPane.setBackground(bg)
setLayout(new BorderLayout())
private def styleList(list: JList[String]): Unit = {
list.setBackground(panel)
list.setForeground(white)
list.setSelectionBackground(new Color(65, 93, 153))
list.setSelectionForeground(Color.WHITE)
list.setFont(new Font("SansSerif", Font.BOLD, 13))
list.setFixedCellHeight(42)
list.setBorder(new EmptyBorder(8, 8, 8, 8))
}
private def makeButton(label: String, color: Color): JButton = {
val b = new JButton(label)
b.setFont(new Font("SansSerif", Font.BOLD, 12))
b.setForeground(Color.WHITE)
b.setBackground(color)
b.setFocusPainted(false)
b.setBorder(new EmptyBorder(11, 15, 11, 15))
b.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR))
b
}
private def buildUI(): Unit = {
val top = new JPanel(new BorderLayout(12, 8))
top.setBackground(bg)
top.setBorder(new EmptyBorder(18, 22, 16, 22))
val titles = new JPanel(new GridLayout(2, 1, 0, 3))
titles.setOpaque(false)
val mainTitle = new JLabel("BIXUU'S ALL STORIES")
mainTitle.setForeground(cyan)
mainTitle.setFont(new Font("SansSerif", Font.BOLD, 27))
val sub = new JLabel("HINGLISH + HINDI STORY LIBRARY ? PARTS ? CHAPTERS ? YOUR OWN BOOKS")
sub.setForeground(muted)
sub.setFont(new Font("SansSerif", Font.PLAIN, 11))
titles.add(mainTitle)
titles.add(sub)
top.add(titles, BorderLayout.WEST)
pageCount.setForeground(purple)
pageCount.setFont(new Font("SansSerif", Font.BOLD, 13))
top.add(pageCount, BorderLayout.EAST)
add(top, BorderLayout.NORTH)
styleList(bookList)
styleList(chapterList)
reader.setEditable(false)
reader.setLineWrap(true)
reader.setWrapStyleWord(true)
reader.setFont(new Font("Noto Sans Devanagari", Font.PLAIN, 18))
reader.setForeground(white)
reader.setBackground(new Color(12, 18, 36))
reader.setCaretColor(cyan)
reader.setMargin(new Insets(22, 24, 24, 24))
val left = new JPanel(new BorderLayout(6, 8))
left.setBackground(panel)
left.setBorder(new EmptyBorder(12, 12, 12, 12))
val leftTitle = new JLabel("STORY COLLECTION")
leftTitle.setForeground(cyan)
leftTitle.setFont(new Font("SansSerif", Font.BOLD, 13))
left.add(leftTitle, BorderLayout.NORTH)
searchField.setBackground(new Color(10, 16, 34))
searchField.setForeground(white)
searchField.setCaretColor(cyan)
searchField.setFont(new Font("SansSerif", Font.PLAIN, 13))
searchField.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(new Color(67, 86, 133)), new EmptyBorder(9, 10, 9, 10)))
val searchWrap = new JPanel(new BorderLayout())
searchWrap.setOpaque(false)
searchWrap.add(searchField, BorderLayout.CENTER)
val leftCenter = new JPanel(new BorderLayout(0, 8))
leftCenter.setOpaque(false)
leftCenter.add(searchWrap, BorderLayout.NORTH)
leftCenter.add(new JScrollPane(bookList), BorderLayout.CENTER)
left.add(leftCenter, BorderLayout.CENTER)
left.setPreferredSize(new Dimension(300, 500))
val middle = new JPanel(new BorderLayout(6, 8))
middle.setBackground(panel)
middle.setBorder(new EmptyBorder(12, 12, 12, 12))
val middleTitle = new JLabel("PART / CHAPTERS")
middleTitle.setForeground(purple)
middleTitle.setFont(new Font("SansSerif", Font.BOLD, 13))
middle.add(middleTitle, BorderLayout.NORTH)
middle.add(new JScrollPane(chapterList), BorderLayout.CENTER)
middle.setPreferredSize(new Dimension(245, 500))
val right = new JPanel(new BorderLayout(8, 8))
right.setBackground(panel)
right.setBorder(new EmptyBorder(14, 16, 14, 16))
val readingTop = new JPanel(new BorderLayout(8, 6))
readingTop.setOpaque(false)
bookHeading.setForeground(cyan)
bookHeading.setFont(new Font("SansSerif", Font.BOLD, 18))
chapterHeading.setForeground(purple)
chapterHeading.setFont(new Font("SansSerif", Font.BOLD, 13))
val readingSubRow = new JPanel(new BorderLayout(8, 0))
readingSubRow.setOpaque(false)
readingSubRow.add(chapterHeading, BorderLayout.CENTER)
languageBox.setSelectedIndex(0)
languageBox.setFont(new Font("SansSerif", Font.BOLD, 11))
languageBox.setForeground(white)
languageBox.setBackground(panel2)
languageBox.setToolTipText("Choose Roman Hindi Hinglish or Devanagari Hindi")
readingSubRow.add(languageBox, BorderLayout.EAST)
readingTop.add(bookHeading, BorderLayout.NORTH)
readingTop.add(readingSubRow, BorderLayout.SOUTH)
right.add(readingTop, BorderLayout.NORTH)
right.add(new JScrollPane(reader), BorderLayout.CENTER)
val note = new JLabel(" NOTE: Copyrighted titles show short original guides. Import your own lawful TXT to read its full text.")
note.setForeground(muted)
note.setFont(new Font("SansSerif", Font.PLAIN, 10))
right.add(note, BorderLayout.SOUTH)
val splitRight = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, middle, right)
splitRight.setResizeWeight(0.30)
splitRight.setBorder(null)
splitRight.setDividerSize(6)
val splitAll = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, left, splitRight)
splitAll.setResizeWeight(0.24)
splitAll.setBorder(null)
splitAll.setDividerSize(7)
add(splitAll, BorderLayout.CENTER)
val bottom = new JPanel(new BorderLayout(10, 6))
bottom.setBackground(bg)
bottom.setBorder(new EmptyBorder(10, 16, 14, 16))
val buttonRow = new JPanel(new FlowLayout(FlowLayout.LEFT, 8, 0))
buttonRow.setOpaque(false)
val prev = makeButton("? PREVIOUS CHAPTER", new Color(60, 75, 123))
val next = makeButton("NEXT CHAPTER ?", new Color(77, 102, 181))
val importBtn = makeButton("IMPORT MY TXT", new Color(20, 130, 133))
val writeBtn = makeButton("WRITE YOUR STORY", new Color(117, 79, 175))
val allBtn = makeButton("SHOW ALL STORIES", new Color(55, 68, 103))
buttonRow.add(prev)
buttonRow.add(next)
buttonRow.add(importBtn)
buttonRow.add(writeBtn)
buttonRow.add(allBtn)
bottom.add(buttonRow, BorderLayout.NORTH)
status.setForeground(cyan)
status.setFont(new Font("SansSerif", Font.PLAIN, 11))
bottom.add(status, BorderLayout.SOUTH)
add(bottom, BorderLayout.SOUTH)
bookList.addListSelectionListener(new ListSelectionListener {
override def valueChanged(e: ListSelectionEvent): Unit = {
if (!e.getValueIsAdjusting) selectBook(bookList.getSelectedIndex)
}
})
chapterList.addListSelectionListener(new ListSelectionListener {
override def valueChanged(e: ListSelectionEvent): Unit = {
if (!e.getValueIsAdjusting) showChapter(chapterList.getSelectedIndex)
}
})
languageBox.addActionListener(new ActionListener {
override def actionPerformed(e: ActionEvent): Unit = {
val selectedIndex = chapterList.getSelectedIndex
if (selectedIndex >= 0) showChapter(selectedIndex)
}
})
searchField.getDocument.addDocumentListener(new DocumentListener {
override def insertUpdate(e: DocumentEvent): Unit = refreshBooks()
override def removeUpdate(e: DocumentEvent): Unit = refreshBooks()
override def changedUpdate(e: DocumentEvent): Unit = refreshBooks()
})
prev.addActionListener(new ActionListener { override def actionPerformed(e: ActionEvent): Unit = moveChapter(-1) })
next.addActionListener(new ActionListener { override def actionPerformed(e: ActionEvent): Unit = moveChapter(1) })
importBtn.addActionListener(new ActionListener { override def actionPerformed(e: ActionEvent): Unit = importTextBook() })
writeBtn.addActionListener(new ActionListener { override def actionPerformed(e: ActionEvent): Unit = openWriter() })
allBtn.addActionListener(new ActionListener { override def actionPerformed(e: ActionEvent): Unit = { searchField.setText(""); refreshBooks() } })
refreshBooks()
}
private def allBooks: Vector[StoryPart] = storyCatalog ++ extraBooks.toVector
private def refreshBooks(): Unit = {
val q = searchField.getText.trim.toLowerCase
visibleBooks = allBooks.filter(b => q.isEmpty || (b.title + " " + b.partLabel).toLowerCase.contains(q))
bookModel.clear()
visibleBooks.foreach { b =>
val marker = if (b.guideOnly) " ? GUIDE" else " ? STORY"
bookModel.addElement(b.title + " ? " + b.partLabel + marker)
}
pageCount.setText("STORY PARTS: " + allBooks.length)
if (visibleBooks.nonEmpty) bookList.setSelectedIndex(0)
else {
chapterModel.clear()
reader.setText("??? ????? ???? ????? Search ????? ??? ????? ?????")
bookHeading.setText("NO STORY FOUND")
chapterHeading.setText("")
}
}
private def selectBook(index: Int): Unit = {
if (index >= 0 && index < visibleBooks.length) {
currentBook = visibleBooks(index)
currentChapter = 0
chapterModel.clear()
currentBook.chapters.zipWithIndex.foreach { pair =>
chapterModel.addElement("CHAPTER " + (pair._2 + 1) + " ? " + pair._1.title)
}
bookHeading.setText(currentBook.title + " / " + currentBook.partLabel)
chapterList.setSelectedIndex(0)
status.setText(" OPENED: " + currentBook.title + " ? " + currentBook.partLabel)
}
}
private def showChapter(index: Int): Unit = {
if (index >= 0 && index < currentBook.chapters.length) {
currentChapter = index
val selected = currentBook.chapters(index)
val hinglish = languageBox.getSelectedIndex == 0
val displayTitle = if (hinglish) toHinglish(selected.title) else selected.title
val displayBody = if (hinglish) toHinglish(selected.body) else selected.body
chapterHeading.setText(currentBook.partLabel + " ? CHAPTER " + (index + 1) + " ? " + displayTitle)
val notice = if (currentBook.guideOnly) "[SHORT GUIDE ? NOT THE ORIGINAL BOOK TEXT]\n\n" else ""
reader.setText(notice + displayBody)
reader.setCaretPosition(0)
status.setText(" READING: " + selected.title + " | CHAPTER " + (index + 1) + " OF " + currentBook.chapters.length)
}
}
private def moveChapter(delta: Int): Unit = {
val nextIndex = currentChapter + delta
if (nextIndex >= 0 && nextIndex < currentBook.chapters.length) chapterList.setSelectedIndex(nextIndex)
else status.setText(" THIS IS THE " + (if (delta < 0) "FIRST" else "LAST") + " CHAPTER OF THIS PART")
}
private def importTextBook(): Unit = {
val chooser = new JFileChooser()
chooser.setDialogTitle("Import your own lawful story TXT")
chooser.setFileFilter(new FileNameExtensionFilter("Text files (*.txt)", "txt"))
val result = chooser.showOpenDialog(this)
if (result == JFileChooser.APPROVE_OPTION) {
val file = chooser.getSelectedFile
try {
val source = Source.fromFile(file, "UTF-8")
val raw = try source.mkString finally source.close()
val imported = parseImportedBook(file.getName, raw)
extraBooks += imported
searchField.setText("")
refreshBooks()
val index = visibleBooks.indexOf(imported)
if (index >= 0) bookList.setSelectedIndex(index)
status.setText(" IMPORTED FULL TEXT: " + file.getName)
} catch {
case ex: Exception => JOptionPane.showMessageDialog(this, "File could not be opened: " + ex.getMessage,
"IMPORT ERROR", JOptionPane.ERROR_MESSAGE)
}
}
}
private def parseImportedBook(fileName: String, raw: String): StoryPart = {
val lines = raw.replace("\r", "").split("\n", -1)
val chapters = ArrayBuffer[Chapter]()
val buffer = new StringBuilder
var title = "FULL STORY"
var sawHeading = false
def isHeading(s: String): Boolean = {
val t = s.trim
t.matches("(?i)^(PART|CHAPTER)\\s*[-:#0-9].*") || t.matches("^(???|??????)\\s*[-:#0-9?-?].*")
}
def flush(): Unit = {
val body = buffer.toString.trim
if (body.nonEmpty) chapters += Chapter(title, body)
buffer.clear()
}
lines.foreach { line =>
if (isHeading(line)) {
if (buffer.toString.trim.nonEmpty) flush()
title = line.trim
sawHeading = true
} else {
buffer.append(line).append("\n")
}
}
flush()
val finalChapters = if (chapters.isEmpty) Vector(Chapter("FULL STORY", raw)) else chapters.toVector
val safeName = fileName.replaceAll("(?i)\\.txt$", "")
StoryPart(safeName, if (sawHeading) "IMPORTED CHAPTERS" else "IMPORTED TXT", finalChapters, false)
}
private def openWriter(): Unit = {
val dialog = new JDialog(this, "BIXUU ? WRITE YOUR STORY", true)
dialog.setSize(760, 640)
dialog.setLocationRelativeTo(this)
dialog.setLayout(new BorderLayout(8, 8))
dialog.getContentPane.setBackground(bg)
val titleField = new JTextField("Bixuu My New Story")
titleField.setFont(new Font("SansSerif", Font.BOLD, 16))
val textArea = new JTextArea()
textArea.setFont(new Font("Noto Sans Devanagari", Font.PLAIN, 17))
textArea.setLineWrap(true)
textArea.setWrapStyleWord(true)
textArea.setText("??? 1 ? ??????\n\n???? ????? ???? ?????...\n\n?????? 2 ? ?? ????\n\n????? ??? ?????...\n")
val top = new JPanel(new BorderLayout(6, 6))
top.setBorder(new EmptyBorder(12, 12, 4, 12))
top.setBackground(bg)
val label = new JLabel("STORY TITLE")
label.setForeground(cyan)
top.add(label, BorderLayout.NORTH)
top.add(titleField, BorderLayout.CENTER)
dialog.add(top, BorderLayout.NORTH)
dialog.add(new JScrollPane(textArea), BorderLayout.CENTER)
val bottom = new JPanel(new FlowLayout(FlowLayout.RIGHT))
bottom.setBackground(bg)
val save = makeButton("SAVE STORY TXT", new Color(20, 130, 133))
val cancel = makeButton("CLOSE", new Color(70, 78, 105))
bottom.add(save)
bottom.add(cancel)
dialog.add(bottom, BorderLayout.SOUTH)
cancel.addActionListener(new ActionListener { override def actionPerformed(e: ActionEvent): Unit = dialog.dispose() })
save.addActionListener(new ActionListener {
override def actionPerformed(e: ActionEvent): Unit = {
val storyTitle = titleField.getText.trim
val body = textArea.getText
if (storyTitle.isEmpty || body.trim.isEmpty) {
JOptionPane.showMessageDialog(dialog, "Please enter a title and story text.", "STORY NEEDED", JOptionPane.WARNING_MESSAGE)
} else {
val chooser = new JFileChooser()
chooser.setDialogTitle("Save your story as TXT")
chooser.setSelectedFile(new File(storyTitle.replaceAll("[^A-Za-z0-9_-]", "_") + ".txt"))
if (chooser.showSaveDialog(dialog) == JFileChooser.APPROVE_OPTION) {
var output: PrintWriter = null
try {
output = new PrintWriter(chooser.getSelectedFile, "UTF-8")
output.print(body)
output.flush()
val newBook = parseImportedBook(storyTitle + ".txt", body)
extraBooks += newBook
searchField.setText("")
refreshBooks()
val index = visibleBooks.indexOf(newBook)
if (index >= 0) bookList.setSelectedIndex(index)
status.setText(" SAVED YOUR STORY: " + storyTitle)
dialog.dispose()
} catch {
case ex: Exception => JOptionPane.showMessageDialog(dialog, "Could not save: " + ex.getMessage,
"SAVE ERROR", JOptionPane.ERROR_MESSAGE)
} finally {
if (output != null) output.close()
}
}
}
}
})
dialog.setVisible(true)
}
buildUI()
setLocationRelativeTo(null)
}
def main(args: Array[String]): Unit = {
SwingUtilities.invokeLater(new Runnable {
override def run(): Unit = {
val window = new MainWindow()
window.setVisible(true)
}
})
}
}
BixuuStoryLibraryUltra.main(new Array[String](0))