Java Code Examples for javax.swing.DefaultListCellRenderer

The following examples show how to use javax.swing.DefaultListCellRenderer. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: netbeans   Source File: OnSaveTabPanel.java    License: Apache License 2.0 6 votes vote down vote up
public OnSaveTabPanel() {
    initComponents();
    // Languages combobox renderer
    cboLanguage.setRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            if ((value instanceof String) && selector != null) {
                value = selector.getLanguageName((String) value);
            }
            return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        }
    });
    
    commonPanel = new OnSaveCommonPanel();
    commonPanelContainer.setLayout(new BorderLayout());
    commonPanelContainer.add(commonPanel, BorderLayout.WEST);
    
    customPanelContainer.setLayout(new BorderLayout());
}
 
Example 2
Source Project: netbeans   Source File: FolderBasedOptionPanel.java    License: Apache License 2.0 6 votes vote down vote up
/** Creates new form FolderBasedOptionPanel */
FolderBasedOptionPanel(FolderBasedController controller, Document filterDocument, boolean allowFiltering) {
    this.controller = controller;

    initComponents();

    filter.setDocument(filterDocument);

    if (!allowFiltering) {
        filter.setVisible(false);
        filterLabel.setVisible(false);
    }
    
    ListCellRenderer renderer = new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            if (value instanceof String)
                value = EditorSettings.getDefault().getLanguageName((String)value);
            return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        }
    };
    languageCombo.setRenderer(renderer);
    languageCombo.addActionListener(this);

    update();
}
 
Example 3
Source Project: netbeans   Source File: CodeCompletionOptionsPanel.java    License: Apache License 2.0 6 votes vote down vote up
/** 
 * Creates new form CodeCompletionOptionsPanel.
 */
public CodeCompletionOptionsPanel () {
    initComponents ();

    // Languages combobox renderer
    cbLanguage.setRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            if (value instanceof String) {
                value = ((String)value).length() > 0
                        ? EditorSettings.getDefault().getLanguageName((String)value)
                        : org.openide.util.NbBundle.getMessage(CodeCompletionOptionsPanel.class, "LBL_AllLanguages"); //NOI18N
            }
            return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        }
    });

}
 
Example 4
Source Project: netbeans   Source File: CharsetSelector.java    License: Apache License 2.0 6 votes vote down vote up
public CharsetSelector() {
    super(
            Charset.availableCharsets().values().toArray(new Charset[]{})
    );
    this.setRenderer(new DefaultListCellRenderer(){

        @Override
        public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            Object displayValue;
            if(value instanceof Charset) {
                displayValue = ((Charset) value).displayName();
            } else {
                displayValue = value;
            }
            return super.getListCellRendererComponent(list, displayValue, index, isSelected, cellHasFocus);
        }
        
    });
}
 
Example 5
@SuppressWarnings("unchecked")
protected UpgradeStrategyEditor() {
  super(new JComboBox<UpgradeXGAPP.UpgradePath.UpgradeStrategy>());
  JComboBox<UpgradeXGAPP.UpgradePath.UpgradeStrategy> combo = (JComboBox)getComponent();
  combo.setRenderer(new DefaultListCellRenderer() {
    @Override
    public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
      JLabel renderer = (JLabel)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
      renderer.setText(((UpgradeXGAPP.UpgradePath.UpgradeStrategy)value).label);
      renderer.setToolTipText(((UpgradeXGAPP.UpgradePath.UpgradeStrategy)value).tooltip);
      renderer.setIcon(strategyIcons.get(value));
      renderer.setDisabledIcon(disabledStrategyIcon);
      return renderer;
    }
  });
  combo.setModel(new DefaultComboBoxModel<>());
}
 
Example 6
public UpdateUIRecursionTest() {
    super("UpdateUIRecursionTest");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(400, 400);

    String[] listData = {
        "First", "Second", "Third", "Fourth", "Fifth", "Sixth"
    };

    list = new JList(listData);
    list.setCellRenderer(this);
    renderer = new DefaultListCellRenderer();
    getContentPane().add(new JScrollPane(list), BorderLayout.CENTER);

    setVisible(true);
}
 
Example 7
public UpdateUIRecursionTest() {
    super("UpdateUIRecursionTest");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(400, 400);

    String[] listData = {
        "First", "Second", "Third", "Fourth", "Fifth", "Sixth"
    };

    combo = new JComboBox(listData);
    combo.setRenderer(this);
    renderer = new DefaultListCellRenderer();
    getContentPane().add(new JScrollPane(combo), BorderLayout.CENTER);

    setVisible(true);
}
 
Example 8
Source Project: gcs   Source File: LibraryDockable.java    License: Mozilla Public License 2.0 6 votes vote down vote up
private void createCategoryCombo() {
    mCategoryCombo = new JComboBox<>();
    // Next two client properties are specific to Mac OS X
    mCategoryCombo.putClientProperty("JComponent.sizeVariant", "small");
    mCategoryCombo.putClientProperty("JComboBox.isPopDown", Boolean.TRUE);
    mCategoryCombo.setMaximumRowCount(20);
    mCategoryCombo.setRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            Component comp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            setFont(getFont().deriveFont(index == 0 ? Font.ITALIC : Font.PLAIN));
            return comp;
        }
    });
    mCategoryCombo.addActionListener((event) -> {
        mCategoryCombo.setFont(mCategoryCombo.getFont().deriveFont(mCategoryCombo.getSelectedIndex() == 0 ? Font.ITALIC : Font.PLAIN));
        mCategoryCombo.revalidate();
        mCategoryCombo.repaint();
        if (mOutline != null) {
            mOutline.reapplyRowFilter();
        }
    });
    mToolbar.add(mCategoryCombo);
    adjustCategoryCombo();
}
 
Example 9
Source Project: Ardulink-2   Source File: ConnectionPanel.java    License: Apache License 2.0 6 votes vote down vote up
private JComboBox createURICombo() {
	JComboBox uris = new JComboBox();
	uris.setRenderer(new DefaultListCellRenderer() {

		private static final long serialVersionUID = 2756587449741341859L;

		@Override
		public Component getListCellRendererComponent(JList list,
				Object value, int index, boolean isSelected,
				boolean cellHasFocus) {
			return value == null ? null : super.getListCellRendererComponent(list,
					extractNameFromURI(URIs.newURI((String) value)), index,
					isSelected, cellHasFocus);
		}
	});
	uris.addItemListener(new ItemListener() {
		@Override
		public void itemStateChanged(ItemEvent event) {
			if (event.getStateChange() == SELECTED) {
				replaceSubpanel();
			}
		}
	});
	return uris;
}
 
Example 10
Source Project: azure-devops-intellij   Source File: CreatePullRequestForm.java    License: MIT License 6 votes vote down vote up
private void createUIComponents() {
    this.targetBranchDropdown = new JComboBox();
    this.targetBranchDropdown.setRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list,
                                                      Object gitRemoteBranch,
                                                      int index,
                                                      boolean isSelected,
                                                      boolean cellHasFocus) {
            return super.getListCellRendererComponent(list,
                    gitRemoteBranch != null ? ((GitRemoteBranch) gitRemoteBranch).getName() : "",
                    index,
                    isSelected,
                    cellHasFocus);
        }
    });
    this.targetBranchDropdown.setActionCommand(CMD_TARGET_BRANCH_UPDATED);

}
 
Example 11
Source Project: azure-devops-intellij   Source File: CreateBranchForm.java    License: MIT License 6 votes vote down vote up
private void ensureInitialized() {
    if (!this.initialized) {
        // override the renderer so it doesn't show the object toString but instead shows the branch name
        remoteBranchComboBox.setRenderer(new DefaultListCellRenderer() {
            @Override
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                return super.getListCellRendererComponent(list,
                        value != null ? ((GitRemoteBranch) value).getName() : StringUtils.EMPTY,
                        index,
                        isSelected,
                        cellHasFocus);
            }
        });

        this.initialized = true;
    }
}
 
Example 12
Source Project: CodenameOne   Source File: PickMIDlet.java    License: GNU General Public License v2.0 6 votes vote down vote up
/** Creates new form PickMIDlet */
public PickMIDlet() {
    initComponents();
    midletPicker.setRenderer(new DefaultListCellRenderer() {
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            if(value == null) {
                value = "";
            } else {
                String s = (String)value;
                value = s.substring(0, s.indexOf(','));
            }
            return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        }
    });
    Preferences pref = Preferences.userNodeForPackage(ResourceEditorView.class);
    jarFile.setText(pref.get("jar", ""));
    updateMIDletList();
    midletPicker.setSelectedItem(pref.get("midlet", null));
    customComponents = null;
}
 
Example 13
Source Project: settlers-remake   Source File: EditorControl.java    License: MIT License 6 votes vote down vote up
/**
 * Constructor
 */
public EditorControl() {
	// use heavyweight component
	playerCombobox.setLightWeightPopupEnabled(false);
	playerCombobox.addActionListener(e -> currentPlayer = (Integer) playerCombobox.getSelectedItem());
	playerCombobox.setRenderer(new DefaultListCellRenderer() {
		private static final long serialVersionUID = 1L;

		@Override
		public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
			super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);

			Integer player = (Integer) value;
			setIcon(new RectIcon(22, new Color(mapContent.getPlayerColor(player.byteValue()).getARGB()), Color.GRAY));
			setText(String.format(Locale.ENGLISH, EditorLabels.getLabel("general.player_x"), player));

			return this;
		}
	});
}
 
Example 14
Source Project: magarena   Source File: OptionsPanel.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void setOnDemandCombo() {
    cboOnDemand.setModel(new DefaultComboBoxModel<>(new Boolean[]{true, false}));
    cboOnDemand.getModel().setSelectedItem(CONFIG.getImagesOnDemand());
    cboOnDemand.setRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            setText((Boolean) value == true ? MText.get(_S12) : MText.get(_S13));
            setForeground(cboOnDemand.isEnabled() ? getForeground() : Color.GRAY);
            return this;
        }
    });
    cboOnDemand.addItemListener((final ItemEvent e) -> {
        if (e.getStateChange() == ItemEvent.SELECTED) {
            doOnDemandChanged();
        }
    });
}
 
Example 15
@Override
protected void buildChooser() {
    colorList = new JList<>(new Vector<>(ColorCodes.getNames()));
    DefaultListCellRenderer cellRenderer = new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            setOpaque(true);
            Color color = ColorCodes.getColor(value.toString());
            int max = Math.max(color.getRed(), Math.max(color.getGreen(), color.getBlue()));
            setForeground(max < 160 ? Color.WHITE : Color.BLACK);
            setBackground(color);
            setBorder(new EmptyBorder(5, 5, 5, 5));
            setFont(getFont().deriveFont(14f));
            return this;
        }
    };
    colorList.setCellRenderer(cellRenderer);
    colorList.addListSelectionListener(this);
    setLayout(new BorderLayout());
    setBorder(new EmptyBorder(5, 5, 5, 5));
    add(new JScrollPane(colorList), BorderLayout.CENTER);
}
 
Example 16
Source Project: arcusplatform   Source File: SelectNewPlacePrompt.java    License: Apache License 2.0 5 votes vote down vote up
SelectNewPlaceDialog() {
   placeSelector.setRenderer(new DefaultListCellRenderer() {
      @Override
      public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
         PlaceAccessDescriptor place = (PlaceAccessDescriptor) value;
         Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
         String text = place == null ? "[No Places Available]" : place.getName();
         ((JLabel) c).setText(text);
         return c;
      }
   });
}
 
Example 17
Source Project: arcusplatform   Source File: ListBoxBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public ListBoxBuilder<T> withRenderer(Function<T, String> renderer) {
   return withRenderer(new DefaultListCellRenderer() {
      @Override
      public Component getListCellRendererComponent(
            JList<?> list, Object value, int index, boolean isSelected,
            boolean cellHasFocus) {
         Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
         ((JLabel) c).setText(renderer.apply((T) value));
         return c;
      }
   });
}
 
Example 18
Source Project: arcusplatform   Source File: ComboBoxBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public ComboBoxBuilder<T> withCellRenderer(Function<T, String> renderer) {
   withCellRenderer(new DefaultListCellRenderer() {
      @Override
      public Component getListCellRendererComponent(
            JList<?> list, Object value, int index, boolean isSelected,
            boolean cellHasFocus) {
         Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
         ((JLabel) c).setText(renderer.apply((T) value));
         return c;
      }
   });
   return this;
}
 
Example 19
Source Project: opt4j   Source File: ConvergencePlotWidget.java    License: MIT License 5 votes vote down vote up
public ObjectiveDropDown() {
	super();

	setRenderer(new ListCellRenderer<Objective>() {
		protected DefaultListCellRenderer renderer = new DefaultListCellRenderer();

		@Override
		public Component getListCellRendererComponent(JList<? extends Objective> list, Objective value,
				int index, boolean isSelected, boolean cellHasFocus) {
			JLabel cell = (JLabel) renderer.getListCellRendererComponent(list, value, index, isSelected,
					cellHasFocus);
			Objective objective = value;
			cell.setText((objective != null ? "objective: " + objective.getName() : ""));
			return cell;
		}
	});

	setMaximumSize(getPreferredSize());
}
 
Example 20
Source Project: netbeans   Source File: ConfigurationsPanel.java    License: Apache License 2.0 5 votes vote down vote up
ConfigurationsPanel(ModelHandle2 handle, NbMavenProjectImpl project) {
        this();
        this.handle = handle;
        this.project = project;
        
//        btnAdd.setVisible(false);
//        btnEdit.setVisible(false);
//        btnRemove.setVisible(false);
//        addProfileConfigurations();
        
        initListUI();
        checkButtonEnablement();
        lstConfigurations.setCellRenderer(new DefaultListCellRenderer() {
            @Override
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                Component supers = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                ModelHandle2.Configuration conf = (ModelHandle2.Configuration)value;
                if (conf == ConfigurationsPanel.this.handle.getActiveConfiguration()) {
                    supers.setFont(supers.getFont().deriveFont(Font.BOLD));
                }
                return supers;
            }
        });
        
        lstConfigurations.addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {
                checkButtonEnablement();
            }

        });
        createListModel();
    }
 
Example 21
Source Project: netbeans   Source File: CreateLibraryPanel.java    License: Apache License 2.0 5 votes vote down vote up
@Messages("NAME_Library=Library Name")
CreateLibraryPanel(DependencyNode root) {
    initComponents();
    DefaultComboBoxModel mdl = new DefaultComboBoxModel();
    SwingValidationGroup.setComponentName(txtName, NAME_Library());

    for (LibraryManager manager : LibraryManager.getOpenManagers()) {
        mdl.addElement(manager);
    }
    comManager.setModel(mdl);
    comManager.addActionListener(new ActionListener() {
        public @Override void actionPerformed(ActionEvent e) {
            if (vg != null) {
                vg.performValidation();
            }
        }

    });
    comManager.setRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            LibraryManager man = (LibraryManager) value;
            return super.getListCellRendererComponent(list, man.getDisplayName(), index, isSelected, cellHasFocus);
        }

    });
    trDeps.setCellRenderer(new CheckRenderer(false));
    CheckNodeListener l = new CheckNodeListener(false);
    trDeps.addMouseListener(l);
    trDeps.addKeyListener(l);
    trDeps.setToggleClickCount(0);
    trDeps.setRootVisible(false);
    trDeps.setModel(new DefaultTreeModel(new DefaultMutableTreeNode()));
    rootnode = root;
    trDeps.setModel(new DefaultTreeModel(createDependenciesList()));
    setLibraryName();
}
 
Example 22
Source Project: netbeans   Source File: ShowEffPomDiffPanel.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates new form ShowEffPomDiffPanel
 */
public ShowEffPomDiffPanel(ProjectConfigurationProvider<MavenConfiguration> configs) {
    initComponents();
    ComboBoxModel<MavenConfiguration> model = new DefaultComboBoxModel<MavenConfiguration>(configs.getConfigurations().toArray(new MavenConfiguration[0]));
    comConfiguration.setModel(model);
    comConfiguration.setEditable(false);
    comConfiguration.setRenderer(new DefaultListCellRenderer() {

        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            return super.getListCellRendererComponent(list, ((ProjectConfiguration)value).getDisplayName(), index, isSelected, cellHasFocus);
        }
    });
    comConfiguration.setSelectedItem(configs.getActiveConfiguration());
    enableFields();
    epProperties.setContentType("text/x-properties");
}
 
Example 23
Source Project: netbeans   Source File: MavenRunOptions.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates new form MavenRunOptions
 */
public MavenRunOptions(Project project, Category category, ModelHandle2 handle) {
    this.project = project;
    this.category = category;
    this.handle = handle;
    
    initComponents();

    cbConfiguration.setEditable(false);
    cbConfiguration.setRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            Component com = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (com instanceof JLabel) {
                if (value == handle.getActiveConfiguration()) {
                    com.setFont(com.getFont().deriveFont(Font.BOLD));
                }
            }
            return com;
        }
    });
    
    nestedOptions = (JShellOptions2)pOptions;
    
    setupConfigurations();
    
    loadOptions(null);
    
    nestedOptions.setConfigChangeListener(this::optionsChanged);
    cbConfiguration.addActionListener(this::loadOptions);
}
 
Example 24
Source Project: netbeans   Source File: ResourcesCustomizer.java    License: Apache License 2.0 5 votes vote down vote up
private static TableCellEditor createEditor() {
    final JComboBox combo = new JComboBox(new Object[] {Boolean.TRUE, Boolean.FALSE});
    combo.setRenderer(new DefaultListCellRenderer(){
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            return super.getListCellRendererComponent(
                    list,
                    NbBundle.getMessage(ResourcesCustomizer.class, value == Boolean.TRUE ? "TXT_LAZY":"TXT_EAGER"),
                    index,
                    isSelected,
                    cellHasFocus);
        }            
    });
    return new DefaultCellEditor(combo);
}
 
Example 25
Source Project: netbeans   Source File: TestCategory.java    License: Apache License 2.0 5 votes vote down vote up
private ListCellRenderer<Object> runBuildRenderer() {
    return new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            if (value instanceof RunBuild) {
                value = runBuildDisplayName.getOrDefault(value, String.valueOf(value));
            }
            return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        }
    };
}
 
Example 26
Source Project: netbeans   Source File: PoliciesVisualPanel.java    License: Apache License 2.0 5 votes vote down vote up
PoliciesListCellRenderer( Set<String> selected ){
    JList list = new JList(new Object[]{""});
    Component comp = new DefaultListCellRenderer().
        getListCellRendererComponent( list, "", 0, true, true);
    mySelectedBckgrnd = comp.getBackground();
    setOpaque( true );
    setLayout( new FlowLayout(FlowLayout.LEFT) );
    myCheckBox = new JCheckBox();
    myCheckBox.setBackground( Color.WHITE );
    add( myCheckBox );
    myLbl = new JLabel( );
    myLbl.setBackground( Color.WHITE );
    add( myLbl );
    setBackground( Color.WHITE );
    
    mySelected = new boolean[ myPoliciesList.getModel().getSize()];
    for( int i=0; i<mySelected.length ; i++ ){
        String id = myPoliciesList.getModel().getElementAt(i).toString();
        mySelected[ i] =selected.contains( id);
    }
}
 
Example 27
Source Project: netbeans   Source File: CustomizerFrameworks.java    License: Apache License 2.0 5 votes vote down vote up
public CustomizerFrameworks(ProjectCustomizer.Category category, Project project) {
    this.category = category;
    this.project = project;

    initComponents();
    initFrameworksList();

    btnRemoveAdded.setEnabled(false);
    jListFrameworks.setCellRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            WebFrameworkProvider prov = (WebFrameworkProvider) value;
            Component toRet = super.getListCellRendererComponent(list, prov.getName(), index, isSelected, cellHasFocus);
            if (toRet instanceof JLabel) {
                JLabel lbl = (JLabel) toRet;
                if (addedFrameworks.contains(prov)) {
                    lbl.setFont(lbl.getFont().deriveFont(Font.BOLD));
                } else {
                    lbl.setFont(lbl.getFont().deriveFont(Font.PLAIN));
                }
            }
            return toRet;
        }
    });
}
 
Example 28
Source Project: netbeans   Source File: ServerSelectionHelper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates new Helper instance for specific project type.
 * It also initiate server model and platform version model combo boxes so they are filled only with supported options
 *
 * @param serverModel combo box for all possible servers
 * @param j2eeVersion combo box for J2ee version specification
 * @param projectType project type
 */
public ServerSelectionHelper(JComboBox serverModel, JComboBox j2eeVersion, J2eeModule.Type projectType) {
    this.serverModel = serverModel;
    this.projectType = projectType;
    this.delegate = j2eeVersion.getRenderer();

    this.j2eeVersion = j2eeVersion;
    this.j2eeVersion.setRenderer(new DefaultListCellRenderer() {

        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            String profileName = null;
            if (value instanceof Profile) {
                profileName = ((Profile) value).getDisplayName();
            }
            if (value instanceof String) {
                profileName = (String) value;
            }
            return delegate.getListCellRendererComponent(list, profileName, index, isSelected, cellHasFocus);
        }

    });
    initServerModel(null);
    updatePlatformVersionModel();
}
 
Example 29
Source Project: netbeans   Source File: J2EEUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static ListCellRenderer getRenderer() {
    return new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (value instanceof DBColumnInfo) {
                DBColumnInfo column = (DBColumnInfo)value;
                String label = column.getName() + (column.isValid() ? "" : " (" + column.getMessage() + ")"); // NOI18N
                setText(label);
                setEnabled(column.isValid());
            }
            return this;
        }
    };
}
 
Example 30
Source Project: netbeans   Source File: FoldOptionsPanel.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates new form FoldOptionsPanel
 */
public FoldOptionsPanel(FoldOptionsController ctrl) {
    this.ctrl = ctrl;
    initComponents();
    
    langSelect.setRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            if (value instanceof String[]) {
                value = ((String[])value)[1];
            }
            return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); //To change body of generated methods, choose Tools | Templates.
        }
    });
    langSelect.addActionListener(this);
    contentPreview.addActionListener(this);
    foldedSummary.addActionListener(this);
    
    // preferences should be set as a reaction to index selection
}