Package com.jedics.swing.plaf

Source Code of com.jedics.swing.plaf.JediIconFactory$MenuArrowIcon

package com.jedics.swing.plaf;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.RoundRectangle2D;
import java.io.Serializable;

import javax.swing.ButtonModel;
import javax.swing.Icon;
import javax.swing.JCheckBox;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JRadioButton;
import javax.swing.plaf.UIResource;

public class JediIconFactory {

  private static Icon radioButtonIcon;
  private static Icon checkBoxIcon;
 
  private static Icon menuArrowIcon;
  private static Icon checkBoxMenuItemIcon;
  private static Icon radioButtonMenuItemIcon;
 
 
  // Constants
  public static final boolean DARK = false;
  public static final boolean LIGHT = true;
 
 
 
  public static Icon getRadioButtonIcon() {
    if (radioButtonIcon == null) {
      radioButtonIcon = new RadioButtonIcon();
    }
    return radioButtonIcon;
  }
  public static Icon getCheckBoxIcon() {
    if (checkBoxIcon == null) {
      checkBoxIcon = new CheckBoxIcon();
    }
    return checkBoxIcon;
  }
 
  public static Icon getMenuArrowIcon() {
    if (menuArrowIcon == null) {
      menuArrowIcon = new MenuArrowIcon();
    }
    return menuArrowIcon;
  }
  public static Icon getMenuItemCheckIcon() {
    return null;
  }
 
  /*
  public static Icon getCheckBoxMenuItemIcon() {
    if (checkBoxMenuItemIcon == null) {
      checkBoxMenuItemIcon = new CheckBoxMenuItemIcon();
    }
    return checkBoxMenuItemIcon;
  }
 
  public static Icon getRadioButtonMenuItemIcon() {
    if (radioButtonMenuItemIcon == null) {
      radioButtonMenuItemIcon = new RadioButtonMenuItemIcon();
    }
    return radioButtonMenuItemIcon;
  }
  */
 
  private static class CheckBoxIcon implements Icon, UIResource, Serializable {
    private final RoundRectangle2D.Float border = new RoundRectangle2D.Float(0, 0, getControlSize(), getControlSize(), 3, 3);
   
    protected int getControlSize() {
      return 13;
    }
   
    public void paintIcon(Component c, Graphics g, int x, int y) {
      g.translate(x, y);
      ButtonModel model = ((JCheckBox)c).getModel();
      int controlSize = getControlSize();
     
      Graphics2D g2d = (Graphics2D)g;
     
      if (model.isEnabled()) {
        if (model.isPressed() && model.isArmed()) {
          g2d.setColor(JLAFConstants.DARK_GRAY);
          g2d.draw(border);
          g2d.setColor(JLAFConstants.GRAY);
          g2d.setClip(border);
          g2d.fillRect(1, 1, controlSize-1, controlSize-1);
          g2d.setClip(null);
          g2d.setColor(JLAFConstants.BLACK);
        } else if(model.isRollover()) {
          g2d.setColor(JLAFConstants.LIGHT_GRAY);
          g2d.draw(border);
          g2d.setClip(border);
          g2d.fillRect(1, 1, controlSize-1, controlSize-1);
          g2d.setClip(null);
          g2d.setColor(JLAFConstants.BLACK);
        } else {
          g2d.setColor(JLAFConstants.BLACK);
          g2d.draw(border);
          g2d.setColor(c.getForeground());
        }
      } else {
        g2d.setColor(JLAFConstants.GRAY);
        g2d.draw(border);
        g2d.setColor(JLAFConstants.GRAY);
      }
     
      if (model.isSelected()) {
        drawCheck(g2d, 3, 5);
      }
      g.translate(-x, -y);
    }
   
    public int getIconWidth() {
      return getControlSize();
    }
   
    public int getIconHeight() {
      return getControlSize();
    }
  }
 

  private static class RadioButtonIcon implements Icon, UIResource, Serializable {
    private static final int controlSize = 13;
   
   
    public void paintIcon(Component c, Graphics g, int x, int y) {
      JRadioButton rb = (JRadioButton)c;
      ButtonModel model = rb.getModel();
     
      g.translate(x, y);
     
     
      if (model.isEnabled()) {
        if(model.isRollover()) {
          g.setColor(JLAFConstants.DARK_GRAY);
        } else {
          g.setColor(JLAFConstants.LIGHT_GRAY);
        }
      } else {
        g.setColor(JLAFConstants.LIGHT_GRAY);
      }
     
     
      // fill interior
      g.fillRect(2, 1, 8, 3);
      g.fillRect(1, 4, 10, 4);
      g.fillRect(2, 8, 8, 3);
     
     
      // draw Dark Circle (start at top, go clockwise)
      if(model.isEnabled()) {
        g.setColor(JLAFConstants.BLACK);
      } else {
        g.setColor(JLAFConstants.DARK_GRAY);
      }
      g.drawLine( 4, 07, 0);
      g.drawLine( 8, 19, 1);
      g.drawLine(10, 2, 10, 3);
      g.drawLine(11, 4, 11, 7);
      g.drawLine(10, 8, 10, 9);
      g.drawLine( 9,108,10);
      g.drawLine( 7,114,11);
      g.drawLine( 3,102,10);
      g.drawLine( 1, 91, 8);
      g.drawLine( 0, 70, 4);
      g.drawLine( 1, 31, 2);
      g.drawLine( 2, 13, 1);
     
      // selected dot
      if (model.isSelected()) {
        if(model.isEnabled()) {
          g.setColor(JLAFConstants.BLACK);
        } else {
          g.setColor(JLAFConstants.DARK_GRAY);
        }
        g.fillRect( 4, 44, 4);
        g.drawLine( 4, 37, 3);
        g.drawLine( 8, 48, 7);
        g.drawLine( 7, 84, 8);
        g.drawLine( 3, 73, 4);
      }
     
      g.translate(-x, -y);
    }
   
