Example usage for javax.swing JComponent setEnabled

List of usage examples for javax.swing JComponent setEnabled

Introduction

In this page you can find the example usage for javax.swing JComponent setEnabled.

Prototype

@BeanProperty(expert = true, preferred = true, visualUpdate = true, description = "The enabled state of the component.")
public void setEnabled(boolean enabled) 

Source Link

Document

Sets whether or not this component is enabled.

Usage

From source file:edu.ku.brc.specify.config.init.MasterUserPanel.java

/**
 * @param enable/*from  w  ww  .j a  va 2 s  . co  m*/
 */
protected void setUIEnabled(final boolean enable) {
    for (JComponent c : compList) {
        c.setEnabled(enable);
    }
    createMUBtn.setEnabled(enable);
}

From source file:mendeley2kindle.MainUIFrame.java

private void fireEnableComponents() {
    for (JComponent c : components)
        c.setEnabled(true);
    int[] indices = new int[collectionsJList.getModel().getSize()];
    for (int i = 0; i < collectionsJList.getModel().getSize(); i++)
        indices[i] = i;/*from   w  w w  .  j  a v  a2s  . co  m*/
    collectionsJList.setSelectedIndices(indices);
}

From source file:mendeley2kindle.MainUIFrame.java

public MainUIFrame(Properties config, Mendeley2Kindle core) {
    super("Mendeley2Kindle");
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    this.core = core;
    core.addStateListener(new UISyncStateListener());

    components = new ArrayList<JComponent>();

    JMenuBar menuBar = new JMenuBar();
    JMenu fileMenu = new JMenu("File");
    JMenuItem openMenuItem = new JMenuItem("Open Mendeley database");
    openMenuItem.addActionListener(new OpenMendeleyListener());
    JMenuItem selectKindleMenuItem = new JMenuItem("Select Kindle device path");
    selectKindleMenuItem.addActionListener(new SelectKindleListener());
    JMenuItem exitMenuItem = new JMenuItem("Quit");
    exitMenuItem.addActionListener(new QuitListener());
    fileMenu.add(openMenuItem);//from   w w  w .  j ava 2s . com
    fileMenu.add(selectKindleMenuItem);
    fileMenu.add(exitMenuItem);
    menuBar.add(fileMenu);

    JMenu helpMenu = new JMenu("Help");
    JMenuItem aboutMenuItem = new JMenuItem("About");
    aboutMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String text = "Mendeley2Kindle 0.3.2\n"
                    + " (c) Copyright Yukinari Toyota, 2013. All rights reserved.\n"
                    + " Contact: Yukinari Toyota <xxseyxx@gmail.com>\n"
                    + " Site: http://sites.google.com/site/xxseyxx/\n" + "Some Icons by Yusuke Kamiyamane\n"
                    + " Site: http://p.yusukekamiyamane.com/\n"
                    + "sqlite-jdbc-3.7.2.jar is provided by xerial.org\n"
                    + " under Apache License version 2.0 (http://www.apache.org/licenses/ )\n"
                    + " Site: https://bitbucket.org/xerial/sqlite-jdbc\n";
            JOptionPane.showMessageDialog(MainUIFrame.this, text);
        }
    });
    helpMenu.add(aboutMenuItem);
    menuBar.add(helpMenu);

    setJMenuBar(menuBar);

    getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));

    getContentPane().add(new JLabel("Select Mendeley collections"));

    collectionsJList = new JList();
    DragSelectionListener mil = new DragSelectionListener();
    collectionsJList.addMouseMotionListener(mil);
    collectionsJList.addMouseListener(mil);
    collectionsJList.setCellRenderer(new MyCellRenderer());
    // collectionsJList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    JScrollPane scroll = new JScrollPane();
    scroll.setPreferredSize(new Dimension(200, 300));
    scroll.getViewport().setView(collectionsJList);
    getContentPane().add(scroll);

    mainButton = new JButton("Open Mendeley database");
    mainButton.addActionListener(new OpenMendeleyListener());
    getContentPane().add(mainButton);

    components.add(collectionsJList);

    for (JComponent c : components)
        c.setEnabled(false);

    pack();
}

From source file:krasa.formatter.plugin.ProjectSettingsForm.java

private void enabledBy(@NotNull JComponent[] targets, @NotNull JToggleButton... control) {
    boolean b = true;
    for (JToggleButton jToggleButton : control) {
        b = b && (jToggleButton.isEnabled() && jToggleButton.isSelected());
    }/* w  ww .ja  v  a 2 s .  c  o m*/
    for (JComponent target : targets) {
        target.setEnabled(b);
    }
}

From source file:krasa.formatter.plugin.ProjectSettingsForm.java

