Example usage for javax.swing JMenuItem setText

List of usage examples for javax.swing JMenuItem setText

Introduction

In this page you can find the example usage for javax.swing JMenuItem setText.

Prototype

@BeanProperty(preferred = true, visualUpdate = true, description = "The button's text.")
public void setText(String text) 

Source Link

Document

Sets the button's text.

Usage

From source file:gtu._work.mvn.MavenRepositoryUI.java

void defaultPopupMenu(final List<PomFile> pomFileList, Component component, MouseEvent evt) {
    if (pomFileList == null || pomFileList.isEmpty()) {
        return;//from  w w  w .jav  a2  s.  co  m
    }
    final PomFile pomFile = pomFileList.size() == 1 ? pomFileList.get(0) : null;

    if (pomFileList.size() > 0) {
        final JMenuItem copyAllMenu = new JMenuItem();
        {
            final Set<File> jarList = new HashSet<File>();
            final StringBuilder sb = new StringBuilder();
            for (PomFile _pomFile : pomFileList) {
                if (_pomFile.jarFile != null) {
                    sb.append(_pomFile.jarFile.getName() + "\n");
                    jarList.add(_pomFile.jarFile);
                }
            }
            if (sb.length() > 200) {
                sb.delete(200, sb.length() - 1);
                sb.append("...etc");
            }

            final String title = "COPY SELECTED JAR : " + jarList.size();
            copyAllMenu.setText(title);
            copyAllMenu.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent paramActionEvent) {
                    System.out.println("# copyMenu action ...");
                    JOptionPaneUtil.ComfirmDialogResult result = JOptionPaneUtil.newInstance()
                            .confirmButtonYesNoCancel().showConfirmDialog(//
                                    "are you sure copy file : \n" + sb + "\tto \n" + copyTo + "\n\t???", title);
                    if (result != JOptionPaneUtil.ComfirmDialogResult.YES_OK_OPTION) {
                        return;
                    }

                    new Thread(Thread.currentThread().getThreadGroup(), new Runnable() {
                        public void run() {
                            long startTime = System.currentTimeMillis();
                            File copyToFile = null;
                            int successCount = 0;
                            int errorCount = 0;
                            StringBuilder err = new StringBuilder();
                            for (File jar : jarList) {
                                copyToFile = new File(copyTo, jar.getName());
                                try {
                                    FileUtil.copyFile(jar, copyToFile);
                                    successCount++;
                                } catch (IOException e) {
                                    e.printStackTrace();
                                    errorCount++;
                                    err.append(jar + "\n");
                                }
                            }
                            JOptionPaneUtil.newInstance().iconInformationMessage().showMessageDialog(//
                                    "copy completed!! \n" + //
                            "during : " + (System.currentTimeMillis() - startTime) + "\n" + "success : "
                                            + successCount + "\n" + //
                            "fail : " + errorCount + "\n" + //
                            "fail list : \n" + err, "COMPLETED");
                        }
                    }, "copy all jar to target " + hashCode()).start();
                }
            });
        }

        final JMenuItem copyAllNewMenu = new JMenuItem();
        {
            final Set<File> jarList = new HashSet<File>();
            final StringBuilder sb = new StringBuilder();
            DependencyKey depenKey = null;
            PomFile _newPomFile = null;
            for (PomFile _pomFile : pomFileList) {
                if (_pomFile.jarFile != null) {
                    depenKey = new DependencyKey(_pomFile.pom.groupId, _pomFile.pom.artifactId);
                    if (pomFileMap.containsKey(depenKey)) {
                        _newPomFile = pomFileMap.get(depenKey);
                        System.out.println("find new success: " + _pomFile + " --> " + _newPomFile);
                        _pomFile = _newPomFile;
                    } else {
                        System.out.println("find new faild!!: " + _pomFile);
                    }
                    if (_pomFile.jarFile != null) {
                        sb.append(_pomFile.jarFile.getName() + "\n");
                        jarList.add(_pomFile.jarFile);
                    }
                }
            }
            if (sb.length() > 200) {
                sb.delete(200, sb.length() - 1);
                sb.append("...etc");
            }

            final String title = "COPY SELECTED JAR(newest) : " + jarList.size();
            copyAllNewMenu.setText(title);
            copyAllNewMenu.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent paramActionEvent) {
                    System.out.println("# copyMenu action ...");
                    JOptionPaneUtil.ComfirmDialogResult result = JOptionPaneUtil.newInstance()
                            .confirmButtonYesNoCancel().showConfirmDialog(//
                                    "are you sure copy file : \n" + sb + "\tto \n" + copyTo + "\n\t???", title);
                    if (result != JOptionPaneUtil.ComfirmDialogResult.YES_OK_OPTION) {
                        return;
                    }

                    new Thread(Thread.currentThread().getThreadGroup(), new Runnable() {
                        public void run() {
                            long startTime = System.currentTimeMillis();
                            File copyToFile = null;
                            int successCount = 0;
                            int errorCount = 0;
                            StringBuilder err = new StringBuilder();
                            for (File jar : jarList) {
                                copyToFile = new File(copyTo, jar.getName());
                                try {
                                    FileUtil.copyFile(jar, copyToFile);
                                    successCount++;
                                } catch (IOException e) {
                                    e.printStackTrace();
                                    errorCount++;
                                    err.append(jar + "\n");
                                }
                            }
                            JOptionPaneUtil.newInstance().iconInformationMessage().showMessageDialog(//
                                    "copy completed!! \n" + //
                            "during : " + (System.currentTimeMillis() - startTime) + "\n" + "success : "
                                            + successCount + "\n" + //
                            "fail : " + errorCount + "\n" + //
                            "fail list : \n" + err, "COMPLETED");
                        }
                    }, "copy all jar to target " + hashCode()).start();
                }
            });
        }

        JPopupMenuUtil.newInstance(component).applyEvent(evt).addJMenuItem(copyAllMenu, copyAllNewMenu).show();
    }

    if (pomFile != null) {
        final JMenuItem copyMenu = new JMenuItem();
        {
            if (pomFile.jarFile == null) {
                copyMenu.setText("COPY : no jar file");
                copyMenu.setEnabled(false);
            } else if (copyTo == null) {
                copyMenu.setText("COPY : copy to not set");
                copyMenu.setEnabled(false);
            } else {
                copyMenu.setText("COPY : " + this.getJarName(pomFile));
                copyMenu.setEnabled(true);
            }
            copyMenu.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent paramActionEvent) {
                    System.out.println("# copyMenu action ...");
                    File copyToFile = new File(copyTo, pomFile.jarFile.getName());
                    JOptionPaneUtil.ComfirmDialogResult result = JOptionPaneUtil.newInstance()
                            .confirmButtonYesNoCancel().showConfirmDialog(//
                                    "are you sure copy file : \n" + //
                    pomFile.jarFile.getParent() + "\nto\n" + //
                    copyToFile.getParent() + "\n" + //
                    "\t???", getJarName(pomFile));
                    if (result == JOptionPaneUtil.ComfirmDialogResult.YES_OK_OPTION) {
                        try {
                            FileUtil.copyFile(pomFile.jarFile, copyToFile);
                        } catch (IOException e) {
                            e.printStackTrace();
                            JOptionPaneUtil.newInstance().iconErrorMessage().showMessageDialog(e.toString(),
                                    "ERROR");
                        }
                        JOptionPaneUtil.newInstance().iconInformationMessage()
                                .showMessageDialog("copy success!!", "SUCCESS");
                    }
                }
            });
        }

        final JMenuItem updateSnapshotMenu = new JMenuItem();
        {
            updateSnapshotMenu.setText("update snapshot");
            updateSnapshotMenu.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent paramActionEvent) {
                    new Thread(Thread.currentThread().getThreadGroup(), new Runnable() {
                        public void run() {
                            try {
                                String command = String.format("cmd /c mvn -U -f \"%s\"", pomFile.xmlFile);
                                System.out.println(command);
                                final ProcessWatcher watcher = ProcessWatcher
                                        .newInstance(Runtime.getRuntime().exec("cmd /c @echo TODO!!"));
                                //TODO
                                //FIXME
                                //XXX
                                JOptionPaneUtil.newInstance().iconInformationMessage().showMessageDialog("TODO",
                                        "MAVEN UPDATE");
                            } catch (Exception ex) {
                                JCommonUtil.handleException(ex);
                            }
                        }
                    }, "execute Maven update").start();
                }
            });
        }

        final JMenuItem jdJarMenu = new JMenuItem();
        {
            jdJarMenu.setText("jd-gui");
            if (pomFile.jarFile == null) {
                jdJarMenu.setEnabled(false);
            }
            jdJarMenu.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent paramActionEvent) {
                    try {
                        Runtime.getRuntime().exec(String.format("cmd /c call \"%s\" \"%s\"", //
                                "C:/apps/jd-gui-0.3.1.windows/jd-gui.exe", pomFile.jarFile));
                    } catch (IOException ex) {
                        JCommonUtil.handleException(ex);
                    }
                }
            });
        }
        final JMenuItem openJarDirMenu = new JMenuItem();
        {
            openJarDirMenu.setText("open dir");
            openJarDirMenu.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent paramActionEvent) {
                    try {
                        Desktop.getDesktop().open(pomFile.xmlFile.getParentFile());
                    } catch (IOException ex) {
                        JCommonUtil.handleException(ex);
                    }
                }
            });
        }
        final JMenuItem showDepedencyMessage = new JMenuItem();
        {
            showDepedencyMessage.setText("show dependency");
            showDepedencyMessage.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent paramActionEvent) {
                    clipboardPomJarConfig(pomFile, true);
                }
            });
        }

        JPopupMenuUtil.newInstance(component).applyEvent(evt)
                .addJMenuItem(copyMenu, updateSnapshotMenu, jdJarMenu, openJarDirMenu, showDepedencyMessage)
                .show();
    }
}

