/* * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, * CA 95054 USA or visit www.sun.com if you need additional information or * have any questions. * */ package gchisto.gui.utils; import gchisto.utils.errorchecking.ArgumentChecking; import javax.swing.JPanel; /** * A convenience class that associates a panel with a title. It is designed to * be used for charts that are included in tabbed panes. This way, the chart * title, needed when adding the chart to a tabbed pane, is immediately * available.cd * * @author Tony Printezis * @see javax.swing.JPanel */ abstract public class AbstractChartPanel extends javax.swing.JPanel { /** * The title of the panel. */ private String title; /** * The optional unit name of the data shown in the panel. If it is * <tt>null</tt>, the unit name is ignored. */ private String unitName; /** * It returns the title of the panel which optionally has the unit name * as its suffix. * * @return The title of the panel. */ public String getTitle() { return title + unitSuffix(); } /** * It returns the optional suffix of the title, which includes the * unit name in round brackets. If the unitName name is <tt>null</tt>, * it returns an empty string. * * @return The title suffix, or an empty string if the unitName name * is <tt>null</tt>. */ public String unitSuffix() { return (unitName != null) ? " (" + unitName + ")" : ""; } /** * It returns the panel it which the chart should be added. The layout * of the panel is <tt>BorderLayout</tt>. * * @return The panel in which the chart should be added. * * @see java.awt.BorderLayout */ protected JPanel mainPanel() { return mainPanel; } /** * It creates a new instance of the chart panel and associates with * it the given title and no unit name. * * @param title The title to be associated with the new chart panel. */ protected AbstractChartPanel(String title) { this(title, null); } /** * It creates a new instance of the chart panel and associates with * it the given title and unit name. * * @param title The title to be associated with the new chart panel. * @param unitName The unit name to be associated with the new chart panel. */ protected AbstractChartPanel(String title, String unitName) { ArgumentChecking.notNull(title, "title"); initComponents(); this.title = title; this.unitName = unitName; } /** * Private constructor with no arguments so that it is not called. */ private AbstractChartPanel() { initComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents private void initComponents() { mainPanel = new javax.swing.JPanel(); mainPanel.setLayout(new java.awt.BorderLayout()); org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(mainPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(mainPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap()) ); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JPanel mainPanel; // End of variables declaration//GEN-END:variables }