001 /* 002 * This program is free software; you can redistribute it and/or modify 003 * it under the terms of the GNU General Public License as published by 004 * the Free Software Foundation; version 2 of the License. 005 * 006 * This program is distributed in the hope that it will be useful, 007 * but WITHOUT ANY WARRANTY; without even the implied warranty of 008 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 009 * GNU General Public License for more details. 010 * 011 * You should have received a copy of the GNU General Public License along 012 * with this program; if not, write to the Free Software Foundation, Inc., 013 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 014 */ 015 package org.tastybug.bugwerk.bugtrail.widget.composition; 016 017 import java.awt.BorderLayout; 018 import java.awt.Dimension; 019 import java.awt.Font; 020 021 import javax.swing.BorderFactory; 022 import javax.swing.JPanel; 023 import javax.swing.JScrollPane; 024 import javax.swing.border.EtchedBorder; 025 import javax.swing.border.TitledBorder; 026 import javax.swing.event.ListSelectionEvent; 027 import javax.swing.event.ListSelectionListener; 028 029 import org.tastybug.bugwerk.blueprint.model.Ticket; 030 import org.tastybug.bugwerk.blueprint.model.TicketQueue; 031 import org.tastybug.bugwerk.bugtrail.widget.queue.TicketQueueStatisticsTable; 032 import org.tastybug.bugwerk.bugtrail.widget.queue.TicketQueueTable; 033 import org.tastybug.bugwerk.bugtrail.widget.queue.TicketQueueTableModel; 034 import org.tastybug.bugwerk.bugtrail.widget.ticket.TicketDisplayTabPane; 035 036 /** 037 * This pane is a composition of 3 widgets: <code>TicketQueueStatisticsTable</code>, 038 * <code>TicketQueueTable</code> and <code>TicketDisplayTabPane</code> and thus displays 039 * the content of one ticket queue. 040 * <br> 041 * The pane listens for selection events on the tables and propagates the changes 042 * to the other widgets upon necessity. 043 * <br> 044 * To use it, call 045 * <pre> 046 * String projectName = "myProject"; 047 * // obtain the adapter for your project 048 * QueueAdapter adapter = Adapters.getAdapter(projectName); 049 * // create the pane 050 * QueueInspectorPane inspector = new QueueInspectorPane(); 051 * // declare the ticket queue 052 * inspector.connectQueue(adapter.getTicketQueue()); 053 * </pre> 054 * 055 * The layout looks like this: 056 * <pre> 057 * +----------------------------+ 058 * | | 059 * | TicketQueueStatisticsTable | 060 * | | 061 * +----------------------------+ 062 * | | 063 * | TicketQueueTable | 064 * | | 065 * +----------------------------+ 066 * | | 067 * | TicketDisplayTabPane | 068 * | | 069 * | | 070 * | | 071 * +----------------------------+ 072 * </pre> 073 * 074 * <hr> 075 * Copyright 2006 Philipp Bartsch.<br> 076 * <a href="http://www.tastybug.com">www.tastybug.com</a><br> 077 * <hr> 078 * Created on Feb 9, 2006<br> 079 * @author Philipp Bartsch, philipp.bartsch{at}tastybug{dot}com</a> 080 */ 081 public class QueueInspectorPane extends JPanel implements ListSelectionListener { 082 083 /**The <code>serialVersionUID</code>*/ 084 private static final long serialVersionUID = -7305228423069744563L; 085 086 private TicketQueueStatisticsTable table; 087 private TicketQueueTable table2; 088 private TicketDisplayTabPane tabPane1; 089 090 /** 091 * Creates the pane; creates all subwidgets. 092 */ 093 public QueueInspectorPane () { 094 super (new BorderLayout()); 095 096 /* 097 * creates the statistical panel: it lists the number of tickets 098 */ 099 JPanel northernStatisticalPane = new JPanel(new BorderLayout()); 100 northernStatisticalPane.setBorder(BorderFactory.createTitledBorder(new EtchedBorder(EtchedBorder.LOWERED), 101 "Statistics", 102 TitledBorder.DEFAULT_JUSTIFICATION, 103 TitledBorder.DEFAULT_POSITION, 104 new Font("Arial", Font.BOLD, 9))); 105 table = new TicketQueueStatisticsTable(); 106 107 northernStatisticalPane.add(table, BorderLayout.CENTER); 108 109 add(northernStatisticalPane, BorderLayout.NORTH); 110 111 /* 112 * creates the panel for ticket queue table and ticket display 113 */ 114 JPanel centerQueueListPane = new JPanel(new BorderLayout(2,2)); 115 centerQueueListPane.setBorder(BorderFactory.createTitledBorder(new EtchedBorder(EtchedBorder.LOWERED), 116 "Ticket List", 117 TitledBorder.DEFAULT_JUSTIFICATION, 118 TitledBorder.DEFAULT_POSITION, 119 new Font("Arial", Font.BOLD, 9))); 120 /* 121 * ticket queue table (lists the tickets of the queue) 122 */ 123 table2 = new TicketQueueTable(); 124 table2.getSelectionModel().addListSelectionListener(this); 125 JScrollPane scroller = new JScrollPane(table2); 126 table2.setPreferredScrollableViewportSize(new Dimension(400, 70)); 127 centerQueueListPane.add(scroller, BorderLayout.CENTER); 128 129 // 130 tabPane1 = new TicketDisplayTabPane(new Dimension(400, 150)); 131 centerQueueListPane.add(tabPane1, BorderLayout.SOUTH); 132 133 add(centerQueueListPane, BorderLayout.CENTER); 134 } 135 136 /** 137 * Declares the queue that is to be displayed. 138 * 139 * @param queue the queue 140 */ 141 public void setQueue(TicketQueue queue) { 142 143 table.connectQueue(queue); 144 table2.connectQueue(queue); 145 } 146 147 /** 148 * Propagates the selection changes between the different widgets (e.g. selecting a 149 * ticket in the ticket queue table results in the display of the ticket in ticket display table). 150 * 151 * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent) 152 */ 153 public void valueChanged(ListSelectionEvent e) { 154 // ich geh mal davon aus, das es der TicketQueueTable ist, der sich hier meldet 155 156 // erst dann den event annehmen, wenns der letzte ist der reihe der events ist. 157 // bsp: wird reihe 1 deselektiert und reihe 2 selektiert, interessiert mich nur der 158 // event bez. reihe 2 159 if (!e.getValueIsAdjusting()) { 160 Ticket ticket; 161 if (table2.getSelectionModel().isSelectedIndex(e.getFirstIndex())) { 162 ticket = ((TicketQueueTableModel)table2.getModel()).getTicketAt(e.getFirstIndex()); 163 } else if (table2.getSelectionModel().isSelectedIndex(e.getLastIndex())) { 164 ticket = ((TicketQueueTableModel)table2.getModel()).getTicketAt(e.getLastIndex()); 165 } else { 166 ticket = null; 167 } 168 tabPane1.setTicket(ticket); 169 } 170 } 171 }