Example usage for java.awt.event InputMethodListener InputMethodListener

List of usage examples for java.awt.event InputMethodListener InputMethodListener

Introduction

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

Prototype

InputMethodListener

Source Link

Usage

From source file:com.smart.aqimonitor.client.AqiMonitor.java

/**
 * Create the frame./*from  w w  w . ja v a  2  s  .c  o m*/
 */
public AqiMonitor() {
    refSelf = this;
    setPreferredSize(new Dimension(640, 480));
    setTitle("\u7A7A\u6C14\u8D28\u91CF\u76D1\u6D4B");
    setIconImage(Toolkit.getDefaultToolkit()
            .getImage(AqiMonitor.class.getResource("/lombok/installer/eclipse/STS.png")));
    setMinimumSize(new Dimension(640, 480));
    setMaximumSize(new Dimension(1024, 768));
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 636, 412);
    contentPane = new JPanel();
    contentPane.setPreferredSize(new Dimension(640, 480));
    contentPane.setMinimumSize(new Dimension(640, 480));
    contentPane.setMaximumSize(new Dimension(1024, 768));
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    contentPane.setLayout(new BorderLayout(0, 0));
    setContentPane(contentPane);

    JPanel mainPanel = new JPanel();
    contentPane.add(mainPanel, BorderLayout.CENTER);
    mainPanel.setLayout(new BorderLayout(0, 0));

    JPanel contentPanel = new JPanel();
    mainPanel.add(contentPanel, BorderLayout.CENTER);
    contentPanel.setLayout(new BorderLayout(0, 0));

    JScrollPane scrollPane = new JScrollPane();
    scrollPane
            .setViewportBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null));
    contentPanel.add(scrollPane, BorderLayout.CENTER);

    textPane = new AqiTextPane();
    textPane.addInputMethodListener(new InputMethodListener() {

        public void caretPositionChanged(InputMethodEvent event) {

        }

        public void inputMethodTextChanged(InputMethodEvent event) {
            textPane.setCaretPosition(document.getLength() + 1);
        }
    });
    textPane.setEditable(false);
    textPane.setOpaque(false);
    textPane.setForeground(Color.BLACK);
    scrollPane.setViewportView(textPane);
    document = textPane.getStyledDocument();

    document.addDocumentListener(new DocumentListener() {

        @Override
        public void removeUpdate(DocumentEvent e) {
            changedUpdate(e);
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            changedUpdate(e);
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            if (e.getDocument() == document) {
                textPane.setCaretPosition(document.getLength());
            }
        }
    });

    JPanel buttonPanel = new JPanel();
    contentPane.add(buttonPanel, BorderLayout.SOUTH);
    buttonPanel.setLayout(new BorderLayout(0, 0));

    JLabel lblTipsLabel = new JLabel(
            "Tips\uFF1A\u6587\u4EF6\u4FDD\u5B58\u683C\u5F0Fcsv\u53EF\u7528Excel\u6253\u5F00");
    lblTipsLabel.setForeground(Color.BLUE);
    buttonPanel.add(lblTipsLabel, BorderLayout.WEST);

    JPanel panel = new JPanel();
    buttonPanel.add(panel, BorderLayout.CENTER);
    panel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

    JButton btnRetrieve = new JButton("\u624B\u52A8\u83B7\u53D6\u6570\u636E");
    panel.add(btnRetrieve);
    btnRetrieve.setVerticalAlignment(SwingConstants.BOTTOM);

    JButton btnNewButton = new JButton("\u5173\u4E8E");
    btnNewButton.setToolTipText("\u5173\u4E8E");
    btnNewButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JTextArea textArea = new JTextArea(
                    "\n        csv\n\n        smartstudio@foxmail.com");
            textArea.setColumns(35);
            textArea.setRows(6);
            textArea.setLineWrap(true);// 
            textArea.setEditable(false);// 
            textArea.setOpaque(false);
            JOptionPane.showMessageDialog(contentPane, textArea, "", JOptionPane.PLAIN_MESSAGE);
        }
    });

    JButton btnSetting = new JButton("\u8BBE\u7F6E");
    btnSetting.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

            Point parentPos = refSelf.getLocation();

            AqiSettingDialog settingDialog = new AqiSettingDialog(refSelf, pm25InDetailJob.getAqiParser());
            settingDialog.setModal(true);
            settingDialog.setLocation(parentPos.x + 100, parentPos.y + 150);
            settingDialog.init();
            settingDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
            settingDialog.setVisible(true);
        }
    });

    JButton btnExportDir = new JButton("\u67E5\u770B\u6570\u636E");
    btnExportDir.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            try {

                String[] cmd = new String[5];

                String filePath = pm25InDetailJob.getAqiParser().getFilePath();
                File file = new File(filePath);
                if (!file.exists()) {
                    FileUtil.makeDir(file);
                }
                if (!file.isDirectory()) {
                    JOptionPane.showMessageDialog(contentPane, "", "",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }

                cmd[0] = "cmd";
                cmd[1] = "/c";
                cmd[2] = "start";
                cmd[3] = " ";
                cmd[4] = pm25InDetailJob.getAqiParser().getFilePath();

                Runtime.getRuntime().exec(cmd);

            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    });
    panel.add(btnExportDir);
    panel.add(btnSetting);
    panel.add(btnNewButton);
    btnRetrieve.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (!isRetrieving) {
                isRetrieving = true;
                Thread firstRun = new Thread(new Runnable() {

                    @Override
                    public void run() {
                        pm25InDetailJob.refresh();
                        isRetrieving = false;
                    }
                });

                firstRun.start();
            }
        }
    });

    init();
}

