Example usage for javax.swing JLabel addMouseListener

List of usage examples for javax.swing JLabel addMouseListener

Introduction

In this page you can find the example usage for javax.swing JLabel addMouseListener.

Prototype

public synchronized void addMouseListener(MouseListener l) 

Source Link

Document

Adds the specified mouse listener to receive mouse events from this component.

Usage

From source file:shuffle.fwk.service.roster.EditRosterService.java

private JPanel createRosterComponent(Species s) {
    JPanel ret = new JPanel(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.BOTH;
    c.gridx = 1;/*from   w  ww  .jav  a2  s.c  o  m*/
    c.gridy = 1;
    c.anchor = GridBagConstraints.CENTER;

    MouseAdapter ma = new PressOrClickMouseAdapter() {

        @Override
        protected void onRight(MouseEvent e) {
            onLeft(e);
        }

        @Override
        protected void onLeft(MouseEvent e) {
            setSelected(s, ret);
            selectedDisplayLabel.repaint();
        }

        @Override
        protected void onEnter() {
            // Do nothing
        }
    };
    SpeciesPaint sp = new SpeciesPaint(s, false, getMegaFilter());
    ImageIcon icon = getUser().getImageManager().getImageFor(sp);
    JLabel iconLabel = new JLabel(icon);
    iconLabel.addMouseListener(ma);
    ret.add(iconLabel, c);
    c.gridy += 1;
    JLabel jLabel = new JLabel(s.getLocalizedName(getMegaFilter()));
    jLabel.setHorizontalTextPosition(SwingConstants.CENTER);
    jLabel.setHorizontalAlignment(SwingConstants.CENTER);
    jLabel.addMouseListener(ma);
    ret.add(jLabel, c);
    JComboBox<Integer> level = new JComboBox<Integer>();
    for (int i = 0; i <= Species.MAX_LEVEL; i++) {
        level.addItem(i);
    }
    Integer thisLevel = getLevelFor(s);
    level.setSelectedItem(thisLevel);
    level.setToolTipText(getString(KEY_POKEMON_LEVEL_TOOLTIP));
    c.gridy += 1; // put the level selector below the icon.
    ret.add(level, c);
    level.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            int index = level.getSelectedIndex();
            myData.setLevelForSpecies(s, index);
            rebuildSelectedLabel();
        }
    });
    return ret;
}

From source file:shuffle.fwk.service.teams.EditTeamService.java

private JPanel createRosterComponent(Species s) {
    JPanel ret = new JPanel(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.gridx = 1;//from  w w w  . j av  a2s .  c o m
    c.gridy = 1;
    c.anchor = GridBagConstraints.CENTER;

    MouseAdapter ma = new PressOrClickMouseAdapter() {

        @Override
        protected void onRight(MouseEvent e) {
            onLeft(e);
        }

        @Override
        protected void onLeft(MouseEvent e) {
            setSelected(s, ret);
            selectedDisplayLabel.repaint();
        }

        @Override
        protected void onEnter() {
            // Do nothing
        }
    };
    SpeciesPaint sp = new SpeciesPaint(s, false, getMegaFilter());
    ImageIcon icon = getUser().getImageManager().getImageFor(sp);
    JLabel iconLabel = new JLabel(icon);
    iconLabel.addMouseListener(ma);
    ret.add(iconLabel, c);
    c.gridy += 1;
    JLabel jLabel = new JLabel(s.getLocalizedName(getMegaFilter()));
    jLabel.setHorizontalTextPosition(SwingConstants.CENTER);
    jLabel.setHorizontalAlignment(SwingConstants.CENTER);
    jLabel.addMouseListener(ma);
    ret.add(jLabel, c);

    JButton addToTeam = new JButton(getString(KEY_ADD));
    addToTeam.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            addSpeciesToTeam(s);
            updateTeamPanel();
        }
    });
    addToTeam.setToolTipText(getString(KEY_ADD_TOOLTIP));
    c.gridy += 1;
    ret.add(addToTeam, c);

    return ret;
}

From source file:utybo.branchingstorytree.swing.visuals.AboutDialog.java

@SuppressWarnings("unchecked")
public AboutDialog(OpenBSTGUI parent) {
    super(parent);
    setTitle(Lang.get("about.title"));
    setModalityType(ModalityType.APPLICATION_MODAL);

    JPanel banner = new JPanel(new FlowLayout(FlowLayout.CENTER));
    banner.setBackground(OpenBSTGUI.OPENBST_BLUE);
    JLabel lblOpenbst = new JLabel(new ImageIcon(Icons.getImage("FullLogoWhite", 48)));
    lblOpenbst.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    banner.add(lblOpenbst, "flowx,cell 0 0,alignx center");
    getContentPane().add(banner, BorderLayout.NORTH);

    JPanel pan = new JPanel();
    pan.setLayout(new MigLayout("insets 10, gap 10px", "[grow]", "[][][grow]"));
    getContentPane().add(pan, BorderLayout.CENTER);

    JLabel lblWebsite = new JLabel("https://utybo.github.io/BST/");
    Font f = lblWebsite.getFont();
    @SuppressWarnings("rawtypes")
    Map attrs = f.getAttributes();
    attrs.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
    lblWebsite.setFont(f.deriveFont(attrs));
    lblWebsite.setForeground(OpenBSTGUI.OPENBST_BLUE);
    lblWebsite.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    lblWebsite.addMouseListener(new MouseAdapter() {
        @Override/*  w w w.  ja  v a2s .  c om*/
        public void mouseClicked(MouseEvent e) {
            if (Desktop.isDesktopSupported()) {
                try {
                    Desktop.getDesktop().browse(new URL("https://utybo.github.io/BST/").toURI());
                } catch (IOException | URISyntaxException e1) {
                    OpenBST.LOG.warn("Exception when trying to open website", e1);
                }
            }
        }
    });
    pan.add(lblWebsite, "cell 0 0,alignx center");

    JLabel lblVersion = new JLabel(Lang.get("about.version").replace("$v", OpenBST.VERSION));
    pan.add(lblVersion, "flowy,cell 0 1");

    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setBorder(new LineBorder(pan.getBackground().darker(), 1, false));
    pan.add(scrollPane, "cell 0 2,grow");

    JTextArea textArea = new JTextArea();
    textArea.setMargin(new Insets(5, 5, 5, 5));
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);
    textArea.setFont(new Font(textArea.getFont().getFontName(), Font.PLAIN, (int) (Icons.getScale() * 11)));

    try (InputStream in = getClass().getResourceAsStream("/utybo/branchingstorytree/swing/about.txt");) {
        textArea.setText(IOUtils.toString(in, StandardCharsets.UTF_8));
    } catch (IOException ex) {
        OpenBST.LOG.warn("Loading about information failed", ex);
    }
    textArea.setEditable(false);
    textArea.setCaretPosition(0);
    scrollPane.setViewportView(textArea);

    JLabel lblTranslatedBy = new JLabel(Lang.get("author"));
    pan.add(lblTranslatedBy, "cell 0 1");

    setSize((int) (Icons.getScale() * 450), (int) (Icons.getScale() * 400));
    setLocationRelativeTo(parent);
}