Search in sources :

Example 21 with MouseListener

use of java.awt.event.MouseListener in project knime-core by knime.

the class ComponentNodeWidget method sendToTarget.

/**
 * Find target of the event. This method is called recursively.
 * @param component the possible target
 * @return true when target is found an recursive search should be stopped.
 */
private boolean sendToTarget(final Container component, final int x, final int y, final MouseEvent e) {
    if (!component.isVisible()) {
        return false;
    }
    int xx = x + component.getX();
    int yy = y + component.getY();
    for (Component c : component.getComponents()) {
        if (sendToTarget((Container) c, xx, yy, e)) {
            return true;
        }
    }
    Point p = new Point(e.getPoint());
    p.translate(-x, -y);
    boolean isIn = component.getBounds().contains(p);
    if (isIn) {
        // translate mouse event
        MouseEvent ee = new MouseEvent(e.getComponent(), e.getID(), e.getWhen(), e.getModifiers(), e.getX() - x, e.getY() - y, e.getXOnScreen(), e.getYOnScreen(), e.getClickCount(), e.isPopupTrigger(), e.getButton());
        for (MouseListener l : component.getMouseListeners()) {
            l.mousePressed(ee);
        }
        if (component instanceof JComponent) {
            JComponent jcomp = (JComponent) component;
            if (jcomp.getBorder() instanceof MouseListener) {
                MouseListener l = (MouseListener) jcomp.getBorder();
                l.mousePressed(ee);
            }
        }
        return true;
    } else {
        return false;
    }
}
Also used : MouseEvent(java.awt.event.MouseEvent) MouseListener(java.awt.event.MouseListener) JComponent(javax.swing.JComponent) Point(java.awt.Point) JComponent(javax.swing.JComponent) Component(java.awt.Component) Point(java.awt.Point)

Example 22 with MouseListener

use of java.awt.event.MouseListener in project knime-core by knime.

the class DropPane method createColumnList.

/**
 */
