< prev index next >

src/demo/share/jfc/J2Ddemo/java2d/demos/Lines/Joins.java

Print this page


   1 /*
   2  *
   3  * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
   4  *
   5  * Redistribution and use in source and binary forms, with or without
   6  * modification, are permitted provided that the following conditions
   7  * are met:
   8  *
   9  *   - Redistributions of source code must retain the above copyright
  10  *     notice, this list of conditions and the following disclaimer.
  11  *
  12  *   - Redistributions in binary form must reproduce the above copyright
  13  *     notice, this list of conditions and the following disclaimer in the
  14  *     documentation and/or other materials provided with the distribution.
  15  *
  16  *   - Neither the name of Oracle nor the names of its
  17  *     contributors may be used to endorse or promote products derived
  18  *     from this software without specific prior written permission.
  19  *
  20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  21  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR


  96         setConstraints(new String[] { BorderLayout.NORTH, BorderLayout.WEST });
  97     }
  98 
  99     @Override
 100     public void render(int w, int h, Graphics2D g2) {
 101         BasicStroke bs = new BasicStroke(bswidth,
 102                 BasicStroke.CAP_BUTT, joinType);
 103         GeneralPath p = new GeneralPath();
 104         p.moveTo(-w / 4.0f, -h / 12.0f);
 105         p.lineTo(+w / 4.0f, -h / 12.0f);
 106         p.lineTo(-w / 6.0f, +h / 4.0f);
 107         p.lineTo(+0.0f, -h / 4.0f);
 108         p.lineTo(+w / 6.0f, +h / 4.0f);
 109         p.closePath();
 110         p.closePath();
 111         g2.translate(w / 2, h / 2);
 112         g2.setColor(BLACK);
 113         g2.draw(bs.createStrokedShape(p));
 114     }
 115 
 116     public static void main(String s[]) {
 117         createDemoFrame(new Joins());
 118     }
 119 
 120 
 121     class DemoControls extends CustomControls implements ActionListener {
 122 
 123         Joins demo;
 124         int joinType[] = { BasicStroke.JOIN_MITER,
 125             BasicStroke.JOIN_ROUND, BasicStroke.JOIN_BEVEL };
 126         String joinName[] = { "Mitered Join", "Rounded Join", "Beveled Join" };
 127         JMenu menu;
 128         JMenuItem menuitem[] = new JMenuItem[joinType.length];
 129         JoinIcon icons[] = new JoinIcon[joinType.length];
 130         JToolBar toolbar;
 131 
 132         @SuppressWarnings("LeakingThisInConstructor")
 133         public DemoControls(Joins demo) {
 134             super(demo.name);
 135             setBorder(new CompoundBorder(getBorder(),
 136                     new EmptyBorder(2, 2, 2, 2)));
 137             this.demo = demo;
 138             setLayout(new BorderLayout());
 139             label = new JLabel(" Width = " + String.valueOf(demo.bswidth));
 140             Font font = new Font(Font.SERIF, Font.BOLD, 14);
 141             label.setFont(font);
 142             add("West", label);
 143             JMenuBar menubar = new JMenuBar();
 144             add("East", menubar);
 145             menu = menubar.add(new JMenu(joinName[0]));
 146             menu.setFont(font = new Font(Font.SERIF, Font.PLAIN, 10));
 147             ActionListener actionListener = new ActionListener() {
 148 
 149                 public void actionPerformed(ActionEvent e) {


   1 /*
   2  *
   3  * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
   4  *
   5  * Redistribution and use in source and binary forms, with or without
   6  * modification, are permitted provided that the following conditions
   7  * are met:
   8  *
   9  *   - Redistributions of source code must retain the above copyright
  10  *     notice, this list of conditions and the following disclaimer.
  11  *
  12  *   - Redistributions in binary form must reproduce the above copyright
  13  *     notice, this list of conditions and the following disclaimer in the
  14  *     documentation and/or other materials provided with the distribution.
  15  *
  16  *   - Neither the name of Oracle nor the names of its
  17  *     contributors may be used to endorse or promote products derived
  18  *     from this software without specific prior written permission.
  19  *
  20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  21  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR


  96         setConstraints(new String[] { BorderLayout.NORTH, BorderLayout.WEST });
  97     }
  98 
  99     @Override
 100     public void render(int w, int h, Graphics2D g2) {
 101         BasicStroke bs = new BasicStroke(bswidth,
 102                 BasicStroke.CAP_BUTT, joinType);
 103         GeneralPath p = new GeneralPath();
 104         p.moveTo(-w / 4.0f, -h / 12.0f);
 105         p.lineTo(+w / 4.0f, -h / 12.0f);
 106         p.lineTo(-w / 6.0f, +h / 4.0f);
 107         p.lineTo(+0.0f, -h / 4.0f);
 108         p.lineTo(+w / 6.0f, +h / 4.0f);
 109         p.closePath();
 110         p.closePath();
 111         g2.translate(w / 2, h / 2);
 112         g2.setColor(BLACK);
 113         g2.draw(bs.createStrokedShape(p));
 114     }
 115 
 116     public static void main(String[] s) {
 117         createDemoFrame(new Joins());
 118     }
 119 
 120 
 121     class DemoControls extends CustomControls implements ActionListener {
 122 
 123         Joins demo;
 124         int[] joinType = { BasicStroke.JOIN_MITER,
 125             BasicStroke.JOIN_ROUND, BasicStroke.JOIN_BEVEL };
 126         String[] joinName = { "Mitered Join", "Rounded Join", "Beveled Join" };
 127         JMenu menu;
 128         JMenuItem[] menuitem = new JMenuItem[joinType.length];
 129         JoinIcon[] icons = new JoinIcon[joinType.length];
 130         JToolBar toolbar;
 131 
 132         @SuppressWarnings("LeakingThisInConstructor")
 133         public DemoControls(Joins demo) {
 134             super(demo.name);
 135             setBorder(new CompoundBorder(getBorder(),
 136                     new EmptyBorder(2, 2, 2, 2)));
 137             this.demo = demo;
 138             setLayout(new BorderLayout());
 139             label = new JLabel(" Width = " + String.valueOf(demo.bswidth));
 140             Font font = new Font(Font.SERIF, Font.BOLD, 14);
 141             label.setFont(font);
 142             add("West", label);
 143             JMenuBar menubar = new JMenuBar();
 144             add("East", menubar);
 145             menu = menubar.add(new JMenu(joinName[0]));
 146             menu.setFont(font = new Font(Font.SERIF, Font.PLAIN, 10));
 147             ActionListener actionListener = new ActionListener() {
 148 
 149                 public void actionPerformed(ActionEvent e) {


< prev index next >