List of usage examples for java.awt Component getHeight
public int getHeight()
From source file:io.github.tavernaextras.biocatalogue.model.Util.java
/** * Makes sure that one component (for example, a window) is centered horizontally and vertically * relatively to the other component. This is achieved by aligning centers of the two components. * /*from w w w.j a v a 2 s. c o m*/ * This method can be used even if the 'dependentComponent' is larger than the 'mainComponent'. In * this case it is probably only useful for centering windows against each other rather than * components inside a container. * * Method also makes sure that the dependent component will not be placed above the screen's upper * edge and to the left of the left edge. */ public static void centerComponentWithinAnother(Component mainComponent, Component dependentComponent) { int iMainComponentCenterX = (int) Math .round(mainComponent.getLocationOnScreen().getX() + (mainComponent.getWidth() / 2)); int iPosX = iMainComponentCenterX - (dependentComponent.getWidth() / 2); if (iPosX < 0) iPosX = 0; int iMainComponentCenterY = (int) Math .round(mainComponent.getLocationOnScreen().getY() + (mainComponent.getHeight() / 2)); int iPosY = iMainComponentCenterY - (dependentComponent.getHeight() / 2); if (iPosY < 0) iPosY = 0; dependentComponent.setLocation(iPosX, iPosY); }
From source file:com.quinsoft.zeidon.objectbrowser.WindowBoundsRestorer.java
private void getBounds(String key, Component c) { key = key + c.getName();/* w w w.ja va2 s . c o m*/ String position = String.format("%d,%d,%d,%d", c.getX(), c.getY(), c.getWidth(), c.getHeight()); properties.setProperty(key, position); if (c instanceof Container) { key = key + "/"; Container container = (Container) c; for (Component child : container.getComponents()) getBounds(key, child); } }
From source file:be.ac.ua.comp.scarletnebula.gui.SSHPanel.java
public SSHPanel(final Server server) { super();//from w w w . ja v a 2 s .c o m final JCTermSwing term = new JCTermSwing(); term.setCompression(7); term.setAntiAliasing(true); setLayout(new BorderLayout()); addComponentListener(new ComponentListener() { @Override public void componentShown(final ComponentEvent e) { } @Override public void componentResized(final ComponentEvent e) { final Component c = e.getComponent(); int cw = c.getWidth(); int ch = c.getHeight(); final JPanel source = ((JPanel) c); final int cwm = source.getBorder() != null ? source.getBorder().getBorderInsets(c).left + source.getBorder().getBorderInsets(c).right : 0; final int chm = source.getBorder() != null ? source.getBorder().getBorderInsets(c).bottom + source.getBorder().getBorderInsets(c).top : 0; cw -= cwm; ch -= chm; term.setBorder(BorderFactory.createMatteBorder(0, 0, term.getTermHeight() - c.getHeight(), term.getTermWidth() - c.getWidth(), Color.BLACK)); term.setSize(cw, ch); term.setPreferredSize(new Dimension(cw, ch)); // term.setMinimumSize(new Dimension(cw, ch)); term.setMaximumSize(new Dimension(cw, ch)); term.redraw(0, 0, term.getTermWidth(), term.getTermHeight()); } @Override public void componentMoved(final ComponentEvent e) { // TODO // Auto-generated // method // stub } @Override public void componentHidden(final ComponentEvent e) { // TODO // Auto-generated // method // stub } }); add(term, BorderLayout.CENTER); setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20), BorderFactory.createBevelBorder(BevelBorder.LOWERED))); final Thread connectionThread = new Thread() { @Override public void run() { Connection connection = null; try { final SSHCommandConnection commandConnection = (SSHCommandConnection) server .newCommandConnection(new NotPromptingJschUserInfo()); connection = commandConnection.getJSchTerminalConnection(); term.requestFocusInWindow(); term.start(connection); } catch (final Exception e) { for (final ExceptionListener listener : exceptionListeners) { listener.exceptionThrown(e); } log.warn("Exception thrown by SSHPanel", e); } finally { } } }; connectionThread.start(); }
From source file:org.jtrfp.trcl.Camera.java
private void updateProjectionMatrix() { final Component component = gpu.getTr().getRootWindow(); final float fov = 70f;// In degrees final float aspect = (float) component.getWidth() / (float) component.getHeight(); final float zF = (float) (viewDepth * 1.5); final float zN = (float) (TR.mapSquareSize / 10); final float f = (float) (1. / Math.tan(fov * Math.PI / 360.)); projectionMatrix = new Array2DRowRealMatrix(new double[][] { new double[] { f / aspect, 0, 0, 0 }, new double[] { 0, f, 0, 0 }, new double[] { 0, 0, (zF + zN) / (zN - zF), -1f }, new double[] { 0, 0, (2f * zF * zN) / (zN - zF), 0 } }).transpose(); }
From source file:org.eclipse.wb.internal.swing.utils.SwingImageUtils.java
/** * Traverses through components hierarchy and prepares screen shot for every component passed in * <code>componentImages</code> map except for branch root if <code>isRoot</code> is * <code>true</code>./*from w ww. j ava2 s . com*/ * * @param component * the branch hierarchy root component. * @param componentImages * the {@link Map} of components which screen shots should be made for. This map would be * filled by prepared {@link java.awt.Image} instances. * @param rootComponent * this branch hierarchy root component. */ static void makeShotsHierarchy(Component component, Map<Component, java.awt.Image> componentImages, Component rootComponent) throws Exception { if (componentImages.containsKey(component) && component != rootComponent) { BufferedImage thisComponentImage = (BufferedImage) createComponentShotAWT(component); // BUG in OS X (Java 1.6.0_24-b07-334-10M3326): Component.printAll() returns no image // for AWT components and these components are not drawn on the JComponent container // using the same printAll() method. // The workaround is to hack into a native peer, get the native image and then paint it. if (EnvironmentUtils.IS_MAC && !(component instanceof JComponent)) { int width = Math.max(1, component.getWidth()); int height = Math.max(1, component.getHeight()); Image nativeImage = OSSupport.get().makeShotAwt(component, width, height); if (nativeImage != null) { BufferedImage rootImage = (BufferedImage) componentImages.get(rootComponent); Point rootLocation = rootComponent.getLocationOnScreen(); Point componentLocation = component.getLocationOnScreen(); thisComponentImage = ImageUtils.convertToAWT(nativeImage.getImageData()); rootImage.getGraphics().drawImage(thisComponentImage, componentLocation.x - rootLocation.x, componentLocation.y - rootLocation.y, null); } } componentImages.put(component, thisComponentImage); } if (component instanceof Container) { Container container = (Container) component; for (Component childComponent : container.getComponents()) { makeShotsHierarchy(childComponent, componentImages, rootComponent); } } }
From source file:pl.edu.icm.visnow.lib.utils.ImageUtilities.java
public static void centerComponent(Component component) { component.setLocation((component.getParent().getWidth() - component.getWidth()) / 2, (component.getParent().getHeight() - component.getHeight()) / 2); }
From source file:pl.edu.icm.visnow.lib.utils.ImageUtilities.java
public static void centerComponentToContainer(Component component, Component container) { if (container.isDisplayable() == false) { container.addNotify();//from ww w. j a v a2 s . co m } component.setLocation((container.getWidth() - component.getWidth()) / 2, (container.getHeight() - component.getHeight()) / 2); }
From source file:org.kchine.rpf.PoolUtils.java
public static void locateInScreenCenter(Component c) { Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize(); c.setLocation((screenDim.width - c.getWidth()) / 2, (screenDim.height - c.getHeight()) / 2); }
From source file:edworld.pdfreader4humans.PDFReader.java
private void draw(Component component, Graphics2D graphics, Color inkColor, Color backgroundColor, boolean showStructure, Map<String, Font> fonts) { for (Component child : component.getChildren()) draw(child, graphics, inkColor, backgroundColor, showStructure, fonts); if (component instanceof BoxComponent && showStructure) { graphics.setColor(boxColor(backgroundColor)); graphics.drawRect((int) component.getFromX(), (int) component.getFromY(), (int) component.getWidth(), (int) component.getHeight()); graphics.setColor(inkColor);/* w w w . jav a2 s . co m*/ } else if (component instanceof GroupComponent && showStructure) { graphics.setColor(groupColor(backgroundColor)); graphics.drawRect(Math.round(component.getFromX()), Math.round(component.getFromY()), Math.round(component.getWidth()), Math.round(component.getHeight())); graphics.setColor(inkColor); } else if (component instanceof MarginComponent && showStructure) { graphics.setColor(marginColor(backgroundColor)); graphics.drawRect(Math.round(component.getFromX()), Math.round(component.getFromY()), Math.round(component.getWidth()), Math.round(component.getHeight())); graphics.setColor(inkColor); } else if (component.getType().equals("line")) graphics.drawLine(Math.round(component.getFromX()), Math.round(component.getFromY()), Math.round(component.getToX()), Math.round(component.getToY())); else if (component.getType().equals("rect")) graphics.drawRect(Math.round(component.getFromX()), Math.round(component.getFromY()), Math.round(component.getWidth()), Math.round(component.getHeight())); else if (component instanceof TextComponent) { graphics.setFont(font((TextComponent) component, fonts)); graphics.drawString(((TextComponent) component).getText(), component.getFromX(), component.getToY()); } }
From source file:org.eclipse.jubula.rc.swing.driver.RobotAwtImpl.java
/** * Implementation of the mouse move. The mouse is moved into the graphics component. * @param graphicsComponent The component to move to * @param constraints The more specific constraints. Use this, for example * when you want the click point to be relative to a part * of the component (e.g. tree node, table cell, etc) * rather than the overall component itself. May be * <code>null</code>. * @param xPos xPos in component * @param yPos yPos in component//from w w w. jav a 2 s .c om * @param xAbsolute true if x-position should be absolute * @param yAbsolute true if y-position should be absolute * @param clickOptions The click options * @throws StepExecutionException If the click delay is interrupted or the * event confirmation receives a timeout. */ private void moveImpl(Object graphicsComponent, final Rectangle constraints, final int xPos, final boolean xAbsolute, final int yPos, final boolean yAbsolute, ClickOptions clickOptions) throws StepExecutionException { if (clickOptions.isScrollToVisible()) { ensureComponentVisible((Component) graphicsComponent, constraints); m_eventFlusher.flush(); } Component component = (Component) graphicsComponent; Rectangle bounds = null; bounds = new Rectangle(getLocation(component, new Point(0, 0))); bounds.width = component.getWidth(); bounds.height = component.getHeight(); if (constraints != null) { bounds.x += constraints.x; bounds.y += constraints.y; bounds.height = constraints.height; bounds.width = constraints.width; } Point p = PointUtil.calculateAwtPointToGo(xPos, xAbsolute, yPos, yAbsolute, bounds); // Move if necessary if (isMouseMoveRequired(p)) { if (log.isDebugEnabled()) { log.debug("Moving mouse to: " + p); //$NON-NLS-1$ } IRobotEventConfirmer confirmer = null; if (clickOptions.isConfirmClick()) { InterceptorOptions options = new InterceptorOptions( new long[] { AWTEvent.MOUSE_MOTION_EVENT_MASK }); confirmer = m_interceptor.intercept(options); } Point startpoint = m_mouseMotionTracker.getLastMousePointOnScreen(); if (startpoint == null) { // If there is no starting point the center of the root component is used Component root = SwingUtilities.getRoot(component); Component c = (root != null) ? root : component; startpoint = getLocation(c, null); } Point[] mouseMove = MouseMovementStrategy.getMovementPath(startpoint, p, clickOptions.getStepMovement(), clickOptions.getFirstHorizontal()); for (int i = 0; i < mouseMove.length; i++) { m_robot.mouseMove(mouseMove[i].x, mouseMove[i].y); m_eventFlusher.flush(); } if (confirmer != null) { confirmer.waitToConfirm(component, new MouseMovedAwtEventMatcher()); } } }