From source file:de.codesourcery.eve.skills.ui.components.impl.MarketPriceEditorComponent.java

protected JMenuItem createMenuItem(final String text, final IMenuAction r, final boolean enabled) {

    final JMenuItem item = new JMenuItem(new AbstractAction() {

        @Override//from   w ww.j a  va2s. c  o m
        public boolean isEnabled() {
            return enabled;
        }

        @Override
        public void actionPerformed(ActionEvent e) {

            submitTask(new UITask() {

                @Override
                public String getId() {
                    return text;
                }

                @Override
                public void run() throws Exception {
                    try {
                        r.run();
                    } catch (PriceInfoUnavailableException e) {
                        displayError("Found no price for " + e.getItemType().getName());
                    } catch (Exception e1) {
                        displayError("Error: " + e1.getMessage(), e1);
                    }
                }
            });

        }
    });

    item.setEnabled(enabled);
    item.setText(text);
    return item;
}

From source file:org.gumtree.vis.awt.JChartPanel.java

protected void addMaskMenu(int x, int y) {
    if (this.removeSelectedMaskMenuItem != null) {
        boolean isRemoveMenuEnabled = false;
        if (this.selectedMask != null) {
            Rectangle2D screenMask = ChartMaskingUtilities.getMaskFramework(selectedMask, getScreenDataArea(),
                    getChart());//from w ww. j a  va2s  .c o  m
            if (screenMask.contains(x, y)) {
                isRemoveMenuEnabled = true;
            }
        }
        this.removeSelectedMaskMenuItem.setEnabled(isRemoveMenuEnabled);
        if (isRemoveMenuEnabled) {
            removeSelectedMaskMenuItem.setVisible(true);
            removeSelectedMaskMenuItem.setText("Remove " + selectedMask.getName());
        } else {
            //              removeSelectedMaskMenuItem.setText("Mask Management");
            removeSelectedMaskMenuItem.setVisible(false);
        }
    }
    maskManagementMenu.removeAll();
    if (maskList.size() > 0) {
        maskManagementMenu.setEnabled(true);
        JMenuItem selectNoneMaskItem = new JRadioButtonMenuItem();
        selectNoneMaskItem.setText("Select None");
        selectNoneMaskItem.setActionCommand(DESELECT_MASK_COMMAND);
        selectNoneMaskItem.addActionListener(this);
        maskManagementMenu.add(selectNoneMaskItem);
        boolean isInShade = false;
        for (AbstractMask mask : maskList.keySet()) {
            Rectangle2D screenMask = ChartMaskingUtilities.getMaskFramework(mask, getScreenDataArea(),
                    getChart());
            if (screenMask.contains(x, y)) {
                JMenuItem selectMaskItem = new JRadioButtonMenuItem();
                selectMaskItem.setText("Select " + mask.getName());
                selectMaskItem.setActionCommand(SELECT_MASK_COMMAND + "-" + mask.getName());
                if (mask == selectedMask) {
                    selectMaskItem.setSelected(true);
                }
                selectMaskItem.addActionListener(this);
                maskManagementMenu.add(selectMaskItem);
                isInShade = true;
            }
        }
        if (isInShade) {
            if (selectedMask == null) {
                selectNoneMaskItem.setSelected(true);
            }
        } else {
            for (AbstractMask mask : getMasks()) {
                JMenuItem selectMaskItem = new JRadioButtonMenuItem();
                selectMaskItem.setText("Select " + mask.getName());
                selectMaskItem.setActionCommand(SELECT_MASK_COMMAND + "-" + mask.getName());
                if (mask == selectedMask) {
                    selectMaskItem.setSelected(true);
                }
                selectMaskItem.addActionListener(this);
                maskManagementMenu.add(selectMaskItem);
            }
            selectNoneMaskItem.setSelected(selectedMask == null);
        }
    } else {
        maskManagementMenu.setEnabled(false);
    }
}

