Example usage for java.awt.event KeyEvent getSource

List of usage examples for java.awt.event KeyEvent getSource

Introduction

In this page you can find the example usage for java.awt.event KeyEvent getSource.

Prototype

public Object getSource() 

Source Link

Document

The object on which the Event initially occurred.

Usage

From source file:nz.dataview.websyncclientgui.WebSYNCClientGUIView.java

/**
 * Determines whether the source of a KeyEvent is flagged to require a restart of the 
 * background service on change of its value.
 * /*  w ww  .ja  va2 s. co  m*/
 * @param   evt   the KeyEvent fired
 * @return        true if event requires a restart if changed, false otherwise
 */
private boolean fieldChangeRequiresRestart(java.awt.event.KeyEvent evt) {
    Object src = evt.getSource();
    boolean ret = false;

    // add any new fields here
    ret = src == useProxyField || src == proxyHostField || src == proxyPortField || src == proxyUserField
            || src == proxyPwField;

    return ret;
}

From source file:edu.ucla.stat.SOCR.analyses.gui.NormalPower.java

public void keyTyped(KeyEvent event) {
    if (event.getKeyCode() == KeyEvent.VK_TAB) {
        System.out.println("rowNames  keyTyped event.getKeyCode() == KeyEvent.VK_TAB");
    }/*ww  w .  jav  a 2  s  .  co  m*/

    System.out.println("rowNames  keyTyped event == " + event);

    if (event.getSource() == checkNE) {
        useNE = true;
        useLT = false;
        useGT = false;
        try {
            hypothesisType = NormalPowerResult.HYPOTHESIS_TYPE_NE;
            graphSampleMean.resetHypotheseType();
        } catch (Exception e) {

            ////////////////System.out.println("keyTyped event.getSource() NE " + e);
        }
    } else if (event.getSource() == checkLT) {
        useNE = false;
        useLT = true;
        useGT = false;
        try {
            hypothesisType = NormalPowerResult.HYPOTHESIS_TYPE_LT;
            graphSampleMean.resetHypotheseType();
        } catch (Exception e) {
            ////////////////System.out.println("keyTyped event.getSource() LT " + e);

        }
    } else if (event.getSource() == checkGT) {
        useNE = false;
        useLT = false;
        useGT = true;
        try {
            hypothesisType = NormalPowerResult.HYPOTHESIS_TYPE_GT;
            graphSampleMean.resetHypotheseType();
        } catch (Exception e) {
            ////////////////System.out.println("keyTyped event.getSource() GT "  +e );

        }
    }

    if (event.getSource() == alphaCombo) {
        try {
            alpha = Double.parseDouble((String) (alphaCombo.getSelectedItem()));
            graphSampleMean.resetHypotheseType();
        } catch (Exception e) {
        }
    } else if (event.getSource() == sampleSizeText) {
        try {
            sampleSize = Integer.parseInt((String) (sampleSizeText.getText()));
            ////////////////////System.out.println("itemStateChanged sampleSize = " + sampleSize);
        } catch (Exception e) {
        }
    } else if (event.getSource() == sigmaText) {
        try {
            sigma = Double.parseDouble((String) (sigmaText.getText()));
            //System.out.println("keyTyped sigma = " + sigma);
        } catch (Exception e) {
        }
    } else if (event.getSource() == mu0Text) {
        try {
            mu0 = Double.parseDouble((String) (mu0Text.getText()));
            ////////////////////System.out.println("keyTyped mu0 = " + mu0);
        } catch (Exception e) {
        }
    } else if (event.getSource() == muAText) {
        try {
            muA = Double.parseDouble((String) (muAText.getText()));
            ////////////////////System.out.println("keyTyped muA = " + muA);
        } catch (Exception e) {
        }
    } else if (event.getSource() == powerText) {
        try {
            power = Double.parseDouble((String) (powerText.getText()));
            ////////////////////System.out.println("keyTyped power = " + power);
        } catch (Exception e) {
        }
    } else if (event.getSource() == xValueText) {
        try {
            xValue = Double.parseDouble((String) (xValueText.getText()));
        } catch (Exception e) {
        }
    }
}

From source file:net.java.sip.communicator.impl.gui.main.chat.ChatWritePanel.java

/**
 * When CTRL+Z is pressed invokes the <code>ChatWritePanel.undo()</code>
 * method, when CTRL+R is pressed invokes the
 * <code>ChatWritePanel.redo()</code> method.
 *
 * @param e the <tt>KeyEvent</tt> that notified us
 *///from  w  w w  .j ava2s .  c om
