Example usage for javax.swing JCheckBox JCheckBox

List of usage examples for javax.swing JCheckBox JCheckBox

Introduction

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

Prototype

public JCheckBox(Action a) 

Source Link

Document

Creates a check box where properties are taken from the Action supplied.

Usage

From source file:net.sf.jabref.gui.preftabs.AppearancePrefsTab.java

/**
 * Customization of appearance parameters.
 *
 * @param prefs a <code>JabRefPreferences</code> value
 *///w  w w. j  ava 2 s . c  om
public AppearancePrefsTab(JabRefPreferences prefs) {
    this.prefs = prefs;
    setLayout(new BorderLayout());

    // Font sizes:
    fontSize = new JTextField(5);

    // Row padding size:
    rowPadding = new JTextField(5);

    colorCodes = new JCheckBox(Localization.lang("Color codes for required and optional fields"));

    overrideFonts = new JCheckBox(Localization.lang("Override default font settings"));

    showGrid = new JCheckBox(Localization.lang("Show gridlines"));

    FormLayout layout = new FormLayout(
            "1dlu, 8dlu, left:pref, 4dlu, fill:pref, 4dlu, fill:60dlu, 4dlu, fill:pref", "");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);

    customLAF = new JCheckBox(Localization.lang("Use other look and feel"));
    // Only list L&F which are available
    List<String> lookAndFeels = LookAndFeel.getAvailableLookAndFeels();
    classNamesLAF = new JComboBox<>(lookAndFeels.toArray(new String[lookAndFeels.size()]));
    classNamesLAF.setEditable(true);
    final JComboBox<String> clName = classNamesLAF;
    customLAF.addChangeListener(e -> clName.setEnabled(((JCheckBox) e.getSource()).isSelected()));

    // only the default L&F shows the the OSX specific first dropdownmenu
    if (!OS.OS_X) {
        JPanel pan = new JPanel();
        builder.appendSeparator(Localization.lang("Look and feel"));
        JLabel lab = new JLabel(
                Localization.lang("Default look and feel") + ": " + UIManager.getSystemLookAndFeelClassName());
        builder.nextLine();
        builder.append(pan);
        builder.append(lab);
        builder.nextLine();
        builder.append(pan);
        builder.append(customLAF);
        builder.nextLine();
        builder.append(pan);
        JPanel pan2 = new JPanel();
        lab = new JLabel(Localization.lang("Class name") + ':');
        pan2.add(lab);
        pan2.add(classNamesLAF);
        builder.append(pan2);
        builder.nextLine();
        builder.append(pan);
        lab = new JLabel(Localization
                .lang("Note that you must specify the fully qualified class name for the look and feel,"));
        builder.append(lab);
        builder.nextLine();
        builder.append(pan);
        lab = new JLabel(Localization
                .lang("and the class must be available in your classpath next time you start JabRef."));
        builder.append(lab);
        builder.nextLine();
    }

    builder.leadingColumnOffset(2);
    JLabel lab;
    builder.appendSeparator(Localization.lang("General"));
    JPanel p1 = new JPanel();
    lab = new JLabel(Localization.lang("Menu and label font size") + ":");
    p1.add(lab);
    p1.add(fontSize);
    builder.append(p1);
    builder.nextLine();
    builder.append(overrideFonts);
    builder.nextLine();
    builder.appendSeparator(Localization.lang("Table appearance"));
    JPanel p2 = new JPanel();
    p2.add(new JLabel(Localization.lang("Table row height padding") + ":"));
    p2.add(rowPadding);
    builder.append(p2);
    builder.nextLine();
    builder.append(colorCodes);
    builder.nextLine();
    builder.append(showGrid);
    builder.nextLine();
    JButton fontButton = new JButton(Localization.lang("Set table font"));
    builder.append(fontButton);
    builder.nextLine();
    builder.appendSeparator(Localization.lang("Table and entry editor colors"));
    builder.append(colorPanel);

    JPanel upper = new JPanel();
    JPanel sort = new JPanel();
    JPanel namesp = new JPanel();
    JPanel iconCol = new JPanel();
    GridBagLayout gbl = new GridBagLayout();
    upper.setLayout(gbl);
    sort.setLayout(gbl);
    namesp.setLayout(gbl);
    iconCol.setLayout(gbl);

    overrideFonts.addActionListener(e -> fontSize.setEnabled(overrideFonts.isSelected()));

    fontButton.addActionListener(e -> new FontSelectorDialog(null, GUIGlobals.currentFont).getSelectedFont()
            .ifPresent(x -> usedFont = x));

    JPanel pan = builder.getPanel();
    pan.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    add(pan, BorderLayout.CENTER);
}

