Java Code Examples for com.intellij.ui.components.JBList#setCellRenderer()

The following examples show how to use com.intellij.ui.components.JBList#setCellRenderer() . 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: GenerateDialog.java    From android-parcelable-intellij-plugin with Apache License 2.0 6 votes vote down vote up
protected GenerateDialog(final PsiClass psiClass) {
    super(psiClass.getProject());
    setTitle("Select Fields for Parcelable Generation");

    fieldsCollection = new CollectionListModel<PsiField>();
    final JBList fieldList = new JBList(fieldsCollection);
    fieldList.setCellRenderer(new DefaultPsiElementCellRenderer());
    final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(fieldList).disableAddAction();
    final JPanel panel = decorator.createPanel();

    fieldsComponent = LabeledComponent.create(panel, "Fields to include in Parcelable");

    includeSubclasses = new JBCheckBox("Include fields from base classes");
    setupCheckboxClickAction(psiClass);
    showCheckbox = psiClass.getFields().length != psiClass.getAllFields().length;

    updateFieldsDisplay(psiClass);
    init();
}
 
Example 2
Source File: CustomActionSettingsForm.java    From StringManipulation with Apache License 2.0 6 votes vote down vote up
private JBList createJBList(DefaultListModel pluginsModel) {
	JBList jbList = new JBList(pluginsModel);
	jbList.setCellRenderer(new DefaultListCellRenderer() {
		@Override
		public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
													  boolean cellHasFocus) {
			final Component comp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
			CustomActionModel goal = (CustomActionModel) value;
			setText(goal.getName());
			return comp;
		}
	});
	jbList.setDragEnabled(true);
	jbList.setDropMode(DropMode.INSERT);
	jbList.setTransferHandler(new MyListDropHandler(jbList));

	new MyDragListener(jbList);
	return jbList;
}
 
Example 3
Source File: HaxeRestoreReferencesDialog.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
@Override
protected JComponent createCenterPanel() {
  final JPanel panel = new JPanel(new BorderLayout(UIUtil.DEFAULT_HGAP, UIUtil.DEFAULT_VGAP));
  myList = new JBList((Object[])myNamedElements);
  myList.setCellRenderer(new FQNameCellRenderer());
  panel.add(ScrollPaneFactory.createScrollPane(myList), BorderLayout.CENTER);

  panel.add(new JBLabel(CodeInsightBundle.message("dialog.paste.on.import.text"), SMALL, BRIGHTER), BorderLayout.NORTH);

  final JPanel buttonPanel = new JPanel(new VerticalFlowLayout());
  final JButton okButton = new JButton(CommonBundle.getOkButtonText());
  getRootPane().setDefaultButton(okButton);
  buttonPanel.add(okButton);
  final JButton cancelButton = new JButton(CommonBundle.getCancelButtonText());
  buttonPanel.add(cancelButton);

  panel.setPreferredSize(new Dimension(500, 400));

  return panel;
}
 
Example 4
Source File: FileChooserDialogImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void showRecentFilesPopup() {
  final JBList files = new JBList(getRecentFiles()) {
    @Override
    public Dimension getPreferredSize() {
      return new Dimension(myPathTextField.getField().getWidth(), super.getPreferredSize().height);
    }
  };
  files.setCellRenderer(new ColoredListCellRenderer() {
    @Override
    protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) {
      final String path = value.toString();
      append(path);
      final VirtualFile file = LocalFileSystem.getInstance().findFileByIoFile(new File(path));
      if (file != null) {
        setIcon(VfsIconUtil.getIcon(file, Iconable.ICON_FLAG_READ_STATUS, null));
      }
    }
  });
  JBPopupFactory.getInstance().createListPopupBuilder(files).setItemChoosenCallback(new Runnable() {
    @Override
    public void run() {
      myPathTextField.getField().setText(files.getSelectedValue().toString());
    }
  }).createPopup().showUnderneathOf(myPathTextField.getField());
}
 
Example 5
Source File: ChatUserForm.java    From floobits-intellij with Apache License 2.0 6 votes vote down vote up
private void createUIComponents() {
    gravatarContainer = new ClickPanel(new Runnable() {
        @Override
        public void run() {
            FlooHandler flooHandler = context.getFlooHandler();
            if (flooHandler == null) {
                return;
            }
            flooHandler.editorEventHandler.goToLastHighlight(username);
        }
    });
    subContainer = new JPanel();
    clientModel = new DefaultListModel();
    clientList = new JBList();
    clientList.setOpaque(false);
    clientList.setModel(clientModel);
    clientList.setCellRenderer(new ClientCellRenderer());
    menuPopup = new JPopupMenu();
    subContainer.setComponentPopupMenu(menuPopup);
    clientList.setComponentPopupMenu(menuPopup);
    gravatarContainer.setComponentPopupMenu(menuPopup);
}
 
