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

📄 mainframe.java

📁 JStock是一个免费股市软件
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	// TODO add your handling code here:
    	if(this.stockCodeAndSymbolDatabase == null) {
        	JOptionPane.showMessageDialog(this, "There are no database ready yet.", "Database not ready", JOptionPane.INFORMATION_MESSAGE);
        	return;
    	}
    
    	StockDatabaseJDialog stockDatabaseJDialog = new StockDatabaseJDialog(this, stockCodeAndSymbolDatabase, true);
    	stockDatabaseJDialog.setSize(540, 540);
    	stockDatabaseJDialog.setLocationRelativeTo(this);
    	stockDatabaseJDialog.setVisible(true); 
    
    	if(stockDatabaseJDialog.getMutableStockCodeAndSymbolDatabase() != null) {
        	this.stockCodeAndSymbolDatabase = stockDatabaseJDialog.getMutableStockCodeAndSymbolDatabase().toStockCodeAndSymbolDatabase();
        	((AutoCompleteJComboBox)jComboBox1).setStockCodeAndSymbolDatabase(stockCodeAndSymbolDatabase);
        	indicatorPanel.setStockCodeAndSymbolDatabase(stockCodeAndSymbolDatabase);        
        
        	log.info("saveStockCodeAndSymbolDatabase...");
        	saveStockCodeAndSymbolDatabase();        
    	}
	}//GEN-LAST:event_jMenuItem8ActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Workaround to solve JXTreeTable look n feel cannot be changed on the fly. */
        initJStockOptions();
        
        try {
            UIManager.setLookAndFeel(MainFrame.getJStockOptions().getLooknFeel());
        }
        catch(java.lang.ClassNotFoundException exp) {
            log.error("", exp);
        }
        catch(java.lang.InstantiationException exp) {
            log.error("", exp);
        }
        catch(java.lang.IllegalAccessException exp) {
            log.error("", exp);
        }
        catch(javax.swing.UnsupportedLookAndFeelException exp) {
            log.error("", exp);
        }
        
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                MainFrame mainFrame = new MainFrame();                
                mainFrame.setExtendedState(Frame.MAXIMIZED_BOTH);
                mainFrame.setVisible(true);               
            }
        });
    }
    
    private void clearAllStocks() {
        assert(java.awt.EventQueue.isDispatchThread());
        
        StockTableModel tableModel = (StockTableModel)jTable1.getModel();            

        if(stockCodeHistoryGUI != null) stockCodeHistoryGUI.clear();
        if(realTimeStockMonitor != null) realTimeStockMonitor.clearStockCodes();
        if(stockHistoryMonitor != null) stockHistoryMonitor.clearStockCodes();
        tableModel.clearAllStocks();     
        
        updateBuyerSellerInformation(null);
        
        if(stockCodeHistoryGUI != null) {
            if(stockCodeHistoryGUI.size() == 0) {
                if(this.stockCodeAndSymbolDatabase != null) {
                    statusBar.setProgressBar(false);
                    statusBar.setMainMessage("Connected");
                }
            }        
        }
    }
    
    // Should we synchronized the jTable1, or post the job at GUI event dispatch
    // queue?    
    private void deteleSelectedTableRow() {
        assert(java.awt.EventQueue.isDispatchThread());
        
        StockTableModel tableModel = (StockTableModel)jTable1.getModel();

        int rows[] = jTable1.getSelectedRows();

        Arrays.sort(rows);

        for(int i=rows.length-1; i>=0; i--) {                
            int row = rows[i];

            if(row < 0) continue;

            final int modelIndex = jTable1.getRowSorter().convertRowIndexToModel(row);
            Stock stock = tableModel.getStock(modelIndex);
            stockCodeHistoryGUI.remove(stock.getCode());
            realTimeStockMonitor.removeStockCode(stock.getCode());
            stockHistoryMonitor.removeStockCode(stock.getCode());
            tableModel.removeRow(modelIndex);
        }            
        
        updateBuyerSellerInformation(null);
        
        if(stockCodeHistoryGUI.size() == 0) {
            if(this.stockCodeAndSymbolDatabase != null) {
                statusBar.setProgressBar(false);
                statusBar.setMainMessage("Connected");
            }
        }
    }
    
    public void setStatusBar(final boolean progressBar, final String mainMessage) {
        if (SwingUtilities.isEventDispatchThread())
        {
            statusBar.setProgressBar(progressBar);
            statusBar.setMainMessage(mainMessage);
        }
        else
        {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    statusBar.setProgressBar(progressBar);
                    statusBar.setMainMessage(mainMessage);
                }
            });
        }
    }
    
    class ChangeLookAndFeelAction extends AbstractAction {
        MainFrame mainFrame;
        String lafClassName;
  
        protected ChangeLookAndFeelAction(MainFrame mainFrame, String lafClassName) {
            super("ChangeTheme");
            this.mainFrame = mainFrame;
            this.lafClassName = lafClassName;
        }
  
        public String getLafClassName() {
            return lafClassName;
        }
        
        public void actionPerformed(ActionEvent e) {
            mainFrame.setLookAndFeel(lafClassName);
        }
    }
  
    public void setLookAndFeel(String lafClassName) {
	/* Backward compataible purpose. Old JStockOptions may contain null in this field. */
        if(lafClassName == null)
            return;
        
        try {
            UIManager.setLookAndFeel(lafClassName);
            SwingUtilities.updateComponentTreeUI(this);
        }
        catch(java.lang.ClassNotFoundException exp) {
            log.error("", exp);
        }
        catch(java.lang.InstantiationException exp) {
            log.error("", exp);
        }
        catch(java.lang.IllegalAccessException exp) {
            log.error("", exp);
        }
        catch(javax.swing.UnsupportedLookAndFeelException exp) {
            log.error("", exp);
        }
        
        MainFrame.jStockOptions.setLookNFeel(lafClassName);
        
        for (Enumeration<AbstractButton> e = this.buttonGroup1.getElements() ; e.hasMoreElements() ;) {
            AbstractButton button = e.nextElement();
            javax.swing.JRadioButtonMenuItem m = (javax.swing.JRadioButtonMenuItem)button;
            ChangeLookAndFeelAction a = (ChangeLookAndFeelAction)m.getActionListeners()[0];
                        
            if(a.getLafClassName().equals(lafClassName)) {
                m.setSelected(true);
                break;                   
            }
        }
        
        // Sequence are important. The AutoCompleteJComboBox itself should have the highest
        // priority.
        ((AutoCompleteJComboBox)jComboBox1).setStockCodeAndSymbolDatabase(stockCodeAndSymbolDatabase);
        this.indicatorPanel.setStockCodeAndSymbolDatabase(stockCodeAndSymbolDatabase);
        initjComboBox1EditorComponentKeyListerner();
        this.indicatorPanel.initjComboBox1EditorComponentKeyListerner();
    }

    private void createChatJPanel() {
        chatJPanel = new org.yccheok.jstock.chat.ChatJPanel();
        jTabbedPane1.addTab("Market Chit Chat", chatJPanel);
        if (jStockOptions.isChatEnabled())
        {
            chatJPanel.startChatServiceManager();
        }
    }
    
    private void createPortfolioManagementJPanel() {
        portfolioManagementJPanel = new PortfolioManagementJPanel();
        
        jTabbedPane1.addTab("Portfolio Management", portfolioManagementJPanel);
    }
    
    private void createStockIndicatorEditor() {
        indicatorPanel = new IndicatorPanel(); 
                
        jTabbedPane1.addTab("Stock Indicator Editor", indicatorPanel);
        jTabbedPane1.addChangeListener(indicatorPanel);
    }

    private void createIndicatorScannerJPanel() {
        this.indicatorScannerJPanel = new IndicatorScannerJPanel(); 
                
        jTabbedPane1.addTab("Stock Indicator Scanner", indicatorScannerJPanel);
        jTabbedPane1.addChangeListener(indicatorScannerJPanel);
    }
    
    // Due to the unknown problem in netbeans IDE, we will add in the tooltip
    // and icon seperately.
    private void  createIconsAndToolTipTextForJTabbedPane() {
        this.jTabbedPane1.setIconAt(0, this.getImageIcon("/images/16x16/strokedocker.png"));
        this.jTabbedPane1.setIconAt(1, this.getImageIcon("/images/16x16/color_line.png"));
        this.jTabbedPane1.setIconAt(2, this.getImageIcon("/images/16x16/bell.png"));
        this.jTabbedPane1.setIconAt(3, this.getImageIcon("/images/16x16/calc.png"));
        this.jTabbedPane1.setIconAt(4, this.getImageIcon("/images/16x16/smile.png"));
        this.jTabbedPane1.setToolTipTextAt(0, "Watch your favorite stock movement in real time");
        this.jTabbedPane1.setToolTipTextAt(1, "Customize your own stock indicator for alert purpose");
        this.jTabbedPane1.setToolTipTextAt(2, "Scan through the entire stock market so that you will be informed what to sell or buy");
        this.jTabbedPane1.setToolTipTextAt(3, "Manage your real time portfolio, which enable you to track buy and sell records");
        this.jTabbedPane1.setToolTipTextAt(4, "Chit chat with other JStock users regarding the hottest stock market news");
    }
      
    public void createCountryMenuItem() {
        final Country[] countries = Country.values();

        for(Country country : countries) {
            final JMenuItem mi = (JRadioButtonMenuItem) jMenu6.add(new JRadioButtonMenuItem(country.toString(), country.getIcon()));
            buttonGroup2.add(mi);
            mi.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    final Country selectedCountry = Country.valueOf(mi.getText());
                    MainFrame.this.changeCountry(selectedCountry);
                }                
            });
            
            if(jStockOptions.getCountry() == country) {
                ((JRadioButtonMenuItem) mi).setSelected(true);
            }
        }
    }
            
    public void createLookAndFeelMenuItem() {
        LookAndFeel currentlaf = UIManager.getLookAndFeel();
        
        UIManager.LookAndFeelInfo[] lafInfo = UIManager.getInstalledLookAndFeels();

        for(int i=0; i<lafInfo.length; i++) {
            JMenuItem mi = (JRadioButtonMenuItem) jMenu4.add(new JRadioButtonMenuItem(lafInfo[i].getName()));
            buttonGroup1.add(mi);
            mi.addActionListener(new ChangeLookAndFeelAction(this, lafInfo[i].getClassName()));
            
            if(currentlaf != null) {
                if(lafInfo[i].getClassName().equals(currentlaf.getClass().getName()))
                {
                    ((JRadioButtonMenuItem) mi).setSelected(true);
                }
            }
        }
    }
  
    private javax.swing.event.TableModelListener getTableModelListener() {
        return new javax.swing.event.TableModelListener() {
           public void tableChanged(javax.swing.event.TableModelEvent e) {
                int firstRow = e.getFirstRow();
                int lastRow = e.getLastRow();
                int mColIndex = e.getColumn();
                
                switch (e.getType()) {
                    case javax.swing.event.TableModelEvent.INSERT:
                        break;
                        
                  case javax.swing.event.TableModelEvent.UPDATE:
                    break;

                  case javax.swing.event.TableModelEvent.DELETE:
                    break;                        
                }
            }            
        };
    }

    private Image getMyIconImage()
    {
        return new javax.swing.ImageIcon(getClass().getResource("/images/16x16/chart.png")).getImage();
    }
    
    private void createSystemTrayIcon() {
        if (SystemTray.isSupported()) {
            SystemTray tray = SystemTray.getSystemTray();
            Image image = new javax.swing.ImageIcon(getClass().getResource("/images/16x16/chart.png")).getImage();

            MouseListener mouseListener = new MouseListener() {

⌨️ 快捷键说明

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