Example usage for java.awt.event ActionEvent getID

List of usage examples for java.awt.event ActionEvent getID

Introduction

In this page you can find the example usage for java.awt.event ActionEvent getID.

Prototype

public int getID() 

Source Link

Document

Returns the event type.

Usage

From source file:EventObject.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    JButton ok = new JButton("Ok");

    ok.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            Calendar cal = Calendar.getInstance();
            cal.setTimeInMillis(event.getWhen());
            Locale locale = Locale.getDefault();
            String s = DateFormat.getTimeInstance(DateFormat.SHORT, locale).format(new Date());

            if (event.getID() == ActionEvent.ACTION_PERFORMED)
                System.out.println(" Event Id: ACTION_PERFORMED");

            System.out.println(" Time: " + s);

            String source = event.getSource().getClass().getName();
            System.out.println(" Source: " + source);

            int mod = event.getModifiers();
            if ((mod & ActionEvent.ALT_MASK) > 0)
                System.out.println("Alt ");

            if ((mod & ActionEvent.SHIFT_MASK) > 0)
                System.out.println("Shift ");

            if ((mod & ActionEvent.META_MASK) > 0)
                System.out.println("Meta ");

            if ((mod & ActionEvent.CTRL_MASK) > 0)
                System.out.println("Ctrl ");

        }/*w  ww .j  a  va2s  . c  o m*/
    });

    f.add(ok);

    f.setSize(420, 250);
    f.setLocationRelativeTo(null);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

From source file:com.quiltplayer.controller.ImageController.java

@Override
public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals(EVENT_CHANGE_COVER)) {
        final Album album = (Album) e.getSource();

        int imageCount = e.getID();

        // This should be set as primary
        LocalImage toFrontImage = album.getImages().get(imageCount);
        album.changeFrontImage(album, toFrontImage);

        frame.updateUI();//w  ww .j  a va 2s. co m
    }
}

From source file:Main.java

public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand() != null) {
        String command = e.getActionCommand();
        if (command != null) {
            command = command.toUpperCase();
        }/*  www  .  j  av  a 2 s.  co  m*/
        e = new ActionEvent(e.getSource(), e.getID(), command, e.getModifiers());
    }

    if (defAction != null) {
        defAction.actionPerformed(e);
    }
}

From source file:Data.c_PriceDB.java

public void actionPerformed(ActionEvent e) {
    String line = e.getActionCommand();
    if (e.getID() == Action.ACTION_PRICES_LOAD_LINE) {
        if (parsedFirstListPrices == false) {
            parsedFirstListPrices = true;
            m_loadingListener.actionPerformed(e);
            return;
        }//from  www.  j  a  v  a  2s  .c o  m

        String ary[] = line.split("\\|");
        c_PriceEntry entry;
        c_Price price;
        Double low, avg, high;
        String name, expansion, temp;

        /* Card|Price|StdDev|Average|High|Low|Change|Raw N
           AEther Figment|0.25|0.00|0.25|0.25|0.25|0.00|4
           AEther Flash (6th)|0.36|0.00|0.36|0.36|0.36|0.00|1 */
        temp = ary[PricesParsing.NAME.val];
        if (temp.endsWith(")")) {
            expansion = str.middleOf("(", temp, ")");
            name = str.leftOf(temp, " (");

            if (m_expansionDB.contains(Acronym.Trader, expansion)) {
                expansion = m_expansionDB.getExpansion(Acronym.Trader, expansion).getName();
            } else {
                expansion = "";
            }
        } else {
            expansion = "";
            name = temp;
        }

        avg = Double.parseDouble(ary[PricesParsing.AVERAGE.val]);
        high = Double.parseDouble(ary[PricesParsing.HIGH.val]);
        low = Double.parseDouble(ary[PricesParsing.LOW.val]);
        price = new c_Price(low, avg, high, PriceType.AVERAGE);

        if (!contains(name)) {
            entry = new c_PriceEntry();
            entry.addPriceEntry(price, expansion);
            m_prices.put(name, entry);
        } else {
            entry = m_prices.get(name);
            entry.addPriceEntry(price, expansion);
        }

        m_loadingListener.actionPerformed(e);
        ary = null;
        entry = null;
        price = null;
        name = null;
        expansion = null;
        temp = null;
    } else {
        m_loadingListener.actionPerformed(e);
    }

    line = null;
}

From source file:Main.java