protected void createColumnList() {
    m_columnListModel = new DefaultListModel<String>();
    m_columnList = new JList<String>(m_columnListModel);
    m_columnList.addMouseListener(new MouseListener() {

        @Override
        public void mouseReleased(final MouseEvent e) {
        // TODO Auto-generated method stub
        }

        @Override
        public void mousePressed(final MouseEvent e) {
        // TODO Auto-generated method stub
        }

        @Override
        public void mouseExited(final MouseEvent e) {
        // TODO Auto-generated method stub
        }

        @Override
        public void mouseEntered(final MouseEvent e) {
        // TODO Auto-generated method stub
        }

        @Override
        public void mouseClicked(final MouseEvent e) {
            if (e.getClickCount() > 1) {
                int i = m_columnList.getSelectedIndex();
                getConfig().addElement(m_columnListModel.get(i));
                m_columnListModel.remove(i);
            }
        }
    });
    m_columnList.setCellRenderer(new ListCellRenderer<String>() {

        @Override
        public Component getListCellRendererComponent(final JList<? extends String> list, final String value, final int index, final boolean isSelected, final boolean cellHasFocus) {
            if (value.endsWith(" ")) {
                JLabel l = new JLabel(value.trim());
                l.setBorder(BorderFactory.createLineBorder(Color.RED));
                return l;
            } else {
                return new JLabel(value);
            }
        }
    });
    m_columnList.setAutoscrolls(true);
    m_columnList.addPropertyChangeListener("dropLocation", new PropertyChangeListener() {

        @Override
        public void propertyChange(final PropertyChangeEvent evt) {
            DropLocation dropLocation = (DropLocation) (evt.getNewValue());
            if (dropLocation != null) {
                int mouseY = getParent().getMousePosition().y;
                int mouseX = getParent().getMousePosition().x;
                getParent().dispatchEvent(new MouseEvent(getParent(), MouseEvent.MOUSE_DRAGGED, System.currentTimeMillis(), 0, mouseX, mouseY, mouseX, mouseY, 1, false, MouseEvent.BUTTON1));
            }
        }
    });
    m_columnList.setDragEnabled(true);
    m_columnList.setTransferHandler(new ListTransferHandler());
    m_columnList.getModel().addListDataListener(new ListDataListener() {

        @Override
        public void intervalRemoved(final ListDataEvent e) {
            if (m_columnList.getModel().getSize() == 0) {
                getParent().remove(getComponentPanel());
                getParent().repaint();
                setParent(null);
                getConfig().removePanel(getPosition());
            } else if (!m_loading) {
                getConfig().getData().get(getPosition()).getSelection().clear();
                for (int i = 0; i < m_columnListModel.getSize(); i++) {
                    getConfig().getData().get(getPosition()).getSelection().add(m_columnListModel.getElementAt(i));
                }
            }
        }

        @Override
        public void intervalAdded(final ListDataEvent e) {
            if (!m_loading) {
                getConfig().getData().get(getPosition()).getSelection().clear();
                for (int i = 0; i < m_columnListModel.getSize(); i++) {
                    getConfig().getData().get(getPosition()).getSelection().add(m_columnListModel.getElementAt(i));
                }
            }
        }

        @Override
        public void contentsChanged(final ListDataEvent e) {
        // nothing
        }
    });
    m_columnList.setPreferredSize(new Dimension(100, 100));
    List<String> columns = getConfig().getData().get(getPosition()).getSelection();
    for (int i = 0; i < columns.size(); i++) {
        m_columnListModel.add(i, columns.get(i));
    }
    m_columnList.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) MouseEvent(java.awt.event.MouseEvent) PropertyChangeListener(java.beans.PropertyChangeListener) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) ListDataListener(javax.swing.event.ListDataListener) ListDataEvent(javax.swing.event.ListDataEvent) MouseListener(java.awt.event.MouseListener) ListTransferHandler(org.knime.base.node.preproc.draganddroppanel.transferhandler.ListTransferHandler) Component(java.awt.Component) DropLocation(javax.swing.JList.DropLocation)

Example 23 with MouseListener

use of java.awt.event.MouseListener in project knime-core by knime.

the class SelectionPanel method createInputList.

private void createInputList() {
    m_inputList = new JList<String>(m_config.getInputListModel());
    m_inputList.addMouseListener(new MouseListener() {

        @Override
        public void mouseReleased(final MouseEvent e) {
        // nothing to do
        }

        @Override
        public void mousePressed(final MouseEvent e) {
        // nothing to do
        }

        @Override
        public void mouseExited(final MouseEvent e) {
        // nothing to do
        }

        @Override
        public void mouseEntered(final MouseEvent e) {
        // nothing to do
        }

        @Override
        public void mouseClicked(final MouseEvent e) {
            if (e.getClickCount() > 1) {
                int selectedIndex = m_inputList.getSelectedIndex();
                int i = m_config.drop((String) ((DefaultListModel) m_inputList.getModel()).get(selectedIndex));
                Pane dp = getNewPane(m_includePanel, m_config, i);
                m_includePanel.add(dp.getComponentPanel(), m_gbc);
                m_gbc.gridy++;
                m_includePanel.setBackground(UIManager.getColor("Panel.background"));
                m_scrollPane.revalidate();
                ((DefaultListModel) m_inputList.getModel()).removeElementAt(selectedIndex);
            }
        }
    });
    m_inputList.setDragEnabled(true);
    m_inputList.setTransferHandler(new ListTransferHandler());
    m_inputList.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
    m_inputListScroller = new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    m_inputListScroller.setPreferredSize(new Dimension(150, 200));
    m_inputListScroller.setViewportView(m_inputList);
}
Also used : JScrollPane(javax.swing.JScrollPane) MouseListener(java.awt.event.MouseListener) MouseEvent(java.awt.event.MouseEvent) ListTransferHandler(org.knime.base.node.preproc.draganddroppanel.transferhandler.ListTransferHandler) Dimension(java.awt.Dimension) JSplitPane(javax.swing.JSplitPane) Pane(org.knime.base.node.preproc.draganddroppanel.droppanes.Pane) JScrollPane(javax.swing.JScrollPane)

