Search in sources :

Example 91 with MouseListener

use of java.awt.event.MouseListener in project Terasology by MovingBlocks.

the class AwtMouseDevice method registerToAwtGlCanvas.

public void registerToAwtGlCanvas(AWTGLCanvas canvas) {
    canvas.addMouseListener(new MouseListener() {

        @Override
        public void mouseClicked(MouseEvent e) {
        }

        @Override
        public void mousePressed(MouseEvent e) {
            int button = e.getButton() - 1;
            buttonStates.add(button);
            MouseInput mouseInput = MouseInput.find(InputType.MOUSE_BUTTON, button);
            queue.offer(new MouseAction(mouseInput, ButtonState.DOWN, getPosition()));
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            int button = e.getButton() - 1;
            buttonStates.remove(button);
            MouseInput mouseInput = MouseInput.find(InputType.MOUSE_BUTTON, button);
            queue.offer(new MouseAction(mouseInput, ButtonState.UP, getPosition()));
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }
    });
    canvas.addMouseMotionListener(new MouseMotionListener() {

        @Override
        public void mouseDragged(MouseEvent e) {
            updateMouse(e.getX(), e.getY());
        }

        @Override
        public void mouseMoved(MouseEvent e) {
            updateMouse(e.getX(), e.getY());
        }
    });
    canvas.addMouseWheelListener(e -> {
        int yOffset = e.getUnitsToScroll();
        if (yOffset != 0.0) {
            int id = (yOffset > 0) ? 1 : -1;
            queue.offer(new MouseAction(InputType.MOUSE_WHEEL.getInput(id), 1, getPosition()));
        }
    });
}
Also used : MouseAction(org.terasology.input.device.MouseAction) MouseListener(java.awt.event.MouseListener) MouseEvent(java.awt.event.MouseEvent) MouseMotionListener(java.awt.event.MouseMotionListener) MouseInput(org.terasology.input.MouseInput)

Example 92 with MouseListener

use of java.awt.event.MouseListener in project triplea by triplea-game.

the class ColorProperty method getEditorComponent.

@Override
public JComponent getEditorComponent() {
    final JLabel label = new JLabel("        ") {

        private static final long serialVersionUID = 3833935337866905836L;

        @Override
        public void paintComponent(final Graphics g) {
            final Graphics2D g2 = (Graphics2D) g;
            g2.setColor(color);
            g2.fill(g2.getClip());
        }
    };
    label.addMouseListener(new MouseListener() {

        @Override
        public void mouseClicked(final MouseEvent e) {
            try {
                final Color colorSelected = JColorChooser.showDialog(label, "Choose color", (ColorProperty.this.color == null ? Color.black : ColorProperty.this.color));
                if (colorSelected != null) {
                    color = colorSelected;
                    // Ask Swing to repaint this label when it's convenient
                    SwingUtilities.invokeLater(label::repaint);
                }
            } catch (final Exception exception) {
                System.err.println(exception.getMessage());
            }
        }

        @Override
        public void mouseEntered(final MouseEvent e) {
        }

        @Override
        public void mouseExited(final MouseEvent e) {
        }

        @Override
        public void mousePressed(final MouseEvent e) {
        }

        @Override
        public void mouseReleased(final MouseEvent e) {
        }
    });
    return label;
}
Also used : Graphics(java.awt.Graphics) MouseListener(java.awt.event.MouseListener) MouseEvent(java.awt.event.MouseEvent) Color(java.awt.Color) JLabel(javax.swing.JLabel) Graphics2D(java.awt.Graphics2D)

Example 93 with MouseListener

use of java.awt.event.MouseListener in project triplea by triplea-game.

the class FileProperty method getEditorComponent.

/**
 * Gets a Swing component to display this property.
 *
 * @return a non-editable JTextField
 */
@Override
public JComponent getEditorComponent() {
    final JTextField label;
    if (m_file == null) {
        label = new JTextField();
    } else {
        label = new JTextField(m_file.getAbsolutePath());
    }
    label.setEditable(false);
    label.addMouseListener(new MouseListener() {

        @Override
        public void mouseClicked(final MouseEvent e) {
            final File selection = getFileUsingDialog(m_acceptableSuffixes);
            if (selection != null) {
                m_file = selection;
                label.setText(m_file.getAbsolutePath());
                // Ask Swing to repaint this label when it's convenient
                SwingUtilities.invokeLater(label::repaint);
            }
        }

        @Override
        public void mouseEntered(final MouseEvent e) {
        }

        @Override
        public void mouseExited(final MouseEvent e) {
        }

        @Override
        public void mousePressed(final MouseEvent e) {
        }

        @Override
        public void mouseReleased(final MouseEvent e) {
        }
    });
    return label;
}
Also used : MouseListener(java.awt.event.MouseListener) MouseEvent(java.awt.event.MouseEvent) JTextField(javax.swing.JTextField) File(java.io.File)

Example 94 with MouseListener

use of java.awt.event.MouseListener in project triplea by triplea-game.

the class GameChooser method setupListeners.

private void setupListeners() {
    okButton.addActionListener(e -> selectAndReturn());
    cancelButton.addActionListener(e -> cancelAndReturn());
    gameList.addListSelectionListener(e -> updateInfoPanel());
    gameList.addMouseListener(new MouseListener() {

        @Override
        public void mouseClicked(final MouseEvent event) {
            if (event.getClickCount() == 2) {
                selectAndReturn();
            }
        }

        @Override
        public void mousePressed(final MouseEvent e) {
        }

        @Override
        public void mouseReleased(final MouseEvent e) {
        }

        @Override
        public void mouseEntered(final MouseEvent e) {
        }

        @Override
        public void mouseExited(final MouseEvent e) {
        }
    });
}
Also used : MouseListener(java.awt.event.MouseListener) MouseEvent(java.awt.event.MouseEvent)

