Package org.joshy.sketch.model

Examples of org.joshy.sketch.model.SelfDrawable


                    scale = Math.max(scale,0.2)//don't scale down by more than a factor of 5
                    Bounds oldClip = gfx.getClipRect();
                    gfx.setClipRect(new Bounds(0,0,size,size));
                    gfx.scale(scale,scale);
                    gfx.translate(-bounds.getX(),-bounds.getY());
                    SelfDrawable sd = (SelfDrawable) item;
                    sd.draw(gfx);
                    gfx.translate(bounds.getX(),bounds.getY());
                    gfx.scale(1/scale,1/scale);
                    gfx.setClipRect(oldClip);
                }
                gfx.setPaint(FlatColor.BLACK);
                gfx.drawRect(0,0,width,height);
                if(listView.getSelectedIndex() == index) {
                    gfx.setPaint(new FlatColor(0.8,0.8,1.0,0.5));
                    gfx.fillRect(0,0,width,height);
                }
                gfx.translate(-x,-y);
            }
        });

        symbolPane = new ScrollPane();
        symbolPane.setContent(listView);
        symbolPane.setHorizontalVisiblePolicy(ScrollPane.VisiblePolicy.Never);

        symbolAddButton = new Button(getString("sidebar.insertSymbol"));
        symbolAddButton.onClicked(new Callback<ActionEvent>() { public void call(ActionEvent event) {
            if(listView.getSelectedIndex() < 0) return;
            SNode node = listView.getModel().get(listView.getSelectedIndex());
            SketchDocument sd = context.getDocument();
            sd.getCurrentPage().add(node.duplicate(null));
            context.redraw();
        }});


        EventBus.getSystem().addListener(listView, MouseEvent.MouseAll, new Callback<MouseEvent>() {
            public double prevx;
            public boolean created;
            public SNode dupe;

            public void call(MouseEvent event) {
                if(event.getType() == MouseEvent.MousePressed) {
                    ContextMenu.hideAll();
                    if(event.getButton() == 3) { // check for right clicks to open the context menu
                        showContextMenu(event);
                        return;
                    }
                }
                if(event.getType() == MouseEvent.MouseDragged) {
                    if(created && dupe != null) {
                        Point2D pt = event.getPointInNodeCoords(context.getCanvas());
                        pt = context.getSketchCanvas().transformToCanvas(pt);
                        Bounds b = dupe.getBounds();
                        dupe.setTranslateX(pt.getX()-b.getWidth()/2);
                        dupe.setTranslateY(pt.getY()-b.getHeight()/2);
                        context.redraw();
                    }
                    if(event.getX() < 0 && prevx >= 0 && !created) {
                        created = true;
                        if(listView.getSelectedIndex() < 0) return;
                        SNode node = listView.getModel().get(listView.getSelectedIndex());
                        SketchDocument sd = context.getDocument();
                        dupe = node.duplicate(null);
                        Bounds b = dupe.getBounds();
                        sd.getCurrentPage().add(dupe);
                        Point2D pt = event.getPointInNodeCoords(context.getCanvas());
                        pt = context.getSketchCanvas().transformToCanvas(pt);
                        dupe.setTranslateX(pt.getX()-b.getWidth()/2);
                        dupe.setTranslateY(pt.getY()-b.getHeight()/2);
                        context.redraw();
View Full Code Here

TOP

Related Classes of org.joshy.sketch.model.SelfDrawable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.