From source file:EditorPaneExample13.java

public EditorPaneExample13() {
    super("JEditorPane Example 13");

    pane = new JEditorPane();
    pane.setEditable(false); // Read-only
    getContentPane().add(new JScrollPane(pane), "Center");

    // Build the panel of controls
    JPanel panel = new JPanel();

    panel.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.gridwidth = 1;/*from   ww w .  jav a2s  .  c o m*/
    c.gridheight = 1;
    c.anchor = GridBagConstraints.EAST;
    c.fill = GridBagConstraints.NONE;
    c.weightx = 0.0;
    c.weighty = 0.0;

    JLabel urlLabel = new JLabel("URL: ", JLabel.RIGHT);
    panel.add(urlLabel, c);
    JLabel loadingLabel = new JLabel("State: ", JLabel.RIGHT);
    c.gridy = 1;
    panel.add(loadingLabel, c);
    JLabel typeLabel = new JLabel("Type: ", JLabel.RIGHT);
    c.gridy = 2;
    panel.add(typeLabel, c);
    c.gridy = 3;
    panel.add(new JLabel(LOAD_TIME), c);

    c.gridy = 4;
    c.gridwidth = 2;
    c.weightx = 1.0;
    c.anchor = GridBagConstraints.WEST;
    onlineLoad = new JCheckBox("Online Load");
    panel.add(onlineLoad, c);
    onlineLoad.setSelected(true);
    onlineLoad.setForeground(typeLabel.getForeground());

    c.gridx = 1;
    c.gridy = 0;
    c.anchor = GridBagConstraints.EAST;
    c.fill = GridBagConstraints.HORIZONTAL;

    urlCombo = new JComboBox();
    panel.add(urlCombo, c);
    urlCombo.setEditable(true);
    loadingState = new JLabel(spaces, JLabel.LEFT);
    loadingState.setForeground(Color.black);
    c.gridy = 1;
    panel.add(loadingState, c);
    loadedType = new JLabel(spaces, JLabel.LEFT);
    loadedType.setForeground(Color.black);
    c.gridy = 2;
    panel.add(loadedType, c);
    timeLabel = new JLabel("");
    c.gridy = 3;
    panel.add(timeLabel, c);

    getContentPane().add(panel, "South");

    // Load a new default style sheet
    InputStream is = EditorPaneExample13.class.getResourceAsStream("changedDefault.css");
    if (is != null) {
        try {
            StyleSheet ss = loadStyleSheet(is);
            editorKit.setStyleSheet(ss);
        } catch (IOException e) {
            System.out.println("Failed to load new default style sheet");
        }
    }

    // Allocate the empty tree model
    DefaultMutableTreeNode emptyRootNode = new DefaultMutableTreeNode("Empty");
    emptyModel = new DefaultTreeModel(emptyRootNode);

    // Create and place the heading tree
    tree = new JTree(emptyModel);
    tree.setPreferredSize(new Dimension(200, 200));
    getContentPane().add(new JScrollPane(tree), "East");

    // Change page based on combo selection
    urlCombo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            if (populatingCombo == true) {
                return;
            }
            Object selection = urlCombo.getSelectedItem();
            loadNewPage(selection);
        }
    });

    // Listen for page load to complete
    pane.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName().equals("page")) {
                loadComplete();
                displayLoadTime();
                populateCombo(findLinks(pane.getDocument(), null));
                TreeNode node = buildHeadingTree(pane.getDocument());
                tree.setModel(new DefaultTreeModel(node));
                enableInput();
                loadingPage = false;
            }
        }
    });

    // Listener for tree selection
    tree.addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent evt) {
            TreePath path = evt.getNewLeadSelectionPath();
            if (path != null) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
                Object userObject = node.getUserObject();
                if (userObject instanceof Heading) {
                    Heading heading = (Heading) userObject;
                    try {
                        Rectangle textRect = pane.modelToView(heading.getOffset());
                        textRect.y += 3 * textRect.height;
                        pane.scrollRectToVisible(textRect);
                    } catch (BadLocationException e) {
                    }
                }
            }
        }
    });

    // Listener for hypertext events
    pane.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent evt) {
            // Ignore hyperlink events if the frame is busy
            if (loadingPage == true) {
                return;
            }
            if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                JEditorPane sp = (JEditorPane) evt.getSource();
                if (evt instanceof HTMLFrameHyperlinkEvent) {
                    HTMLDocument doc = (HTMLDocument) sp.getDocument();
                    doc.processHTMLFrameHyperlinkEvent((HTMLFrameHyperlinkEvent) evt);
                } else {
                    loadNewPage(evt.getURL());
                }
            } else if (evt.getEventType() == HyperlinkEvent.EventType.ENTERED) {
                pane.setCursor(handCursor);
            } else if (evt.getEventType() == HyperlinkEvent.EventType.EXITED) {
                pane.setCursor(defaultCursor);
            }
        }
    });
}

