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

📄 sglconfiguration.java

📁 an example to create form base. it include table, panel,customize document
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

package com.freescale.RAppID.view.sgl;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.ResourceBundle;

import javax.swing.JCheckBox;
import javax.swing.JTextField;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;

import com.freescale.RAppID.controller.ApplicationController;
import com.freescale.RAppID.controller.devicemgmt.SGLController;
import com.freescale.RAppID.controller.devicemgmt.SGLMgr;
import com.freescale.RAppID.controller.model.sgl.SGLModel;
import com.freescale.RAppID.controller.projectmgmt.ProjectManager;
import com.freescale.RAppID.util.CommonUtility;
import com.freescale.RAppID.util.RappidLogger;
import com.freescale.RAppID.view.adc.RJTextPanel;
import com.freescale.RAppID.view.common.IUIConstant;
import com.freescale.RAppID.view.common.RJButton;
import com.freescale.RAppID.view.common.RJButtonPanel;
import com.freescale.RAppID.view.common.RJComboBox;
import com.freescale.RAppID.view.common.RJComboBoxPanel;
import com.freescale.RAppID.view.common.RJLabel;
import com.freescale.RAppID.view.common.RJPanel;
import com.freescale.RAppID.view.common.RToolTipText;

public class SGLConfiguration extends RJPanel
{
  RappidLogger logger = RappidLogger.getLogger(this);
  private static ResourceBundle res = SGLMgr.getSGLResourceFile();
       
  RJPanel mainframe = new RJPanel();
  RJPanel mainPanel = new RJPanel();
  RJPanel pnlGeneralModuleConfiguration = new RJPanel(res
        .getString("mainpanel0.label"));
  RJPanel mainpanel0_Left = new RJPanel();
  RJPanel mainpanel0_Right = new RJPanel();
  RJPanel mainpanel0_Right_Up = new RJPanel();
  RJPanel mainpanel0_Right_Down = new RJPanel()
  {
    public Insets getInsets()
    {
      return new Insets(10, 0, 5, 5);
    }
  };

  RJPanel mainpanel0_Right_blank = new RJPanel();
  RJPanel pnlInterruptConfiguration = new RJPanel(res
        .getString("subpanel0.label"));
  RJPanel pnlBlankBottom = new RJPanel();
  RJPanel pnlFormula = new RJPanel();

  SGLMgr SGLManager = new SGLMgr();
  RJComboBoxPanel cmbSoundType = null;
  RJComboBoxPanel cmbMuxAChannelSelect = null;
  RJComboBoxPanel cmbMuxBChannelSelect = null;
  RJComboBoxPanel cmbSGLMode = null;
  RJButtonPanel btnSoundGenerationCompleteInterrupt = new RJButtonPanel();
  RJTextPanel txtPrescaler = new RJTextPanel(128, 1);
  RJHexPanel_SGL txtSoundDuration = null;
  RJHexPanel_SGL txtHighPeriod = null;
  RJHexPanel_SGL txtLowPeriod = null;

  RJLabel lblSoundDurationVal = new RJLabel();
  RJLabel lblHighPeriodVal = new RJLabel();
  RJLabel lblLowPeriodVal = new RJLabel();
  RJLabel lblSoundDuration = new RJLabel();
  RJLabel lblHighPeriod = new RJLabel();
  RJLabel lblLowPeriod = new RJLabel();
  RJPanel pnlSoundDuration = new RJPanel();
  RJPanel pnlHighPeriod = new RJPanel();
  RJPanel pnlLowPeriod = new RJPanel();
  RJLabel lblFormula = new RJLabel();
  JCheckBox chkEnableHex = new JCheckBox();
  Border borderNote;
  TitledBorder titledBorderNote;

  private int SGLModeIndexValue = 0;
  private int SoundTypeIndexVal = 0;
  boolean resultChkbox = false;
  boolean prescalerFlag = true;
  boolean soundDurationFlag = false;
  boolean highPeriodFlag = false;
  boolean lowPeriodFlag = false;

