/*
 * @(#)PDFToolBarSeparatorUI.java  1.2  2006-06-16
 *
 * Copyright (c) 2004 Werner Randelshofer, Immensee, Switzerland.
 * All rights reserved.
 *
 * You may not use, copy or modify this file, except in compliance with the
 * license agreement you entered into with Werner Randelshofer.
 * For details see accompanying license terms.
 */

package ch.randelshofer.pdf.plaf;

import java.awt.*;
import javax.swing.*;
import javax.swing.plaf.*;
import javax.swing.plaf.basic.*;
/**
 * PDFToolBarSeparatorUI.
 *
 * @author  Werner Randelshofer
 * @version 1.2 2006-06-16 Fixed size values again. 
 * <br>1.1 2006-02-12 Fixed size values and drawing code.
 * <br>1.0  28 March 2005  Created.
 */
public class PDFToolBarSeparatorUI extends BasicToolBarSeparatorUI {
    private final static Stroke separatorStroke =
    new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0,
    new float[] {2f,2f}, 0f);
    
    public static ComponentUI createUI( JComponent c ) {
        return new PDFToolBarSeparatorUI();
    }
    @Override
    protected void installDefaults( JSeparator s ) {
        //super.installDefaults(s);
        PDFLookAndFeel plaf = PDFLookAndFeel.getInstance();
        Dimension size = ( (JToolBar.Separator)s ).getSeparatorSize();

	//if ( size == null || size instanceof UIResource )
	//{
	    JToolBar.Separator sep = (JToolBar.Separator)s;
	    size = (Dimension)(plaf.get("ToolBar.separatorSize"));
	    if (size != null) {
		if (sep.getOrientation() == JSeparator.HORIZONTAL) {
		    size = new Dimension(size.height, size.width);
		}
		sep.setSeparatorSize(size);
	    }
	//}
        s.setForeground(plaf.getColor("ToolBarSeparator.foreground"));
    }
    
    
    @Override
    public void paint( Graphics gr, JComponent c ) {
        Graphics2D g = (Graphics2D) gr;
        int width = c.getWidth();
        int height = c.getHeight();
        g.setColor(c.getForeground());
        g.setStroke(separatorStroke);
        JToolBar.Separator sep = (JToolBar.Separator) c;
        if (sep.getOrientation() == JSeparator.HORIZONTAL) {
            g.drawLine(2,height / 2, width - 3, height / 2);
        } else {
            g.drawLine(width / 2, 2, width / 2, height - 3);
        }
    }
    
    @Override
    public Dimension getMinimumSize( JComponent c ) {
        JToolBar.Separator sep = (JToolBar.Separator) c;
        if (sep.getOrientation() == JSeparator.HORIZONTAL) {
            return new Dimension(20,20);
        } else {
            return new Dimension(20,20);
        }
    }
    @Override
    public Dimension getPreferredSize( JComponent c ) {
        JToolBar.Separator sep = (JToolBar.Separator) c;
        if (sep.getOrientation() == JSeparator.HORIZONTAL) {
            return new Dimension(20,20);
        } else {
            return new Dimension(20, 20);
        }
    }
    @Override
    public Dimension getMaximumSize( JComponent c ) {
        JToolBar.Separator sep = (JToolBar.Separator) c;
        if (sep.getOrientation() == JSeparator.HORIZONTAL) {
            return new Dimension(Integer.MAX_VALUE,20);
        } else {
            return new Dimension(20,Integer.MAX_VALUE);
        }
    }
}