public void actionPerformed(ActionEvent e) {

    Locale locale = Locale.getDefault();
    Date date = new Date(e.getWhen());
    String s = DateFormat.getTimeInstance(DateFormat.SHORT, locale).format(date);

    if (!model.isEmpty()) {
        model.clear();//from w w w  .jav a2s  .  co m
    }

    if (e.getID() == ActionEvent.ACTION_PERFORMED) {
        model.addElement(" Event Id: ACTION_PERFORMED");

    }

    model.addElement("Time: " + s);

    String source = e.getSource().getClass().getName();

    int mod = e.getModifiers();

    StringBuffer buffer = new StringBuffer("Modifiers: ");

    if ((mod & ActionEvent.ALT_MASK) > 0) {
        buffer.append("Alt ");

    }

    if ((mod & ActionEvent.SHIFT_MASK) > 0) {
        buffer.append("Shift ");

    }

    if ((mod & ActionEvent.META_MASK) > 0) {
        buffer.append("Meta ");

    }

    if ((mod & ActionEvent.CTRL_MASK) > 0) {
        buffer.append("Ctrl ");

    }
    model.addElement(buffer);

}

From source file:Data.c_CardDB.java

public void actionPerformed(ActionEvent e) {
    /* ID   Language   Name   Alt   Cost   Type   Set   Rarity   P   T   Oracle Rules   Printed Name   Printed Type   Printed Rules   Flavor Text   Card #   Artist   Printings */
    if (!e.getActionCommand().startsWith("ID") && e.getID() == Action.ACTION_CARDS_DB_LOAD_LINE) {
        String ary[] = e.getActionCommand().split("\t");
        c_Card card = new c_Card(ary);
        if (card.Name != null) {
            addCard(card);/*w  w w.  ja va  2  s.  c  o m*/
            if (m_loadingListener != null) {
                m_loadingListener.actionPerformed(e);
            }
            card = null;
        }
    } else {
        if (m_loadingListener != null) {
            m_loadingListener.actionPerformed(e);
        }
    }
}

From source file:fur.shadowdrake.minecraft.InstallPanel.java

private void showReadMe() throws NetworkException {
    StringBuilder sb = new StringBuilder();
    while (true) {
        result = ftpClient.openDataChannel((ActionEvent e) -> {
            if (e.getID() == FtpClient.FTP_OK) {
                try {
                    InputStreamReader isr;
                    char[] buffer = new char[4096];
                    int n;
                    isr = new InputStreamReader(((Socket) e.getSource()).getInputStream());
                    while (true) {
                        n = isr.read(buffer);
                        if (n < 0) {
                            break;
                        }//from w  w  w .  j a  va  2s  . c  o  m
                        sb.append(buffer, 0, n);
                    }
                } catch (IOException ex) {
                    Logger.getLogger(InstallPanel.class.getName()).log(Level.SEVERE, "Readme", ex);
                    log.println("Faild retrieve readme.");
                    ftpClient.closeDataChannel();
                }
            }
        });
        switch (result) {
        case FtpClient.FTP_OK:
            downloadSize = ftpClient.retr(workingPack + "/readme", (ActionEvent e) -> {
                ftpClient.closeDataChannel();
                EventQueue.invokeLater(() -> {
                    ReadmeBox rb = new ReadmeBox(parentFrame, true, sb.toString());
                    rb.setVisible(true);
                });
            });
            if (downloadSize >= 0) {
            } else {
                switch (downloadSize) {
                case FtpClient.FTP_NODATA:
                    log.println(
                            "Oops! Server's complaining about missing data channel, although I've opened it.");
                    ftpClient.abandonDataChannel();
                    return;
                default:
                    ftpClient.abandonDataChannel();
                }
            }
            break;
        case FtpClient.FTP_TIMEOUT:
            if (reconnect()) {
                continue;
            }
        }
        break;
    }
}

From source file:fur.shadowdrake.minecraft.InstallPanel.java

private List<String> fetchUpdateInstructions(Pack pack) throws NetworkException {
    final Semaphore semaphore = new Semaphore(0);
    final StringBuffer sb = new StringBuffer();
    while (true) {
        result = ftpClient.openDataChannel((ActionEvent e) -> {
            if (e.getID() == FtpClient.FTP_OK) {
                try {
                    InputStreamReader isr;
                    int n;
                    char[] buffer = new char[4096];
                    isr = new InputStreamReader(((Socket) e.getSource()).getInputStream());
                    while (true) {
                        n = isr.read(buffer);
                        if (n < 0) {
                            break;
                        }/*from  w w w. ja v  a2s .c  o m*/
                        sb.append(buffer, 0, n);
                    }
                } catch (IOException ex) {
                    Logger.getLogger(InstallPanel.class.getName()).log(Level.SEVERE, "Download", ex);
                    log.println("Faild to save file.");
                    ftpClient.closeDataChannel();
                }
            }
        });
        switch (result) {
        case FtpClient.FTP_OK:
            int status = ftpClient.uins(pack, (ActionEvent e) -> {
                ftpClient.closeDataChannel();
                semaphore.release();
            });
            switch (status) {
            case FtpClient.FTP_OK:
                try {
                    semaphore.acquire();
                } catch (InterruptedException ex) {
                    return null;
                }
                break;
            case FtpClient.FTP_NODATA:
                log.println("Oops! Server's complaining about missing data channel, although I've opened it.");
                ftpClient.abandonDataChannel();
                return null;
            default:
                ftpClient.abandonDataChannel();
                return null;
            }
            break;
        case FtpClient.FTP_TIMEOUT:
            if (reconnect()) {
                continue;
            } else {
                return null;
            }
        default:
            return null;
        }
        break;
    }
    return Arrays.asList(sb.toString().split("\n"));
}

