private int getMaxWidth() { if (myMaxWidth < 0) { final Point p = myLookup.getComponent().getLocationOnScreen(); final Rectangle rectangle = ScreenUtil.getScreenRectangle(p); myMaxWidth = rectangle.x + rectangle.width - p.x - 111; } return myMaxWidth; }
private RelativePoint relativePointWithDominantRectangle( final JLayeredPane layeredPane, final Rectangle bounds) { Dimension preferredSize = getComponent().getPreferredSize(); if (myDimensionServiceKey != null) { final Dimension dimension = DimensionService.getInstance().getSize(myDimensionServiceKey, myProject); if (dimension != null) { preferredSize = dimension; } } final Point leftTopCorner = new Point(bounds.x + bounds.width, bounds.y); final Point leftTopCornerScreen = (Point) leftTopCorner.clone(); SwingUtilities.convertPointToScreen(leftTopCornerScreen, layeredPane); final RelativePoint relativePoint; if (!ScreenUtil.isOutsideOnTheRightOFScreen( new Rectangle( leftTopCornerScreen.x, leftTopCornerScreen.y, preferredSize.width, preferredSize.height))) { relativePoint = new RelativePoint(layeredPane, leftTopCorner); } else { if (bounds.x > preferredSize.width) { relativePoint = new RelativePoint(layeredPane, new Point(bounds.x - preferredSize.width, bounds.y)); } else { setDimensionServiceKey(null); // going to cut width Rectangle screen = ScreenUtil.getScreenRectangle(leftTopCornerScreen.x, leftTopCornerScreen.y); final int spaceOnTheLeft = bounds.x; final int spaceOnTheRight = (screen.x + screen.width) - leftTopCornerScreen.x; if (spaceOnTheLeft > spaceOnTheRight) { relativePoint = new RelativePoint(layeredPane, new Point(0, bounds.y)); myComponent.setPreferredSize( new Dimension(spaceOnTheLeft, Math.max(preferredSize.height, 200))); } else { relativePoint = new RelativePoint(layeredPane, leftTopCorner); myComponent.setPreferredSize( new Dimension(spaceOnTheRight, Math.max(preferredSize.height, 200))); } } } return relativePoint; }
public final void writeExternal(final Element element) { // Save frame bounds final Element frameElement = new Element(FRAME_ELEMENT); element.addContent(frameElement); final Project[] projects = ProjectManager.getInstance().getOpenProjects(); final Project project; if (projects.length > 0) { project = projects[projects.length - 1]; } else { project = null; } final IdeFrameImpl frame = getFrame(project); if (frame != null) { int extendedState = frame.getExtendedState(); if (SystemInfo.isMacOSLion && frame.getPeer() instanceof FramePeer) { // frame.state is not updated by jdk so get it directly from peer extendedState = ((FramePeer) frame.getPeer()).getState(); } boolean usePreviousBounds = extendedState == Frame.MAXIMIZED_BOTH || isFullScreenSupportedInCurrentOS() && WindowManagerEx.getInstanceEx().isFullScreen(frame); Rectangle rectangle = usePreviousBounds ? myFrameBounds : frame.getBounds(); if (rectangle == null) { // frame is out of the screen? rectangle = ScreenUtil.getScreenRectangle(0, 0); } frameElement.setAttribute(X_ATTR, Integer.toString(rectangle.x)); frameElement.setAttribute(Y_ATTR, Integer.toString(rectangle.y)); frameElement.setAttribute(WIDTH_ATTR, Integer.toString(rectangle.width)); frameElement.setAttribute(HEIGHT_ATTR, Integer.toString(rectangle.height)); frameElement.setAttribute(EXTENDED_STATE_ATTR, Integer.toString(extendedState)); // Save default layout final Element layoutElement = new Element(DesktopLayout.TAG); element.addContent(layoutElement); myLayout.writeExternal(layoutElement); } }
public void showFrame() { final IdeFrameImpl frame = new IdeFrameImpl( myApplicationInfoEx, myActionManager, myUiSettings, myDataManager, ApplicationManager.getApplication()); myProject2Frame.put(null, frame); if (myFrameBounds == null || !ScreenUtil.isVisible( myFrameBounds)) { // avoid situations when IdeFrame is out of all screens Rectangle rect = ScreenUtil.getScreenRectangle(0, 0); int yParts = rect.height / 6; int xParts = rect.width / 5; myFrameBounds = new Rectangle(xParts, yParts, xParts * 3, yParts * 4); } frame.setBounds(myFrameBounds); frame.setVisible(true); frame.setExtendedState(myFrameExtendedState); }
private static Dimension computeNotBiggerDimension( Dimension ofContent, final Point locationOnScreen) { int resultHeight = ofContent.height > MAX_SIZE.height + 50 ? MAX_SIZE.height : ofContent.height; if (locationOnScreen != null) { final Rectangle r = ScreenUtil.getScreenRectangle(locationOnScreen); resultHeight = ofContent.height > r.height - (r.height / 4) ? r.height - (r.height / 4) : ofContent.height; } int resultWidth = ofContent.width > MAX_SIZE.width ? MAX_SIZE.width : ofContent.width; if (ofContent.height > MAX_SIZE.height) { resultWidth += ScrollPaneFactory.createScrollPane() .getVerticalScrollBar() .getPreferredSize() .getWidth(); } return new Dimension(resultWidth, resultHeight); }
public FlatWelcomeFrame() { final JRootPane rootPane = getRootPane(); myScreen = new FlatWelcomeScreen(); final IdeGlassPaneImpl glassPane = new IdeGlassPaneImpl(rootPane) { @Override public void addNotify() { super.addNotify(); rootPane.remove(getProxyComponent()); //noinspection SSBasedInspection SwingUtilities.invokeLater( new Runnable() { public void run() { JBProtocolCommand.handleCurrentCommand(); } }); } }; setGlassPane(glassPane); glassPane.setVisible(false); // setUndecorated(true); setContentPane(myScreen.getWelcomePanel()); setTitle("Welcome to " + ApplicationNamesInfo.getInstance().getFullProductName()); AppUIUtil.updateWindowIcon(this); final int width = RecentProjectsManager.getInstance().getRecentProjectsActions(false).length == 0 ? 666 : 777; setSize(JBUI.size(width, 460)); setResizable(false); // int x = bounds.x + (bounds.width - getWidth()) / 2; // int y = bounds.y + (bounds.height - getHeight()) / 2; Point location = DimensionService.getInstance().getLocation(WelcomeFrame.DIMENSION_KEY, null); 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)); // setLocation(x, y); ProjectManager.getInstance() .addProjectManagerListener( new ProjectManagerAdapter() { @Override public void projectOpened(Project project) { dispose(); } }); myBalloonLayout = new BalloonLayoutImpl(rootPane, JBUI.insets(8)); WelcomeFrame.setupCloseAction(this); MnemonicHelper.init(this); Disposer.register( ApplicationManager.getApplication(), new Disposable() { @Override public void dispose() { FlatWelcomeFrame.this.dispose(); } }); }
private EditorFragmentComponent( EditorEx editor, int startLine, int endLine, boolean showFolding, boolean showGutter) { Document doc = editor.getDocument(); final int endOffset = endLine < doc.getLineCount() ? doc.getLineEndOffset(endLine) : doc.getTextLength(); int textWidth = Math.min( editor.getMaxWidthInRange(doc.getLineStartOffset(startLine), endOffset), ScreenUtil.getScreenRectangle(1, 1).width); LOG.assertTrue( textWidth > 0, "TextWidth: " + textWidth + "; startLine:" + startLine + "; endLine:" + endLine + ";"); FoldingModelEx foldingModel = editor.getFoldingModel(); boolean isFoldingEnabled = foldingModel.isFoldingEnabled(); if (!showFolding) { foldingModel.setFoldingEnabled(false); } Point p1 = editor.logicalPositionToXY(new LogicalPosition(startLine, 0)); Point p2 = editor.logicalPositionToXY(new LogicalPosition(Math.max(endLine, startLine + 1), 0)); int y1 = p1.y; int y2 = p2.y; int height = y2 - y1 == 0 ? editor.getLineHeight() : y2 - y1; LOG.assertTrue( height > 0, "Height: " + height + "; startLine:" + startLine + "; endLine:" + endLine + "; p1:" + p1 + "; p2:" + p2); int savedScrollOffset = editor.getScrollingModel().getHorizontalScrollOffset(); if (savedScrollOffset > 0) { editor.stopOptimizedScrolling(); editor.getScrollingModel().scrollHorizontally(0); } final Image textImage = new BufferedImage(textWidth, height, BufferedImage.TYPE_INT_RGB); Graphics textGraphics = textImage.getGraphics(); final JComponent rowHeader; final Image markersImage; if (showGutter) { rowHeader = editor.getGutterComponentEx(); markersImage = new BufferedImage(Math.max(1, rowHeader.getWidth()), height, BufferedImage.TYPE_INT_RGB); Graphics markerGraphics = markersImage.getGraphics(); markerGraphics.translate(0, -y1); markerGraphics.setClip(0, y1, rowHeader.getWidth(), height); markerGraphics.setColor(getBackgroundColor(editor)); markerGraphics.fillRect(0, y1, rowHeader.getWidth(), height); rowHeader.paint(markerGraphics); } else { rowHeader = null; markersImage = null; } textGraphics.translate(0, -y1); textGraphics.setClip(0, y1, textWidth, height); final boolean wasVisible = editor.setCaretVisible(false); editor.setPurePaintingMode(true); try { editor.getContentComponent().paint(textGraphics); } finally { editor.setPurePaintingMode(false); } if (wasVisible) { editor.setCaretVisible(true); } if (!showFolding) { foldingModel.setFoldingEnabled(isFoldingEnabled); } if (savedScrollOffset > 0) { editor.stopOptimizedScrolling(); editor.getScrollingModel().scrollHorizontally(savedScrollOffset); } JComponent component = new JComponent() { public Dimension getPreferredSize() { return new Dimension( textImage.getWidth(null) + (markersImage == null ? 0 : markersImage.getWidth(null)), textImage.getHeight(null)); } protected void paintComponent(Graphics graphics) { if (markersImage != null) { graphics.drawImage(markersImage, 0, 0, null); graphics.drawImage(textImage, rowHeader.getWidth(), 0, null); } else { graphics.drawImage(textImage, 0, 0, null); } } }; setLayout(new BorderLayout()); add(component); final Color borderColor = editor.getColorsScheme().getColor(EditorColors.SELECTED_TEARLINE_COLOR); Border outsideBorder = BorderFactory.createLineBorder(borderColor, 1); Border insideBorder = BorderFactory.createEmptyBorder(2, 2, 2, 2); setBorder(BorderFactory.createCompoundBorder(outsideBorder, insideBorder)); }
public void showPopup(final Action actionToSelect, final boolean ensureSelection) { if (myPopupIsShowing) return; myPopupIsShowing = true; final Point loc = getLocationOnScreen(); final Rectangle screen = ScreenUtil.getScreenRectangle(loc); final Dimension popupSize = myUnderPopup.getPreferredSize(); final Rectangle intersection = screen.intersection(new Rectangle(new Point(loc.x, loc.y + getHeight()), popupSize)); final boolean above = intersection.height < popupSize.height; int y = above ? getY() - popupSize.height : getY() + getHeight(); final JPopupMenu popup = above ? myAbovePopup : myUnderPopup; final Ref<PopupMenuListener> listener = new Ref<PopupMenuListener>(); listener.set( new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) {} @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { if (popup != null && listener.get() != null) { popup.removePopupMenuListener(listener.get()); } SwingUtilities.invokeLater( new Runnable() { @Override public void run() { myPopupIsShowing = false; } }); } @Override public void popupMenuCanceled(PopupMenuEvent e) {} }); popup.addPopupMenuListener(listener.get()); popup.show(this, 0, y); SwingUtilities.invokeLater( new Runnable() { @Override public void run() { if (popup == null || !popup.isShowing() || !myPopupIsShowing) return; Action selection = actionToSelect; if (selection == null && myOptions.length > 0 && ensureSelection) { selection = getAction(); } if (selection == null) return; final MenuElement[] elements = popup.getSubElements(); for (MenuElement eachElement : elements) { if (eachElement instanceof JMenuItem) { JMenuItem eachItem = (JMenuItem) eachElement; if (selection.equals(eachItem.getAction())) { final MenuSelectionManager mgr = MenuSelectionManager.defaultManager(); final MenuElement[] path = new MenuElement[2]; path[0] = popup; path[1] = eachItem; mgr.setSelectedPath(path); break; } } } } }); }