private ButtonUI addButton(final MenuItem mi) { ButtonUI btnNewButton = new ButtonUI(mi.getLabel()); final MainMenuUI thisMenu = this; add(btnNewButton); final String buttonText = "clicked it!" + mi.getLabel(); btnNewButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { System.out.println(buttonText); thisMenu.load(mi.open()); } }); return btnNewButton; }
@Override public void OnMessage(int MessageType, Object data, int firmwareVersion) { switch (MessageType) { case CONNECTED: String count = (String) data; if (count.equals("1")) connectToDevice(firmwareVersion); break; case DISCONNECTED: gLEDOff(); IsConnected = false; m_ButtonUI.setEnable(ButtonUI.BUTTON_START, false); m_ButtonUI.setEnable(ButtonUI.BUTTON_STOP, false); m_ButtonUI.setEnable(ButtonUI.BUTTON_PROTOCOL, false); m_PCRTask.killTimer(NopTimer.TIMER_NUMBER); m_PCRStatusText.setMessage(UIConstant.DEFAULT_STATUS_MESSAGE0, 0); m_PCRStatusText.setMessage(UIConstant.DEFAULT_STATUS_MESSAGE1, 1); m_PCRStatusText.setMessage(UIConstant.DEFAULT_STATUS_MESSAGE2, 2); break; } }
private void connectToDevice(int firmwareVersion) { try { if (m_Device != null) { m_Device.close(); m_Device = null; } m_Device = m_Manager.openById(DeviceConstant.VENDOR_ID, DeviceConstant.PRODUCT_ID, serialNumber); if (m_Device != null) { IsConnected = true; m_Device.disableBlocking(); m_ButtonUI.setEnable(ButtonUI.BUTTON_START, true); m_ButtonUI.setEnable(ButtonUI.BUTTON_STOP, false); m_ButtonUI.setEnable(ButtonUI.BUTTON_PROTOCOL, true); m_PCRStatusText.setMessage(m_Device.getSerialNumberString(), 0); m_PCRTask.setTimer(NopTimer.TIMER_NUMBER); setTitle(m_Device.getSerialNumberString()); setSerialNumber(m_Device.getSerialNumberString()); gLEDOn(); if (firmwareVersion == 0) currentVersion = null; else currentVersion = ((firmwareVersion >> 8) & 0xff) + "." + (firmwareVersion & 0xff); // 150506 YJ Firmware check disable // UpdateFromServer(); } else { // ���� ���� ó�� System.out.println("Fatal Error!"); gLEDOff(); } } catch (IOException e) { e.printStackTrace(); } }
/** * Handler�� implements �� �ҵ�. �ٸ� Ŭ�����κ��� ���� Message�� �´�. * * @param MessageType int ���� ���� * @param data Object ������ ���� ���� ������ */ @Override public void OnHandleMessage(int MessageType, Object data) { switch (MessageType) { // Protocol �� �о��ٴ� ���� �� ��� case MESSAGE_READ_PROTOCOL: // Protocol ����Ʈ�� ����ִ�. Action[] actions = (Action[]) data; // null �� ���� �������� ������ �߸� �ҷ��� ��� if (actions == null) JOptionPane.showMessageDialog(this, "�ùٸ��� ���� Protocol �����Դϴ�."); else { // �÷��� �ʱ�ȭ IsProtocolRead = false; // action�� 0��° �迭�� ���̺��� null�� ���� �߸��� ������ ���. if (actions[0].getLabel() == null) return; // List�� ����ش�. m_ProtocolList.ResetContent(); // ���� �������� ��ŭ insert ���ش�. for (Action action : actions) { m_ProtocolList.InsertData(action); } int total = 0; int goton = 0; for (int i = 0; i < actions.length; i++) { if (!actions[i].getLabel().equals("GOTO")) total += Integer.parseInt(actions[i].getTime()); else { int count = Integer.parseInt(actions[i].getTime()); if (goton < count) { String gotoLabel = actions[i].getTemp(); for (int j = 0; j < actions.length; j++) { if (actions[j].getLabel().equals(gotoLabel)) { i = j - 1; break; } } goton++; } else { goton = 0; } } } // �ƿ� �������ݵ��� ��������� �������ش�. m_ActionList = actions; // �о�� �������� ������ �̸��� ��ܿ� ǥ���Ѵ�. m_ProtocolText.setProtocolText(actions[0].getProtocolName()); m_ProtocolText.setRemainingTimeText( String.format( "%02d:%02d:%02d", total / 3600, (total % 3600) / 60, (total % 3600) % 60)); // �о����� �÷��� true IsProtocolRead = true; } break; // ��ŸƮ ��ư�� ������ ��. case MESSAGE_START_PCR: if (IsConnected) { // �ҷ��� �������� ������ ���� ��쿡�� ���� if (IsProtocolRead) { rLEDOff(); m_PCRTask.PCR_Start(m_LidText.getText()); m_PCRTask.setTimer(GoTimer.TIMER_NUMBER); m_ButtonUI.setEnable(ButtonUI.BUTTON_START, false); m_ButtonUI.setEnable(ButtonUI.BUTTON_STOP, true); m_ButtonUI.setEnable(ButtonUI.BUTTON_PROTOCOL, false); } else { JOptionPane.showMessageDialog(this, "�ҷ��� �������� ������ �����ϴ�."); } } break; // ��ž ��ư�� ������ �� case MESSAGE_STOP_PCR: if (IsConnected) { // ���� ó�� m_PCRTask.Stop_PCR(); m_ButtonUI.setEnable(ButtonUI.BUTTON_START, true); m_ButtonUI.setEnable(ButtonUI.BUTTON_STOP, false); m_ButtonUI.setEnable(ButtonUI.BUTTON_PROTOCOL, true); // �÷��� ���� IsNoStop = false; // Stop ������ �˸��� ���α��� �� final ProgressDialog dialog = new ProgressDialog(this, "Stoping this device...", 10); // ����� ����� ���� ��� ��ȭ���ڸ� ���� ���� ������ ���� Thread tempThread = new Thread() { public void run() { dialog.setModal(true); dialog.setVisible(true); } }; tempThread.start(); // 0.2�� ���� ���α����ٰ� 1ĭ�� �����ϵ��� 2���� ���� �ð��� �д�. ( �������� ���Ḧ ���� ) Thread tempThread2 = new Thread() { public void run() { for (int i = 1; i <= 10; i++) { dialog.setProgressValue(i); try { Thread.sleep(200); } catch (InterruptedException e) { e.printStackTrace(); } } dialog.setVisible(false); m_PCRTask.PCR_End(); } }; tempThread2.start(); } break; // Start ����, �������ݵ��� ���� ���� ���� ��쿡 NOP Ÿ�̸Ӹ� ���� ��Ű�� ���� ���� case MESSAGE_TASK_WRITE_END: try { Thread.sleep(300); } catch (InterruptedException e) { e.printStackTrace(); } // NopTimer ���۽�Ų��. m_PCRTask.setTimer(NopTimer.TIMER_NUMBER); break; } }
/** * UI�� �ʱ�ȭ �ϰų�, ��ü���� �ʱ�ȭ �ϴ� ������ �Ѵ�. MainUI() �����ڿ����� ȣ���� �� �ִ�. �� �ѹ��� ȣ��ȴ�. */ private void init() { // �������� ũ�� ���� setBounds( (Resolution.X * 2 / 5), Resolution.Y / 4, UIConstant.MYPCR_WIDTH, UIConstant.MYPCR_HEIGHT); // Ÿ��Ʋ ���� setTitle("MyPCR version 3.2"); // ����� ���α� ���� setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // �ִ�ȭ ���� setResizable(false); // title icon ���� setIconImage(new ImageIcon(getClass().getClassLoader().getResource("icon.png")).getImage()); // ���� ������Ʈ�� ������� Panel // ���̾ƿ��� ������ǥ�� ����ϱ� ���� null�� ���� m_Panel = new JPanel(); m_Panel.setLayout(null); m_Panel.setBackground(UIConstant.BACKGROUND_COLOR); // 3���� GroupBox�� title String[] titles = {"Serial Number", "CHAMBER", "LID HEATER"}; /** ������Ʈ ���� * */ m_ProtocolText = new ProtocolText(); m_PCRStatusText = StatusText.getInstance(UIConstant.GROUP_SIZE, titles); m_ProtocolList = ProtocolList.getInstance(); m_ButtonUI = ButtonUI.getInstance(this); m_LidText = new JTextField(); m_LidText.setLayout(null); m_LidText.setBounds(310, 55, 40, 20); m_LidText.setText("104"); m_LidText.addKeyListener(this); // �ΰ� �߰� JLabel labelLogo = new JLabel(new ImageIcon(getClass().getClassLoader().getResource("logo.jpg"))); labelLogo.setBounds(100, 385, 182, 37); // for bootloader mode labelLogo.addMouseListener( new MouseListener() { public void mouseReleased(MouseEvent e) {} public void mousePressed(MouseEvent e) {} public void mouseExited(MouseEvent e) {} public void mouseEntered(MouseEvent e) {} public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 3 && currentVersion != null) { String res = JOptionPane.showInputDialog( null, "Please input admin password for bootloader", "Admin Mode(Firmware V" + currentVersion + ")", JOptionPane.OK_CANCEL_OPTION); if (res != null) { if (res.equals(Constants.ADMIN_PASSWORD)) { if (m_ButtonUI.isEnable(ButtonUI.BUTTON_START)) OnHandleMessage(MESSAGE_STOP_PCR, null); Thread tempThread = new Thread() { public void run() { try { Thread.sleep(1000); OnMessage(DISCONNECTED, null, 0); Thread.sleep(1000); m_Device.write(m_PCRTask.m_TxAction.Tx_BootLoader()); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }; tempThread.start(); } else JOptionPane.showMessageDialog( null, "Wrong password!", "Admin Mode", JOptionPane.WARNING_MESSAGE); } } } }); // LED added icon_blueOff = new ImageIcon(url_blueOff); icon_blueOn = new ImageIcon(url_blueOn); icon_greenOff = new ImageIcon(url_greenOff); icon_greenOn = new ImageIcon(url_greenOn); icon_redOff = new ImageIcon(url_redOff); icon_redOn = new ImageIcon(url_redOn); ledBlue = new JLabel(icon_blueOff); ledBlue.setBounds(310, 1, 22, 29); ledRed = new JLabel(icon_redOff); ledRed.setBounds(332, 1, 22, 29); ledGreen = new JLabel(icon_greenOff); ledGreen.setBounds(354, 1, 22, 29); m_Panel.add(m_ProtocolText); m_Panel.add(m_PCRStatusText); m_Panel.add(m_ProtocolList.getPane()); m_Panel.add(m_ButtonUI.getPanel()); m_Panel.add(m_LidText); // 150509 logo and led added m_Panel.add(labelLogo); m_Panel.add(ledBlue); m_Panel.add(ledGreen); m_Panel.add(ledRed); /** ������Ʈ ���� * */ // �dz��� ���� �����ӿ� ���� add(m_Panel); // 150507 ȭ�鿡 UI �� ���� ���� ��ġ Ȯ���� ���� �ϱ� ���� ó�� // ȭ�鿡 ���̵��� // setVisible(true); // Device ���� üũ�� �ݹ� �Լ� ���� try { // DeviceManager �ν��Ͻ� ���� m_Manager = HIDManager.getInstance(); // Device ���� ���¸� ǥ�����ִ� �ݹ��Լ� ��� m_Callback_DeviceChange = CallbackDeviceChange.getInstance(m_Manager, this); m_Callback_DeviceChange.setDaemon(true); m_Callback_DeviceChange.start(); } catch (IOException e) { e.printStackTrace(); } // MyPCR ���� ����� ��� �ִ� ��ü�� �ν��Ͻ��� ���� m_PCRTask = PCR_Task.getInstance(this); }