Example 6
Source File: NewItemWithTemplatesPopupPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private JBList<T> createTemplatesList(@Nonnull ListModel<T> model, ListCellRenderer<T> renderer) {
  JBList<T> list = new JBList<>(model);
  MouseAdapter mouseListener = new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent e) {
      if (myApplyAction != null && e.getClickCount() > 1) myApplyAction.consume(e);
    }
  };

  list.addMouseListener(mouseListener);
  list.setCellRenderer(renderer);
  list.setFocusable(false);
  list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

  Border border = JBUI.Borders.merge(JBUI.Borders.emptyLeft(JBUIScale.scale(5)), JBUI.Borders.customLine(JBUI.CurrentTheme.NewClassDialog.bordersColor(), 1, 0, 0, 0), true);
  list.setBorder(border);
  return list;
}
 
Example 7
Source File: ApplicationSettingsForm.java    From MavenHelper with Apache License 2.0 6 votes vote down vote up
private JBList createJBList(DefaultListModel pluginsModel) {
	JBList jbList = new JBList(pluginsModel);
	jbList.setCellRenderer(new DefaultListCellRenderer() {
		@Override
		public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
													  boolean cellHasFocus) {
			final Component comp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
			Goal goal = (Goal) value;

			setText(goal.getPresentableName());
			return comp;
		}
	});
	jbList.setDragEnabled(true);
	jbList.setDropMode(DropMode.INSERT);
	jbList.setTransferHandler(new MyListDropHandler(jbList));

	new MyDragListener(jbList);
	return jbList;
}
 
Example 8
Source File: ProjectLibraryTabContext.java    From consulo with Apache License 2.0 6 votes vote down vote up
public ProjectLibraryTabContext(final ClasspathPanel classpathPanel, StructureConfigurableContext context) {
  super(classpathPanel, context);

  StructureLibraryTableModifiableModelProvider projectLibrariesProvider = context.getProjectLibrariesProvider();
  Library[] libraries = projectLibrariesProvider.getModifiableModel().getLibraries();
  final Condition<Library> condition = LibraryEditingUtil.getNotAddedLibrariesCondition(myClasspathPanel.getRootModel());

  myItems = ContainerUtil.filter(libraries, condition);
  ContainerUtil.sort(myItems, new Comparator<Library>() {
    @Override
    public int compare(Library o1, Library o2) {
      return StringUtil.compare(o1.getName(), o2.getName(), false);
    }
  });

  myLibraryList = new JBList(myItems);
  myLibraryList.setCellRenderer(new ColoredListCellRendererWrapper<Library>() {
    @Override
    protected void doCustomize(JList list, Library value, int index, boolean selected, boolean hasFocus) {
      final CellAppearanceEx appearance = OrderEntryAppearanceService.getInstance().forLibrary(classpathPanel.getProject(), value, false);

      appearance.customize(this);
    }
  });
  new ListSpeedSearch(myLibraryList);
}
 
Example 9
Source File: IgnoredSettingsPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
public IgnoredSettingsPanel(Project project) {
  myList = new JBList();
  myList.setCellRenderer(new MyCellRenderer());
  myList.getEmptyText().setText(VcsBundle.message("no.ignored.files"));

  myProject = project;
  myChangeListManager = ChangeListManagerImpl.getInstanceImpl(myProject);
}
 
Example 10
Source File: RunConfigurationBeforeRunProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected JComponent createCenterPanel() {
  myJBList = new JBList(mySettings);
  myJBList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  myJBList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
    @Override
    public void valueChanged(ListSelectionEvent e) {
      Object selectedValue = myJBList.getSelectedValue();
      if (selectedValue instanceof RunnerAndConfigurationSettings) {
        mySelectedSettings = (RunnerAndConfigurationSettings)selectedValue;
      }
      else {
        mySelectedSettings = null;
      }
      setOKActionEnabled(mySelectedSettings != null);
    }
  });
  myJBList.setCellRenderer(new ColoredListCellRenderer() {
    @Override
    protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) {
      if (value instanceof RunnerAndConfigurationSettings) {
        RunnerAndConfigurationSettings settings = (RunnerAndConfigurationSettings)value;
        RunManagerEx runManager = RunManagerEx.getInstanceEx(myProject);
        setIcon(runManager.getConfigurationIcon(settings));
        RunConfiguration configuration = settings.getConfiguration();
        append(configuration.getName(), settings.isTemporary() ? SimpleTextAttributes.GRAY_ATTRIBUTES : SimpleTextAttributes.REGULAR_ATTRIBUTES);
      }
    }
  });
  return new JBScrollPane(myJBList);
}
 
