⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainframe.java

📁 JStock是一个免费股市软件
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        return realTimeStockMonitor;
    }
    
    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
// TODO add your handling code here:
        if(getStockCodeAndSymbolDatabase() == null) {
            javax.swing.JOptionPane.showMessageDialog(this, "We haven't connected to stock server.", "Not Connected", javax.swing.JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        
        JFileChooser fc = new JFileChooser();
        fc.setAcceptAllFileFilterUsed(false);
        fc.addChoosableFileFilter(new MyFilter());
        int returnVal = fc.showOpenDialog(this);

        if (returnVal != JFileChooser.APPROVE_OPTION) {
            return;            
        }
        
        File file = fc.getSelectedFile();
        if(file.getName().endsWith(".xls")) {
            loadFromExcelFile(file);
        }
        else if(file.getName().endsWith(".txt")) {
            loadFromTextFile(file);
        }                       
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private static class MyFilter extends javax.swing.filechooser.FileFilter {
        public boolean accept(File file) {
            if (file.isDirectory()) {
                return true;
            }       
            
            String filename = file.getName();
            return filename.endsWith(".xls") || filename.endsWith(".txt");
        }
        
        public String getDescription() {
            return "Text file or Microsoft Excel";
        }
    }
    
    // Policy : Each pane should have their own real time stock monitoring.
    //
    //          Each pane should share history monitoring with main frame, 
    //          for optimized history retrieving purpose.
    //
    private void jTabbedPane1StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jTabbedPane1StateChanged
// TODO add your handling code here:
        JTabbedPane pane = (JTabbedPane)evt.getSource();
        if(pane.getSelectedComponent() == this.jPanel8) {  
            if(realTimeStockMonitor != null) {  
                this.realTimeStockMonitor.softStart();
                this.portfolioManagementJPanel.softStop();
                this.realTimeStockMonitor.attach(this.realTimeStockMonitorObserver);
                log.info("Start real time stock monitor and re-attach observer.");
                log.info("Stop portfolio monitor.");
            }
            if(stockHistoryMonitor != null) {                
                this.stockHistoryMonitor.attach(this.stockHistoryMonitorObserver);
                log.info("Stock history monitor re-attach observer.");
            }            
        }
        else if(pane.getSelectedComponent() == this.indicatorPanel) {
            if(realTimeStockMonitor != null) {                

                // Take note that we will not soft stop indicatorPanel itself, because
                // we wish to get alert all the time, even we are not visually looking
                // at that panel.
                //
                this.realTimeStockMonitor.softStop();
                this.portfolioManagementJPanel.softStop();
                this.realTimeStockMonitor.dettach(this.realTimeStockMonitorObserver);
                log.info("Stop real time stock monitor and dettach observer.");
                log.info("Stop portfolio monitor.");
            }
            if(stockHistoryMonitor != null) {                
                this.stockHistoryMonitor.attach(this.stockHistoryMonitorObserver);
                log.info("Stock history monitor re-attach observer.");
            }                
        }
        else if(pane.getSelectedComponent() == this.indicatorScannerJPanel) {
            if(realTimeStockMonitor != null) {
                this.realTimeStockMonitor.softStop();
                this.portfolioManagementJPanel.softStop();
                this.realTimeStockMonitor.dettach(this.realTimeStockMonitorObserver);
                log.info("Stop real time stock monitor and dettach observer.");
                log.info("Stop portfolio monitor.");
            }
            if(stockHistoryMonitor != null) {  
                /* We need chart history displaying feature, by using help from MainFrame. */
                this.stockHistoryMonitor.attach(this.stockHistoryMonitorObserver);
                log.info("Stock history monitor re-attach observer.");
            }             
        }
        else if(pane.getSelectedComponent() == this.portfolioManagementJPanel) {
            if(realTimeStockMonitor != null) {                
                this.realTimeStockMonitor.softStop();
                this.portfolioManagementJPanel.softStart();
                this.realTimeStockMonitor.dettach(this.realTimeStockMonitorObserver);
                log.info("Stop real time stock monitor and dettach observer.");
                log.info("Start portfolio monitor.");
            }
            if(stockHistoryMonitor != null) {  
                /* We need chart history displaying feature, by using help from MainFrame. */
                this.stockHistoryMonitor.attach(this.stockHistoryMonitorObserver);
                log.info("Stock history monitor re-attach observer.");
            }             
        }
        else if (pane.getSelectedComponent() == this.chatJPanel) {
            if(realTimeStockMonitor != null) {

                // Take note that we will not soft stop indicatorPanel itself, because
                // we wish to get alert all the time, even we are not visually looking
                // at that panel.
                //
                this.realTimeStockMonitor.softStop();
                this.portfolioManagementJPanel.softStop();
                this.realTimeStockMonitor.dettach(this.realTimeStockMonitorObserver);
                log.info("Stop real time stock monitor and dettach observer.");
                log.info("Stop portfolio monitor.");
            }
            if(stockHistoryMonitor != null) {
                this.stockHistoryMonitor.attach(this.stockHistoryMonitorObserver);
                log.info("Stock history monitor re-attach observer.");
            }
        }

        if (pane.getSelectedComponent() == this.chatJPanel)
        {
            if (timer != null)
            {
                timer.stop();
                timer = null;
            }

            // Ensure at the end, we are using smile icon.
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    MainFrame.this.jTabbedPane1.setIconAt(4, smileIcon);
                }
            });
        }
    }//GEN-LAST:event_jTabbedPane1StateChanged


    private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed
// TODO add your handling code here
        OptionsJDialog optionsJDialog = new OptionsJDialog(this, true);
        optionsJDialog.setLocationRelativeTo(this);
        optionsJDialog.set(MainFrame.jStockOptions);
        optionsJDialog.setVisible(true);		
    }//GEN-LAST:event_jMenuItem6ActionPerformed

    public static JStockOptions getJStockOptions() {
        return MainFrame.jStockOptions;
    }
    
    /* Dangerous! We didn't perform proper clean up, because we do not want
     * to give user perspective that our system is slow. But, is it safe
     * to do so?
     */
    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        log.info("Widnow is closed...");
        
        //log.info("stop indicator scanner panel...");
        //this.indicatorScannerJPanel.stop();
        
        //log.info("stop indicator panel...");
        //this.indicatorPanel.stop();

        log.info("saveJStockOptions...");
        this.saveJStockOptions();
        
        log.info("saveBrokingFirmLogos...");
        this.saveBrokingFirmLogos();
        
        log.info("saveRealTimeStocks...");
        this.saveRealTimeStocks();
        
        log.info("saveIndicatorProjectManager...");
        this.indicatorPanel.saveIndicatorProjectManager();

        log.info("savePortfolio...");
        this.portfolioManagementJPanel.savePortfolio();

		log.info("latestNewsTask stop...");
        if(this.latestNewsTask != null)
        {
            this.latestNewsTask.cancel(true);
        }

        //log.info("stockCodeAndSymbolDatabaseTask stop...");
        //stockCodeAndSymbolDatabaseTask._stop();
                
        //try {
        //    stockCodeAndSymbolDatabaseTask.get();
        //}
        //catch(InterruptedException exp) {
        //    log.error("", exp);
        //}
        //catch(java.util.concurrent.ExecutionException exp) {
        //    log.error("", exp);
        //}
        
        //log.info("marketThread stop...");
        //marketThread.interrupt();
        
        //try {
        //    marketThread.join();
        //}
        //catch(InterruptedException exp) {
        //    log.error("", exp);
        //}
        
        //log.info("realTimeStockMonitor stop...");
        //realTimeStockMonitor.stop();
        //log.info("stockHistoryMonitor stop...");
        //stockHistoryMonitor.stop();

        this.chatJPanel.stopChatServiceManager();
        
        if(trayIcon != null)
            SystemTray.getSystemTray().remove(trayIcon);
        
        log.info("Widnow is closed.");
        
        // Final clean up.
        System.exit(0);
    }//GEN-LAST:event_formWindowClosed

    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
        new AboutJDialog(this, true).setVisible(true);
    }//GEN-LAST:event_jMenuItem5ActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
// TODO add your handling code here:
        this.setVisible(false);
        this.dispose();
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void formWindowIconified(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowIconified
// TODO add your handling code here:
        // Calling setVisible(false) will cause modal dialog box to be unblocked
        // for JDialog.setVisible(true). This will happen in Linux system where
        // user are allowed to minimize window even there is a modal JDialog box
        // We have no solution at current moment.
        //

        if (Utils.isWindows())
        {
            this.setVisible(false);
        }
    }//GEN-LAST:event_formWindowIconified

    private void formWindowDeiconified(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowDeiconified
// TODO add your handling code here:
    }//GEN-LAST:event_formWindowDeiconified

    private void formMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseClicked
// TODO add your handling code here:
        this.jTable1.getSelectionModel().clearSelection();
        this.indicatorScannerJPanel.clearTableSelection();
        this.portfolioManagementJPanel.clearTableSelection();
        updateBuyerSellerInformation(null);
    }//GEN-LAST:event_formMouseClicked

    private void jTable1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTable1KeyPressed
// TODO add your handling code here:
        if(KeyEvent.VK_DELETE == evt.getKeyCode()) {
            this.deteleSelectedTableRow();
            return;
        }
        
        if(evt.isActionKey()) {
            int[] rows = MainFrame.this.jTable1.getSelectedRows();
            
            if(rows.length == 1) {
                int row = rows[0];
                
                StockTableModel tableModel = (StockTableModel)jTable1.getModel();
                int modelIndex = jTable1.convertRowIndexToModel(row);
                Stock stock = tableModel.getStock(modelIndex);
                updateBuyerSellerInformation(stock);
            }
            else {
            	updateBuyerSellerInformation(null);
            }
            
            return;
        }
    }//GEN-LAST:event_jTable1KeyPressed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
// TODO add your handling code here:
        log.info("Widnow is closing.");     
    }//GEN-LAST:event_formWindowClosing

    private void jMenu3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenu3ActionPerformed
// TODO add your handling code here:
    }//GEN-LAST:event_jMenu3ActionPerformed

	private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem8ActionPerformed

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -