protected Color defaultActionForeground(boolean isSelected, Presentation presentation) { return isSelected ? UIUtil.getListSelectionForeground() : presentation.isEnabled() && presentation.isVisible() ? UIUtil.getListForeground() : UIUtil.getInactiveTextColor(); }
@Override protected JComponent createCenterPanel() { final int selectionMode = myAllowMultipleSelections ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION : ListSelectionModel.SINGLE_SELECTION; myList.setSelectionMode(selectionMode); if (myUseIdeaEditor) { EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); myList.setFont(scheme.getFont(EditorFontType.PLAIN)); Color fg = ObjectUtils.chooseNotNull(scheme.getDefaultForeground(), UIUtil.getListForeground()); Color bg = ObjectUtils.chooseNotNull(scheme.getDefaultBackground(), UIUtil.getListBackground()); myList.setForeground(fg); myList.setBackground(bg); } new DoubleClickListener() { @Override protected boolean onDoubleClick(MouseEvent e) { close(OK_EXIT_CODE); return true; } }.installOn(myList); myList.setCellRenderer(new MyListCellRenderer()); myList.addKeyListener( new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_DELETE) { int newSelectionIndex = -1; for (Object o : myList.getSelectedValues()) { int i = ((Item) o).index; removeContentAt(myAllContents.get(i)); if (newSelectionIndex < 0) { newSelectionIndex = i; } } rebuildListContent(); if (myAllContents.isEmpty()) { close(CANCEL_EXIT_CODE); return; } newSelectionIndex = Math.min(newSelectionIndex, myAllContents.size() - 1); myList.setSelectedIndex(newSelectionIndex); } else if (e.getKeyCode() == KeyEvent.VK_ENTER) { doOKAction(); } else { final char aChar = e.getKeyChar(); if (aChar >= '0' && aChar <= '9') { int idx = aChar == '0' ? 9 : aChar - '1'; if (idx < myAllContents.size()) { myList.setSelectedIndex(idx); e.consume(); doOKAction(); } } } } }); mySplitter.setFirstComponent( ListWithFilter.wrap( myList, ScrollPaneFactory.createScrollPane(myList), new Function<Object, String>() { @Override public String fun(Object o) { return ((Item) o).longText; } })); mySplitter.setSecondComponent(new JPanel()); rebuildListContent(); ScrollingUtil.installActions(myList); ScrollingUtil.ensureSelectionExists(myList); updateViewerForSelection(); myList.addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { myUpdateAlarm.cancelAllRequests(); myUpdateAlarm.addRequest( new Runnable() { @Override public void run() { updateViewerForSelection(); } }, 100); } }); mySplitter.setPreferredSize(JBUI.size(500, 500)); SplitterProportionsData d = new SplitterProportionsDataImpl(); d.externalizeToDimensionService(getClass().getName()); d.restoreSplitterProportions(mySplitter); return mySplitter; }
/** @author yole */ public class ReadOnlyStatusDialog extends OptionsDialog { static final SimpleTextAttributes BOLD_ATTRIBUTES = new SimpleTextAttributes(SimpleTextAttributes.STYLE_BOLD, UIUtil.getListForeground()); static final SimpleTextAttributes SELECTED_BOLD_ATTRIBUTES = new SimpleTextAttributes( SimpleTextAttributes.STYLE_BOLD, UIUtil.getListSelectionForeground()); private JPanel myTopPanel; private JList myFileList; private JRadioButton myUsingFileSystemRadioButton; private JRadioButton myUsingVcsRadioButton; private JComboBox myChangelist; private FileInfo[] myFiles; public ReadOnlyStatusDialog(Project project, final FileInfo[] files) { super(project); myFiles = files; initFileList(); ActionListener listener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { myChangelist.setEnabled(myUsingVcsRadioButton.isSelected()); } }; myUsingVcsRadioButton.addActionListener(listener); myUsingFileSystemRadioButton.addActionListener(listener); if (myUsingVcsRadioButton.isEnabled()) { myUsingVcsRadioButton.setSelected(true); } else { myUsingFileSystemRadioButton.setSelected(true); } myChangelist.setEnabled(myUsingVcsRadioButton.isSelected()); myFileList.setCellRenderer(new FileListRenderer()); setTitle(VcsBundle.message("dialog.title.clear.read.only.file.status")); init(); } @Override public long getTypeAheadTimeoutMs() { return Registry.intValue("actionSystem.typeAheadTimeBeforeDialog"); } private void initFileList() { myFileList.setModel( new AbstractListModel() { public int getSize() { return myFiles.length; } public Object getElementAt(final int index) { return myFiles[index].getFile(); } }); boolean hasVcs = false; for (FileInfo info : myFiles) { if (info.hasVersionControl()) { hasVcs = true; HandleType handleType = info.getSelectedHandleType(); List<String> changelists = handleType.getChangelists(); final String defaultChangelist = handleType.getDefaultChangelist(); myChangelist.setModel(new CollectionComboBoxModel(changelists, defaultChangelist)); myChangelist.setRenderer( new ColoredListCellRendererWrapper<String>() { @Override protected void doCustomize( JList list, String value, int index, boolean selected, boolean hasFocus) { if (value == null) return; String trimmed = StringUtil.first(value, 50, true); if (value.equals(defaultChangelist)) { append(trimmed, selected ? SELECTED_BOLD_ATTRIBUTES : BOLD_ATTRIBUTES); } else { append( trimmed, selected ? SimpleTextAttributes.SELECTED_SIMPLE_CELL_ATTRIBUTES : SimpleTextAttributes.SIMPLE_CELL_ATTRIBUTES); } } }); break; } } myUsingVcsRadioButton.setEnabled(hasVcs); } protected boolean isToBeShown() { return ((ReadonlyStatusHandlerImpl) ReadonlyStatusHandler.getInstance(myProject)) .getState() .SHOW_DIALOG; } protected void setToBeShown(boolean value, boolean onOk) { if (onOk) { ((ReadonlyStatusHandlerImpl) ReadonlyStatusHandler.getInstance(myProject)) .getState() .SHOW_DIALOG = value; } } protected boolean shouldSaveOptionsOnCancel() { return false; } @Nullable protected JComponent createCenterPanel() { return myTopPanel; } @Override @NonNls protected String getDimensionServiceKey() { return "vcs.readOnlyHandler.ReadOnlyStatusDialog"; } protected void doOKAction() { for (FileInfo info : myFiles) { if (myUsingFileSystemRadioButton.isSelected()) { info.getHandleType().selectFirst(); } else if (info.hasVersionControl()) { info.getHandleType().select(info.getHandleType().get(1)); } } ArrayList<FileInfo> files = new ArrayList<FileInfo>(); Collections.addAll(files, myFiles); String changelist = (String) myChangelist.getSelectedItem(); ReadonlyStatusHandlerImpl.processFiles(files, changelist); if (files.isEmpty()) { super.doOKAction(); } else { myFiles = files.toArray(new FileInfo[files.size()]); initFileList(); } } @Override @Nullable public JComponent getPreferredFocusedComponent() { final JRootPane pane = getRootPane(); return pane != null ? pane.getDefaultButton() : null; } }