Example 95 with MouseListener

use of java.awt.event.MouseListener in project cardgame1 by joey101937.

the class DeckBuilder method init.

/**
 * initializes core components
 */
private void init() {
    panel = new BackgroundPane(Main.BackgroundImage);
    panel.setSize(this.getSize());
    panel.setLayout(null);
    this.add(panel);
    scroll = new JScrollPane();
    scroll.setSize(700, 500);
    scroll.setLocation(10, 100);
    scroll.getVerticalScrollBar().setUnitIncrement(20);
    scroll.getHorizontalScrollBar().setEnabled(false);
    interior = new JPanel();
    interior.setLocation(0, 0);
    interior.setSize(700, 1000);
    interior.setPreferredSize(interior.getSize());
    interior.setBackground(Color.gray);
    scroll.add(interior);
    scroll.setViewportView(interior);
    panel.add(scroll);
    interior.setLayout(null);
    titleLabel = new JLabel();
    titleLabel.setSize(300, 50);
    titleLabel.setText("DECK BUILDER");
    titleLabel.setLocation(400, 20);
    titleLabel.setFont(titleFont);
    panel.add(titleLabel);
    classTitle = new JLabel();
    classTitle.setFont(classTitleFont);
    classTitle.setText("Deck Class:");
    classTitle.setLocation(20, 10);
    classTitle.setSize(200, 30);
    panel.add(classTitle);
    classCombo = new JComboBox();
    classCombo.setSize(new Dimension(200, 25));
    classCombo.setLocation(20, 50);
    classCombo.addItem(HeroClass.Neutral);
    classCombo.addItem(HeroClass.Ocean);
    classCombo.addItem(HeroClass.Undead);
    classCombo.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            updateDeckClass();
        }
    });
    panel.add(classCombo);
    classLabel = new JLabel();
    classLabel.setSize(80, 80);
    classLabel.setLocation(230, 20);
    classLabel.setIcon(new ImageIcon(product.deckClass.getClassIcon()));
    panel.add(classLabel);
    isValidLabel = new JLabel();
    isValidLabel.setSize(200, 100);
    isValidLabel.setLocation(770, 550);
    isValidLabel.setFont(classTitleFont);
    updateIsValidLabel();
    isValidLabel.addMouseListener(new MouseListener() {

        @Override
        public void mouseClicked(MouseEvent e) {
        }

        @Override
        public void mousePressed(MouseEvent e) {
            if (!product.isValid()) {
                String toDisplay = "";
                for (String s : product.diagnose()) {
                    toDisplay += (s + "\n");
                }
                JOptionPane.showMessageDialog(null, toDisplay);
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }
    });
    panel.add(isValidLabel);
    loadButton = new JButton();
    loadButton.setSize(100, 50);
    loadButton.setLocation(510, 600);
    loadButton.setText("Load...");
    loadButton.setFont(classTitleFont);
    loadButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            mainBuilder.setEnabled(false);
            DeckLoaderScratch dl = new DeckLoaderScratch(mainBuilder);
        }
    });
    panel.add(loadButton);
    clearButton = new JButton();
    clearButton.setSize(100, 50);
    clearButton.setLocation(410, 600);
    clearButton.setText("Clear");
    clearButton.setFont(classTitleFont);
    clearButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            product.deck.clear();
            mainBuilder.updateList();
        }
    });
    panel.add(clearButton);
    saveButton = new JButton();
    saveButton.setSize(100, 50);
    saveButton.setText("Save...");
    saveButton.setFont(classTitleFont);
    saveButton.setLocation(610, 600);
    panel.add(saveButton);
    saveButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            String givenName = JOptionPane.showInputDialog("Save as...");
            if (givenName == null || givenName.trim().equals("")) {
                JOptionPane.showMessageDialog(null, "No name detected");
                return;
            }
            if (!isStringSafe(givenName)) {
                JOptionPane.showMessageDialog(null, "Name cannot contain the following characters:\n ~ # % * { } [ ] < > ? /\\ + |");
                return;
            }
            product.deckName = givenName;
            File f = new File("Decks/" + givenName + ".deck");
            if (f.exists()) {
                int shouldOverwrite = JOptionPane.showConfirmDialog(null, "Deck already exists. Overwrite?");
                // user doesnt want to overwrite
                if (shouldOverwrite != 0)
                    return;
            }
            product.export();
            JOptionPane.showMessageDialog(null, "Deck Saved!\n" + f.getAbsolutePath());
        }
    });
    int column = 0;
    int row = 0;
    for (Card c : Card.getCardList()) {
        CardIcon ci = new CardIcon(c, this);
        ci.setLocation(10 + column * (c.sprite.getWidth() + 30), row * (c.sprite.getHeight() + 20));
        column++;
        if (column > 2) {
            row++;
            column = 0;
        }
        interior.add(ci);
    }
    interior.setPreferredSize(new Dimension(700, row * (300 + 20)));
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) ImageIcon(javax.swing.ImageIcon) MouseEvent(java.awt.event.MouseEvent) JComboBox(javax.swing.JComboBox) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) Card(Cards.Card) MouseListener(java.awt.event.MouseListener) ActionListener(java.awt.event.ActionListener) File(java.io.File)

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