private void init(Context context, AttributeSet attrs, int defStyle) { PixelUtils.init(getContext()); layoutManager = new LayoutManager(); titleWidget = new TextLabelWidget( layoutManager, new Size(25, SizeLayoutType.ABSOLUTE, 100, SizeLayoutType.ABSOLUTE), TextOrientationType.HORIZONTAL); titleWidget.position( 0, XLayoutStyle.RELATIVE_TO_CENTER, 0, YLayoutStyle.ABSOLUTE_FROM_TOP, AnchorPosition.TOP_MIDDLE); // initialize attr defaults: titleWidget.getLabelPaint().setTextSize(PixelUtils.spToPix(DEFAULT_TITLE_WIDGET_TEXT_SIZE_SP)); onPreInit(); // make sure the title widget is always the topmost widget: layoutManager.moveToTop(titleWidget); if (context != null && attrs != null) { loadAttrs(attrs, defStyle); } layoutManager.onPostInit(); if (renderMode == RenderMode.USE_BACKGROUND_THREAD) { renderThread = new Thread( new Runnable() { @Override public void run() { keepRunning = true; while (keepRunning) { isIdle = false; synchronized (pingPong) { Canvas c = pingPong.getCanvas(); renderOnCanvas(c); pingPong.swap(); } synchronized (renderSynch) { postInvalidate(); // prevent this thread from becoming an orphan // after the view is destroyed if (keepRunning) { try { renderSynch.wait(); } catch (InterruptedException e) { keepRunning = false; } } } } } }); } }
/** * Creation and initialization of a layout delegate for a new container. * * @param initialize * @return false if suitable layout delegate is not found * @throws java.lang.Exception * @throw IllegalArgumentException if the container instance is not empty */ public boolean prepareLayoutDelegate(boolean initialize) throws Exception { LayoutSupportDelegate delegate = null; LayoutManager lmInstance = null; // first try to find a dedicated layout delegate (for the container) Class<?> layoutDelegateClass = LayoutSupportRegistry.getSupportClassForContainer(radContainer.getBeanClass()); if (layoutDelegateClass != null) { delegate = (LayoutSupportDelegate) layoutDelegateClass.newInstance(); /* if (!delegate.checkEmptyContainer(getPrimaryContainer())) { RuntimeException ex = new IllegalArgumentException(); org.openide.ErrorManager.getDefault().annotate( ex, AbstractLayoutSupport.getBundle().getString( "MSG_ERR_NonEmptyContainer")); // NOI18N throw ex; } */ } else { Container contDel = getPrimaryContainerDelegate(); // if (contDel.getComponentCount() == 0) { // we can still handle only empty containers ... lmInstance = contDel.getLayout(); delegate = LayoutSupportRegistry.createSupportForLayout(lmInstance.getClass()); /* } else { RuntimeException ex = new IllegalArgumentException(); org.openide.ErrorManager.getDefault().annotate( ex, AbstractLayoutSupport.getBundle().getString( "MSG_ERR_NonEmptyContainer")); // NOI18N throw ex; } */ } if (delegate != null) { if (initialize) { setLayoutDelegate(delegate); } else { layoutDelegate = delegate; needInit = true; initializeFromInstance = lmInstance != null; } return true; } else { return false; } }
/** * Renders the plot onto a canvas. Used by both main thread to draw directly onto the View's * canvas as well as by background draw to render onto a Bitmap buffer. At the end of the day this * is the main entry for a plot's "heavy lifting". * * @param canvas */ protected synchronized void renderOnCanvas(Canvas canvas) { try { // any series interested in synchronizing with plot should // implement PlotListener.onBeforeDraw(...) and do a read lock from within its // invocation. This is the entry point into that call: notifyListenersBeforeDraw(canvas); try { // need to completely erase what was on the canvas before redrawing, otherwise // some odd aliasing artifacts begin to build up around the edges of aa'd entities // over time. canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); if (backgroundPaint != null) { drawBackground(canvas, displayDims.marginatedRect); } layoutManager.draw(canvas); if (getBorderPaint() != null) { drawBorder(canvas, displayDims.marginatedRect); } } catch (PlotRenderException e) { Log.e(TAG, "Exception while rendering Plot.", e); } catch (Exception e) { Log.e(TAG, "Exception while rendering Plot.", e); } } finally { isIdle = true; // any series interested in synchronizing with plot should // implement PlotListener.onAfterDraw(...) and do a read unlock from within that // invocation. This is the entry point for that invocation. notifyListenersAfterDraw(canvas); } }
/* * (non-Javadoc) * * @see javax.swing.JFrame#setLayout(java.awt.LayoutManager) */ @Override public void setLayout(LayoutManager manager) { if (manager.getClass() != RibbonFrameLayout.class) { LayoutManager currManager = getLayout(); if (currManager != null) { throw new IllegalArgumentException("Can't set a custom layout manager on JRibbonFrame"); } } super.setLayout(manager); }
public Test(LayoutManager layout, JComponent[] components) { super(layout.getClass().getName()); JPanel panel = new JPanel(layout); // --- code needed to add the components // less than using a GridBagLayout for (JComponent component : components) { panel.add(component); } // --- panel.setBorder(new EtchedBorder()); setContentPane(new JScrollPane(panel)); pack(); show(); }
@Override public synchronized void layout(final DisplayDimensions dims) { displayDims = dims; layoutManager.layout(displayDims); }