public void addElement(Element el, BoxBounds bounds) { Layer layer = new Layer(el, bounds); layers.add(layer); el.getStyle().setPosition(Style.Position.ABSOLUTE); presetLayerBounds(layer); container.appendChild(el); }
public S screenCenter() { int width = this.outerWidth(); int height = this.outerHeight(); int left = (Window.getClientWidth() - width) >> 1; int top = (Window.getClientHeight() - height) >> 1; int computedLeft = Math.max(Window.getScrollLeft() + left, 0) - Document.get().getBodyOffsetLeft(); int computedTop = Math.max(Window.getScrollTop() + top, 0) - Document.get().getBodyOffsetTop(); Element element = this.getElement(); element.getStyle().setPropertyPx("left", computedLeft); element.getStyle().setPropertyPx("top", computedTop); element.getStyle().setPosition(Position.ABSOLUTE); return (S) this; }
public SpinningTopSpaceView(SpinningTop rigidBody) { this.rigidBody = rigidBody; frame.setSize(600, 600); // panel.setDisplayMode(VisualizationHints.DISPLAY_NO_PERSPECTIVE); double d = 4; frame.setPreferredMinMax(-d, d, -d, d, -d, d); frame.setDecorationType( org.opensourcephysics.display3d.core.VisualizationHints.DECORATION_AXES); orientation.getStyle().setFillColor(java.awt.Color.RED); orientationTrace.getStyle().setLineColor(java.awt.Color.BLACK); base.setSizeXYZ(2, 2, 0.15); base.getStyle().setResolution(new Resolution(4, 12, 1)); base.getStyle().setFillColor(java.awt.Color.RED); base.setZ(-3); post.setSizeXYZ(0.2, 0.2, 3); post.getStyle().setResolution(new Resolution(2, 10, 15)); post.setZ(-1.5); // shift by half the length post.getStyle().setFillColor(java.awt.Color.RED); shaft.setSizeXYZ(0.2, 0.2, 3); shaft.setXYZ(0, 0, 1.5); shaft.getStyle().setResolution(new Resolution(1, 10, 15)); disk.setSizeXYZ(1.75, 1.75, 0.25); disk.setXYZ(0, 0, 2.0); disk.getStyle().setResolution(new Resolution(4, 12, 1)); topGroup.addElement(shaft); topGroup.addElement(disk); topGroup.setTransformation(rigidBody.getTransformation()); frame.addElement(base); frame.addElement(post); frame.addElement(orientation); frame.addElement(orientationTrace); frame.addElement(topGroup); }
public CameraApp() { ball.setXYZ(0.0, 0.0, 0.0); ball.setSizeXYZ(0.5, 0.5, 0.5); ball.getStyle().setFillColor(Color.YELLOW); // right wall wallR.setXYZ(6.0, 0.0, 0.0); wallR.setSizeXYZ(0.2, 4.0, 4.0); wallR.getStyle().setFillColor(Color.GREEN); // left wall wallL.setXYZ(-6.0, 0.0, 0.0); wallL.setSizeXYZ(0.2, 4.0, 4.0); wallL.getStyle().setFillColor(Color.GREEN); // Add the objects panel.setPreferredMinMax(-6, 6, -6, 6, -6, 6); panel.getInteractionTarget(org.opensourcephysics.display3d.core.DrawingPanel3D.TARGET_PANEL); panel.addInteractionListener(this); panel.addElement(ball); panel.addElement(wallR); panel.addElement(wallL); DrawingFrame3D frame = new DrawingFrame3D(); frame.setDrawingPanel3D(panel); }
/** * set container * * @param container container * @return content layer */ public Element init( Element container, int insetLeft, int insetTop, int insetRight, int insetBottom) { this.container = container; if (!"absolute".equals(container.getStyle().getPosition()) && !"relative".equals(container.getStyle().getPosition())) { container.getStyle().setPosition(Style.Position.RELATIVE); } Element contentLayer = DOM.createDiv(); contentLayer.getStyle().setPosition(Style.Position.ABSOLUTE); if (insetTop > 0) contentLayer.getStyle().setPaddingTop(insetTop, Style.Unit.PX); if (insetLeft > 0) contentLayer.getStyle().setPaddingLeft(insetLeft, Style.Unit.PX); if (insetRight > 0) contentLayer.getStyle().setPaddingRight(insetRight, Style.Unit.PX); if (insetBottom > 0) contentLayer.getStyle().setPaddingBottom(insetBottom, Style.Unit.PX); container.appendChild(contentLayer); return contentLayer; }
/** * Gets an attribute of the given element's style. * * @param elem the element whose style attribute is to be retrieved * @param attr the name of the style attribute to be retrieved * @return the style attribute's value * @deprecated Use {@link Element#getStyle()} and {@link Style#getProperty(String)} instead. */ @Deprecated public static String getStyleAttribute(Element elem, String attr) { return elem.getStyle().getProperty(attr); }
/** * Sets an attribute on the given element's style. * * @param elem the element whose style attribute is to be set * @param attr the name of the style attribute to be set * @param value the style attribute's new value * @deprecated Use {@link Element#getStyle()} and {@link Style#setProperty(String, String)} * instead. */ @Deprecated public static void setStyleAttribute(Element elem, String attr, String value) { elem.getStyle().setProperty(attr, value); }
/** * Sets an integer attribute on the given element's style. * * @param elem the element whose style attribute is to be set * @param attr the name of the style attribute to be set * @param value the style attribute's new integer value */ public static void setIntStyleAttribute(Element elem, String attr, int value) { elem.getStyle().setProperty(attr, Integer.toString(value)); }