Search in sources :

Example 91 with ActionListener

use of java.awt.event.ActionListener in project OpenNotebook by jaltekruse.

the class OCButton method addToContainer.

private void addToContainer(int gridwidth, int gridheight, int gridx, int gridy, boolean hasInsets, JComponent comp) {
    setMargin(new Insets(1, 1, 1, 1));
    GridBagConstraints bCon;
    bCon = new GridBagConstraints();
    bCon.fill = GridBagConstraints.BOTH;
    bCon.weightx = .1;
    bCon.weighty = .2;
    bCon.gridheight = gridheight;
    bCon.gridwidth = gridwidth;
    bCon.gridx = gridx;
    bCon.gridy = gridy;
    bCon.insets = new Insets(2, 2, 2, 2);
    this.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            associatedAction();
        }
    });
    comp.add(this, bCon);
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent)

Example 92 with ActionListener

use of java.awt.event.ActionListener in project OpenNotebook by jaltekruse.

the class EnumeratedAdjuster method addPanelContent.

@Override
public void addPanelContent() {
    if (displayFormat == COMBO_BOX) {
        setLayout(new GridBagLayout());
        GridBagConstraints con = new GridBagConstraints();
        con.fill = GridBagConstraints.HORIZONTAL;
        con.weightx = .1;
        con.gridx = 0;
        con.gridy = 0;
        con.insets = new Insets(0, 10, 0, 0);
        add(new JLabel(mAtt.getName()), con);
        con.insets = new Insets(0, 10, 0, 5);
        con.weightx = 1;
        con.gridx = 1;
        final JComboBox valueChoices = new JComboBox(mAtt.getPossibleValues());
        valueChoices.setSelectedItem(mAtt.getValue());
        valueChoices.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ev) {
                mAtt.setValue((String) valueChoices.getSelectedItem());
                if (notebookPanel != null) {
                    notebookPanel.getCurrentDocViewer().addUndoState();
                    notebookPanel.getCurrentDocViewer().repaintDoc();
                }
            }
        });
        this.add(valueChoices, con);
    } else if (displayFormat == RADIO_BUTTON_ROW) {
        setLayout(new GridBagLayout());
        GridBagConstraints con = new GridBagConstraints();
        con.fill = GridBagConstraints.HORIZONTAL;
        con.weightx = .1;
        con.gridwidth = mAtt.getPossibleValues().length;
        con.gridx = 0;
        con.gridy = 0;
        con.insets = new Insets(2, 2, 2, 2);
        Font f = new Font("Arial", Font.PLAIN, 12);
        Font smallF = new Font("Arial", Font.PLAIN, 11);
        JLabel label = new JLabel(mAtt.getName());
        label.setFont(f);
        add(label, con);
        con.gridwidth = 1;
        con.weightx = 1;
        con.gridy++;
        final ButtonGroup group = new ButtonGroup();
        for (final String s : mAtt.getPossibleValues()) {
            final JRadioButton button = new JRadioButton(s);
            button.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent ev) {
                    mAtt.setValue(s);
                    if (notebookPanel != null) {
                        notebookPanel.getCurrentDocViewer().addUndoState();
                        notebookPanel.getCurrentDocViewer().repaintDoc();
                    }
                }
            });
            if (mAtt.getValue().equals(s)) {
                button.setSelected(true);
            }
            button.setFont(smallF);
            this.add(button, con);
            group.add(button);
            con.gridx++;
        }
    } else if (displayFormat == RADIO_BUTTON_COLOUMN) {
    }
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) JRadioButton(javax.swing.JRadioButton) GridBagLayout(java.awt.GridBagLayout) JComboBox(javax.swing.JComboBox) ActionListener(java.awt.event.ActionListener) ButtonGroup(javax.swing.ButtonGroup) ActionEvent(java.awt.event.ActionEvent) JLabel(javax.swing.JLabel) Font(java.awt.Font)

Example 93 with ActionListener

use of java.awt.event.ActionListener in project OpenNotebook by jaltekruse.

the class GenericAdjustmentPanel method addPanelContent.

