Example usage for java.awt.event ComponentEvent toString

List of usage examples for java.awt.event ComponentEvent toString

Introduction

In this page you can find the example usage for java.awt.event ComponentEvent toString.

Prototype

public String toString() 

Source Link

Document

Returns a String representation of this object.

Usage

From source file:lejos.pc.charting.LogChartFrame.java

/** All the setup of components, etc. What's scary is Swing is a "lightweight" GUI framework...
 * @throws Exception/*from  w  w  w .j av a  2 s  .c  o m*/
 */
private void jbInit() throws Exception {
    this.setJMenuBar(menuBar);
    this.setSize(new Dimension(819, 613));
    this.setMinimumSize(new Dimension(819, 613));
    this.setTitle("NXT Charting Logger");
    this.setEnabled(true);
    // enforce minimum window size
    this.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent e) {
            JFrame theFrame = (JFrame) e.getSource();
            Dimension d1 = theFrame.getMinimumSize();
            Dimension d2 = theFrame.getSize();
            boolean enforce = false;
            if (theFrame.getWidth() < d1.getWidth()) {
                d2.setSize(d1.getWidth(), d2.getHeight());
                enforce = true;
            }
            if (theFrame.getHeight() < d1.getHeight()) {
                d2.setSize(d2.getWidth(), d1.getHeight());
                enforce = true;
            }
            if (enforce)
                theFrame.setSize(d2);
        }
    });

    this.getContentPane().setLayout(gridBagLayout1);
    MenuActionListener menuItemActionListener = new MenuActionListener();
    MenuEventListener menuListener = new MenuEventListener();

    menu = new JMenu("Edit");
    menu.setMnemonic(KeyEvent.VK_E);
    menuBar.add(menu);
    menuItem = new JMenuItem("Copy Chart Image", KeyEvent.VK_I);
    menuItem.addActionListener(menuItemActionListener);
    menu.add(menuItem);
    menuItem = new JMenuItem("Copy Data Log", KeyEvent.VK_D);
    menuItem.addActionListener(menuItemActionListener);
    menu.add(menuItem);

    menu = new JMenu("View");
    menu.setMnemonic(KeyEvent.VK_V);
    menu.setActionCommand("VIEW_MENU");
    menu.addMenuListener(menuListener);
    menuBar.add(menu);
    menuItem = new JMenuItem("Expand Chart", KeyEvent.VK_F);
    menuItem.addActionListener(menuItemActionListener);
    menu.add(menuItem);
    menuItem = new JMenuItem("Chart in New Window", KeyEvent.VK_N);
    menuItem.addActionListener(menuItemActionListener);
    menu.add(menuItem);

    menu = new JMenu("Help");
    menu.setMnemonic(KeyEvent.VK_H);
    menuBar.add(menu);
    menuItem = new JMenuItem("Chart controls", KeyEvent.VK_C);
    menuItem.addActionListener(menuItemActionListener);
    menu.add(menuItem);
    menuItem = new JMenuItem("Generate sample data", KeyEvent.VK_G);
    menuItem.addActionListener(menuItemActionListener);
    menu.add(menuItem);
    menuItem = new JMenuItem("About", KeyEvent.VK_A);
    menuItem.addActionListener(menuItemActionListener);
    jTabbedPane1.setPreferredSize(new Dimension(621, 199));
    jTabbedPane1.setMinimumSize(new Dimension(621, 199));
    menu.add(menuItem);

    jButtonConnect.setText("Connect");
    jButtonConnect.setBounds(new Rectangle(25, 65, 115, 25));
    jButtonConnect.setToolTipText("Connect/disconnect toggle");
    jButtonConnect.setMnemonic('C');
    jButtonConnect.setSelected(true);
    jButtonConnect.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            jButtonConnect_actionPerformed(e);
        }
    });
    UIPanel.setSize(new Dimension(820, 200));
    UIPanel.setLayout(null);
    UIPanel.setPreferredSize(new Dimension(300, 200));
    UIPanel.setMinimumSize(new Dimension(300, 200));
    UIPanel.setBounds(new Rectangle(0, 350, 820, 200));
    UIPanel.setMaximumSize(new Dimension(300, 32767));
    connectionPanel.setBounds(new Rectangle(10, 10, 175, 100));
    connectionPanel.setBorder(BorderFactory.createTitledBorder("Connection"));
    connectionPanel.setLayout(null);
    connectionPanel.setFont(new Font("Tahoma", 0, 11));

    jLabel1logfilename.setText("Log File:");
    jLabel1logfilename.setBounds(new Rectangle(10, 125, 165, 20));
    jLabel1logfilename.setHorizontalTextPosition(SwingConstants.RIGHT);
    jLabel1logfilename.setHorizontalAlignment(SwingConstants.LEFT);
    jLabel1logfilename.setToolTipText("Specify the name of your log file here");

    jTextFieldNXTName.setBounds(new Rectangle(5, 40, 165, 20));
    jTextFieldNXTName.setToolTipText(
            "The name or Address of the NXT. Leave empty and the first one found will be used.");

    jTextFieldNXTName.requestFocus();

    jTextAreaStatus.setLineWrap(true);
    jTextAreaStatus.setFont(new Font("Tahoma", 0, 11));
    jTextAreaStatus.setWrapStyleWord(true);
    jTextAreaStatus.setBackground(SystemColor.window);

    dataLogTextArea.setLineWrap(false);
    dataLogTextArea.setFont(new Font("Tahoma", 0, 11));
    dataLogTextArea.setBackground(SystemColor.window);

    FQPathTextArea.setBounds(new Rectangle(5, 170, 185, 40));
    FQPathTextArea.setLineWrap(true);
    FQPathTextArea.setText(getCanonicalName(new File(".", "")));
    FQPathTextArea.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    FQPathTextArea.setRows(2);

    FQPathTextArea.setFont(new Font("Tahoma", 0, 9));
    FQPathTextArea.setOpaque(false);
    FQPathTextArea.setEditable(false);

    selectFolderButton.setText("Folder...");
    selectFolderButton.setBounds(new Rectangle(120, 125, 70, 20));
    selectFolderButton.setMargin(new Insets(1, 1, 1, 1));
    selectFolderButton.setFocusable(false);
    selectFolderButton.setMnemonic('F');
    selectFolderButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            selectFolderButton_actionPerformed(e);
        }
    });

    // domain display limits GUI
    chartOptionsPanel.setLayout(null);
    chartDomLimitsPanel.setBounds(new Rectangle(5, 35, 180, 135));
    chartDomLimitsPanel.setLayout(gridLayout1);
    chartDomLimitsPanel.setBorder(BorderFactory.createTitledBorder("Domain Display Limiting"));
    domainDisplayLimitSlider.setEnabled(false);
    domainDisplayLimitSlider.setMaximum(MAXDOMAIN_DATAPOINT_LIMIT);
    domainDisplayLimitSlider.setMinimum(MINDOMAIN_LIMIT);
    domainDisplayLimitSlider.setValue(MAXDOMAIN_DATAPOINT_LIMIT);
    domainDisplayLimitSlider.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            domainDisplayLimitSlider_stateChanged(e);
        }
    });
    useTimeRadioButton.setText("By Time");
    useTimeRadioButton.setEnabled(false);
    useTimeRadioButton.setMnemonic('I');
    useTimeRadioButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            domainDisplayLimitRadioButton_actionPerformed(e);
        }
    });
    useDataPointsRadioButton.setText("By Data Points");
    ButtonGroup bg1 = new ButtonGroup();
    bg1.add(useTimeRadioButton);
    bg1.add(useDataPointsRadioButton);
    useDataPointsRadioButton.setSelected(true);
    useDataPointsRadioButton.setEnabled(false);
    useDataPointsRadioButton.setMnemonic('P');
    useDataPointsRadioButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            domainDisplayLimitRadioButton_actionPerformed(e);
        }
    });
    datasetLimitEnableCheckBox.setText("Enable");
    datasetLimitEnableCheckBox.setRolloverEnabled(true);
    datasetLimitEnableCheckBox.setMnemonic('A');
    datasetLimitEnableCheckBox.setToolTipText("Enable Domain Clipping");
    datasetLimitEnableCheckBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            datasetLimitEnableCheckBox_actionPerformed(e);
        }
    });
    domainLimitLabel.setText(String.format("%1$,d datapoints", MAXDOMAIN_DATAPOINT_LIMIT).toString());
    domainLimitLabel.setEnabled(false);
    gridLayout1.setRows(5);
    gridLayout1.setColumns(1);

    jLabel1.setText("Chart Title:");
    jLabel1.setBounds(new Rectangle(200, 10, 85, 20));
    jLabel1.setPreferredSize(new Dimension(115, 14));
    jLabel2.setText("Range Axis 1 Label:");
    jLabel2.setBounds(new Rectangle(200, 35, 115, 20));
    jLabel2.setSize(new Dimension(115, 20));
    jLabel3.setText("Range Axis 2 Label:");
    jLabel3.setBounds(new Rectangle(200, 60, 115, 20));
    jLabel3.setSize(new Dimension(115, 20));
    jLabel4.setText("Range Axis 3 Label:");
    jLabel4.setBounds(new Rectangle(200, 85, 115, 20));
    jLabel4.setSize(new Dimension(115, 20));
    jLabel6.setText("Range Axis 4 Label:");
    jLabel6.setBounds(new Rectangle(200, 110, 115, 20));
    jLabel6.setSize(new Dimension(115, 20));
    titleLabelChangeNotifier notifier = new titleLabelChangeNotifier();
    chartTitleTextField.setBounds(new Rectangle(315, 10, 290, 20));
    chartTitleTextField.getDocument().addDocumentListener(notifier);
    axis1LabelTextField.setBounds(new Rectangle(315, 35, 290, 20));
    axis1LabelTextField.getDocument().addDocumentListener(notifier);
    axis2LabelTextField.setBounds(new Rectangle(315, 60, 290, 20));
    axis2LabelTextField.getDocument().addDocumentListener(notifier);
    axis3LabelTextField.setBounds(new Rectangle(315, 85, 290, 20));
    axis3LabelTextField.getDocument().addDocumentListener(notifier);
    axis4LabelTextField.setBounds(new Rectangle(315, 110, 290, 20));
    showCommentsCheckBox.setText("Show Comment Markers");
    showCommentsCheckBox.setBounds(new Rectangle(200, 140, 185, 25));
    showCommentsCheckBox.setToolTipText("Show/Hide any comment markers on the chart");
    showCommentsCheckBox.setRolloverEnabled(true);
    showCommentsCheckBox.setSelected(true);
    showCommentsCheckBox.setMnemonic('M');
    showCommentsCheckBox.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            customChartPanel.setCommentsVisible(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    scrollDomainCheckBox.setText("Scroll Domain");
    scrollDomainCheckBox.setBounds(new Rectangle(10, 5, 175, 20));
    scrollDomainCheckBox.setSize(new Dimension(175, 25));
    scrollDomainCheckBox.setSelected(true);
    scrollDomainCheckBox.setMnemonic('O');
    scrollDomainCheckBox.setToolTipText("Checked to scroll domain as new data is received");
    scrollDomainCheckBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scrollDomainCheckBox_actionPerformed(e);
        }
    });
    axis4LabelTextField.getDocument().addDocumentListener(notifier);

    logFileTextField.setBounds(new Rectangle(10, 145, 180, 20));
    logFileTextField.setText("NXTData.txt");
    logFileTextField.setPreferredSize(new Dimension(180, 20));
    logFileTextField.setToolTipText("File name. Leave empty to not log to file.");
    statusScrollPane.setOpaque(false);
    dataLogScrollPane.setOpaque(false);

    customChartPanel.setMinimumSize(new Dimension(400, 300));
    customChartPanel.setPreferredSize(new Dimension(812, 400));

    jLabel5.setText("NXT Name/Address:");
    jLabel5.setBounds(new Rectangle(5, 20, 160, 20));
    jLabel5.setToolTipText(jTextFieldNXTName.getToolTipText());
    jLabel5.setHorizontalTextPosition(SwingConstants.RIGHT);
    jLabel5.setHorizontalAlignment(SwingConstants.LEFT);

    connectionPanel.add(jTextFieldNXTName, null);
    connectionPanel.add(jButtonConnect, null);
    connectionPanel.add(jLabel5, null);
    dataLogScrollPane.setViewportView(dataLogTextArea);
    jTabbedPane1.addTab("Data Log", dataLogScrollPane);
    statusScrollPane.setViewportView(jTextAreaStatus);
    jTabbedPane1.addTab("Status", statusScrollPane);
    jTabbedPane1.addTab("Chart", chartOptionsPanel);
    chartDomLimitsPanel.add(datasetLimitEnableCheckBox, null);
    chartDomLimitsPanel.add(useDataPointsRadioButton, null);
    chartDomLimitsPanel.add(useTimeRadioButton, null);
    chartDomLimitsPanel.add(domainDisplayLimitSlider, null);
    chartDomLimitsPanel.add(domainLimitLabel, null);
    chartOptionsPanel.add(scrollDomainCheckBox, null);
    chartOptionsPanel.add(showCommentsCheckBox, null);
    chartOptionsPanel.add(axis4LabelTextField, null);
    chartOptionsPanel.add(axis3LabelTextField, null);
    chartOptionsPanel.add(axis2LabelTextField, null);
    chartOptionsPanel.add(axis1LabelTextField, null);
    chartOptionsPanel.add(chartTitleTextField, null);
    chartOptionsPanel.add(jLabel6, null);
    chartOptionsPanel.add(jLabel4, null);
    chartOptionsPanel.add(jLabel3, null);
    chartOptionsPanel.add(jLabel2, null);
    chartOptionsPanel.add(jLabel1, null);
    chartOptionsPanel.add(chartDomLimitsPanel, null);

    tglbtnpauseplay = new JToggleButton("");
    tglbtnpauseplay.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (lpm == null)
                return;
            boolean doPause = false;
            if (e.getStateChange() == ItemEvent.SELECTED) {
                doPause = true;
            }
            lpm.setReaderPaused(doPause);
        }
    });
    //        tglbtnpauseplay.addChangeListener(new ChangeListener() {
    //           public void stateChanged(ChangeEvent e) {
    //              System.out.println(e.toString());
    //              //lpm.setReaderPaused(doPause)
    //           }
    //        });
    tglbtnpauseplay
            .setSelectedIcon(new ImageIcon(LogChartFrame.class.getResource("/lejos/pc/charting/play.png")));
    tglbtnpauseplay.setIcon(new ImageIcon(LogChartFrame.class.getResource("/lejos/pc/charting/pause.png")));
    tglbtnpauseplay.setBounds(571, 135, 30, 30);
    chartOptionsPanel.add(tglbtnpauseplay);

    jTabbedPane1.setToolTipTextAt(0, "The tab-delimited log of the data sent from the NXT");
    jTabbedPane1.setToolTipTextAt(1, "Status output");
    jTabbedPane1.setToolTipTextAt(2, "Chart options");
    jTabbedPane1.setMnemonicAt(0, KeyEvent.VK_D);
    jTabbedPane1.setMnemonicAt(1, KeyEvent.VK_S);
    jTabbedPane1.setMnemonicAt(2, KeyEvent.VK_T);
    this.getContentPane().add(customChartPanel, new GridBagConstraints(0, 0, 2, 1, 1.0, 1.0,
            GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    this.getContentPane().add(UIPanel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
            GridBagConstraints.NONE, new Insets(0, 0, 0, 0), -107, 0));

    this.getContentPane().add(jTabbedPane1, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,
            GridBagConstraints.NORTHEAST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    UIPanel.add(connectionPanel, null);
    UIPanel.add(selectFolderButton, null);
    UIPanel.add(logFileTextField, null);
    UIPanel.add(jLabel1logfilename, null);
    UIPanel.add(FQPathTextArea, null);
    ActionListener taskPerformer = new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            String theData = null;
            for (;;) {
                theData = LogChartFrame.this.logDataQueue.poll();
                if (theData == null)
                    break;
                try {
                    dataLogTextArea.getDocument().insertString(dataLogTextArea.getDocument().getLength(),
                            theData, null);
                } catch (BadLocationException e) {
                    System.out.print(
                            "BadLocationException in datalog textarea updater thread:" + e.toString() + "\n");
                }
            }
        }
    };
    this.updateLogTextAreaTimer = new Timer(1000, taskPerformer);
    this.updateLogTextAreaTimer.start();
}