  public SGLConfiguration()
  {
    try
    {
      jbInit();
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }

  private void jbInit()
  {
    this.setLayout(new BorderLayout());
    mainPanel.setLayout(new BorderLayout());
    mainPanel.setPreferredSize(new Dimension(700, 700));

    SoundConfig_ComboBox_ItemListener comboBox_EventHandler = new SoundConfig_ComboBox_ItemListener(
          this);
    SoundConfig_HexCheckBox_ItemListener hexCheckBox_EventHandler = new SoundConfig_HexCheckBox_ItemListener(
          this);
    SoundConfigFocusLostAdapter focusListener = new SoundConfigFocusLostAdapter(
          this);
    SoundConfigFocusLost_Prescalar_Adapter PrescalarfocusListener = new SoundConfigFocusLost_Prescalar_Adapter(
          this);
    SoundConfigKeyListnerAdapter keyListener = new SoundConfigKeyListnerAdapter(
          this);
    pnlGeneralModuleConfiguration.setLayout(new BorderLayout());
    pnlInterruptConfiguration.setLayout(new BorderLayout());
    pnlGeneralModuleConfiguration.setPreferredSize(new Dimension(700, 280));

    cmbSoundType = new RJComboBoxPanel(SGLMgr.getSoundType());
    cmbSoundType.getLbl().setText(( res.getString("SoundType.label") ));
    cmbSoundType.getLbl().setPreferredSize(new Dimension(140, 22));
    cmbSoundType.getCmb().setPreferredSize(new Dimension(150, 22));
    cmbSoundType.getCmb().addItemListener(comboBox_EventHandler);

    cmbSGLMode = new RJComboBoxPanel(SGLMgr.getSGLMode());
    cmbSGLMode.getLbl().setText(( res.getString("SGLMode.label") ));
    cmbSGLMode.getCmb().setHorizontalSCroller(true);
    cmbSGLMode.getLbl().setPreferredSize(new Dimension(140, 22));
    cmbSGLMode.getCmb().setPreferredSize(new Dimension(150, 22));
    cmbSGLMode.getCmb().addItemListener(comboBox_EventHandler);

    cmbMuxAChannelSelect = new RJComboBoxPanel(SGLMgr.getMuxAChannelSelect());
    cmbMuxAChannelSelect.getLbl().setText(
          ( res.getString("MuxAChannelSelect.label") ));
    cmbMuxAChannelSelect.getLbl().setPreferredSize(new Dimension(140, 22));
    cmbMuxAChannelSelect.getCmb().setPreferredSize(new Dimension(150, 22));
    cmbMuxAChannelSelect.getCmb().addItemListener(comboBox_EventHandler);

    cmbMuxBChannelSelect = new RJComboBoxPanel(SGLMgr.getMuxBChannelSelect());
    cmbMuxBChannelSelect.getLbl().setText(
          ( res.getString("MuxBChannelSelect.label") ));
    cmbMuxBChannelSelect.getLbl().setPreferredSize(new Dimension(140, 22));
    cmbMuxBChannelSelect.getCmb().setPreferredSize(new Dimension(150, 22));
    cmbMuxBChannelSelect.getCmb().addItemListener(comboBox_EventHandler);

    txtPrescaler.getLable().setPreferredSize(new Dimension(140, 30));
    txtPrescaler.getLable().setText(res.getString("Prescaler.label"));
    txtPrescaler.getTextField().setColumns(10);
    txtPrescaler.getTextField().addFocusListener(PrescalarfocusListener);
    txtPrescaler.getTextField().addKeyListener(keyListener);
    txtPrescaler.getTextField().createMessageLabel(
          ( res.getString("Prescaler.label") ));

    txtSoundDuration = new RJHexPanel_SGL(4294967295L, 0);
    txtSoundDuration.setBounds(5, 10, 150, 25);
    txtSoundDuration.getTextField().setHexFlag(true);
    txtSoundDuration.getLable().setText(res.getString("SoundDuration.label"));
    txtSoundDuration.getTextField().setColumns(10);
    txtSoundDuration.getTextField().setFont(IUIConstant.NORMAL_FONT);
    txtSoundDuration.getTextField().setLabelName(
          res.getString("SoundDuration.label"));
    txtSoundDuration.getTextField().addFocusListener(focusListener);
    txtSoundDuration.getTextField().addKeyListener(keyListener);

    txtHighPeriod = new RJHexPanel_SGL(4294967295L, 0);
    txtHighPeriod.setBounds(5, 40, 150, 25);
    txtHighPeriod.getTextField().setHexFlag(true);
    txtHighPeriod.getLable().setText(res.getString("HighPeriod.label"));
    txtHighPeriod.getTextField().setColumns(10);
    txtHighPeriod.getTextField().setFont(IUIConstant.NORMAL_FONT);
    txtHighPeriod.getTextField()
          .setLabelName(res.getString("HighPeriod.label"));
    txtHighPeriod.getTextField().addFocusListener(focusListener);
    txtHighPeriod.getTextField().addKeyListener(keyListener);

    txtLowPeriod = new RJHexPanel_SGL(4294967295L, 0);
    txtLowPeriod.setBounds(5, 70, 150, 25);
    txtLowPeriod.getTextField().setHexFlag(true);
    txtLowPeriod.getLable().setText(res.getString("LowPeriod.label"));
    txtLowPeriod.getTextField().setColumns(10);
    txtLowPeriod.getTextField().setFont(IUIConstant.NORMAL_FONT);
    txtLowPeriod.getTextField().setLabelName(res.getString("LowPeriod.label"));
    txtLowPeriod.getTextField().addFocusListener(focusListener);
    txtLowPeriod.getTextField().addKeyListener(keyListener);

    lblSoundDuration.setPreferredSize(new Dimension(120, 15));
    lblSoundDuration.setText(res.getString("SoundDurationms.label"));
    lblHighPeriod.setPreferredSize(new Dimension(120, 15));
    lblHighPeriod.setText(res.getString("HighPeriodms.label"));
    lblLowPeriod.setPreferredSize(new Dimension(120, 15));
    lblLowPeriod.setText(res.getString("LowPeriodms.label"));
    lblSoundDurationVal.setPreferredSize(new Dimension(130, 15));
    lblHighPeriodVal.setPreferredSize(new Dimension(130, 15));
    lblLowPeriodVal.setPreferredSize(new Dimension(130, 15));

    btnSoundGenerationCompleteInterrupt = new RJButtonPanel();
    btnSoundGenerationCompleteInterrupt.getLabel().setText(
          res.getString("SoundDurationInterrupt.label"));
    btnSoundGenerationCompleteInterrupt.getButton().addActionListener(
          new ActionListener_SoundConfiguration(this));
    btnSoundGenerationCompleteInterrupt.getButton().setPreferredSize(
          new Dimension(65, 22));
    btnSoundGenerationCompleteInterrupt.getLabel().setPreferredSize(
          new Dimension(210, 30));
    btnSoundGenerationCompleteInterrupt
          .setPreferredSize(new Dimension(355, 50));

    borderNote = new EtchedBorder(EtchedBorder.RAISED, Color.white, Color.black);
    titledBorderNote = new TitledBorder(borderNote, "Note");
    lblFormula.setBounds(new Rectangle(380, 330, 395, 100));
    lblFormula.setForeground(Color.blue);
    lblFormula.setBorder(titledBorderNote);
    lblFormula.setText(res.getString("Formula.label"));

    boolean bolValue = chkEnableHex.isSelected();
    txtSoundDuration.getTextField().setHexFlag(bolValue);
    txtHighPeriod.getTextField().setHexFlag(bolValue);
    txtLowPeriod.getTextField().setHexFlag(bolValue);

    chkEnableHex.setText(res.getString("Load_Hex.label"));
    chkEnableHex.setFont(IUIConstant.NORMAL_FONT);
    chkEnableHex.setBackground(SystemColor.control);
    chkEnableHex.setBounds(new Rectangle(20, 180, 180, 22));
    chkEnableHex.addItemListener(hexCheckBox_EventHandler);

    mainpanel0_Left.setLayout(new GridLayout(6, 0));
    mainpanel0_Right.setLayout(new BorderLayout());

    mainpanel0_Left.add(cmbSoundType);
    mainpanel0_Left.add(cmbSGLMode);
    mainpanel0_Left.add(cmbMuxAChannelSelect);
    mainpanel0_Left.add(cmbMuxBChannelSelect);
    mainpanel0_Left.add(txtPrescaler);

    pnlSoundDuration.add(lblSoundDuration);
    pnlSoundDuration.add(lblSoundDurationVal);
    pnlHighPeriod.add(lblHighPeriod);
    pnlHighPeriod.add(lblHighPeriodVal);
    pnlLowPeriod.add(lblLowPeriod);
    pnlLowPeriod.add(lblLowPeriodVal);

    mainpanel0_Right_Up.setLayout(new GridLayout(4, 0, 0, 9));
    mainpanel0_Right_Up.add(chkEnableHex);
    mainpanel0_Right_Up.add(txtSoundDuration);
    mainpanel0_Right_Up.add(txtHighPeriod);
    mainpanel0_Right_Up.add(txtLowPeriod);

    mainpanel0_Right_Down.setLayout(new GridLayout(3, 0, 0, 7));
    mainpanel0_Right_Down.add(pnlSoundDuration);
    mainpanel0_Right_Down.add(pnlHighPeriod);
    mainpanel0_Right_Down.add(pnlLowPeriod);

    mainpanel0_Right.add(mainpanel0_Right_Up, BorderLayout.NORTH);
    mainpanel0_Right.add(mainpanel0_Right_Down, BorderLayout.WEST);
    mainpanel0_Right.add(mainpanel0_Right_blank, BorderLayout.EAST);
    mainpanel0_Right_blank.setPreferredSize(new Dimension(110, 250));
    pnlGeneralModuleConfiguration.add(mainpanel0_Left, BorderLayout.WEST);
    pnlGeneralModuleConfiguration.add(mainpanel0_Right, BorderLayout.CENTER);
    pnlInterruptConfiguration.add(btnSoundGenerationCompleteInterrupt,
          BorderLayout.CENTER);
    pnlBlankBottom.setPreferredSize(new Dimension(600, 230));
    pnlFormula.add(lblFormula);
    pnlBlankBottom.setLayout(new BorderLayout());
    pnlBlankBottom.add(pnlFormula, BorderLayout.EAST);

    mainPanel.add(pnlGeneralModuleConfiguration, BorderLayout.NORTH);
    mainPanel.add(pnlInterruptConfiguration, BorderLayout.CENTER);
    mainPanel.add(pnlBlankBottom, BorderLayout.SOUTH);
    this.add(mainPanel);

  }

  private void updateCalculationsOfLabels()
  {
    SGLModel objSGLModel = SGLController.getInstance().getSGLModel();

    if(prescalerFlag || soundDurationFlag)
    {
      double soundDuration = objSGLModel.getSoundDurationCalulationVal();
      lblSoundDurationVal.setText(""
            + CommonUtility.formatNumber(soundDuration,
                  CommonUtility.FIVE_DECIMAL_POINT_FORMAT) + " ms");
    }
    if(prescalerFlag || highPeriodFlag)
    {
      double highPeriod = objSGLModel.getHighPeriodCalulationVal();
      lblHighPeriodVal.setText(""
            + CommonUtility.formatNumber(highPeriod,
                  CommonUtility.FIVE_DECIMAL_POINT_FORMAT) + " ms");
    }
    if(prescalerFlag || lowPeriodFlag)
    {
      double lowPeriod = objSGLModel.getLowPeriodCalulationVal();
      lblLowPeriodVal.setText(""
            + CommonUtility.formatNumber(lowPeriod,
                  CommonUtility.FIVE_DECIMAL_POINT_FORMAT) + " ms");
    }
    refreshForm();
  }

  private void SoundTypeValidation(int index)
  {
    if(SoundTypeIndexVal == 0)
    {
      cmbMuxBChannelSelect.getCmb().setEnabled(false);
    }
    else
    {
      cmbMuxBChannelSelect.getCmb().setEnabled(true);
    }
  }

  private void SGLModeValidation(int index)
  {
    switch (index)
    {
      case 0:
        txtSoundDuration.getTextField().setEnabled(false);
        txtHighPeriod.getTextField().setEnabled(false);
        txtLowPeriod.getTextField().setEnabled(false);
      break;
      case 1:
        txtSoundDuration.getTextField().setEnabled(true);
        txtHighPeriod.getTextField().setEnabled(false);
        txtLowPeriod.getTextField().setEnabled(false);
      break;
      case 2:
        txtSoundDuration.getTextField().setEnabled(false);
        txtHighPeriod.getTextField().setEnabled(false);
        txtLowPeriod.getTextField().setEnabled(false);
      break;
      case 3:
        txtSoundDuration.getTextField().setEnabled(true);
        txtHighPeriod.getTextField().setEnabled(true);
        txtLowPeriod.getTextField().setEnabled(true);
      break;
      case 4:
        txtSoundDuration.getTextField().setEnabled(false);
        txtHighPeriod.getTextField().setEnabled(true);
        txtLowPeriod.getTextField().setEnabled(true);
      break;
    }
    refreshForm();
  }

  private void refreshForm()
  {
    SGLModel objSGLModel = SGLController.getInstance().getSGLModel();

    int value = 0;
    value = cmbSoundType.getCmb().getSelectedIndex() == 0 ? 0 : 1;
    cmbSoundType.getCmb().setToolTipText(
          RToolTipText.gettooltiptext(res.getString("SoundType.tooltips"),
                value + "", true));

    btnSoundGenerationCompleteInterrupt.getButton().setToolTipText(
          RToolTipText.gettooltiptext(res
                .getString("SoundDurationInterrupt.tooltips"), null, false));

    cmbSGLMode.getCmb().setToolTipText(
          RToolTipText.gettooltiptext(res.getString("SGLMode.tooltips"),
                objSGLModel.getSGL_MODE_SEL().getSGLMode() + "", true));

    cmbMuxAChannelSelect.getCmb().setToolTipText(
          RToolTipText.gettooltiptext(res
                .getString("MuxAChannelSelect.tooltips"), objSGLModel
                .getSGL_MODE_SEL().getMuxAChannelSelect()
                + "", true));

    cmbMuxBChannelSelect.getCmb().setToolTipText(
          RToolTipText.gettooltiptext(res
                .getString("MuxBChannelSelect.tooltips"), objSGLModel
                .getSGL_MODE_SEL().getMuxBChannelSelect()
                + "", true));

    txtPrescaler.getTextField().setToolTipText(
          RToolTipText.gettooltiptext(res.getString("Prescaler.tooltips"),
                objSGLModel.getSGL_MODE_SEL().getPrescaler() + "", true));

    txtSoundDuration.getTextField().setToolTipText(
          RToolTipText.gettooltiptext(res.getString("SoundDuration.tooltips"),
                objSGLModel.getSGL_SOUND_DUR().getSoundDuration() + "", true));

    txtHighPeriod.getTextField().setToolTipText(
          RToolTipText.gettooltiptext(res.getString("HighPeriod.tooltips"),
                objSGLModel.getSGL_HIGH_PER().getHighPeriod() + "", true));

    txtLowPeriod.getTextField().setToolTipText(
          RToolTipText.gettooltiptext(res.getString("LowPeriod.tooltips"),
                objSGLModel.getSGL_LOW_PER().getLowPeriod() + "", true));

    lblSoundDurationVal.setToolTipText(RToolTipText.gettooltiptext(res
          .getString("SoundDurationms.tooltips"), "", false));

    lblHighPeriodVal.setToolTipText(RToolTipText.gettooltiptext(res
          .getString("HighPeriodms.tooltips"), "", false));

    lblLowPeriodVal.setToolTipText(RToolTipText.gettooltiptext(res
          .getString("LowPeriodms.tooltips"), "", false));

  }

  public void updateUIFromControllerModel()
  {
    SGLModel objSGLModel = SGLController.getInstance().getSGLModel();
    this.setButtonAction(btnSoundGenerationCompleteInterrupt.getButton(),
          objSGLModel.getSGL_MODE_SEL().getSoundGenerationCompleteInterrupt());

    cmbSoundType.getCmb().setIndexValue(

⌨️ 快捷键说明

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