Example 24 with MouseListener

use of java.awt.event.MouseListener in project JWildfire by thargor6.

the class SystemInfoTest method testSystemInfoInternalFrame.

@Test
public void testSystemInfoInternalFrame() throws Exception {
    // SwingHelper.printTree(sif, 0);
    SystemInfoInternalFrame sif = new SystemInfoInternalFrame();
    sif.setVisible(true);
    JButton comp = (JButton) SwingHelper.match(sif, "siif.okbutton");
    JTextPane text = (JTextPane) SwingHelper.match(sif, "siif.text");
    String text1 = text.getText();
    Assert.assertNotNull(text1);
    for (MouseListener ml : (MouseListener[]) (comp.getListeners(MouseListener.class))) {
        if (ml != null && ml.getClass().getName().contains("SystemInfoInternalFrame"))
            ml.mouseClicked(null);
    }
    Assert.assertFalse("Expect SystemInfoInternalFrame to no longer be visible after click event", sif.isVisible());
    // use 4 more MB
    byte[] b = new byte[4096 * 1024];
    sif.refresh();
    // make sure it is not using same information
    Assert.assertNotEquals("Added " + b.length + "bytes, expect different stats", text1, text.getText());
}
Also used : JTextPane(javax.swing.JTextPane) MouseListener(java.awt.event.MouseListener) JButton(javax.swing.JButton)

Example 25 with MouseListener

use of java.awt.event.MouseListener in project Robot by fo0.

the class MainGUI method initialize.

/**
 * Initialize the contents of the frame.
 */