From source file:corelyzer.ui.CorelyzerGLCanvas.java

private void updateMainFrameListSelection(final int track, final int section, final MouseEvent event) {
    CorelyzerApp app = CorelyzerApp.getApp();
    if (app == null) {
        return;//from w  w  w  . j  av a 2s . co m
    }

    if (track >= 0) {
        // Now, we need to traverse app's list model
        // to find match of native id
        // index conversion (native to java list)

        CRDefaultListModel sessionModel = app.getSessionListModel();
        int sessionIndex = -1;
        TrackSceneNode trackNode = null;
        for (int i = 0; i < sessionModel.size(); i++) {
            Session session = (Session) sessionModel.elementAt(i);
            trackNode = session.getTrackSceneNodeWithTrackId(track);

            if (trackNode != null) {
                sessionIndex = i;
            }
        }

        if (sessionIndex < 0) {
            return;
        }

        // Set selected session
        app.getSessionList().setSelectedIndex(sessionIndex);

        // Track
        int ssize;
        boolean found = false;
        CRDefaultListModel tmodel = app.getTrackListModel();
        // tsize = tmodel.getSize();
        TrackSceneNode tt;
        CoreSection cs = null;

        for (int i = 0; i < tmodel.size() && !found; i++) {
            tt = (TrackSceneNode) tmodel.elementAt(i);

            if (track == tt.getId()) {
                selectedTrackIndex = i;
                ssize = tt.getNumCores();

                for (int j = 0; j < ssize; j++) {
                    cs = tt.getCoreSection(j);
                    if (section == cs.getId()) {
                        selectedTrackSectionIndex = j;
                        found = true;
                        break;
                    }
                }
            }
        }

        if (!found || cs == null) {
            return;
        }

        // update ui
        CorelyzerApp.getApp().getTrackList().setSelectedIndex(selectedTrackIndex);
        JList secList = CorelyzerApp.getApp().getSectionList();
        boolean selected = secList.isSelectedIndex(selectedTrackSectionIndex);
        List<Integer> indices = new ArrayList<Integer>();
        indices.addAll(Arrays.asList(ArrayUtils.toObject(secList.getSelectedIndices())));
        if (event.isControlDown() || (event.isMetaDown() && CorelyzerApp.MAC_OS_X)) { // toggle selection
            if (indices.contains(selectedTrackSectionIndex))
                indices.remove(new Integer(selectedTrackSectionIndex));
            else
                indices.add(selectedTrackSectionIndex);

            int[] newSelArray = ArrayUtils.toPrimitive(indices.toArray(new Integer[0]));
            secList.setSelectedIndices(newSelArray);
        } else if (event.isShiftDown()) { // select range
            int[] toSel = null;
            if (indices.size() == 0) {
                toSel = makeRangeArray(0, selectedTrackSectionIndex);
            } else {
                final int minSel = Collections.min(indices);
                final int maxSel = Collections.max(indices);
                if (selectedTrackSectionIndex < minSel) {
                    toSel = makeRangeArray(selectedTrackSectionIndex, minSel);
                } else if (selectedTrackSectionIndex > maxSel) {
                    toSel = makeRangeArray(maxSel, selectedTrackSectionIndex);
                }
            }
            secList.setSelectedIndices(toSel);
        } else if (!(event.isAltDown() && selected)) {
            // don't modify selection if Alt is down and section was already
            // selected...user is presumably trying to move it
            secList.setSelectedIndex(selectedTrackSectionIndex);
        }

        CRDefaultListModel lm = CorelyzerApp.getApp().getSectionListModel();
        String secName = null;
        if (lm != null) {
            Object selSec = lm.getElementAt(selectedTrackSectionIndex);
            if (selSec != null) {
                secName = selSec.toString();
            } else {
                System.out.println("no object at index");
            }
        } else {
            System.out.println("no list model");
        }

        JMenuItem title = (JMenuItem) this.scenePopupMenu.getComponent(0);
        String trackName = CorelyzerApp.getApp().getTrackListModel().getElementAt(selectedTrackIndex)
                .toString();
        title.setText("Track: " + trackName);
        JMenuItem stitle = (JMenuItem) this.scenePopupMenu.getComponent(1);
        stitle.setText("Section: " + secName);

        // Enable section-based popupMenu options
        this.setEnableSectionBasedPopupMenuOptions(true);

        // 2/5/2012 brg: check Stagger Sections menu item if necessary
        final boolean trackIsStaggered = SceneGraph.trackIsStaggered(selectedTrack);
        AbstractButton ab = (AbstractButton) this.scenePopupMenu.getComponent(14);
        ab.getModel().setSelected(trackIsStaggered);

        // check section and graph lock menu items
        final boolean sectionIsLocked = !SceneGraph.isSectionMovable(selectedTrack, selectedTrackSection);
        ab = (AbstractButton) this.scenePopupMenu.getComponent(7);
        ab.getModel().setSelected(sectionIsLocked);
        final boolean sectionGraphIsLocked = !SceneGraph.isSectionGraphMovable(selectedTrack,
                selectedTrackSection);
        ab = (AbstractButton) this.scenePopupMenu.getComponent(8);
        ab.getModel().setSelected(sectionGraphIsLocked);

        CoreSectionImage csImg = cs.getCoreSectionImage();
        if (csImg != null && csImg.getId() != -1) {
            this.propertyMenuItem.setEnabled(true);
            this.splitMenuItem.setEnabled(true);
        } else {
            this.propertyMenuItem.setEnabled(false);
            this.splitMenuItem.setEnabled(false);
        }

        // System.out.println("---> [in Java DS] Picked Track " + track +
        // " and Track Section " + section);
        // String secname = CorelyzerApp.getApp().getSectionListModel().
        // getElementAt(section).toString();
        // System.out.println("---> [INFO] Section " + secname +
        // " is selected");
    } else {
        JMenuItem title = (JMenuItem) this.scenePopupMenu.getComponent(0);
        title.setText("Track: N/A");
        JMenuItem stitle = (JMenuItem) this.scenePopupMenu.getComponent(1);
        stitle.setText("Section: N/A");

        // disable section based items
        this.setEnableSectionBasedPopupMenuOptions(false);
    }
}

