Java Code Examples for consulo.awt.TargetAWT

The following examples show how to use consulo.awt.TargetAWT. 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: consulo   Source File: DesktopWindowManagerImpl.java    License: Apache License 2.0 6 votes vote down vote up
public void showFrame() {
  final DesktopIdeFrameImpl frame = new DesktopIdeFrameImpl(myActionManager, myDataManager, ApplicationManager.getApplication());
  myProject2Frame.put(null, frame);

  if (myFrameBounds == null || !ScreenUtil.isVisible(myFrameBounds)) { //avoid situations when IdeFrame is out of all screens
    myFrameBounds = ScreenUtil.getMainScreenBounds();
    int xOff = myFrameBounds.width / 8;
    int yOff = myFrameBounds.height / 8;
    JBInsets.removeFrom(myFrameBounds, new Insets(yOff, xOff, yOff, xOff));
  }

  JFrame jWindow = (JFrame)TargetAWT.to(frame.getWindow());

  jWindow.setBounds(myFrameBounds);
  jWindow.setExtendedState(myFrameExtendedState);
  jWindow.setVisible(true);
}
 
Example 2
Source Project: consulo   Source File: ModuleStructureConfigurable.java    License: Apache License 2.0 6 votes vote down vote up
public void addLibraryOrderEntry(final Module module, final Library library) {
  Component parent = TargetAWT.to(WindowManager.getInstance().suggestParentWindow(module.getProject()));

  final ModuleEditor moduleEditor = myContext.myModulesConfigurator.getModuleEditor(module);
  LOG.assertTrue(moduleEditor != null, "Current module editor was not initialized");
  final ModifiableRootModel modelProxy = moduleEditor.getModifiableRootModelProxy();
  final OrderEntry[] entries = modelProxy.getOrderEntries();
  for (OrderEntry entry : entries) {
    if (entry instanceof LibraryOrderEntry && Comparing.strEqual(entry.getPresentableName(), library.getName())) {
      if (Messages.showYesNoDialog(parent,
                                   ProjectBundle.message("project.roots.replace.library.entry.message", entry.getPresentableName()),
                                   ProjectBundle.message("project.roots.replace.library.entry.title"),
                                   Messages.getInformationIcon()) == Messages.YES) {
        modelProxy.removeOrderEntry(entry);
        break;
      }
    }
  }
  modelProxy.addLibraryEntry(library);
  myContext.getDaemonAnalyzer().queueUpdate(new ModuleProjectStructureElement(myContext, module));
  myTree.repaint();
}
 
Example 3
Source Project: consulo   Source File: DesktopDeferredIconImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public Icon evaluate() {
  consulo.ui.image.Image result;
  try {
    result = nonNull(myEvaluator.fun(myParam));
  }
  catch (IndexNotReadyException e) {
    result = EMPTY_ICON;
  }

  if (Holder.CHECK_CONSISTENCY) {
    checkDoesntReferenceThis(result);
  }

  Icon icon = TargetAWT.to(result);

  if (getScale() != 1f && icon instanceof ScalableIcon) {
    icon = ((ScalableIcon)result).scale(getScale());
  }
  return icon;
}
 
Example 4
Source Project: consulo   Source File: Bookmark.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
private static Image createMnemonicIcon(char cha) {
  int width = AllIcons.Actions.Checked.getWidth();
  int height = AllIcons.Actions.Checked.getHeight();

  return ImageEffects.canvas(width, height, c -> {
    // FIXME [VISTALL] make constant ??
    c.setFillStyle(TargetAWT.from(new JBColor(new Color(0xffffcc), new Color(0x675133))));
    c.fillRect(0, 0, width, height);

    c.setStrokeStyle(StandardColors.GRAY);
    c.rect(0, 0, width, height);
    c.stroke();

    c.setFillStyle(ComponentColors.TEXT);
    c.setFont(FontManager.get().createFont("Monospaced", 11, consulo.ui.font.Font.STYLE_BOLD));
    c.setTextAlign(Canvas2D.TextAlign.center);
    c.setTextBaseline(Canvas2D.TextBaseline.middle);

    c.fillText(Character.toString(cha), width / 2, height / 2 - 2);
  });
}
 
Example 5
Source Project: consulo   Source File: MinimizeCurrentWindowAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void update(final AnActionEvent e) {
  final Presentation p = e.getPresentation();
  p.setVisible(SystemInfo.isMac);

  if (SystemInfo.isMac) {
    Project project = e.getData(CommonDataKeys.PROJECT);
    if (project != null) {
      JFrame frame = (JFrame)TargetAWT.to(WindowManager.getInstance().getWindow(project));
      if (frame != null) {
        JRootPane pane = frame.getRootPane();
        p.setEnabled(pane != null && pane.getClientProperty(MacMainFrameDecorator.FULL_SCREEN) == null);
      }
    }
  }
  else {
    p.setEnabled(false);
  }
}
 
Example 6
Source Project: consulo   Source File: DesktopToolWindowManagerImpl.java    License: Apache License 2.0 6 votes vote down vote up
private EditorsSplitters getSplittersToFocus() {
  WindowManagerEx windowManager = (WindowManagerEx)myWindowManager.get();

  Window activeWindow = TargetAWT.to(windowManager.getMostRecentFocusedWindow());

  if (activeWindow instanceof DesktopFloatingDecorator) {
    IdeFocusManager ideFocusManager = IdeFocusManager.findInstanceByComponent(activeWindow);
    IdeFrame lastFocusedFrame = ideFocusManager.getLastFocusedFrame();
    JComponent frameComponent = lastFocusedFrame != null ? lastFocusedFrame.getComponent() : null;
    Window lastFocusedWindow = frameComponent != null ? SwingUtilities.getWindowAncestor(frameComponent) : null;
    activeWindow = ObjectUtil.notNull(lastFocusedWindow, activeWindow);
  }

  FileEditorManagerEx fem = FileEditorManagerEx.getInstanceEx(myProject);
  EditorsSplitters splitters = activeWindow != null ? fem.getSplittersFor(activeWindow) : null;
  return splitters != null ? splitters : fem.getSplitters();
}
 
