Search in sources :

Example 16 with JFormattedTextField

use of javax.swing.JFormattedTextField in project EnrichmentMapApp by BaderLab.

the class CutoffPropertiesPanel method getFormatterFactory.

private static AbstractFormatterFactory getFormatterFactory(boolean scientific) {
    return new AbstractFormatterFactory() {

        @Override
        public AbstractFormatter getFormatter(JFormattedTextField tf) {
            NumberFormat format = scientific ? new DecimalFormat("0.######E00") : new DecimalFormat();
            format.setMinimumFractionDigits(scientific ? 0 : 1);
            format.setMaximumFractionDigits(12);
            InternationalFormatter formatter = new InternationalFormatter(format);
            formatter.setAllowsInvalid(true);
            return formatter;
        }
    };
}
Also used : DecimalFormat(java.text.DecimalFormat) InternationalFormatter(javax.swing.text.InternationalFormatter) JFormattedTextField(javax.swing.JFormattedTextField) AbstractFormatterFactory(javax.swing.JFormattedTextField.AbstractFormatterFactory) NumberFormat(java.text.NumberFormat)

Example 17 with JFormattedTextField

use of javax.swing.JFormattedTextField in project EnrichmentMapApp by BaderLab.

the class PostAnalysisKnownSignaturePanel method createKnownSignatureGMTPanel.

/**
	 * @return Panel for choosing and loading GMT and SignatureGMT Geneset-Files
	 */
private JPanel createKnownSignatureGMTPanel() {
    knownSignatureGMTFileNameTextField = new JFormattedTextField();
    knownSignatureGMTFileNameTextField.setColumns(15);
    knownSignatureGMTFileNameTextField.setToolTipText(Messages.GMT_INSTRUCTION);
    final Color textFieldForeground = knownSignatureGMTFileNameTextField.getForeground();
    knownSignatureGMTFileNameTextField.addPropertyChangeListener("value", new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent e) {
            // if the text is red set it back to black as soon as the user starts typing
            knownSignatureGMTFileNameTextField.setForeground(textFieldForeground);
        }
    });
    JButton selectSigGMTFileButton = new JButton("Browse...");
    selectSigGMTFileButton.setToolTipText(Messages.GMT_INSTRUCTION);
    selectSigGMTFileButton.setActionCommand("Known Signature");
    selectSigGMTFileButton.addActionListener(e -> {
        parentPanel.chooseGMTFile(knownSignatureGMTFileNameTextField);
    });
    makeSmall(knownSignatureGMTFileNameTextField, selectSigGMTFileButton);
    JPanel panel = new JPanel();
    panel.setBorder(LookAndFeelUtil.createTitledBorder("SigGMT File (contains signature-genesets)"));
    final GroupLayout layout = new GroupLayout(panel);
    panel.setLayout(layout);
    layout.setAutoCreateContainerGaps(true);
    layout.setAutoCreateGaps(!LookAndFeelUtil.isAquaLAF());
    layout.setHorizontalGroup(layout.createSequentialGroup().addComponent(knownSignatureGMTFileNameTextField, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE).addComponent(selectSigGMTFileButton, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE));
    layout.setVerticalGroup(layout.createParallelGroup(Alignment.CENTER, false).addComponent(knownSignatureGMTFileNameTextField, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(selectSigGMTFileButton));
    if (LookAndFeelUtil.isAquaLAF())
        panel.setOpaque(false);
    return panel;
}
Also used : JPanel(javax.swing.JPanel) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) Color(java.awt.Color) JFormattedTextField(javax.swing.JFormattedTextField) JButton(javax.swing.JButton) GroupLayout(javax.swing.GroupLayout)

Example 18 with JFormattedTextField

use of javax.swing.JFormattedTextField in project EnrichmentMapApp by BaderLab.

the class PostAnalysisSignatureDiscoveryPanel method createSignatureDiscoveryGMTPanel.

/**
     * @return Panel for choosing and loading GMT and SignatureGMT Geneset-Files 
     */
