/*
 * Copyright 2008 Sanjiv Sahayam
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.pondskum.gui.swing.notifyer;

import com.googlecode.pondskum.client.BigpondUsageInformation;
import com.googlecode.pondskum.stub.StubbyBigpondUsageInformationBuilder;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.uiDesigner.core.Spacer;

import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.Insets;

public final class ProgressionPanel {

    private final BigpondUsageInformation usageInfo;
    private JPanel contentPanel;
    private JLabel planNameLabel;
    private JLabel accountNameLabel;
    private JLabel lastUpdatedLabel;
    private JPanel lastUpdatedPanel;
    private JPanel accountPanel;

    public ProgressionPanel() {
        //for the gui-builder.
        this(new StubbyBigpondUsageInformationBuilder().build());
    }

    public ProgressionPanel(final BigpondUsageInformation usageInfo) {
        this.usageInfo = usageInfo;
        createUIComponents();
    }

    public JPanel getContentPanel() {
        return contentPanel;
    }

    private void createUIComponents() {
        BigpondDisplayDetailsPack detailsPack = new BigpondDisplayDetailsPack(usageInfo);
        contentPanel.add(new RemainderPanel(detailsPack), BorderLayout.CENTER);

        planNameLabel.setForeground(detailsPack.getLimitTextColour());
        planNameLabel.setBackground(detailsPack.getBackgroundColour());
        accountNameLabel.setForeground(detailsPack.getLimitTextColour());
        accountNameLabel.setBackground(detailsPack.getBackgroundColour());
        lastUpdatedLabel.setBackground(detailsPack.getBackgroundColour());
        lastUpdatedLabel.setForeground(detailsPack.getLimitTextColour());
        lastUpdatedPanel.setBackground(detailsPack.getBackgroundColour());
        accountPanel.setBackground(detailsPack.getBackgroundColour());

        planNameLabel.setText(detailsPack.getPlanName());
        accountNameLabel.setText(detailsPack.getAccountName());
        lastUpdatedLabel.setText("8:37 PM");
    }

    {
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
        $$$setupUI$$$();
    }

    /**
     * Method generated by IntelliJ IDEA GUI Designer
     * >>> IMPORTANT!! <<<
     * DO NOT edit this method OR call it in your code!
     *
     * @noinspection ALL
     */
    private void $$$setupUI$$$() {
        contentPanel = new JPanel();
        contentPanel.setLayout(new BorderLayout(0, 0));
        accountPanel = new JPanel();
        accountPanel.setLayout(new GridLayoutManager(1, 3, new Insets(0, 10, 0, 10), -1, -1));
        accountPanel.setBackground(Color.gray);
        accountPanel.setEnabled(true);
        contentPanel.add(accountPanel, BorderLayout.NORTH);
        accountNameLabel = new JLabel();
        accountNameLabel.setBackground(Color.gray);
        accountNameLabel.setFont(new Font("TlwgMono", Font.ITALIC, 12));
        accountNameLabel.setText("Account Name");
        accountPanel.add(accountNameLabel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        final Spacer spacer1 = new Spacer();
        accountPanel.add(spacer1, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false));
        planNameLabel = new JLabel();
        planNameLabel.setFont(new Font("TlwgMono", Font.ITALIC, 12));
        planNameLabel.setHorizontalAlignment(10);
        planNameLabel.setText("Plan Name");
        accountPanel.add(planNameLabel, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        lastUpdatedPanel = new JPanel();
        lastUpdatedPanel.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
        contentPanel.add(lastUpdatedPanel, BorderLayout.SOUTH);
        lastUpdatedLabel = new JLabel();
        lastUpdatedLabel.setFont(new Font("TlwgMono", Font.BOLD, 12));
        lastUpdatedLabel.setText("");
        lastUpdatedPanel.add(lastUpdatedLabel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_NORTH, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
    }

    /**
     * @noinspection ALL
     */
    public JComponent $$$getRootComponent$$$() {
        return contentPanel;
    }
}

@@ -1117,16 +1117,43 @@
 .Insets;
+%0Aimport java.util.Calendar;
 %0A%0Apublic
@@ -1800,24 +1800,202 @@
 nel;%0A    %7D%0A%0A
+    public String getCurrentTime() %7B%0A        return String.format(String.format(%22%251$tA %251$tB %251$te %251$tY @ %251$tl:%251$tM %251$Tp%22, Calendar.getInstance().getTimeInMillis()));%0A    %7D%0A%0A
     private 
@@ -2940,17 +2940,24 @@
 ext(
-%228:37 PM%22
+getCurrentTime()
 );%0A 

Set last updated time.