From source file:de.dmarcini.submatix.pclogger.gui.MainCommGUI.java

/**
 * verfgbare Sprachen in Men eintragen Project: SubmatixBTConfigPC Package: de.dmarcini.submatix.pclogger.gui
 * //from  www  .  j  av a 2  s  .c om
 * @author Dirk Marciniak (dirk_marciniak@arcor.de) Stand: 18.12.2011
 * @param programLocale
 */
private void initLanuageMenu(Locale programLocale) {
    ResourceBundle rb;
    Enumeration<String> enu;
    String key = null;
    String cmd = null;
    try {
        lg.debug("try init language menu...");
        ignoreAction = true;
        // Lies die Resource aus
        rb = ResourceBundle.getBundle("de.dmarcini.submatix.pclogger.lang.languages");
        // Alle KEYS lesen
        enu = rb.getKeys();
        try {
            lg.debug("try init language menuitems...");
            while (enu.hasMoreElements()) {
                JMenuItem menuItem = new JMenuItem();
                key = enu.nextElement();
                cmd = rb.getString(key);
                menuItem.setText(key);
                menuItem.addActionListener(this);
                menuItem.setActionCommand(cmd);
                menuItem.addMouseMotionListener(this);
                mnLanguages.add(menuItem);
            }
            lg.debug("try init language menuitems...done");
        } catch (NullPointerException ex) {
            lg.error("NULL POINTER EXCEPTION <" + ex.getMessage() + ">");
            statusTextField.setText("ERROR set language strings");
            System.out.println("ERROR set language strings <" + ex.getMessage() + "> ABORT!");
            System.exit(-1);
        } catch (MissingResourceException ex) {
            lg.error("MISSING RESOURCE EXCEPTION <" + ex.getMessage() + ">");
            statusTextField.setText("ERROR set language strings");
            System.out.println("ERROR set language strings <" + ex.getMessage() + "> ABORT!");
            System.exit(-1);
        } catch (ClassCastException ex) {
            lg.error("CLASS CAST EXCEPTION <" + ex.getMessage() + ">");
            statusTextField.setText("ERROR set language strings");
            System.out.println("ERROR set language strings <" + ex.getMessage() + "> ABORT!");
            System.exit(-1);
        } finally {
            ignoreAction = false;
        }
    } catch (NullPointerException ex) {
        lg.error("NULL POINTER EXCEPTION <" + ex.getMessage() + ">");
        statusTextField.setText("ERROR set language strings");
        System.out.println("ERROR set language strings <" + ex.getMessage() + "> ABORT!");
        System.exit(-1);
    } catch (MissingResourceException ex) {
        lg.error("MISSING RESOURCE EXCEPTION <" + ex.getMessage() + ">");
        statusTextField.setText("ERROR set language strings - the given key can be found");
        System.out.println(
                "ERROR set language strings - the given key can be found <" + ex.getMessage() + "> ABORT!");
        System.exit(-1);
    } catch (ClassCastException ex) {
        lg.error("CLASS CAST EXCEPTION <" + ex.getMessage() + ">");
        statusTextField.setText("ERROR set language strings");
        System.out.println("ERROR set language strings <" + ex.getMessage() + "> ABORT!");
        System.exit(-1);
    } finally {
        ignoreAction = false;
    }
    lg.debug("try init language menu...done");
}

