Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package twice;
- import javax.swing.*;
- import java.awt.*;
- import java.io.File;
- import java.io.IOException;
- import static java.lang.Thread.sleep;
- import java.util.ArrayList;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javafx.scene.media.Media;
- import javafx.scene.media.MediaPlayer;
- import javax.swing.text.SimpleAttributeSet;
- import javax.swing.text.StyleConstants;
- import javax.swing.text.StyledDocument;
- /**
- *
- * @author Robin
- */
- public class GroupGUI extends javax.swing.JFrame {
- private Group group;
- private StyledDocument doc;
- private boolean dispRomText = true;
- private boolean dispHanText = true;
- private boolean dispJapText = true;
- private boolean dispEngText = true;
- /**
- * Creates new form GroupGUI
- */
- public GroupGUI() {
- initComponents();
- setLocationRelativeTo(null);
- txtLyrics.setEditable(false);
- doc = txtLyrics.getStyledDocument();
- SimpleAttributeSet center = new SimpleAttributeSet();
- StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
- doc.setParagraphAttributes(0, doc.getLength(), center, false);
- group = new Group("Twice");
- for (Album a : group.getAlbums()) {
- cmbAlbum.addItem(a.getName());
- }
- chkRom.setSelected(true);
- chkKrJp.setSelected(true);
- chkEng.setSelected(true);
- setColours();
- /*String bip = "Song.mp3";
- Media hit = new Media(new File(bip).toURI().toString());
- MediaPlayer mediaPlayer = new MediaPlayer(hit);
- mediaPlayer.play();*/
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jLabel1 = new javax.swing.JLabel();
- lblCover = new javax.swing.JLabel();
- lblAlbum = new javax.swing.JLabel();
- lblSong = new javax.swing.JLabel();
- cmbAlbum = new javax.swing.JComboBox<>();
- cmbSong = new javax.swing.JComboBox<>();
- jScrollPane1 = new javax.swing.JScrollPane();
- txtLyrics = new javax.swing.JTextPane();
- chkRom = new javax.swing.JCheckBox();
- chkKrJp = new javax.swing.JCheckBox();
- chkEng = new javax.swing.JCheckBox();
- jLabel1.setText("jLabel1");
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- setBackground(new java.awt.Color(255, 255, 255));
- setForeground(java.awt.Color.white);
- setPreferredSize(new java.awt.Dimension(600, 600));
- setResizable(false);
- getContentPane().setLayout(null);
- lblCover.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
- lblCover.setMaximumSize(new java.awt.Dimension(300, 300));
- lblCover.setMinimumSize(new java.awt.Dimension(300, 300));
- lblCover.setName(""); // NOI18N
- lblCover.setPreferredSize(new java.awt.Dimension(300, 300));
- getContentPane().add(lblCover);
- lblCover.setBounds(295, 0, 300, 300);
- lblAlbum.setFont(new java.awt.Font("Dialog", 1, 13)); // NOI18N
- lblAlbum.setText("Album:");
- getContentPane().add(lblAlbum);
- lblAlbum.setBounds(10, 13, 45, 18);
- lblSong.setFont(new java.awt.Font("Dialog", 1, 13)); // NOI18N
- lblSong.setText("Song:");
- getContentPane().add(lblSong);
- lblSong.setBounds(9, 53, 37, 18);
- cmbAlbum.setFont(new java.awt.Font("Dialog", 0, 11)); // NOI18N
- cmbAlbum.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- cmbAlbumActionPerformed(evt);
- }
- });
- getContentPane().add(cmbAlbum);
- cmbAlbum.setBounds(60, 10, 230, 25);
- cmbSong.setFont(new java.awt.Font("Dialog", 0, 11)); // NOI18N
- cmbSong.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- cmbSongActionPerformed(evt);
- }
- });
- getContentPane().add(cmbSong);
- cmbSong.setBounds(60, 50, 230, 25);
- txtLyrics.setFont(new java.awt.Font("Serif", 0, 20)); // NOI18N
- jScrollPane1.setViewportView(txtLyrics);
- getContentPane().add(jScrollPane1);
- jScrollPane1.setBounds(7, 307, 580, 250);
- chkRom.setText("Romanized");
- getContentPane().add(chkRom);
- chkRom.setBounds(10, 280, 91, 24);
- chkKrJp.setText("Nihongo");
- getContentPane().add(chkKrJp);
- chkKrJp.setBounds(100, 280, 74, 24);
- chkEng.setText("English");
- getContentPane().add(chkEng);
- chkEng.setBounds(173, 280, 69, 24);
- pack();
- }// </editor-fold>
- private void cmbAlbumActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- lblCover.setIcon(new ImageIcon(("Covers\\" + (cmbAlbum.getSelectedItem()) + " Cover.png").trim()));
- setColours();
- for (Album a : group.getAlbums()) {
- if (a.getName().equals(cmbAlbum.getSelectedItem())) {
- cmbSong.removeAllItems();
- for (Song s : a.getSongs()) {
- cmbSong.addItem(s.getName());
- }
- }
- }
- }
- private void cmbSongActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- updateText();
- }
- private void setColours() {
- for (Album a : group.getAlbums()) {
- if (a.getName().equals((String) cmbAlbum.getSelectedItem())) {
- this.getContentPane().setBackground(new Color(a.getColour().get(0), a.getColour().get(1), a.getColour().get(2)));
- //txtLyrics.setBackground(new Color(Math.max(0,a.getColour().get(0)-10),Math.max(0,a.getColour().get(1)-10),Math.max(0, a.getColour().get(2)-10)));
- cmbAlbum.setBackground(new Color(Math.max(0, a.getColour().get(0) - 10), Math.max(0, a.getColour().get(1) - 10), Math.max(0, a.getColour().get(2) - 10)));
- cmbSong.setBackground(new Color(Math.max(0, a.getColour().get(0) - 10), Math.max(0, a.getColour().get(1) - 10), Math.max(0, a.getColour().get(2) - 10)));
- if (!(a.getColour().get(0) == 255 && a.getColour().get(1) == 255 && a.getColour().get(2) == 255)) {
- lblAlbum.setForeground(new Color(Math.min(255, a.getColour().get(0) + 75), Math.min(255, a.getColour().get(1) + 75), Math.min(255, a.getColour().get(2) + 75)));
- lblSong.setForeground(new Color(Math.min(255, a.getColour().get(0) + 75), Math.min(255, a.getColour().get(1) + 75), Math.min(255, a.getColour().get(2) + 75)));
- } else {
- lblAlbum.setForeground(Color.BLACK);
- lblSong.setForeground(Color.BLACK);
- }
- }
- }
- }
- private void updateText() {
- txtLyrics.setText("");
- boolean setText = false;
- for (Album a : group.getAlbums()) {
- for (Song s : a.getSongs()) {
- if (s.getName().equals(cmbSong.getSelectedItem()) && !setText) {
- int index = 0;
- for (String str : s.lyrics) {
- try {
- if (index == 0) {
- doc.insertString(doc.getLength(), "[ROMANIZED]\n\n", null);
- doc.insertString(doc.getLength(), str + "\n\n", null);
- } else if (index == 1) {
- if (!(s.getName().contains("Jap") || a.getName().equals("One More Time"))) {
- doc.insertString(doc.getLength(), "[HANGUL]\n\n", null);
- } else {
- doc.insertString(doc.getLength(), "[NIHONGO]\n\n", null);
- }
- doc.insertString(doc.getLength(), str + "\n\n", null);
- } else {
- doc.insertString(doc.getLength(), "[ENGLISH]\n\n", null);
- doc.insertString(doc.getLength(), str, null);
- }
- txtLyrics.setCaretPosition(0);
- ++index;
- } catch (Exception e) {
- JOptionPane.showMessageDialog(this, "Error", "Something went wrong while getting ahold of the lyrics", JOptionPane.ERROR_MESSAGE);
- }
- }
- setText = true;
- }
- }
- }
- }
- private void updateCheckBoxes() {
- String tempStr = (String) cmbSong.getSelectedItem();
- System.out.println(cmbAlbum.getSelectedItem());
- System.out.println("-"+tempStr);
- for (Album a : group.getAlbums()) {
- for (Song s : a.getSongs()) {
- if (s.getName().equals(cmbSong.getSelectedItem()) && s.getIsJap()) {
- chkKrJp.setText("Nihongo");
- } else {
- chkKrJp.setText("Hangul");
- }
- }
- }
- }
- /*private void useTitleFont() {
- StyleConstants.setFontFamily(aSet, titleFont.getFamily());
- StyleConstants.setFontSize(aSet, titleFont.getSize());
- doc.setParagraphAttributes(0, 0, aSet, false);
- }
- private void useTextFont() {
- StyleConstants.setFontFamily(aSet, textFont.getFamily());
- StyleConstants.setFontSize(aSet, textFont.getSize());
- doc.setParagraphAttributes(0, 0, aSet, false);
- }*/
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(GroupGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(GroupGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(GroupGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(GroupGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new GroupGUI().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JCheckBox chkEng;
- private javax.swing.JCheckBox chkKrJp;
- private javax.swing.JCheckBox chkRom;
- private javax.swing.JComboBox<String> cmbAlbum;
- private javax.swing.JComboBox<String> cmbSong;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JLabel lblAlbum;
- private javax.swing.JLabel lblCover;
- private javax.swing.JLabel lblSong;
- private javax.swing.JTextPane txtLyrics;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement