@NoWarning("BC") public void actionPerformed(ActionEvent e) { Component c = (Component) e.getSource(); JPopupMenu jpm = (JPopupMenu) SwingUtilities.getAncestorOfClass(JPopupMenu.class, c); } }
public void centerCurrentLine() { JViewport viewport = (JViewport) SwingUtilities.getAncestorOfClass(JViewport.class, this); if (viewport == null) { return; } try { Rectangle r = modelToView(getCaretPosition()); if (r == null) { return; } int extentHeight = viewport.getExtentSize().height; Dimension viewSize = viewport.getViewSize(); if (viewSize == null) { return; } int viewHeight = viewSize.height; int y = Math.max(0, r.y - extentHeight / 2); y = Math.min(y, viewHeight - extentHeight); viewport.setViewPosition(new Point(0, y)); } catch (BadLocationException e) { LOG.debug("Can't center current line", e); } }
protected JDialog createDialog(Component parent) { Frame frame = parent instanceof Frame ? (Frame) parent : (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parent); JDialog dialog = new JDialog(frame, ("Select Font"), true); Action okAction = new DialogOKAction(dialog); Action cancelAction = new DialogCancelAction(dialog); JButton okButton = new JButton(okAction); okButton.setFont(DEFAULT_FONT); JButton cancelButton = new JButton(cancelAction); cancelButton.setFont(DEFAULT_FONT); JPanel buttonsPanel = new JPanel(); buttonsPanel.setLayout(new GridLayout(2, 1)); buttonsPanel.add(okButton); buttonsPanel.add(cancelButton); buttonsPanel.setBorder(BorderFactory.createEmptyBorder(25, 0, 10, 10)); ActionMap actionMap = buttonsPanel.getActionMap(); actionMap.put(cancelAction.getValue(Action.DEFAULT), cancelAction); actionMap.put(okAction.getValue(Action.DEFAULT), okAction); InputMap inputMap = buttonsPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), cancelAction.getValue(Action.DEFAULT)); inputMap.put(KeyStroke.getKeyStroke("ENTER"), okAction.getValue(Action.DEFAULT)); JPanel dialogEastPanel = new JPanel(); dialogEastPanel.setLayout(new BorderLayout()); dialogEastPanel.add(buttonsPanel, BorderLayout.NORTH); dialog.getContentPane().add(this, BorderLayout.CENTER); dialog.getContentPane().add(dialogEastPanel, BorderLayout.EAST); dialog.pack(); dialog.setLocationRelativeTo(frame); return dialog; }
public void postKey(@NotNull KeyStroke stroke, @NotNull Editor editor) { final Component component = SwingUtilities.getAncestorOfClass(Window.class, editor.getComponent()); final KeyEvent event = createKeyEvent(stroke, component); ApplicationManager.getApplication().invokeLater(() -> { if (logger.isDebugEnabled()) { logger.debug("posting " + event); } Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(event); }); }
private FileDialog createFileDialog( File currentDirectory ) { if( badger != null ) return null; if( !Boolean.getBoolean("nb.native.filechooser") ) return null; if( dirsOnly && !Utilities.isMac() ) return null; Component parentComponent = findDialogParent(); Frame parentFrame = (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parentComponent); FileDialog fileDialog = new FileDialog(parentFrame); if (title != null) { fileDialog.setTitle(title); } if( null != currentDirectory ) fileDialog.setDirectory(currentDirectory.getAbsolutePath()); return fileDialog; }
private void positionPanel() { if (parent == null) return; Container scroll = SwingUtilities.getAncestorOfClass(JScrollPane.class, parent); int height = (int)getPreferredSize().getHeight(); if (scroll != null) { Rectangle bounds = scroll.getBounds(); bounds.translate(0, scroll.getHeight() - height); bounds.height = height; Point pos = SwingUtilities.convertPoint(scroll.getParent(), bounds.getLocation(), oldGlass); bounds.setLocation(pos); setBounds(bounds); repaint(); } }
} else { frame = (parent instanceof java.awt.Frame) ? (Frame) parent : (Frame) javax.swing.SwingUtilities.getAncestorOfClass( Frame.class, parent );
final Container scroll = SwingUtilities.getAncestorOfClass(JScrollPane.class, myParent); final int height = (int)getPreferredSize().getHeight(); if (scroll != null) {
JTable table = (JTable) SwingUtilities.getAncestorOfClass(JTable.class, (Component) e.getSource()); int row = table.getEditingRow(); table.getCellEditor().stopCellEditing();
private void positionPanel() { final JComponent contentComponent = myEditor.getContentComponent(); Container scroll = SwingUtilities.getAncestorOfClass(JScrollPane.class, contentComponent); setSize(scroll.getSize()); myLineHeight = myText.getFontMetrics(myText.getFont()).getHeight(); int count = countLines(myText.getText()); int visLines = getSize().height / myLineHeight - 1; int lines = Math.min(count, visLines); setSize(getSize().width, lines * myLineHeight + myLabel.getPreferredSize().height + getBorder().getBorderInsets(this).top * 2); int height = getSize().height; Rectangle bounds = scroll.getBounds(); bounds.translate(0, scroll.getHeight() - height); bounds.height = height; Point pos = SwingUtilities.convertPoint(scroll.getParent(), bounds.getLocation(), SwingUtilities.getRootPane(contentComponent).getGlassPane()); bounds.setLocation(pos); setBounds(bounds); myScrollPane.getVerticalScrollBar().setValue(0); if (!Options.getInstance().isSet("more")) { // FIX scrollOffset(100000); } else { scrollOffset(0); } }
private void pickCustomColor() { Color c = JColorChooser.showDialog( SwingUtilities.getAncestorOfClass( Dialog.class, this ), NbBundle.getMessage( ColorComboBox.class, "SelectColor" ), //NOI18N lastSelection != null ? (( ColorValue ) lastSelection).color : null ); if( c != null ) { setSelectedColor( c ); } else if( lastSelection != null ) { setSelectedItem( lastSelection ); } }
} else { frame = (parent instanceof java.awt.Frame) ? (Frame) parent : (Frame) javax.swing.SwingUtilities.getAncestorOfClass( Frame.class, parent );
public static MapView getMapView(final Component component) { if(component instanceof MapView) return (MapView) component; return (MapView) SwingUtilities.getAncestorOfClass(MapView.class, component); }
destination = SwingUtilities.getAncestorOfClass(destinationClass, source);
@Override public void run () { TopComponent toClose = ( TopComponent ) SwingUtilities.getAncestorOfClass( TopComponent.class, CloneableEditor.this ); if( null == toClose ) toClose = CloneableEditor.this; toClose.close(); } });
public void actionPerformed(ActionEvent actionEvent) { PSheet sheet = (PSheet) SwingUtilities.getAncestorOfClass(PSheet.class, this); if (sheet != null) { sheet.helpRequested(); } }
/** * Notification method that the user has requested a popup menu. */ protected void popupRequested(Point p) { PropertySheet ps = (PropertySheet) SwingUtilities.getAncestorOfClass(PropertySheet.class, this); if (ps != null) { ps.showPopup(p); } }
public void mouseMoved(MouseEvent e) { Point p = e.getPoint(); JComponent comp = (JComponent) e.getSource(); JScrollPane jsp = (JScrollPane) SwingUtilities.getAncestorOfClass(JScrollPane.class, comp); if (jsp != null) { p = SwingUtilities.convertPoint (comp, p, jsp); show(jsp, p); } }
private Component getDialogParent() { // @@TODO move prefs somewhere more central Preferences prefs = PreferencesManager.getInstance().getApplicationPreferences(ProtegeApplication.ID); return prefs.getBoolean(GeneralPreferencesPanel.DIALOGS_ALWAYS_CENTRED, false) ? SwingUtilities.getAncestorOfClass(Frame.class, getParent()) : getParent(); }
@Override protected int getMaxAvailablePageWidth(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Insets insets = list.getInsets();//OWLFrameList.ITEM_BORDER.getBorderInsets(); int componentWidth = list.getWidth(); JViewport vp = (JViewport) SwingUtilities.getAncestorOfClass(JViewport.class, list); if (vp != null) { componentWidth = vp.getViewRect().width; } int width = componentWidth - list.getInsets().left - list.getInsets().right - insets.left + insets.right - 20; return width > 0 ? width : 500; }