private JPanel createSignatureDiscoveryGMTPanel() {
    signatureDiscoveryGMTFileNameTextField = new JFormattedTextField();
    signatureDiscoveryGMTFileNameTextField.setColumns(15);
    signatureDiscoveryGMTFileNameTextField.setToolTipText(Messages.GMT_INSTRUCTION);
    final Color textFieldForeground = signatureDiscoveryGMTFileNameTextField.getForeground();
    signatureDiscoveryGMTFileNameTextField.addPropertyChangeListener("value", (PropertyChangeEvent e) -> {
        // if the text is red set it back to black as soon as the user starts typing
        signatureDiscoveryGMTFileNameTextField.setForeground(textFieldForeground);
    });
    JButton selectSigGMTFileButton = new JButton("Browse...");
    selectSigGMTFileButton.setToolTipText(Messages.GMT_INSTRUCTION);
    selectSigGMTFileButton.setActionCommand("Signature Discovery");
    selectSigGMTFileButton.addActionListener((ActionEvent evt) -> {
        parentPanel.chooseGMTFile(signatureDiscoveryGMTFileNameTextField);
    });
    JLabel filterLabel = new JLabel("Filter:");
    filterTextField = new JFormattedTextField();
    filterTextField.setColumns(4);
    filterTextField.setHorizontalAlignment(JTextField.RIGHT);
    filterTextField.addPropertyChangeListener("value", (PropertyChangeEvent e) -> {
        StringBuilder message = new StringBuilder("The value you have entered is invalid.\n");
        Number number = (Number) filterTextField.getValue();
        PostAnalysisFilterType filterType = getFilterType();
        Optional<Double> value = PostAnalysisInputPanel.validateAndGetFilterValue(number, filterType, message);
        savedFilterValues.put(filterType, value.orElse(filterType.defaultValue));
        if (!value.isPresent()) {
            filterTextField.setValue(filterType.defaultValue);
            JOptionPane.showMessageDialog(application.getJFrame(), message.toString(), "Parameter out of bounds", JOptionPane.WARNING_MESSAGE);
        }
    });
    // Types of filters:
    // 1. filter by percent, i.e. the overlap between the signature geneset and EM geneset
    //    has to be X percentage of the EM set it overlaps with for at least one geneset in the enrichment map.
    // 2. filter by number, i.e. the overlap between the signature geneset and EM geneset
    //    has to be X genes of the EM set it overlaps with for at least one geneset in the enrichment map.
    // 3. filter by specificity, i.e looking for the signature genesets that are more specific than other genesets
    //    for instance a drug A that targets only X and Y as opposed to drug B that targets X,y,L,M,N,O,P.
    filterTypeCombo = new JComboBox<>();
    // default
    filterTypeCombo.addItem(PostAnalysisFilterType.NO_FILTER);
    //		filterTypeCombo.addItem(PostAnalysisFilterType.MANN_WHIT_TWO_SIDED);
    //		filterTypeCombo.addItem(PostAnalysisFilterType.MANN_WHIT_GREATER);
    //		filterTypeCombo.addItem(PostAnalysisFilterType.MANN_WHIT_LESS);
    filterTypeCombo.addItem(PostAnalysisFilterType.HYPERGEOM);
    filterTypeCombo.addItem(PostAnalysisFilterType.NUMBER);
    filterTypeCombo.addItem(PostAnalysisFilterType.PERCENT);
    filterTypeCombo.addItem(PostAnalysisFilterType.SPECIFIC);
    filterTypeCombo.addActionListener(e -> {
        updateFilterTextField();
    });
    updateFilterTextField();
    //TODO: Maybe move loading SigGMT to File-selection Event add load button
    JButton loadButton = new JButton();
    loadButton.setText("Load Gene Sets");
    loadButton.addActionListener(e -> {
        String filePath = (String) signatureDiscoveryGMTFileNameTextField.getValue();
        if (filePath == null || PostAnalysisInputPanel.checkFile(filePath).equals(Color.RED)) {
            String message = "Signature GMT file name not valid.\n";
            signatureDiscoveryGMTFileNameTextField.setForeground(Color.RED);
            JOptionPane.showMessageDialog(application.getJFrame(), message, "Post Analysis Known Signature", JOptionPane.WARNING_MESSAGE);
            return;
        }
        if (!EnrichmentMapParameters.checkFile(filePath)) {
            String message = "Signature GMT does not exist.\n";
            signatureDiscoveryGMTFileNameTextField.setForeground(Color.RED);
            JOptionPane.showMessageDialog(application.getJFrame(), message, "Post Analysis Known Signature", JOptionPane.WARNING_MESSAGE);
            return;
        }
        FilterMetric filterMetric = createFilterMetric();
        LoadSignatureSetsActionListener action = loadSignatureSetsActionListenerFactory.create(new File(filePath), filterMetric, parentPanel.getEnrichmentMap());
        action.setGeneSetCallback(gs -> {
            this.signatureGenesets = gs;
        });
        action.setFilteredSignatureSetsCallback(selected -> {
            availSigSetsModel.clear();
            selectedSigSetsModel.clear();
            for (String name : selected) availSigSetsModel.addElement(name);
            update();
        });
        action.actionPerformed(null);
    });
    makeSmall(signatureDiscoveryGMTFileNameTextField, selectSigGMTFileButton);
    makeSmall(filterLabel, filterTypeCombo, filterTextField);
    makeSmall(loadButton);
    JPanel panel = new JPanel();
    panel.setBorder(LookAndFeelUtil.createTitledBorder("SigGMT File (contains signature-genesets)"));
    final GroupLayout layout = new GroupLayout(panel);
    panel.setLayout(layout);
    layout.setAutoCreateContainerGaps(true);
    layout.setAutoCreateGaps(!LookAndFeelUtil.isAquaLAF());
    layout.setHorizontalGroup(layout.createParallelGroup(Alignment.CENTER, true).addGroup(layout.createSequentialGroup().addComponent(signatureDiscoveryGMTFileNameTextField, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE).addComponent(selectSigGMTFileButton, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addGroup(layout.createSequentialGroup().addComponent(filterLabel, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(filterTypeCombo, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE).addComponent(filterTextField, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addComponent(loadButton, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE));
    layout.setVerticalGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(Alignment.CENTER, false).addComponent(signatureDiscoveryGMTFileNameTextField, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(selectSigGMTFileButton)).addGroup(layout.createParallelGroup(Alignment.CENTER, false).addComponent(filterLabel, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(filterTypeCombo, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(filterTextField, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addComponent(loadButton, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE));
    if (LookAndFeelUtil.isAquaLAF())
        panel.setOpaque(false);
    return panel;
}
Also used : JPanel(javax.swing.JPanel) PropertyChangeEvent(java.beans.PropertyChangeEvent) PostAnalysisFilterType(org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterType) ActionEvent(java.awt.event.ActionEvent) Color(java.awt.Color) JFormattedTextField(javax.swing.JFormattedTextField) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) FilterMetric(org.baderlab.csplugins.enrichmentmap.task.postanalysis.FilterMetric) LoadSignatureSetsActionListener(org.baderlab.csplugins.enrichmentmap.actions.LoadSignatureSetsActionListener) GroupLayout(javax.swing.GroupLayout) File(java.io.File)

Example 19 with JFormattedTextField

use of javax.swing.JFormattedTextField in project EnrichmentMapApp by BaderLab.

the class PostAnalysisWeightPanel method createHypergeomPanel.

private JPanel createHypergeomPanel() {
    ActionListener universeSelectActionListener = e -> {
        boolean enable = e.getActionCommand().equals("User Defined");
        universeSelectionTextField.setEnabled(enable);
    };
    gmtRadioButton = new JRadioButton();
    gmtRadioButton.setActionCommand("GMT");
    gmtRadioButton.addActionListener(universeSelectActionListener);
    gmtRadioButton.setSelected(true);
    expressionSetRadioButton = new JRadioButton();
    expressionSetRadioButton.setActionCommand("Expression Set");
    expressionSetRadioButton.addActionListener(universeSelectActionListener);
    intersectionRadioButton = new JRadioButton();
    intersectionRadioButton.setActionCommand("Intersection");
    intersectionRadioButton.addActionListener(universeSelectActionListener);
    userDefinedRadioButton = new JRadioButton("User Defined:");
    userDefinedRadioButton.setActionCommand("User Defined");
    userDefinedRadioButton.addActionListener(universeSelectActionListener);
    ButtonGroup buttonGroup = new ButtonGroup();
    buttonGroup.add(gmtRadioButton);
    buttonGroup.add(expressionSetRadioButton);
    buttonGroup.add(intersectionRadioButton);
    buttonGroup.add(userDefinedRadioButton);
    DecimalFormat intFormat = new DecimalFormat();
    intFormat.setParseIntegerOnly(true);
    universeSelectionTextField = new JFormattedTextField(intFormat);
    universeSelectionTextField.addPropertyChangeListener("value", e -> {
        Number val = (Number) universeSelectionTextField.getValue();
        if (val == null || val.intValue() < 0) {
            universeSelectionTextField.setValue(1);
            CySwingApplication application = serviceRegistrar.getService(CySwingApplication.class);
            JOptionPane.showMessageDialog(application.getJFrame(), "Universe value must be greater than zero", "Parameter out of bounds", JOptionPane.WARNING_MESSAGE);
        }
    });
    universeSelectionTextField.setEnabled(false);
    gmtRadioButton.setText("GMT");
    expressionSetRadioButton.setText("Expression Set");
    intersectionRadioButton.setText("Intersection");
    universeSelectionTextField.setValue(0);
    makeSmall(gmtRadioButton, expressionSetRadioButton, intersectionRadioButton, userDefinedRadioButton, universeSelectionTextField);
    JPanel panel = new JPanel();
    panel.setBorder(LookAndFeelUtil.createTitledBorder("Advanced Hypergeometric Universe"));
    final GroupLayout layout = new GroupLayout(panel);
    panel.setLayout(layout);
    layout.setAutoCreateContainerGaps(true);
    layout.setAutoCreateGaps(!LookAndFeelUtil.isAquaLAF());
    layout.setHorizontalGroup(layout.createParallelGroup(Alignment.LEADING, true).addComponent(gmtRadioButton).addComponent(expressionSetRadioButton).addComponent(intersectionRadioButton).addGroup(layout.createSequentialGroup().addComponent(userDefinedRadioButton, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addPreferredGap(ComponentPlacement.RELATED).addComponent(universeSelectionTextField, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE)));
    layout.setVerticalGroup(layout.createSequentialGroup().addComponent(gmtRadioButton, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(expressionSetRadioButton, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(intersectionRadioButton, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addGroup(layout.createParallelGroup(Alignment.CENTER, false).addComponent(userDefinedRadioButton, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(universeSelectionTextField, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)));
    if (LookAndFeelUtil.isAquaLAF())
        panel.setOpaque(false);
    return panel;
}
Also used : Arrays(java.util.Arrays) CardLayout(java.awt.CardLayout) ActionListener(java.awt.event.ActionListener) PostAnalysisParameters(org.baderlab.csplugins.enrichmentmap.model.PostAnalysisParameters) JTextField(javax.swing.JTextField) EnrichmentMap(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap) Ranking(org.baderlab.csplugins.enrichmentmap.model.Ranking) IconManager(org.cytoscape.util.swing.IconManager) PostAnalysisFilterParameters(org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterParameters) GeneExpressionMatrix(org.baderlab.csplugins.enrichmentmap.model.GeneExpressionMatrix) Map(java.util.Map) EnablementComboBoxRenderer(org.baderlab.csplugins.enrichmentmap.view.EnablementComboBoxRenderer) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) SwingUtil.makeSmall(org.baderlab.csplugins.enrichmentmap.view.util.SwingUtil.makeSmall) JComboBox(javax.swing.JComboBox) JFrame(javax.swing.JFrame) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) DEFAULT_SIZE(javax.swing.GroupLayout.DEFAULT_SIZE) UniverseType(org.baderlab.csplugins.enrichmentmap.model.PostAnalysisParameters.UniverseType) JFormattedTextField(javax.swing.JFormattedTextField) ButtonGroup(javax.swing.ButtonGroup) DecimalFormat(java.text.DecimalFormat) ComponentPlacement(javax.swing.LayoutStyle.ComponentPlacement) JOptionPane(javax.swing.JOptionPane) JRadioButton(javax.swing.JRadioButton) PREFERRED_SIZE(javax.swing.GroupLayout.PREFERRED_SIZE) List(java.util.List) Alignment(javax.swing.GroupLayout.Alignment) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) PostAnalysisFilterType(org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterType) LookAndFeelUtil(org.cytoscape.util.swing.LookAndFeelUtil) JLabel(javax.swing.JLabel) GroupLayout(javax.swing.GroupLayout) CySwingApplication(org.cytoscape.application.swing.CySwingApplication) Optional(java.util.Optional) Collections(java.util.Collections) JPanel(javax.swing.JPanel) JPanel(javax.swing.JPanel) JRadioButton(javax.swing.JRadioButton) ActionListener(java.awt.event.ActionListener) ButtonGroup(javax.swing.ButtonGroup) CySwingApplication(org.cytoscape.application.swing.CySwingApplication) DecimalFormat(java.text.DecimalFormat) JFormattedTextField(javax.swing.JFormattedTextField) GroupLayout(javax.swing.GroupLayout)

Example 20 with JFormattedTextField

use of javax.swing.JFormattedTextField in project EnrichmentMapApp by BaderLab.

the class SliderBarPanel method getTextField.

public JFormattedTextField getTextField() {
    if (textField == null) {
        textField = new JFormattedTextField(format) {

            @Override
            public Dimension getPreferredSize() {
                final Dimension d = super.getPreferredSize();
                if (this.getGraphics() != null) {
                    // Set the preferred text field size after it gets a Graphics
                    int sw = 16 + this.getGraphics().getFontMetrics().stringWidth(format.format(max));
                    d.width = Math.max(sw, 48);
                }
                return d;
            }
        };
        textField.setHorizontalAlignment(JTextField.RIGHT);
        textField.addActionListener(evt -> {
            textFieldValueChanged();
        });
        textField.addFocusListener(new FocusAdapter() {

            @Override
            public void focusLost(FocusEvent e) {
                textFieldValueChanged();
            }
        });
    }
    return textField;
}
Also used : FocusAdapter(java.awt.event.FocusAdapter) JFormattedTextField(javax.swing.JFormattedTextField) Dimension(java.awt.Dimension) FocusEvent(java.awt.event.FocusEvent)

Aggregations

JFormattedTextField (javax.swing.JFormattedTextField)55 JLabel (javax.swing.JLabel)17 JPanel (javax.swing.JPanel)16 ParseException (java.text.ParseException)10 DecimalFormat (java.text.DecimalFormat)9 JButton (javax.swing.JButton)9 ActionListener (java.awt.event.ActionListener)8 NumberFormatter (javax.swing.text.NumberFormatter)8 ActionEvent (java.awt.event.ActionEvent)7 PropertyChangeEvent (java.beans.PropertyChangeEvent)7 JComboBox (javax.swing.JComboBox)7 Dimension (java.awt.Dimension)6 PropertyChangeListener (java.beans.PropertyChangeListener)6 GroupLayout (javax.swing.GroupLayout)6 Component (java.awt.Component)5 GridBagConstraints (java.awt.GridBagConstraints)5 GridBagLayout (java.awt.GridBagLayout)5 JCheckBox (javax.swing.JCheckBox)5 JScrollPane (javax.swing.JScrollPane)5 JSpinner (javax.swing.JSpinner)5