Search in sources :

Example 26 with MouseAdapter

use of java.awt.event.MouseAdapter in project intellij-community by JetBrains.

the class IpnbEditablePanel method createEditablePanel.

private JTextArea createEditablePanel() {
    final JTextArea textArea = new JTextArea(getRawCellText());
    textArea.setLineWrap(true);
    textArea.setEditable(true);
    textArea.setBorder(BorderFactory.createLineBorder(JBColor.lightGray));
    textArea.setBackground(IpnbEditorUtil.getEditablePanelBackground());
    textArea.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 1) {
                setEditing(true);
                final Container parent = getParent();
                parent.repaint();
                if (parent instanceof IpnbFilePanel) {
                    ((IpnbFilePanel) parent).setSelectedCellPanel(IpnbEditablePanel.this);
                    IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
                        IdeFocusManager.getGlobalInstance().requestFocus(textArea, true);
                    });
                }
            }
        }
    });
    textArea.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                setEditing(false);
                final Container parent = getParent();
                if (parent instanceof IpnbFilePanel) {
                    parent.repaint();
                    UIUtil.requestFocus((IpnbFilePanel) parent);
                }
            }
        }
    });
    return textArea;
}
Also used : KeyEvent(java.awt.event.KeyEvent) MouseEvent(java.awt.event.MouseEvent) KeyAdapter(java.awt.event.KeyAdapter) MouseAdapter(java.awt.event.MouseAdapter)

Example 27 with MouseAdapter

use of java.awt.event.MouseAdapter in project intellij-community by JetBrains.

the class IpnbEditablePanel method addRightClickMenu.

@Override
protected void addRightClickMenu() {
    myViewPanel.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e) && e.getClickCount() == 1) {
                final DefaultActionGroup group = new DefaultActionGroup(new IpnbMergeCellAboveAction(), new IpnbMergeCellBelowAction());
                final ListPopup menu = createPopupMenu(group);
                menu.show(RelativePoint.fromScreen(e.getLocationOnScreen()));
            }
        }
    });
    myEditableTextArea.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e) && e.getClickCount() == 1) {
                final DefaultActionGroup group = new DefaultActionGroup(new IpnbSplitCellAction());
                final ListPopup menu = createPopupMenu(group);
                menu.show(RelativePoint.fromScreen(e.getLocationOnScreen()));
            }
        }
    });
}
Also used : MouseEvent(java.awt.event.MouseEvent) IpnbMergeCellBelowAction(org.jetbrains.plugins.ipnb.editor.actions.IpnbMergeCellBelowAction) MouseAdapter(java.awt.event.MouseAdapter) ListPopup(com.intellij.openapi.ui.popup.ListPopup) IpnbMergeCellAboveAction(org.jetbrains.plugins.ipnb.editor.actions.IpnbMergeCellAboveAction) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) IpnbSplitCellAction(org.jetbrains.plugins.ipnb.editor.actions.IpnbSplitCellAction)

Example 28 with MouseAdapter

use of java.awt.event.MouseAdapter in project intellij-community by JetBrains.

the class PaletteItemsComponent method updateUI.

@Override
public void updateUI() {
    setUI(new BasicListUI() {

        MouseListener myListener;

        @Override
        protected void updateLayoutState() {
            super.updateLayoutState();
            Insets insets = list.getInsets();
            int listWidth = list.getWidth() - (insets.left + insets.right);
            if (listWidth >= cellWidth) {
                int columnCount = listWidth / cellWidth;
                cellWidth = (columnCount == 0) ? 1 : listWidth / columnCount;
            }
        }

        @Override
        protected void installListeners() {
            addMouseListener(myListener = new MouseAdapter() {

                @Override
                public void mousePressed(MouseEvent e) {
                    myBeforeClickSelectedRow = list.getSelectedIndex();
                }
            });
            super.installListeners();
        }

        @Override
        protected void uninstallListeners() {
            if (myListener != null) {
                removeMouseListener(myListener);
            }
            super.uninstallListeners();
        }
    });
    invalidate();
}
Also used : MouseListener(java.awt.event.MouseListener) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) BasicListUI(javax.swing.plaf.basic.BasicListUI)

Example 29 with MouseAdapter

use of java.awt.event.MouseAdapter in project Botnak by Gocnak.