private void enabledByAny(@NotNull JComponent[] targets, @NotNull JToggleButton... control) {
    boolean b = false;
    for (JToggleButton jToggleButton : control) {
        b = b || (jToggleButton.isEnabled() && jToggleButton.isSelected());
    }/*from   w w w  .  j  a  v a2s .  co m*/
    for (JComponent target : targets) {
        target.setEnabled(b);
    }
}

From source file:net.sf.mzmine.chartbasics.graphicsexport.GraphicsExportDialog.java

/**
 * Create the dialog./*from   w  w w .  j  av  a 2  s  .  c  o  m*/
 */
public GraphicsExportDialog() {
    final JFrame thisframe = this;
    //
    parameters = new GraphicsExportParameters();
    chartParam = new ChartThemeParameters();
    parametersAndComponents = new HashMap<String, JComponent>();

    String[] formats = parameters.getParameter(GraphicsExportParameters.exportFormat).getChoices();
    chooser.addChoosableFileFilter(new FileTypeFilter(formats, "Export images"));
    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    //
    setBounds(100, 100, 808, 795);
    getContentPane().setLayout(new BorderLayout());
    contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    getContentPane().add(contentPanel, BorderLayout.CENTER);
    contentPanel.setLayout(new MigLayout("", "[][][grow]", "[][][][grow]"));
    {
        StringParameter p = parameters.getParameter(GraphicsExportParameters.path);
        StringComponent txtPath = p.createEditingComponent();
        contentPanel.add(txtPath, "flowx,cell 0 0,growx");
        parametersAndComponents.put(p.getName(), txtPath);
    }
    {
        btnPath = new JButton("Path");
        btnPath.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                choosePath();
            }
        });
        contentPanel.add(btnPath, "cell 1 0");
    }
    {
        StringParameter p = parameters.getParameter(GraphicsExportParameters.filename);
        StringComponent txtFileName = p.createEditingComponent();
        contentPanel.add(txtFileName, "cell 0 1,growx");
        parametersAndComponents.put(p.getName(), txtFileName);
    }
    {
        JLabel lblFilename = new JLabel("filename");
        contentPanel.add(lblFilename, "cell 1 1");
    }
    {
        JPanel pnSettingsLeft = new JPanel();
        pnSettingsLeft.setMinimumSize(new Dimension(260, 260));
        contentPanel.add(pnSettingsLeft, "cell 0 3,grow");
        pnSettingsLeft.setLayout(new BorderLayout(0, 0));
        {

            GridBagPanel pn = new GridBagPanel();
            {
                // add unit
                UserParameter p;
                JComponent comp;
                // add unit
                p = (UserParameter) parameters.getParameter(GraphicsExportParameters.unit);
                comp = p.createEditingComponent();
                comp.setToolTipText(p.getDescription());
                comp.setEnabled(true);
                pn.add(comp, 2, 2);
                parametersAndComponents.put(p.getName(), comp);

                int i = 0;
                // add export settings
                Parameter[] param = parameters.getParameters();
                for (int pi = 3; pi < param.length; pi++) {
                    p = (UserParameter) param[pi];
                    comp = p.createEditingComponent();
                    comp.setToolTipText(p.getDescription());
                    comp.setEnabled(true);
                    pn.add(new JLabel(p.getName()), 0, i);
                    pn.add(comp, 1, i, 1, 1, 1, 1);
                    // add to map
                    parametersAndComponents.put(p.getName(), comp);
                    i++;
                }

                // add separator
                pn.add(new JSeparator(), 0, i, 5, 1, 1, 1, GridBagConstraints.BOTH);
                i++;
                // add Apply theme button
                JButton btnApply2 = new JButton("Apply theme");
                btnApply2.addActionListener(e -> applyTheme());
                pn.add(btnApply2, 0, i, 5, 1, 1, 1, GridBagConstraints.BOTH);
                i++;

                // add chart settings
                param = chartParam.getParameters();
                for (int pi = 0; pi < param.length; pi++) {
                    p = (UserParameter) param[pi];
                    comp = p.createEditingComponent();
                    comp.setToolTipText(p.getDescription());
                    comp.setEnabled(true);
                    pn.add(new JLabel(p.getName()), 0, i);
                    pn.add(comp, 1, i, 4, 1);
                    // add to map
                    parametersAndComponents.put(p.getName(), comp);
                    i++;
                }

                // add listener to master font
                JFontSpecs master = (JFontSpecs) parametersAndComponents
                        .get(chartParam.getParameter(ChartThemeParameters.masterFont).getName());
                master.addListener(fspec -> {
                    if (listenersEnabled)
                        handleMasterFontChanged(fspec);
                });
            }

            JScrollPane scrollPane = new JScrollPane(pn);
            scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
            pnSettingsLeft.add(scrollPane, BorderLayout.CENTER);
            scrollPane.getVerticalScrollBar().setUnitIncrement(18);
            scrollPane.revalidate();
            scrollPane.repaint();
        }
    }
    {
        {
            pnChartPreview = new JPanel();
            pnChartPreview.setLayout(null);
            contentPanel.add(pnChartPreview, "cell 1 3 2 1,grow");
        }
    }
    {
        JPanel buttonPane = new JPanel();
        buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
        getContentPane().add(buttonPane, BorderLayout.SOUTH);
        {
            JButton okButton = new JButton("Save");
            okButton.addActionListener(e -> saveGraphicsAs());
            okButton.setActionCommand("OK");
            buttonPane.add(okButton);
            getRootPane().setDefaultButton(okButton);
        }
        {
            btnRenewPreview = new JButton("Renew Preview");
            btnRenewPreview.addActionListener(e -> renewPreview());
            buttonPane.add(btnRenewPreview);
        }
        {
            btnApply = new JButton("Apply theme");
            btnApply.addActionListener(e -> applyTheme());
            buttonPane.add(btnApply);
        }
        {
            JButton cancelButton = new JButton("Cancel");
            cancelButton.addActionListener(e -> setVisible(false));
            cancelButton.setActionCommand("Cancel");
            buttonPane.add(cancelButton);
        }
    }
    // set all to components
    updateComponentsFromParameters();
}

