List of usage examples for java.awt Component setBounds
public void setBounds(Rectangle r)
From source file:uk.co.modularaudio.service.guicompfactory.impl.RealComponentFront.java
public RealComponentFront(final ContainerImages ci, final RackComponent rc, final BufferedImage frontBufferedImage) { this.frontBufferedImage = frontBufferedImage; this.rc = rc; this.setOpaque(true); this.setLayout(null); final AbstractMadUiControlInstance<?, ?, ?>[] uiControls = rc.getUiControlInstances(); for (final AbstractMadUiControlInstance<?, ?, ?> uic : uiControls) { final Component swingComponent = uic.getControl(); this.add(swingComponent); swingComponent.setBounds(uic.getUiControlDefinition().getControlBounds()); }//w w w.j av a2 s. com final Dimension size = new Dimension(PaintedComponentDefines.FRONT_MIN_WIDTH, PaintedComponentDefines.FRONT_MIN_HEIGHT); setSize(size); setMinimumSize(size); setPreferredSize(size); }
From source file:EntryLayout.java
/** * Lays out the container in the specified panel. This is a row-column type * layout; find x, y, width and height of each Component. * //from ww w . jav a 2s. c om * @param parent * The Container whose children we are laying out. */ public void layoutContainer(Container parent) { if (!validWidths) return; Component[] components = parent.getComponents(); Dimension contSize = parent.getSize(); int x = 0; for (int i = 0; i < components.length; i++) { int row = i / COLUMNS; int col = i % COLUMNS; Component c = components[i]; Dimension d = c.getPreferredSize(); int colWidth = (int) (contSize.width * widthPercentages[col]); if (col == 0) { x = hpad; } else { x += hpad * (col - 1) + (int) (contSize.width * widthPercentages[col - 1]); } int y = vpad * (row) + (row * heights[row]) + (heights[row] - d.height); Rectangle r = new Rectangle(x, y, colWidth, d.height); c.setBounds(r); } }
From source file:self.philbrown.javaQuery.$.java
/** * Set the width of the views in the current selection * @param width the new width/*from w w w . j a va 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
/** * Set the height of the selected views/*from www . j a v a 2 s.c o 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
/** * Sets the coordinates of each selected view, relative to its offset parent * @param x the x-coordinate/*from ww w . ja va 2 s.co 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:TileLayout.java
private void align(Dimension cont, Object cons[], Component comp) { int align = 0; Insets insets = null;/*www . ja v a2 s . co m*/ Rectangle tile = null, fixd = null; if (cons != null) { for (int i = 0; i < cons.length; i++) { // gather constraints if (cons[i] != null) { if (cons[i] instanceof Rectangle) fixd = (Rectangle) cons[i]; else if (cons[i] instanceof Insets) insets = (Insets) cons[i]; else if (cons[i] instanceof Integer) align = ((Integer) cons[i]).intValue(); else if (cons[i] instanceof Component) tile = ((Component) cons[i]).getBounds(); } } } if (tile == null) tile = new Rectangle(cont); Rectangle pref = new Rectangle(tile.getLocation(), comp.getPreferredSize()); // perform component positioning: if ((align & 0x004000) != 0) pref.width = fixd.width; else if ((align & 0x008000) != 0) pref.width = (tile.width * fixd.width + 500) / 1000; else if ((align & 0x010000) != 0) pref.width = tile.width; if ((align & 0x080000) != 0) pref.height = fixd.height; else if ((align & 0x100000) != 0) pref.height = (tile.height * fixd.height + 500) / 1000; else if ((align & 0x200000) != 0) pref.height = tile.height; if ((align & 0x000001) != 0) pref.x -= pref.width; else if ((align & 0x000002) != 0) pref.x += (tile.width - pref.width >> 1); else if ((align & 0x000004) != 0) pref.x += tile.width - pref.width; else if ((align & 0x000008) != 0) pref.x += tile.width; else if ((align & 0x000010) != 0) pref.x += fixd.x; else if ((align & 0x000020) != 0) pref.x += (tile.width * fixd.x + 500) / 1000; if ((align & 0x000040) != 0) pref.y -= pref.height; else if ((align & 0x000080) != 0) pref.y += (tile.height - pref.height >> 1); else if ((align & 0x000100) != 0) pref.y += tile.height - pref.height; else if ((align & 0x000200) != 0) pref.y += tile.height; else if ((align & 0x000400) != 0) pref.y += fixd.y; else if ((align & 0x000800) != 0) pref.y += (tile.height * fixd.y + 500) / 1000; if ((align & 0x001000) != 0) pref.setBounds(0, pref.y, pref.x + pref.width, pref.height); else if ((align & 0x002000) != 0) pref.width = cont.width - pref.x; if ((align & 0x020000) != 0) pref.setBounds(pref.x, 0, pref.width, pref.y + pref.height); else if ((align & 0x040000) != 0) pref.height = cont.height - pref.y; if (insets != null) { // apply insets, if any: pref.x += insets.left; pref.y += insets.top; pref.width -= insets.left + insets.right; pref.height -= insets.top + insets.bottom; } // Note: this can cause surprising results, so use it, if you dare. :-) // Honour component minimum size: Dimension d = comp.getMinimumSize(); if (pref.width < d.width) pref.width = d.width; if (pref.height < d.height) pref.height = d.height; comp.setBounds(pref); // now the tile is set! }
From source file:self.philbrown.javaQuery.$.java
/** * Animate multiple view properties at the same time. Example: * <pre>/*from w w w. j a v a 2s . c o m*/ * $.with(myView).animate(new QuickMap(QuickEntry.qe("alpha", .8f), QuickEntry.qe("width", 50%)), 400, Easing.LINEAR, null); * </pre> * @param properties mapping of property names and final values to animate * @param options the options for setting the duration, easing, etc of the animation * @return this */ public $ animate(Map<String, Object> properties, final AnimationOptions options) { List<Animator> animations = new ArrayList<Animator>(); for (Entry<String, Object> entry : properties.entrySet()) { final String key = entry.getKey(); //Java sometimes will interpret these Strings as Numbers, so some trickery is needed below Object value = entry.getValue(); for (final Component view : this.views) { Animator anim = null; if (value instanceof String) value = getAnimationValue(view, key, (String) value); //final Object fValue = value; if (value != null) { //special color cases if (key.equals("alpha") || key.equals("red") || key.equals("green") || key.equals("blue")) { if (key.equals("alpha") && view instanceof JComponent) { ((JComponent) view).setOpaque(false); } try { final Method getComponent = Color.class .getMethod(Log.buildString("get", capitalize(key))); final int colorComponent = (Integer) getComponent.invoke(view.getBackground()); final ColorHelper color = new ColorHelper(view.getBackground()); final Method setComponent = ColorHelper.class.getMethod( Log.buildString("set", capitalize(key)), new Class<?>[] { int.class }); anim = new Animator(); //if integer - assume 0-255 if (value instanceof Integer || is(value, int.class)) { anim.addTarget(PropertySetter.getTarget(color, key, colorComponent, Integer.parseInt(value.toString()))); } //if float - assume 0.0-1.0 else if (value instanceof Float || is(value, float.class)) { anim.addTarget(PropertySetter.getTarget(color, key, colorComponent, (int) (255 * Float.parseFloat(value.toString())))); } anim.addTarget(new TimingTargetAdapter() { @Override public void timingEvent(Animator source, double fraction) { double d = source.getInterpolator().interpolate(fraction); try { setComponent.invoke(color, (int) d); view.setBackground(color.getColor()); // if (view instanceof JComponent) // ((JComponent) view).revalidate(); view.repaint(); } catch (Throwable t) { if (options.debug()) t.printStackTrace(); } } }); } catch (Throwable t) { if (options.debug()) t.printStackTrace(); } } else { final Rectangle params = view.getBounds(); try { final Field field = params.getClass().getField(key); if (field != null) { anim = new Animator(); anim.addTarget(PropertySetter.getTarget(params, key, field.get(params), value)); anim.addTarget(new TimingTargetAdapter() { @Override public void timingEvent(Animator source, double fraction) { Rectangle bounds = view.getBounds(); double d = source.getInterpolator().interpolate(fraction); try { field.set(bounds, d); } catch (Throwable t) { if (options.debug()) t.printStackTrace(); } view.setBounds(bounds); view.repaint(); if (options.progress() != null) { options.progress().invoke($.with(view), key, d, source.getDuration() - source.getTotalElapsedTime()); } } }); } } catch (Throwable t) { if (options.debug()) Log.w("$", String.format(Locale.US, "%s is not a LayoutParams attribute.", key)); } if (anim == null) { anim = new Animator(); Object first; try { final Method getter = view.getClass() .getMethod(Log.buildString("get", capitalize(key))); first = getter.invoke(view); } catch (Throwable t) { first = 0; } anim.addTarget(PropertySetter.getTarget(view, key, first, value)); if (options.progress() != null) { anim.addTarget(new TimingTargetAdapter() { @Override public void timingEvent(Animator source, double fraction) { double d = source.getInterpolator().interpolate(fraction); if (options.progress() != null) { options.progress().invoke($.with(view), key, d, source.getDuration() - source.getTotalElapsedTime()); } } }); } } } if (options.repeatCount() >= 1) anim.setRepeatCount(options.repeatCount()); if (options.reverse()) anim.setRepeatBehavior(Animator.RepeatBehavior.REVERSE); animations.add(anim); } } } AnimatorSet animation = animationWithOptions(options, animations); animation.start(); return this; }