Visual Lib no clipping for ComponentWidgets ?

View: New views
2 Messages — Rating Filter:   Alert me  

Visual Lib no clipping for ComponentWidgets ?

by bruehlicke :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I am having a ComponentWidget which contains a JPanel where a oval is
rendered as shown below

The widget is create like below where it is given a resize border and
a resize and move action


        JPanel jpanel = new MyPanel();
        ComponentWidget widget = new ComponentWidget(_scene, jpanel);
        widget.setBorder(_resizeBorder);
        widget.setVisible(true);
        widget.setOpaque(false);

        widget.getActions().addAction(resizeAction);
        widget.getActions().addAction(moveAction);

        _mainLayer.addChild(widget);



Now, the _mainLayer sits in a scene which has clipping enabled. When
moving the widget to the edge, the border gets clipped correctly but
the oval is still drawn fully.

Do I need to handle clipping of the Component in the ComponentWidget
manually (explicitly) ?






    class MyPanel extends JPanel {

        private Color _mColor;
        private BasicStroke _mStroke;

        public MyPanel() {
            _mColor = Color.GREEN;
            _mStroke = new BasicStroke(2.0f);
            setBackground(Color.WHITE);
            setOpaque(false);
        }

        @Override
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2d = ( Graphics2D ) g;
            g2d.setStroke( _mStroke );
            g2d.setColor(_mColor);
            int width = getWidth();
            int height = getHeight();
            g2d.drawOval(0, 0, width, height);
        }

       public void setMyStroke(BasicStroke stroke) {
            _mStroke = stroke;
            repaint();
        }

        public void setMyColor(Color col) {
            _mColor = col;
            repaint();
        }
    }

Re: Visual Lib no clipping for ComponentWidgets ?

by bruehlicke :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

OK - fixed this - rather cumbersome, but makes sense.

The idea is to set the clipping in the JPanel class. The key here is
that the Move and Resize Providers and Strategies have to update the
clipping Rectangle as this is always in the componentWidget local
coordinates

So each time the widget is moved or resized I have to get the clipping
area in Scene coordinates, convert those to the componentWidget local
coordinates and inject those into the MyPanel class by adding a new
setClippingArea(Rectangle clip) method.

Cool.

B-)





On Tue, Oct 20, 2009 at 10:58 PM, bruehlicke <bruehlicke@...> wrote:

> I am having a ComponentWidget which contains a JPanel where a oval is
> rendered as shown below
>
> The widget is create like below where it is given a resize border and
> a resize and move action
>
>
>        JPanel jpanel = new MyPanel();
>        ComponentWidget widget = new ComponentWidget(_scene, jpanel);
>        widget.setBorder(_resizeBorder);
>        widget.setVisible(true);
>        widget.setOpaque(false);
>
>        widget.getActions().addAction(resizeAction);
>        widget.getActions().addAction(moveAction);
>
>        _mainLayer.addChild(widget);
>
>
>
> Now, the _mainLayer sits in a scene which has clipping enabled. When
> moving the widget to the edge, the border gets clipped correctly but
> the oval is still drawn fully.
>
> Do I need to handle clipping of the Component in the ComponentWidget
> manually (explicitly) ?
>
>
>
>
>
>
>    class MyPanel extends JPanel {
>
>        private Color _mColor;
>        private BasicStroke _mStroke;
>
>        public MyPanel() {
>            _mColor = Color.GREEN;
>            _mStroke = new BasicStroke(2.0f);
>            setBackground(Color.WHITE);
>            setOpaque(false);
>        }
>
>        @Override
>        public void paintComponent(Graphics g) {
>            super.paintComponent(g);
>            Graphics2D g2d = ( Graphics2D ) g;
>            g2d.setStroke( _mStroke );
>            g2d.setColor(_mColor);
>            int width = getWidth();
>            int height = getHeight();
>            g2d.drawOval(0, 0, width, height);
>        }
>
>       public void setMyStroke(BasicStroke stroke) {
>            _mStroke = stroke;
>            repaint();
>        }
>
>        public void setMyColor(Color col) {
>            _mColor = col;
>            repaint();
>        }
>    }
>