From source file:fur.shadowdrake.minecraft.InstallPanel.java

@SuppressWarnings({ "Convert2Lambda" })
private boolean downloadFile(String filename, String local) throws NetworkException {
    final Semaphore semaphore = new Semaphore(0);
    success = false;/* w ww.  j ava 2  s .c  om*/
    while (true) {
        result = ftpClient.openDataChannel(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (e.getID() == FtpClient.FTP_OK) {
                    try {
                        InputStream is;
                        FileOutputStream fos;

                        is = ((Socket) e.getSource()).getInputStream();
                        fos = new FileOutputStream(new File(workingDir, local));
                        byte[] buffer = new byte[4096];
                        for (int n = is.read(buffer); n > 0; n = is.read(buffer)) {
                            fos.write(buffer, 0, n);
                            log.advance(n);
                        }
                        fos.close();
                        success = true;
                    } catch (IOException ex) {
                        Logger.getLogger(InstallPanel.class.getName()).log(Level.SEVERE, "Download", ex);
                        log.println("Faild to save file.");
                        success = false;
                    }
                }
            }
        });
        switch (result) {
        case FtpClient.FTP_OK:
            int size = ftpClient.retr(filename, (ActionEvent e) -> {
                ftpClient.closeDataChannel();
                semaphore.release();
            });
            if (size < 0) {
                ftpClient.abandonDataChannel();
            } else {
                log.reset();
                log.setMaximum(size);
            }
            try {
                semaphore.acquire();
            } catch (InterruptedException ex) {
                return false;
            }
            break;
        case FtpClient.FTP_TIMEOUT:
            if (reconnect()) {
                continue;
            } else {
                ftpClient.abandonDataChannel();
                return false;
            }
        default:
            ftpClient.abandonDataChannel();
            return false;
        }
        break;
    }
    return success;
}

From source file:fur.shadowdrake.minecraft.InstallPanel.java

private boolean downloadArchive(String filename) throws NetworkException {
    final Semaphore semaphore1 = new Semaphore(0);
    final Semaphore semaphore2 = new Semaphore(0);
    success = false;/*from  w w  w. j a  va  2s.co  m*/
    log.setIndeterminate();
    while (true) {
        result = ftpClient.openDataChannel((ActionEvent e) -> {
            if (e.getID() == FtpClient.FTP_OK) {
                try {
                    semaphore1.acquire();
                    InputStream is;
                    is = ((Socket) e.getSource()).getInputStream();
                    downloadedFiles = unTar(is, new File(workingDir));
                    success = true;
                } catch (IOException ex) {
                    Logger.getLogger(InstallPanel.class.getName()).log(Level.SEVERE, "Download", ex);
                    log.println("Faild to save file.");
                    ftpClient.closeDataChannel();
                    success = false;
                } catch (ArchiveException | InterruptedException ex) {
                    Logger.getLogger(InstallPanel.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });

        switch (result) {
        case FtpClient.FTP_OK:
            downloadSize = ftpClient.retr(filename, (ActionEvent e) -> {
                ftpClient.closeDataChannel();
                semaphore2.release();
            });
            if (downloadSize >= 0) {
                if (downloadSize > 1048576) {
                    log.println("~" + Integer.toString(downloadSize / 1048576) + " MB");
                } else if (downloadSize > 1024) {
                    log.println("~" + Integer.toString(downloadSize / 1024) + " kB");
                }
                log.reset();
                log.showPercentage(true);
                log.setMaximum(downloadSize);
                semaphore1.release();
                try {
                    semaphore2.acquire();
                } catch (InterruptedException ex) {
                    return false;
                }
            } else {
                switch (downloadSize) {
                case FtpClient.FTP_NODATA:
                    log.println(
                            "Oops! Server's complaining about missing data channel, although I've opened it.");
                    ftpClient.abandonDataChannel();
                    return false;
                default:
                    ftpClient.abandonDataChannel();
                    return false;
                }
            }
            break;
        case FtpClient.FTP_TIMEOUT:
            if (reconnect()) {
                continue;
            } else {
                return false;
            }
        default:
            return false;
        }

        break;
    }
    return success;
}