Example 7
Source Project: consulo   Source File: Messages.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @return {@link #YES} if user pressed "Yes" or {@link #NO} if user pressed "No", or {@link #CANCEL} if user pressed "Cancel" button.
 */
@YesNoCancelResult
public static int showYesNoCancelDialog(@Nonnull Component parent,
                                        String message,
                                        @Nonnull String title,
                                        @Nonnull String yes,
                                        @Nonnull String no,
                                        @Nonnull String cancel,
                                        Icon icon) {
  try {
    if (canShowMacSheetPanel()) {
      return MacMessages.getInstance().showYesNoCancelDialog(title, message, yes, no, cancel, TargetAWT.from(SwingUtilities.getWindowAncestor(parent)), null);
    }
  }
  catch (Exception exception) {
  }

  int buttonNumber = showDialog(parent, message, title, new String[]{yes, no, cancel}, 0, icon);
  return buttonNumber == 0 ? YES : buttonNumber == 1 ? NO : CANCEL;
}
 
Example 8
Source Project: consulo   Source File: CreateDirectoryOrPackageHandler.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
private Boolean suggestCreatingFileInstead(String subDirName) {
  Boolean createFile = false;
  if (StringUtil.countChars(subDirName, '.') == 1 && Registry.is("ide.suggest.file.when.creating.filename.like.directory")) {
    FileType fileType = findFileTypeBoundToName(subDirName);
    if (fileType != null) {
      String message = "The name you entered looks like a file name. Do you want to create a file named " + subDirName + " instead?";
      int ec = Messages.showYesNoCancelDialog(myProject, message, "File Name Detected", "&Yes, create file", "&No, create " + (myIsDirectory ? "directory" : "packages"),
                                              CommonBundle.getCancelButtonText(), TargetAWT.to(fileType.getIcon()));
      if (ec == Messages.CANCEL) {
        createFile = null;
      }
      if (ec == Messages.YES) {
        createFile = true;
      }
    }
  }
  return createFile;
}
 
Example 9
Source Project: consulo   Source File: NewItemWithTemplatesPopupPanel.java    License: Apache License 2.0 6 votes vote down vote up
public NewItemWithTemplatesPopupPanel(List<T> templatesList, ListCellRenderer<T> renderer) {
  setBackground(JBUI.CurrentTheme.NewClassDialog.panelBackground());

  myTemplatesListModel = new MyListModel(templatesList);
  myTemplatesList = createTemplatesList(myTemplatesListModel, renderer);

  ScrollingUtil.installMoveUpAction(myTemplatesList, (JComponent)TargetAWT.to(myTextField));
  ScrollingUtil.installMoveDownAction(myTemplatesList, (JComponent)TargetAWT.to(myTextField));

  JBScrollPane scrollPane = new JBScrollPane(myTemplatesList);
  scrollPane.setBorder(JBUI.Borders.empty());
  scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
  templatesListHolder = new Box(BoxLayout.Y_AXIS);
  Border border = JBUI.Borders
          .merge(JBUI.Borders.emptyTop(JBUI.CurrentTheme.NewClassDialog.fieldsSeparatorWidth()), JBUI.Borders.customLine(JBUI.CurrentTheme.NewClassDialog.bordersColor(), 1, 0, 0, 0), true);

  templatesListHolder.setBorder(border);
  templatesListHolder.add(scrollPane);

  add(templatesListHolder, BorderLayout.CENTER);
}
 
Example 10
Source Project: consulo   Source File: DesktopWindowWatcher.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @return active window for specified <code>project</code>. There is only one window
 * for project can be at any point of time.
 */
@Nullable
private Window getFocusedWindowForProject(@Nullable final Project project) {
  //todo[anton,vova]: it is possible that returned wnd is not contained in myFocusedWindows; investigate
  outer:
  for (consulo.ui.Window window : myFocusedWindows) {
    Window awtWindow = TargetAWT.to(window);

    while (!awtWindow.isDisplayable() || !awtWindow.isShowing()) { // if window isn't visible then gets its first visible ancestor
      awtWindow = awtWindow.getOwner();
      if (awtWindow == null) {
        continue outer;
      }
    }
    final DataContext dataContext = DataManager.getInstance().getDataContext(awtWindow);
    if (project == dataContext.getData(CommonDataKeys.PROJECT)) {
      return awtWindow;
    }
  }
  return null;
}
 
Example 11
Source Project: consulo   Source File: DesktopDeferredIconImpl.java    License: Apache License 2.0 6 votes vote down vote up
private void checkDoesntReferenceThis(final consulo.ui.image.Image icon) {
  if (icon == this) {
    throw new IllegalStateException("Loop in icons delegation");
  }

  if (icon instanceof DesktopDeferredIconImpl) {
    checkDoesntReferenceThis(((DesktopDeferredIconImpl)icon).myScaledDelegateIcon);
  }
  else if (icon instanceof LayeredIcon) {
    for (Icon layer : ((LayeredIcon)icon).getAllLayers()) {
      checkDoesntReferenceThis(TargetAWT.from(layer));
    }
  }
  else if (icon instanceof RowIcon) {
    final RowIcon rowIcon = (RowIcon)icon;
    final int count = rowIcon.getIconCount();
    for (int i = 0; i < count; i++) {
      checkDoesntReferenceThis(TargetAWT.from(rowIcon.getIcon(i)));
    }
  }
}
 
Example 12
Source Project: consulo   Source File: BaseExecuteBeforeRunDialog.java    License: Apache License 2.0 6 votes vote down vote up
private DefaultMutableTreeNode buildNodes() {
  DefaultMutableTreeNode root = new DefaultMutableTreeNode(new Descriptor());
  RunManager runManager = RunManager.getInstance(myProject);
  final ConfigurationType[] configTypes = runManager.getConfigurationFactories();

  for (final ConfigurationType type : configTypes) {
    final Icon icon = TargetAWT.to(type.getIcon());
    DefaultMutableTreeNode typeNode = new DefaultMutableTreeNode(new ConfigurationTypeDescriptor(type, icon, isConfigurationAssigned(type)));
    root.add(typeNode);
    final Set<String> addedNames = new THashSet<>();
    RunConfiguration[] configurations = runManager.getConfigurations(type);
    for (final RunConfiguration configuration : configurations) {
      final String configurationName = configuration.getName();
      if (addedNames.contains(configurationName)) {
        // add only the first configuration if more than one has the same name
        continue;
      }
      addedNames.add(configurationName);
      typeNode.add(new DefaultMutableTreeNode(new ConfigurationDescriptor(configuration, isConfigurationAssigned(configuration))));
    }
  }

  return root;
}
 
Example 13
Source Project: consulo   Source File: NewItemSimplePopupPanel.java    License: Apache License 2.0 5 votes vote down vote up
public NewItemSimplePopupPanel() {
  super(new BorderLayout());

  myTextField = createTextField();
  add(TargetAWT.to(myTextField), BorderLayout.NORTH);

  //myErrorShowPoint = new RelativePoint(myTextField, new Point(0, myTextField.getHeight()));
}
 
Example 14
Source Project: consulo   Source File: DesktopMenuImpl.java    License: Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Nonnull
@Override
public Menu add(@Nonnull MenuItem menuItem) {
  if (menuItem instanceof MenuSeparator) {
    myComponent.addSeparator();
    return this;
  }
  myComponent.add((JMenuItem)TargetAWT.to(menuItem));
  return this;
}
 
Example 15
Source Project: consulo   Source File: WizardStep.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
@Deprecated
@DeprecationInfo("Temp UI version")
@RequiredUIAccess
default java.awt.Component getSwingComponent() {
  return TargetAWT.to(getComponent());
}
 
Example 16
Source Project: consulo   Source File: DesktopStripeButton.java    License: Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void updatePresentation() {
  updateState();
  updateText();
  Image image = myDecorator.getToolWindow().getIcon();
  setIcon(TargetAWT.to(image));
  setDisabledIcon(image == null ? null : TargetAWT.to(ImageEffects.grayed(image)));
}
 
Example 17
Source Project: consulo   Source File: TreeComboBox.java    License: Apache License 2.0 5 votes vote down vote up
private static Icon getValueIcon(final Object value, final int index) {
  if (value instanceof CustomPresentation) {
    return ((CustomPresentation)value).getIcon(index, 0);
  }
  if (value instanceof Iconable) {
    return TargetAWT.to(((Iconable)value).getIcon(0));
  }

  return null;
}
 
Example 18
Source Project: consulo   Source File: DefaultLookupItemRenderer.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
private static Icon _getRawIcon(LookupElement item, boolean real) {
  if (item instanceof LookupItem) {
    Icon icon = (Icon)((LookupItem)item).getAttribute(LookupItem.ICON_ATTR);
    if (icon != null) return icon;
  }

  Object o = item.getObject();

  if (!real) {
    if (item.getObject() instanceof String) {
      return EmptyIcon.ICON_0;
    }

    return new EmptyIcon(IconUtil.getDefaultNodeIconSize() * 2, IconUtil.getDefaultNodeIconSize());
  }

  if (o instanceof Iconable && !(o instanceof PsiElement)) {
    return TargetAWT.to(((Iconable)o).getIcon(Iconable.ICON_FLAG_VISIBILITY));
  }

  final PsiElement element = item.getPsiElement();
  if (element != null && element.isValid()) {
    return TargetAWT.to(IconDescriptorUpdaters.getIcon(element, Iconable.ICON_FLAG_VISIBILITY));
  }
  return null;
}
 
Example 19
Source Project: consulo   Source File: StopAction.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
private static Pair<List<HandlerItem>, HandlerItem> getItemsList(List<Pair<TaskInfo, ProgressIndicator>> tasks,
                                                                 List<RunContentDescriptor> descriptors,
                                                                 RunContentDescriptor toSelect) {
  if (tasks.isEmpty() && descriptors.isEmpty()) {
    return null;
  }

  List<HandlerItem> items = new ArrayList<>(tasks.size() + descriptors.size());
  HandlerItem selected = null;
  for (final RunContentDescriptor descriptor : descriptors) {
    final ProcessHandler handler = descriptor.getProcessHandler();
    if (handler != null) {
      HandlerItem item = new HandlerItem(descriptor.getDisplayName(), TargetAWT.to(descriptor.getIcon()), false) {
        @Override
        void stop() {
          ExecutionManagerImpl.stopProcess(descriptor);
        }
      };
      items.add(item);
      if (descriptor == toSelect) {
        selected = item;
      }
    }
  }

  boolean hasSeparator = true;
  for (final Pair<TaskInfo, ProgressIndicator> eachPair : tasks) {
    items.add(new HandlerItem(eachPair.first.getTitle(), AllIcons.Process.Step_passive, hasSeparator) {
      @Override
      void stop() {
        eachPair.second.cancel();
      }
    });
    hasSeparator = false;
  }
  return Pair.create(items, selected);
}
 
Example 20
Source Project: consulo   Source File: RunnerContentUi.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void showNotify() {
  Window awtWindow = SwingUtilities.getWindowAncestor(myComponent);
  consulo.ui.Window uiWindow = TargetAWT.from(awtWindow);

  IdeFrame ideFrame = uiWindow.getUserData(IdeFrame.KEY);
  if (ideFrame instanceof IdeFrame.Child) {
    ideFrame.setFrameTitle(mySessionName);
  }
}
 
Example 21
Source Project: consulo   Source File: Messages.java    License: Apache License 2.0 5 votes vote down vote up
public static void showErrorDialog(@Nonnull Component component, String message) {
  try {
    if (canShowMacSheetPanel()) {
      MacMessages.getInstance().showErrorDialog(CommonBundle.getErrorTitle(), message, OK_BUTTON, TargetAWT.from(SwingUtilities.getWindowAncestor(component)));
      return;
    }
  }
  catch (Exception exception) {
  }

  showDialog(component, message, CommonBundle.getErrorTitle(), new String[]{OK_BUTTON}, 0, getErrorIcon());
}
 
Example 22
Source Project: consulo   Source File: Messages.java    License: Apache License 2.0 5 votes vote down vote up
public static void showWarningDialog(@Nonnull Component component, String message, @Nonnull String title) {
  try {
    if (canShowMacSheetPanel()) {
      MacMessages.getInstance().showErrorDialog(title, message, OK_BUTTON, TargetAWT.from(SwingUtilities.getWindowAncestor(component)));
      return;
    }
  }
  catch (Exception exception) {
  }

  showDialog(component, message, title, new String[]{OK_BUTTON}, 0, getWarningIcon());
}
 
Example 23
Source Project: consulo   Source File: FileInfoManager.java    License: Apache License 2.0 5 votes vote down vote up
public static Object getFileLookupItem(PsiElement psiElement) {
  if (!(psiElement instanceof PsiFile) || !(psiElement.isPhysical())) {
    return psiElement;
  }

  final PsiFile file = (PsiFile)psiElement;
  return getFileInfoManager()._getLookupItem(file, file.getName(), TargetAWT.to(IconDescriptorUpdaters.getIcon(file, 0)));
}
 
Example 24
Source Project: consulo   Source File: DesktopToolWindowManagerImpl.java    License: Apache License 2.0 5 votes vote down vote up
public void projectClosed() {
  if (myFrame == null) {
    return;
  }
  final String[] ids = getToolWindowIds();

  WindowManagerEx windowManager = (WindowManagerEx)myWindowManager.get();

  // Remove ToolWindowsPane
  JFrame window = (JFrame)TargetAWT.to(myFrame.getWindow());
  ((IdeRootPane)window.getRootPane()).setToolWindowsPane(null);
  windowManager.releaseFrame(myFrame);
  List<FinalizableCommand> commandsList = new ArrayList<>();
  appendUpdateToolWindowsPaneCmd(commandsList);

  // Hide all tool windows

  for (final String id : ids) {
    deactivateToolWindowImpl(id, true, commandsList);
  }

  // Remove editor component

  final JComponent editorComponent = getEditorComponent(myProject);
  appendSetEditorComponentCmd(null, commandsList);
  execute(commandsList);
  myFrame = null;
}
 
Example 25
Source Project: consulo   Source File: ApplicationActivationStateManager.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
private static IdeFrame getIdeFrameFromWindow(Window window) {
  final Component frame = UIUtil.findUltimateParent(window);
  if (!(frame instanceof Window)) {
    return null;
  }

  consulo.ui.Window uiWindow = TargetAWT.from((Window)frame);
  return uiWindow.getUserData(IdeFrame.KEY);
}
 
Example 26
Source Project: consulo   Source File: ChooseLibrariesDialogBase.java    License: Apache License 2.0 5 votes vote down vote up
protected LibraryDescriptor(final Project project, final NodeDescriptor parentDescriptor, final Library element) {
  super(project, parentDescriptor, element);
  final CellAppearanceEx appearance = OrderEntryAppearanceService.getInstance().forLibrary(project, element, false);
  final SimpleColoredComponent coloredComponent = new SimpleColoredComponent();
  appearance.customize(coloredComponent);
  final PresentationData templatePresentation = getTemplatePresentation();
  templatePresentation.setIcon(TargetAWT.from(coloredComponent.getIcon()));
  templatePresentation.addText(notEmpty(appearance.getText()), SimpleTextAttributes.REGULAR_ATTRIBUTES);
}
 
Example 27
Source Project: consulo   Source File: Win7TaskBar.java    License: Apache License 2.0 5 votes vote down vote up
private static WinDef.HWND getHandle(IdeFrame frame) {
  try {
    Pointer pointer = Native.getWindowPointer(TargetAWT.to(frame.getWindow()));
    return new WinDef.HWND(pointer);
  }
  catch (Throwable e) {
    LOG.error(e);
    return null;
  }
}
 
Example 28
Source Project: consulo   Source File: JDialogAsUIWindow.java    License: Apache License 2.0 5 votes vote down vote up
public JDialogAsUIWindow(Window owner, String title) {
  super(TargetAWT.to(owner), title);

  myWindowOverAWTWindow = new WindowOverAWTWindow(this) {
    @RequiredUIAccess
    @Override
    public void setTitle(@Nonnull String title) {
      JDialogAsUIWindow.this.setTitle(title);
    }
  };
}
 
Example 29
Source Project: consulo   Source File: XDebuggerEditorBase.java    License: Apache License 2.0 5 votes vote down vote up
protected JPanel addMultilineButton(JComponent component) {
  ComponentWithBrowseButton<JComponent> componentWithButton =
          new ComponentWithBrowseButton<>(component, e -> showCodeFragmentEditor(component, this));
  componentWithButton.setButtonIcon(AllIcons.Actions.ShowViewer);
  componentWithButton.getButton().setDisabledIcon(TargetAWT.to(ImageEffects.grayed(AllIcons.Actions.ShowViewer)));
  return componentWithButton;
}
 
Example 30
Source Project: consulo   Source File: FileLabel.java    License: Apache License 2.0 5 votes vote down vote up
public void setFile(File ioFile) {
  myFile = ioFile;
  if (myShowIcon) {
    setIcon(TargetAWT.to(FileTypeManager.getInstance().getFileTypeByFileName(myFile.getName()).getIcon()));
  }
  else {
    setIcon(null);
  }
}