From source file:EditorPaneExample14.java

public EditorPaneExample14() {
    super("JEditorPane Example 14");

    pane = new JEditorPane();
    pane.setEditable(false); // Read-only
    getContentPane().add(new JScrollPane(pane), "Center");

    // Build the panel of controls
    JPanel panel = new JPanel();

    panel.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.gridwidth = 1;//from  ww w .j  ava  2 s.  co m
    c.gridheight = 1;
    c.anchor = GridBagConstraints.EAST;
    c.fill = GridBagConstraints.NONE;
    c.weightx = 0.0;
    c.weighty = 0.0;

    JLabel urlLabel = new JLabel("URL: ", JLabel.RIGHT);
    panel.add(urlLabel, c);
    JLabel loadingLabel = new JLabel("State: ", JLabel.RIGHT);
    c.gridy = 1;
    panel.add(loadingLabel, c);
    JLabel typeLabel = new JLabel("Type: ", JLabel.RIGHT);
    c.gridy = 2;
    panel.add(typeLabel, c);
    c.gridy = 3;
    panel.add(new JLabel(LOAD_TIME), c);

    c.gridy = 4;
    c.gridwidth = 2;
    c.weightx = 1.0;
    c.anchor = GridBagConstraints.WEST;
    onlineLoad = new JCheckBox("Online Load");
    panel.add(onlineLoad, c);
    onlineLoad.setSelected(true);
    onlineLoad.setForeground(typeLabel.getForeground());

    c.gridx = 1;
    c.gridy = 0;
    c.anchor = GridBagConstraints.EAST;
    c.fill = GridBagConstraints.HORIZONTAL;

    urlCombo = new JComboBox();
    panel.add(urlCombo, c);
    urlCombo.setEditable(true);
    loadingState = new JLabel(spaces, JLabel.LEFT);
    loadingState.setForeground(Color.black);
    c.gridy = 1;
    panel.add(loadingState, c);
    loadedType = new JLabel(spaces, JLabel.LEFT);
    loadedType.setForeground(Color.black);
    c.gridy = 2;
    panel.add(loadedType, c);
    timeLabel = new JLabel("");
    c.gridy = 3;
    panel.add(timeLabel, c);

    getContentPane().add(panel, "South");

    // Modify the default style sheet
    InputStream is = EditorPaneExample14.class.getResourceAsStream("changedDefault.css");
    if (is != null) {
        try {
            addToStyleSheet(editorKit.getStyleSheet(), is);
        } catch (IOException e) {
            System.out.println("Failed to modify default style sheet");
        }
    }

    // Allocate the empty tree model
    DefaultMutableTreeNode emptyRootNode = new DefaultMutableTreeNode("Empty");
    emptyModel = new DefaultTreeModel(emptyRootNode);

    // Create and place the heading tree
    tree = new JTree(emptyModel);
    tree.setPreferredSize(new Dimension(200, 200));
    getContentPane().add(new JScrollPane(tree), "East");

    // Change page based on combo selection
    urlCombo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            if (populatingCombo == true) {
                return;
            }
            Object selection = urlCombo.getSelectedItem();
            loadNewPage(selection);
        }
    });

    // Listen for page load to complete
    pane.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName().equals("page")) {
                loadComplete();
                displayLoadTime();
                populateCombo(findLinks(pane.getDocument(), null));
                TreeNode node = buildHeadingTree(pane.getDocument());
                tree.setModel(new DefaultTreeModel(node));
                enableInput();
                loadingPage = false;
            }
        }
    });

    // Listener for tree selection
    tree.addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent evt) {
            TreePath path = evt.getNewLeadSelectionPath();
            if (path != null) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
                Object userObject = node.getUserObject();
                if (userObject instanceof Heading) {
                    Heading heading = (Heading) userObject;
                    try {
                        Rectangle textRect = pane.modelToView(heading.getOffset());
                        textRect.y += 3 * textRect.height;
                        pane.scrollRectToVisible(textRect);
                    } catch (BadLocationException e) {
                    }
                }
            }
        }
    });

    // Listener for hypertext events
    pane.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent evt) {
            // Ignore hyperlink events if the frame is busy
            if (loadingPage == true) {
                return;
            }
            if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                JEditorPane sp = (JEditorPane) evt.getSource();
                if (evt instanceof HTMLFrameHyperlinkEvent) {
                    HTMLDocument doc = (HTMLDocument) sp.getDocument();
                    doc.processHTMLFrameHyperlinkEvent((HTMLFrameHyperlinkEvent) evt);
                } else {
                    loadNewPage(evt.getURL());
                }
            } else if (evt.getEventType() == HyperlinkEvent.EventType.ENTERED) {
                pane.setCursor(handCursor);
            } else if (evt.getEventType() == HyperlinkEvent.EventType.EXITED) {
                pane.setCursor(defaultCursor);
            }
        }
    });
}

