public void paintEmptyText(@NotNull final JComponent splitters, @NotNull Graphics g) { UISettings.setupAntialiasing(g); g.setColor(new JBColor(Gray._80, Gray._160)); g.setFont(JBUI.Fonts.label(16f)); UIUtil.TextPainter painter = new UIUtil.TextPainter().withLineSpacing(1.8f); advertiseActions(splitters, painter); painter.draw(g, new PairFunction<Integer, Integer, Couple<Integer>>() { @Override public Couple<Integer> fun(Integer width, Integer height) { Dimension s = splitters.getSize(); int w = (s.width - width) / 2; int h = s.height * 3 / 8; // fix vertical position @ golden ratio return Couple.of(w, h); } }); }
@Override public void paint(Graphics g) { boolean isDarkBackground = UIUtil.isUnderDarcula(); UISettings.setupAntialiasing(g); g.setColor(new JBColor(isDarkBackground ? Gray._230 : Gray._80, Gray._160)); g.setFont(JBUI.Fonts.label(isDarkBackground ? 24f : 20f)); UIUtil.TextPainter painter = new UIUtil.TextPainter().withLineSpacing(1.5f); painter.withShadow(true, new JBColor(Gray._200.withAlpha(100), Gray._0.withAlpha(255))); painter.appendLine("No files are open");//.underlined(new JBColor(Gray._150, Gray._180)); painter.draw(g, new PairFunction<Integer, Integer, Couple<Integer>>() { @Override public Couple<Integer> fun(Integer width, Integer height) { Dimension s = EmptyStatePanel.this.getSize(); return Couple.of((s.width - width) / 2, (s.height - height) / 2); } }); }
@NotNull public static <E> JBIterable<E> generate(@Nullable final E first1, @Nullable final E first2, @NotNull final PairFunction<? super E, ? super E, ? extends E> generator) { if (first1 == null) return empty(); return new JBIterable<E>() { @Override public Iterator<E> iterator() { return new JBIterator<E>() { E cur1 = first1; E cur2 = first2; @Override public E nextImpl() { E result = cur1; cur1 = cur2; cur2 = generator.fun(result, cur2); if (result == null) return stop(); return result; } }; } }; }
public GutteredLanguageConsole(@NotNull String title, @NotNull Project project, @NotNull Language language, @Nullable GutterContentProvider gutterContentProvider, @Nullable final PairFunction<VirtualFile, Project, PsiFile> psiFileFactory) { super(new Helper(project, new LightVirtualFile(title, language, "")) { @NotNull @Override public PsiFile getFile() { return psiFileFactory == null ? super.getFile() : psiFileFactory.fun(virtualFile, project); } }); this.gutterContentProvider = gutterContentProvider == null ? new BasicGutterContentProvider() : gutterContentProvider; }
private static Map<String, XmlTag> findScopesWithItemRef(@Nullable PsiFile file) { if (!(file instanceof XmlFile)) return Collections.emptyMap(); final Map<String, XmlTag> result = new THashMap<String, XmlTag>(); file.accept(new XmlRecursiveElementVisitor() { @Override public void visitXmlTag(final XmlTag tag) { super.visitXmlTag(tag); XmlAttribute refAttr = tag.getAttribute(ITEM_REF); if (refAttr != null && tag.getAttribute(ITEM_SCOPE) != null) { getReferencesForAttributeValue(refAttr.getValueElement(), new PairFunction<String, Integer, PsiReference>() { @Nullable @Override public PsiReference fun(String t, Integer v) { result.put(t, tag); return null; } }); } } }); return result; }
public static PsiReference[] getReferencesForAttributeValue(@Nullable XmlAttributeValue element, PairFunction<String, Integer, PsiReference> refFun) { if (element == null) { return PsiReference.EMPTY_ARRAY; } String text = element.getText(); String urls = StringUtil.unquoteString(text); StringTokenizer tokenizer = new StringTokenizer(urls); List<PsiReference> result = new ArrayList<PsiReference>(); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); int index = text.indexOf(token); PsiReference ref = refFun.fun(token, index); if (ref != null) { result.add(ref); } } return result.toArray(new PsiReference[result.size()]); }
@Nullable private static PsiType getQualifierCastType(PsiJavaReference javaReference, CompletionParameters parameters) { if (javaReference instanceof PsiReferenceExpression) { final PsiReferenceExpression refExpr = (PsiReferenceExpression)javaReference; final PsiExpression qualifier = refExpr.getQualifierExpression(); if (qualifier != null) { final Project project = qualifier.getProject(); PsiType type = null; final PairFunction<PsiExpression, CompletionParameters, PsiType> evaluator = refExpr.getContainingFile().getCopyableUserData(DYNAMIC_TYPE_EVALUATOR); if (evaluator != null) { type = evaluator.fun(qualifier, parameters); } if (type == null) { type = GuessManager.getInstance(project).getControlFlowExpressionType(qualifier); } return type; } } return null; }
public static PsiReference[] getReferencesForAttributeValue(@Nullable XmlAttributeValue element, PairFunction<String, Integer, PsiReference> refFun) { if (element == null) { return PsiReference.EMPTY_ARRAY; } String text = element.getText(); String urls = StringUtil.stripQuotesAroundValue(text); StringTokenizer tokenizer = new StringTokenizer(urls); List<PsiReference> result = new ArrayList<PsiReference>(); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); int index = text.indexOf(token); PsiReference ref = refFun.fun(token, index); if (ref != null) { result.add(ref); } } return result.toArray(new PsiReference[result.size()]); }
@Nullable public static Object calcBinary(IElementType elementType, Object p1, Object p2) { Couple<Class> key = Couple.<Class>of(p1.getClass(), p2.getClass()); Map<IElementType, PairFunction<Object, Object, Object>> map = ourOperators.get(key); if(map == null) { return null; } PairFunction<Object, Object, Object> function = map.get(elementType); if(function == null) { return null; } return function.fun(p1, p2); }
private static void processParameterList(final DotNetParameterListOwner declaration, StringBuilder builder, char p1, char p2) { builder.append(p1); StubBlockUtil.join(builder, declaration.getParameters(), new PairFunction<StringBuilder, DotNetParameter, Void>() { @Nullable @Override @RequiredReadAction public Void fun(StringBuilder t, DotNetParameter v) { appendAttributeList(t, v); processModifierList(t, v); DotNetTypeRef typeRef = v.toTypeRef(false); appendTypeRef(declaration, t, typeRef); if(typeRef != CSharpStaticTypeRef.__ARGLIST_TYPE) { t.append(" "); appendValidName(t, v.getName()); appendInitializer(t, v); } return null; } }, ", "); builder.append(p2); }
public static int showCheckboxMessageDialog(String message, String title, @Nonnull String[] options, String checkboxText, final boolean checked, final int defaultOptionIndex, final int focusedOptionIndex, Icon icon, @Nullable final PairFunction<Integer, JCheckBox, Integer> exitFunc) { if (isApplicationInUnitTestOrHeadless()) { return ourTestImplementation.show(message); } else { TwoStepConfirmationDialog dialog = new TwoStepConfirmationDialog(message, title, options, checkboxText, checked, defaultOptionIndex, focusedOptionIndex, icon, exitFunc); dialog.show(); return dialog.getExitCode(); } }
private <T> void jumpTo(@Nonnull final T commitId, @Nonnull final PairFunction<GraphTableModel, T, Integer> rowGetter, @Nonnull final SettableFuture<Boolean> future) { if (future.isCancelled()) return; GraphTableModel model = getTable().getModel(); int row = rowGetter.fun(model, commitId); if (row >= 0) { myMainFrame.getGraphTable().jumpToRow(row); future.set(true); } else if (model.canRequestMore()) { model.requestToLoadMore(() -> jumpTo(commitId, rowGetter, future)); } else if (!myVisiblePack.isFull()) { invokeOnChange(() -> jumpTo(commitId, rowGetter, future)); } else { commitNotFound(commitId.toString()); future.set(false); } }
public static PsiReference[] getReferencesForAttributeValue(@Nullable XmlAttributeValue element, PairFunction<String, Integer, PsiReference> refFun) { if(element == null) { return PsiReference.EMPTY_ARRAY; } String text = element.getText(); String urls = StringUtil.unquoteString(text); StringTokenizer tokenizer = new StringTokenizer(urls); List<PsiReference> result = new ArrayList<>(); while(tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); int index = text.indexOf(token); PsiReference ref = refFun.fun(token, index); if(ref != null) { result.add(ref); } } return result.toArray(new PsiReference[result.size()]); }
@Nullable private static PsiType getQualifierCastType(PsiJavaReference javaReference, CompletionParameters parameters) { if(javaReference instanceof PsiReferenceExpression) { final PsiReferenceExpression refExpr = (PsiReferenceExpression) javaReference; final PsiExpression qualifier = refExpr.getQualifierExpression(); if(qualifier != null) { final Project project = qualifier.getProject(); PsiType type = null; final PairFunction<PsiExpression, CompletionParameters, PsiType> evaluator = refExpr.getContainingFile().getCopyableUserData(DYNAMIC_TYPE_EVALUATOR); if(evaluator != null) { type = evaluator.fun(qualifier, parameters); } if(type == null) { type = GuessManager.getInstance(project).getControlFlowExpressionType(qualifier); } return type; } } return null; }
@Nullable public static PsiAnnotationMemberValue setDeclaredAttributeValue(@NotNull PsiAnnotation psiAnnotation, @Nullable String attributeName, @Nullable PsiAnnotationMemberValue value, @NotNull PairFunction<Project, String, PsiAnnotation> annotationCreator) { PsiAnnotationMemberValue existing = psiAnnotation.findDeclaredAttributeValue(attributeName); if (value == null) { if (existing == null) { return null; } existing.getParent().delete(); } else { if (existing != null) { ((PsiNameValuePair)existing.getParent()).setValue(value); } else { PsiNameValuePair[] attributes = psiAnnotation.getParameterList().getAttributes(); if (attributes.length == 1) { PsiNameValuePair attribute = attributes[0]; if (attribute.getName() == null) { PsiAnnotationMemberValue defValue = attribute.getValue(); assert defValue != null : attribute; attribute.replace(createNameValuePair(defValue, PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME + "=", annotationCreator)); } } boolean allowNoName = attributes.length == 0 && ("value".equals(attributeName) || null == attributeName); final String namePrefix; if (allowNoName) { namePrefix = ""; } else { namePrefix = attributeName + "="; } psiAnnotation.getParameterList().addBefore(createNameValuePair(value, namePrefix, annotationCreator), null); } } return psiAnnotation.findDeclaredAttributeValue(attributeName); }
/** * @return true if completed, false if "too complex" */ private boolean runDfa(boolean forward, PairFunction<Instruction, BitSet, BitSet> handleState) { Set<Instruction> entryPoints = ContainerUtil.newHashSet(); if (forward) { entryPoints.add(myInstructions[0]); } else { entryPoints.addAll(ContainerUtil.findAll(myInstructions, FilteringIterator.instanceOf(ReturnInstruction.class))); } Queue<InstructionState> queue = new Queue<InstructionState>(10); for (Instruction i : entryPoints) { queue.addLast(new InstructionState(i, new BitSet())); } int limit = myForwardMap.size() * 20; Set<InstructionState> processed = ContainerUtil.newHashSet(); while (!queue.isEmpty()) { int steps = processed.size(); if (steps > limit) { return false; } if (steps % 1024 == 0) { ProgressManager.checkCanceled(); } InstructionState state = queue.pullFirst(); Instruction instruction = state.first; Collection<Instruction> nextInstructions = forward ? myForwardMap.get(instruction) : myBackwardMap.get(instruction); BitSet nextVars = handleState.fun(instruction, state.second); for (Instruction next : nextInstructions) { InstructionState nextState = new InstructionState(next, nextVars); if (processed.add(nextState)) { queue.addLast(nextState); } } } return true; }
public static int showCheckboxOkCancelDialog(String message, @Nls(capitalization = Nls.Capitalization.Title) String title, String checkboxText, final boolean checked, final int defaultOptionIndex, final int focusedOptionIndex, Icon icon) { return showCheckboxMessageDialog(message, title, new String[]{OK_BUTTON, CANCEL_BUTTON}, checkboxText, checked, defaultOptionIndex, focusedOptionIndex, icon, new PairFunction<Integer, JCheckBox, Integer>() { @Override public Integer fun(final Integer exitCode, final JCheckBox cb) { return exitCode == -1 ? CANCEL : exitCode + (cb.isSelected() ? 1 : 0); } }); }
public static int showCheckboxMessageDialog(String message, @Nls(capitalization = Nls.Capitalization.Title) String title, @NotNull String[] options, String checkboxText, final boolean checked, final int defaultOptionIndex, final int focusedOptionIndex, Icon icon, @Nullable final PairFunction<Integer, JCheckBox, Integer> exitFunc) { if (isApplicationInUnitTestOrHeadless()) { return ourTestImplementation.show(message); } else { TwoStepConfirmationDialog dialog = new TwoStepConfirmationDialog(message, title, options, checkboxText, checked, defaultOptionIndex, focusedOptionIndex, icon, exitFunc); dialog.show(); return dialog.getExitCode(); } }
public TwoStepConfirmationDialog(String message, @Nls(capitalization = Nls.Capitalization.Title) String title, @NotNull String[] options, String checkboxText, boolean checked, final int defaultOptionIndexed, final int focusedOptionIndex, Icon icon, @Nullable final PairFunction<Integer, JCheckBox, Integer> exitFunc) { myCheckboxText = checkboxText; myChecked = checked; myExitFunc = exitFunc; _init(title, message, options, defaultOptionIndexed, focusedOptionIndex, icon, null); }
@NotNull public Future<Boolean> jumpToCommit(@NotNull Hash commitHash) { SettableFuture<Boolean> future = SettableFuture.create(); jumpTo(commitHash, new PairFunction<GraphTableModel, Hash, Integer>() { @Override public Integer fun(GraphTableModel model, Hash hash) { return model.getRowOfCommit(hash); } }, future); return future; }
@NotNull public Future<Boolean> jumpToCommitByPartOfHash(@NotNull String commitHash) { SettableFuture<Boolean> future = SettableFuture.create(); jumpTo(commitHash, new PairFunction<GraphTableModel, String, Integer>() { @Override public Integer fun(GraphTableModel model, String hash) { return model.getRowOfCommitByPartOfHash(hash); } }, future); return future; }
public TableSpeedSearch(JTable table, final Convertor<Object, String> toStringConvertor) { this(table, new PairFunction<Object, Cell, String>() { @Override public String fun(Object o, Cell c) { return toStringConvertor.convert(o); } }); }
public TableSpeedSearch(JTable table, final PairFunction<Object, Cell, String> toStringConvertor) { super(table); myToStringConvertor = toStringConvertor; // edit on F2 & double click, do not interfere with quick search table.putClientProperty("JTable.autoStartsEdit", Boolean.FALSE); }
public PropertyTable() { setModel(myModel); setSelectionMode(ListSelectionModel.SINGLE_SELECTION); setShowColumns(false); setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); setShowVerticalLines(false); setIntercellSpacing(new Dimension(0, 1)); setGridColor(UIUtil.getSlightlyDarkerColor(getBackground())); setColumnSelectionAllowed(false); setCellSelectionEnabled(false); setRowSelectionAllowed(true); addMouseListener(new MouseTableListener()); mySpeedSearch = new TableSpeedSearch(this, new PairFunction<Object, Cell, String>() { @Override public String fun(Object object, Cell cell) { if (cell.column != 0) return null; if (object instanceof GroupProperty) return null; return ((Property)object).getName(); } }) { @Override protected void selectElement(Object element, String selectedText) { super.selectElement(element, selectedText); repaint(PropertyTable.this.getVisibleRect()); } }; mySpeedSearch.setComparator(new SpeedSearchComparator(false, false)); // TODO: Updates UI after LAF updated }
public static PsiReference[] getUrlReferencesForAttributeValue(final XmlAttributeValue element) { return getReferencesForAttributeValue(element, new PairFunction<String, Integer, PsiReference>() { @Nullable @Override public PsiReference fun(String token, Integer offset) { if (HtmlUtil.hasHtmlPrefix(token)) { final TextRange range = TextRange.from(offset, token.length()); final URLReference urlReference = new URLReference(element, range, true); return new DependentNSReference(element, range, urlReference, true); } return null; } }); }
private void createUIComponents() { myModulesTable = new ModuleTable(); new TableSpeedSearch(myModulesTable, new PairFunction<Object, Cell, String>() { @Override public String fun(Object o, Cell v) { if (o instanceof ModuleRow) { ModuleRow row = (ModuleRow)o; return getNameOf(row.module); } return o == null || o instanceof Boolean ? "" : o.toString(); } }); }
private void installSpeedSearch() { new TableSpeedSearch(myCommitsTable, new PairFunction<Object, Cell, String>() { @Nullable @Override public String fun(Object o, Cell cell) { return cell.column == 0 ? null : String.valueOf(o); } }); }
@NotNull public PairFunction<GrMethodCall, PsiMethod, PsiType> getReturnTypeCalculator() { if (myReturnTypeCalculatorInstance == null) { myReturnTypeCalculatorInstance = SingletonInstancesCache.getInstance(myReturnTypeCalculatorClassName, myClassLoader); } return myReturnTypeCalculatorInstance; }
public static <T> void join(StringBuilder builder, List<T> list, PairFunction<StringBuilder, T, Void> function, String dem) { for(int i = 0; i < list.size(); i++) { if(i != 0) { builder.append(dem); } T t = list.get(i); function.fun(builder, t); } }
public static <T> void join(StringBuilder builder, T[] list, PairFunction<StringBuilder, T, Void> function, String dem) { for(int i = 0; i < list.length; i++) { if(i != 0) { builder.append(dem); } T t = list[i]; function.fun(builder, t); } }
@Nullable public static PsiAnnotationMemberValue setDeclaredAttributeValue(@NotNull PsiAnnotation psiAnnotation, @Nullable String attributeName, @Nullable PsiAnnotationMemberValue value, @NotNull PairFunction<Project, String, PsiAnnotation> annotationCreator) { final PsiAnnotationMemberValue existing = psiAnnotation.findDeclaredAttributeValue(attributeName); if (value == null) { if (existing == null) { return null; } existing.getParent().delete(); } else { if (existing != null) { ((PsiNameValuePair)existing.getParent()).setValue(value); } else { final PsiNameValuePair[] attributes = psiAnnotation.getParameterList().getAttributes(); if (attributes.length == 1 && attributes[0].getName() == null) { attributes[0].replace(createNameValuePair(attributes[0].getValue(), PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME + "=", annotationCreator)); } boolean allowNoName = attributes.length == 0 && ("value".equals(attributeName) || null == attributeName); final String namePrefix; if (allowNoName) { namePrefix = ""; } else { namePrefix = attributeName + "="; } psiAnnotation.getParameterList().addBefore(createNameValuePair(value, namePrefix, annotationCreator), null); } } return psiAnnotation.findDeclaredAttributeValue(attributeName); }
public static int showCheckboxOkCancelDialog(String message, String title, String checkboxText, final boolean checked, final int defaultOptionIndex, final int focusedOptionIndex, Icon icon) { return showCheckboxMessageDialog(message, title, new String[]{OK_BUTTON, CANCEL_BUTTON}, checkboxText, checked, defaultOptionIndex, focusedOptionIndex, icon, new PairFunction<Integer, JCheckBox, Integer>() { @Override public Integer fun(final Integer exitCode, final JCheckBox cb) { return exitCode == -1 ? CANCEL : exitCode + (cb.isSelected() ? 1 : 0); } }); }
public static int showCheckboxMessageDialog(String message, String title, String[] options, String checkboxText, final boolean checked, final int defaultOptionIndex, final int focusedOptionIndex, Icon icon, @Nullable final PairFunction<Integer, JCheckBox, Integer> exitFunc) { if (isApplicationInUnitTestOrHeadless()) { return ourTestImplementation.show(message); } else { TwoStepConfirmationDialog dialog = new TwoStepConfirmationDialog(message, title, options, checkboxText, checked, defaultOptionIndex, focusedOptionIndex, icon, exitFunc); dialog.show(); return dialog.getExitCode(); } }
public TwoStepConfirmationDialog(String message, String title, String[] options, String checkboxText, boolean checked, final int defaultOptionInxed, final int focusedOptionIndex, Icon icon, @Nullable final PairFunction<Integer, JCheckBox, Integer> exitFunc) { myCheckboxText = checkboxText; myChecked = checked; myExitFunc = exitFunc; _init(title, message, options, defaultOptionInxed, focusedOptionIndex, icon, null); }
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); if (myCurrentWindow == null || myCurrentWindow.getFiles().length == 0) { g.setColor(UIUtil.isUnderDarcula()? UIUtil.getBorderColor() : new Color(0, 0, 0, 50)); g.drawLine(0, 0, getWidth(), 0); } if (showEmptyText()) { UIUtil.applyRenderingHints(g); g.setColor(new JBColor(Gray._100, Gray._160)); g.setFont(UIUtil.getLabelFont().deriveFont(UIUtil.isUnderDarcula() ? 24f : 18f)); final UIUtil.TextPainter painter = new UIUtil.TextPainter().withShadow(true).withLineSpacing(1.4f); painter.appendLine("No files are open").underlined(new JBColor(Gray._150, Gray._100)); if (!isProjectViewVisible()) { painter.appendLine("Open Project View with " + KeymapUtil.getShortcutText(new KeyboardShortcut( KeyStroke.getKeyStroke((SystemInfo.isMac ? "meta" : "alt") + " 1"), null))).smaller().withBullet(); } painter.appendLine("Open a file by name with " + getActionShortcutText("GotoFile")).smaller().withBullet() .appendLine("Open Recent files with " + getActionShortcutText(IdeActions.ACTION_RECENT_FILES)).smaller().withBullet() .appendLine("Open Navigation Bar with " + getActionShortcutText("ShowNavBar")).smaller().withBullet() .appendLine("Drag'n'Drop file(s) here from " + ShowFilePathAction.getFileManagerName()).smaller().withBullet() .draw(g, new PairFunction<Integer, Integer, Pair<Integer, Integer>>() { @Override public Pair<Integer, Integer> fun(Integer width, Integer height) { final Dimension s = getSize(); return Pair.create((s.width - width) / 2, (s.height - height) / 2); } }); } }