下面列出了javax.swing.text.html.ImageView#com.intellij.openapi.wm.ex.WindowManagerEx 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
protected void showPopup(DataContext context, ListPopup popup, JComponent contextComponent) {
Component focusedComponent = contextComponent != null ? contextComponent : context.getData(PlatformDataKeys.CONTEXT_COMPONENT);
if (focusedComponent != null) {
if (popup instanceof PopupFactoryImpl.ActionGroupPopup && focusedComponent instanceof JLabel) {
((PopupFactoryImpl.ActionGroupPopup)popup).showUnderneathOfLabel((JLabel)focusedComponent);
} else {
popup.showUnderneathOf(focusedComponent);
}
}
else {
Rectangle r;
int x;
int y;
focusedComponent = WindowManagerEx.getInstanceEx().getFocusedComponent((Project)null);
r = WindowManagerEx.getInstanceEx().getScreenBounds();
x = r.x + r.width / 2;
y = r.y + r.height / 2;
Point point = new Point(x, y);
SwingUtilities.convertPointToScreen(point, focusedComponent.getParent());
popup.showInScreenCoordinates(focusedComponent.getParent(), point);
}
}
public IdeMenuBar(ActionManager actionManager, DataManager dataManager) {
myActionManager = actionManager;
myTimerListener = new MyTimerListener();
myVisibleActions = new ArrayList<AnAction>();
myNewVisibleActions = new ArrayList<AnAction>();
myPresentationFactory = new MenuItemPresentationFactory();
myDataManager = dataManager;
if (WindowManagerEx.getInstanceEx().isFloatingMenuBarSupported()) {
myAnimator = new MyAnimator();
myActivationWatcher = new Timer(100, new MyActionListener());
myClockPanel = new ClockPanel();
myButton = new MyExitFullScreenButton();
add(myClockPanel);
add(myButton);
addPropertyChangeListener(WindowManagerEx.FULL_SCREEN, evt -> updateState());
addMouseListener(new MyMouseListener());
}
else {
myAnimator = null;
myActivationWatcher = null;
myClockPanel = null;
myButton = null;
}
}
public static void showNotification() {
if (notificationHasBeenShown) {
return;
}
consulo.ui.Window window = WindowManagerEx.getInstanceEx().getMostRecentFocusedWindow();
if(!KeyboardSettingsExternalizable.isSupportedKeyboardLayout(TargetAWT.to(window))) {
return;
}
MyNotificationListener listener = new MyNotificationListener();
Notifications.Bus.notify(createNotification(LOCALIZATION_GROUP_DISPLAY_ID, listener));
notificationHasBeenShown = true;
}
public static Notification createNotification(@Nonnull final String groupDisplayId, @Nullable NotificationListener listener) {
final String productName = ApplicationNamesInfo.getInstance().getProductName();
Window recentFocusedWindow = TargetAWT.to(WindowManagerEx.getInstanceEx().getMostRecentFocusedWindow());
String text = "<html>We have found out that you are using a non-english keyboard layout. You can <a href='enable'>enable</a> smart layout support for " +
KeyboardSettingsExternalizable.getDisplayLanguageNameForComponent(recentFocusedWindow) +
" language." +
"You can change this option in the settings of " +
productName +
" <a href='settings'>more...</a></html>";
String title = "Enable smart keyboard internalization for " + productName + ".";
return new Notification(groupDisplayId, title, text, NotificationType.INFORMATION, listener);
}
@Override
public void hyperlinkUpdate(@Nonnull Notification notification, @Nonnull HyperlinkEvent event) {
if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
final String description = event.getDescription();
if ("enable".equals(description)) {
KeyboardSettingsExternalizable.getInstance().setNonEnglishKeyboardSupportEnabled(true);
}
else if ("settings".equals(description)) {
final ShowSettingsUtil util = ShowSettingsUtil.getInstance();
IdeFrame ideFrame = WindowManagerEx.getInstanceEx().findFrameFor(null);
//util.editConfigurable((JFrame)ideFrame, new StatisticsConfigurable(true));
util.showSettingsDialog(ideFrame.getProject(), KeymapPanel.class);
}
NotificationsConfiguration.getNotificationsConfiguration().changeSettings(LOCALIZATION_GROUP_DISPLAY_ID, NotificationDisplayType.NONE, false, false);
notification.expire();
}
}
private boolean noIntersections(Rectangle bounds) {
Window owner = SwingUtilities.getWindowAncestor(myComponent);
Window popup = SwingUtilities.getWindowAncestor(myTipComponent);
Window focus = TargetAWT.to(WindowManagerEx.getInstanceEx().getMostRecentFocusedWindow());
if (focus == owner.getOwner()) {
focus = null; // do not check intersection with parent
}
boolean focused = SystemInfo.isWindows || owner.isFocused();
for (Window other : owner.getOwnedWindows()) {
if (!focused && !SystemInfo.isWindows) {
focused = other.isFocused();
}
if (popup != other && other.isVisible() && bounds.x + 10 >= other.getX() && bounds.intersects(other.getBounds())) {
return false;
}
if (focus == other) {
focus = null; // already checked
}
}
return focused && (focus == owner || focus == null || !owner.getBounds().intersects(focus.getBounds()));
}
private Window updateMaskAndAlpha(Window window) {
if (window == null) return null;
if (!window.isDisplayable() || !window.isShowing()) return window;
final WindowManagerEx wndManager = getWndManager();
if (wndManager == null) return window;
if (!wndManager.isAlphaModeEnabled(window)) return window;
if (myAlpha != myLastAlpha) {
wndManager.setAlphaModeRatio(window, myAlpha);
myLastAlpha = myAlpha;
}
if (myMaskProvider != null) {
final Dimension size = window.getSize();
Shape mask = myMaskProvider.getMask(size);
wndManager.setWindowMask(window, mask);
}
WindowManagerEx.WindowShadowMode mode = myShadowed ? WindowManagerEx.WindowShadowMode.NORMAL : WindowManagerEx.WindowShadowMode.DISABLED;
WindowManagerEx.getInstanceEx().setWindowShadow(window, mode);
return window;
}
/**
* @return true if window ancestor of component was most recent focused window and most recent focused component
* in that window was descended from component
*/
public static boolean hasFocus2(Component component) {
WindowManagerEx windowManager = WindowManagerEx.getInstanceEx();
Window activeWindow=null;
if (windowManager != null) {
activeWindow = TargetAWT.to(windowManager.getMostRecentFocusedWindow());
}
if(activeWindow==null){
return false;
}
Component focusedComponent = windowManager.getFocusedComponent(activeWindow);
if (focusedComponent == null) {
return false;
}
return SwingUtilities.isDescendingFrom(focusedComponent, component);
}
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();
}
@Override
public final void show() {
setFocusableWindowState(myInfo.isActive());
super.show();
final UISettings uiSettings = UISettings.getInstance();
if (uiSettings.ENABLE_ALPHA_MODE) {
final WindowManagerEx windowManager = WindowManagerEx.getInstanceEx();
windowManager.setAlphaModeEnabled(this, true);
if (myInfo.isActive()) {
windowManager.setAlphaModeRatio(this, 0.0f);
}
else {
windowManager.setAlphaModeRatio(this, uiSettings.ALPHA_MODE_RATIO);
}
}
paint(getGraphics()); // This prevents annoying flick
setFocusableWindowState(true);
uiSettings.addUISettingsListener(myUISettingsListener, myDelayAlarm);
}
@Override
public void uiSettingsChanged(final UISettings uiSettings) {
LOG.assertTrue(isDisplayable());
LOG.assertTrue(isShowing());
final WindowManagerEx windowManager = WindowManagerEx.getInstanceEx();
myDelayAlarm.cancelAllRequests();
if (uiSettings.ENABLE_ALPHA_MODE) {
if (!myInfo.isActive()) {
windowManager.setAlphaModeEnabled(DesktopFloatingDecorator.this, true);
windowManager.setAlphaModeRatio(DesktopFloatingDecorator.this, uiSettings.ALPHA_MODE_RATIO);
}
}
else {
windowManager.setAlphaModeEnabled(DesktopFloatingDecorator.this, false);
}
}
private static void fireUpdate() {
UISettings.getInstance().fireUISettingsChanged();
EditorFactory.getInstance().refreshAllEditors();
Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
for (Project openProject : openProjects) {
FileStatusManager.getInstance(openProject).fileStatusesChanged();
DaemonCodeAnalyzer.getInstance(openProject).restart();
}
for (IdeFrame frame : WindowManagerEx.getInstanceEx().getAllProjectFrames()) {
if (frame instanceof IdeFrameEx) {
((IdeFrameEx)frame).updateView();
}
}
ActionToolbarImpl.updateAllToolbarsImmediately();
}
public static void showStartupDialog(Project project) {
Window w = WindowManagerEx.getInstanceEx().suggestParentWindow(project);
if (ourInstance != null && ourInstance.isVisible()) {
ourInstance.dispose();
}
ourInstance = (w == null) ? new KPXStartupDialog() : new KPXStartupDialog(w);
ourInstance.show();
}
@Override
public void projectOpened(Project project) {
if (!enabled.getValue()) {
return;
}
ProjectFrameHelper frameHelper = WindowManagerEx.getInstanceEx().getFrameHelper(project);
if (frameHelper != null) {
frameHelper.updateView();
}
}
/**
* Find current window element of given project.
* Use this to find a component for new dialogs without using JBPopupFactory
*
* @see com.intellij.ui.popup.AbstractPopup#showCenteredInCurrentWindow
*/
@Nullable
public static Window getWindowComponentFromProject(@NotNull Project project) {
WindowManagerEx windowManager = getWindowManager();
if(windowManager == null) {
return null;
}
Window window = null;
Component focusedComponent = windowManager.getFocusedComponent(project);
if (focusedComponent != null) {
Component parent = UIUtil.findUltimateParent(focusedComponent);
if (parent instanceof Window) {
window = (Window)parent;
}
}
if (window == null) {
window = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
}
if (window != null && window.isShowing()) {
return window;
}
return window;
}
public void showIfNoProjectOpened() {
myApplication.invokeLater((DumbAwareRunnable)() -> {
WindowManagerEx windowManager = (WindowManagerEx)WindowManager.getInstance();
windowManager.disposeRootFrame();
IdeFrame[] frames = windowManager.getAllProjectFrames();
if (frames.length == 0) {
showFrame();
}
}, ModalityState.NON_MODAL);
}
public DataContext getDataContextTest(consulo.ui.Component component) {
DataContext dataContext = getDataContext(component);
Project project = dataContext.getData(CommonDataKeys.PROJECT);
Component focusedComponent = ((WindowManagerEx)myWindowManager.get()).getFocusedComponent(project);
if (focusedComponent != null) {
dataContext = getDataContext(focusedComponent);
}
return dataContext;
}
protected void notifyFrameComponents(boolean state) {
JFrame jFrame = getJFrame();
if (jFrame == null) {
return;
}
jFrame.getRootPane().putClientProperty(WindowManagerEx.FULL_SCREEN, state);
jFrame.getJMenuBar().putClientProperty(WindowManagerEx.FULL_SCREEN, state);
}
public IdeRootPane(ActionManager actionManager, DataManager dataManager, Application application, final IdeFrame frame) {
myActionManager = actionManager;
myContentPane.add(myNorthPanel, BorderLayout.NORTH);
myContentPane.addMouseMotionListener(new MouseMotionAdapter() {}); // listen to mouse motion events for a11y
createStatusBar(frame);
updateStatusBarVisibility();
myContentPane.add(myStatusBar, BorderLayout.SOUTH);
if (WindowManagerEx.getInstanceEx().isFloatingMenuBarSupported()) {
menuBar = new IdeMenuBar(actionManager, dataManager);
getLayeredPane().add(menuBar, new Integer(JLayeredPane.DEFAULT_LAYER - 1));
if (frame instanceof IdeFrameEx) {
addPropertyChangeListener(WindowManagerEx.FULL_SCREEN, __ -> myFullScreen = ((IdeFrameEx)frame).isInFullScreen());
}
}
else {
setJMenuBar(new IdeMenuBar(actionManager, dataManager));
}
IdeGlassPaneImpl glassPane = new IdeGlassPaneImpl(this, true);
setGlassPane(glassPane);
myGlassPaneInitialized = true;
SwingUIDecorator.apply(SwingUIDecorator::decorateWindowTitle, this);
glassPane.setVisible(false);
}
public ProgressDialog(ProgressWindow progressWindow, boolean shouldShowBackground, Project project, String cancelText) {
myProgressWindow = progressWindow;
consulo.ui.Window parentWindow = WindowManager.getInstance().suggestParentWindow(project);
if (parentWindow == null) {
parentWindow = WindowManagerEx.getInstanceEx().getMostRecentFocusedWindow();
}
myParentWindow = parentWindow;
initDialog(shouldShowBackground, cancelText);
}
public BackgroundableProcessIndicator(@Nullable final Project project, @Nonnull TaskInfo info, @Nonnull PerformInBackgroundOption option) {
super(info.isCancellable(), true, project, info.getCancelText());
setOwnerTask(info);
myOption = option;
myInfo = info;
setTitle(info.getTitle());
final Project nonDefaultProject = project == null || project.isDisposed() ? null : project.isDefault() ? null : project;
final IdeFrame frame = ((WindowManagerEx)WindowManager.getInstance()).findFrameFor(nonDefaultProject);
myStatusBar = frame != null ? (StatusBarEx)frame.getStatusBar() : null;
myBackgrounded = shouldStartInBackground();
if (myBackgrounded) {
doBackground();
}
}
protected void loadFrameState(@Nullable WindowState state) {
final Window frame = getFrame();
if(state != null) {
state.applyTo(frame);
}
else {
final IdeFrame ideFrame = WindowManagerEx.getInstanceEx().getIdeFrame(myProject);
if (ideFrame != null) {
frame.setBounds(TargetAWT.to(ideFrame.suggestChildFrameBounds()));
}
}
((RootPaneContainer)frame).getRootPane().revalidate();
}
private void actionsUpdated(boolean forced, @Nonnull List<? extends AnAction> newVisibleActions) {
if (forced || !newVisibleActions.equals(myVisibleActions)) {
boolean shouldRebuildUI = newVisibleActions.isEmpty() || myVisibleActions.isEmpty();
myVisibleActions = newVisibleActions;
Dimension oldSize = getPreferredSize();
removeAll();
mySecondaryActions.removeAll();
mySecondaryActionsButton = null;
fillToolBar(myVisibleActions, getLayoutPolicy() == AUTO_LAYOUT_POLICY && myOrientation == SwingConstants.HORIZONTAL);
Dimension newSize = getPreferredSize();
if (!mySkipWindowAdjustments) {
((WindowManagerEx)WindowManager.getInstance()).adjustContainerWindow(this, oldSize, newSize);
}
if (shouldRebuildUI) {
revalidate();
}
else {
Container parent = getParent();
if (parent != null) {
parent.invalidate();
parent.validate();
}
}
repaint();
}
}
private void commandStarted(UndoConfirmationPolicy undoConfirmationPolicy, boolean recordOriginalReference) {
if (myCommandLevel == 0) {
myCurrentMerger = new CommandMerger(this, CommandProcessor.getInstance().isUndoTransparentActionInProgress());
if (recordOriginalReference && myProject != null) {
Editor editor = null;
final Application application = ApplicationManager.getApplication();
if (application.isUnitTestMode() || application.isHeadlessEnvironment()) {
editor = DataManager.getInstance().getDataContext().getData(CommonDataKeys.EDITOR);
}
else {
Component component = WindowManagerEx.getInstanceEx().getFocusedComponent(myProject);
if (component != null) {
editor = DataManager.getInstance().getDataContext(component).getData(CommonDataKeys.EDITOR);
}
}
if (editor != null) {
Document document = editor.getDocument();
VirtualFile file = FileDocumentManager.getInstance().getFile(document);
if (file != null && file.isValid()) {
myOriginatorReference = DocumentReferenceManager.getInstance().create(file);
}
}
}
}
LOG.assertTrue(myCurrentMerger != null, String.valueOf(myCommandLevel));
myCurrentMerger.setBeforeState(getCurrentState());
myCurrentMerger.mergeUndoConfirmationPolicy(undoConfirmationPolicy);
myCommandLevel++;
}
private MyDragSession(MouseEvent me, @Nonnull DockableContent content) {
myWindow = JWindowPopupFactory.getInstance().create(null);
myContent = content;
Image previewImage = content.getPreviewImage();
double requiredSize = 220;
double width = previewImage.getWidth(null);
double height = previewImage.getHeight(null);
double ratio;
if (width > height) {
ratio = requiredSize / width;
}
else {
ratio = requiredSize / height;
}
BufferedImage buffer = UIUtil.createImage(myWindow, (int)width, (int)height, BufferedImage.TYPE_INT_ARGB);
buffer.createGraphics().drawImage(previewImage, 0, 0, (int)width, (int)height, null);
myDefaultDragImage = buffer.getScaledInstance((int)(width * ratio), (int)(height * ratio), Image.SCALE_SMOOTH);
myDragImage = myDefaultDragImage;
myWindow.getContentPane().setLayout(new BorderLayout());
myImageContainer = new JLabel(IconUtil.createImageIcon(myDragImage));
myImageContainer.setBorder(new LineBorder(Color.lightGray));
myWindow.getContentPane().add(myImageContainer, BorderLayout.CENTER);
setLocationFrom(me);
myWindow.setVisible(true);
WindowManagerEx.getInstanceEx().setAlphaModeEnabled(myWindow, true);
WindowManagerEx.getInstanceEx().setAlphaModeRatio(myWindow, 0.1f);
myWindow.getRootPane().putClientProperty("Window.shadow", Boolean.FALSE);
}
public void setTransparent(boolean transparent) {
if (transparent) {
WindowManagerEx.getInstanceEx().setAlphaModeEnabled(getFrame(), true);
WindowManagerEx.getInstanceEx().setAlphaModeRatio(getFrame(), 0.5f);
}
else {
WindowManagerEx.getInstanceEx().setAlphaModeEnabled(getFrame(), true);
WindowManagerEx.getInstanceEx().setAlphaModeRatio(getFrame(), 0f);
}
}
@Nullable
@RequiredUIAccess
private static Component getOccurenceNavigatorFromContext(DataContext dataContext) {
Window window = TargetAWT.to(WindowManagerEx.getInstanceEx().getMostRecentFocusedWindow());
if (window != null) {
Component component = window.getFocusOwner();
for (Component c = component; c != null; c = c.getParent()) {
if (c instanceof OccurenceNavigator) {
return c;
}
}
}
Project project = dataContext.getData(CommonDataKeys.PROJECT);
if (project == null) {
return null;
}
ToolWindowManagerEx mgr = ToolWindowManagerEx.getInstanceEx(project);
String id = mgr.getLastActiveToolWindowId(component -> findNavigator(component) != null);
if (id == null) {
return null;
}
return (Component)findNavigator(mgr.getToolWindow(id).getComponent());
}
public void actionPerformed(AnActionEvent e){
Project project = e.getData(CommonDataKeys.PROJECT);
if(project==null){
return;
}
ToolWindowLayout layout = ToolWindowManagerEx.getInstanceEx(project).getLayout();
WindowManagerEx.getInstanceEx().setLayout(layout);
}
public void actionPerformed(AnActionEvent e){
Project project = e.getData(CommonDataKeys.PROJECT);
if(project==null){
return;
}
ToolWindowLayout layout=WindowManagerEx.getInstanceEx().getLayout();
ToolWindowManagerEx.getInstanceEx(project).setLayout(layout);
}
private static void showPopup(@Nonnull Project project, @Nonnull JBPopup popup) {
Point savedLocation = DimensionService.getInstance().getLocation(LOCATION_SETTINGS_KEY, project);
Window recentFocusedWindow = TargetAWT.to(WindowManagerEx.getInstanceEx().getMostRecentFocusedWindow());
if (savedLocation != null && recentFocusedWindow != null) {
popup.showInScreenCoordinates(recentFocusedWindow, savedLocation);
}
else {
popup.showCenteredInCurrentWindow(project);
}
}