From source file:self.philbrown.javaQuery.$.java

/**
 * Registers common component changes/*  ww  w .  ja v a  2  s  .  c o  m*/
 * @param function receives an instance of javaQuery with the changed view selected, as well as the
 * following arguments:
 * <ol>
 * <li>{@link changeEvent} to define the type of event that was triggered
 * <li>The associated event
 * </ol>
 * @return
 * @see changeEvent
 */
public $ change(final Function function) {
    for (final Component component : views) {
        component.addInputMethodListener(new InputMethodListener() {

            @Override
            public void caretPositionChanged(InputMethodEvent event) {
                function.invoke($.with(component), ChangeEvent.INPUT_CARET_POSITION_CHANGED, event);
            }

            @Override
            public void inputMethodTextChanged(InputMethodEvent event) {
                function.invoke($.with(component), ChangeEvent.INPUT_METHOD_TEXT_CHANGED, event);
            }

        });

        component.addHierarchyBoundsListener(new HierarchyBoundsListener() {

            @Override
            public void ancestorMoved(HierarchyEvent event) {
                function.invoke($.with(component), ChangeEvent.HIERARCHY_ANCESTOR_MOVED, event);
            }

            @Override
            public void ancestorResized(HierarchyEvent event) {
                function.invoke($.with(component), ChangeEvent.HIERARCHY_ANCENSTOR_RESIZED, event);
            }

        });

        component.addHierarchyListener(new HierarchyListener() {

            @Override
            public void hierarchyChanged(HierarchyEvent event) {
                function.invoke($.with(component), ChangeEvent.HIERARCHY_CHANGED, event);
            }

        });

        component.addPropertyChangeListener(new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent event) {
                function.invoke($.with(component), ChangeEvent.PROPERTY_CHANGED, event);
            }
        });

        component.addComponentListener(new ComponentListener() {

            @Override
            public void componentHidden(ComponentEvent event) {
                function.invoke($.with(component), ChangeEvent.COMPONENT_HIDDEN, event);
            }

            @Override
            public void componentMoved(ComponentEvent event) {
                function.invoke($.with(component), ChangeEvent.COMPONENT_MOVED, event);
            }

            @Override
            public void componentResized(ComponentEvent event) {
                function.invoke($.with(component), ChangeEvent.COMPONENT_RESIZED, event);
            }

            @Override
            public void componentShown(ComponentEvent event) {
                function.invoke($.with(component), ChangeEvent.COMPONENT_SHOWN, event);
            }

        });

        if (component instanceof Container) {
            ((Container) component).addContainerListener(new ContainerListener() {

                @Override
                public void componentAdded(ContainerEvent event) {
                    function.invoke($.with(component), ChangeEvent.COMPONENT_ADDED, event);
                }

                @Override
                public void componentRemoved(ContainerEvent event) {
                    function.invoke($.with(component), ChangeEvent.COMPONENT_REMOVED, event);
                }

            });
        }
    }
    return this;
}