All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.publicobject.issuesbrowser.swing.IssueDetailsComponent Maven / Gradle / Ivy

/* Glazed Lists                                                 (c) 2003-2006 */
/* http://publicobject.com/glazedlists/                      publicobject.com,*/
/*                                                     O'Dell Engineering Ltd.*/
package com.publicobject.issuesbrowser.swing;

import ca.odell.glazedlists.EventList;
import com.publicobject.issuesbrowser.Issue;

import javax.swing.*;
import java.awt.*;

/**
 * This component simply delegates between two other subcomponents. When
 * no issues are selected, summary charts are shown in the details section.
 * When a selection does exist, the details of the selected Issue are shown
 * in the details section.
 *
 * @author James Lemieux
 */
class IssueDetailsComponent extends JComponent {

    /** Shown when an Issue is selected. */
    private final IssueDescriptionsPanel issueDetailComponent;

    /** Shown when no Issue is selected. */
    private final IssueSummaryChartsComponent issueSummaryChartsComponent;

    /**
     * Display details for the given issuesList.
     */
    public IssueDetailsComponent(EventList issuesList) {
        this.issueDetailComponent = new IssueDescriptionsPanel();
        this.issueSummaryChartsComponent = new IssueSummaryChartsComponent(issuesList);

        this.setLayout(new BorderLayout());
        // initially there is no selection so show the chart component
        this.showDetailComponent(this.issueSummaryChartsComponent.getComponent());
    }

    /**
     * If issue is null then summary charts are displayed
     * summarizing the current list of Issues. Otherwise, details of the given
     * issue are displayed.
     *
     * @param issue the newly selected Issue or null
     *      if the issue selection was cleared
     */
    public void setIssue(Issue issue) {
        if (issue != null) {
            this.showDetailComponent(this.issueDetailComponent.getComponent());
            this.issueDetailComponent.setIssue(issue);
        } else {
            this.showDetailComponent(this.issueSummaryChartsComponent.getComponent());
        }
    }

    /**
     * A helper method to display a given detailComponent within
     * this component.
     */
    private void showDetailComponent(JComponent detailComponent) {
        if (this.getComponentCount() == 0 || this.getComponent(0) != detailComponent) {
            this.removeAll();
            this.add(detailComponent, BorderLayout.CENTER);
            this.validate();
            this.repaint();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy