...
import java.awt.event.ActionListener;
...
import javax.swing.JDialog;
...
public class NewsController {
...
private JDialog viewDialog;
...
private MediaTypeSelectionView mediaTypeSelectionView;
private List<NewsMedia> selectedMediaTypes;
...
...
This method is called to display pie charts when requested by the user.
<code></code>
private void displayPieCharts() {
int[] indices = selectionView.getSelectedNewsMakers();
if (0 == indices.length) {
JOptionPane.showMessageDialog(selectionView, "No newsmaker selected.", "Invalid Selection",
JOptionPane.WARNING_MESSAGE);
} else {
NewsMakerListModel newsMakerListModel = this.newsDataBaseModel.getNewsMakerListModel();
for (int index : indices) {
NewsMakerModel newsMakerModel = newsMakerListModel.get(index);
String newsMakerName = newsMakerModel.getName();
this.selectedMediaTypes = null;
this.mediaTypeSelectionView = new MediaTypeSelectionView();
MediaTypeSelectionListener mediaTypeSelectionListener = new MediaTypeSelectionListener();
this.mediaTypeSelectionView.jbOkay.addActionListener(mediaTypeSelectionListener);
this.mediaTypeSelectionView.jbCancel.addActionListener(mediaTypeSelectionListener);
this.viewDialog = new JDialog(selectionView, newsMakerName, true);
this.viewDialog.add(mediaTypeSelectionView);
this.viewDialog.setResizable(false);
this.viewDialog.pack();
this.viewDialog.setVisible(true);
if (null == this.selectedMediaTypes) {
continue;
}
NewsContent selectedNewsContent = null;
selectedNewsContent = (NewsContent) JOptionPane.showInputDialog(selectionView,
"Graph news stories based on which content?", newsMakerName, JOptionPane.PLAIN_MESSAGE, null,
NewsContent.values(), NewsContent.TOPIC);
if (null == selectedNewsContent) {
continue;
}
NewsMetric selectedNewsMetric = null;
selectedNewsMetric = (NewsMetric) JOptionPane.showInputDialog(selectionView,
"Graph news stories based on which metric?", newsMakerName, JOptionPane.PLAIN_MESSAGE, null,
NewsMetric.values(), NewsMetric.LENGTH);
if (null == selectedNewsMetric) {
continue;
}
PieChartView pieChartView = new PieChartView(newsMakerModel, selectedMediaTypes, selectedNewsContent,
selectedNewsMetric);
newsMakerModel.addActionListener(pieChartView);
}
}
}
...
<code>MediaTypeSelectionListener</code> is an inner class (within
<code>NewsController</code>) to listen for actions from a
<code>MediaTypeSelectionView</code>.
<code></code>
<code></code>
@author
@version
public class MediaTypeSelectionListener implements ActionListener {
The overridden <code>actionPerformed</code> method that does all of
the work.
<code></code>
<code></code><code></code>
<code></code><code></code>
<code></code>
<code></code>
@Override
public void actionPerformed(ActionEvent actionEvent) {
selectedMediaTypes = new LinkedList<NewsMedia>();
if ("OK".equals(actionEvent.getActionCommand())) {
if (mediaTypeSelectionView.jcbNewspaper.isSelected()) {
selectedMediaTypes.add(NewsMedia.NEWSPAPER);
}
if (mediaTypeSelectionView.jcbTVNews.isSelected()) {
selectedMediaTypes.add(NewsMedia.TV);
}
if (mediaTypeSelectionView.jcbOnline.isSelected()) {
selectedMediaTypes.add(NewsMedia.ONLINE);
}
if (null == selectedMediaTypes) {
JOptionPane.showMessageDialog(selectionView, "No media type selected.", "Invalid Selection",
JOptionPane.WARNING_MESSAGE);
}
}
viewDialog.dispose();
}
}
}