/** * Reinitialize the insets parameter with this Border's current Insets. * * @param c the component for which this border insets value applies * @param insets the object to be reinitialized */ public Insets getBorderInsets(Component c, Insets insets) { Border border = getBorder(); if (border != null) { if (border instanceof AbstractBorder) { ((AbstractBorder) border).getBorderInsets(c, insets); } else { // Can't reuse border insets because the Border interface // can't be enhanced. Insets i = border.getBorderInsets(c); insets.top = i.top; insets.right = i.right; insets.bottom = i.bottom; insets.left = i.left; } } else { insets.left = insets.top = insets.right = insets.bottom = 0; } insets.left += EDGE_SPACING + TEXT_SPACING; insets.right += EDGE_SPACING + TEXT_SPACING; insets.top += EDGE_SPACING + TEXT_SPACING; insets.bottom += EDGE_SPACING + TEXT_SPACING; if (c == null || label == null) { return insets; } insets.top += label.getHeight(); return insets; }
/** * If necessary paints the background of the component, then invokes <code>paint</code>. * * @param g Graphics to paint to * @param c JComponent painting on * @throws NullPointerException if <code>g</code> or <code>c</code> is null * @see javax.swing.plaf.ComponentUI#update * @see javax.swing.plaf.ComponentUI#paint * @since 1.5 */ public void update(Graphics g, JComponent c) { AbstractButton button = (AbstractButton) c; if ((c.getBackground() instanceof UIResource) && button.isContentAreaFilled() && c.isEnabled()) { ButtonModel model = button.getModel(); if (!MetalUtils.isToolBarButton(c)) { if (!model.isArmed() && !model.isPressed() && MetalUtils.drawGradient( c, g, "Button.gradient", 0, 0, c.getWidth(), c.getHeight(), true)) { paint(g, c); return; } } else if (model.isRollover() && MetalUtils.drawGradient( c, g, "Button.gradient", 0, 0, c.getWidth(), c.getHeight(), true)) { paint(g, c); return; } } super.update(g, c); }
private void _update(Graphics2D graphics2D, JComponent jComponent) { GFX ctx = new Java2DGFX(graphics2D); graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); graphics2D.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); graphics2D.setRenderingHint( RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); // graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, // RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB); ctx.setPaint(backgroundFill); ctx.fillRect(0, 0, jComponent.getWidth(), jComponent.getHeight()); // draw the scene root.draw(ctx); }
public DropDownComponent( String fieldName, JComponent visibleComponent, Window dropDownComponent, int type) { this.fieldName = fieldName; this.visibleComponent = visibleComponent; this.visibleComponent.setPreferredSize( new Dimension(visibleComponent.getWidth(), visibleComponent.getHeight())); this.hideableWindow = dropDownComponent; ResourceInjector.get("common-package.style").inject(this); createIcon(dropDownComponent, type); addAncestorListener(this); setupLayout(); }
/** * Show the window. * * @param container - Window of JFrame to show */ private void showPopup(Window container) { if (visibleComponent.isEnabled()) { Point pt = visibleComponent.getLocationOnScreen(); pt.translate(0, visibleComponent.getHeight()); container.setLocation(pt); container.toFront(); ApplicationManager.setCurrentlySelectedField(fieldName); if (container instanceof OntologySelector) { ((OntologySelector) container).makeVisible(); } else { container.setVisible(true); container.requestFocusInWindow(); } } }
public void paint(Graphics g, JComponent c) { boolean hasFocus = comboBox.hasFocus(); Rectangle r; if (comboBox.isEnabled()) { g.setColor(comboBox.getBackground()); } else { g.setColor(UIManager.getColor("ComboBox.disabledBackground")); } g.fillRect(0, 0, c.getWidth(), c.getHeight()); if (!comboBox.isEditable()) { r = rectangleForCurrentValue(); paintCurrentValue(g, r, hasFocus); } r = rectangleForArrowIcon(); arrowIcon.paintIcon(c, g, r.x, r.y); if (!comboBox.isEditable()) { Border border = comboBox.getBorder(); Insets in; if (border != null) { in = border.getBorderInsets(comboBox); } else { in = new Insets(0, 0, 0, 0); } // Draw the separation if (MotifGraphicsUtils.isLeftToRight(comboBox)) { r.x -= (HORIZ_MARGIN + 2); } else { r.x += r.width + HORIZ_MARGIN + 1; } r.y = in.top; r.width = 1; r.height = comboBox.getBounds().height - in.bottom - in.top; g.setColor(UIManager.getColor("controlShadow")); g.fillRect(r.x, r.y, r.width, r.height); r.x++; g.setColor(UIManager.getColor("controlHighlight")); g.fillRect(r.x, r.y, r.width, r.height); } }
@Override protected int getHeight() { return component.getHeight(); }
void paintBackground(SynthContext context, Graphics g, JComponent c) { context .getPainter() .paintRadioButtonMenuItemBackground(context, g, 0, 0, c.getWidth(), c.getHeight()); }
/** * Causes the popup to be displayed at the specified location. * * @param component The component whose cooredinate system is to be used. * @param x The horizontal location of the popup * @param y The vertical location of the popup. */ public void showPopup(JComponent component, int x, int y) { // Get the root (JFrame probably) Component rootComp = SwingUtilities.getRoot(component); // Determine where to place the popup // (Left or right, top or bottom of the mouse cursor // We want to fit the popup within the top level frame int componentMaxX = (int) rootComp.getSize().width; int componentMaxY = (int) rootComp.getSize().height; int xPosOnRoot = SwingUtilities.convertPoint(component, x, y, rootComp).x; int yPosOnRoot = SwingUtilities.convertPoint(component, x, y, rootComp).y; // Display to the right of the mouse cursor, unless // there is not enough room int deltaX = xPosOnRoot + content.getWidth() - componentMaxX; if (deltaX > 0) { xPosOnRoot -= deltaX; if (xPosOnRoot < 0) { xPosOnRoot = 0; } } int deltaY = yPosOnRoot + content.getHeight() - componentMaxY; if (deltaY > 0) { yPosOnRoot -= deltaY; if (yPosOnRoot < 0) { yPosOnRoot = 0; } } // Convert root pos back to component pos int xPos = SwingUtilities.convertPoint(rootComp, xPosOnRoot, yPosOnRoot, component).x; int yPos = SwingUtilities.convertPoint(rootComp, xPosOnRoot, yPosOnRoot, component).y; JRootPane rootPane = component.getRootPane(); rootPane.setGlassPane(glassPane); // Convert the mouse point from the invoking component coordinate // system to the glassPane coordinate system Point pt = SwingUtilities.convertPoint(component, xPos, yPos, glassPane); // Set the location of the popup in the glass pane content.setLocation(pt); // Show the glass pane. glassPane.setVisible(true); // If the popup is set to hide automatically after a specified // amount of time, then reset the timer. if (HIDE_ON_TIMER == true) { timer.stop(); timer.start(); } }
public void actionPerformed(ActionEvent event) { JPopupMenu menu = new JPopupMenu(); loadPopupMenu(menu); JComponent c = (JComponent) event.getSource(); menu.show(c, 0, c.getHeight()); }