From source file:search2go.UIFrame.java

public UIFrame() throws IOException, ParseException {
    topLevels = new TopLevelGTermSet[] { CCs, MFs, BPs };

    this.addWindowListener(new WindowAdapter() {
        @Override/*w w w.j a v  a  2s  . com*/
        public void windowClosing(WindowEvent et) {
            try {
                if (os.isWindows()) {
                    Runtime.getRuntime().exec("cmd /C TaskKill -IM blastx.exe -F");
                    Runtime.getRuntime().exec("cmd /C TaskKill -IM blastn.exe -F");
                    Runtime.getRuntime().exec("cmd /C TaskKill -IM blastp.exe -F");
                    Runtime.getRuntime().exec("cmd /C TaskKill -IM python.exe -F");
                } else {
                    Runtime.getRuntime().exec("killAll -KILL blastx");
                    Runtime.getRuntime().exec("killAll -KILL blastn");
                    Runtime.getRuntime().exec("killAll -KILL blastp");
                    Runtime.getRuntime().exec("killAll -KILL python");
                }
            } catch (IOException ex) {
                System.out.println("Error closing child processes");
            }
        }
    });

    initComponents();

    txtBlastOutput.getDocument().addDocumentListener(new BufferEnforcer(txtBlastOutput));
    txtFullOutput.getDocument().addDocumentListener(new BufferEnforcer(txtFullOutput));
    txtMapOutput.getDocument().addDocumentListener(new BufferEnforcer(txtMapOutput));

    ((DefaultCaret) txtBlastOutput.getCaret()).setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
    ((DefaultCaret) txtMapOutput.getCaret()).setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
    ((DefaultCaret) txtFullOutput.getCaret()).setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);

    webSaveMenu = new JPopupMenu();
    JMenuItem saveWeb = new JMenuItem();
    saveWeb.setText("Save");
    saveWeb.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            webSaveDialogue.showSaveDialog(pnlChartHolder);
            File saveFile = webSaveDialogue.getSelectedFile();
            if (!saveFile.getPath().contains(".png"))
                saveFile = new File(saveFile.getPath() + ".png");
            try {
                BufferedImage webChartImage = new BufferedImage(pnlChartHolder.getWidth(),
                        pnlChartHolder.getHeight(), BufferedImage.TYPE_INT_RGB);
                pnlChartHolder.print(webChartImage.getGraphics());
                ImageIO.write(webChartImage, "png", saveFile);
            } catch (Exception ex) {
                javax.swing.JOptionPane.showMessageDialog(pnlChartHolder,
                        "Error saving chart. Please try again.");
            }
        }

    });
    webSaveMenu.add(saveWeb);
    pnlChartHolder.add(webSaveMenu);
    pnlChartHolder.setLayout(new java.awt.BorderLayout());

    try {
        currentProj = Workspace.open(new Path("Search2GO_Data"));
        chkDoCCs.setState(currentProj.willDoCC());
        chkDoBPs.setState(currentProj.willDoBP());
        chkDoMFs.setState(currentProj.willDoMF());
        txtQuery.setText(currentProj.getQueryPath());
        txtQueryFP.setText(currentProj.getQueryPath());
        txtDatabase.setText(currentProj.getPathToDB());
        txtDatabaseFP.setText(currentProj.getPathToDB());
        txtThreads.setValue(currentProj.getThreadNo());
        txtThreadsFP.setValue(currentProj.getThreadNo());
        cbxNXP.setSelectedIndex(currentProj.getBlastTypeIndex());
        cbxNXPFP.setSelectedIndex(currentProj.getBlastTypeIndex());
        cbxDBID.setSelectedIndex(currentProj.getSelectedDBIndex());
        cbxDBIDFP.setSelectedIndex(currentProj.getSelectedDBIndex());
        txtBitScore.setValue(currentProj.getBitScoreThreshold());
        txtBitScoreFP.setValue(currentProj.getBitScoreThreshold());
        txtBlastE.setValue(currentProj.getEThreshold());
        txtMapE.setValue(currentProj.getEThreshold());
        txtEFP.setValue(currentProj.getEThreshold());
    } catch (FileNotFoundException e) {
        currentProj = Workspace.create(new Path("Search2GO_Data"));
        chkDoCCs.setState(currentProj.willDoCC());
        chkDoBPs.setState(currentProj.willDoBP());
        chkDoMFs.setState(currentProj.willDoMF());
    }
    this.setTitle("Search2GO " + currentProj.getPath().toString());

    GTermTableModel = new DefaultTableModel();
    GTermTableModel.setColumnCount(2);
    GTermTableModel.setColumnIdentifiers(new String[] { "GO ID", "Frequency" });

    ListSelectionModel GTermSelector = tblGOFreq.getSelectionModel();
    GTermSelector.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                if (tblGOFreq.getSelectedRow() > -1) {
                    DefaultListModel emptyModel = new DefaultListModel();
                    lstQueries.setModel(emptyModel);
                    txtTermInfo.setText("");
                    String selectedID = (String) tblGOFreq.getValueAt(tblGOFreq.getSelectedRow(), 0);
                    JTextArea tempHolderInfo = new JTextArea();
                    JTextArea tempHolderQueries = new JTextArea();

                    if (tblGOFreq.getSelectedRow() != -1) {
                        ResetGTermInfoGetter(tempHolderInfo, tempHolderQueries);
                        gTermInfoGetter.getProcess(0).addParameter("id",
                                selectedID.substring(0, selectedID.indexOf("[")));
                        gTermInfoGetter.getProcess(1).addParameter("id",
                                selectedID.substring(0, selectedID.indexOf("[")));
                        GTerm currentGTerm = gTerms.getGTerm(selectedID.substring(0, selectedID.indexOf("[")));
                        gTermInfoGetter.getProcess(1).addParameter("db", currentGTerm.getTopLevel().getCode());
                        gTermInfoGetter.setTail(new ProcessSequenceEnd() {
                            @Override
                            public void run() {
                                tempHolderInfo.setText("id: " + selectedID + "\n" + tempHolderInfo.getText());
                                txtTermInfo.setText(tempHolderInfo.getText());

                                DefaultListModel queryList = new DefaultListModel();
                                for (String str : tempHolderQueries.getText().split(";")) {
                                    queryList.addElement(str.replaceAll("Query: ", ""));
                                }

                                lstQueries.setModel(queryList);
                                prgIdentification.setIndeterminate(false);
                            }
                        });
                        try {
                            gTermInfoGetter.start();
                            prgIdentification.setIndeterminate(true);
                        } catch (IOException ex) {
                            Logger.getLogger(UIFrame.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                }
            }
        }
    });

    lstQueries.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting() && !e.toString().contains("invalid")
                    && lstQueries.getSelectedValue() != null) {
                JTextArea tempHolder = new JTextArea();

                ProcessSequence fetchLocusSequence = new ProcessSequence(new ProcessSequenceEnd() {
                    @Override
                    public void run() {
                        if (txtTermInfo.getText().contains("Score")) {
                            txtTermInfo.setText(
                                    txtTermInfo.getText().substring(0, txtTermInfo.getText().indexOf("Score")));
                        }
                        txtTermInfo.append(tempHolder.getText());
                        prgIdentification.setIndeterminate(false);
                    }
                });
                Path fetchLocusPath = new Path("Processes");
                fetchLocusPath.append("fetchLocus.py");
                Process fetchLocus = new Process(tempHolder);
                fetchLocus.setScriptCommand(fetchLocusPath.toEscString());
                fetchLocus.addParameter("dir", currentProj.getPath().toEscString());
                fetchLocus.addParameter("q",
                        new ParameterString(lstQueries.getSelectedValue().replace("\n", "")).toString());

                String selectedID = (String) tblGOFreq.getValueAt(tblGOFreq.getSelectedRow(), 0);
                GTerm currentGTerm = gTerms.getGTerm(selectedID.substring(0, selectedID.indexOf("[")));
                fetchLocus.addParameter("db", currentGTerm.getTopLevel().getCode());
                fetchLocus.addParameter("id", currentGTerm.getID());
                fetchLocusSequence.addProcess(fetchLocus);

                try {
                    fetchLocusSequence.start();
                    prgIdentification.setIndeterminate(true);
                } catch (IOException ex) {
                    Logger.getLogger(UIFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    });

    DocumentListener filterListener = new DocumentListener() {
        private void anyUpdate() {
            gTerms.getFilter().setFilterString(txtSearchTerms.getText());
            if (!txtMinFreqFilter.getText().equals(""))
                gTerms.getFilter().setMinFreq(Integer.parseInt(txtMinFreqFilter.getText()));
            else
                gTerms.getFilter().setMinFreq(0);
            if (!txtMaxFreqFilter.getText().equals(""))
                gTerms.getFilter().setMaxFreq(Integer.parseInt(txtMaxFreqFilter.getText()));
            else
                gTerms.getFilter().setMaxFreq(-1);
            fillIdentTable(gTerms.stringFilter(), false);
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            anyUpdate();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            anyUpdate();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            anyUpdate();
        }
    };
    txtSearchTerms.getDocument().addDocumentListener(filterListener);
    txtMinFreqFilter.getDocument().addDocumentListener(filterListener);
    txtMaxFreqFilter.getDocument().addDocumentListener(filterListener);

    NumberFormat numberMask = NumberFormat.getIntegerInstance();
    numberMask.setGroupingUsed(false);
    NumberFormatter numberMasker = new NumberFormatter(numberMask);
    NumberFormatter numberMaskerAndBlank = new NumberFormatter(numberMask) {
        @Override
        public Object stringToValue(String s) throws ParseException {
            if (s == null || s.length() == 0)
                return null;
            return super.stringToValue(s);
        }
    };
    DefaultFormatterFactory numberMaskFactory = new DefaultFormatterFactory(numberMasker);
    DefaultFormatterFactory numberMaskAndBlankFactory = new DefaultFormatterFactory(numberMaskerAndBlank);

    txtThreads.setFormatterFactory(numberMaskFactory);
    txtThreadsFP.setFormatterFactory(numberMaskFactory);
    txtBitScore.setFormatterFactory(numberMaskAndBlankFactory);
    txtBitScoreFP.setFormatterFactory(numberMaskAndBlankFactory);
    txtMinFreqFilter.setFormatterFactory(numberMaskFactory);
    txtMaxFreqFilter.setFormatterFactory(numberMaskFactory);
    txtBlastE.setFormatterFactory(numberMaskAndBlankFactory);
    txtMapE.setFormatterFactory(numberMaskAndBlankFactory);
    txtEFP.setFormatterFactory(numberMaskAndBlankFactory);

    blastButton = new StopButton(btnBlast);
    mapButton = new StopButton(btnMapIDs);
    identButton = new StopButton(btnGTermIdent);
    fullButton = new StopButton(btnProcessFP);

    if (currentProj.getStage() >= 2)
        identify(false);
}