    public int getIconWidth() {
      return controlSize;
    }
   
    public int getIconHeight() {
      return controlSize;
    }
  }
 
  //
  // Menu Icons
  //
 
  static private final Dimension menuArrowIconSize = new Dimension( 4, 8 );
  static private final Dimension menuCheckIconSize = new Dimension( 10, 10 );
  static private final int xOff = 4;
 
  private static class MenuArrowIcon implements Icon, UIResource, Serializable {
    public void paintIcon( Component c, Graphics g, int x, int y ) {
      JMenuItem b = (JMenuItem) c;
      ButtonModel model = b.getModel();
     
      g.translate( x, y );
     
      if ( !model.isEnabled() ) {
        g.setColor(JLAFConstants.GRAY);
      } else {
        if ( model.isArmed() || ( c instanceof JMenu && model.isSelected() ) ) {
          g.setColor(JLAFConstants.WHITE);
        } else {
          g.setColor( b.getForeground() );
        }
      }
      if( b.getComponentOrientation().isLeftToRight() ) {
        g.drawLine( 0, 0, 0, 7 );
        g.drawLine( 1, 1, 1, 6 );
        g.drawLine( 2, 2, 2, 5 );
        g.drawLine( 3, 3, 3, 4 );
      } else {
        g.drawLine( 4, 0, 4, 7 );
        g.drawLine( 3, 1, 3, 6 );
        g.drawLine( 2, 2, 2, 5 );
        g.drawLine( 1, 3, 1, 4 );
      }
     
      g.translate( -x, -y );
    }
   
    public int getIconWidth() { return menuArrowIconSize.width; }
    public int getIconHeight() { return menuArrowIconSize.height; }
   
  }
 
  /*
  private static class CheckBoxMenuItemIcon implements Icon, UIResource, Serializable {
    private RoundRectangle2D.Float border = new RoundRectangle2D.Float(0, 0, getIconWidth(), getIconHeight(), 3, 3);
   
    public void paintIcon( Component c, Graphics g, int x, int y ) {
      JMenuItem b = (JMenuItem) c;
      ButtonModel model = b.getModel();

     
      g.translate( x, y );
     
      if (model.isEnabled()) {
          g.setColor(SolareLookAndFeel.getPrimaryControlShadow());
          g.setClip(border);
          g.fillRect(0, 0, getIconWidth(), getIconHeight());
          g.setClip(null);
      }
      else {
        g.setColor(SolareLookAndFeel.getPrimaryPressedControlShadow());
        g.setClip(border);
        g.fillRect(0, 0, getIconWidth(), getIconHeight());
        g.setClip(null);
      }
     
      if (model.isSelected()) {
        if (model.isEnabled()) {
          if (model.isArmed()) {
            g.setColor(b.getForeground());
          }
          else {
            g.setColor(SolareLookAndFeel.getPrimaryControlInfo());
          }
        }
        else {
          g.setColor( SolareLookAndFeel.getMenuDisabledForeground()  );
        }
       
        drawCheck(g, 2, 2);
      }
     
      g.translate( -x, -y );
    }
    public int getIconWidth() { return menuCheckIconSize.width; }
    public int getIconHeight() { return menuCheckIconSize.height; }
   
  }
 
  private static class RadioButtonMenuItemIcon implements Icon, UIResource, Serializable{
    public void paintIcon( Component c, Graphics g, int x, int y ) {
      JMenuItem b = (JMenuItem) c;
      ButtonModel model = b.getModel();

     
      g.translate( x, y );
     
      if (model.isEnabled()) {
        if(model.isRollover()) {
          g.setColor(SolareLookAndFeel.getPrimaryPressedControlShadow());
        } else {
          g.setColor(SolareLookAndFeel.getPrimaryControlShadow());
        }
      } else {
        g.setColor(SolareLookAndFeel.getDisabledControlShadow());
      }
     
      ((Graphics2D)g).setStroke(TSSUtils.ONE_STROKE);
     
      g.drawLine(4, 1, 7, 1);
      g.fillRect(2, 2, 8, 2);
      g.fillRect(1, 4, 10, 4);
      g.fillRect(2, 8, 8, 2);
      g.drawLine(4, 10, 7, 10);
     
      if (model.isSelected()) {
        if (model.isEnabled()) {
          if (model.isArmed()) {
            g.setColor(b.getForeground());
          }
          else {
            g.setColor(SolareLookAndFeel.getPrimaryControlInfo());
          }
        }
        else {
          g.setColor( SolareLookAndFeel.getMenuDisabledForeground()  );
        }
       
        drawCheck(g, 2, 2);
      }
     
      g.translate( -x, -y );
    }
   
    public int getIconWidth() { return menuCheckIconSize.width; }
    public int getIconHeight() { return menuCheckIconSize.height; }
  }
  */
 
  private static void drawCheck(Graphics g, int x, int y) {
    g.fillRect( x, y, 2, 5 );
    g.drawLine( x+7, y-2, x+2, y+3 );
    g.drawLine( x+7, y-1, x+2, y+4);
  }
}
TOP

Related Classes of com.jedics.swing.plaf.JediIconFactory$MenuArrowIcon

TOP
Copyright © 2018 www.massapi.com. 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.