List of usage examples for javax.swing JCheckBox setSelected
public void setSelected(boolean b)
From source file:com.declarativa.interprolog.gui.Ini.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed try {//from w w w . jav a 2s.c o m Forest<String, Integer> forest = new DelegateForest<>(); ObservableGraph g = new ObservableGraph(new BalloonLayoutDemo().createTree(forest)); Layout layout = new BalloonLayout(forest); //Layout layout = new TreeLayout(forest, 70, 70); final BaseJungScene scene = new SceneImpl(g, layout); jLayeredPane1.setLayout(new BorderLayout()); jLayeredPane1.add(new JScrollPane(scene.createView()), BorderLayout.CENTER); final JCheckBox checkbox = new JCheckBox("Animate iterative layouts"); scene.setLayoutAnimationFramesPerSecond(48); //********************** DefaultComboBoxModel<Transformer<Context<Graph<String, Number>, Number>, Shape>> shapes = new DefaultComboBoxModel<>(); shapes.addElement(new EdgeShape.QuadCurve<String, Number>()); shapes.addElement(new EdgeShape.BentLine<String, Number>()); shapes.addElement(new EdgeShape.CubicCurve<String, Number>()); shapes.addElement(new EdgeShape.Line<String, Number>()); shapes.addElement(new EdgeShape.Box<String, Number>()); shapes.addElement(new EdgeShape.Orthogonal<String, Number>()); shapes.addElement(new EdgeShape.Wedge<String, Number>(10)); /* final JComboBox<Transformer<Context<Graph<String, Number>, Number>, Shape>> shapesBox = new JComboBox<>(shapes); shapesBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { Transformer<Context<Graph<String, Number>, Number>, Shape> xform = (Transformer<Context<Graph<String, Number>, Number>, Shape>) shapesBox.getSelectedItem(); scene.setConnectionEdgeShape(xform); } }); shapesBox.setRenderer(new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent(JList<?> jlist, Object o, int i, boolean bln, boolean bln1) { o = o.getClass().getSimpleName(); return super.getListCellRendererComponent(jlist, o, i, bln, bln1); //To change body of generated methods, choose Tools | Templates. } }); shapesBox.setSelectedItem(new EdgeShape.QuadCurve<>()); */ final JLabel selectionLabel = new JLabel("<html> </html>"); System.out.println("LOOKUP IS " + scene.getLookup()); Lookup.Result<String> selectedNodes = scene.getLookup().lookupResult(String.class); LookupListener listener = new LookupListener() { @Override public void resultChanged(LookupEvent le) { System.out.println("RES CHANGED"); Lookup.Result<String> res = (Lookup.Result<String>) le.getSource(); StringBuilder sb = new StringBuilder("<html>"); List<String> l = new ArrayList<>(res.allInstances()); Collections.sort(l); for (String s : l) { if (sb.length() != 0) { sb.append(", "); } sb.append(s); } sb.append("</html>"); selectionLabel.setText(sb.toString()); System.out.println("LOOKUP EVENT " + sb); } }; selectedNodes.addLookupListener(listener); selectedNodes.allInstances(); checkbox.setSelected(true); checkbox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { scene.setAnimateIterativeLayouts(checkbox.isSelected()); } }); jLayeredPane1.setSize(456, 458); //// jf.setSize(jf.getGraphicsConfiguration().getBounds().width - 120, 700); this.addWindowListener(new WindowAdapter() { @Override public void windowOpened(WindowEvent we) { scene.relayout(true); scene.validate(); } }); /* int returnVal = fileChooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); fileChooser.addChoosableFileFilter(new FileFilter() { public String getDescription() { return "Prolog native program (*.P)"; } public boolean accept(File f) { if (f.isDirectory()) { return true; } else { return f.getName().toLowerCase().endsWith(".P"); } } }); try { // What to do with the file, e.g. display it in a TextArea prologOutput.read(new FileReader(file.getAbsolutePath()), null); } catch (IOException ex) { System.out.println("problem accessing file" + file.getAbsolutePath()); } } else { System.out.println("File access cancelled by user."); } */ //One file chooser for each buton click } catch (IOException ex) { Exceptions.printStackTrace(ex); System.out.println("AUCH"); } }
From source file:com.mirth.connect.client.ui.Frame.java
/** * Alerts the user with a conflict resolution dialog *//*from ww w .j a v a2 s. com*/ public ConflictOption alertConflict(Component parentComponent, String message, int count) { final JCheckBox conflictCheckbox = new JCheckBox( "Do this for the next " + String.valueOf(count - 1) + " conflicts"); conflictCheckbox.setSelected(false); Object[] params = { message, conflictCheckbox }; int jOption = JOptionPane.showConfirmDialog(getVisibleComponent(parentComponent), params, "Select an Option", JOptionPane.YES_NO_OPTION); boolean isSelected = conflictCheckbox.isSelected(); ConflictOption conflictOption = null; if (jOption == JOptionPane.YES_OPTION) { if (isSelected) { conflictOption = ConflictOption.YES_APPLY_ALL; } else { conflictOption = ConflictOption.YES; } } else { if (isSelected || jOption == -1) { conflictOption = ConflictOption.NO_APPLY_ALL; } else { conflictOption = ConflictOption.NO; } } return conflictOption; }
From source file:cool.pandora.modeller.ui.jpanel.base.SaveBagFrame.java
private JPanel createComponents() { final Border border = new EmptyBorder(5, 5, 5, 5); final TitlePane titlePane = new TitlePane(); initStandardCommands();// w ww.j av a 2s. c o m final JPanel pageControl = new JPanel(new BorderLayout()); final JPanel titlePaneContainer = new JPanel(new BorderLayout()); titlePane.setTitle(bagView.getPropertyMessage("SaveBagFrame.title")); titlePane.setMessage(new DefaultMessage(bagView.getPropertyMessage("Define the Bag " + "settings"))); titlePaneContainer.add(titlePane.getControl()); titlePaneContainer.add(new JSeparator(), BorderLayout.SOUTH); pageControl.add(titlePaneContainer, BorderLayout.NORTH); final JPanel contentPane = new JPanel(); // TODO: Add bag name field // TODO: Add save name file selection button final JLabel location = new JLabel("Save in:"); final JButton browseButton = new JButton(getMessage("bag.button.browse")); browseButton.addActionListener(new SaveBagAsHandler()); browseButton.setEnabled(true); browseButton.setToolTipText(getMessage("bag.button.browse.help")); final DefaultBag bag = bagView.getBag(); if (bag != null) { bagNameField = new JTextField(bag.getName()); bagNameField.setCaretPosition(bag.getName().length()); bagNameField.setEditable(false); bagNameField.setEnabled(false); } // Holey bag control final JLabel holeyLabel = new JLabel(bagView.getPropertyMessage("bag.label.isholey")); holeyLabel.setToolTipText(bagView.getPropertyMessage("bag.isholey.help")); final JCheckBox holeyCheckbox = new JCheckBox(bagView.getPropertyMessage("bag.checkbox" + ".isholey")); holeyCheckbox.setBorder(border); holeyCheckbox.addActionListener(new HoleyBagHandler()); holeyCheckbox.setToolTipText(bagView.getPropertyMessage("bag.isholey.help")); urlLabel = new JLabel(bagView.getPropertyMessage("baseURL.label")); urlLabel.setToolTipText(bagView.getPropertyMessage("baseURL.description")); urlField = new JTextField(""); try { assert bag != null; urlField.setText(bag.getFetch().getBaseURL()); } catch (Exception e) { log.error("Failed to set url label", e); } urlField.setEnabled(false); // TODO: Add format label final JLabel serializeLabel; serializeLabel = new JLabel(getMessage("bag.label.ispackage")); serializeLabel.setToolTipText(getMessage("bag.serializetype.help")); // TODO: Add format selection panel noneButton = new JRadioButton(getMessage("bag.serializetype.none")); noneButton.setEnabled(true); final AbstractAction serializeListener = new SerializeBagHandler(); noneButton.addActionListener(serializeListener); noneButton.setToolTipText(getMessage("bag.serializetype.none.help")); zipButton = new JRadioButton(getMessage("bag.serializetype.zip")); zipButton.setEnabled(true); zipButton.addActionListener(serializeListener); zipButton.setToolTipText(getMessage("bag.serializetype.zip.help")); /* * tarButton = new JRadioButton(getMessage("bag.serializetype.tar")); * tarButton.setEnabled(true); * tarButton.addActionListener(serializeListener); * tarButton.setToolTipText(getMessage("bag.serializetype.tar.help")); * * tarGzButton = new JRadioButton(getMessage("bag.serializetype.targz")); * tarGzButton.setEnabled(true); * tarGzButton.addActionListener(serializeListener); * tarGzButton.setToolTipText(getMessage("bag.serializetype.targz.help")); * * tarBz2Button = new JRadioButton(getMessage("bag.serializetype.tarbz2")); * tarBz2Button.setEnabled(true); * tarBz2Button.addActionListener(serializeListener); * tarBz2Button.setToolTipText(getMessage("bag.serializetype.tarbz2.help")); */ short mode = 2; if (bag != null) { mode = bag.getSerialMode(); } if (mode == DefaultBag.NO_MODE) { this.noneButton.setEnabled(true); } else if (mode == DefaultBag.ZIP_MODE) { this.zipButton.setEnabled(true); } else { this.noneButton.setEnabled(true); } final ButtonGroup serializeGroup = new ButtonGroup(); serializeGroup.add(noneButton); serializeGroup.add(zipButton); // serializeGroup.add(tarButton); // serializeGroup.add(tarGzButton); // serializeGroup.add(tarBz2Button); final JPanel serializeGroupPanel = new JPanel(new FlowLayout()); serializeGroupPanel.add(serializeLabel); serializeGroupPanel.add(noneButton); serializeGroupPanel.add(zipButton); // serializeGroupPanel.add(tarButton); // serializeGroupPanel.add(tarGzButton); // serializeGroupPanel.add(tarBz2Button); serializeGroupPanel.setBorder(border); serializeGroupPanel.setEnabled(true); serializeGroupPanel.setToolTipText(bagView.getPropertyMessage("bag.serializetype.help")); final JLabel tagLabel = new JLabel(getMessage("bag.label.istag")); tagLabel.setToolTipText(getMessage("bag.label.istag.help")); final JCheckBox isTagCheckbox = new JCheckBox(); isTagCheckbox.setBorder(border); isTagCheckbox.addActionListener(new TagManifestHandler()); isTagCheckbox.setToolTipText(getMessage("bag.checkbox.istag.help")); final JLabel tagAlgorithmLabel = new JLabel(getMessage("bag.label.tagalgorithm")); tagAlgorithmLabel.setToolTipText(getMessage("bag.label.tagalgorithm.help")); final ArrayList<String> listModel = new ArrayList<>(); for (final Algorithm algorithm : Algorithm.values()) { listModel.add(algorithm.bagItAlgorithm); } final JComboBox<String> tagAlgorithmList = new JComboBox<>(listModel.toArray(new String[listModel.size()])); tagAlgorithmList.setName(getMessage("bag.tagalgorithmlist")); tagAlgorithmList.addActionListener(new TagAlgorithmListHandler()); tagAlgorithmList.setToolTipText(getMessage("bag.tagalgorithmlist.help")); final JLabel payloadLabel = new JLabel(getMessage("bag.label.ispayload")); payloadLabel.setToolTipText(getMessage("bag.ispayload.help")); final JCheckBox isPayloadCheckbox = new JCheckBox(); isPayloadCheckbox.setBorder(border); isPayloadCheckbox.addActionListener(new PayloadManifestHandler()); isPayloadCheckbox.setToolTipText(getMessage("bag.ispayload.help")); final JLabel payAlgorithmLabel = new JLabel(bagView.getPropertyMessage("bag.label" + ".payalgorithm")); payAlgorithmLabel.setToolTipText(getMessage("bag.payalgorithm.help")); final JComboBox<String> payAlgorithmList = new JComboBox<String>( listModel.toArray(new String[listModel.size()])); payAlgorithmList.setName(getMessage("bag.payalgorithmlist")); payAlgorithmList.addActionListener(new PayAlgorithmListHandler()); payAlgorithmList.setToolTipText(getMessage("bag.payalgorithmlist.help")); //only if bag is not null if (bag != null) { final String fileName = bag.getName(); bagNameField = new JTextField(fileName); bagNameField.setCaretPosition(fileName.length()); holeyCheckbox.setSelected(bag.isHoley()); urlLabel.setEnabled(bag.isHoley()); isTagCheckbox.setSelected(bag.isBuildTagManifest()); tagAlgorithmList.setSelectedItem(bag.getTagManifestAlgorithm()); isPayloadCheckbox.setSelected(bag.isBuildPayloadManifest()); payAlgorithmList.setSelectedItem(bag.getPayloadManifestAlgorithm()); } final GridBagLayout layout = new GridBagLayout(); final GridBagConstraints glbc = new GridBagConstraints(); final JPanel panel = new JPanel(layout); panel.setBorder(new EmptyBorder(10, 10, 10, 10)); int row = 0; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); layout.setConstraints(location, glbc); panel.add(location); buildConstraints(glbc, 2, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.EAST); glbc.ipadx = 5; layout.setConstraints(browseButton, glbc); glbc.ipadx = 0; panel.add(browseButton); buildConstraints(glbc, 1, row, 1, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); glbc.ipadx = 5; layout.setConstraints(bagNameField, glbc); glbc.ipadx = 0; panel.add(bagNameField); row++; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); layout.setConstraints(holeyLabel, glbc); panel.add(holeyLabel); buildConstraints(glbc, 1, row, 1, 1, 80, 50, GridBagConstraints.WEST, GridBagConstraints.WEST); layout.setConstraints(holeyCheckbox, glbc); panel.add(holeyCheckbox); row++; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); layout.setConstraints(urlLabel, glbc); panel.add(urlLabel); buildConstraints(glbc, 1, row, 1, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER); layout.setConstraints(urlField, glbc); panel.add(urlField); row++; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); layout.setConstraints(serializeLabel, glbc); panel.add(serializeLabel); buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); layout.setConstraints(serializeGroupPanel, glbc); panel.add(serializeGroupPanel); row++; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); layout.setConstraints(tagLabel, glbc); panel.add(tagLabel); buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER); layout.setConstraints(isTagCheckbox, glbc); panel.add(isTagCheckbox); row++; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); layout.setConstraints(tagAlgorithmLabel, glbc); panel.add(tagAlgorithmLabel); buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER); layout.setConstraints(tagAlgorithmList, glbc); panel.add(tagAlgorithmList); row++; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); layout.setConstraints(payloadLabel, glbc); panel.add(payloadLabel); buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER); layout.setConstraints(isPayloadCheckbox, glbc); panel.add(isPayloadCheckbox); row++; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); layout.setConstraints(payAlgorithmLabel, glbc); panel.add(payAlgorithmLabel); buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER); layout.setConstraints(payAlgorithmList, glbc); panel.add(payAlgorithmList); row++; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER); GuiStandardUtils.attachDialogBorder(contentPane); pageControl.add(panel); final JComponent buttonBar = createButtonBar(); pageControl.add(buttonBar, BorderLayout.SOUTH); this.pack(); return pageControl; }
From source file:nz.govt.natlib.ndha.manualdeposit.StructMapFileDescMgmtPresenter.java
private void setExtraLayerValues(HashMap<String, String> extraLayers) { for (Entry<String, JComponent> attr : this.extraLayers.entrySet()) { String value = extraLayers.get(attr.getKey()); // If JComponent is a checkbox if (attr.getKey().startsWith("Allow")) { JCheckBox field = (JCheckBox) attr.getValue(); if (value == null) field.setSelected(false); else// w w w. j a v a2 s .co m field.setSelected(Boolean.parseBoolean(value)); } // Else it is a text field else { JTextField field = (JTextField) attr.getValue(); if (value == null) field.setText(""); else field.setText(value); } } }
From source file:op.controlling.PnlControlling.java
private JPanel createContentPanel4Hygiene() { JPanel pnlContent = new JPanel(new VerticalLayout()); JPanel pnlPrevalence = new JPanel(new BorderLayout()); final JButton btnPrevalence = GUITools.createHyperlinkButton("opde.controlling.hygiene.prevalence", null, null);//from w w w. j a v a2 s . co m final JDateChooser jdc = new JDateChooser(new Date()); final JCheckBox cbAnonymous = new JCheckBox(SYSTools.xx("misc.msg.anon")); cbAnonymous.setSelected(true); jdc.setMaxSelectableDate(new Date()); btnPrevalence.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { OPDE.getMainframe().setBlocked(true); SwingWorker worker = new SwingWorker() { @Override protected Object doInBackground() throws Exception { MREPrevalenceSheets mre = new MREPrevalenceSheets(new LocalDate(), cbAnonymous.isSelected(), progressClosure); return mre.createSheet(); } @Override protected void done() { try { File source = (File) get(); Object[] options = { SYSTools.xx("prevalence.optiondialog.option1"), SYSTools.xx("prevalence.optiondialog.option2"), SYSTools.xx("opde.wizards.buttontext.cancel") }; int n = JOptionPane.showOptionDialog(OPDE.getMainframe(), SYSTools.xx("prevalence.optiondialog.question"), SYSTools.xx("prevalence.optiondialog.title"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]); File copyTargetDirectory = null; if (n == 1) { JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle("title"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setMultiSelectionEnabled(false); chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(pnlPrevalence) == JFileChooser.APPROVE_OPTION) { copyTargetDirectory = chooser.getSelectedFile(); } } if (copyTargetDirectory != null) { FileUtils.copyFile(source, copyTargetDirectory); } else { if (n == 0) { SYSFilesTools.handleFile((File) get(), Desktop.Action.OPEN); } } } catch (Exception e) { OPDE.fatal(e); } OPDE.getDisplayManager().setProgressBarMessage(null); OPDE.getMainframe().setBlocked(false); } }; worker.execute(); } }); pnlPrevalence.add(btnPrevalence, BorderLayout.WEST); JPanel optionPanel = new JPanel(); optionPanel.setLayout(new BoxLayout(optionPanel, BoxLayout.LINE_AXIS)); optionPanel.add(cbAnonymous); optionPanel.add(jdc); pnlPrevalence.add(optionPanel, BorderLayout.EAST); pnlContent.add(pnlPrevalence); return pnlContent; }
From source file:org.codinjutsu.tools.jenkins.view.BuildParamDialog.java
private JCheckBox createCheckBox(String defaultValue) { JCheckBox checkBox = new JCheckBox(); if (Boolean.TRUE.equals(Boolean.valueOf(defaultValue))) { checkBox.setSelected(true); }//from w w w . j a va 2 s . c o m return checkBox; }
From source file:org.ecoinformatics.seek.ecogrid.CheckBoxTableCellRenderer.java
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { jTable = table;//from w ww.jav a 2 s . co m JPanel cellPanel = new JPanel(); cellPanel.setBorder(new LineBorder(Color.lightGray, 1)); cellPanel.setBackground(Color.WHITE); cellPanel.setPreferredSize( new Dimension(ServicesDisplayPanel.CELLPREFERREDWIDTH, ServicesDisplayPanel.HEIGHT)); SelectableDocumentType selectedDocumentType = null; boolean isChecked = false; boolean isEnable = true; String text = null; if (value != null && value instanceof SelectableObjectInterface) { SelectableObjectInterface selectedObj = (SelectableObjectInterface) value; text = selectedObj.getSelectableObjectLabel(); isChecked = selectedObj.getIsSelected(); isEnable = selectedObj.getEnabled(); } /* * label = (JLabel)renderer.getTableCellRendererComponent(table, text, * isSelected, hasFocus, row, column); */ JLabel label = new JLabel(text); label.setFont(new Font(FONTNAME, Font.PLAIN, FONTSIZE)); label.setPreferredSize(new Dimension(ServicesDisplayPanel.LABELPREFERWIDTH, ServicesDisplayPanel.HEIGHT)); // set a check box name String checkBoxName = "" + topRowNum + SEPERATOR + row; JCheckBox checkBox = new JCheckBox(); checkBox.setName(checkBoxName); checkBox.setBackground(Color.WHITE); checkBox.setSelected(isChecked); CheckBoxListener listener = new CheckBoxListener(); checkBox.addItemListener(listener); // checkBox.setEnabled(false); /* * if (topRowNum != DEFAUTTOPROW ) { // for sub table we need to set up * check box enable status checkBox.setEnabled(isEnable); }//if */ // add the label and checkbox to jpanel which has a border layout // manager BorderLayout layoutManager = new BorderLayout(); cellPanel.setLayout(layoutManager); cellPanel.add(label, BorderLayout.CENTER); cellPanel.add(checkBox, BorderLayout.WEST); return cellPanel; }
From source file:org.esa.snap.ui.tooladapter.model.PropertyMemberUIWrapperFactory.java
private static PropertyMemberUIWrapper buildBooleanPropertyWrapper(String attributeName, ToolParameterDescriptor property, ToolAdapterOperatorDescriptor opDescriptor, BindingContext context, int width, PropertyMemberUIWrapper.CallBackAfterEdit callback) { return new PropertyMemberUIWrapper(attributeName, property, opDescriptor, context, width, callback) { @Override/*from w w w . j a v a2 s .c o m*/ protected void setMemberValue(Object value) throws PropertyAttributeException { property.setAttribute(attributeName, value); } @Override public Boolean getMemberValue() throws PropertyAttributeException { Object obj = property.getAttribute(attributeName); return obj != null && (boolean) obj; } @Override protected JComponent buildUIComponent() throws PropertyAttributeException { JCheckBox button = new JCheckBox(); button.setSelected(getMemberValue()); return button; } @Override protected Boolean getValueFromUIComponent() throws PropertyAttributeException { return ((JCheckBox) UIComponent).isSelected(); } }; }
From source file:org.formic.wizard.step.gui.FeatureListStep.java
/** * {@inheritDoc}//from w w w . j av a 2 s.co m * @see org.formic.wizard.step.GuiStep#init() */ public Component init() { featureInfo = new JEditorPane("text/html", StringUtils.EMPTY); featureInfo.setEditable(false); featureInfo.addHyperlinkListener(new HyperlinkListener()); Feature[] features = provider.getFeatures(); JTable table = new JTable(features.length, 1) { private static final long serialVersionUID = 1L; public Class getColumnClass(int column) { return getValueAt(0, column).getClass(); } public boolean isCellEditable(int row, int column) { return false; } }; table.setBackground(new javax.swing.JList().getBackground()); GuiForm form = createForm(); for (int ii = 0; ii < features.length; ii++) { final Feature feature = (Feature) features[ii]; final JCheckBox box = new JCheckBox(); String name = getName() + '.' + feature.getKey(); form.bind(name, box); box.putClientProperty("feature", feature); featureMap.put(feature.getKey(), box); if (feature.getInfo() == null) { feature.setInfo(Installer.getString(getName() + "." + feature.getKey() + ".html")); } feature.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (Feature.ENABLED_PROPERTY.equals(event.getPropertyName())) { if (box.isSelected() != feature.isEnabled()) { box.setSelected(feature.isEnabled()); } } } }); box.setText(Installer.getString(name)); box.setBackground(table.getBackground()); if (!feature.isAvailable()) { box.setSelected(false); box.setEnabled(false); } table.setValueAt(box, ii, 0); } FeatureListMouseListener mouseListener = new FeatureListMouseListener(); for (int ii = 0; ii < features.length; ii++) { Feature feature = (Feature) features[ii]; if (feature.isEnabled() && feature.isAvailable()) { JCheckBox box = (JCheckBox) featureMap.get(feature.getKey()); box.setSelected(true); mouseListener.processDependencies(feature); mouseListener.processExclusives(feature); } } table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setShowHorizontalLines(false); table.setShowVerticalLines(false); table.setDefaultRenderer(JCheckBox.class, new ComponentTableCellRenderer()); table.addKeyListener(new FeatureListKeyListener()); table.addMouseListener(mouseListener); table.getSelectionModel().addListSelectionListener(new FeatureListSelectionListener(table)); table.setRowSelectionInterval(0, 0); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); JPanel container = new JPanel(new BorderLayout()); container.add(table, BorderLayout.CENTER); panel.add(new JScrollPane(container), BorderLayout.CENTER); JScrollPane infoScroll = new JScrollPane(featureInfo); infoScroll.setMinimumSize(new Dimension(0, 50)); infoScroll.setMaximumSize(new Dimension(0, 50)); infoScroll.setPreferredSize(new Dimension(0, 50)); panel.add(infoScroll, BorderLayout.SOUTH); return panel; }
From source file:org.intermine.install.swing.source.PropertyComponentCreator.java
/** * Create a wrapper and components for the given property. * /* w w w. j a v a 2 s.co m*/ * @param propertyName The name of the property. * @param descriptor The descriptor of the property. If <code>null</code>, a default * descriptor will be created for the property. * @param initialValue The initial value for the field. * * @return The wrapper around the display components. */ protected static PropertyComponentWrapper createComponent(String propertyName, PropertyDescriptor descriptor, String initialValue) { if (descriptor == null) { ObjectFactory factory = new ObjectFactory(); descriptor = factory.createPropertyDescriptor(); descriptor.setName(propertyName); descriptor.setRequired(false); descriptor.setType(PropertyType.STRING); descriptor.setHidden(false); } JCheckBox checkBox; JTextField textField; switch (descriptor.getType()) { case BOOLEAN: checkBox = new JCheckBox(); checkBox.setSelected(Boolean.parseBoolean(initialValue)); return new PropertyComponentWrapper(propertyName, descriptor, checkBox); case INTEGER: textField = new JTextField(new IntegerDocument(), initialValue, 0); return new PropertyComponentWrapper(propertyName, descriptor, textField); case DECIMAL: textField = new JTextField(new DecimalDocument(), initialValue, 0); return new PropertyComponentWrapper(propertyName, descriptor, textField); case CLASS: textField = new JTextField(new RestrictedInputDocument(CLASS_CHARACTERS), initialValue, 0); return new PropertyComponentWrapper(propertyName, descriptor, textField); case STRING: textField = new JTextField(initialValue); if (descriptor != null) { if (descriptor.getValidation() != null) { new ValidatedPropertyFocusListener(textField, descriptor.getValidation(), descriptor.isRequired()); } } return new PropertyComponentWrapper(propertyName, descriptor, textField); case DIRECTORY: case FILE: return createFileComponent(propertyName, descriptor, initialValue); } throw new IllegalArgumentException( "Don't know how to create a component for field type " + descriptor.getType()); }