001    package org.apache.tapestry.contrib.services;
002    
003    import org.apache.tapestry.contrib.services.impl.RoundedCornerGenerator;
004    
005    import javax.swing.*;
006    import java.awt.*;
007    import java.awt.image.BufferedImage;
008    
009    /**
010     *
011     */
012    public class TestRoundedUtil extends JComponent {
013    
014        private static final int WIDTH = 100;
015        private static final int HEIGHT = 100;
016    
017        public TestRoundedUtil()
018        {
019        }
020    
021        public Dimension getPreferredSize() {
022    
023            return new Dimension(200, 200);
024        }
025    
026        public Dimension getMinimumSize() {
027    
028            return new Dimension(200,200);
029        }
030    
031        protected void paintComponent(Graphics g) {
032    
033            Graphics2D g2 = (Graphics2D)g;
034    
035            RoundedCornerGenerator generator = new RoundedCornerGenerator();
036            BufferedImage image = null;
037    
038            try {
039    
040                image = generator.buildShadow("99ccff", "white", 100, 100, 20f, 20f, 6, 0.5f);
041            }
042            catch (Exception e) {
043                e.printStackTrace();
044                System.exit(-1);
045            }
046    
047            //g2.setColor(Color.white);
048            //g2.fillRect(0, 0, 100, 100);
049    
050            g2.drawImage(image, 0, 0, null);
051        }
052    
053        /*
054        protected void paintComponent(Graphics g) {
055    
056            Graphics2D g2 = (Graphics2D)g;
057    
058            RoundedCornerGenerator generator = new RoundedCornerGenerator();
059            BufferedImage image = null;
060    
061            try {
062                
063                image = generator.buildSideShadow("top", 8, 0.5f);
064            }
065            catch (Exception e) {
066                e.printStackTrace();
067                System.exit(-1);
068            }
069    
070            g2.setColor(Color.white);
071            g2.fillRect(0, 0, 100, 100);
072            
073            g2.drawImage(image, 0, 0, null);
074        }
075        */
076    
077        /*
078        protected void paintComponent(Graphics g) {
079    
080            Graphics2D g2 = (Graphics2D)g;
081    
082            RoundedCornerGenerator generator = new RoundedCornerGenerator();
083            BufferedImage image = null;
084    
085            try {
086    
087                image = generator.buildCorner("6188C7", "white", 6, 6, "tr", -1, -1);
088            }
089            catch (Exception e) {
090                e.printStackTrace();
091                System.exit(-1);
092            }
093    
094            g2.drawImage(image, 0, 0, null);
095    
096            
097        }*/
098    
099        private static void createAndShowGUI() {
100            //Create and set up the window.
101            JFrame frame = new JFrame("Rounded Corner Viewer");
102            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
103    
104            //Create and set up the content pane.
105            TestRoundedUtil id = new TestRoundedUtil();
106            frame.getContentPane().add(id, BorderLayout.CENTER);
107    
108            //Display the window.
109            frame.pack();
110            frame.setVisible(true);
111        }
112    
113        public static void main(String[] args) {
114            //Schedule a job for the event-dispatching thread:
115            //creating and showing this application's GUI.
116            javax.swing.SwingUtilities.invokeLater(new Runnable() {
117                public void run() {
118                    createAndShowGUI();
119                }
120            });
121        }
122    }