/** * Show the given message in a dialog box or independent window, depending on whether the source * component is contained in a Frame or not. * * @param c The Controller that calls this method, or null if it is not called by a Controller. * (The Controller, if any, will be notified when the error message is cleared.) * @param message The message to display. */ public void setErrorMessage(Controller c, String message) { if (popup != null) clearErrorMessage(); if (message == null) return; errorSource = c; errorMessage = message; Component parent = source; while (parent != null && !(parent instanceof Frame)) parent = parent.getParent(); if (parent != null) popup = new Dialog((Frame) parent, "Error Message", true); // modal dialog else popup = new Frame("Error Message"); // independent window popup.setBackground(Color.white); popup.add(new MC(message), BorderLayout.CENTER); Panel buttonBar = new Panel(); buttonBar.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 10)); Button OK = new Button(" OK "); OK.addActionListener(this); buttonBar.add(OK); popup.add(buttonBar, BorderLayout.SOUTH); popup.pack(); if (parent == null) popup.setLocation(100, 80); else popup.setLocation(parent.getLocation().x + 50, parent.getLocation().y + 30); popup.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent evt) { popup.dispose(); } }); popup.show(); // make the dialog visible. }
@Override public Insets getBorderInsets(final Component c) { if (myProject == null) return new Insets(0, 0, 0, 0); ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(myProject); if (!(toolWindowManager instanceof ToolWindowManagerImpl) || !((ToolWindowManagerImpl) toolWindowManager).isToolWindowRegistered(myInfo.getId()) || myWindow.getType() == ToolWindowType.FLOATING) { return new Insets(0, 0, 0, 0); } ToolWindowAnchor anchor = myWindow.getAnchor(); Component component = myWindow.getComponent(); Container parent = component.getParent(); while (parent != null) { if (parent instanceof Splitter) { Splitter splitter = (Splitter) parent; boolean isFirst = splitter.getFirstComponent() == component; boolean isVertical = splitter.isVertical(); return new Insets( 0, anchor == ToolWindowAnchor.RIGHT || (!isVertical && !isFirst) ? 1 : 0, (isVertical && isFirst) ? 1 : 0, anchor == ToolWindowAnchor.LEFT || (!isVertical && isFirst) ? 1 : 0); } component = parent; parent = component.getParent(); } return new Insets( 0, anchor == ToolWindowAnchor.RIGHT ? 1 : 0, anchor == ToolWindowAnchor.TOP ? 1 : 0, anchor == ToolWindowAnchor.LEFT ? 1 : 0); }
protected Frame getFrame(Component comp) { if (comp == null) { comp = this; } if (comp.getParent() instanceof Frame) { return (Frame) comp.getParent(); } return getFrame(comp.getParent()); }
@Override public void setBounds(int x, int y, int width, int height, int op) { super.setBounds(x, y, width, height, op); if (xtext != null) { /* * Fixed 6277332, 6198290: * the coordinates is coming (to peer): relatively to closest HW parent * the coordinates is setting (to textField): relatively to closest ANY parent * the parent of peer is target.getParent() * the parent of textField is the same * see 6277332, 6198290 for more information */ int childX = x; int childY = y; Component parent = target.getParent(); // we up to heavyweight parent in order to be sure // that the coordinates of the text pane is relatively to closest parent while (parent.isLightweight()) { childX -= parent.getX(); childY -= parent.getY(); parent = parent.getParent(); } xtext.setBounds(childX, childY, width, height); xtext.validate(); } }
/** * Creates a new AWT <tt>Container</tt> which can display a single <tt>Component</tt> at a time * (supposedly, one which represents video) and, in the absence of such a <tt>Component</tt>, * displays a predefined default <tt>Component</tt> (in accord with the previous supposition, one * which is the default when there is no video). The returned <tt>Container</tt> will track the * <tt>Components</tt>s added to and removed from it in order to make sure that * <tt>noVideoContainer</tt> is displayed as described. * * @param noVideoComponent the predefined default <tt>Component</tt> to be displayed in the * returned <tt>Container</tt> when there is no other <tt>Component</tt> in it * @return a new <tt>Container</tt> which can display a single <tt>Component</tt> at a time and, * in the absence of such a <tt>Component</tt>, displays <tt>noVideoComponent</tt> */ private VideoContainer createVideoContainer(Component noVideoComponent) { Container oldParent = noVideoComponent.getParent(); if (oldParent != null) oldParent.remove(noVideoComponent); return new VideoContainer(noVideoComponent, false); }
/** * Internal MDI frames have offsets where a popup menu should be shown (in JDK 1.2). This method * sums up iteratively all x and y offsets of all parent compontents until the top parent * component is reached. */ private void adjustOffsets(Component comp, Point offsetPoint) { if (comp != null) { Point compLocation = comp.getLocation(); offsetPoint.translate(compLocation.x, compLocation.y); adjustOffsets(comp.getParent(), offsetPoint); } }
@Override public void keyPressed(KeyEvent evt) { if (evt.isConsumed()) return; Component comp = getFocusOwner(); if (evt.getKeyCode() == KeyEvent.VK_ENTER && enterEnabled) { while (comp != null) { if (comp instanceof JComboBox) { JComboBox<?> combo = (JComboBox<?>) comp; if (combo.isEditable()) { Object selected = combo.getEditor().getItem(); if (selected != null) combo.setSelectedItem(selected); } if (combo.isPopupVisible()) { evt.consume(); combo.setPopupVisible(false); } return; } // TODO: add other classes that need custom key handling here. comp = comp.getParent(); } evt.consume(); ok(); } else if (evt.getKeyCode() == KeyEvent.VK_ESCAPE || isCloseBufferShortcut(evt)) { evt.consume(); if (comp instanceof JComboBox) { JComboBox<?> combo = (JComboBox<?>) comp; if (combo.isPopupVisible()) combo.setPopupVisible(false); else cancel(); } else cancel(); } }
private static Frame getFrame(Component c) { Component w = c; while (!(w instanceof Frame) && (w != null)) { w = w.getParent(); } return (Frame) w; }
/** Return the JComboBox for the given event, or null if none. */ private JComboBox getComboBox(AWTEvent event) { Component comp = (Component) event.getSource(); // Depends somewhat on LAF; sometimes the combo box is itself the // button, sometimes a panel containing the button. if (comp instanceof javax.swing.JButton) comp = comp.getParent(); if (comp instanceof JComboBox) return (JComboBox) comp; return null; }
public static JFrame getFrame(Component c) { if (c instanceof JFrame) return (JFrame) c; while ((c = c.getParent()) != null) { if (c instanceof JFrame) return (JFrame) c; } return null; }
/** * Overridden to enforce the position of the glass component as the zero child. * * @param comp the component to be enhanced * @param constraints the constraints to be respected * @param index the index */ protected void addImpl(Component comp, Object constraints, int index) { super.addImpl(comp, constraints, index); /// We are making sure the glassPane is on top. if (glassPane != null && glassPane.getParent() == this && getComponent(0) != glassPane) { add(glassPane, 0); } }
/** * Returns the specified component's toplevel {@code Frame} or {@code Dialog}. * * @param parentComponent the {@code Component} to check for a {@code Frame} or {@code Dialog} * @return the {@code Frame} or {@code Dialog} that contains the component, or the default frame * if the component is {@code null}, or does not have a valid {@code Frame} or {@code Dialog} * parent */ static Window getWindowForComponent(Component parentComponent) { if (parentComponent == null) { return JOptionPane.getRootFrame(); } if (parentComponent instanceof Frame || parentComponent instanceof Dialog) { return (Window) parentComponent; } return getWindowForComponent(parentComponent.getParent()); }
/* * Keep the size of the component within the bounds of its parent. */ private Dimension getBoundingSize(Component source) { if (source instanceof Window) { GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); Rectangle bounds = env.getMaximumWindowBounds(); return new Dimension(bounds.width, bounds.height); } else { return source.getParent().getSize(); } }
/** * Returns the native container object of the specified component. This method is necessary * because the parent component might be a lightweight component. * * @param component The component to fetch the native container for. * @return The native container object for this component. */ protected static Container getNativeContainer(Component component) { component = component.getParent(); for (; ; ) { if (component == null) return (null); if (!(component instanceof Container)) { component = component.getParent(); continue; } if (component.getPeer() instanceof LightweightPeer) { component = component.getParent(); continue; } return ((Container) component); } }
/** * Checks whether the specified component or one of its ancestors has the specified client * property set to {@link Boolean#TRUE}. * * @param c Component. * @param clientPropName Client property name. * @return <code>true</code> if the specified component or one of its ancestors has the * specified client property set to {@link Boolean#TRUE}, <code>false</code> otherwise. */ private boolean hasClientPropertySetToTrue(Component c, String clientPropName) { while (c != null) { if (c instanceof JComponent) { JComponent jc = (JComponent) c; if (Boolean.TRUE.equals(jc.getClientProperty(clientPropName))) return true; } c = c.getParent(); } return false; }
public static JTableRenderer getVertex(Component component) { while (component != null) { if (component instanceof JTableRenderer) { return (JTableRenderer) component; } component = component.getParent(); } return null; }
public void internalFrameClosed(InternalFrameEvent e) { Component cont = getParent(); while ((cont != null) && (!(cont instanceof JInternalFrame))) { cont = cont.getParent(); } if (cont != null) { if (!((JInternalFrame) cont).isClosed()) { refreshMe(); } } }
/** * Checks if the component is in an EmbeddedFrame. If so, returns the applet found in the * hierarchy or null if not found. * * @return the parent applet or {@ null} * @since 1.6 */ public static Applet getAppletIfAncestorOf(Component comp) { Container parent = comp.getParent(); Applet applet = null; while (parent != null && !(parent instanceof EmbeddedFrame)) { if (parent instanceof Applet) { applet = (Applet) parent; } parent = parent.getParent(); } return parent == null ? null : applet; }
public void propertyChange(PropertyChangeEvent ev) { if (!isEditing() || getClientProperty("terminateEditOnFocusLost") != Boolean.TRUE) { // NOI18N return; } Component c = focusManager.getPermanentFocusOwner(); while (c != null) { if (c == JListMutable.this) { // focus remains inside the table return; } else if ((c instanceof Window) || (c instanceof Applet && c.getParent() == null)) { if (c == SwingUtilities.getRoot(JListMutable.this)) { if (!getListCellEditor().stopCellEditing()) { getListCellEditor().cancelCellEditing(); } } break; } c = c.getParent(); } }
// Overridden for performance reasons. ----> @Override public boolean isOpaque() { Color back = getBackground(); Component p = getParent(); if (Objects.nonNull(p)) { p = p.getParent(); } // p should now be the JTable. boolean colorMatch = Objects.nonNull(back) && Objects.nonNull(p) && back.equals(p.getBackground()) && p.isOpaque(); return !colorMatch && super.isOpaque(); }
/** * This method displays a popup menu, if there is one registered with the Figure (the Figure's * attributes are queried for Figure.POPUP_MENU which is used to indicate an association of a * popup menu with the Figure). * * @param figure Figure for which a popup menu should be displayed * @param x x coordinate where the popup menu should be displayed * @param y y coordinate where the popup menu should be displayed * @param component Component which invoked the popup menu */ protected void showPopupMenu(Figure figure, int x, int y, Component comp) { final Object attribute = figure.getAttribute(Figure.POPUP_MENU); if ((attribute != null) && (attribute instanceof JPopupMenu)) { JPopupMenu popup = (JPopupMenu) attribute; if (popup instanceof PopupMenuFigureSelection) { ((PopupMenuFigureSelection) popup).setSelectedFigure(figure); } // calculate offsets for internal MDI frames Point newLocation = new Point(x, y); adjustOffsets(comp.getParent(), newLocation); popup.setLocation(newLocation); popup.setInvoker(comp); popup.setVisible(true); } }
// java.awt.Toolkit#getNativeContainer() is not available // from this package private WComponentPeer getNearestNativePeer(Component comp) { if (comp == null) return null; ComponentPeer peer = comp.getPeer(); if (peer == null) return null; while (peer instanceof java.awt.peer.LightweightPeer) { comp = comp.getParent(); if (comp == null) return null; peer = comp.getPeer(); if (peer == null) return null; } if (peer instanceof WComponentPeer) return (WComponentPeer) peer; else return null; }
public void actionPerformed(ActionEvent evt) { Component parent = extensionButton.getParent(); while ((parent != null) && !(parent instanceof Frame)) parent = parent.getParent(); String newExtensions = JOptionPane.showInputDialog( parent, "Edit the extension list.\nSeparate extensions by commas.\n\n", filter.getExtensionString()); if ((newExtensions != null) && !newExtensions.trim().equals("")) { newExtensions = newExtensions.replaceAll("\\s", ""); filter.setExtensions(newExtensions); extensionButton.setText(filter.getDescription()); properties.setProperty("extensions", filter.getExtensionString()); directoryPane.reloadTree(); } }
public void refreshMe() { Component cont = getParent(); while ((cont != null) && (!(cont instanceof JInternalFrame))) { cont = cont.getParent(); } if (cont != null) { if (!((JInternalFrame) cont).isClosed()) { Collection<ICFBamTableColObj> dataCollection; ICFBamTextTypeObj focus = (ICFBamTextTypeObj) getSwingFocusAsTextType(); if (focus != null) { dataCollection = focus.getOptionalChildrenRef(swingIsInitializing); } else { dataCollection = null; } JPanel panel = getTabViewChildrenRefListJPanel(); ICFBamSwingTableColJPanelList jpList = (ICFBamSwingTableColJPanelList) panel; jpList.setSwingDataCollection(dataCollection); } } }
public void refreshMe() { Component cont = getParent(); while ((cont != null) && (!(cont instanceof JInternalFrame))) { cont = cont.getParent(); } if (cont != null) { if (!((JInternalFrame) cont).isClosed()) { Collection<ICFBamClearSubDep1Obj> dataCollection; ICFBamClearTopDepObj focus = (ICFBamClearTopDepObj) getSwingFocusAsClearTopDep(); if (focus != null) { dataCollection = focus.getOptionalComponentsClearDep(swingIsInitializing); } else { dataCollection = null; } JPanel panel = getTabViewComponentsClearDepListJPanel(); ICFBamSwingClearSubDep1JPanelList jpList = (ICFBamSwingClearSubDep1JPanelList) panel; jpList.setSwingDataCollection(dataCollection); } } }
/** * Sets a specified <code>Component</code> to be the glass pane for this root pane. The glass pane * should normally be a lightweight, transparent component, because it will be made visible when * ever the root pane needs to grab input events. * * <p>The new glass pane's visibility is changed to match that of the current glass pane. An * implication of this is that care must be taken when you want to replace the glass pane and make * it visible. Either of the following will work: * * <pre> * root.setGlassPane(newGlassPane); * newGlassPane.setVisible(true); * </pre> * * or: * * <pre> * root.getGlassPane().setVisible(true); * root.setGlassPane(newGlassPane); * </pre> * * @param glass the <code>Component</code> to use as the glass pane for this <code>JRootPane * </code> * @exception NullPointerException if the <code>glass</code> parameter is <code>null</code> */ public void setGlassPane(Component glass) { if (glass == null) { throw new NullPointerException("glassPane cannot be set to null."); } AWTAccessor.getComponentAccessor().setMixingCutoutShape(glass, new Rectangle()); boolean visible = false; if (glassPane != null && glassPane.getParent() == this) { this.remove(glassPane); visible = glassPane.isVisible(); } glass.setVisible(visible); glassPane = glass; this.add(glassPane, 0); if (visible) { repaint(); } }
public void refreshMe() { Component cont = getParent(); while ((cont != null) && (!(cont instanceof JInternalFrame))) { cont = cont.getParent(); } if (cont != null) { if (!((JInternalFrame) cont).isClosed()) { Collection<ICFBamParamObj> dataCollection; ICFBamServerListFuncObj focus = getSwingFocusAsServerListFunc(); if (focus != null) { dataCollection = focus.getOptionalComponentsParams(swingIsInitializing); } else { dataCollection = null; } JPanel panel = getTabViewComponentsParamsListJPanel(); ICFBamSwingParamJPanelList jpList = (ICFBamSwingParamJPanelList) panel; jpList.setSwingDataCollection(dataCollection); } } }
public void refreshMe() { Component cont = getParent(); while ((cont != null) && (!(cont instanceof JInternalFrame))) { cont = cont.getParent(); } if (cont != null) { if (!((JInternalFrame) cont).isClosed()) { Collection<ICFInternetMinorVersionObj> dataCollection; ICFAccMajorVersionObj focus = (ICFAccMajorVersionObj) getSwingFocusAsMajorVersion(); if (focus != null) { dataCollection = focus.getOptionalComponentsMinorVersion(swingIsInitializing); } else { dataCollection = null; } JPanel panel = getTabViewComponentsMinorVersionListJPanel(); ICFAccSwingMinorVersionJPanelList jpList = (ICFAccSwingMinorVersionJPanelList) panel; jpList.setSwingDataCollection(dataCollection); } } }
public void choseTenant(ICFSecurityTenantObj value) { Component cont = getParent(); while ((cont != null) && (!(cont instanceof JInternalFrame))) { cont = cont.getParent(); } if (cont != null) { if (!((JInternalFrame) cont).isClosed()) { if (swingReferenceOwnerTenant != null) { ICFInternetDomainBaseObj cur = getSwingFocusAsDomainBase(); if (cur != null) { ICFInternetDomainBaseEditObj editObj = (ICFBamDomainBaseEditObj) cur.getEdit(); if (null != editObj) { CFJPanel.PanelMode curMode = getPanelMode(); if ((curMode == CFJPanel.PanelMode.Add) || (curMode == CFJPanel.PanelMode.Edit)) { swingReferenceOwnerTenant.setReferencedObject(value); editObj.setRequiredOwnerTenant(value); } } } } } } }
public void choseSecUser(ICFSecuritySecUserObj value) { Component cont = getParent(); while ((cont != null) && (!(cont instanceof JInternalFrame))) { cont = cont.getParent(); } if (cont != null) { if (!((JInternalFrame) cont).isClosed()) { if (swingReferenceContainerSecUser != null) { ICFSecuritySecSessionObj cur = getSwingFocusAsSecSession(); if (cur != null) { ICFSecuritySecSessionEditObj editObj = (ICFDbTestSecSessionEditObj) cur.getEdit(); if (null != editObj) { CFJPanel.PanelMode curMode = getPanelMode(); if ((curMode == CFJPanel.PanelMode.Add) || (curMode == CFJPanel.PanelMode.Edit)) { swingReferenceContainerSecUser.setReferencedObject(value); editObj.setRequiredContainerSecUser(value); } } } } } } }