/*
 * @(#)TightLayoutMonthUI.java
 *
 * Copyright (c) 2003-2004 Stand By Soft, Ltd. All rights reserved.
 *
 * This software is the proprietary information of Stand By Soft, Ltd.  
 * Use is subject to license terms.
 */
package com.standbysoft.demo.date.plaf;

import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.LayoutManager;

import javax.swing.JComponent;
import javax.swing.plaf.ComponentUI;

import com.standbysoft.component.date.swing.plaf.basic.DefaultMonthUI;

/**
 <p>A UI delegate for <code>JMonth</code> that uses a different title layout
 * in order to minimize the space it occupies.</p>
 
 <p>In order for all <code>JMonth</code> components to use such a custom UI,
 * one must register it in the system like this:</p>
 
 <pre>
 *         UIManager.put("MonthUI", TightLayoutMonthUI.class.getName());
 </pre>
 
 <p>Whenever a new <code>JMonth</code> is created it will use the specified UI delegate.</p>
 */
public class TightLayoutMonthUI extends DefaultMonthUI {
    /**
     * Factory method that creates the actual UI delegate.
     */
    public static ComponentUI createUI(JComponent c) {
        return new TightLayoutMonthUI();
    }

    protected LayoutManager createLayout() {
        return new TightLayoutManager();
    }

    protected LayoutManager createTitleLayout() {
        return new TightTitleLayoutManager();
    }
    
    private class TightLayoutManager extends GridBagLayout {
        public void addLayoutComponent(Component comp, Object constraints) {
            if (constraints.equals("Title")) {
                super.addLayoutComponent(comp,
                        new GridBagConstraints(0,0,1,1,0.0,0.0,GridBagConstraints.CENTER,GridBagConstraints.HORIZONTAL,
                            new Insets(0000),0,0));
            }
            if (constraints.equals("Month")) {
                super.addLayoutComponent(comp,
                        new GridBagConstraints(0,1,1,1,1.0,1.0,GridBagConstraints.CENTER,GridBagConstraints.BOTH,
                            new Insets(0000),0,0));
            }
        }
    };
    
    private class TightTitleLayoutManager extends GridBagLayout {
        public void addLayoutComponent(Component comp, Object constraints) {
            if (constraints.equals("TitleMonth")) {
                super.addLayoutComponent(comp, new GridBagConstraints(10111.00.0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, new Insets(2521)00));
            else if (constraints.equals("TitleYear")) {
                super.addLayoutComponent(comp, new GridBagConstraints(20111.00.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(2125)00));
            else if (constraints.equals("TitleLeft")) {
                super.addLayoutComponent(comp, new GridBagConstraints(00112.00.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(2020)00));
            else if (constraints.equals("TitleRight")) {
                super.addLayoutComponent(comp, new GridBagConstraints(30112.00.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(2020)00));
            }
        }
    };
}