From source file:com.xtructure.xevolution.gui.components.CollectArgsDialog.java

/**
 * Creates a new {@link CollectArgsDialog}
 * //from   w  w  w .  j a  va 2s. co  m
 * @param frame
 *            the parent JFrame for the new {@link CollectArgsDialog}
 * @param statusBar
 *            the {@link StatusBar} to update (can be null)
 * @param title
 *            the title of the new {@link CollectArgsDialog}
 * @param xOptions
 *            the {@link Collection} of {@link XOption}s for which to
 *            collect user input
 */
public CollectArgsDialog(JFrame frame, final StatusBar statusBar, String title,
        final Collection<XOption<?>> xOptions) {
    super(frame, title, true);

    argComponents = new ArrayList<JComponent>();

    final CollectArgsDialog dialog = this;
    JPanel panel = new JPanel(new GridBagLayout());
    getContentPane().add(panel);
    GridBagConstraints c = new GridBagConstraints();
    c.insets = new Insets(3, 3, 3, 3);
    c.fill = GridBagConstraints.BOTH;

    int row = 0;
    for (XOption<?> xOption : xOptions) {
        if (xOption.getName() == null) {
            continue;
        }
        if (xOption.hasArg()) {
            JLabel label = new JLabel(xOption.getName());
            JTextField textField = new JTextField();
            textField.setName(xOption.getOpt());
            textField.setToolTipText(xOption.getDescription());
            argComponents.add(textField);
            c.gridx = 0;
            c.gridy = row;
            panel.add(label, c);
            c.gridx = 1;
            c.gridy = row;
            panel.add(textField, c);
        } else {
            JCheckBox checkBox = new JCheckBox(xOption.getName());
            checkBox.setName(xOption.getOpt());
            checkBox.setToolTipText(xOption.getDescription());
            argComponents.add(checkBox);
            c.gridx = 0;
            c.gridy = row;
            panel.add(checkBox, c);
        }
        row++;
    }

    JPanel buttonPanel = new JPanel();
    c.gridx = 1;
    c.gridy = row;
    panel.add(buttonPanel, c);

    JButton okButton = new JButton(new AbstractAction("OK") {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            dialog.setVisible(false);
            if (statusBar != null) {
                statusBar.setMessage("building args...");
            }
            ArrayList<String> args = new ArrayList<String>();
            for (JComponent component : argComponents) {
                if (component instanceof JCheckBox) {
                    JCheckBox checkbox = (JCheckBox) component;
                    String opt = checkbox.getName();
                    if (checkbox.isSelected()) {
                        args.add("-" + opt);
                    }
                }
                if (component instanceof JTextField) {
                    JTextField textField = (JTextField) component;
                    String opt = textField.getName();
                    String text = textField.getText().trim();
                    if (!text.isEmpty()) {
                        args.add("-" + opt);
                        args.add("\"" + text + "\"");
                    }
                }
            }
            if (statusBar != null) {
                statusBar.setMessage("parsing args...");
            }
            try {
                Options options = new Options();
                for (XOption<?> xOpt : xOptions) {
                    options.addOption(xOpt);
                }
                XOption.parseArgs(options, args.toArray(new String[0]));
                dialog.success = true;
            } catch (ParseException e1) {
                e1.printStackTrace();
                dialog.success = false;
            }
            if (statusBar != null) {
                statusBar.clearMessage();
            }
        }
    });
    buttonPanel.add(okButton);
    getRootPane().setDefaultButton(okButton);

    buttonPanel.add(new JButton(new AbstractAction("Cancel") {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            dialog.setVisible(false);
            if (statusBar != null) {
                statusBar.clearMessage();
            }
        }
    }));
    pack();
    setLocationRelativeTo(frame);
    setVisible(true);
}