@Override
public void addPanelContent() {
    setLayout(new GridBagLayout());
    GridBagConstraints con = new GridBagConstraints();
    con.fill = GridBagConstraints.HORIZONTAL;
    con.weightx = .1;
    con.gridx = 0;
    con.gridy = 0;
    con.insets = new Insets(0, 5, 0, 5);
    add(new JLabel(mAtt.getName()), con);
    field = new JTextField();
    con.weightx = 1;
    con.gridx = 1;
    con.insets = new Insets(0, 0, 0, 0);
    add(field, con);
    if (mAtt.getValue() instanceof Double) {
        int len = mAtt.getValue().toString().length();
        if (len > 5) {
            formatter = new Formatter();
            field.setText(String.format("%.5G", mAtt.getValue()));
        }
    } else {
        if (mAtt.getValue() == null) {
            field.setText("");
        } else
            field.setText(mAtt.getValue().toString());
    }
    field.addFocusListener(new FocusListener() {

        @Override
        public void focusGained(FocusEvent arg0) {
        }

        @Override
        public void focusLost(FocusEvent arg0) {
            try {
                if (mAtt.getParentObject() != null) {
                    mAtt.getParentObject().setAttributeValueWithString(mAtt.getName(), field.getText());
                } else {
                    mAtt.setValueWithString(field.getText());
                }
                if (notebookPanel != null) {
                    notebookPanel.getCurrentDocViewer().repaintDoc();
                    notebookPanel.getCurrentDocViewer().updateObjectToolFrame();
                }
            } catch (AttributeException e) {
                if (!showingDialog) {
                    JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
                    showingDialog = false;
                }
            }
        }
    });
    field.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            applyPanelValueToObject();
        }
    });
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) Formatter(java.util.Formatter) ActionEvent(java.awt.event.ActionEvent) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) FocusEvent(java.awt.event.FocusEvent) AttributeException(doc.attributes.AttributeException) ActionListener(java.awt.event.ActionListener) FocusListener(java.awt.event.FocusListener)

Example 94 with ActionListener

use of java.awt.event.ActionListener in project jna by java-native-access.

the class AlphaMaskDemo2 method run.