the class GUIStreams method initComponents.

private void initComponents() {
    JScrollPane scrollPane1 = new JScrollPane();
    followedList = new JList<>();
    listLabel = new JLabel();
    JLabel label3 = new JLabel();
    newChannel = new JTextField();
    JSeparator separator1 = new JSeparator();
    JSeparator separator2 = new JSeparator();
    JButton addStreamButton = new JButton();
    JButton doneButton = new JButton();
    //======== this ========
    setTitle("Add a Stream");
    setIconImage(new ImageIcon(getClass().getResource("/image/icon.png")).getImage());
    setResizable(false);
    Container contentPane = getContentPane();
    //======== scrollPane1 ========
    {
        //---- followedList ----
        setFollowedListModel("Enable \"Read followed Streams\" on", " your Oauth key!");
        followedList.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseReleased(MouseEvent e) {
                String selected = followedList.getSelectedValue();
                if (selected != null) {
                    newChannel.setText(selected);
                    newChannel.requestFocusInWindow();
                }
            }
        });
        followedList.setFocusable(false);
        scrollPane1.setViewportView(followedList);
    }
    //---- listLabel ----
    listLabel.setText("Followed Streams:");
    //---- label3 ----
    label3.setText("Twitch Username:");
    //---- newChannel ----
    newChannel.setFont(new Font("Tahoma", Font.PLAIN, 12));
    newChannel.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            newChannelKeyReleased(e);
        }
    });
    //---- addStreamButton ----
    addStreamButton.setText("Add");
    addStreamButton.setFocusable(false);
    addStreamButton.addActionListener(e -> addStreamButtonActionPerformed());
    //---- doneButton ----
    doneButton.setText("Close");
    doneButton.setFocusable(false);
    doneButton.addActionListener(e -> doneButtonActionPerformed());
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    GroupLayout contentPaneLayout = new GroupLayout(contentPane);
    contentPane.setLayout(contentPaneLayout);
    contentPaneLayout.setHorizontalGroup(contentPaneLayout.createParallelGroup().addGroup(contentPaneLayout.createSequentialGroup().addContainerGap().addGroup(contentPaneLayout.createParallelGroup().addGroup(contentPaneLayout.createSequentialGroup().addComponent(addStreamButton, GroupLayout.PREFERRED_SIZE, 56, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE).addComponent(doneButton, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)).addGroup(contentPaneLayout.createSequentialGroup().addGroup(contentPaneLayout.createParallelGroup().addComponent(listLabel).addComponent(scrollPane1, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE).addComponent(label3).addComponent(newChannel, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE)).addGap(0, 0, Short.MAX_VALUE))).addContainerGap()).addComponent(separator1, GroupLayout.DEFAULT_SIZE, 174, Short.MAX_VALUE).addComponent(separator2, GroupLayout.DEFAULT_SIZE, 174, Short.MAX_VALUE));
    contentPaneLayout.setVerticalGroup(contentPaneLayout.createParallelGroup().addGroup(contentPaneLayout.createSequentialGroup().addContainerGap().addComponent(listLabel).addGap(6, 6, 6).addComponent(scrollPane1, GroupLayout.PREFERRED_SIZE, 125, GroupLayout.PREFERRED_SIZE).addGap(8, 8, 8).addComponent(separator1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addComponent(label3).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(newChannel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addComponent(separator2, GroupLayout.PREFERRED_SIZE, 2, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(addStreamButton, GroupLayout.PREFERRED_SIZE, 28, GroupLayout.PREFERRED_SIZE).addComponent(doneButton, GroupLayout.PREFERRED_SIZE, 29, GroupLayout.PREFERRED_SIZE)).addContainerGap(3, Short.MAX_VALUE)));
    pack();
    setLocationRelativeTo(getOwner());
}
Also used : MouseEvent(java.awt.event.MouseEvent) KeyAdapter(java.awt.event.KeyAdapter) MouseAdapter(java.awt.event.MouseAdapter) KeyEvent(java.awt.event.KeyEvent)

Example 30 with MouseAdapter

use of java.awt.event.MouseAdapter in project otapij by FellowTraveler.

the class DatePicker method init.

/**
     * Initializes the panel components according to the current value
     * of selectedDate.
     */
private void init() {
    setLayout(new AbsoluteLayout());
    this.setMinimumSize(new Dimension(161, 226));
    this.setMaximumSize(getMinimumSize());
    this.setPreferredSize(getMinimumSize());
    this.setBorder(new BorderUIResource.EtchedBorderUIResource());
    backButton.setFont(smallFont);
    backButton.setText("<");
    backButton.setMargin(insets);
    backButton.setDefaultCapable(false);
    backButton.addActionListener(new ActionListener() {

        public void actionPerformed(final ActionEvent evt) {
            onBackClicked(evt);
        }
    });
    add(backButton, new AbsoluteConstraints(10, 10, 20, 20));
    monthAndYear.setFont(largeFont);
    monthAndYear.setHorizontalAlignment(JTextField.CENTER);
    monthAndYear.setText(formatDateText(selectedDate.getTime()));
    add(monthAndYear, new AbsoluteConstraints(30, 10, 100, 20));
    forwardButton.setFont(smallFont);
    forwardButton.setText(">");
    forwardButton.setMargin(insets);
    forwardButton.setDefaultCapable(false);
    forwardButton.addActionListener(new ActionListener() {

        public void actionPerformed(final ActionEvent evt) {
            onForwardClicked(evt);
        }
    });
    add(forwardButton, new AbsoluteConstraints(130, 10, 20, 20));
    // layout the column headings for the days of the week
    int x = startX;
    for (int ii = 0; ii < dayHeadings.length; ii++) {
        dayHeadings[ii].setBackground(gray);
        dayHeadings[ii].setEditable(false);
        dayHeadings[ii].setFont(smallFont);
        dayHeadings[ii].setHorizontalAlignment(JTextField.CENTER);
        dayHeadings[ii].setFocusable(false);
        add(dayHeadings[ii], new AbsoluteConstraints(x, 40, 21, 21));
        x += 20;
    }
    // layout the days of the month
    x = startX;
    int y = startY;
    for (int ii = 0; ii < daysInMonth.length; ii++) {
        for (int jj = 0; jj < daysInMonth[ii].length; jj++) {
            daysInMonth[ii][jj].setBackground(gray);
            daysInMonth[ii][jj].setEditable(false);
            daysInMonth[ii][jj].setFont(smallFont);
            daysInMonth[ii][jj].setHorizontalAlignment(JTextField.RIGHT);
            daysInMonth[ii][jj].setText("");
            daysInMonth[ii][jj].setFocusable(false);
            daysInMonth[ii][jj].addMouseListener(new MouseAdapter() {

                public void mouseClicked(final MouseEvent evt) {
                    onDayClicked(evt);
                }
            });
            add(daysInMonth[ii][jj], new AbsoluteConstraints(x, y, 21, 21));
            x += 20;
        }
        x = startX;
        y += 20;
    }
    initButtons(true);
    calculateCalendar();
}
Also used : MouseEvent(java.awt.event.MouseEvent) BorderUIResource(javax.swing.plaf.BorderUIResource) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) MouseAdapter(java.awt.event.MouseAdapter) AbsoluteLayout(org.netbeans.lib.awtextra.AbsoluteLayout) AbsoluteConstraints(org.netbeans.lib.awtextra.AbsoluteConstraints)

Aggregations

MouseAdapter (java.awt.event.MouseAdapter)202 MouseEvent (java.awt.event.MouseEvent)199 JLabel (javax.swing.JLabel)52 JPanel (javax.swing.JPanel)48 ActionEvent (java.awt.event.ActionEvent)36 JScrollPane (javax.swing.JScrollPane)36 BorderLayout (java.awt.BorderLayout)35 Dimension (java.awt.Dimension)34 JButton (javax.swing.JButton)33 ActionListener (java.awt.event.ActionListener)32 Insets (java.awt.Insets)24 GridBagConstraints (java.awt.GridBagConstraints)20 KeyEvent (java.awt.event.KeyEvent)20 KeyAdapter (java.awt.event.KeyAdapter)19 JTextField (javax.swing.JTextField)16 ListSelectionEvent (javax.swing.event.ListSelectionEvent)16 Component (java.awt.Component)15 Point (java.awt.Point)15 JTable (javax.swing.JTable)15 ListSelectionListener (javax.swing.event.ListSelectionListener)15