List of usage examples for java.awt Component getBounds
public Rectangle getBounds()
From source file:org.eclipse.jubula.rc.swing.driver.RobotAwtImpl.java
/** * // w w w . j a v a2 s .c o m * {@inheritDoc} */ public boolean isMouseInComponent(Object graphicsComponent) { Component comp = (Component) graphicsComponent; final Point currMousePos = getCurrentMousePosition(); if (currMousePos == null) { return false; } final Point treeLocUpperLeft = comp.getLocationOnScreen(); final Rectangle bounds = comp.getBounds(); final Point treeLocLowerRight = new Point(bounds.width + treeLocUpperLeft.x, bounds.height + treeLocUpperLeft.y); final boolean x1 = currMousePos.x >= treeLocUpperLeft.x; final boolean x2 = currMousePos.x < treeLocLowerRight.x; final boolean y1 = currMousePos.y >= treeLocUpperLeft.y; final boolean y2 = currMousePos.y < treeLocLowerRight.y; return x1 && x2 && y1 && y2; }
From source file:edu.ku.brc.specify.utilapps.sp5utils.Sp5Forms.java
public void generate() { BufferedImage bufImage = null; if (formFrame != null) { Component topComp = formFrame.getContentPane(); Rectangle rect = topComp.getBounds(); if (rect.width < 1 || rect.height < 1) { System.err.println("Can't create image. " + selectedForm.getTitle()); } else {//w w w. j av a 2s . com bufImage = new BufferedImage(rect.width, rect.height, (BufferedImage.TYPE_INT_ARGB)); Graphics2D g2 = bufImage.createGraphics(); topComp.paint(g2); g2.dispose(); } } if (formIndex < forms.size()) { selectedForm = forms.get(formIndex); showForm(); SwingUtilities.invokeLater(new Runnable() { public void run() { SwingUtilities.invokeLater(new Runnable() { public void run() { formFrame.pack(); formFrame.repaint(); } }); } }); } File dir = new File("conversions" + File.separator + namePair.second + "_6" + File.separator + "forms"); if (!dir.exists()) { dir.mkdirs(); } if (bufImage != null) { String fName = dir.getAbsolutePath() + File.separator + formName + ".png"; try { File imgFile = new File(fName); ImageIO.write(bufImage, "PNG", imgFile); } catch (Exception e) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ERDVisualizer.class, e); e.printStackTrace(); } } if (formIndex >= forms.size()) { SwingUtilities.invokeLater(new Runnable() { public void run() { SwingUtilities.invokeLater(new Runnable() { public void run() { if (formFrame != null) formFrame.setVisible(false); createIndex(); UIRegistry.showLocalizedMsg("Done"); } }); } }); } if (selectedForm != null) { formName = selectedForm.getFileName(); } }
From source file:edu.ku.brc.af.ui.forms.validation.ValFormattedTextField.java
@Override public void paint(Graphics g) { super.paint(g); if (!isViewOnly && !isPartialOK && !isNew && valState == UIValidatable.ErrorType.Error && isEnabled()) { Dimension size;/* w w w.jav a 2 s . co m*/ if (comps != null && comps.length > 0) { size = getSize(); Component lastComp = comps[comps.length - 1]; size.width = lastComp.getBounds().x + lastComp.getBounds().width; size.height--; } else if (editTF != null) { size = editTF.getSize(); } else { size = getSize(); } UIHelper.drawRoundedRect((Graphics2D) g, valTextColor.getColor(), size, 0); } }
From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java
/** * Sets the location of the specified child relative to the location * of the specified parent and then makes it visible, and size to fill * the window./* w w w . jav a2 s. c om*/ * This method is mainly useful for windows, frames and dialogs. * * @param parent The visible parent. * @param child The child to display. * @param max The maximum size of the window. */ public static void setLocationRelativeToAndSizeToWindow(Component parent, Component child, Dimension max) { setLocationRelativeToAndSizeToWindow(parent.getBounds(), child, max); }
From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java
/** * Centers the specified component on the parent and then makes it visible. * This method is mainly useful for windows, frames and dialogs. * //from ww w . j a v a2 s. c o m * @param parent The visible parent. * @param child The child to display. */ public static void centerAndShow(Component parent, Component child) { if (parent == null || child == null) return; Rectangle bounds = parent.getBounds(); Rectangle ed = child.getBounds(); child.setLocation(bounds.x + (bounds.width - ed.width) / 2, bounds.y + (bounds.height - ed.height) / 2); child.setVisible(true); }
From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java
/** * Centers the specified component on the screen. * The location of the specified component is set so that it will appear * in the middle of the screen when made visible. * This method is mainly useful for windows, frames and dialogs. * //from w w w. jav a 2s .co m * @param window The component to center. */ public static void centerOnScreen(Component window) { if (window == null) return; Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Rectangle ed = window.getBounds(); window.setLocation((screenSize.width - ed.width) / 2, (screenSize.height - ed.height) / 2); }
From source file:self.philbrown.javaQuery.$.java
/** * Set the height of the selected views/*from w w w .ja v a2 s .co m*/ * @param height the new height * @return this */ public $ height(int height) { for (Component view : this.views) { Rectangle bounds = view.getBounds(); bounds.height = height; view.setBounds(bounds); } return this; }
From source file:self.philbrown.javaQuery.$.java
/** * Set the width of the views in the current selection * @param width the new width//w w w . j a v a 2s . c o m * @return this */ public $ width(int width) { for (Component view : this.views) { Rectangle bounds = view.getBounds(); bounds.width = width; view.setBounds(bounds); } return this; }
From source file:self.philbrown.javaQuery.$.java
/** * Sets the coordinates of each selected view, relative to its offset parent * @param x the x-coordinate// w w w. j a v a2s . c o m * @param y the y-coordinate * @return */ public $ position(int x, int y) { for (Component view : this.views) { Rectangle bounds = view.getBounds(); bounds.x = x; bounds.y = y; view.setBounds(bounds); } return this; }
From source file:self.philbrown.javaQuery.$.java
/** * Includes the given image inside of the selected views. If a view is an `ImageView`, its image * is set. Otherwise, the background image of the view is set. * @param image the drawable image to include * @return this//from w w w. j av a2 s. c o m */ public $ image(Image image) { for (Component v : views) { if (v instanceof JLabel) { ((JLabel) v).setIcon(new ImageIcon(image)); } else if (v instanceof Window) { ((Window) v).setIconImage(image); } else { if (v instanceof Container) { JLabel l = new JLabel(new ImageIcon(image)); l.setBounds(v.getBounds()); ((Container) v).add(l); } else if (v.getParent() != null && v.getParent() instanceof Container) { JLabel l = new JLabel(new ImageIcon(image)); l.setBounds(v.getBounds()); ((Container) v.getParent()).add(l); } } } return this; }