List of usage examples for javax.swing JComponent putClientProperty
public final void putClientProperty(Object key, Object value)
From source file:org.tinymediamanager.ui.panels.MediaScraperConfigurationPanel.java
private JPanel createConfigPanel() { JPanel panel = new JPanel(); GridBagLayout gridBagLayout = new GridBagLayout(); gridBagLayout.columnWidths = new int[] { 0 }; gridBagLayout.rowHeights = new int[] { 0 }; gridBagLayout.columnWeights = new double[] { Double.MIN_VALUE }; gridBagLayout.rowWeights = new double[] { Double.MIN_VALUE }; panel.setLayout(gridBagLayout);/*from w w w. j av a 2s . c o m*/ GridBagConstraints constraints = new GridBagConstraints(); constraints.gridy = 0; // build up the panel for being displayed in the popup MediaProviderConfig config = mediaProvider.getProviderInfo().getConfig(); for (Entry<String, MediaProviderConfigObject> entry : config.getConfigObjects().entrySet()) { if (!entry.getValue().isVisible()) { continue; } constraints.anchor = GridBagConstraints.LINE_START; constraints.ipadx = 20; // label JLabel label = new JLabel(entry.getValue().getKeyDescription()); constraints.gridx = 0; panel.add(label, constraints); JComponent comp; switch (entry.getValue().getType()) { case BOOL: // display as checkbox JCheckBox checkbox = new JCheckBox(); checkbox.setSelected(entry.getValue().getValueAsBool()); checkbox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dirty = true; } }); comp = checkbox; break; case SELECT: case SELECT_INDEX: // display as combobox JComboBox<String> combobox = new JComboBox<>( entry.getValue().getPossibleValues().toArray(new String[0])); combobox.setSelectedItem(entry.getValue().getValueAsString()); combobox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dirty = true; } }); comp = combobox; break; default: // display as text JTextField tf; if (entry.getValue().isEncrypt()) { tf = new JPasswordField(config.getValue(entry.getKey())); } else { tf = new JTextField(config.getValue(entry.getKey())); } tf.setPreferredSize(new Dimension(100, 24)); tf.getDocument().addDocumentListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { dirty = true; } @Override public void insertUpdate(DocumentEvent e) { dirty = true; } @Override public void changedUpdate(DocumentEvent e) { dirty = true; } }); comp = tf; break; } comp.putClientProperty(entry.getKey(), entry.getKey()); constraints.ipadx = 0; constraints.gridx = 1; panel.add(comp, constraints); // add a hint if a long text has been found try { String desc = BUNDLE.getString( "scraper." + mediaProvider.getProviderInfo().getId() + "." + entry.getKey() + ".desc"); //$NON-NLS-1$ if (StringUtils.isNotBlank(desc)) { JLabel lblHint = new JLabel(IconManager.HINT); lblHint.setToolTipText(desc); constraints.gridx = 2; panel.add(lblHint, constraints); } } catch (Exception ignored) { } constraints.gridy++; } return panel; }
From source file:umich.ms.batmass.projects.actions.newproject.NewProjectWizardAction.java
@Override public void actionPerformed(ActionEvent e) { List<WizardDescriptor.Panel<WizardDescriptor>> panels = new ArrayList<>(); panels.add(new NewProjectWizardPanel1()); panels.add(new NewProjectWizardPanel2()); String[] steps = new String[panels.size()]; for (int i = 0; i < panels.size(); i++) { Component c = panels.get(i).getComponent(); // Default step name to component name of panel. steps[i] = c.getName();/*from w w w . j a va 2s . c o m*/ if (c instanceof JComponent) { // assume Swing components JComponent jc = (JComponent) c; jc.putClientProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, i); jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, steps); jc.putClientProperty(WizardDescriptor.PROP_AUTO_WIZARD_STYLE, true); jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DISPLAYED, true); jc.putClientProperty(WizardDescriptor.PROP_CONTENT_NUMBERED, true); } } WizardDescriptor wiz = new WizardDescriptor(new WizardDescriptor.ArrayIterator<>(panels)); // {0} will be replaced by WizardDesriptor.Panel.getComponent().getName() wiz.setTitleFormat(new MessageFormat("{0}")); wiz.setTitle("Create a new project"); if (DialogDisplayer.getDefault().notify(wiz) == WizardDescriptor.FINISH_OPTION) { BMProjectFactory pf = (BMProjectFactory) wiz.getProperty(NewProjectWizardPanel1.PROP_PROJECT_FACTORY); String name = (String) wiz.getProperty(NewProjectWizardPanel2.PROP_PRROJECT_NAME); String location = (String) wiz.getProperty(NewProjectWizardPanel2.PROP_PRROJECT_LOCATION); DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message( name + " @ " + location + "\ntype: " + pf.getClass().getSimpleName())); try { // now we have all input data to create a project // BMProjectFactory should know how to create a proper file structure pf.createProjectDirStructure(Paths.get(location), name); // and open the project, if it was created Path newProjectPath = Paths.get(location); FileObject projectToBeOpened = FileUtil.toFileObject(newProjectPath.toFile()); Project project = ProjectManager.getDefault().findProject(projectToBeOpened); Project[] projectsToOpen = { project }; OpenProjects.getDefault().open(projectsToOpen, false, true); } catch (IOException ex) { Exceptions.printStackTrace(ex); } catch (ConfigurationException ex) { Exceptions.printStackTrace(ex); } } }