From source file:krasa.formatter.plugin.ProjectSettingsForm.java

private void enabledByAny(@NotNull JComponent[] targets, @NotNull JToggleButton[] negated,
        @NotNull JToggleButton... control) {
    boolean b = false;

    for (JToggleButton jToggleButton : control) {
        b = b || (jToggleButton.isEnabled() && jToggleButton.isSelected());
    }//from www .  j a  v a2s .  c  om
    for (JToggleButton jToggleButton : negated) {
        b = b || (jToggleButton.isEnabled() && !jToggleButton.isSelected());
    }

    for (JComponent target : targets) {
        target.setEnabled(b);
    }
}

From source file:com.eviware.soapui.support.components.SimpleForm.java

public void setEnabled(boolean b) {
    for (JComponent component : components.values()) {
        if (component instanceof JScrollPane) {
            ((JScrollPane) component).getViewport().getView().setEnabled(b);
        }//from  w  w w.j  a v  a 2 s .com

        component.setEnabled(b);
    }
}

From source file:com.lottery.gui.MainLotteryForm.java

private void setPanelEnabled(JPanel panel, Boolean isEnabled) {
    panel.setEnabled(isEnabled);//from   w w  w .j a  v  a2  s.  com

    for (int i = 0; i < panel.getComponents().length; i++) {
        JComponent component = (JComponent) panel.getComponents()[i];
        if (component.getClass().getName() == "javax.swing.JPanel") {
            setPanelEnabled((JPanel) component, isEnabled);
        }

        component.setEnabled(isEnabled);
    }
}

From source file:com.diversityarrays.kdxplore.trials.SampleGroupExportDialog.java

