consulo.awt.TargetAWT Java Examples

The following examples show how to use consulo.awt.TargetAWT. 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: CreateDirectoryOrPackageHandler.java    From consulo with 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 #2
Source File: BaseExecuteBeforeRunDialog.java    From consulo with 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 #3
Source File: DesktopWindowManagerImpl.java    From consulo with 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 #4
Source File: ModuleStructureConfigurable.java    From consulo with 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 #5
Source File: DesktopDeferredIconImpl.java    From consulo with 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 #6
Source File: Bookmark.java    From consulo with 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 #7
Source File: DesktopDeferredIconImpl.java    From consulo with 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 #8
Source File: MinimizeCurrentWindowAction.java    From consulo with 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 #9
Source File: DesktopToolWindowManagerImpl.java    From consulo with 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 #10
Source File: Messages.java    From consulo with 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 #11
Source File: NewItemWithTemplatesPopupPanel.java    From consulo with 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 #12
Source File: XDebuggerEditorBase.java    From consulo with Apache License 2.0 6 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 #13
Source File: DesktopWindowWatcher.java    From consulo with 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 #14
Source File: AbstractPopup.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean isIdeFrame(Component component) {
  if (!(component instanceof Window)) {
    return false;
  }
  consulo.ui.Window uiWindow = TargetAWT.from((Window)component);
  return uiWindow.getUserData(IdeFrame.KEY) != null;
}
 
Example #15
Source File: NotificationsManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
@RequiredUIAccess
public static IdeFrame findIdeFrameForBalloon(@Nullable Project project) {
  Window windowForBalloon = findWindowForBalloon(project);
  consulo.ui.Window uiWindow = TargetAWT.from(windowForBalloon);
  return uiWindow == null ? null : uiWindow.getUserData(IdeFrame.KEY);
}
 
Example #16
Source File: FlatWelcomeFrame.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
public FlatWelcomeFrame(Runnable clearInstance) {
  myClearInstance = clearInstance;
  final JRootPane rootPane = getRootPane();
  FlatWelcomeScreen screen = new FlatWelcomeScreen(this);

  final IdeGlassPaneImpl glassPane = new IdeGlassPaneImpl(rootPane);

  setGlassPane(glassPane);
  glassPane.setVisible(false);
  //setUndecorated(true);
  setContentPane(screen);
  setDefaultTitle();
  AppUIUtil.updateWindowIcon(this);
  SwingUIDecorator.apply(SwingUIDecorator::decorateWindowTitle, rootPane);
  setSize(TargetAWT.to(WelcomeFrameManager.getDefaultWindowSize()));
  setResizable(false);
  Point location = WindowStateService.getInstance().getLocation(WelcomeFrameManager.DIMENSION_KEY);
  Rectangle screenBounds = ScreenUtil.getScreenRectangle(location != null ? location : new Point(0, 0));
  setLocation(new Point(screenBounds.x + (screenBounds.width - getWidth()) / 2, screenBounds.y + (screenBounds.height - getHeight()) / 3));

  myBalloonLayout = new WelcomeDesktopBalloonLayoutImpl(rootPane, JBUI.insets(8), screen.getMainWelcomePanel().myEventListener, screen.getMainWelcomePanel().myEventLocation);

  setupCloseAction(this);
  MnemonicHelper.init(this);
  Disposer.register(ApplicationManager.getApplication(), this);
}
 
Example #17
Source File: HideableDecorator.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void off() {
  myOn = false;
  myTitledSeparator.getLabel().setIcon(TargetAWT.to(AllIcons.General.SplitRight));
  myTitledSeparator.getLabel().setDisabledIcon(TargetAWT.to(ImageEffects.transparent(AllIcons.General.SplitRight, 0.5f)));
  if (myContent != null) {
    myContent.setVisible(false);
    myPreviousContentSize = myContent.getSize();
  }
  adjustWindow();
  myPanel.invalidate();
  myPanel.repaint();
}
 
Example #18
Source File: ConfigurableUIMigrationUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
public static JComponent getPreferredFocusedComponent(@Nonnull Configurable.HoldPreferredFocusedComponent component) {
  JComponent preferredFocusedComponent = component.getPreferredFocusedComponent();
  if(preferredFocusedComponent != null) {
    return preferredFocusedComponent;
  }
  consulo.ui.Component uiComponent = component.getPreferredFocusedUIComponent();
  if (uiComponent != null) {
    return (JComponent)TargetAWT.to(uiComponent);
  }
  return null;
}
 
Example #19
Source File: XDebuggerSmartStepIntoHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static <V extends XSmartStepIntoVariant> void doSmartStepInto(final XSmartStepIntoHandler<V> handler,
                                                                      XSourcePosition position,
                                                                      final XDebugSession session,
                                                                      Editor editor) {
  List<V> variants = handler.computeSmartStepVariants(position);
  if (variants.isEmpty()) {
    session.stepInto();
    return;
  }
  else if (variants.size() == 1) {
    session.smartStepInto(handler, variants.get(0));
    return;
  }

  ListPopup popup = JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<V>(handler.getPopupTitle(position), variants) {
    @Override
    public Icon getIconFor(V aValue) {
      return TargetAWT.to(aValue.getIcon());
    }

    @Nonnull
    @Override
    public String getTextFor(V value) {
      return value.getText();
    }

    @Override
    public PopupStep onChosen(V selectedValue, boolean finalChoice) {
      session.smartStepInto(handler, selectedValue);
      return FINAL_CHOICE;
    }
  });
  DebuggerUIUtil.showPopupForEditorLine(popup, editor, position.getLine());
}
 
Example #20
Source File: ExportToFileUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void browseFile() {
  JFileChooser chooser = new JFileChooser();
  if (myTfFile != null) {
    chooser.setCurrentDirectory(new File(myTfFile.getText()));
  }
  chooser.showOpenDialog(TargetAWT.to(WindowManager.getInstance().suggestParentWindow(myProject)));
  if (chooser.getSelectedFile() != null) {
    myTfFile.setText(chooser.getSelectedFile().getAbsolutePath());
  }
}
 
Example #21
Source File: FileEditor.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * @return component which represents editor in the UI.
 * The method should never return <code>null</code>.
 */
@Nonnull
default javax.swing.JComponent getComponent() {
  Component uiComponent = getUIComponent();
  if(uiComponent != null) {
    return (javax.swing.JComponent)TargetAWT.to(uiComponent);
  }
  throw new AbstractMethodError();
}
 
Example #22
Source File: DesktopToolWindowManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static Rectangle2D getRootBounds(JFrame frame) {
  JRootPane rootPane = frame.getRootPane();
  Rectangle bounds = rootPane.getBounds();
  bounds.setLocation(frame.getX() + rootPane.getX(), frame.getY() + rootPane.getY());
  return TargetAWT.from(bounds);
}
 
Example #23
Source File: CreateNewLibraryAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private CreateNewLibraryAction(@Nonnull String text,
                               @Nullable Image icon,
                               @Nullable LibraryType type,
                               @Nonnull BaseLibrariesConfigurable librariesConfigurable,
                               final @Nonnull Project project) {
  super(text, null, TargetAWT.to(icon));
  myType = type;
  myLibrariesConfigurable = librariesConfigurable;
  myProject = project;
}
 
Example #24
Source File: NotificationPopup.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static IdeFrame findFrame(JComponent owner) {
  final Window frame = SwingUtilities.getWindowAncestor(owner);
  if(frame == null) {
    return null;
  }

  consulo.ui.Window uiWindow = TargetAWT.from(frame);
  return uiWindow.getUserData(IdeFrame.KEY);
}
 
Example #25
Source File: FileLabel.java    From consulo with 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);
  }
}
 
Example #26
Source File: InfoAndProgressPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static DesktopBalloonLayoutImpl getBalloonLayout(@Nonnull JRootPane pane) {
  Component parent = UIUtil.findUltimateParent(pane);
  if (parent instanceof Window) {
    consulo.ui.Window uiWindow = TargetAWT.from((Window)parent);

    IdeFrame ideFrame = uiWindow.getUserData(IdeFrame.KEY);
    if (ideFrame == null) {
      return null;
    }
    return (DesktopBalloonLayoutImpl)ideFrame.getBalloonLayout();
  }
  return null;
}
 
Example #27
Source File: JDialogAsUIWindow.java    From consulo with 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 #28
Source File: Win7TaskBar.java    From consulo with 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 #29
Source File: ChooseLibrariesDialogBase.java    From consulo with 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 #30
Source File: IdeStatusBarImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public StatusBar findChild(Component c) {
  Component eachParent = c;
  IdeFrame frame = null;
  while (eachParent != null) {
    if (eachParent instanceof Window) {
      consulo.ui.Window uiWindow = TargetAWT.from((Window)eachParent);
      frame = uiWindow.getUserData(IdeFrame.KEY);
    }
    eachParent = eachParent.getParent();
  }

  return frame != null ? frame.getStatusBar() : this;
}