From source file:task5.Histogram.java

private JPanel createControlPanel() {
    JPanel panel = new JPanel();
    panel.add(new JCheckBox(new VisibleAction(0)));
    panel.add(new JCheckBox(new VisibleAction(1)));
    panel.add(new JCheckBox(new VisibleAction(2)));
    return panel;
}

From source file:org.jfree.chart.demo.XYTickLabelDemo.java

/**
 * A demonstration application showing some bugs with tick labels in version 0.9.13
 *
 * @param title  the frame title.//from w w w  .  j av a  2  s . com
 */
public XYTickLabelDemo(final String title) {

    super(title);
    this.chart = createChart();
    final ChartPanel chartPanel = new ChartPanel(this.chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(600, 270));

    final JPanel mainPanel = new JPanel(new BorderLayout());
    setContentPane(mainPanel);
    mainPanel.add(chartPanel);

    final JPanel optionsPanel = new JPanel();
    mainPanel.add(optionsPanel, BorderLayout.SOUTH);

    this.symbolicAxesCheckBox = new JCheckBox("Symbolic axes");
    this.symbolicAxesCheckBox.addActionListener(this);
    optionsPanel.add(this.symbolicAxesCheckBox);

    this.verticalTickLabelsCheckBox = new JCheckBox("Tick labels vertical");
    this.verticalTickLabelsCheckBox.addActionListener(this);
    optionsPanel.add(this.verticalTickLabelsCheckBox);

    this.fontSizeTextField = new JTextField(3);
    this.fontSizeTextField.addActionListener(this);
    optionsPanel.add(new JLabel("Font size:"));
    optionsPanel.add(this.fontSizeTextField);
    final ValueAxis axis = this.chart.getXYPlot().getDomainAxis();
    this.fontSizeTextField.setText(DEFAULT_FONT_SIZE + "");

    final XYPlot plot = this.chart.getXYPlot();
    Font ft = axis.getTickLabelFont();
    ft = ft.deriveFont((float) DEFAULT_FONT_SIZE);
    plot.getDomainAxis().setTickLabelFont(ft);
    plot.getRangeAxis().setTickLabelFont(ft);
    plot.getDomainAxis(1).setTickLabelFont(ft);
    plot.getRangeAxis(1).setTickLabelFont(ft);

    this.horizontalPlotCheckBox = new JCheckBox("Plot horizontal");
    this.horizontalPlotCheckBox.addActionListener(this);
    optionsPanel.add(this.horizontalPlotCheckBox);
}

From source file:pdi.HistogramaRGB.java

private JPanel criaPainel() {
    JPanel panel = new JPanel();
    JComboBox Jbox = new JComboBox();
    JButton histEqual = new JButton("Equalizar Histograma");
    panel.add(new JCheckBox(new HistogramaRGB.exibeAcao(0)));
    panel.add(new JCheckBox(new HistogramaRGB.exibeAcao(1)));
    panel.add(new JCheckBox(new HistogramaRGB.exibeAcao(2)));
    panel.add(histEqual);/*from   w ww  . ja v  a2s .  c  o m*/
    panel.add(Jbox);
    return panel;
}

From source file:jgnash.ui.report.compiled.RunningAccountBalanceChart.java