public void run() {
    // Must find a graphics configuration with a depth of 32 bits
    GraphicsConfiguration gconfig = WindowUtils.getAlphaCompatibleGraphicsConfiguration();
    frame = new JFrame("Alpha Mask Demo");
    alphaWindow = new JWindow(frame, gconfig);
    icon = new JLabel();
    icon.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    alphaWindow.getContentPane().add(icon);
    JButton quit = new JButton("Quit");
    JLabel label = new JLabel("Drag this window by its image");
    label.setHorizontalAlignment(SwingConstants.CENTER);
    alphaWindow.getContentPane().add(label, BorderLayout.NORTH);
    alphaWindow.getContentPane().add(quit, BorderLayout.SOUTH);
    quit.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });
    MouseInputAdapter handler = new MouseInputAdapter() {

        private Point offset;

        public void mousePressed(MouseEvent e) {
            if (SwingUtilities.isLeftMouseButton(e))
                offset = e.getPoint();
        }

        public void mouseReleased(MouseEvent e) {
            offset = null;
        }

        public void mouseDragged(MouseEvent e) {
            if (offset != null) {
                Window w = (Window) e.getSource();
                Point where = e.getPoint();
                where.translate(-offset.x, -offset.y);
                Point loc = w.getLocationOnScreen();
                loc.translate(where.x, where.y);
                w.setLocation(loc.x, loc.y);
            }
        }
    };
    alphaWindow.addMouseListener(handler);
    alphaWindow.addMouseMotionListener(handler);
    JPanel p = new JPanel(new BorderLayout(8, 8));
    p.setBorder(new EmptyBorder(8, 8, 8, 8));
    p.setTransferHandler(new TransferHandler() {

        private static final long serialVersionUID = 1L;

        public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) {
            List<DataFlavor> list = Arrays.asList(transferFlavors);
            if (list.contains(URL_FLAVOR) || list.contains(URI_LIST_FLAVOR) || list.contains(DataFlavor.imageFlavor) || list.contains(DataFlavor.javaFileListFlavor)) {
                return true;
            }
            if (DataFlavor.selectBestTextFlavor(transferFlavors) != null) {
                return true;
            }
            System.err.println("No acceptable flavor found in " + Arrays.asList(transferFlavors));
            return false;
        }

        public boolean importData(JComponent comp, Transferable t) {
            try {
                if (t.isDataFlavorSupported(URL_FLAVOR)) {
                    URL url = (URL) t.getTransferData(URL_FLAVOR);
                    setImage(Toolkit.getDefaultToolkit().getImage(url));
                    return true;
                }
                if (t.isDataFlavorSupported(URI_LIST_FLAVOR)) {
                    String s = (String) t.getTransferData(URI_LIST_FLAVOR);
                    String[] uris = s.split("[\r\n]");
                    if (uris.length > 0) {
                        URL url = new URL(uris[0]);
                        setImage(Toolkit.getDefaultToolkit().getImage(url));
                        return true;
                    }
                    return false;
                }
                if (t.isDataFlavorSupported(DataFlavor.imageFlavor)) {
                    Image image = (Image) t.getTransferData(DataFlavor.imageFlavor);
                    setImage(image);
                    return true;
                }
                if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
                    List<File> files = (List<File>) t.getTransferData(DataFlavor.javaFileListFlavor);
                    File f = files.get(0);
                    URL url = new URL("file://" + f.toURI().toURL().getPath());
                    Image image = Toolkit.getDefaultToolkit().getImage(url);
                    setImage(image);
                    return true;
                }
                DataFlavor flavor = DataFlavor.selectBestTextFlavor(t.getTransferDataFlavors());
                if (flavor != null) {
                    Reader reader = flavor.getReaderForText(t);
                    char[] buf = new char[512];
                    StringBuilder b = new StringBuilder();
                    int count;
                    // encoding wrong
                    while ((count = reader.read(buf)) > 0) {
                        for (int i = 0; i < count; i++) {
                            if (buf[i] != 0)
                                b.append(buf, i, 1);
                        }
                    }
                    String html = b.toString();
                    Pattern p = Pattern.compile("<img.*src=\"([^\\\"\">]+)\"", Pattern.CANON_EQ | Pattern.UNICODE_CASE);
                    Matcher m = p.matcher(html);
                    if (m.find()) {
                        URL url = new URL(m.group(1));
                        System.out.println("Load image from " + url);
                        Image image = Toolkit.getDefaultToolkit().getImage(url);
                        setImage(image);
                        return true;
                    }
                    System.err.println("Can't parse text: " + html);
                    return false;
                }
                System.err.println("No flavor available: " + Arrays.asList(t.getTransferDataFlavors()));
            } catch (UnsupportedFlavorException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (Throwable e) {
                e.printStackTrace();
            }
            return false;
        }
    });
    p.add(new JLabel("<html><center>Drop an image with an alpha channel onto this window<br>" + "You may also adjust the overall transparency with the slider</center></html>"), BorderLayout.NORTH);
    p.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    final JSlider slider = new JSlider(0, 255, 255);
    slider.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            int value = slider.getValue();
            WindowUtils.setWindowAlpha(alphaWindow, value / 255f);
        }
    });
    p.add(slider, BorderLayout.SOUTH);
    frame.getContentPane().add(p);
    frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    centerOnScreen(frame);
    frame.setVisible(true);
    WindowUtils.setWindowTransparent(alphaWindow, true);
    alphaWindow.setLocation(frame.getX() + frame.getWidth() + 4, frame.getY());
    try {
        URL url = getClass().getResource("tardis.png");
        if (url != null) {
            setImage(Toolkit.getDefaultToolkit().getImage(url));
        }
    } catch (Exception e) {
    }
}
Also used : JPanel(javax.swing.JPanel) Matcher(java.util.regex.Matcher) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) Reader(java.io.Reader) Image(java.awt.Image) URL(java.net.URL) GraphicsConfiguration(java.awt.GraphicsConfiguration) DataFlavor(java.awt.datatransfer.DataFlavor) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) JSlider(javax.swing.JSlider) List(java.util.List) ChangeListener(javax.swing.event.ChangeListener) EmptyBorder(javax.swing.border.EmptyBorder) Window(java.awt.Window) JWindow(javax.swing.JWindow) Pattern(java.util.regex.Pattern) MouseEvent(java.awt.event.MouseEvent) JWindow(javax.swing.JWindow) JComponent(javax.swing.JComponent) Transferable(java.awt.datatransfer.Transferable) JLabel(javax.swing.JLabel) Point(java.awt.Point) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) IOException(java.io.IOException) ActionListener(java.awt.event.ActionListener) ChangeEvent(javax.swing.event.ChangeEvent) TransferHandler(javax.swing.TransferHandler) File(java.io.File) MouseInputAdapter(javax.swing.event.MouseInputAdapter)

