1 package org.telscenter.pas.ui.dialog;
2
3 import java.awt.BorderLayout;
4 import java.awt.Font;
5 import java.awt.Point;
6
7 import javax.swing.BorderFactory;
8 import javax.swing.BoxLayout;
9 import javax.swing.ImageIcon;
10 import javax.swing.JButton;
11 import javax.swing.JComponent;
12 import javax.swing.JLabel;
13 import javax.swing.JPanel;
14 import javax.swing.JScrollPane;
15 import javax.swing.SwingUtilities;
16
17 import org.telscenter.pas.beans.IWorkReporter;
18 import org.telscenter.pas.beans.PasActivity;
19 import org.telscenter.pas.beans.PasProject;
20 import org.telscenter.pas.navigation.PasProjectNavigationTaskPanel;
21 import org.telscenter.pas.beans.PasStep;
22 import org.telscenter.pas.common.ui.CommonUI;
23 import org.telscenter.pas.common.ui.layouts.EqualsLayout;
24 import org.telscenter.pas.service.INavigationService;
25 import org.telscenter.pas.service.NavigateAction;
26 import org.telscenter.pas.steps.actions.DialogSaveAction;
27 import org.telscenter.pas.ui.icons.PasCommonIconProvider;
28 import org.telscenter.pas.ui.pdf.actions.GeneratePDFAction;
29 import org.telscenter.pas.ui.util.PasColors;
30
31
32 public class PasShowReportsDialogUI extends PasMessageDialogUI {
33
34 protected PasProject pasProject;
35 protected INavigationService navigationService;
36 private float headerFontSize = 16.0f;
37
38 public PasShowReportsDialogUI() {
39 super();
40
41 }
42
43 public PasShowReportsDialogUI(PasProject pasProject, INavigationService navigationService) {
44 super();
45 this.pasProject = pasProject;
46 this.navigationService = navigationService;
47 }
48
49 protected void addButtonActions() {
50 getOkButton().setAction(new DialogSaveAction("Close"));
51 }
52 public JPanel createDialogPanel() {
53 contentPanel = new JPanel(new BorderLayout(0,0));
54 contentPanel.setBorder(BorderFactory.createLineBorder(PasColors.showReportsContentBorderColor, 2));
55 contentPanel.setBackground(PasColors.showReportsContentPanelBackgroundColor);
56
57 buttonPanel = createButtonPanel();
58
59
60
61 contentPanel.add(createMessagePanel(),BorderLayout.CENTER);
62 contentPanel.add(buttonPanel,BorderLayout.SOUTH);
63 JPanel cp = new JPanel();
64 cp.setLayout(new BorderLayout(0,0));
65 cp.setBackground(PasColors.showReportsBackgroundColor);
66 cp.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
67 cp.add(contentPanel,BorderLayout.CENTER);
68 return cp;
69 }
70 protected void arrangeButtons() {
71 buttonPanel = new JPanel(new EqualsLayout(
72 EqualsLayout.HORIZONTAL, EqualsLayout.RIGHT, 2));
73
74 JButton pdfButton = new JButton(new GeneratePDFAction(new ImageIcon( PasCommonIconProvider.getImage("pdf.gif") ), "Make PDF",pasProject));
75 pdfButton.setToolTipText("Create a PDF file");
76
77 CommonUI.makeEnhancedButton(pdfButton);
78 buttonPanel.add(CommonUI.makeEnhancedButton(pdfButton));
79 buttonPanel.add(okButton);
80 buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 5));
81 buttonPanel.setOpaque(false);
82 }
83
84 protected JComponent createMessagePanel() {
85 JPanel activitiesPanel = new JPanel(new BorderLayout(0,0));
86 activitiesPanel.setLayout(new BoxLayout(activitiesPanel, BoxLayout.Y_AXIS));
87 PasActivity[] activities = pasProject.getActivities();
88 PasProjectNavigationTaskPanel thisPanel = pasProject.getPanel();
89 JPanel activityPanel = null;
90
91 for (int i = 0; i < activities.length; i++) {
92 PasActivity activity = activities[i];
93
94 activityPanel = new JPanel(new BorderLayout(1,1));
95
96 if( activity.getSteps().length > 0) {
97 JLabel actTitle = new JLabel("Activity " + (i + 1) + ": "+ activity.getTitle());
98 actTitle.setFont(actTitle.getFont().deriveFont(Font.BOLD, headerFontSize));
99 actTitle.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
100
101 JPanel titlePanel = new JPanel(new BorderLayout(0,0));
102 titlePanel.add(actTitle,BorderLayout.WEST);
103 titlePanel.setBackground(PasColors.showReportsActivityTitleBackgroundColor);
104 titlePanel.setBorder(BorderFactory.createLineBorder(PasColors.showReportsActivityTitleBorderColor, 1));
105 activityPanel.add(titlePanel,BorderLayout.NORTH);
106 actTitle.setBackground(actTitle.getBackground().brighter());
107 activityPanel.setBackground(PasColors.showReportsActivityBackgroundColor);
108 activityPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 0, 2));
109
110 JPanel stepsPanel = new JPanel();
111 stepsPanel.setLayout(new BoxLayout(stepsPanel, BoxLayout.Y_AXIS));
112
113 PasStep[] steps = activity.getSteps();
114
115 for (int j = 0; j < steps.length; j++) {
116 PasStep step = steps[j];
117
118 if (step instanceof IWorkReporter) {
119 IWorkReporter reporter = (IWorkReporter) step;
120 JPanel reportForLearner = reporter.getReportForLearner(null);
121 reportForLearner.setOpaque(false);
122
123 JButton title = new JButton(new NavigateAction(step, navigationService,thisPanel));
124
125 title.setHorizontalTextPosition(JLabel.LEFT);
126 title.setContentAreaFilled(false);
127 title.setFont(title.getFont().deriveFont(16.0f));
128 title.setBorder(BorderFactory.createEmptyBorder(0, 0, 8, 0));
129 title.setText("Step " + (j + 1) + " : " + title.getText());
130
131 JPanel p = new JPanel(new BorderLayout(0,0));
132 p.add(CommonUI.makeLink(title),BorderLayout.WEST);
133 p.setOpaque(false);
134
135 JPanel stepTitlePanel = createStepTitlePanel(p, reportForLearner);
136 stepsPanel.add(stepTitlePanel);
137 stepsPanel.setBorder(BorderFactory.createEmptyBorder(0, 8, 8, 10));
138 stepsPanel.setOpaque(false);
139
140 }
141 }
142
143 activityPanel.add(stepsPanel,BorderLayout.CENTER);
144 activitiesPanel.add(activityPanel);
145 activitiesPanel.setOpaque(false);
146 }
147 }
148
149 final JScrollPane spane = new JScrollPane(activitiesPanel);
150 spane.setBorder(BorderFactory.createEmptyBorder());
151 spane.setOpaque(false);
152
153
154 SwingUtilities.invokeLater(new Runnable() {
155 public void run() {
156 spane.getViewport().setViewPosition(new Point(0,0));
157 }
158 });
159
160 JPanel p = new JPanel(new BorderLayout(0,0));
161 p.setOpaque(false);
162 p.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
163 p.add(spane,BorderLayout.CENTER);
164
165 return p;
166
167 }
168
169 private JPanel createStepTitlePanel(JPanel p, JPanel reportForLearner){
170 JPanel stepTitlePanel = new JPanel(new BorderLayout(0, 0));
171 stepTitlePanel.setOpaque(false);
172 stepTitlePanel.add(p, BorderLayout.NORTH);
173 stepTitlePanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
174
175 stepTitlePanel.add(new JLabel(" "),BorderLayout.WEST);
176 stepTitlePanel.add(reportForLearner,BorderLayout.CENTER);
177 return stepTitlePanel;
178 }
179 }