private JPanel createPanel() {
    LocalDate end = DateUtils.getLastDayOfTheMonth(endDateField.getLocalDate());
    LocalDate start = end.minusYears(1);

    startDateField.setDate(start);//from w ww.j a  v a  2s  .co  m

    JButton refreshButton = new JButton(rb.getString("Button.Refresh"));
    refreshButton.setIcon(IconUtils.getIcon("/jgnash/resource/view-refresh.png"));

    subAccountCheckBox = new JCheckBox(rb.getString("Button.IncludeSubAccounts"));
    subAccountCheckBox.setSelected(true);

    hideLockedAccountCheckBox = new JCheckBox(rb.getString("Button.HideLockedAccount"));
    hidePlaceholderAccountCheckBox = new JCheckBox(rb.getString("Button.HidePlaceholderAccount"));

    JFreeChart chart = createVerticalXYBarChart(combo.getSelectedAccount());
    final ChartPanel chartPanel = new ChartPanel(chart);

    FormLayout layout = new FormLayout("p, 4dlu, p:g", "");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);

    FormLayout dLayout = new FormLayout("p, 4dlu, p, 8dlu, p, 4dlu, p, 8dlu, p", "");
    DefaultFormBuilder dBuilder = new DefaultFormBuilder(dLayout);

    dBuilder.append(rb.getString("Label.StartDate"), startDateField);
    dBuilder.append(rb.getString("Label.EndDate"), endDateField);
    dBuilder.append(refreshButton);

    FormLayout cbLayout = new FormLayout("p, 4dlu, p, 4dlu, p, 4dlu", "");
    DefaultFormBuilder cbBuilder = new DefaultFormBuilder(cbLayout);

    cbBuilder.append(subAccountCheckBox);
    cbBuilder.append(hideLockedAccountCheckBox);
    cbBuilder.append(hidePlaceholderAccountCheckBox);

    builder.append(rb.getString("Label.Account"), combo);
    builder.nextLine();
    builder.append(" ");
    builder.append(cbBuilder.getPanel());
    builder.nextLine();
    builder.appendRelatedComponentsGapRow();
    builder.nextLine();
    builder.append(dBuilder.getPanel(), 3);
    builder.nextLine();
    builder.appendUnrelatedComponentsGapRow();
    builder.nextLine();

    builder.appendRow(RowSpec.decode("fill:p:g"));
    builder.append(chartPanel, 3);

    final JPanel panel = builder.getPanel();

    ActionListener listener = e -> {
        updateSubAccountBox();
        Account a = combo.getSelectedAccount();
        if (a == null) {
            return;
        }
        chartPanel.setChart(createVerticalXYBarChart(a));
        panel.validate();
    };

    hideLockedAccountCheckBox.addActionListener(e -> {
        combo.setHideLocked(hideLockedAccountCheckBox.isSelected());
        updateSubAccountBox();
        Account a = combo.getSelectedAccount();
        if (a == null) {
            return;
        }
        chartPanel.setChart(createVerticalXYBarChart(a));
        panel.validate();
    });

    hidePlaceholderAccountCheckBox.addActionListener(e -> {
        combo.setHidePlaceholder(hidePlaceholderAccountCheckBox.isSelected());
        updateSubAccountBox();
        Account a = combo.getSelectedAccount();
        if (a == null) {
            return;
        }
        chartPanel.setChart(createVerticalXYBarChart(a));
        panel.validate();
    });

    updateSubAccountBox();

    combo.addActionListener(listener);
    refreshButton.addActionListener(listener);

    return panel;
}

From source file:com.mirth.connect.client.ui.dependencies.ChannelDependenciesWarningDialog.java

private void initComponents(final ChannelTask task, Set<ChannelDependency> dependencies,
        final Set<String> selectedChannelIds, Set<String> additionalChannelIds)
        throws ChannelDependencyException {
    additionalChannelIds.removeAll(selectedChannelIds);
    final OrderedChannels orderedChannels = ChannelDependencyUtil.getOrderedChannels(dependencies,
            new HashSet<String>(CollectionUtils.union(selectedChannelIds, additionalChannelIds)));
    final List<Set<String>> orderedChannelIds = orderedChannels.getOrderedIds();
    if (task.isForwardOrder()) {
        Collections.reverse(orderedChannelIds);
    }/*ww w  . j a v a  2  s.  com*/

    descriptionLabel = new JLabel(
            "<html>There are additional channels in the dependency chain.<br/><b>Bolded</b> channels will be "
                    + task.getFuturePassive() + " in the following order:</html>");

    channelsPane = new JTextPane();
    channelsPane.setContentType("text/html");
    HTMLEditorKit editorKit = new HTMLEditorKit();
    StyleSheet styleSheet = editorKit.getStyleSheet();
    styleSheet.addRule("div {font-family:\"Tahoma\";font-size:11;text-align:top}");
    channelsPane.setEditorKit(editorKit);
    channelsPane.setEditable(false);
    channelsPane.setBackground(getBackground());

    setTextPane(task, orderedChannels, orderedChannelIds, selectedChannelIds, false);

    descriptionScrollPane = new JScrollPane(channelsPane);

    includeCheckBox = new JCheckBox(WordUtils.capitalize(task.toString()) + " " + additionalChannelIds.size()
            + " additional channel" + (additionalChannelIds.size() == 1 ? "" : "s"));
    includeCheckBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            setTextPane(task, orderedChannels, orderedChannelIds, selectedChannelIds,
                    includeCheckBox.isSelected());
        }
    });

    okButton = new JButton("OK");
    okButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            result = JOptionPane.OK_OPTION;
            dispose();
        }
    });

    cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            result = JOptionPane.CANCEL_OPTION;
            dispose();
        }
    });
}