private static void initialize() {
    // create main frame
    frame = new JFrame();
    frame.setTitle("Robot v" + CONSTANTS.VERSION);
    frame.getContentPane().setLayout(null);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    // center frame on screen
    frame.setSize(655, 528);
    frame.setLocationRelativeTo(null);
    frame.getContentPane().setBackground(Color.LIGHT_GRAY);
    frame.setBackground(Color.LIGHT_GRAY);
    frame.setResizable(false);
    toggleConsole(currentMode);
    JPanel panelTop = new JPanel();
    panelTop.setBounds(0, 0, 653, 25);
    frame.getContentPane().add(panelTop);
    panelTop.setLayout(null);
    JButton btnAdd = new JButton("ADD");
    btnAdd.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            new AddChainItemWindow();
        }
    });
    btnAdd.setBounds(97, 0, 73, 24);
    panelTop.add(btnAdd);
    JButton btnDel = new JButton("DEL");
    btnDel.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            int col = actionTable.getSelectedRow();
            deleteItem(tableModel.getRow(col));
        }
    });
    btnDel.setBounds(169, 0, 73, 24);
    panelTop.add(btnDel);
    JButton btnStart = new JButton("START");
    btnStart.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent a) {
            new Thread(() -> {
                SwingUtilities.invokeLater(() -> {
                    areaConsole.setText("");
                    areaChain.setText("");
                });
                SwingUtilities.invokeLater(() -> {
                    toggleConsole(EMode.ConsoleMaximized);
                });
                Utils.sleep(TimeUnit.MILLISECONDS, 200);
                // adding listener to receive events from backend
                ControllerChain.getChain().addCmdListener((ctx, e) -> {
                    appendToChain(String.valueOf(e.getKey().getId()), e.getKey().getName(), e.getKey().getDescription(), e.getValue().getData().getState().getCmd().name());
                });
                // add listener for: Console output log
                ControllerChain.getChain().getContext().addOutputListener(cli -> {
                    appendToConsole(cli);
                });
                Utils.sleep(TimeUnit.SECONDS, 1);
                ControllerChain.start();
            }).start();
        }
    });
    btnStart.setBounds(0, 0, 98, 24);
    panelTop.add(btnStart);
    JButton buttonToggleConsole = new JButton(">_");
    buttonToggleConsole.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (currentMode == EMode.ConsoleMaximized) {
                toggleConsole(EMode.Normal);
            } else {
                toggleConsole(EMode.ConsoleMaximized);
            }
        }
    });
    buttonToggleConsole.setBounds(580, 0, 73, 24);
    panelTop.add(buttonToggleConsole);
    ErrorMode errMode = ErrorMode.FailOnErr;
    if (Controller.getConfig().ignoreErrors)
        errMode = ErrorMode.NotFailOnErr;
    JButton btnTgleErrors = new JButton(errMode.name());
    btnTgleErrors.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (btnTgleErrors.getText().equals(ErrorMode.FailOnErr.name())) {
                Controller.getConfig().ignoreErrors = true;
                btnTgleErrors.setText(ErrorMode.NotFailOnErr.name());
            } else {
                Controller.getConfig().ignoreErrors = false;
                btnTgleErrors.setText(ErrorMode.FailOnErr.name());
            }
        }
    });
    btnTgleErrors.setBounds(468, 0, 105, 24);
    panelTop.add(btnTgleErrors);
    createStopButton(panelTop);
    createProcessLabel(panelTop);
    JPanel panelTable = new JPanel();
    panelTable.setBounds(0, 26, 653, 265);
    frame.getContentPane().add(panelTable);
    panelTable.setLayout(new CardLayout(0, 0));
    actionTable = new JTable();
    actionTable.addMouseListener(new MouseListener() {

        @Override
        public void mouseReleased(MouseEvent e) {
        }

        @Override
        public void mousePressed(MouseEvent e) {
            if (e.getClickCount() == 2) {
                JTable table = (JTable) e.getSource();
                Point point = e.getPoint();
                int row = table.rowAtPoint(point);
                ActionItem item = tableModel.getRow(row);
                new AddChainItemWindow(item);
            }
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseClicked(MouseEvent e) {
        }
    });
    tableModel = new BeanTableModelAction();
    actionTable.setModel(tableModel);
    JScrollPane scrollPaneTable = new JScrollPane(actionTable);
    panelTable.add(scrollPaneTable, "name_7985051461163");
    JPanel panelChain = new JPanel();
    panelChain.setBounds(0, 292, 248, 188);
    frame.getContentPane().add(panelChain);
    panelChain.setLayout(new CardLayout(0, 0));
    areaChain = new JTextArea();
    areaChain.setEditable(false);
    JScrollPane scrollPaneChain = new JScrollPane(areaChain);
    // scrollPaneChain.getVerticalScrollBar().addAdjustmentListener(e -> {
    // e.getAdjustable().setValue(e.getAdjustable().getMaximum());
    // });
    panelChain.add(scrollPaneChain, "name_1466312782685");
    JPanel panelConsole = new JPanel();
    panelConsole.setBounds(248, 292, 405, 188);
    frame.getContentPane().add(panelConsole);
    panelConsole.setLayout(new CardLayout(0, 0));
    JScrollPane scrollPaneConsole = new JScrollPane((Component) null);
    // scrollPaneConsole.getVerticalScrollBar().addAdjustmentListener(e -> {
    // e.getAdjustable().setValue(e.getAdjustable().getMaximum());
    // });
    panelConsole.add(scrollPaneConsole, "name_2349855873542");
    areaConsole = new JTextArea();
    areaConsole.setEditable(false);
    scrollPaneConsole.setViewportView(areaConsole);
    JMenuBar menuBar = new JMenuBar();
    frame.setJMenuBar(menuBar);
    JMenu mnConfig = new JMenu("Config");
    menuBar.add(mnConfig);
    JMenuItem mntmConfigLoad = new JMenuItem("Load");
    mntmConfigLoad.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser = new JFileChooser();
            chooser.setCurrentDirectory(new File("."));
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Robot", "robot");
            chooser.setFileFilter(filter);
            int returnVal = chooser.showOpenDialog(null);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = chooser.getSelectedFile();
                // load config from disk -> file
                ControllerChain.getChain().getContext().loadFromFile(file.getAbsolutePath());
                MainGUI.getTableModel().loadActionContextFromController();
            }
        }
    });
    mnConfig.add(mntmConfigLoad);
    JMenuItem mntmConfigSave = new JMenuItem("Save");
    mntmConfigSave.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser = new JFileChooser();
            String lastPathDetection = ".";
            if (!Controller.getConfig().configFile.isEmpty()) {
                lastPathDetection = Controller.getConfig().configFile;
            }
            chooser.setCurrentDirectory(new File(lastPathDetection));
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Robot", "robot");
            chooser.setFileFilter(filter);
            int returnVal = chooser.showSaveDialog(null);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = chooser.getSelectedFile();
                if (!file.getName().endsWith(".robot")) {
                    Logger.info("detected missing file extension, appending .robot to file");
                    File tmpFile = new File(file.getAbsolutePath() + ".robot");
                    file.renameTo(tmpFile);
                    file = tmpFile;
                }
                // save config to disk -> file
                ControllerChain.getChain().getContext().save(file.getAbsolutePath());
            }
        }
    });
    mnConfig.add(mntmConfigSave);
    JMenu mnHelp = new JMenu("Help");
    menuBar.add(mnHelp);
    JMenuItem mntmHelpAbout = new JMenuItem("About");
    mntmHelpAbout.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
        }
    });
    mnHelp.add(mntmHelpAbout);
    JMenuItem mntmHelpUpdate = new JMenuItem("Update");
    mntmHelpUpdate.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            new UpdateWindow();
        }
    });
    mnHelp.add(mntmHelpUpdate);
    refreshTable();
    addChainObservers();
}
Also used : JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) UpdateWindow(com.fo0.robot.client.gui.sub.UpdateWindow) MouseListener(java.awt.event.MouseListener) JFrame(javax.swing.JFrame) JMenuItem(javax.swing.JMenuItem) JScrollPane(javax.swing.JScrollPane) CardLayout(java.awt.CardLayout) BeanTableModelAction(com.fo0.robot.model.BeanTableModelAction) MouseEvent(java.awt.event.MouseEvent) ActionItem(com.fo0.robot.model.ActionItem) Point(java.awt.Point) AddChainItemWindow(com.fo0.robot.client.gui.sub.AddChainItemWindow) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) ActionListener(java.awt.event.ActionListener) JFileChooser(javax.swing.JFileChooser) JTable(javax.swing.JTable) File(java.io.File) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Aggregations

MouseListener (java.awt.event.MouseListener)104 MouseEvent (java.awt.event.MouseEvent)67 Dimension (java.awt.Dimension)21 JLabel (javax.swing.JLabel)20 MouseAdapter (java.awt.event.MouseAdapter)19 JPanel (javax.swing.JPanel)16 Component (java.awt.Component)14 JComponent (javax.swing.JComponent)14 ActionEvent (java.awt.event.ActionEvent)13 ActionListener (java.awt.event.ActionListener)11 MouseMotionListener (java.awt.event.MouseMotionListener)11 JButton (javax.swing.JButton)11 JScrollPane (javax.swing.JScrollPane)11 Insets (java.awt.Insets)8 BorderLayout (java.awt.BorderLayout)7 Color (java.awt.Color)7 Point (java.awt.Point)7 File (java.io.File)7 ImageIcon (javax.swing.ImageIcon)6 JCheckBox (javax.swing.JCheckBox)6