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

📄 indicatorpanel.java

📁 JStock是一个免费股市软件
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        jComboBox1.setEditable(true);
        jComboBox1.setPreferredSize(new java.awt.Dimension(150, 24));
        this.jComboBox1.getEditor().getEditorComponent().addKeyListener(jComboBox1EditorComponentKeyAdapter);
        jPanel7.add(jComboBox1);

        jPanel5.add(jPanel7, java.awt.BorderLayout.NORTH);
        jPanel5.add(objectInspectorJPanel, java.awt.BorderLayout.CENTER);

        jSplitPane2.setBottomComponent(jPanel5);

        jSplitPane1.setRightComponent(jSplitPane2);

        add(jSplitPane1, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
// TODO add your handling code here:
        this.jButton4.setEnabled(true);
        this.jButton6.setEnabled(false);     
        
        stop();
        
        MainFrame m = MainFrame.getMe();
        m.setStatusBar(false, "Simulation stopped");
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
// TODO add your handling code here:
        final int select = jList1.getSelectedIndex();

        String projectName = null;
        
        if(select >= 0 && select < indicatorProjectManager.getNumOfProject()) {
            projectName = this.indicatorProjectManager.getProject(select);        
        }
        
        // String projectName = (String)this.jList1.getSelectedValue();
        
        if(projectName == null) {
            while(true) {
                projectName = JOptionPane.showInputDialog(this, "Please enter the new project name you want to save");

                if(projectName == null) return;

                if(projectName.length() == 0) {
                    JOptionPane.showMessageDialog(this, "You need to specific a project name.", "Project name needed", JOptionPane.INFORMATION_MESSAGE);
                    continue;
                }

                if(indicatorProjectManager.contains(projectName)) {
                    JOptionPane.showMessageDialog(this, "Database already contains similar project name.", "Duplicated project name", JOptionPane.INFORMATION_MESSAGE);
                    continue;
                }
                
                IndicatorDefaultDrawing drawing = (IndicatorDefaultDrawing)view.getDrawing();

                if(this.indicatorProjectManager.addProject(drawing, projectName))
                {
                    if(drawing.getOperatorIndicator().isValid()) {
                        ((javax.swing.DefaultListModel)this.jList1.getModel()).addElement(projectName);                    
                        JOptionPane.showMessageDialog(this, projectName + " has been saved successfully.", "Project saved", JOptionPane.INFORMATION_MESSAGE);
                    }
                    else {
                        ((javax.swing.DefaultListModel)this.jList1.getModel()).addElement(projectName + " *");                    
                        JOptionPane.showMessageDialog(this, projectName + " has been saved successfully. However, " + projectName + " is not valid yet.", "Project saved", JOptionPane.INFORMATION_MESSAGE);
                    }
                    
                    this.jList1.setSelectedIndex(this.jList1.getModel().getSize() - 1);
                    return;
                }
                else
                {
                    JOptionPane.showMessageDialog(this, "You have provided an invalid project name.", "Invalid project name", JOptionPane.INFORMATION_MESSAGE);
                    continue;
                }
            }
        } else {
            IndicatorDefaultDrawing drawing = (IndicatorDefaultDrawing)view.getDrawing();
            
            if(indicatorProjectManager.addProject(drawing, projectName)) {
                if(drawing.getOperatorIndicator().isValid()) {
                    ((javax.swing.DefaultListModel)this.jList1.getModel()).setElementAt(projectName, select);                    
                    JOptionPane.showMessageDialog(this, projectName + " has been saved successfully.", "Project saved", JOptionPane.INFORMATION_MESSAGE);
                }
                else {
                    ((javax.swing.DefaultListModel)this.jList1.getModel()).setElementAt(projectName + " *", select);                    
                    JOptionPane.showMessageDialog(this, projectName + " has been saved successfully. However, " + projectName + " is not valid yet.", "Project saved", JOptionPane.INFORMATION_MESSAGE);
                }
            }
            else {
                JOptionPane.showMessageDialog(this, "Unable to save project " + projectName + " due to unknown reason.", "Unable to save project", JOptionPane.ERROR_MESSAGE);
            }
        }
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jList1ValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jList1ValueChanged
// TODO add your handling code here:
        
        // When the user release the mouse button and completes the selection,
        // getValueIsAdjusting() becomes false        
        if (evt.getValueIsAdjusting()) return;
        
        int select = jList1.getSelectedIndex();
        
        if(select < 0 || select >= indicatorProjectManager.getNumOfProject()) {
            this.view.setDrawing(this.createDrawing());
            return;
        }
        
        // final String project = (String)this.jList1.getModel().getElementAt(select);
        String project = this.indicatorProjectManager.getProject(select);
        
        IndicatorDefaultDrawing indicatorDefaultDrawing = this.indicatorProjectManager.getIndicatorDefaultDrawing(project);
        if(indicatorDefaultDrawing != null) {
            view.setDrawing(indicatorDefaultDrawing);
        }
        else {
            if(JOptionPane.showConfirmDialog(this, "Project " + project + " is corrupted. Do you want to remove it?", project + " corrupted", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
            {
                jButton3ActionPerformed(null);
            }
            else
            {
                this.view.setDrawing(this.createDrawing());
            }
        }       
    }//GEN-LAST:event_jList1ValueChanged

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
// TODO add your handling code here:   
        final MainFrame m = MainFrame.getMe();
        final StockCodeAndSymbolDatabase stockCodeAndSymbolDatabase = m.getStockCodeAndSymbolDatabase();
        
        if(stockCodeAndSymbolDatabase == null) {
            javax.swing.JOptionPane.showMessageDialog(this, "We haven't connected to stock server.", "Not Connected", javax.swing.JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        
        IndicatorDefaultDrawing indicatorDefaultDrawing = (IndicatorDefaultDrawing)this.view.getDrawing();
        OperatorIndicator operatorIndicator = indicatorDefaultDrawing.getOperatorIndicator();
        
        if(operatorIndicator.isValid() == false)
        {
            JOptionPane.showMessageDialog(this, "An indicator must has only 1 stock alert output with 1 input connection and 0 output connection.", "Invalid indicator", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        
        Object o = ((ObjectInspectorJPanel)this.objectInspectorJPanel).getBean();
        MutableStock mutableStock = (MutableStock)o;
        final Stock stock = mutableStock.getStock();
        Code searchedStockCode = stockCodeAndSymbolDatabase.searchStockCode(stock.getCode().toString());
        
        if(searchedStockCode == null) {
            JOptionPane.showMessageDialog(this, "You need to first select a stock to be simulated.", "Stock needed", JOptionPane.INFORMATION_MESSAGE);
            return;            
        }
        else {
            if(searchedStockCode.equals(stock.getCode()) == false) {
                JOptionPane.showMessageDialog(this, "You need to first select a stock to be simulated.", "Stock needed", JOptionPane.INFORMATION_MESSAGE);
                return;                
            }
        }
        
        this.jButton4.setEnabled(false);
        this.jButton6.setEnabled(true);
        
        if(simulationThread != null) {
            simulationThread.interrupt();
            try {
                simulationThread.join();
            }
            catch(InterruptedException exp) {
                log.error("", exp);
            }
        }
        
        simulationThread = new Thread(new Runnable() {
            public void run() {
                IndicatorPanel.this.simulate(stock.getCode());
            }
        });
        
        simulationThread.start();
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
// TODO add your handling code here:

        final int index = this.jList1.getSelectedIndex();
        
        if(index < 0 || index >= indicatorProjectManager.getNumOfProject()) {
            JOptionPane.showMessageDialog(this, "You must at least select a project in order to delete.", "Select needed", JOptionPane.INFORMATION_MESSAGE);
            return;
        } 
                                
        indicatorProjectManager.removeProject(indicatorProjectManager.getProject(index));
        
        DefaultListModel defaultListModel = (DefaultListModel)this.jList1.getModel();
        defaultListModel.removeElementAt(index);
        
        if((index - 1) < 0) {
            this.jList1.clearSelection();
        }
        else {
            this.jList1.setSelectedIndex(index - 1);
        }
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
        final int select = jList1.getSelectedIndex();
        
        if(select < 0 || select >= indicatorProjectManager.getNumOfProject()) {
            JOptionPane.showMessageDialog(this, "You must at least select a project in order to rename.", "Select needed", JOptionPane.INFORMATION_MESSAGE);
            return;
        }

        String oldProjectName = null;
        oldProjectName = this.indicatorProjectManager.getProject(select);

        if(oldProjectName == null) {
            JOptionPane.showMessageDialog(this, "You must at least select a project in order to rename.", "Select needed", JOptionPane.INFORMATION_MESSAGE);
            return;
        }                

        boolean isValid = true;
        
        String stringAtList = (String)this.jList1.getSelectedValue();
        if(stringAtList.equals(oldProjectName) == false)
        {
            isValid = false;
        }
        
        String newProjectName = null;
        
        while(true) {
            newProjectName = JOptionPane.showInputDialog(this, "Please enter the new project name you wish to rename to", oldProjectName);
            
            if(newProjectName == null) return;
            
            if(newProjectName.length() == 0) {
                JOptionPane.showMessageDialog(this, "You need to specific a project name.", "Project name needed", JOptionPane.INFORMATION_MESSAGE);
                continue;
            }

            if(indicatorProjectManager.contains(newProjectName)) {
                JOptionPane.showMessageDialog(this, "Database already contains similar project name.", "Duplicated project name", JOptionPane.INFORMATION_MESSAGE);
                continue;
            }
            
            if(this.indicatorProjectManager.renameProject(newProjectName, oldProjectName))
            {
                final DefaultListModel defaultListModel = (DefaultListModel)this.jList1.getModel();
                if(isValid)
                    defaultListModel.setElementAt(newProjectName, select);
                else
                    defaultListModel.setElementAt(newProjectName + " *", select);
                
                // Update the project.xml as well.
                IndicatorPanel.this.saveIndicatorProjectManager();
            }
            else
            {
                JOptionPane.showMessageDialog(this, "Unable to rename project from " + oldProjectName + " to " + newProjectName + " due to unknown reason.", "Unable to rename project", JOptionPane.ERROR_MESSAGE);
            }
            
            break;
        }
        
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
        String projectName = null;        
        
        while(true) {
            projectName = JOptionPane.showInputDialog(this, "Please enter the new project name");

            if(projectName == null) return;

            if(projectName.length() == 0) {
                JOptionPane.showMessageDialog(this, "You need to specific a project name.", "Project name needed", JOptionPane.WARNING_MESSAGE);
                continue;
            }

⌨️ 快捷键说明

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