Example 11
Source File: CompoundRunConfigurationSettingsEditor.java    From consulo with Apache License 2.0 5 votes vote down vote up
public CompoundRunConfigurationSettingsEditor(@Nonnull Project project) {
  myRunManager = RunManagerImpl.getInstanceImpl(project);
  myModel = new SortedListModel<>(CompoundRunConfiguration.COMPARATOR);
  myList = new JBList(myModel);
  myList.setCellRenderer(new ColoredListCellRenderer() {
    @Override
    protected void customizeCellRenderer(@Nonnull JList list, Object value, int index, boolean selected, boolean hasFocus) {
      RunConfiguration configuration = myModel.get(index);
      setIcon(configuration.getType().getIcon());
      append(configuration.getType().getDisplayName() + " '" + configuration.getName() + "'");
    }
  });
  myList.setVisibleRowCount(15);
}
 
Example 12
Source File: ModuleDependencyTabContext.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ModuleDependencyTabContext(ClasspathPanel panel, StructureConfigurableContext context) {
  super(panel, context);
  myNotAddedModules = getNotAddedModules();
  myModuleList = new JBList(myNotAddedModules);
  myModuleList.setCellRenderer(new ModuleListCellRenderer());

  new ListSpeedSearch(myModuleList);
}
 
Example 13
Source File: CourseTabFactory.java    From tmc-intellij with MIT License 5 votes vote down vote up
public void createCourseSpecificTab(
        ObjectFinder finder,
        ProjectOpener opener,
        String course,
        JTabbedPane tabbedPaneBase,
        CourseAndExerciseManager courseAndExerciseManager) {
    logger.info("Creating course specific tab. @CourseTabFactory");
    final JBScrollPane panel = new JBScrollPane();
    final JBList list = new JBList();
    list.setCellRenderer(new ProjectListRenderer());

    DefaultListModel defaultListModel = new DefaultListModel();
    panel.setBorder(BorderFactory.createTitledBorder(""));

    ProjectListManagerHolder.get()
            .addExercisesToList(finder, course, defaultListModel, courseAndExerciseManager);

    if (defaultListModel.getSize() <= 0) {
        return;
    }

    list.setName(course);
    list.setModel(defaultListModel);

    MouseListener mouseListener = createMouseListenerForWindow(opener, panel, list);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.addMouseListener(mouseListener);

    panel.setName(course);
    panel.setViewportView(list);

    ProjectListManagerHolder.get().addList(list);
    tabbedPaneBase.addTab(course, panel);
    tabbedPaneBase.addMouseListener(tabMouseListener(tabbedPaneBase));
    setScrollBarToBottom(course, tabbedPaneBase, panel);
}
 