public SampleGroupExportDialog(Window owner, String title, Trial trial, KdxploreDatabase kdxploreDatabase,
        DeviceType deviceType, DeviceIdentifier devid, SampleGroup sampleGroup,
        Set<Integer> excludeTheseTraitIds, Map<Integer, Trait> allTraitIds, Set<Integer> excludeThesePlotIds) {
    super(owner, title, ModalityType.APPLICATION_MODAL);

    setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    setGlassPane(backgroundRunner.getBlockingPane());

    this.allTraits = allTraitIds;
    this.trial = trial;
    this.kdxploreDatabase = kdxploreDatabase;
    this.sampleGroup = sampleGroup;
    this.excludeTheseTraitIds = excludeTheseTraitIds;
    this.excludeThesePlotIds = excludeThesePlotIds;

    String deviceName = devid == null ? "Unknown_" + deviceType.name() : devid.getDeviceName();

    if (DeviceType.FOR_SCORING.equals(deviceType)) {
        if (!Check.isEmpty(sampleGroup.getOperatorName())) {
            deviceName = sampleGroup.getOperatorName();
        }//from w  ww. ja  v a2  s.  co m
    }

    File directory = KdxplorePreferences.getInstance().getOutputDirectory();
    if (directory == null) {
        directory = new File(System.getProperty("user.home"));
    }
    String filename = Util.getTimestampedOutputFileName(trial.getTrialName(), deviceName);

    File outfile = new File(directory, filename);

    filepathText.setText(outfile.getPath());

    filepathText.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent e) {
            updateButtons();
        }

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

        @Override
        public void changedUpdate(DocumentEvent e) {
            updateButtons();
        }
    });
    updateButtons();

    boolean developer = RunMode.getRunMode().isDeveloper();
    oldKdsmartOption.setForeground(Color.BLUE);
    oldKdsmartOption.setToolTipText("For ElapsedDays value compatiblity with older versions of KDSmart");

    Box exportForOptionsBox = Box.createHorizontalBox();
    for (JComponent comp : exportForOptions) {
        if (developer || comp != oldKdsmartOption) {
            exportForOptionsBox.add(comp);
        }
    }

    Map<JRadioButton, OutputOption> optionByRb = new HashMap<>();
    ActionListener rbListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            selectedOutputOption = optionByRb.get(e.getSource());
            boolean enb = selectedOutputOption.exportFor != null;
            for (JComponent comp : exportForOptions) {
                if (comp == wantMediaFilesOption) {
                    comp.setEnabled(enb && selectedOutputOption.supportsMediaFiles());
                } else if (comp == kdsmartVersion3option) {
                    comp.setEnabled(enb && selectedOutputOption.usesWorkPackage());
                } else {
                    comp.setEnabled(enb);
                }
            }
        }
    };

    boolean anySamplesForIndividuals = true;
    try {
        anySamplesForIndividuals = kdxploreDatabase.getAnySamplesForIndividuals(sampleGroup);
    } catch (IOException e) {
        Shared.Log.w("SampleGroupExportDialog", "getAnySamplesForIndividuals", e);
    }

    ButtonGroup bg = new ButtonGroup();
    Box radioButtons = Box.createHorizontalBox();

    List<OutputOption> options = new ArrayList<>();
    Collections.addAll(options, OutputOption.values());

    if (!anySamplesForIndividuals) {
        // No relevant samples so don't bother offering the option.
        options.remove(OutputOption.CSV_FULL);
    }

    for (OutputOption oo : options) {
        if (!developer && OutputOption.JSON == oo) {
            continue;
        }

        JRadioButton rb = new JRadioButton(oo.displayName);
        if (OutputOption.KDX == oo) {
            kdxExportButton = rb;
        }

        if (OutputOption.ZIP == oo) {
            zipExportButton = rb;
        }

        rb.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                exportExclusionBox.selectAndDeactivateButtons(
                        kdxExportButton.isSelected() || zipExportButton.isSelected());
            }
        });

        if (OutputOption.JSON == oo) {
            rb.setForeground(Color.BLUE);
            rb.setToolTipText("Developer Only");
        }
        bg.add(rb);
        optionByRb.put(rb, oo);
        radioButtons.add(rb);
        rb.addActionListener(rbListener);
        if (bg.getButtonCount() == 1) {
            rb.doClick();
        }
    }

    Box additionalOptionsBox = Box.createHorizontalBox();
    additionalOptionsBox.add(this.wantMediaFilesOption);
    additionalOptionsBox.add(this.kdsmartVersion3option);

    dbVersionLabel.setToolTipText(TTT_DATABASE_VERSION_FOR_EXPORT);
    databaseVersionChoices.setToolTipText(TTT_DATABASE_VERSION_FOR_EXPORT);

    JPanel panel = new JPanel();
    GBH gbh = new GBH(panel);
    int y = 0;

    gbh.add(0, y, 1, 1, GBH.NONE, 0, 1, GBH.EAST, "Output File:");
    gbh.add(1, y, 1, 1, GBH.HORZ, 1, 1, GBH.CENTER, filepathText);
    gbh.add(2, y, 1, 1, GBH.NONE, 1, 1, GBH.WEST, new JButton(browseFileAction));
    ++y;

    gbh.add(0, y, 1, 1, GBH.NONE, 0, 1, GBH.EAST, "Options:");
    gbh.add(1, y, 2, 1, GBH.HORZ, 1, 1, GBH.CENTER, radioButtons);
    ++y;

    gbh.add(0, y, 3, 1, GBH.HORZ, 1, 1, GBH.CENTER, exportExclusionBox);
    ++y;

    gbh.add(0, y, 3, 1, GBH.HORZ, 1, 1, GBH.CENTER, additionalOptionsBox);
    ++y;

    gbh.add(0, y, 1, 1, GBH.NONE, 0, 1, GBH.EAST, dbVersionLabel);
    gbh.add(1, y, 2, 1, GBH.HORZ, 1, 1, GBH.CENTER, BoxBuilder.horizontal().add(databaseVersionChoices).get());

    gbh.add(1, y, 2, 1, GBH.HORZ, 1, 1, GBH.CENTER, exportForOptionsBox);
    ++y;

    Box buttons = Box.createHorizontalBox();
    buttons.add(Box.createHorizontalGlue());
    buttons.add(new JButton(cancelAction));
    buttons.add(new JButton(exportAction));
    buttons.add(new JButton(exportAndCloseAction));

    Container cp = getContentPane();

    cp.add(panel, BorderLayout.CENTER);
    cp.add(buttons, BorderLayout.SOUTH);

    pack();
}