Java Code Examples for org.openide.util.Utilities#getUsableScreenBounds()
The following examples show how to use
org.openide.util.Utilities#getUsableScreenBounds() .
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: Table.java From netbeans with Apache License 2.0 | 6 votes |
@Override public Dimension getPreferredScrollableViewportSize() { if( needCalcRowHeight ) { calcRowHeight( getOffscreenGraphics() ); prefSize = null; } if( null == prefSize ) { Dimension dim = new Dimension(); for( int i=0; i<getColumnCount(); i++ ) { TableColumn tc = getColumnModel().getColumn( i ); dim.width += tc.getPreferredWidth(); } int rowCount = Math.min( MAX_VISIBLE_ROWS, getRowCount() ); dim.height = rowCount*getRowHeight(); Rectangle screen = Utilities.getUsableScreenBounds(); dim.width = Math.min( dim.width, screen.width-100 ); dim.height = Math.min( dim.height, screen.height-100 ); prefSize = dim; } return prefSize; }
Example 2
Source File: CommandManager.java From netbeans with Apache License 2.0 | 6 votes |
/** Shows given popup on given coordinations and takes care about the * situation when menu can exceed screen limits */ private static void showPopupMenu (JPopupMenu popup, Point p, Component comp) { if (NO_POPUP_PLACEMENT_HACK) { popup.show(comp, p.x, p.y); return; } SwingUtilities.convertPointToScreen (p, comp); Dimension popupSize = popup.getPreferredSize (); Rectangle screenBounds = Utilities.getUsableScreenBounds(comp.getGraphicsConfiguration()); if (p.x + popupSize.width > screenBounds.x + screenBounds.width) { p.x = screenBounds.x + screenBounds.width - popupSize.width; } if (p.y + popupSize.height > screenBounds.y + screenBounds.height) { p.y = screenBounds.y + screenBounds.height - popupSize.height; } SwingUtilities.convertPointFromScreen (p, comp); popup.show(comp, p.x, p.y); }
Example 3
Source File: CompletionLayoutPopup.java From netbeans with Apache License 2.0 | 6 votes |
/** * Find bounds of the popup based on knowledge of the preferred size * of the content component and the preference of the displaying * of the popup either above or below the occupied bounds. * * @param occupiedBounds bounds of the rectangle above or below which * the bounds should be found. * @param aboveOccupiedBounds whether the bounds should be found for position * above or below the occupied bounds. * @return rectangle with absolute screen bounds of the popup. */ private Rectangle findPopupBounds(Rectangle occupiedBounds, boolean aboveOccupiedBounds) { Rectangle screen = Utilities.getUsableScreenBounds(); Dimension prefSize = getPreferredSize(); Rectangle popupBounds = new Rectangle(); popupBounds.x = Math.min(occupiedBounds.x, (screen.x + screen.width) - prefSize.width); popupBounds.x = Math.max(popupBounds.x, screen.x); popupBounds.width = Math.min(prefSize.width, screen.width); if (aboveOccupiedBounds) { popupBounds.height = Math.min(prefSize.height, occupiedBounds.y - screen.y - CompletionLayout.POPUP_VERTICAL_GAP); popupBounds.y = occupiedBounds.y - CompletionLayout.POPUP_VERTICAL_GAP - popupBounds.height; } else { // below caret popupBounds.y = occupiedBounds.y + occupiedBounds.height + CompletionLayout.POPUP_VERTICAL_GAP; popupBounds.height = Math.min(prefSize.height, (screen.y + screen.height) - popupBounds.y); } return popupBounds; }
Example 4
Source File: ButtonPopupSwitcher.java From netbeans with Apache License 2.0 | 5 votes |
/** Creates a new instance of TabListPanel */ private ButtonPopupSwitcher(JComponent owner, SwitcherTableItem items[], int x, int y) { int ownerWidth = owner.getWidth(); int ownerHeight = owner.getHeight(); int cornerX, cornerY; int xOrient, yOrient; Rectangle screenRect = Utilities.getUsableScreenBounds(); // get rid of the effect when popup seems to be higher that screen height int gap = (y == 0 ? 10 : 5); int height = 0; int width = 0; int leftD = x - screenRect.x; int rightD = screenRect.x + screenRect.width - x; if (leftD < rightD / 2) { xOrient = 1; width = rightD; cornerX = x + 1; } else { xOrient = -1; width = leftD + ownerWidth; cornerX = x + ownerWidth; } int topD = y - screenRect.y; int bottomD = screenRect.y + screenRect.height - y; if (bottomD < topD / 4) { yOrient = -1; height = topD - gap; cornerY = y; } else { yOrient = 1; cornerY = y + ownerHeight; height = screenRect.height - cornerY - gap; } this.pTable = new SwitcherTable(items, height, width); this.x = cornerX - (xOrient == -1 ? (int) pTable.getPreferredSize().getWidth() : 0); this.y = cornerY - (yOrient == -1 ? (int) pTable.getPreferredSize().getHeight() : 0); }
Example 5
Source File: CompletionLayoutPopup.java From netbeans with Apache License 2.0 | 5 votes |
final Dimension getPreferredSize() { JComponent comp = getContentComponent(); if (comp == null) return new Dimension(0, 0); int screenWidth = Utilities.getUsableScreenBounds().width; Dimension maxSize = new Dimension((int) (screenWidth * MAX_COMPL_COVERAGE), comp.getMaximumSize().height); //set maximum part of screen covered setMaxSize(comp, maxSize); return comp.getPreferredSize(); }
Example 6
Source File: KeyboardPopupSwitcher.java From netbeans with Apache License 2.0 | 5 votes |
private void showPopup() { if (!isShown()) { // set popup to be always on top to be in front of all // floating separate windows popup = new JWindow(); popup.setAlwaysOnTop(true); popup.getContentPane().add(switcher); Dimension popupDim = switcher.getPreferredSize(); Rectangle screen = Utilities.getUsableScreenBounds(); int x = screen.x + ((screen.width / 2) - (popupDim.width / 2)); int y = screen.y + ((screen.height / 2) - (popupDim.height / 2)); popup.setLocation(x, y); popup.pack(); MenuSelectionManager.defaultManager().addChangeListener( new ChangeListener() { @Override public void stateChanged( ChangeEvent e ) { MenuSelectionManager.defaultManager().removeChangeListener( this ); hidePopup(); } }); popup.setVisible(true); // #82743 - on JDK 1.5 popup steals focus from main window for a millisecond, // so we have to delay attaching of focus listener SwingUtilities.invokeLater(new Runnable() { @Override public void run () { WindowManager.getDefault().getMainWindow(). addWindowFocusListener( KeyboardPopupSwitcher.this ); } }); shown = true; } }
Example 7
Source File: OptionsPanel.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Dimension getPreferredSize() { //#108865 Scrollbars appear on Options dialog - preferredSize mustn't exceed screenBounds.? - 100 //else NbPresenter will show up scrollbars Dimension d = super.getPreferredSize(); final Rectangle screenBounds = Utilities.getUsableScreenBounds(); return new Dimension(Math.min(d.width, screenBounds.width - 101), Math.min(d.height, screenBounds.height - 101)); }
Example 8
Source File: CompletionJList.java From netbeans with Apache License 2.0 | 5 votes |
void setData(List data, int selectedIndex) { smartIndex = -1; if (data != null) { int itemCount = data.size(); ListCellRenderer renderer = getCellRenderer(); int width = 0; int maxWidth = getParent().getParent().getMaximumSize().width; boolean stop = false; for(int index = 0; index < itemCount; index++) { Object value = data.get(index); if (value instanceof LazyCompletionItem) { maxWidth = (int)(Utilities.getUsableScreenBounds().width * CompletionLayoutPopup.COMPL_COVERAGE); } Component c = renderer.getListCellRendererComponent(this, value, index, false, false); if (c != null) { Dimension cellSize = c.getPreferredSize(); if (cellSize.width > width) { width = cellSize.width; if (width >= maxWidth) stop = true; } } if (smartIndex < 0 && value instanceof CompletionItem && ((CompletionItem)value).getSortPriority() >= 0) smartIndex = index; if (stop && smartIndex >= 0) break; } setFixedCellWidth(width); LazyListModel lm = LazyListModel.create( new Model(data), CompletionImpl.filter, 1.0d, LocaleSupport.getString("completion-please-wait") ); //NOI18N setModel(lm); if (itemCount > 0) { setSelectedIndex(selectedIndex < 0 ? 0 : lm.findExternalIndex(selectedIndex)); } int visibleRowCount = Math.min(itemCount, maxVisibleRowCount); setVisibleRowCount(visibleRowCount); } }
Example 9
Source File: JPopupMenuUtils.java From netbeans with Apache License 2.0 | 4 votes |
public static Rectangle getScreenRect() { return Utilities.getUsableScreenBounds(); }
Example 10
Source File: FileSearchAction.java From netbeans with Apache License 2.0 | 4 votes |
private Dialog createDialog( final FileSearchPanel panel) { openBtn = new JButton(); Mnemonics.setLocalizedText(openBtn, NbBundle.getMessage(FileSearchAction.class, "CTL_Open")); openBtn.getAccessibleContext().setAccessibleDescription(openBtn.getText()); openBtn.setEnabled( false ); final Object[] buttons = new Object[] { openBtn, DialogDescriptor.CANCEL_OPTION }; String title = NbBundle.getMessage(FileSearchAction.class, "MSG_FileSearchDlgTitle"); DialogDescriptor dialogDescriptor = new DialogDescriptor( panel, title, true, buttons, openBtn, DialogDescriptor.DEFAULT_ALIGN, HelpCtx.DEFAULT_HELP, new DialogButtonListener(panel)); dialogDescriptor.setClosingOptions(buttons); Dialog d = DialogDisplayer.getDefault().createDialog(dialogDescriptor); d.getAccessibleContext().setAccessibleName(NbBundle.getMessage(FileSearchAction.class, "AN_FileSearchDialog")); d.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(FileSearchAction.class, "AD_FileSearchDialog")); // Set size d.setPreferredSize( new Dimension( FileSearchOptions.getWidth(), FileSearchOptions.getHeight() ) ); // Center the dialog after the size changed. Rectangle r = Utilities.getUsableScreenBounds(); int maxW = (r.width * 9) / 10; int maxH = (r.height * 9) / 10; Dimension dim = d.getPreferredSize(); dim.width = Math.min(dim.width, maxW); dim.height = Math.min(dim.height, maxH); initialDimension = dim; d.setBounds(Utilities.findCenterBounds(dim)); d.addWindowListener(new WindowAdapter() { public @Override void windowClosed(WindowEvent e) { cleanup(false); } }); return d; }
Example 11
Source File: DialogFactory.java From netbeans with Apache License 2.0 | 4 votes |
static Dialog createDialog( final String title, final GoToPanelImpl panel, final GoToPanelImpl.ContentProvider contentProvider, final JButton okButton) { okButton.setEnabled (false); panel.getAccessibleContext().setAccessibleName( NbBundle.getMessage( GoToSymbolAction.class, "AN_GoToSymbol") ); //NOI18N panel.getAccessibleContext().setAccessibleDescription( NbBundle.getMessage( GoToSymbolAction.class, "AD_GoToSymbol") ); //NOI18N DialogDescriptor dialogDescriptor = new DialogDescriptor( panel, // innerPane title, // displayName true, new Object[] {okButton, DialogDescriptor.CANCEL_OPTION}, okButton, DialogDescriptor.DEFAULT_ALIGN, HelpCtx.DEFAULT_HELP, new DialogButtonListener(panel, okButton)); dialogDescriptor.setClosingOptions(new Object[] {okButton, DialogDescriptor.CANCEL_OPTION}); Dialog d = DialogDisplayer.getDefault().createDialog( dialogDescriptor ); // Set size when needed final int width = UiOptions.GoToSymbolDialog.getWidth(); final int height = UiOptions.GoToSymbolDialog.getHeight(); if (width != -1 && height != -1) { d.setPreferredSize(new Dimension(width,height)); } // Center the dialog after the size changed. Rectangle r = Utilities.getUsableScreenBounds(); int maxW = (r.width * 9) / 10; int maxH = (r.height * 9) / 10; final Dimension dim = d.getPreferredSize(); dim.width = Math.min(dim.width, maxW); dim.height = Math.min(dim.height, maxH); d.setBounds(Utilities.findCenterBounds(dim)); initialDimension = dim; d.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { contentProvider.closeDialog(); } }); return d; }
Example 12
Source File: GoToTypeAction.java From netbeans with Apache License 2.0 | 4 votes |
/** Creates the dialog to show */ private Dialog createDialog( final GoToPanel panel) { okButton = new JButton (NbBundle.getMessage(GoToTypeAction.class, "CTL_OK")); okButton.getAccessibleContext().setAccessibleDescription(okButton.getText()); okButton.setEnabled (false); panel.getAccessibleContext().setAccessibleName( NbBundle.getMessage( GoToTypeAction.class, "AN_GoToType") ); //NOI18N panel.getAccessibleContext().setAccessibleDescription( NbBundle.getMessage( GoToTypeAction.class, "AD_GoToType") ); //NOI18N DialogDescriptor dialogDescriptor = new DialogDescriptor( panel, // innerPane title, // displayName true, new Object[] {okButton, DialogDescriptor.CANCEL_OPTION}, okButton, DialogDescriptor.DEFAULT_ALIGN, HelpCtx.DEFAULT_HELP, new DialogButtonListener( panel ) ); // Action listener dialogDescriptor.setClosingOptions(new Object[] {okButton, DialogDescriptor.CANCEL_OPTION}); // panel.addPropertyChangeListener( new HelpCtxChangeListener( dialogDescriptor, helpCtx ) ); // if ( panel instanceof HelpCtx.Provider ) { // dialogDescriptor.setHelpCtx( ((HelpCtx.Provider)panel).getHelpCtx() ); // } Dialog d = DialogDisplayer.getDefault().createDialog( dialogDescriptor ); // Set size when needed final int width = UiOptions.GoToTypeDialog.getWidth(); final int height = UiOptions.GoToTypeDialog.getHeight(); if (width != -1 && height != -1) { d.setPreferredSize(new Dimension(width,height)); } // Center the dialog after the size changed. Rectangle r = Utilities.getUsableScreenBounds(); int maxW = (r.width * 9) / 10; int maxH = (r.height * 9) / 10; final Dimension dim = d.getPreferredSize(); dim.width = Math.min(dim.width, maxW); dim.height = Math.min(dim.height, maxH); d.setBounds(Utilities.findCenterBounds(dim)); initialDimension = dim; d.addWindowListener(new WindowAdapter() { public @Override void windowClosed(WindowEvent e) { cleanup(); } }); return d; }
Example 13
Source File: CompletionLayoutPopup.java From netbeans with Apache License 2.0 | 4 votes |
/** * Displays popup right, left of currently occupied bounds if possible, * otherwise fallback to above/below * @param occupiedBounds bounds of CC popup * @param unionBounds bounds occupied by all popups */ void showAlongOrNextOccupiedBounds(Rectangle occupiedBounds, Rectangle unionBounds) { if (occupiedBounds != null) { Rectangle screen = Utilities.getUsableScreenBounds(); Dimension prefSize = getPreferredSize(); Rectangle bounds = new Rectangle(); boolean aboveCaret; if (isEnoughSpace(occupiedBounds, preferDisplayAboveCaret)) { aboveCaret = preferDisplayAboveCaret; } else aboveCaret = false; boolean left = false; boolean right = false; // Right of CC if (occupiedBounds.x + occupiedBounds.width + prefSize.width < screen.width && occupiedBounds.y + prefSize.height < screen.height) { bounds.x = occupiedBounds.x + occupiedBounds.width + CompletionLayout.POPUP_VERTICAL_GAP; right = true; } // Left of CC if (!right && occupiedBounds.x - prefSize.width > 0 && occupiedBounds.y + prefSize.height < screen.height) { bounds.x = occupiedBounds.x - prefSize.width - CompletionLayout.POPUP_VERTICAL_GAP; left = true; } if (right || left) { bounds.width = prefSize.width; bounds.height = Math.min(prefSize.height, screen.height); if (aboveCaret) { bounds.y = occupiedBounds.y + occupiedBounds.height - prefSize.height; } else { bounds.y = occupiedBounds.y; } show(bounds, aboveCaret); return; } } // Fallback to Above/Below showAlongOccupiedBounds(unionBounds); }
Example 14
Source File: CompletionLayoutPopup.java From netbeans with Apache License 2.0 | 4 votes |
/** * Displays popup right, left of currently occupied bounds if possible, * otherwise fallback to above/below * @param occupiedBounds bounds of CC popup * @param unionBounds bounds occupied by all popups */ void showAlongOrNextOccupiedBounds(Rectangle occupiedBounds, Rectangle unionBounds) { if (occupiedBounds != null) { Rectangle screen = Utilities.getUsableScreenBounds(); Dimension prefSize = getPreferredSize(); Rectangle bounds = new Rectangle(); boolean aboveCaret; if (isEnoughSpace(occupiedBounds, preferDisplayAboveCaret)) { aboveCaret = preferDisplayAboveCaret; } else { aboveCaret = false; } boolean left = false; boolean right = false; // Right of CC if (occupiedBounds.x + occupiedBounds.width + prefSize.width < screen.width && occupiedBounds.y + prefSize.height < screen.height) { bounds.x = occupiedBounds.x + occupiedBounds.width + ScrollCompletionPane.POPUP_VERTICAL_GAP; right = true; } // Left of CC if (!right && occupiedBounds.x - prefSize.width > 0 && occupiedBounds.y + prefSize.height < screen.height) { bounds.x = occupiedBounds.x - prefSize.width - ScrollCompletionPane.POPUP_VERTICAL_GAP; left = true; } if (right || left) { bounds.width = prefSize.width; bounds.height = Math.min(prefSize.height, screen.height); if (aboveCaret) { bounds.y = occupiedBounds.y + occupiedBounds.height - prefSize.height; } else { bounds.y = occupiedBounds.y; } show(bounds, aboveCaret); return; } } // Fallback to Above/Below showAlongOccupiedBounds(unionBounds); }
Example 15
Source File: CompletionLayoutPopup.java From netbeans with Apache License 2.0 | 4 votes |
/** * Displays popup right, left of currently occupied bounds if possible, * otherwise fallback to above/below * @param occupiedBounds bounds of CC popup * @param unionBounds bounds occupied by all popups */ void showAlongOrNextOccupiedBounds(Rectangle occupiedBounds, Rectangle unionBounds) { if (occupiedBounds != null) { Rectangle screen = Utilities.getUsableScreenBounds(); Dimension prefSize = getPreferredSize(); Rectangle bounds = new Rectangle(); boolean aboveCaret; if (isEnoughSpace(occupiedBounds, preferDisplayAboveCaret)) { aboveCaret = preferDisplayAboveCaret; } else aboveCaret = false; boolean left = false; boolean right = false; // Right of CC if (occupiedBounds.x + occupiedBounds.width + prefSize.width < screen.width && occupiedBounds.y + prefSize.height < screen.height) { bounds.x = occupiedBounds.x + occupiedBounds.width + CompletionLayout.POPUP_VERTICAL_GAP; right = true; } // Left of CC if (!right && occupiedBounds.x - prefSize.width > 0 && occupiedBounds.y + prefSize.height < screen.height) { bounds.x = occupiedBounds.x - prefSize.width - CompletionLayout.POPUP_VERTICAL_GAP; left = true; } if (right || left) { bounds.width = prefSize.width; bounds.height = Math.min(prefSize.height, screen.height); if (aboveCaret) { bounds.y = occupiedBounds.y + occupiedBounds.height - prefSize.height; } else { bounds.y = occupiedBounds.y; } show(bounds, aboveCaret); return; } } // Fallback to Above/Below showAlongOccupiedBounds(unionBounds); }
Example 16
Source File: SwitcherTable.java From netbeans with Apache License 2.0 | 3 votes |
/** * Show new set of switcher items in this table. * @param newItems * @param y * * @since 1.35 */ public void setSwitcherItems( SwitcherTableItem[] newItems, int y ) { int gap = (y == 0 ? 10 : 5); int height = Utilities.getUsableScreenBounds().height - y - gap; setModel(new SwitcherTableModel(newItems, getRowHeight(), height)); prefSize = null; }
Example 17
Source File: CompletionLayoutPopup.java From netbeans with Apache License 2.0 | 3 votes |
/** * Check whether there is enough space for this popup above * or below the given occupied bounds. * * @param occupiedBounds bounds above or below which the available * space should be determined. * @param aboveOccupiedBounds whether the space should be checked above * or below the occupiedBounds. * @return true if there is enough space for the preferred size of this popup * on the requested side or false if not. */ boolean isEnoughSpace(Rectangle occupiedBounds, boolean aboveOccupiedBounds) { Rectangle screen = Utilities.getUsableScreenBounds(); int freeHeight = aboveOccupiedBounds ? occupiedBounds.y - screen.y : (screen.y + screen.height) - (occupiedBounds.y + occupiedBounds.height); Dimension prefSize = getPreferredSize(); return (prefSize.height < freeHeight); }
Example 18
Source File: CompletionLayoutPopup.java From netbeans with Apache License 2.0 | 3 votes |
/** * Check whether there is enough space for this popup above * or below the given occupied bounds. * * @param occupiedBounds bounds above or below which the available * space should be determined. * @param aboveOccupiedBounds whether the space should be checked above * or below the occupiedBounds. * @return true if there is enough space for the preferred size of this popup * on the requested side or false if not. */ boolean isEnoughSpace(Rectangle occupiedBounds, boolean aboveOccupiedBounds) { Rectangle screen = Utilities.getUsableScreenBounds(); int freeHeight = aboveOccupiedBounds ? occupiedBounds.y - screen.y : (screen.y + screen.height) - (occupiedBounds.y + occupiedBounds.height); Dimension prefSize = getPreferredSize(); return (prefSize.height < freeHeight); }
Example 19
Source File: SwitcherTableModel.java From netbeans with Apache License 2.0 | 2 votes |
/** * Use whole screen for table height during number of columns/row * computing. */ SwitcherTableModel(SwitcherTableItem[] items, int rowHeight) { this(items, rowHeight, Utilities.getUsableScreenBounds().height); }
Example 20
Source File: SwitcherTableModel.java From netbeans with Apache License 2.0 | 2 votes |
/** * Use whole screen for table height during number of columns/row * computing. */ SwitcherTableModel(SwitcherTableItem[] items, int rowHeight) { this(items, rowHeight, Utilities.getUsableScreenBounds().height); }