Coverage report

  %line %branch
org.cb.jset.client.ui.JSetLogo
0% 
0% 

 1  
 // START LICENSE
 2  
 // JSet - a Java JSet card board game implementation
 3  
 // Copyright (C) 2004 Jerome Lacoste
 4  
 //
 5  
 // This program is free software; you can redistribute it and/or modify
 6  
 // it under the terms of the GNU General Public License as published by
 7  
 // the Free Software Foundation; either version 2 of the License, or (at
 8  
 // your option) any later version.
 9  
 //
 10  
 // This program is distributed in the hope that it will be useful, but
 11  
 // WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  
 // General Public License for more details.
 14  
 //
 15  
 // You should have received a copy of the GNU General Public License
 16  
 // along with this program; if not, write to the Free Software
 17  
 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 18  
 // END LICENSE
 19  
 
 20  
 package org.cb.jset.client.ui;
 21  
 
 22  
 import javax.swing.JPanel;
 23  
 import javax.swing.BorderFactory;
 24  
 import javax.swing.JComponent;
 25  
 import javax.swing.JWindow;
 26  
 import java.awt.FlowLayout;
 27  
 import java.awt.Color;
 28  
 import java.awt.Image;
 29  
 
 30  
 import org.cb.jset.CardProperties;
 31  
 import org.cb.jset.JSetCard;
 32  
 
 33  
 /**
 34  
  * A small class to help build a logo.
 35  
  *
 36  
  * Would be nice to have a way to close it...
 37  
  * @author jerome@coffeebreaks.org - last modified by $LastChangedBy: jerome $
 38  
  * @version $Id: JSetClientUI.java 85 2004-04-13 14:29:08Z jerome $
 39  
  */
 40  
 public class JSetLogo extends JWindow
 41  
 {
 42  0
   private final JPanel _logoPanel = new JPanel();
 43  
 
 44  
   /**
 45  
    * Constructs a JSetLogo instance.
 46  
    */
 47  
   public JSetLogo()
 48  0
   {
 49  0
     init();
 50  0
   }
 51  
 
 52  
   /*
 53  
   class JLogoName extends JComponent
 54  
   {
 55  
     private final AffineTransform at = new AffineTransform();
 56  
     private TextLayout _textTl;
 57  
     private final String _logoName = "JSet";
 58  
 
 59  
     public JLogoName()
 60  
     {
 61  
       init();
 62  
     }
 63  
 
 64  
     void init()
 65  
     {
 66  
       _textTl = new TextLayout(_logoName,
 67  
                                new Font("Helvetica", 3, 16),
 68  
                                new FontRenderContext(null, false, false));
 69  
       AffineTransform textAt = new AffineTransform();
 70  
       textAt.translate(0, (float)_textTl.getBounds().getHeight());
 71  
     }
 72  
 
 73  
     protected void paintComponent(final Graphics g)
 74  
     {
 75  
       super.paintComponent(g);
 76  
 
 77  
       Graphics2D g2 = (Graphics2D) g;
 78  
       Dimension d = getSize();
 79  
       int w = d.width;
 80  
       int h = d.height;
 81  
 
 82  
       float width = (float) _textTl.getBounds().getWidth();
 83  
       float height = (float) _textTl.getBounds().getHeight();
 84  
       final float v = w/2-width/2;
 85  
       AffineTransform at = new AffineTransform();
 86  
       at.rotate(Math.toRadians(-6));
 87  
       g2.transform(at);
 88  
 
 89  
       g2.setPaint(new GradientPaint(0, 0, Color.darkGray, w-50, h, Color.orange, false));
 90  
       _textTl.draw(g2, v, 15);
 91  
     }
 92  
   }
 93  
   */
 94  
 
 95  
   /**
 96  
    * initialize the contents of the JWindow representing the logo.
 97  
    */
 98  
   private void init()
 99  
   {
 100  
 
 101  0
     this.getContentPane().add(_logoPanel);
 102  0
     _logoPanel.setLayout(null);
 103  0
     this.pack();
 104  0
     this.setBounds(50, 50, 82, 108);
 105  
 
 106  
     JPanel lPanel;
 107  0
     final int distanceFromCenter = 18;
 108  0
     final int centerX = 20;
 109  0
     final int centerY = 20;
 110  
 
 111  
     // unused for now...
 112  
 //    {
 113  
 //      JLogoName logoName = new JLogoName();
 114  
 //      logoName.setSize(50, 30);
 115  
 //      logoName.setBounds(37, centerY + 3 * distanceFromCenter,
 116  
 //                        logoName.getWidth(), logoName.getHeight());
 117  
 //      logoName.setPreferredSize(logoName.getPreferredSize());
 118  
 //
 119  
 //      _logoPanel.add(logoName);
 120  
 //    }
 121  
     {
 122  0
       final org.cb.jset.JSetCard card3 =
 123  
           new JSetCard(class="keyword">new CardProperties((byte) 3, (byte) 3, (byte) 1, (byte) 3));
 124  0
       final int x = centerX;
 125  0
       final int y = centerY + distanceFromCenter;
 126  0
       lPanel = createCardPanel(card3, x, y);
 127  0
       _logoPanel.add(lPanel);
 128  
     }
 129  
     {
 130  0
       final org.cb.jset.JSetCard card1 =
 131  
           new JSetCard(class="keyword">new CardProperties((byte) 1, (byte) 1, (byte) 1, (byte) 1));
 132  0
       final int x = (class="keyword">int) (centerX - distanceFromCenter * Math.sqrt(3) / 2);
 133  0
       final int y = (class="keyword">int) (centerY - distanceFromCenter / 2);
 134  0
       lPanel = createCardPanel(card1, x, y);
 135  0
       _logoPanel.add(lPanel);
 136  
     }
 137  
     {
 138  0
       final org.cb.jset.JSetCard card2 =
 139  
           new JSetCard(class="keyword">new CardProperties((byte) 2, (byte) 2, (byte) 1, (byte) 2));
 140  0
       final int x = (class="keyword">int) (centerX + distanceFromCenter * Math.sqrt(3) / 2);
 141  0
       final int y = (class="keyword">int) (centerY - distanceFromCenter);
 142  0
       lPanel = createCardPanel(card2, x, y);
 143  0
       _logoPanel.add(lPanel);
 144  
     }
 145  0
   }
 146  
 
 147  
   /**
 148  
    * Saves the logo in a file.
 149  
    * Note: not implemented right now
 150  
    *
 151  
    * @param filePath the path where the image will be contained
 152  
    * @todo implement the save image functionality. We probably need to specify image type (e.g. png)
 153  
    */
 154  
   void saveLogo(final String filePath)
 155  
   {
 156  0
     Image image = this.createImage(class="keyword">this.getWidth(), class="keyword">this.getHeight());
 157  
     // FIXME would be nice to be able to save this image somwehere. Find a way...
 158  0
   }
 159  
 
 160  
   /**
 161  
    * Helper method to create a small panel containing the specified card, located
 162  
    * at the specified coordinates.
 163  
    * @param card1
 164  
    * @param x
 165  
    * @param y
 166  
    * @return
 167  
    */
 168  
   private JPanel createCardPanel(final JSetCard card1, class="keyword">final int x, class="keyword">final int y)
 169  
   {
 170  
     JComponent lCard;
 171  
     JPanel lPanel;
 172  0
     lCard = new JSetCardComponent(card1).getShape(0);
 173  0
     lCard.setSize(32, 52);
 174  0
     lCard.setPreferredSize(lCard.getSize());
 175  0
     lPanel = new JPanel();
 176  0
     lPanel.setLayout(new FlowLayout());
 177  0
     lPanel.setSize(42, 64);
 178  0
     lPanel.setBackground(Color.white);
 179  0
     lPanel.setPreferredSize(lPanel.getSize());
 180  0
     lPanel.add(lCard);
 181  0
     lPanel.setBounds(x, y, lPanel.getWidth(), lPanel.getHeight());
 182  0
     lPanel.setBorder(BorderFactory.createLineBorder(Color.black));
 183  0
     return lPanel;
 184  
   }
 185  
 
 186  
   /**
 187  
    * Start and show the logo.
 188  
    * @param args the arguments
 189  
    */
 190  
   public static void main(final String[] args)
 191  
   {
 192  0
     final JSetLogo logo = new JSetLogo();
 193  0
     logo.show();
 194  0
   }
 195  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.