public void keyPressed(KeyEvent e) {
    if ((e.getModifiers() & KeyEvent.CTRL_MASK) == KeyEvent.CTRL_MASK && (e.getKeyCode() == KeyEvent.VK_Z)
    // And not ALT(right ALT gives CTRL + ALT).
            && (e.getModifiers() & KeyEvent.ALT_MASK) != KeyEvent.ALT_MASK) {
        if (undo.canUndo())
            undo();
    } else if ((e.getModifiers() & KeyEvent.CTRL_MASK) == KeyEvent.CTRL_MASK
            && (e.getKeyCode() == KeyEvent.VK_R)
            // And not ALT(right ALT gives CTRL + ALT).
            && (e.getModifiers() & KeyEvent.ALT_MASK) != KeyEvent.ALT_MASK) {
        if (undo.canRedo())
            redo();
    } else if (e.getKeyCode() == KeyEvent.VK_TAB) {
        if (!(chatPanel.getChatSession() instanceof ConferenceChatSession))
            return;

        e.consume();
        int index = ((JEditorPane) e.getSource()).getCaretPosition();

        StringBuffer message = new StringBuffer(chatPanel.getMessage());

        int position = index - 1;

        while (position > 0 && (message.charAt(position) != ' ')) {
            position--;
        }

        if (position != 0)
            position++;

        String sequence = message.substring(position, index);

        if (sequence.length() <= 0) {
            // Do not look for matching contacts if the matching pattern is
            // 0 chars long, since all contacts will match.
            return;
        }

        Iterator<ChatContact<?>> iter = chatPanel.getChatSession().getParticipants();
        ArrayList<String> contacts = new ArrayList<String>();
        while (iter.hasNext()) {
            ChatContact<?> c = iter.next();
            if (c.getName().length() >= (index - position)
                    && c.getName().substring(0, index - position).equals(sequence)) {
                message.replace(position, index, c.getName().substring(0, index - position));
                contacts.add(c.getName());
            }
        }

        if (contacts.size() > 1) {
            char key = contacts.get(0).charAt(index - position - 1);
            int pos = index - position - 1;
            boolean flag = true;

            while (flag) {
                try {
                    for (String name : contacts) {
                        if (key != name.charAt(pos)) {
                            flag = false;
                        }
                    }

                    if (flag) {
                        pos++;
                        key = contacts.get(0).charAt(pos);
                    }
                } catch (IndexOutOfBoundsException exp) {
                    flag = false;
                }
            }

            message.replace(position, index, contacts.get(0).substring(0, pos));

            Iterator<String> contactIter = contacts.iterator();
            String contactList = "<DIV align='left'><h5>";
            while (contactIter.hasNext()) {
                contactList += contactIter.next() + " ";
            }
            contactList += "</h5></DIV>";

            chatPanel.getChatConversationPanel().appendMessageToEnd(contactList,
                    ChatHtmlUtils.HTML_CONTENT_TYPE);
        } else if (contacts.size() == 1) {
            String limiter = (position == 0) ? ": " : "";
            message.replace(position, index, contacts.get(0) + limiter);
        }

        try {
            ((JEditorPane) e.getSource()).getDocument().remove(0,
                    ((JEditorPane) e.getSource()).getDocument().getLength());
            ((JEditorPane) e.getSource()).getDocument().insertString(0, message.toString(), null);
        } catch (BadLocationException ex) {
            ex.printStackTrace();
        }
    } else if (e.getKeyCode() == KeyEvent.VK_UP) {
        // Only enters editing mode if the write panel is empty in
        // order not to lose the current message contents, if any.
        if (this.chatPanel.getLastSentMessageUID() != null && this.chatPanel.isWriteAreaEmpty()) {
            this.chatPanel.startLastMessageCorrection();
            e.consume();
        }
    } else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
        if (chatPanel.isMessageCorrectionActive()) {
            Document doc = editorPane.getDocument();
            if (editorPane.getCaretPosition() == doc.getLength()) {
                chatPanel.stopMessageCorrection();
            }
        }
    }
}

From source file:CSSDFarm.UserInterface.java

private void sliderServerOnOffKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_sliderServerOnOffKeyReleased
    // TODO add your handling code here:
    JSlider source = (JSlider) evt.getSource();
    server.togglePower(source.getValue());
}

From source file:corelyzer.ui.CorelyzerApp.java

private void setupUI() {
    String versionNumber = CorelyzerApp.getApp().getCorelyzerVersion();
    if ((versionNumber == null) || versionNumber.equals("")) {
        versionNumber = "undetermined";
    }//from w  w w .ja  v  a  2s. c o  m

    this.baseTitle = "Corelyzer " + versionNumber;

    mainFrame = new JFrame(baseTitle);
    mainFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    mainFrame.setSize(320, 100);
    mainFrame.setLocation(600, 100);
    mainFrame.addWindowListener(this);

    GridLayout layout = new GridLayout(1, 1);
    mainFrame.getContentPane().setLayout(layout);

    rootPanel = new JPanel(new GridLayout(1, 5));
    rootPanel.setBorder(BorderFactory.createTitledBorder("Main Panel"));

    // add lists/panels
    JPanel sessionPanel = new JPanel(new GridLayout(1, 1));
    sessionPanel.setBorder(BorderFactory.createTitledBorder("Session"));
    sessionList = new JList(getSessionListModel());
    sessionList.setName("SessionList");
    sessionList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    sessionList.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(final ListSelectionEvent event) {
            int idx = sessionList.getSelectedIndex();
            if (idx >= 0) {
                CoreGraph cg = CoreGraph.getInstance();
                cg.setCurrentSessionIdx(idx);
            }
        }
    });
    sessionList.addMouseListener(this);
    JScrollPane sessionScrollPane = new JScrollPane(sessionList);
    sessionPanel.add(sessionScrollPane);
    rootPanel.add(sessionPanel);

    JPanel trackPanel = new JPanel(new GridLayout(1, 1));
    trackPanel.setBorder(BorderFactory.createTitledBorder("Track"));
    trackList = new JList(getTrackListModel());
    trackList.setName("TrackList");
    trackList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    trackList.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(final ListSelectionEvent event) {
            int idx = trackList.getSelectedIndex();
            if (idx >= 0) {
                CoreGraph cg = CoreGraph.getInstance();
                cg.setCurrentTrackIdx(idx);
                updateHighlightedSections();
            }
        }
    });
    trackList.addMouseListener(this);
    JScrollPane trackScrollPane = new JScrollPane(trackList);
    trackPanel.add(trackScrollPane);
    rootPanel.add(trackPanel);

    JPanel sectionsPanel = new JPanel(new GridLayout(1, 1));
    sectionsPanel.setBorder(BorderFactory.createTitledBorder("Sections"));
    sectionList = new JList(getSectionListModel());
    sectionList.setName("SectionList");
    sectionList.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(final ListSelectionEvent event) {
            if (event.getValueIsAdjusting())
                return;
            updateHighlightedSections();
        }
    });
    sectionList.addMouseListener(this);
    JScrollPane sectionsScrollPane = new JScrollPane(sectionList);
    sectionsPanel.add(sectionsScrollPane);
    rootPanel.add(sectionsPanel);

    JPanel dataFilesPanel = new JPanel(new GridLayout(1, 1));
    dataFilesPanel.setBorder(BorderFactory.createTitledBorder("Data Files"));
    dataFileList = new JList(getDataFileListModel());
    dataFileList.setName("DatafileList");
    dataFileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    dataFileList.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(final ListSelectionEvent event) {
            int idx = dataFileList.getSelectedIndex();
            if (idx >= 0) {
                CoreGraph cg = CoreGraph.getInstance();
                cg.setCurrentDatasetIdx(idx);
            }
        }
    });
    dataFileList.addMouseListener(this);
    JScrollPane dataFilesScrollPane = new JScrollPane(dataFileList);
    dataFilesPanel.add(dataFilesScrollPane);
    rootPanel.add(dataFilesPanel);

    JPanel fieldsPanel = new JPanel(new GridLayout(1, 1));
    fieldsPanel.setBorder(BorderFactory.createTitledBorder("Fields"));
    fieldList = new JList(getFieldListModel());
    fieldList.setName("FieldList");
    fieldList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    fieldList.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(final ListSelectionEvent event) {
            int idx = fieldList.getSelectedIndex();
            if (idx >= 0) {
                CoreGraph cg = CoreGraph.getInstance();
                cg.setCurrentFieldIdx(idx);
            }
        }
    });
    JScrollPane fieldsScrollPane = new JScrollPane(fieldList);
    fieldsPanel.add(fieldsScrollPane);
    rootPanel.add(fieldsPanel);

    mainFrame.getContentPane().add(rootPanel);

    setupMenuStuff();
    setupPopupMenu();

    // init new mode tool frame
    toolFrame = new CRToolPalette();
    toolFrame.pack();
    int canvasWidth = preferences().screenWidth;
    Dimension mydim = toolFrame.getSize();
    int myLocX = canvasWidth / 2 - mydim.width / 2;
    toolFrame.setLocation(myLocX, 0);
    toolFrame.setVisible(true);

    // delete key listener on track and section list
    KeyListener listKeyListener = new KeyListener() {
        public void keyPressed(final KeyEvent keyEvent) {
        }

        public void keyReleased(final KeyEvent keyEvent) {

            int keyCode = keyEvent.getKeyCode();

            if (keyCode == KeyEvent.VK_DELETE) {
                Object actionSource = keyEvent.getSource();

                if (actionSource.equals(trackList)) {
                    controller.deleteSelectedTrack();
                } else if (actionSource.equals(sectionList)) {
                    int[] rows = getSectionList().getSelectedIndices();
                    onDeleteSelectedSections(rows);
                }
            }
        }

        public void keyTyped(final KeyEvent keyEvent) {
        }
    };

    trackList.addKeyListener(listKeyListener);
    sectionList.addKeyListener(listKeyListener);
}

From source file:net.pms.newgui.NavigationShareTab.java