Example 14
Source File: ColumnFilteringStrategy.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ColumnFilteringStrategy(final ChangeListColumn column,
                               final Class<? extends CommittedChangesProvider> providerClass) {
  myModel = new MyListModel();
  myValueList = new JBList();
  myScrollPane = ScrollPaneFactory.createScrollPane(myValueList);
  myValueList.setModel(myModel);
  myValueList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
    public void valueChanged(final ListSelectionEvent e) {
      for (ChangeListener listener : myListeners) {
        listener.stateChanged(new ChangeEvent(this));
      }
    }
  });
  myValueList.setCellRenderer(new ColoredListCellRenderer() {
    protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) {
      if (index == 0) {
        append(value.toString(), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
      }
      else if (value.toString().length() == 0) {
        append(VcsBundle.message("committed.changes.filter.none"), SimpleTextAttributes.GRAYED_ATTRIBUTES);
      }
      else {
        append(value.toString(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
      }
    }
  });
  myColumn = column;
  myProviderClass = providerClass;
}
 
Example 15
Source File: GuiForm.java    From MavenHelper with Apache License 2.0 5 votes vote down vote up
private void createUIComponents() {
	listDataModel = new DefaultListModel();
	leftPanelList = new JBList(listDataModel);
	leftPanelList.addListSelectionListener(new MyListSelectionListener());
	// no generics in IJ12
	leftPanelList.setCellRenderer(new ColoredListCellRenderer() {
		@Override
		protected void customizeCellRenderer(JList jList, Object o, int i, boolean b, boolean b2) {
			MyListNode value = (MyListNode) o;
			String rightVersion = value.getRightVersion();
			final String[] split = value.key.split(":");
			boolean conflict = value.isConflict();

			SimpleTextAttributes attributes = SimpleTextAttributes.REGULAR_ATTRIBUTES;
			SimpleTextAttributes boldAttributes = SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES;
			if (conflict && allDependenciesAsListRadioButton.isSelected()) {
				attributes = SimpleTextAttributes.ERROR_ATTRIBUTES;
				boldAttributes = errorBoldAttributes;
			}

			if (showGroupId.isSelected()) {
				append(split[0] + " : ", attributes);
			}
			append(split[1], boldAttributes);
			append(" : " + rightVersion, attributes);

		}
	});
	rightTree = new MyHighlightingTree(project);
	leftTree = new MyHighlightingTree(project);
}
 
Example 16
Source File: DataSourceListPanel.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
private JBList prepareDataSourcesList(DefaultListModel dataSourcesListModel) {
    final JBList dataSourcesList = new JBList(dataSourcesListModel);
    dataSourcesList.getEmptyText().setText("No data sources defined");
    dataSourcesList.setDragEnabled(false);
    dataSourcesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    dataSourcesList.setCellRenderer(new DataSourceConfigurationCellRenderer());
    dataSourcesList.addListSelectionListener(getSelectionChangedListener());
    return dataSourcesList;
}
 
Example 17
Source File: SubclassTestChooser.java    From intellij with Apache License 2.0 5 votes vote down vote up
static void chooseSubclass(
    ConfigurationContext context,
    PsiClass testClass,
    Consumer<PsiClass> callbackOnClassSelection) {
  List<PsiClass> classes = findTestSubclasses(testClass);
  if (!testClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
    classes.add(testClass);
  }
  if (classes.isEmpty()) {
    return;
  }
  if (classes.size() == 1) {
    callbackOnClassSelection.accept(classes.get(0));
    return;
  }
  PsiClassListCellRenderer renderer = new PsiClassListCellRenderer();
  classes.sort(renderer.getComparator());
  JBList<PsiClass> list = new JBList<>(classes);
  list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  list.setCellRenderer(renderer);
  JBPopupFactory.getInstance()
      .createListPopupBuilder(list)
      .setTitle("Choose test class to run")
      .setMovable(false)
      .setResizable(false)
      .setRequestFocus(true)
      .setCancelOnWindowDeactivation(false)
      .setItemChoosenCallback(
          () -> callbackOnClassSelection.accept((PsiClass) list.getSelectedValue()))
      .createPopup()
      .showInBestPositionFor(context.getDataContext());
}
 
Example 18
Source File: ChooseOneOrAllRunnable.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
  if (myClasses.length == 1) {
    //TODO: cdr this place should produce at least warning
    // selected(myClasses[0]);
    selected((T[])ArrayUtil.toObjectArray(myClasses[0].getClass(), myClasses[0]));
  }
  else if (myClasses.length > 0) {
    PsiElementListCellRenderer<T> renderer = createRenderer();

    Arrays.sort(myClasses, renderer.getComparator());

    if (ApplicationManager.getApplication().isUnitTestMode()) {
      selected(myClasses);
      return;
    }
    Vector<Object> model = new Vector<Object>(Arrays.asList(myClasses));
    model.insertElementAt(CodeInsightBundle.message("highlight.thrown.exceptions.chooser.all.entry"), 0);

    myList = new JBList(model);
    myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    myList.setCellRenderer(renderer);

    final PopupChooserBuilder builder = new PopupChooserBuilder(myList);
    renderer.installSpeedSearch(builder);

    final Runnable callback = new Runnable() {
      @Override
      public void run() {
        int idx = myList.getSelectedIndex();
        if (idx < 0) return;
        if (idx > 0) {
          selected((T[])ArrayUtil.toObjectArray(myClasses[idx-1].getClass(), myClasses[idx-1]));
        }
        else {
          selected(myClasses);
        }
      }
    };

    ApplicationManager.getApplication().invokeLater(new Runnable() {
      @Override
      public void run() {
        builder.
          setTitle(myTitle).
          setItemChoosenCallback(callback).
          createPopup().
          showInBestPositionFor(myEditor);
      }
    });
  }
}
 
Example 19
Source File: FocusDebugger.java    From consulo with Apache License 2.0 3 votes vote down vote up
private JComponent init() {
  final JPanel result = new JPanel(new BorderLayout());

  myLogModel = new DefaultListModel();
  myLog = new JBList(myLogModel);
  myLog.setCellRenderer(new FocusElementRenderer());


  myAllocation = new JEditorPane();
  final DefaultCaret caret = new DefaultCaret();
  myAllocation.setCaret(caret);
  caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
  myAllocation.setEditable(false);


  final Splitter splitter = new Splitter(true);
  splitter.setFirstComponent(ScrollPaneFactory.createScrollPane(myLog));
  splitter.setSecondComponent(ScrollPaneFactory.createScrollPane(myAllocation));

  myLog.addListSelectionListener(this);

  KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(this);

  result.add(splitter, BorderLayout.CENTER);


  final DefaultActionGroup group = new DefaultActionGroup();
  group.add(new ClearAction());

  result.add(ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true).getComponent(), BorderLayout.NORTH);

  return result;
}