Advertisement
Guest User

Untitled

a guest
Dec 15th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 12.69 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package twice;
  7.  
  8. import javax.swing.*;
  9. import java.awt.*;
  10. import java.io.File;
  11. import java.io.IOException;
  12. import static java.lang.Thread.sleep;
  13. import java.util.ArrayList;
  14. import java.util.logging.Level;
  15. import java.util.logging.Logger;
  16. import javafx.scene.media.Media;
  17. import javafx.scene.media.MediaPlayer;
  18. import javax.swing.text.SimpleAttributeSet;
  19. import javax.swing.text.StyleConstants;
  20. import javax.swing.text.StyledDocument;
  21.  
  22. /**
  23.  *
  24.  * @author Robin
  25.  */
  26. public class GroupGUI extends javax.swing.JFrame {
  27.  
  28.     private Group group;
  29.     private StyledDocument doc;
  30.     private boolean dispRomText = true;
  31.     private boolean dispHanText = true;
  32.     private boolean dispJapText = true;
  33.     private boolean dispEngText = true;
  34.    
  35.  
  36.     /**
  37.      * Creates new form GroupGUI
  38.      */
  39.     public GroupGUI() {
  40.         initComponents();
  41.         setLocationRelativeTo(null);
  42.  
  43.         txtLyrics.setEditable(false);
  44.         doc = txtLyrics.getStyledDocument();
  45.         SimpleAttributeSet center = new SimpleAttributeSet();
  46.         StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
  47.         doc.setParagraphAttributes(0, doc.getLength(), center, false);
  48.  
  49.         group = new Group("Twice");
  50.         for (Album a : group.getAlbums()) {
  51.             cmbAlbum.addItem(a.getName());
  52.         }
  53.        
  54.         chkRom.setSelected(true);
  55.         chkKrJp.setSelected(true);
  56.         chkEng.setSelected(true);
  57.         setColours();
  58.  
  59.         /*String bip = "Song.mp3";
  60.         Media hit = new Media(new File(bip).toURI().toString());
  61.         MediaPlayer mediaPlayer = new MediaPlayer(hit);
  62.         mediaPlayer.play();*/
  63.     }
  64.  
  65.     /**
  66.      * This method is called from within the constructor to initialize the form.
  67.      * WARNING: Do NOT modify this code. The content of this method is always
  68.      * regenerated by the Form Editor.
  69.      */
  70.     @SuppressWarnings("unchecked")
  71.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  72.     private void initComponents() {
  73.  
  74.         jLabel1 = new javax.swing.JLabel();
  75.         lblCover = new javax.swing.JLabel();
  76.         lblAlbum = new javax.swing.JLabel();
  77.         lblSong = new javax.swing.JLabel();
  78.         cmbAlbum = new javax.swing.JComboBox<>();
  79.         cmbSong = new javax.swing.JComboBox<>();
  80.         jScrollPane1 = new javax.swing.JScrollPane();
  81.         txtLyrics = new javax.swing.JTextPane();
  82.         chkRom = new javax.swing.JCheckBox();
  83.         chkKrJp = new javax.swing.JCheckBox();
  84.         chkEng = new javax.swing.JCheckBox();
  85.  
  86.         jLabel1.setText("jLabel1");
  87.  
  88.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  89.         setBackground(new java.awt.Color(255, 255, 255));
  90.         setForeground(java.awt.Color.white);
  91.         setPreferredSize(new java.awt.Dimension(600, 600));
  92.         setResizable(false);
  93.         getContentPane().setLayout(null);
  94.  
  95.         lblCover.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
  96.         lblCover.setMaximumSize(new java.awt.Dimension(300, 300));
  97.         lblCover.setMinimumSize(new java.awt.Dimension(300, 300));
  98.         lblCover.setName(""); // NOI18N
  99.         lblCover.setPreferredSize(new java.awt.Dimension(300, 300));
  100.         getContentPane().add(lblCover);
  101.         lblCover.setBounds(295, 0, 300, 300);
  102.  
  103.         lblAlbum.setFont(new java.awt.Font("Dialog", 1, 13)); // NOI18N
  104.         lblAlbum.setText("Album:");
  105.         getContentPane().add(lblAlbum);
  106.         lblAlbum.setBounds(10, 13, 45, 18);
  107.  
  108.         lblSong.setFont(new java.awt.Font("Dialog", 1, 13)); // NOI18N
  109.         lblSong.setText("Song:");
  110.         getContentPane().add(lblSong);
  111.         lblSong.setBounds(9, 53, 37, 18);
  112.  
  113.         cmbAlbum.setFont(new java.awt.Font("Dialog", 0, 11)); // NOI18N
  114.         cmbAlbum.addActionListener(new java.awt.event.ActionListener() {
  115.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  116.                 cmbAlbumActionPerformed(evt);
  117.             }
  118.         });
  119.         getContentPane().add(cmbAlbum);
  120.         cmbAlbum.setBounds(60, 10, 230, 25);
  121.  
  122.         cmbSong.setFont(new java.awt.Font("Dialog", 0, 11)); // NOI18N
  123.         cmbSong.addActionListener(new java.awt.event.ActionListener() {
  124.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  125.                 cmbSongActionPerformed(evt);
  126.             }
  127.         });
  128.         getContentPane().add(cmbSong);
  129.         cmbSong.setBounds(60, 50, 230, 25);
  130.  
  131.         txtLyrics.setFont(new java.awt.Font("Serif", 0, 20)); // NOI18N
  132.         jScrollPane1.setViewportView(txtLyrics);
  133.  
  134.         getContentPane().add(jScrollPane1);
  135.         jScrollPane1.setBounds(7, 307, 580, 250);
  136.  
  137.         chkRom.setText("Romanized");
  138.         getContentPane().add(chkRom);
  139.         chkRom.setBounds(10, 280, 91, 24);
  140.  
  141.         chkKrJp.setText("Nihongo");
  142.         getContentPane().add(chkKrJp);
  143.         chkKrJp.setBounds(100, 280, 74, 24);
  144.  
  145.         chkEng.setText("English");
  146.         getContentPane().add(chkEng);
  147.         chkEng.setBounds(173, 280, 69, 24);
  148.  
  149.         pack();
  150.     }// </editor-fold>                        
  151.  
  152.     private void cmbAlbumActionPerformed(java.awt.event.ActionEvent evt) {                                        
  153.         // TODO add your handling code here:
  154.         lblCover.setIcon(new ImageIcon(("Covers\\" + (cmbAlbum.getSelectedItem()) + " Cover.png").trim()));
  155.         setColours();
  156.  
  157.         for (Album a : group.getAlbums()) {
  158.             if (a.getName().equals(cmbAlbum.getSelectedItem())) {
  159.                 cmbSong.removeAllItems();
  160.                 for (Song s : a.getSongs()) {
  161.                     cmbSong.addItem(s.getName());
  162.                 }
  163.             }
  164.         }
  165.     }                                        
  166.  
  167.     private void cmbSongActionPerformed(java.awt.event.ActionEvent evt) {                                        
  168.         // TODO add your handling code here:
  169.         updateText();
  170.     }                                      
  171.  
  172.     private void setColours() {
  173.         for (Album a : group.getAlbums()) {
  174.             if (a.getName().equals((String) cmbAlbum.getSelectedItem())) {
  175.                 this.getContentPane().setBackground(new Color(a.getColour().get(0), a.getColour().get(1), a.getColour().get(2)));
  176.                 //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)));
  177.                 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)));
  178.                 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)));
  179.                 if (!(a.getColour().get(0) == 255 && a.getColour().get(1) == 255 && a.getColour().get(2) == 255)) {
  180.                     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)));
  181.                     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)));
  182.                 } else {
  183.                     lblAlbum.setForeground(Color.BLACK);
  184.                     lblSong.setForeground(Color.BLACK);
  185.                 }
  186.  
  187.             }
  188.         }
  189.     }
  190.  
  191.     private void updateText() {
  192.         txtLyrics.setText("");
  193.         boolean setText = false;
  194.         for (Album a : group.getAlbums()) {
  195.             for (Song s : a.getSongs()) {
  196.                 if (s.getName().equals(cmbSong.getSelectedItem()) && !setText) {
  197.                     int index = 0;
  198.                     for (String str : s.lyrics) {
  199.                         try {
  200.                             if (index == 0) {
  201.                                 doc.insertString(doc.getLength(), "[ROMANIZED]\n\n", null);
  202.                                 doc.insertString(doc.getLength(), str + "\n\n", null);
  203.                             } else if (index == 1) {
  204.                                 if (!(s.getName().contains("Jap") || a.getName().equals("One More Time"))) {
  205.                                     doc.insertString(doc.getLength(), "[HANGUL]\n\n", null);
  206.                                 } else {
  207.                                     doc.insertString(doc.getLength(), "[NIHONGO]\n\n", null);
  208.                                 }
  209.                                 doc.insertString(doc.getLength(), str + "\n\n", null);
  210.                             } else {
  211.                                 doc.insertString(doc.getLength(), "[ENGLISH]\n\n", null);
  212.                                 doc.insertString(doc.getLength(), str, null);
  213.                             }
  214.                             txtLyrics.setCaretPosition(0);
  215.                             ++index;
  216.                         } catch (Exception e) {
  217.                             JOptionPane.showMessageDialog(this, "Error", "Something went wrong while getting ahold of the lyrics", JOptionPane.ERROR_MESSAGE);
  218.                         }
  219.                     }
  220.                     setText = true;
  221.                 }
  222.             }
  223.         }
  224.     }
  225.    
  226.     private void updateCheckBoxes() {
  227.        
  228.        
  229.         String tempStr = (String) cmbSong.getSelectedItem();
  230.         System.out.println(cmbAlbum.getSelectedItem());
  231.         System.out.println("-"+tempStr);
  232.        
  233.         for (Album a : group.getAlbums()) {
  234.             for (Song s : a.getSongs()) {
  235.                     if (s.getName().equals(cmbSong.getSelectedItem()) && s.getIsJap()) {
  236.                         chkKrJp.setText("Nihongo");
  237.                     } else {
  238.                         chkKrJp.setText("Hangul");
  239.                     }
  240.             }
  241.         }
  242.     }
  243.    
  244.     /*private void useTitleFont() {
  245.         StyleConstants.setFontFamily(aSet, titleFont.getFamily());
  246.         StyleConstants.setFontSize(aSet, titleFont.getSize());
  247.         doc.setParagraphAttributes(0, 0, aSet, false);
  248.     }
  249.  
  250.     private void useTextFont() {
  251.         StyleConstants.setFontFamily(aSet, textFont.getFamily());
  252.         StyleConstants.setFontSize(aSet, textFont.getSize());
  253.         doc.setParagraphAttributes(0, 0, aSet, false);
  254.     }*/
  255.     /**
  256.      * @param args the command line arguments
  257.      */
  258.     public static void main(String args[]) {
  259.         /* Set the Nimbus look and feel */
  260.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  261.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  262.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  263.          */
  264.         try {
  265.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  266.                 if ("Nimbus".equals(info.getName())) {
  267.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  268.                     break;
  269.                 }
  270.             }
  271.         } catch (ClassNotFoundException ex) {
  272.             java.util.logging.Logger.getLogger(GroupGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  273.         } catch (InstantiationException ex) {
  274.             java.util.logging.Logger.getLogger(GroupGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  275.         } catch (IllegalAccessException ex) {
  276.             java.util.logging.Logger.getLogger(GroupGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  277.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  278.             java.util.logging.Logger.getLogger(GroupGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  279.         }
  280.         //</editor-fold>
  281.  
  282.         /* Create and display the form */
  283.         java.awt.EventQueue.invokeLater(new Runnable() {
  284.             public void run() {
  285.                 new GroupGUI().setVisible(true);
  286.             }
  287.         });
  288.     }
  289.  
  290.     // Variables declaration - do not modify                    
  291.     private javax.swing.JCheckBox chkEng;
  292.     private javax.swing.JCheckBox chkKrJp;
  293.     private javax.swing.JCheckBox chkRom;
  294.     private javax.swing.JComboBox<String> cmbAlbum;
  295.     private javax.swing.JComboBox<String> cmbSong;
  296.     private javax.swing.JLabel jLabel1;
  297.     private javax.swing.JScrollPane jScrollPane1;
  298.     private javax.swing.JLabel lblAlbum;
  299.     private javax.swing.JLabel lblCover;
  300.     private javax.swing.JLabel lblSong;
  301.     private javax.swing.JTextPane txtLyrics;
  302.     // End of variables declaration                  
  303. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement