javax.swing.DefaultListCellRenderer Java Examples

The following examples show how to use javax.swing.DefaultListCellRenderer. 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 File: Main.java    From desktop with The Unlicense 7 votes vote down vote up
/**
 * @main
 */
  
      
public Main() {
    initComponents();
    setLocationRelativeTo(this);
    this.setTitle("EVIL INSULT GENERATOR");
    this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/imgs/app-icon.png")));

    addCombobox();

    AutoCompleteDecorator.decorate(this.cmbLanguage);
    DefaultListCellRenderer dlcr = new DefaultListCellRenderer();
    dlcr.setHorizontalAlignment(DefaultListCellRenderer.CENTER);

    cmbLanguage.setRenderer(dlcr);

    StyledDocument doc = txtPaneShow.getStyledDocument();
    SimpleAttributeSet center = new SimpleAttributeSet();
    StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
    doc.setParagraphAttributes(0, doc.getLength(), center, false);

    try {

        Document doc1 = Jsoup.connect("http://evilinsult.com/generate_insult.php?lang=en").get();

        Elements links = doc1.select("body");
        for (Element link : links) {
            txtPaneShow.setText("\n" + link.text());
        }
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception ex) {
        txtPaneShow.setText("Insult Outage! Please Check Your Internet Connection And Try Again In Three Minutes");
    }

}
 
Example #2
Source File: OnSaveTabPanel.java    From netbeans with 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 #3
Source File: PickMIDlet.java    From CodenameOne with 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 #4
Source File: OptionsPanel.java    From magarena with 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 #5
Source File: ColorChooserPanel.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
@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 #6
Source File: EditorControl.java    From settlers-remake with 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 #7
Source File: CreatePullRequestForm.java    From azure-devops-intellij with 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 #8
Source File: CreateBranchForm.java    From azure-devops-intellij with 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 #9
Source File: ConnectionPanel.java    From Ardulink-2 with 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 File: LibraryDockable.java    From gcs with 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 #11
Source File: UpdateUIRecursionTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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 #12
Source File: UpdateUIRecursionTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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 #13
Source File: XgappUpgradeSelector.java    From gate-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #14
Source File: CharsetSelector.java    From netbeans with 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 #15
Source File: CodeCompletionOptionsPanel.java    From netbeans with 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 #16
Source File: FolderBasedOptionPanel.java    From netbeans with 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 #17
Source File: BaseTextListComp.java    From scelight with Apache License 2.0 5 votes vote down vote up
/**
 * Builds the GUI of the tab.
 * 
 * <p>
 * Does not finalizes the {@link #toolBar}
 * </p>
 */
protected void buildGui() {
	addNorth( toolBarsBox );
	
	toolBarsBox.add( toolBar );
	
	toolBar.addSelectInfoLabel( "Select text." );
	toolBar.addSelEnabledButton( copySelectedAction );
	toolBar.add( copyAllAction );
	toolBar.add( new TipIcon( Tips.TEXT_SELECTION ) );
	
	toolBar.addSeparator();
	toolBar.add( searchComp );
	searchComp.registerFocusHotkey( this );
	searchComp.setSearcher( searcher );
	
	toolBar.addSeparator();
	toolBar.add( textSizeLabel );
	
	textList.setCellRenderer( new DefaultListCellRenderer() {
		private final Border focusedBorder = BorderFactory.createMatteBorder( 1, 0, 1, 0, Color.BLACK );
		
		@Override
		public Component getListCellRendererComponent( JList< ? > list, Object value, int index, boolean isSelected, boolean cellHasFocus ) {
			super.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus );
			
			// Default border results in big line height, set a thicker border
			setBorder( cellHasFocus ? focusedBorder : null );
			
			return this;
		}
	} );
	textList.setSelectionMode( ListSelectionModel.MULTIPLE_INTERVAL_SELECTION );
	addCenter( new XScrollPane( textList, true, false ) );
	
	rebuildText();
}
 
Example #18
Source File: SpaceCombo.java    From Open-Realms-of-Stars with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Init default space look and feel.
 * @param data Data model for combo box in array.
 */
public SpaceCombo(final E[] data) {
  super(data);
  setBackground(GuiStatics.COLOR_DEEP_SPACE_PURPLE_DARK);
  setForeground(GuiStatics.COLOR_COOL_SPACE_BLUE);
  setBorder(new SimpleBorder());
  setFont(GuiStatics.getFontCubellan());
  setMaximumSize(new Dimension(Integer.MAX_VALUE,
      GuiStatics.TEXT_FIELD_HEIGHT));
  DefaultListCellRenderer dlcr = new DefaultListCellRenderer();
  dlcr.setHorizontalAlignment(DefaultListCellRenderer.CENTER);
  setRenderer(dlcr);
}
 
Example #19
Source File: AttributesPropertyDialog.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Create a list cell renderer for lists that show attributes and their value types.
 *
 * @return the renderer, never {@code null}
 */
private DefaultListCellRenderer createAttributeTypeListRenderer() {
	return new DefaultListCellRenderer() {

		@Override
		public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
			JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
			String stringValue = (String) value;
			Integer type = valueTypeMap.get(stringValue);
			if (type != null) {
				Icon icon;
				if (Ontology.ATTRIBUTE_VALUE_TYPE.isA(type, Ontology.NUMERICAL)) {
					icon = AttributeGuiTools.NUMERICAL_COLUMN_ICON;
				} else if (Ontology.ATTRIBUTE_VALUE_TYPE.isA(type, Ontology.NOMINAL)) {
					icon = AttributeGuiTools.NOMINAL_COLUMN_ICON;
				} else if (Ontology.ATTRIBUTE_VALUE_TYPE.isA(type, Ontology.DATE_TIME)) {
					icon = AttributeGuiTools.DATE_COLUMN_ICON;
				} else {
					// attribute value type
					icon = AttributeGuiTools.UNKNOWN_COLUMN_ICON;
				}
				label.setIcon(icon);
			}
			return label;
		}
	};
}
 
Example #20
Source File: ChooserTreeView.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
public Component getListCellRendererComponent(JList   list,
					  Object  value,
					  int     index,
					  boolean isSelected,
					  boolean cellHasFocus)
   {
     DefaultListCellRenderer result = 
(DefaultListCellRenderer)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
     
     result.setIcon(tree.isLeaf(value) ? 
	     MetalIconFactory.getTreeLeafIcon() :
	     MetalIconFactory.getTreeFolderIcon());
     
     return result;
   }
 
Example #21
Source File: Import9Patch.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
private void pickDirectoryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pickDirectoryActionPerformed
        File[] result = ResourceEditorView.showOpenFileChooserWithTitle("Select The Directory", true, "Directory");
        if(result != null && result.length == 1) {
            imageDirectory.setText(result[0].getAbsolutePath());
        }
        
        File drawableHdpi = new File(imageDirectory.getText() + File.separator + "drawable-hdpi");
        File[] potentials = drawableHdpi.listFiles(new FileFilter() {
                @Override
                public boolean accept(File file) {
                    return file.getName().endsWith(".9.png");
                }
            });

        if(potentials == null || potentials.length == 0) {
            JOptionPane.showMessageDialog(this, "Can't find 9-patch files in the hdpi directory", "Error", JOptionPane.ERROR_MESSAGE);
            return;
        }

        imagesCombo.setRenderer(new DefaultListCellRenderer() {

            @Override
            public Component getListCellRendererComponent(JList jlist, Object o, int i, boolean bln, boolean bln1) {
                if(o instanceof File) {
                    o = ((File)o).getName();
                }
                return super.getListCellRendererComponent(jlist, o, i, bln, bln1);
            }
        });
        imagesCombo.setModel(new DefaultComboBoxModel(potentials));        
}
 
Example #22
Source File: TranslationPanel.java    From magarena with GNU General Public License v3.0 5 votes vote down vote up
private DefaultListCellRenderer getLanguageComboRenderer() {
    return new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            String lang = value.toString();
            String newValue = (lang + " " + MText.getTranslationVersion(lang)).trim();
            return super.getListCellRendererComponent(list, newValue, index, isSelected, cellHasFocus);
        }
    };
}
 
Example #23
Source File: AttributeValueCellEditor.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Create a list cell renderer for lists that show attributes and their value types.
 *
 * @return the renderer, never {@code null}
 */
private DefaultListCellRenderer createAttributeTypeListRenderer(AttributeComboBox.AttributeComboBoxModel model) {
	return new DefaultListCellRenderer() {

		@Override
		public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
			JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
			Pair<String, Integer> valueTypePair = index >= 0 ? model.getAttributePairs().get(index) : null;
			if (valueTypePair != null) {
				Integer type = valueTypePair.getSecond();
				if (type != null) {
					Icon icon;
					if (Ontology.ATTRIBUTE_VALUE_TYPE.isA(type, Ontology.NUMERICAL)) {
						icon = AttributeGuiTools.NUMERICAL_COLUMN_ICON;
					} else if (Ontology.ATTRIBUTE_VALUE_TYPE.isA(type, Ontology.NOMINAL)) {
						icon = AttributeGuiTools.NOMINAL_COLUMN_ICON;
					} else if (Ontology.ATTRIBUTE_VALUE_TYPE.isA(type, Ontology.DATE_TIME)) {
						icon = AttributeGuiTools.DATE_COLUMN_ICON;
					} else {
						// attribute value type
						icon = AttributeGuiTools.UNKNOWN_COLUMN_ICON;
					}
					label.setIcon(icon);
				}
			}
			return label;
		}
	};
}
 
Example #24
Source File: DuelPropertiesDialog.java    From magarena with GNU General Public License v3.0 5 votes vote down vote up
public DuelPropertiesDialog(
    final int handSize,
    final int initialLife,
    final int maxGames,
    final MagicFormat cube
) {

    super(MText.get(_S1), new Dimension(380, 260));

    lifeSliderPanel = new SliderPanel(MText.get(_S2), (MagicSystem.isDevMode() ? 1 : 10), 30, 5, initialLife, false);
    handSizeSliderPanel = new SliderPanel(MText.get(_S3), 6, 8, 1, handSize);
    winsSliderPanel = new SliderPanel(MText.get(_S4), 1, 11, 2, maxGames);

    cubeComboBox = new JComboBox<>(MagicFormat.getDuelFormatsArray());
    cubeComboBox.setLightWeightPopupEnabled(false);
    cubeComboBox.setFocusable(false);
    cubeComboBox.setSelectedItem(cube);
    cubeComboBox.setRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            MagicFormat fmt = (MagicFormat)value;
            value = fmt.getLabel();
            return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        }
    });

    refreshLayout();
    setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));

    setVisible(true);
}
 
Example #25
Source File: VariableSelectionPane.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private void createPane() {
    final TableLayout tableLayout = new TableLayout(1);
    tableLayout.setTableAnchor(TableLayout.Anchor.NORTHWEST);
    tableLayout.setTableFill(TableLayout.Fill.BOTH);
    tableLayout.setTablePadding(4, 4);
    tableLayout.setTableWeightY(1.0);
    tableLayout.setTableWeightX(1.0);
    setLayout(tableLayout);
    variableList = new CheckBoxList(model);
    variableList.setCellRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                                                      boolean cellHasFocus) {
            JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected,
                                                                       cellHasFocus);
            if (value instanceof Variable) {
                Variable variable = (Variable) value;
                label.setText(variable.getName());
            }
            return label;

        }
    });
    variableList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    checkBoxSelectionListener = new CheckBoxSelectionListener(variableList);
    variableList.getCheckBoxListSelectionModel().addListSelectionListener(checkBoxSelectionListener);
    add(new JScrollPane(variableList));
}
 
Example #26
Source File: RoiMaskSelector.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public RoiMaskSelector(BindingContext bindingContext) {
    final Property useRoiMaskProperty = bindingContext.getPropertySet().getProperty(PROPERTY_NAME_USE_ROI_MASK);
    Assert.argument(useRoiMaskProperty != null, "bindingContext");
    Assert.argument(useRoiMaskProperty.getType().equals(Boolean.class) || useRoiMaskProperty.getType() == Boolean.TYPE, "bindingContext");
    Assert.argument(bindingContext.getPropertySet().getProperty(PROPERTY_NAME_ROI_MASK) != null, "bindingContext");
    Assert.argument(bindingContext.getPropertySet().getProperty(PROPERTY_NAME_ROI_MASK).getType().equals(Mask.class), "bindingContext");

    this.productNodeListener = new PNL();
    this.bindingContext = bindingContext;
    useRoiMaskCheckBox = new JCheckBox("Use ROI mask:");
    roiMaskComboBox = new JComboBox();
    roiMaskComboBox.setRenderer(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 != null) {
                this.setText(((Mask) value).getName());
            }
            return this;
        }
    });

    this.showMaskManagerButton = createShowMaskManagerButton();

    bindingContext.bind(PROPERTY_NAME_USE_ROI_MASK, useRoiMaskCheckBox);
    bindingContext.bind(PROPERTY_NAME_ROI_MASK, roiMaskComboBox);

    bindingContext.bindEnabledState(PROPERTY_NAME_USE_ROI_MASK, true, createUseRoiCondition());
    bindingContext.bindEnabledState(PROPERTY_NAME_ROI_MASK, true, createEnableMaskDropDownCondition());
}
 
Example #27
Source File: JFontChooser.java    From Luyten with Apache License 2.0 5 votes vote down vote up
public JList<?> getFontFamilyList() {
	if (fontNameList == null) {
		fontNameList = new JList<Object>(getFontFamilies());
		fontNameList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		fontNameList.addListSelectionListener(new ListSelectionHandler(getFontFamilyTextField()));
		fontNameList.setSelectedIndex(0);

		// Draw Fonts
		fontNameList.setCellRenderer(new DefaultListCellRenderer() {
			/**
			 * 
			 */
			private static final long serialVersionUID = -6753380853569310954L;

			public Component getListCellRendererComponent(JList<?> list, Object value, int index,
					boolean isSelected, boolean cellHasFocus) {

				JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent(list, value, index,
						isSelected, cellHasFocus);

				if (value instanceof String) {
					renderer.setText((String) value);
					renderer.setFont(new Font((String) value, DEFAULT_FONT.getStyle(), DEFAULT_FONT.getSize() + 2));
				} else {
					renderer.setText("");
				}
				return renderer;
			}
		});
		fontNameList.setFocusable(false);
	}
	return fontNameList;
}
 
Example #28
Source File: JFontChooser.java    From Luyten with Apache License 2.0 5 votes vote down vote up
public JList<?> getFontStyleList() {
	if (fontStyleList == null) {
		fontStyleList = new JList<Object>(getFontStyleNames());
		fontStyleList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		fontStyleList.addListSelectionListener(new ListSelectionHandler(getFontStyleTextField()));
		fontStyleList.setSelectedIndex(0);
		fontStyleList.setFocusable(false);
		fontStyleList.setCellRenderer(new DefaultListCellRenderer() {
			/**
			 * 
			 */
			private static final long serialVersionUID = -3904668242514776943L;

			public Component getListCellRendererComponent(JList<?> list, Object value, int index,
					boolean isSelected, boolean cellHasFocus) {

				JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent(list, value, index,
						isSelected, cellHasFocus);

				if (value instanceof String) {
					renderer.setText((String) value);
					renderer.setFont(
							new Font(DEFAULT_FONT.getName(), FONT_STYLE_CODES[index], DEFAULT_FONT.getSize() + 2));
				} else {
					renderer.setText("");
				}
				return renderer;
			}
		});
	}
	return fontStyleList;
}
 
Example #29
Source File: ComponentListCellRenderer.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public ComponentListCellRenderer( final Class aComponentType ) {
  try {
    setLayout( new BorderLayout() );
    defaultComp = new DefaultListCellRenderer();
    abstractButton = (AbstractButton) aComponentType.newInstance();
    add( abstractButton );
  } catch ( Exception e ) {
    throw new IllegalStateException( "Unable to continue" + e );
  }
}
 
Example #30
Source File: XComboBox.java    From scelight with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link XComboBox}.
 * 
 * @param items initial items to be added to the combo box
 */
public XComboBox( final Vector< E > items ) {
	super( new XComboBoxModel<>( items ) );
	
	comboBoxModel = (XComboBoxModel< E >) getModel();
	
	setMaximumRowCount( 14 );
	
	setRenderer( new DefaultListCellRenderer() {
		@Override
		public Component getListCellRendererComponent( final JList< ? > list, final Object value, final int index, final boolean isSelected,
		        final boolean cellHasFocus ) {
			if ( value instanceof JComponent )
				return (JComponent) value;
			
			final boolean itemEnabled = !comboBoxModel.isItemDisabled( value );
			
			super.getListCellRendererComponent( list, value, index, isSelected && itemEnabled, cellHasFocus );
			
			ToLabelRenderer.render( this, value, isSelected, cellHasFocus );
			
			// Set cell value as tool tip if it's truncated (due to not fitting into into the cell's area).
			final int comboWidth = XComboBox.this.getWidth();
			if ( getToolTipText() == null && comboWidth > 0 && getPreferredSize().width > comboWidth )
				setToolTipText( value.toString() );
			
			if ( separatedItemSet != null && separatedItemSet.contains( value ) )
				setBorder( SEPARATOR_BORDER );
			
			setEnabled( itemEnabled );
			
			return this;
		}
	} );
}