From source file:edu.ku.brc.ui.UIHelper.java

/**
 * Creates a JMenuItem./*from w  w  w.ja  v  a  2s  .c  om*/
 * @param menu parent menu
 * @param label the label of the menu item
 * @param mnemonic the mnemonic
 * @param accessibleDescription the accessible Description
 * @param enabled enabled
 * @param action the aciton
 * @return menu item
 */
public static JMenuItem createMenuItemWithAction(final JPopupMenu menu, final String label,
        final String mnemonic, final String accessibleDescription, final boolean enabled, final Action action) {
    JMenuItem mi = new JMenuItem(action);
    mi.setText(label);
    if (menu != null) {
        menu.add(mi);
    }
    if (isNotEmpty(mnemonic)) {
        mi.setMnemonic(mnemonic.charAt(0));
    }
    if (isNotEmpty(accessibleDescription)) {
        mi.getAccessibleContext().setAccessibleDescription(accessibleDescription);
    }

    if (action != null) {
        action.addPropertyChangeListener(new MenuItemPropertyChangeListener(mi));
        action.setEnabled(enabled);
    }

    return mi;
}

From source file:corelyzer.ui.CorelyzerApp.java

private void setupPopupMenu() {
    // session popup
    sessionPopupMenu = new JPopupMenu("Sessions");

    JMenuItem hideSession = new JMenuItem("Hide");
    hideSession.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            JMenuItem m = (JMenuItem) e.getSource();
            Session s = (Session) sessionList.getSelectedValue();
            String l = s.isShow() ? "Show" : "Hide";
            controller.setSessionVisible(!s.isShow());
            m.setText(l);
        }//ww w  .  j a v a 2s  . c  o m
    });
    sessionPopupMenu.add(hideSession);

    JMenuItem renameSession = new JMenuItem("Rename...");
    renameSession.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            controller.renameSession();
        }
    });
    sessionPopupMenu.add(renameSession);

    JMenuItem removeSession = new JMenuItem("Close");
    removeSession.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            Session s = (Session) sessionList.getSelectedValue();
            controller.removeSession(s);
        }
    });
    sessionPopupMenu.add(removeSession);

    // track popup
    trackPopupMenu = new JPopupMenu("Tracks");

    JMenuItem hide = new JMenuItem("Hide");
    hide.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            controller.setTrackVisible();
        }
    });
    trackPopupMenu.add(hide);

    JMenuItem rename = new JMenuItem("Rename...");
    rename.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            controller.renameTrack();
        }
    });
    trackPopupMenu.add(rename);

    trackPopupDeleteMenuItem = new JMenuItem("Delete");
    trackPopupDeleteMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent event) {
            controller.deleteTrack();
        }
    });
    trackPopupMenu.add(trackPopupDeleteMenuItem);

    // data popup
    dataPopupMenu = new JPopupMenu("Datasets");

    dataPopupGraphMenuItem = new JMenuItem("Graph...");
    dataPopupGraphMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent event) {
            controller.showGraphDialog();
        }
    });

    JMenuItem dataPopupDeleteMenuItem = new JMenuItem("Delete");
    dataPopupDeleteMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent event) {
            controller.deleteDataset();
        }
    });

    dataPopupMenu.add(dataPopupGraphMenuItem);
    dataPopupMenu.add(dataPopupDeleteMenuItem);
}

