Guest User

Maintenanca.java

a guest
Oct 12th, 2011
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 26.71 KB | None | 0 0
  1. package maintenance;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Desktop;
  5. import java.io.IOException;
  6. import java.net.URI;
  7. import java.net.URISyntaxException;
  8. import javax.swing.JOptionPane;
  9. import javax.swing.SwingWorker;
  10.  
  11. /**
  12.  *
  13.  * @author Tim
  14.  */
  15. public final class Maintenance extends javax.swing.JFrame {
  16.  
  17.     /**
  18.      * @access private
  19.      * The thread
  20.      */
  21.     private SwingWorker<Integer, Integer> worker;
  22.     /**
  23.      * @access private
  24.      * Whether S4 is online or not
  25.      */
  26.     private boolean s4 = false;
  27.     /**
  28.      * @access private
  29.      * Whether LOCO is online or not
  30.      */
  31.     private boolean loco = false;
  32.     /**
  33.      * @access private
  34.      * If a first check has been done or not.
  35.      */
  36.     private boolean firstCheck = false;
  37.     /**
  38.      * @access private
  39.      * The amount of miliseconds, needed to check if a maintenance check is needed.
  40.      */
  41.     private int timer = 999999;
  42.     /**
  43.      * @access private
  44.      * Initialize checker class
  45.      */
  46.     private Checker check = new Checker();
  47.     /**
  48.      * @access private
  49.      * The delay between each check
  50.      */
  51.     private int globalcheckTime = 10;
  52.     /**
  53.      * @access private
  54.      * Desktop variable, to open browser
  55.      */
  56.     private Desktop desktop;
  57.     /**
  58.      * @access private
  59.      * URI variabe, needed for the browser
  60.      */
  61.     private URI uri = null;
  62.  
  63.     /** Creates new form download and launches it */
  64.     public Maintenance() {
  65.         initComponents(); //initialize components
  66.         setVisible(true); //show GUI
  67.         launch(); //launch the real application
  68.     }
  69.  
  70.     /** This method is called from within the constructor to
  71.      * initialize the form.
  72.      * WARNING: Do NOT modify this code. The content of this method is
  73.      * always regenerated by the Form Editor.
  74.      */
  75.     @SuppressWarnings("unchecked")
  76.     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  77.     private void initComponents() {
  78.  
  79.         title = new javax.swing.JLabel();
  80.         jSeparator1 = new javax.swing.JSeparator();
  81.         jLabel1 = new javax.swing.JLabel();
  82.         jPanel1 = new javax.swing.JPanel();
  83.         s4_status = new javax.swing.JLabel();
  84.         s4chat = new javax.swing.JButton();
  85.         jPanel2 = new javax.swing.JPanel();
  86.         loco_status = new javax.swing.JLabel();
  87.         locochat = new javax.swing.JButton();
  88.         jPanel3 = new javax.swing.JPanel();
  89.         top = new javax.swing.JCheckBox();
  90.         checks4 = new javax.swing.JCheckBox();
  91.         checkloco = new javax.swing.JCheckBox();
  92.         checktime = new javax.swing.JSpinner();
  93.         jLabel3 = new javax.swing.JLabel();
  94.         jLabel2 = new javax.swing.JLabel();
  95.         load = new javax.swing.JProgressBar();
  96.         chat = new javax.swing.JButton();
  97.         alachat = new javax.swing.JButton();
  98.         alaflash = new javax.swing.JButton();
  99.  
  100.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  101.         setTitle("GameSig Online  Maintenance Checker");
  102.         setBackground(new java.awt.Color(255, 255, 255));
  103.         setForeground(new java.awt.Color(255, 255, 255));
  104.         setName("frame"); // NOI18N
  105.         setResizable(false);
  106.  
  107.         title.setFont(new java.awt.Font("Myriad Pro", 0, 36)); // NOI18N
  108.         title.setIcon(new javax.swing.ImageIcon("C:\\Users\\Tim\\Documents\\GameSig\\images\\logo.png")); // NOI18N
  109.         title.setText("GameSig");
  110.         title.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
  111.         title.setDoubleBuffered(true);
  112.         title.addMouseListener(new java.awt.event.MouseAdapter() {
  113.             public void mouseClicked(java.awt.event.MouseEvent evt) {
  114.                 titleMouseClicked(evt);
  115.             }
  116.         });
  117.  
  118.         jLabel1.setFont(new java.awt.Font("Kokila", 0, 18));
  119.         jLabel1.setText("The Online Maintenance Checker");
  120.         jLabel1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
  121.  
  122.         jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "S4 League", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 14), new java.awt.Color(0, 0, 0))); // NOI18N
  123.  
  124.         s4_status.setFont(new java.awt.Font("Tahoma", 0, 18));
  125.         s4_status.setForeground(new java.awt.Color(255, 0, 0));
  126.         s4_status.setText("S4 is offline!");
  127.  
  128.         s4chat.setText("S4 Chat");
  129.         s4chat.setEnabled(false);
  130.         s4chat.setMaximumSize(new java.awt.Dimension(87, 23));
  131.         s4chat.setMinimumSize(new java.awt.Dimension(87, 23));
  132.         s4chat.setPreferredSize(new java.awt.Dimension(87, 23));
  133.         s4chat.addActionListener(new java.awt.event.ActionListener() {
  134.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  135.                 s4chatActionPerformed(evt);
  136.             }
  137.         });
  138.  
  139.         javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  140.         jPanel1.setLayout(jPanel1Layout);
  141.         jPanel1Layout.setHorizontalGroup(
  142.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  143.             .addGroup(jPanel1Layout.createSequentialGroup()
  144.                 .addContainerGap()
  145.                 .addComponent(s4_status)
  146.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 66, Short.MAX_VALUE)
  147.                 .addComponent(s4chat, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
  148.                 .addContainerGap())
  149.         );
  150.         jPanel1Layout.setVerticalGroup(
  151.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  152.             .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  153.                 .addComponent(s4_status)
  154.                 .addComponent(s4chat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  155.         );
  156.  
  157.         jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "LOCO", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 14), new java.awt.Color(0, 0, 0))); // NOI18N
  158.  
  159.         loco_status.setFont(new java.awt.Font("Tahoma", 0, 18));
  160.         loco_status.setForeground(new java.awt.Color(255, 0, 0));
  161.         loco_status.setText("LOCO is offline!");
  162.  
  163.         locochat.setText("LOCO Chat");
  164.         locochat.setEnabled(false);
  165.         locochat.addActionListener(new java.awt.event.ActionListener() {
  166.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  167.                 locochatActionPerformed(evt);
  168.             }
  169.         });
  170.  
  171.         javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
  172.         jPanel2.setLayout(jPanel2Layout);
  173.         jPanel2Layout.setHorizontalGroup(
  174.             jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  175.             .addGroup(jPanel2Layout.createSequentialGroup()
  176.                 .addContainerGap()
  177.                 .addComponent(loco_status)
  178.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 49, Short.MAX_VALUE)
  179.                 .addComponent(locochat)
  180.                 .addContainerGap())
  181.         );
  182.         jPanel2Layout.setVerticalGroup(
  183.             jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  184.             .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  185.                 .addComponent(loco_status)
  186.                 .addComponent(locochat))
  187.         );
  188.  
  189.         jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Settings", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 14))); // NOI18N
  190.  
  191.         top.setText("Always on top");
  192.         top.addChangeListener(new javax.swing.event.ChangeListener() {
  193.             public void stateChanged(javax.swing.event.ChangeEvent evt) {
  194.                 topStateChanged(evt);
  195.             }
  196.         });
  197.  
  198.         checks4.setSelected(true);
  199.         checks4.setText("Check S4 League");
  200.  
  201.         checkloco.setSelected(true);
  202.         checkloco.setText("Check LOCO");
  203.  
  204.         checktime.setModel(new javax.swing.SpinnerNumberModel(30, 10, 60, 10));
  205.         checktime.setToolTipText("");
  206.  
  207.         jLabel3.setText("Check every:");
  208.  
  209.         javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
  210.         jPanel3.setLayout(jPanel3Layout);
  211.         jPanel3Layout.setHorizontalGroup(
  212.             jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  213.             .addGroup(jPanel3Layout.createSequentialGroup()
  214.                 .addContainerGap()
  215.                 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  216.                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
  217.                         .addComponent(jLabel3)
  218.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
  219.                         .addComponent(checktime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  220.                     .addComponent(top)
  221.                     .addComponent(checks4)
  222.                     .addComponent(checkloco))
  223.                 .addContainerGap())
  224.         );
  225.         jPanel3Layout.setVerticalGroup(
  226.             jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  227.             .addGroup(jPanel3Layout.createSequentialGroup()
  228.                 .addComponent(top)
  229.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  230.                 .addComponent(checks4)
  231.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  232.                 .addComponent(checkloco)
  233.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  234.                 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  235.                     .addComponent(checktime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  236.                     .addComponent(jLabel3))
  237.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  238.         );
  239.  
  240.         jLabel2.setText("Next check in:");
  241.  
  242.         load.setToolTipText("");
  243.         load.setString("0 seconds");
  244.         load.setStringPainted(true);
  245.  
  246.         chat.setText("GameSig Chat");
  247.         chat.setEnabled(false);
  248.         chat.setMaximumSize(new java.awt.Dimension(125, 23));
  249.         chat.setMinimumSize(new java.awt.Dimension(125, 23));
  250.         chat.setPreferredSize(new java.awt.Dimension(125, 23));
  251.         chat.addActionListener(new java.awt.event.ActionListener() {
  252.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  253.                 chatActionPerformed(evt);
  254.             }
  255.         });
  256.  
  257.         alachat.setText("alaplaya Chat");
  258.         alachat.setEnabled(false);
  259.         alachat.setMinimumSize(new java.awt.Dimension(125, 23));
  260.         alachat.setPreferredSize(new java.awt.Dimension(125, 23));
  261.         alachat.addActionListener(new java.awt.event.ActionListener() {
  262.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  263.                 alachatActionPerformed(evt);
  264.             }
  265.         });
  266.  
  267.         alaflash.setText("alaplaya flash Chat");
  268.         alaflash.setEnabled(false);
  269.         alaflash.addActionListener(new java.awt.event.ActionListener() {
  270.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  271.                 alaflashActionPerformed(evt);
  272.             }
  273.         });
  274.  
  275.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  276.         getContentPane().setLayout(layout);
  277.         layout.setHorizontalGroup(
  278.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  279.             .addGroup(layout.createSequentialGroup()
  280.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  281.                     .addGroup(layout.createSequentialGroup()
  282.                         .addGap(105, 105, 105)
  283.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  284.                             .addComponent(title)
  285.                             .addGroup(layout.createSequentialGroup()
  286.                                 .addGap(20, 20, 20)
  287.                                 .addComponent(jLabel1))))
  288.                     .addGroup(layout.createSequentialGroup()
  289.                         .addContainerGap()
  290.                         .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 438, Short.MAX_VALUE))
  291.                     .addGroup(layout.createSequentialGroup()
  292.                         .addContainerGap()
  293.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  294.                             .addComponent(load, javax.swing.GroupLayout.DEFAULT_SIZE, 438, Short.MAX_VALUE)
  295.                             .addGroup(layout.createSequentialGroup()
  296.                                 .addComponent(jLabel2)
  297.                                 .addGap(260, 260, 260))
  298.                             .addGroup(layout.createSequentialGroup()
  299.                                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  300.                                     .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  301.                                     .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  302.                                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  303.                                         .addComponent(chat, javax.swing.GroupLayout.DEFAULT_SIZE, 137, Short.MAX_VALUE)
  304.                                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  305.                                         .addComponent(alachat, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)))
  306.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  307.                                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  308.                                     .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  309.                                     .addComponent(alaflash))))))
  310.                 .addContainerGap())
  311.         );
  312.         layout.setVerticalGroup(
  313.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  314.             .addGroup(layout.createSequentialGroup()
  315.                 .addComponent(title)
  316.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  317.                 .addComponent(jLabel1)
  318.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  319.                 .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE)
  320.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  321.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  322.                     .addGroup(layout.createSequentialGroup()
  323.                         .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  324.                         .addGap(10, 10, 10)
  325.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE, false)
  326.                             .addComponent(chat, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
  327.                             .addComponent(alachat, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
  328.                             .addComponent(alaflash, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
  329.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  330.                         .addComponent(jLabel2))
  331.                     .addGroup(layout.createSequentialGroup()
  332.                         .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  333.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  334.                         .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
  335.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  336.                 .addComponent(load, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
  337.                 .addContainerGap())
  338.         );
  339.  
  340.         pack();
  341.     }// </editor-fold>//GEN-END:initComponents
  342.  
  343.     /**
  344.      * @return void
  345.      * @param evt
  346.      * This will be executed when the "stay on top" checkbox changes. It will place the application or it will disable it.
  347.      */
  348. private void topStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_topStateChanged
  349.     boolean state = top.isSelected(); //if selected, true, otherwise false.
  350.     if (state) {
  351.         setAlwaysOnTop(true); //if selected, always on top
  352.     } else {
  353.         setAlwaysOnTop(false); //if not selected, not always on top
  354.     }
  355. }//GEN-LAST:event_topStateChanged
  356.  
  357.     /**
  358.      * @return  void
  359.      * @param evt
  360.      * This will be executed when the GameSig chat button is clicked. Will open a browser and the chat page.
  361.      */
  362. private void chatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chatActionPerformed
  363.     browse("http://webchat.euirc.net/?nick=GameSig..&channels=GameSig"); //open this page
  364. }//GEN-LAST:event_chatActionPerformed
  365.  
  366.     /**
  367.      * @return  void
  368.      * @param evt
  369.      * This will be executed when the s4 chat button is clicked. Will open a browser and the chat page.
  370.      */
  371. private void s4chatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_s4chatActionPerformed
  372.     browse("http://webchat.euirc.net/?nick=GameSig..&channels=s4league"); //open this page
  373. }//GEN-LAST:event_s4chatActionPerformed
  374.  
  375.     /**
  376.      * @return  void
  377.      * @param evt
  378.      * This will be executed when the loco chat button is clicked. Will open a browser and the chat page.
  379.      */
  380. private void locochatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_locochatActionPerformed
  381.     browse("http://webchat.euirc.net/?nick=loco..&channels=GameSig"); //open this page
  382. }//GEN-LAST:event_locochatActionPerformed
  383.  
  384.     /**
  385.      * @return  void
  386.      * @param evt
  387.      * This will be executed when the alaplaya chat button is clicked. Will open a browser and the chat page.
  388.      */
  389. private void alachatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_alachatActionPerformed
  390.     browse("http://webchat.euirc.net/?nick=GameSig..&channels=alaplaya"); //open this page
  391. }//GEN-LAST:event_alachatActionPerformed
  392.  
  393.     /**
  394.      * @return  void
  395.      * @param evt
  396.      * This will be executed when the alaplaya flash chat button is clicked. Will open a browser and the chat page.
  397.      */
  398. private void alaflashActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_alaflashActionPerformed
  399.     browse("http://alaplaya.net/chat"); //open this page
  400. }//GEN-LAST:event_alaflashActionPerformed
  401.  
  402. private void titleMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_titleMouseClicked
  403.     browse("http://www.gamesig.net"); //open this page
  404. }//GEN-LAST:event_titleMouseClicked
  405.  
  406.     /**
  407.      * @param args the command line arguments
  408.      * @return void
  409.      * Will start the application
  410.      */
  411.     public static void main(String args[]) {
  412.         java.awt.EventQueue.invokeLater(new Runnable() {
  413.  
  414.             public void run() {
  415.                 Maintenance maint = new Maintenance(); //start application
  416.             }
  417.         });
  418.     }
  419.  
  420.     /**
  421.      * @return void
  422.      * First it will check if the browser can be opened. Then it will do a check for LOCO and S4. After that it will create a Thread to keep checking S4 and LOCO if neccesary
  423.      */
  424.     public void launch() {
  425.  
  426.         if (Desktop.isDesktopSupported()) { //check if Desktop is supported
  427.             desktop = Desktop.getDesktop(); //create desktop
  428.             if (desktop.isSupported(Desktop.Action.BROWSE)) { //check if browser is supported
  429.                 enableButtons();
  430.             } else {
  431.                 changeTextButtons();
  432.             }
  433.         }
  434.  
  435.         worker = new SwingWorker<Integer, Integer>() { //create Thread
  436.  
  437.             /**
  438.              * @return int nothing of any value
  439.              * Will do a check and update the loadbar as long as LOCO and S4 are both offline
  440.              */
  441.             @Override
  442.             protected Integer doInBackground() {
  443.                 while (!s4 && !loco) { //while both games are offline
  444.                     doCheck();
  445.                     updateBar();
  446.                     try {
  447.                         Thread.sleep(100);
  448.                         firstCheck = true;
  449.                     } catch (InterruptedException ex) {
  450.                     }
  451.                 }
  452.                 load.setString("All games are online!"); //change the text in the progressbar
  453.                 worker.cancel(true); //stop the Thread
  454.                 return 100;
  455.             }
  456.  
  457.             /**
  458.              * @return void
  459.              * Changes the global time. Adds 1 to the timer. Calculates if needed to check, if so, do a check.
  460.              */
  461.             private void doCheck() {
  462.                 globalcheckTime = Integer.valueOf(checktime.getValue().toString()).intValue(); //get value from the spinner
  463.                 timer++;
  464.                 boolean[] array;
  465.                 if (timer >= globalcheckTime * 10) {
  466.                     timer = 0;
  467.                     array = check.checkGames(); //get array of the status of GameSig and the games
  468.                     if (!array[0]) { //GameSig is offline
  469.                         JOptionPane.showMessageDialog(rootPane, "Oops, it appears that GameSig is offline! Try again later!");
  470.                     } else {
  471.                         doS4(array[1]);
  472.                         doLoco(array[2]);
  473.                     }
  474.                 }
  475.             }
  476.         };
  477.         worker.execute(); //run Thread
  478.     }
  479.  
  480.     /**
  481.      * @return void
  482.      * Will update the progress bar
  483.      */
  484.     private void updateBar() {
  485.         load.setString(globalcheckTime - timer / 10 + " seconds");
  486.         load.setValue(timer * 10 / globalcheckTime);
  487.     }
  488.  
  489.     /**
  490.      *
  491.      * @param result boolean if S4 is online or not.
  492.      * @return void
  493.      * Will give a warning is S4 was offline and turns online. Will set text to offline if S4 is offline.
  494.      */
  495.     private void doS4(boolean result) {
  496.         if (!s4 && checks4.isSelected()) {
  497.             if (result) {
  498.                 s4_status.setText("S4 is online!");
  499.                 s4_status.setForeground(Color.GREEN);
  500.                 s4 = true;
  501.                 if (firstCheck) {
  502.                     setAlwaysOnTop(true); //make sure popup gets th attention
  503.                     JOptionPane.showMessageDialog(rootPane, "S4 is back online!!!");
  504.                     if (!top.isSelected()) {
  505.                         setAlwaysOnTop(false); //disable it again
  506.                     }
  507.                 }
  508.             }
  509.         }
  510.     }
  511.  
  512.     /**
  513.      *
  514.      * @param result boolean if LOCO is online or not.
  515.      * @return void
  516.      * Will give a warning is LOCO was offline and turns online. Will set text to offline if LOCO is offline.
  517.      */
  518.     private void doLoco(boolean result) {
  519.         if (!loco && checkloco.isSelected()) {
  520.             if (result) {
  521.                 loco_status.setText("LOCO is online!");
  522.                 loco_status.setForeground(Color.GREEN);
  523.                 loco = true;
  524.                 if (firstCheck) {
  525.                     setAlwaysOnTop(true); //make sure popup gets th attention
  526.                     JOptionPane.showMessageDialog(rootPane, "LOCO is back online!!!");
  527.                     if (!top.isSelected()) {
  528.                         setAlwaysOnTop(false); //disable it again
  529.                     }
  530.                 }
  531.             }
  532.         }
  533.     }
  534.  
  535.     /**
  536.      *
  537.      * @param link the url of the page that needs to be opened
  538.      * @return void
  539.      * Will open the link in the browser
  540.      */
  541.     private void browse(String link) {
  542.         try {
  543.             uri = new URI(link); //create new URI
  544.             desktop.browse(uri); //open browser and page
  545.         } catch (IOException ioe) {
  546.         } catch (URISyntaxException use) {
  547.         }
  548.     }
  549.  
  550.     /*
  551.      * @return void
  552.      * Will set the buttons to N/A in case a browser can't be opened.
  553.      */
  554.     private void changeTextButtons() {
  555.         alachat.setText("N/A");
  556.         alaflash.setText("N/A");
  557.         chat.setText("N/A");
  558.         s4chat.setText("N/A");
  559.         locochat.setText("N/A");
  560.     }
  561.  
  562.     /*
  563.      * @return void
  564.      * Will enable the butons in case a browser can be opened.
  565.      */
  566.     private void enableButtons() {
  567.         alachat.setEnabled(true);
  568.         alaflash.setEnabled(true);
  569.         chat.setEnabled(true);
  570.         s4chat.setEnabled(true);
  571.         locochat.setEnabled(true);
  572.     }
  573.     // Variables declaration - do not modify//GEN-BEGIN:variables
  574.     private javax.swing.JButton alachat;
  575.     private javax.swing.JButton alaflash;
  576.     private javax.swing.JButton chat;
  577.     private javax.swing.JCheckBox checkloco;
  578.     private javax.swing.JCheckBox checks4;
  579.     private javax.swing.JSpinner checktime;
  580.     private javax.swing.JLabel jLabel1;
  581.     private javax.swing.JLabel jLabel2;
  582.     private javax.swing.JLabel jLabel3;
  583.     private javax.swing.JPanel jPanel1;
  584.     private javax.swing.JPanel jPanel2;
  585.     private javax.swing.JPanel jPanel3;
  586.     private javax.swing.JSeparator jSeparator1;
  587.     private javax.swing.JProgressBar load;
  588.     private javax.swing.JLabel loco_status;
  589.     private javax.swing.JButton locochat;
  590.     private javax.swing.JLabel s4_status;
  591.     private javax.swing.JButton s4chat;
  592.     private javax.swing.JLabel title;
  593.     private javax.swing.JCheckBox top;
  594.     // End of variables declaration//GEN-END:variables
  595. }
  596.  
  597.  
Advertisement
Add Comment
Please, Sign In to add comment