Example 95 with ActionListener

use of java.awt.event.ActionListener in project screenbird by adamhub.

the class RecorderPanel method startCountdown.

/**
     * Initiates countdown and prepares for screen capture. 
     */
private void startCountdown() {
    final Countdown[] countdown = new Countdown[1];
    countdownSec = 6;
    countdownTimer = new Timer(500, new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            countdownSec--;
            log("Counting: " + countdownSec);
            switch(countdownSec) {
                case 0:
                    countdownTimer.stop();
                    jLabel5.setText("Recording");
                    btnRecordNonRec.setText("Stop");
                    btnRecordRec.setText("Stop");
                    btnPlayPauseBackup.setText("");
                    btnPlayPauseBackup.setIcon(pauseIcon);
                    btnFinalizeBackup.setEnabled(true);
                    // Destroy the countdown window.
                    countdown[0].destroy();
                    try {
                        Thread.sleep(500);
                    } catch (Exception ee) {
                    }
                    startRecordState();
                    break;
                case 1:
                case 2:
                case 3:
                case 4:
                    btnPlayPauseBackup.setText(String.valueOf(countdownSec));
                    countdown[0].destroy();
                    countdown[0] = new Countdown(false, recorder);
                    countdown[0].setCount(countdownSec);
                    countdown[0].setVisible(true);
                    try {
                        SoundUtil.tone(880, 500, 0.15);
                    } catch (LineUnavailableException ee) {
                    }
                    break;
                case 5:
                    btnPlayPauseBackup.setText(String.valueOf(countdownSec));
                    // Hide drop box
                    if (captureBox != null) {
                        captureBox.setDragBoxVisible(false);
                    }
                    countdown[0] = new Countdown(false, recorder);
                    countdown[0].setCount(5);
                    countdown[0].setVisible(true);
                    try {
                        SoundUtil.tone(880, 500, 0.15);
                    } catch (LineUnavailableException ee) {
                    }
                    break;
            }
        }
    });
    countdownTimer.start();
}
Also used : Timer(javax.swing.Timer) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) LineUnavailableException(javax.sound.sampled.LineUnavailableException) Countdown(com.bixly.pastevid.screencap.components.capturebox.Countdown) MissingResourceException(java.util.MissingResourceException) FileNotFoundException(java.io.FileNotFoundException) LineUnavailableException(javax.sound.sampled.LineUnavailableException) IOException(java.io.IOException)

Aggregations

ActionListener (java.awt.event.ActionListener)1347 ActionEvent (java.awt.event.ActionEvent)1303 JButton (javax.swing.JButton)363 JPanel (javax.swing.JPanel)345 JLabel (javax.swing.JLabel)234 JMenuItem (javax.swing.JMenuItem)191 BoxLayout (javax.swing.BoxLayout)150 GridBagConstraints (java.awt.GridBagConstraints)121 Insets (java.awt.Insets)121 GridBagLayout (java.awt.GridBagLayout)114 Dimension (java.awt.Dimension)113 FlowLayout (java.awt.FlowLayout)110 JCheckBox (javax.swing.JCheckBox)103 JScrollPane (javax.swing.JScrollPane)103 JMenu (javax.swing.JMenu)96 BorderLayout (java.awt.BorderLayout)88 JTextField (javax.swing.JTextField)79 JComboBox (javax.swing.JComboBox)73 ButtonGroup (javax.swing.ButtonGroup)64 ArrayList (java.util.ArrayList)60