private void initSimpleComponents(CellConstraints cc) {
    // Thumbnail seeking position
    seekpos = new JTextField("" + configuration.getThumbnailSeekPos());
    seekpos.addKeyListener(new KeyAdapter() {
        @Override//from   ww  w  .j ava2s  . co  m
        public void keyReleased(KeyEvent e) {
            try {
                int ab = Integer.parseInt(seekpos.getText());
                configuration.setThumbnailSeekPos(ab);
                if (configuration.getUseCache()) {
                    PMS.get().getDatabase().init(true);
                }
            } catch (NumberFormatException nfe) {
                LOGGER.debug("Could not parse thumbnail seek position from \"" + seekpos.getText() + "\"");
            }

        }
    });
    if (configuration.isThumbnailGenerationEnabled()) {
        seekpos.setEnabled(true);
    } else {
        seekpos.setEnabled(false);
    }

    // Generate thumbnails
    thumbgenCheckBox = new JCheckBox(Messages.getString("NetworkTab.2"),
            configuration.isThumbnailGenerationEnabled());
    thumbgenCheckBox.setContentAreaFilled(false);
    thumbgenCheckBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setThumbnailGenerationEnabled((e.getStateChange() == ItemEvent.SELECTED));
            seekpos.setEnabled(configuration.isThumbnailGenerationEnabled());
            mplayer_thumb.setEnabled(configuration.isThumbnailGenerationEnabled());
        }
    });

    // Use MPlayer for video thumbnails
    mplayer_thumb = new JCheckBox(Messages.getString("FoldTab.14"), configuration.isUseMplayerForVideoThumbs());
    mplayer_thumb.setToolTipText(Messages.getString("FoldTab.61"));
    mplayer_thumb.setContentAreaFilled(false);
    mplayer_thumb.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setUseMplayerForVideoThumbs((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    if (configuration.isThumbnailGenerationEnabled()) {
        mplayer_thumb.setEnabled(true);
    } else {
        mplayer_thumb.setEnabled(false);
    }

    // DVD ISO thumbnails
    dvdiso_thumb = new JCheckBox(Messages.getString("FoldTab.19"), configuration.isDvdIsoThumbnails());
    dvdiso_thumb.setContentAreaFilled(false);
    dvdiso_thumb.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setDvdIsoThumbnails((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    // Image thumbnails
    image_thumb = new JCheckBox(Messages.getString("FoldTab.21"), configuration.getImageThumbnailsEnabled());
    image_thumb.setContentAreaFilled(false);
    image_thumb.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setImageThumbnailsEnabled((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    // Audio thumbnails import
    final KeyedComboBoxModel<CoverSupplier, String> thumbKCBM = new KeyedComboBoxModel<>(
            new CoverSupplier[] { CoverSupplier.NONE, CoverSupplier.COVER_ART_ARCHIVE },
            new String[] { Messages.getString("FoldTab.35"), Messages.getString("FoldTab.73") });
    audiothumbnail = new JComboBox<>(thumbKCBM);
    audiothumbnail.setEditable(false);

    thumbKCBM.setSelectedKey(configuration.getAudioThumbnailMethod());

    audiothumbnail.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                configuration.setAudioThumbnailMethod(thumbKCBM.getSelectedKey());
                LOGGER.info("Setting {} {}", Messages.getRootString("FoldTab.26"),
                        thumbKCBM.getSelectedValue());
            }
        }
    });

    // Alternate video cover art folder
    defaultThumbFolder = new JTextField(configuration.getAlternateThumbFolder());
    defaultThumbFolder.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setAlternateThumbFolder(defaultThumbFolder.getText());
        }
    });

    // Alternate video cover art folder button
    select = new CustomJButton("...");
    select.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser;
            try {
                chooser = new JFileChooser();
            } catch (Exception ee) {
                chooser = new JFileChooser(new RestrictedFileSystemView());
            }
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int returnVal = chooser.showDialog((Component) e.getSource(), Messages.getString("FoldTab.28"));
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                defaultThumbFolder.setText(chooser.getSelectedFile().getAbsolutePath());
                configuration.setAlternateThumbFolder(chooser.getSelectedFile().getAbsolutePath());
            }
        }
    });

    // Show Server Settings folder
    isShowFolderServerSettings = new JCheckBox(Messages.getString("FoldTab.ShowServerSettingsFolder"),
            configuration.isShowServerSettingsFolder());
    isShowFolderServerSettings.setContentAreaFilled(false);
    isShowFolderServerSettings.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setShowServerSettingsFolder((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    // Show #--TRANSCODE--# folder
    isShowFolderTranscode = new JCheckBox(Messages.getString("FoldTab.ShowTranscodeFolder"),
            configuration.isShowTranscodeFolder());
    isShowFolderTranscode.setContentAreaFilled(false);
    isShowFolderTranscode.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setShowTranscodeFolder((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    // Show Media Library folder
    isShowFolderMediaLibrary = new JCheckBox(Messages.getString("FoldTab.ShowMediaLibraryFolder"),
            configuration.isShowMediaLibraryFolder());
    isShowFolderMediaLibrary.setContentAreaFilled(false);
    isShowFolderMediaLibrary.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setShowMediaLibraryFolder((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    // Browse compressed archives
    archive = new JCheckBox(Messages.getString("NetworkTab.1"), configuration.isArchiveBrowsing());
    archive.setContentAreaFilled(false);
    archive.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setArchiveBrowsing(e.getStateChange() == ItemEvent.SELECTED);
        }
    });

    // Enable the Media Library
    cacheenable = new JCheckBox(Messages.getString("NetworkTab.EnableMediaLibrary"),
            configuration.getUseCache());
    cacheenable.setToolTipText(Messages.getString("FoldTab.ShowMediaLibraryFolderTooltip"));
    cacheenable.setContentAreaFilled(false);
    cacheenable.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setUseCache((e.getStateChange() == ItemEvent.SELECTED));
            cachereset.setEnabled(configuration.getUseCache());
            setScanLibraryEnabled(configuration.getUseCache());
        }
    });

    // Reset cache
    cachereset = new CustomJButton(Messages.getString("NetworkTab.EmptyMediaLibrary"));
    cachereset.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int option = JOptionPane.showConfirmDialog(looksFrame,
                    Messages.getString("NetworkTab.MediaLibraryEmptiedExceptFullyPlayed") + "\n"
                            + Messages.getString("NetworkTab.19"),
                    Messages.getString("Dialog.Question"), JOptionPane.YES_NO_OPTION);
            if (option == JOptionPane.YES_OPTION) {
                PMS.get().getDatabase().init(true);
            }

        }
    });
    cachereset.setEnabled(configuration.getUseCache());

    // Hide file extensions
    hideextensions = new JCheckBox(Messages.getString("FoldTab.5"), configuration.isHideExtensions());
    hideextensions.setContentAreaFilled(false);
    if (configuration.isPrettifyFilenames()) {
        hideextensions.setEnabled(false);
    }
    hideextensions.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setHideExtensions((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    // Hide transcoding engine names
    hideengines = new JCheckBox(Messages.getString("FoldTab.8"), configuration.isHideEngineNames());
    hideengines.setToolTipText(Messages.getString("FoldTab.46"));
    hideengines.setContentAreaFilled(false);
    hideengines.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setHideEngineNames((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    // Hide empty folders
    hideemptyfolders = new JCheckBox(Messages.getString("FoldTab.31"), configuration.isHideEmptyFolders());
    hideemptyfolders.setToolTipText(Messages.getString("FoldTab.59"));
    hideemptyfolders.setContentAreaFilled(false);
    hideemptyfolders.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setHideEmptyFolders((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    // Show iTunes library
    itunes = new JCheckBox(Messages.getString("FoldTab.30"), configuration.isShowItunesLibrary());
    itunes.setToolTipText(Messages.getString("FoldTab.47"));
    itunes.setContentAreaFilled(false);
    if (!(Platform.isMac() || Platform.isWindows())) {
        itunes.setEnabled(false);
    }
    itunes.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setShowItunesLibrary((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    // Show iPhoto library
    iphoto = new JCheckBox(Messages.getString("FoldTab.29"), configuration.isShowIphotoLibrary());
    iphoto.setContentAreaFilled(false);
    if (!Platform.isMac()) {
        iphoto.setEnabled(false);
    }
    iphoto.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setShowIphotoLibrary((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    // Show aperture library
    aperture = new JCheckBox(Messages.getString("FoldTab.34"), configuration.isShowApertureLibrary());
    aperture.setContentAreaFilled(false);
    if (!Platform.isMac()) {
        aperture.setEnabled(false);
    }
    aperture.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setShowApertureLibrary((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    // File order
    final KeyedComboBoxModel<Integer, String> kcbm = new KeyedComboBoxModel<>(
            new Integer[] { UMSUtils.SORT_LOC_SENS, // alphabetical
                    UMSUtils.SORT_LOC_NAT, // natural sort
                    UMSUtils.SORT_INS_ASCII, // ASCIIbetical
                    UMSUtils.SORT_MOD_NEW, // newest first
                    UMSUtils.SORT_MOD_OLD, // oldest first
                    UMSUtils.SORT_RANDOM, // random
                    UMSUtils.SORT_NO_SORT // no sorting
            },
            new String[] { Messages.getString("FoldTab.15"), Messages.getString("FoldTab.22"),
                    Messages.getString("FoldTab.20"), Messages.getString("FoldTab.16"),
                    Messages.getString("FoldTab.17"), Messages.getString("FoldTab.58"),
                    Messages.getString("FoldTab.62") });
    sortmethod = new JComboBox<>(kcbm);
    sortmethod.setEditable(false);
    kcbm.setSelectedKey(configuration.getSortMethod(null));

    sortmethod.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                configuration.setSortMethod(kcbm.getSelectedKey());
                LOGGER.info("Setting {} {}", Messages.getRootString("FoldTab.18"), kcbm.getSelectedValue());
            }
        }
    });

    // Ignore the word "the" while sorting
    ignorethewordthe = new JCheckBox(Messages.getString("FoldTab.39"), configuration.isIgnoreTheWordAandThe());
    ignorethewordthe.setToolTipText(Messages.getString("FoldTab.44"));
    ignorethewordthe.setContentAreaFilled(false);
    ignorethewordthe.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setIgnoreTheWordAandThe((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    atzLimit = new JTextField("" + configuration.getATZLimit());
    atzLimit.setToolTipText(Messages.getString("FoldTab.49"));
    atzLimit.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            try {
                int ab = Integer.parseInt(atzLimit.getText());
                configuration.setATZLimit(ab);
            } catch (NumberFormatException nfe) {
                LOGGER.debug("Could not parse ATZ limit from \"" + atzLimit.getText() + "\"");
                LOGGER.debug("The full error was: " + nfe);
            }
        }
    });

    isShowFolderLiveSubtitles = new JCheckBox(Messages.getString("FoldTab.ShowLiveSubtitlesFolder"),
            configuration.isShowLiveSubtitlesFolder());
    isShowFolderLiveSubtitles.setContentAreaFilled(false);
    isShowFolderLiveSubtitles.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setShowLiveSubtitlesFolder((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    prettifyfilenames = new JCheckBox(Messages.getString("FoldTab.43"), configuration.isPrettifyFilenames());
    prettifyfilenames.setToolTipText(Messages.getString("FoldTab.45"));
    prettifyfilenames.setContentAreaFilled(false);
    prettifyfilenames.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setPrettifyFilenames((e.getStateChange() == ItemEvent.SELECTED));
            hideextensions.setEnabled((e.getStateChange() != ItemEvent.SELECTED));
            episodeTitles.setEnabled((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    episodeTitles = new JCheckBox(Messages.getString("FoldTab.74"), configuration.isUseInfoFromIMDb());
    episodeTitles.setToolTipText(Messages.getString("FoldTab.64"));
    episodeTitles.setContentAreaFilled(false);
    if (!configuration.isPrettifyFilenames()) {
        episodeTitles.setEnabled(false);
    }
    episodeTitles.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setUseInfoFromIMDb((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    isShowFolderNewMedia = new JCheckBox(Messages.getString("FoldTab.ShowNewMediaFolder"),
            configuration.isShowNewMediaFolder());
    isShowFolderNewMedia.setToolTipText(Messages.getString("FoldTab.66"));
    isShowFolderNewMedia.setContentAreaFilled(false);
    isShowFolderNewMedia.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setShowNewMediaFolder((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    resume = new JCheckBox(Messages.getString("NetworkTab.68"), configuration.isResumeEnabled());
    resume.setToolTipText(Messages.getString("NetworkTab.69"));
    resume.setContentAreaFilled(false);
    resume.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setResume((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    isShowFolderRecentlyPlayed = new JCheckBox(Messages.getString("FoldTab.ShowRecentlyPlayedFolder"),
            configuration.isShowRecentlyPlayedFolder());
    isShowFolderRecentlyPlayed.setContentAreaFilled(false);
    isShowFolderRecentlyPlayed.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setShowRecentlyPlayedFolder((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    // Fully played action
    final KeyedComboBoxModel<FullyPlayedAction, String> fullyPlayedActionModel = new KeyedComboBoxModel<>(
            new FullyPlayedAction[] { FullyPlayedAction.NO_ACTION, FullyPlayedAction.MARK,
                    FullyPlayedAction.HIDE_VIDEO, FullyPlayedAction.MOVE_FOLDER, FullyPlayedAction.MOVE_TRASH },
            new String[] { Messages.getString("FoldTab.67"), Messages.getString("FoldTab.68"),
                    Messages.getString("FoldTab.69"), Messages.getString("FoldTab.70"),
                    Messages.getString("FoldTab.71") });
    fullyPlayedAction = new JComboBox<>(fullyPlayedActionModel);
    fullyPlayedAction.setEditable(false);
    fullyPlayedActionModel.setSelectedKey(configuration.getFullyPlayedAction());
    fullyPlayedAction.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                configuration.setFullyPlayedAction(fullyPlayedActionModel.getSelectedKey());
                fullyPlayedOutputDirectory
                        .setEnabled(fullyPlayedActionModel.getSelectedKey() == FullyPlayedAction.MOVE_FOLDER);
                selectFullyPlayedOutputDirectory
                        .setEnabled(fullyPlayedActionModel.getSelectedKey() == FullyPlayedAction.MOVE_FOLDER);

                if (configuration.getUseCache()
                        && fullyPlayedActionModel.getSelectedKey() == FullyPlayedAction.NO_ACTION) {
                    PMS.get().getDatabase().init(true);
                }
            }
        }
    });

    // Watched video output directory
    fullyPlayedOutputDirectory = new JTextField(configuration.getFullyPlayedOutputDirectory());
    fullyPlayedOutputDirectory.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setFullyPlayedOutputDirectory(fullyPlayedOutputDirectory.getText());
        }
    });
    fullyPlayedOutputDirectory
            .setEnabled(configuration.getFullyPlayedAction() == FullyPlayedAction.MOVE_FOLDER);

    // Watched video output directory selection button
    selectFullyPlayedOutputDirectory = new CustomJButton("...");
    selectFullyPlayedOutputDirectory.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser;
            try {
                chooser = new JFileChooser();
            } catch (Exception ee) {
                chooser = new JFileChooser(new RestrictedFileSystemView());
            }
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int returnVal = chooser.showDialog((Component) e.getSource(), Messages.getString("FoldTab.28"));
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                fullyPlayedOutputDirectory.setText(chooser.getSelectedFile().getAbsolutePath());
                configuration.setFullyPlayedOutputDirectory(chooser.getSelectedFile().getAbsolutePath());
            }
        }
    });
    selectFullyPlayedOutputDirectory
            .setEnabled(configuration.getFullyPlayedAction() == FullyPlayedAction.MOVE_FOLDER);
}

From source file:base.BasePlayer.Main.java

@Override

public void keyPressed(KeyEvent e) {
    keyCode = e.getKeyCode();/*from   www .ja v a 2  s.c  o  m*/

    if (!Main.shift && (e.getModifiers() & KeyEvent.SHIFT_MASK) != 0) {

        Main.shift = true;
    } else if ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0) {
        Main.drawCanvas.ctrlpressed = 100;

        if (keyCode == KeyEvent.VK_S) {

            if (drawCanvas.drawVariables.projectName.equals("Untitled")) {
                saveProjectAs.doClick();
            } else {
                Serializer ser = new Serializer();
                ser.serialize(drawCanvas.drawVariables.projectFile);
            }
        }
        if (keyCode == KeyEvent.VK_W) {

            //   System.out.println("\n----\n");

            /*
               int[][] array = new int[Main.varsamples][VariantHandler.callSlider.getUpperValue()+1];
                       
                  for(int i = 0; i<array.length; i++) {
                     for(int j = 0; j<array[i].length; j++) {
             array[i][j] = 0;
                     }
                  }
                  /*VarNode node = FileRead.head.getNext();
                  int counter = 0;
                  while(node != null) {
                     if(!drawCanvas.hideNode(node)) {               
             counter++;
             for(int i = 0; i<node.vars.size(); i++) {
                if(!drawCanvas.hideNodeVar(node, node.vars.get(i))) {
                   for(int j = 0;j<node.vars.get(i).getValue().size(); j++) {
                      if(!drawCanvas.hideVar(node.vars.get(i).getValue().get(j), false)) {
                         array[node.vars.get(i).getValue().get(j).getSample().getIndex()][(int)(MethodLibrary.round(node.vars.get(i).getValue().get(j).getAlleleFraction()*100,2))]++;
                      }
                              
                   }
                           
                           
                }                  
             }
                     }
                       
                     node = node.getNext();
                  }*/
            /*   int width = Main.drawCanvas.getWidth()-Main.sidebarWidth;
                    
               JPopupMenu menu = new JPopupMenu();
            Plotter plotter = new Plotter(width);         
            plotter.setPreferredSize(new Dimension(width,400));
            menu.add(plotter);
            menu.pack();
            menu.show(Main.drawCanvas,Main.sidebarWidth, drawScroll.getVerticalScrollBar().getValue());
            */
        }
        if (keyCode == KeyEvent.VK_PLUS || keyCode == 107) {

            //      defaultFontSize++;

            //      setFonts();
        }
        if (keyCode == KeyEvent.VK_M || keyCode == KeyEvent.VK_MINUS || keyCode == 109) {

            //      defaultFontSize--;

            //      setFonts();
        }
        /*   else if(keyCode == KeyEvent.VK_M) {
              VarNode current = FileRead.head.getNext();
               while(current != null) {
                          
                  if(current.getNext() != null && current.getNext().getPosition()-current.getPosition() > 100000) {
        System.out.println(current.getPosition() +" " +(current.getNext().getPosition()-current.getPosition()));
                  }
                  current = current.getNext();
               }
               current = null;
           }
           */
    } else if (keyCode == KeyEvent.VK_DELETE) {
        if (Main.drawCanvas.selectedSample != null) {
            Main.drawCanvas.removeSample(Main.drawCanvas.selectedSample);
        }
    }
    /*   else if(keyCode == KeyEvent.VK_7) {
                  
                  
       }*/
    else if (keyCode == KeyEvent.VK_O && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) {
        /*   clearData();
                   
           try {
              FileInputStream fin = new FileInputStream("C:/HY-Data/RKATAINE/test.ses");
              ObjectInputStream ois = new ObjectInputStream(fin);
              drawCanvas.sampleList = (ArrayList<Sample>) ois.readObject();
              Main.samples = (short)drawCanvas.sampleList.size();
                      
              drawCanvas.splits = (ArrayList<SplitClass>) ois.readObject();
              for(int i = 0; i<drawCanvas.splits.size(); i++) {
                 drawCanvas.splits.get(i).resetSplits();
              }
              drawCanvas.drawVariables = (DrawVariables)ois.readObject();
                      
              ois.close();
              drawCanvas.resizeCanvas(Main.drawCanvas.getWidth(), Main.drawCanvas.getHeight());
                      
              Draw.setScrollbar(drawCanvas.drawVariables.scrollbarpos);
                      
              for(int i= 0; i<drawCanvas.splits.size(); i++) {
                 drawCanvas.splits.get(i).setCytoImage(null);
                 chromDraw.drawCyto(drawCanvas.splits.get(i));
                 chromDraw.updateExons = true;
                 FileRead.search = true;
                 drawCanvas.gotoPos(drawCanvas.splits.get(i).chrom, drawCanvas.splits.get(i).start, drawCanvas.splits.get(i).end);
                 chromDraw.repaint();
              }
              for(int i = 0 ;i<drawCanvas.sampleList.size(); i++) {
                 for(int r = 0 ;r<drawCanvas.sampleList.size(); r++) {
                    if(drawCanvas.sampleList.get(i).getreadHash().size() > 0) {
          drawCanvas.sampleList.get(i).resetreadHash();
                    }
                 }
              }
                   
           }
           catch(Exception ex) {
              ex.printStackTrace();
           }
           */
    }

    else if (keyCode == KeyEvent.VK_F9) {

        FileRead.head.putNext(null);
        drawCanvas.variantsStart = 0;
        drawCanvas.variantsEnd = 1;
        Draw.updatevars = true;
        Main.drawCanvas.repaint();

    } else if (keyCode == KeyEvent.VK_F11) {

        /*   try {
              BBFileReader reader = new BBFileReader( Main.bedCanvas.bedTrack.get(0).file.getCanonicalPath(),  Main.bedCanvas.bedTrack.get(0));
              int zoomlevel = 1;
              for(int i =2;i<reader.getZoomLevels().getZoomHeaderCount();i++) {
                 if(reader.getZoomLevels().getZoomLevelHeader(i).getReductionLevel() < (Main.drawCanvas.splits.get(0).viewLength/(Main.drawCanvas.splits.get(0).pixel*Main.drawCanvas.splits.get(0).viewLength))) {
                    zoomlevel = i;
                 }
                 else {
                    break;
                 }
              }
                      
                
                         
           }
           catch(Exception ex) {
              ex.printStackTrace();
           }*/
    } else if (keyCode == KeyEvent.VK_F12) {
        /*VarNode next = Main.drawCanvas.current.getNext();
                
        MethodLibrary.makeMultiAlt("2",next.getPosition(), "G", next);
                
           next = null;
        */
        /*   try {
              URL urli = new URL("ftp://ftp.ensembl.org/pub/grch37/update/gff3/homo_sapiens/Homo_sapiens.GRCh37.87.gff3.gz");
              System.out.println(urli.getProtocol() +" " +urli.getHost() +" " +urli.getPath().substring(0,urli.getPath().lastIndexOf("/")+1));
           }
           catch(Exception ex) {
              ex.printStackTrace();
           }*/
    } else if (keyCode == KeyEvent.VK_F8) {

        File file = new File(searchField.getText().replaceAll(" ", ""));
        if (!file.exists()) {
            if (Main.drawCanvas.splits.get(0).viewLength < 1000) {

                Main.getConsSeq();
            }
        } else {
            try {
                /*
                JFileChooser chooser = new JFileChooser(file.getPath());
                chooser.setAcceptAllFileFilterUsed(true);                       
                        
                chooser.setDialogTitle("Save FASTA file as...");
                int returnVal = chooser.showSaveDialog((Component)this.getParent());                   
                        
                if(returnVal == JFileChooser.APPROVE_OPTION) {  
                  String suffix = "";
                  if(!chooser.getSelectedFile().getName().endsWith(".fa") && !chooser.getSelectedFile().getName().endsWith(".fasta")) {
                     suffix = ".fa";
                  }
                          
                   File outfile = new File(chooser.getSelectedFile().getCanonicalPath() +suffix);   
                 //  File outfile = new File("test.fa");   
                   Main.nothread = true;
                  Main.noreadthread = true;
                  FileRead.search = true;   
                  Draw.variantcalculator = true;
                        
                  Seqfetcher fetcher = new Seqfetcher(file, outfile);
                  fetcher.execute();
                           
                }*/
            } catch (Exception ex) {
                ex.printStackTrace();
            }

        }

    } else if (keyCode == KeyEvent.VK_ENTER) {

        if (e.getSource() == searchField) {
            search(searchField.getText());

        }

    }

}