Package org.eclipse.swt.widgets

Examples of org.eclipse.swt.widgets.Canvas


  }

  public void createPartControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NULL);
      composite.setLayout(new FillLayout());
      final Canvas canvas = new Canvas(composite, SWT.NULL);
    canvas.setBackground(canvas.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    canvas.addPaintListener(new PaintListener(){
          public void paintControl(PaintEvent e){
              Rectangle clientArea = canvas.getClientArea();
              e.gc.drawLine(0,0,clientArea.width,clientArea.height);
          }
         
      });
   
View Full Code Here


       
        imgs = new Image[6];
        for(int i = 0; i < imgs.length; i++)
            imgs[i] = new Image(null, new Formatter().format("imgs\\%02d.jpg", i+1).toString());
       
        final Canvas cnvs = new Canvas(sShell, SWT.DOUBLE_BUFFERED);
        cnvs.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
        FormData fd = new FormData();
        fd.left = new FormAttachment(0, 5);
        fd.right = new FormAttachment(100, -5);
        fd.top = new FormAttachment(0, 5);
        fd.bottom = new FormAttachment(100, -35);
        cnvs.setLayoutData(fd);
       
        final Button btn = new Button(sShell, SWT.PUSH);
        btn.setText("Hit me!");
        fd = new FormData();
        fd.top = new FormAttachment(cnvs, 5);
        fd.bottom = new FormAttachment(100, -5);
        fd.left = new FormAttachment(0, 5);
        fd.right = new FormAttachment(100, -5);
        btn.setLayoutData(fd);
       
        Transition t = new Transition(new Transitionable() {
            @Override
            public void setSelection(int index) {
                me.curImg = (index + 1) % me.imgs.length;
            }
       
            @Override
            public int getSelection() {
                return me.curImg;
            }
       
            @Override
            public Control getControl(int index) {
                return cnvs;
            }
       
            @Override
            public Composite getComposite() {
                return sShell;
            }
       
            @Override
            public int compare(int index1, int index2) {
                return Math.random() > 0.5 ? index1 : index2;
            }
       
            @Override
            public void addSelectionListener(SelectionListener listener) {
                btn.addSelectionListener(listener);
            }
        });
        t.setTransition(Transition.RANDOM_ROTATION);
        t.addTransitionListener(new TransitionListener() {
            public void transitionFinished(Transition transition) {
                System.out.println("End Of Transition! current item: "
                        + transition.getTransitionable().getSelection());
            }
        });
       
        cnvs.addPaintListener(new PaintListener() {
            @Override
            public void paintControl(PaintEvent e) {
                Image img = me.imgs[me.curImg];
                e.gc.drawImage(
                        img
                        , 0
                        , 0
                        , img.getImageData().width
                        , img.getImageData().height
                        , 0
                        , 0
                        , cnvs.getSize().x
                        , cnvs.getSize().y
                        );
            }
        });
       
    }
View Full Code Here

            transitionable.setSelection(currentItem);
            Image imgTo = ImageCapture.getImage(to, size.width, size.height, true);
            transitionable.setSelection(lastItem);
           
            //create and show the canvas that the transition will be showed on
            Canvas canvas = new Canvas(transitionable.getComposite(), SWT.DOUBLE_BUFFERED);
            canvas.moveAbove(null);
            canvas.setBounds(to.getBounds());
           
            //make the transition
            GC gcOn = new GC(canvas);
            switch(transition) {
            case HORIZONTAL_ROTATION:
            case VERTICAL_ROTATION:
            case HORIZONTAL_LINEAR:
            case VERTICAL_LINEAR:
            case FADE:
                translate(transition, imgFrom, imgTo, gcOn
                        , transitionable.compare(currentItem, lastItem) == currentItem);
                break;
            case RANDOM:
            case RANDOM_LINEAR:
            case RANDOM_ROTATION:
                randomTransition(transition, imgFrom, imgTo, gcOn
                        , transitionable.compare(currentItem, lastItem) == currentItem);
                break;
            }
            transitionable.setSelection(currentItem);
            gcOn.dispose();
           
            //dispose the transition canvas
            canvas.dispose();
           
            //now the item transition ends on will be used
            //to start transition from next time
            lastItem = currentItem;
           
View Full Code Here

        Display.getCurrent().readAndDispatch();
    }

    public void translate(final Composite from, final Composite to, final Composite on) {
        Rectangle size = from.getClientArea();
        Canvas canvas = new Canvas(on, SWT.DOUBLE_BUFFERED);
        canvas.moveAbove(null);
        canvas.setBounds(from.getBounds());
       
        Image imgFrom = new Image(Display.getCurrent(), size.width, size.height);
        GC gcfrom = new GC(from);
        System.out.println("from: " + from.getData());
        gcfrom.copyArea(imgFrom, 0, 0);
//        ImageLoader loader = new ImageLoader();
//        loader.data = new ImageData[]{imgFrom.getImageData()};
//        loader.save("E:\\from.bmp", SWT.IMAGE_BMP);
        gcfrom.dispose();
       
        Image imgTo = new Image(Display.getCurrent(), size.width, size.height);
        GC gcto = new GC(to);
        System.out.println("to: " + to.getData());
        gcto.copyArea(imgTo, 0, 0);
//        loader.data = new ImageData[]{imgTo.getImageData()};
//        loader.save("E:\\to.bmp", SWT.IMAGE_BMP);
        gcto.dispose();
       
        GC gcOn = new GC(canvas);
        //hRotate(imgFrom, imgTo, gcOn);
        gcOn.dispose();
       
        canvas.dispose();
    }
View Full Code Here

        // TODO: size position and size of each widget and store a pointer to its respective object data/property
        // TODO: check object property for each widget, calculated values should not be editable
        // TODO: wire up a modify listener for inputs that the user can edit

        // this thing is the sheet ;)
        Canvas sheet = new Canvas(scrolledComp, SWT.NONE);
        sheet.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));

        // TODO: load a suitable character sheet image
        // sheet.setBackgroundImage(image)

        // Composite sheet = new Composite(scrolledComp, SWT.NONE);
        // sheet.setLayout(new GridLayout(3, true));
        // // sheet.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 6, 1));
        //
        // // sheet logo
        // Label imageLabel = new Label(sheet, SWT.CENTER);
        // imageLabel.setText("logo goes here"); // TODO
        //
        // // bio
        // Composite bioComp = new Composite(sheet, SWT.NONE);
        // bioComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 2));
        // setupBioComp(bioComp);
        //
        // // ability scores
        // Group scoresComp = new Group(sheet, SWT.NONE);
        // scoresComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 2));
        // scoresComp.setText(Messages
        // .getString("object.instance.charsheet.editor.page.character_sheet.group.ability_scores.label"));
        // setupAbilityScoresComp(scoresComp);
        //
        // // defenses
        // Group defensesComp = new Group(sheet, SWT.NONE);
        // defensesComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 2));
        // defensesComp.setText(Messages
        // .getString("object.instance.charsheet.editor.page.character_sheet.group.defenses.label"));
        // setupDefensesComp(defensesComp);
        //
        // // hit points
        // Group hitPointsComp = new Group(sheet, SWT.NONE);
        // hitPointsComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 3));
        // hitPointsComp.setText(Messages
        // .getString("object.instance.charsheet.editor.page.character_sheet.group.hit_points.label"));
        // setupHitPointsComp(hitPointsComp);
        //
        // // action points
        // Group actionPointsComp = new Group(sheet, SWT.NONE);
        // actionPointsComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
        // actionPointsComp.setText(Messages
        // .getString("object.instance.charsheet.editor.page.character_sheet.group.action_points.label"));
        // setupActionPointsComp(actionPointsComp);
        //
        // // skills
        // Group skillsComp = new Group(sheet, SWT.NONE);
        // skillsComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 4));
        // skillsComp.setText(Messages
        // .getString("object.instance.charsheet.editor.page.character_sheet.group.skills.label"));
        // setupSkillsComp(skillsComp);
        //
        // // senses
        // Group sensesComp = new Group(sheet, SWT.NONE);
        // sensesComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
        // sensesComp.setText(Messages
        // .getString("object.instance.charsheet.editor.page.character_sheet.group.senses.label"));
        // setupSensesComp(sensesComp);
        //
        // // initiative
        // Group initiativeComp = new Group(sheet, SWT.NONE);
        // initiativeComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
        // initiativeComp.setText(Messages
        // .getString("object.instance.charsheet.editor.page.character_sheet.group.initiative.label"));
        // setupInitiativeComp(initiativeComp);
        //
        // // speed
        // Group speedComp = new Group(sheet, SWT.NONE);
        // speedComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
        // speedComp
        // .setText(Messages.getString("object.instance.charsheet.editor.page.character_sheet.group.speed.label"));
        // setupSpeedComp(speedComp);
        //
        // // attacks
        // Group attacksComp = new Group(sheet, SWT.NONE);
        // attacksComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 2));
        // attacksComp.setText(Messages
        // .getString("object.instance.charsheet.editor.page.character_sheet.group.attacks.label"));
        // setupAttacksComp(attacksComp);
        //
        // // languages
        // Group languagesComp = new Group(sheet, SWT.NONE);
        // languagesComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
        // languagesComp.setText(Messages
        // .getString("object.instance.charsheet.editor.page.character_sheet.group.languages.label"));
        // setupLanguagesComp(languagesComp);
        //
        // // feats
        // Group featsComp = new Group(sheet, SWT.NONE);
        // featsComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
        // featsComp
        // .setText(Messages.getString("object.instance.charsheet.editor.page.character_sheet.group.feats.label"));
        // setupFeatsComp(featsComp);
        //
        // // equipment
        // Group equipmentComp = new Group(sheet, SWT.NONE);
        // equipmentComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
        // equipmentComp.setText(Messages
        // .getString("object.instance.charsheet.editor.page.character_sheet.group.equipment.label"));
        // setupEquipmentComp(equipmentComp);
        //
        // // race features
        // Group raceFeaturesComp = new Group(sheet, SWT.NONE);
        // raceFeaturesComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
        // raceFeaturesComp.setText(Messages
        // .getString("object.instance.charsheet.editor.page.character_sheet.group.race_features.label"));
        // setupRaceFeaturesComp(raceFeaturesComp);
        //
        // // class features
        // Group classFeaturesComp = new Group(sheet, SWT.NONE);
        // classFeaturesComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 2));
        // classFeaturesComp.setText(Messages
        // .getString("object.instance.charsheet.editor.page.character_sheet.group.class_features.label"));
        // setupClassFeaturesComp(classFeaturesComp);
        //
        // // appearance
        // Group appearanceComp = new Group(sheet, SWT.NONE);
        // appearanceComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
        // appearanceComp.setText(Messages
        // .getString("object.instance.charsheet.editor.page.character_sheet.group.appearance.label"));
        // setupAppearanceComp(appearanceComp);
        //
        // // wealth
        // Group wealthComp = new Group(sheet, SWT.NONE);
        // wealthComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
        // wealthComp.setText(Messages
        // .getString("object.instance.charsheet.editor.page.character_sheet.group.wealth.label"));
        // setupWealthComp(wealthComp);
        //
        // // personality
        // Group personalityComp = new Group(sheet, SWT.NONE);
        // personalityComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
        // personalityComp.setText(Messages
        // .getString("object.instance.charsheet.editor.page.character_sheet.group.personality.label"));
        // setupPersonalityComp(personalityComp);

        scrolledComp.setContent(sheet);
        scrolledComp.setExpandHorizontal(true);
        scrolledComp.setExpandVertical(true);
        scrolledComp.setMinSize(sheet.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    }
View Full Code Here

 
  // private methods

  private Canvas getControl(Composite cmp, final ShapeModel shape) {   
     
    final Canvas ctrl = new Canvas(cmp, SWT.BORDER_SOLID);
    ctrl.setLayoutData(new RowData(iconSize, iconSize));
   
    //ctrl.pack();
    //Point size = ctrl.computeSize (iconSize, iconSize);
    //ctrl.setSize (size.x, size.y);
   
    ctrl.addPaintListener(new PaintListener() {
      public void paintControl(PaintEvent e) {
        //ctrl.setSize(iconSize, iconSize);
        Rectangle clientArea = ctrl.getClientArea();
        e.gc.setBackground(ctrl.getDisplay().getSystemColor(
            SWT.COLOR_WHITE));
        e.gc.fillRectangle(0, 0, clientArea.width - 1,
            clientArea.height - 1);
        e.gc.setBackground(ctrl.getDisplay().getSystemColor(
            SWT.COLOR_BLACK));
        e.gc.drawRectangle(0, 0, clientArea.width - 1,
            clientArea.height - 1);

        // now draw this control
        Rectangle2D bounds = shape.getBounds();
        // get the resize ratio
        double resize = (iconSize - 8)
            / (bounds.getWidth() > bounds.getHeight() ? bounds
                .getWidth() : bounds.getHeight());
        // resize graphics
        ShapeModel newShape = shape.clone();
        newShape.moveToCenter();
        newShape.scale(resize, resize);
        // now move it to centre of the icon
        newShape.translate(iconSize / 2, iconSize  / 2);
               
       
        for (LineModel line : newShape.getLines()) {
          for (int i=0; i<line.getPoints().size()-1; i++) {
            drawLine(e.gc, line.getPoints().get(i), line.getPoints().get(i+1));
          }
          if (line.isClosed()) {
            drawLine(e.gc, line.getPoints().get(0), line.getPoints().get(line.getPoints().size()-1));
          }
        }
      }
    });
   
    // add mouse listener
    ctrl.addMouseListener(new MouseListener() {     
      @Override
      public void mouseUp(MouseEvent e) {
      }
     
      @Override
      public void mouseDown(MouseEvent e) {
      }
     
      @Override
      public void mouseDoubleClick(MouseEvent e) {
        // get the rendering editor
        IEditorPart editor =  getSite().getPage().getActiveEditor();
        if (editor == null) {
          MessageDialog.openInformation(getSite().getShell(), "Information", "You need to open the renderer to continue");
          return;
        }
        RenderingEditor renderer = (RenderingEditor) editor;
        renderer.getProtocol().getShapeBasket().clear();
        renderer.getProtocol().getShapeBasket().add(shape);
        renderer.setRenderedShape();
      }
    });
   
    Cursor cursor = new Cursor(ctrl.getDisplay(), SWT.CURSOR_HAND);
    ctrl.setCursor(cursor);

    return ctrl;
  }
View Full Code Here

 
  // private methods

  public static Canvas getControl(Composite cmp, final ShapeModel shape) {   
     
    final Canvas ctrl = new ShapeIconControl(cmp, shape);
    return ctrl;
  }
View Full Code Here

    return ctrl;
  }
 
  public static void getSeparator(Composite cmp) {   
   
    final Canvas ctrl = new Canvas(cmp, SWT.BORDER_SOLID);
    ctrl.setLayoutData(new RowData(20, iconSize));
    ctrl.addPaintListener(new PaintListener() {
      public void paintControl(PaintEvent e) {
        e.gc.drawLine(2, iconSize/2-2, 15, iconSize/2-2);
        e.gc.drawLine(2, iconSize/2+2, 15, iconSize/2+2);
        e.gc.drawLine(15, iconSize/2-5, 19, iconSize/2);
        e.gc.drawLine(15, iconSize/2+5, 19, iconSize/2);
View Full Code Here

         */

        // You must specify SWT.NO_BACKGROUND for the canvas as we are
        // taking care of its complete rendering.
        if (canvas == null) {
            canvas = new Canvas(getGroup(), SWT.NO_BACKGROUND);
            canvas.addPaintListener(new PaintListener() {
                public void paintControl(PaintEvent pe) {
                    Rectangle canvasArea = canvas.getClientArea();
                    // Because image is passed into the constructor and the
                    // getChild method is called from Preview's constructor, we
View Full Code Here

        showTreeview();
    }

    private void createOverview(Composite parent) {
        ScalableFreeformRootEditPart rootEditPart = (ScalableFreeformRootEditPart) editor.getGraphicalViewer().getRootEditPart();
        overview = new Canvas(parent, SWT.NONE);
        LightweightSystem lws = new LightweightSystem(overview);
        thumbnail = new ScrollableThumbnail((Viewport) rootEditPart.getFigure());
        thumbnail.setBorder(new MarginBorder(3));
        thumbnail.setSource(rootEditPart.getLayer(LayerConstants.PRINTABLE_LAYERS));
        lws.setContents(thumbnail);
View Full Code Here

TOP

Related Classes of org.eclipse.swt.widgets.Canvas

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.