From source file:edu.ku.brc.ui.UIHelper.java

/**
 * Creates a JMenuItem.//from w  w  w  .ja  va2  s  . com
 * @param menu parent menu
 * @param label the label of the menu item
 * @param mnemonic the mnemonic
 * @param accessibleDescription the accessible Description
 * @param enabled enabled
 * @param action the aciton
 * @return menu item
 */
public static JMenuItem createMenuItemWithAction(final JMenu menu, final String label, final String mnemonic,
        final String accessibleDescription, final boolean enabled, final Action action) {
    JMenuItem mi = new JMenuItem(action);
    mi.setText(label);

    if (menu != null) {
        menu.add(mi);
    }
    if (isNotEmpty(mnemonic)) {
        mi.setMnemonic(mnemonic.charAt(0));
    }
    if (isNotEmpty(accessibleDescription)) {
        mi.getAccessibleContext().setAccessibleDescription(accessibleDescription);
    }

    if (action != null) {
        action.addPropertyChangeListener(new MenuItemPropertyChangeListener(mi));
        action.setEnabled(enabled);
    }

    return mi;
}

From source file:corelyzer.ui.CorelyzerApp.java

public void mousePressed(final MouseEvent e) {
    // From JDK Doc
    // Note: Popup menus are triggered differently on different systems.
    // Therefore, isPopupTrigger should be checked in both mousePressed and
    // mouseReleased for proper cross-platform functionality.

    Point p = e.getPoint();//from   w w w. j a v a 2 s .  c o m
    Object actionSource = e.getSource();

    if (actionSource instanceof JList) {
        // find the index of the clicked item in the JList
        int index = ((JList) e.getSource()).locationToIndex(e.getPoint());
        if (index < 0) {
            return;
        }

        // show our popup menu if it was a right/ctrl-click
        if (e.isPopupTrigger()) {
            if (actionSource.equals(sessionList)) {
                Session s = (Session) sessionList.getSelectedValue();
                JMenuItem t;

                // Show label switching
                if (s == null) {
                    return;
                }

                String l = s.isShow() ? "Hide" : "Show";
                t = (JMenuItem) sessionPopupMenu.getComponent(0);
                t.setText(l);

                sessionPopupMenu.show(e.getComponent(), p.x, p.y);
            } else if (actionSource.equals(trackList)) {
                ((JList) e.getSource()).setSelectedIndex(index);

                // Update context-aware show/hide
                TrackSceneNode t = (TrackSceneNode) trackList.getSelectedValue();
                if ((t != null) && (t.getId() >= 0)) {
                    boolean isShown = SceneGraph.getTrackShow(t.getId());
                    String label = isShown ? "Hide" : "Show";
                    ((JMenuItem) trackPopupMenu.getComponent(0)).setText(label);
                }

                trackPopupMenu.show(e.getComponent(), p.x, p.y);
            } else if (actionSource.equals(sectionList)) {
                int[] rows = getSectionList().getSelectedIndices();

                JPopupMenu menu = sectionListPopupMenu(rows);
                menu.show(e.getComponent(), p.x, p.y);
            } else if (actionSource.equals(dataFileList)) {
                ((JList) e.getSource()).setSelectedIndex(index);
                dataPopupMenu.show(e.getComponent(), p.x, p.y);
            }
        }
    }
}