From source file:com.hexidec.ekit.component.PropertiesDialog.java

public PropertiesDialog(Window parent, String[] fields, String[] types, String[] values, String title,
        boolean bModal) {
    super(parent, title);
    setModal(bModal);//from   w w w.j  a va  2s.c  o m
    htInputFields = new Hashtable<String, JComponent>();
    final Object[] buttonLabels = { Translatrix.getTranslationString("DialogAccept"),
            Translatrix.getTranslationString("DialogCancel") };
    List<Object> panelContents = new ArrayList<Object>();
    for (int iter = 0; iter < fields.length; iter++) {
        String fieldName = fields[iter];
        String fieldType = types[iter];
        JComponent fieldComponent;
        JComponent panelComponent = null;
        if (fieldType.equals("text") || fieldType.equals("integer")) {
            fieldComponent = new JTextField(3);
            if (values[iter] != null && values[iter].length() > 0) {
                ((JTextField) (fieldComponent)).setText(values[iter]);
            }

            if (fieldType.equals("integer")) {
                ((AbstractDocument) ((JTextField) (fieldComponent)).getDocument())
                        .setDocumentFilter(new DocumentFilter() {

                            @Override
                            public void insertString(FilterBypass fb, int offset, String text,
                                    AttributeSet attrs) throws BadLocationException {
                                replace(fb, offset, 0, text, attrs);
                            }

                            @Override
                            public void replace(FilterBypass fb, int offset, int length, String text,
                                    AttributeSet attrs) throws BadLocationException {

                                if (StringUtils.isNumeric(text)) {
                                    super.replace(fb, offset, length, text, attrs);
                                }

                            }

                        });
            }
        } else if (fieldType.equals("bool")) {
            fieldComponent = new JCheckBox(fieldName);
            if (values[iter] != null) {
                ((JCheckBox) (fieldComponent)).setSelected(values[iter] == "true");
            }
            panelComponent = fieldComponent;
        } else if (fieldType.equals("combo")) {
            fieldComponent = new JComboBox();
            if (values[iter] != null) {
                StringTokenizer stParse = new StringTokenizer(values[iter], ",", false);
                while (stParse.hasMoreTokens()) {
                    ((JComboBox) (fieldComponent)).addItem(stParse.nextToken());
                }
            }
        } else {
            fieldComponent = new JTextField(3);
        }
        htInputFields.put(fieldName, fieldComponent);
        if (panelComponent == null) {
            panelContents.add(fieldName);
            panelContents.add(fieldComponent);
        } else {
            panelContents.add(panelComponent);
        }
    }
    jOptionPane = new JOptionPane(panelContents.toArray(), JOptionPane.QUESTION_MESSAGE,
            JOptionPane.OK_CANCEL_OPTION, null, buttonLabels, buttonLabels[0]);

    setContentPane(jOptionPane);
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);

    jOptionPane.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent e) {
            String prop = e.getPropertyName();
            if (isVisible() && (e.getSource() == jOptionPane) && (prop.equals(JOptionPane.VALUE_PROPERTY)
                    || prop.equals(JOptionPane.INPUT_VALUE_PROPERTY))) {
                Object value = jOptionPane.getValue();
                if (value == JOptionPane.UNINITIALIZED_VALUE) {
                    return;
                }
                if (value.equals(buttonLabels[0])) {
                    setVisible(false);
                } else {
                    setVisible(false);
                }
            }
        }
    });
    this.pack();
    setLocation(SwingUtilities.getPointForCentering(this, parent));
}