001: // WebOnSwing - Web Application Framework
002: //Copyright (C) 2004 Fernando Damian Petrola
003: //
004: //This library is free software; you can redistribute it and/or
005: //modify it under the terms of the GNU Lesser General Public
006: //License as published by the Free Software Foundation; either
007: //version 2.1 of the License, or (at your option) any later version.
008: //
009: //This library is distributed in the hope that it will be useful,
010: //but WITHOUT ANY WARRANTY; without even the implied warranty of
011: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: //Lesser General Public License for more details.
013: //
014: //You should have received a copy of the GNU Lesser General Public
015: //License along with this library; if not, write to the Free Software
016: //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017:
018: package weblog;
019:
020: import java.awt.*;
021: import java.awt.event.*;
022: import java.util.*;
023: import java.util.List;
024:
025: import javax.swing.*;
026:
027: import net.ar.webonswing.*;
028: import net.ar.webonswing.swing.layouts.*;
029:
030: import org.apache.commons.lang.exception.*;
031: import org.wafer.weblog.om.*;
032: import org.wafer.weblog.servlet.*;
033: import org.wafer.weblog.util.*;
034:
035: import weblog.contributors.*;
036:
037: public class CompleteStoryPanel extends JPanel {
038: private Story story;
039:
040: public CompleteStoryPanel() {
041: WosFramework.assignContributor(this ,
042: StoryPanelContributor.class);
043: }
044:
045: public CompleteStoryPanel(Story aStory) {
046: this ();
047: story = aStory;
048: initialize();
049: }
050:
051: public void initialize() {
052: setLayout(new BorderLayout());
053: removeAll();
054:
055: StoryPanel storyShortView = new StoryPanel(story);
056: storyShortView.setName("story");
057: storyShortView.setPreferredSize(new Dimension(400, 40));
058:
059: JButton addCommentButton = new JButton("Add comment");
060: addCommentButton.addActionListener(new AddStoryCommentAction(
061: getTopLevelAncestor(), story));
062: addCommentButton.setName("addCommentButton");
063: addCommentButton.setBackground(new Color(0xD1, 0xDC, 0xEB));
064:
065: JPanel commentsPanel = new JPanel(new GridLayout(0, 1));
066: commentsPanel.setName("commentsPanel");
067:
068: JPanel topPanel = new JPanel(new BorderLayout());
069: topPanel.add(storyShortView, BorderLayout.NORTH);
070: topPanel.add(addCommentButton, BorderLayout.SOUTH);
071: topPanel.setName("topPanel");
072:
073: add(topPanel, BorderLayout.NORTH);
074:
075: JScrollPane sp = new JScrollPane();
076: sp.setViewportView(commentsPanel);
077: sp.setPreferredSize(new Dimension(640, 300));
078: add(sp, BorderLayout.CENTER);
079:
080: List comments = getStoryComments();
081:
082: for (Iterator i = comments.iterator(); i.hasNext();) {
083: JPanel commentPanel = new JPanel(new BorderLayout());
084: commentPanel.setName("commentPanel");
085:
086: final Comment comment = (Comment) i.next();
087:
088: CommentPanel commentView = new CommentPanel(comment);
089: commentView.setName("commentView");
090: commentPanel.add(commentView);
091:
092: JButton replyButton = new JButton("Reply");
093: replyButton.setName("replyButton");
094: replyButton.setBackground(new Color(0xD1, 0xDC, 0xEB));
095: replyButton.addActionListener(new ActionListener() {
096: public void actionPerformed(ActionEvent arg0) {
097: ReplyCommentView replyComment = new ReplyCommentView(
098: comment);
099: replyComment.setModal(true);
100: WosFramework.showAndExecute(getTopLevelAncestor(),
101: replyComment, "afterReply");
102: }
103: });
104:
105: commentsPanel.add(commentPanel, BorderLayout.NORTH);
106: commentPanel.add(replyButton, BorderLayout.SOUTH);
107: }
108:
109: String bodyLook = WosFramework.getSessionContext().get(
110: "lookandfeel").equals("flat") ? "StoryView"
111: : "StoryViewAqua";
112:
113: if (WosFramework.isActive())
114: setLayout(new PropagateTemplateLayoutByName(WosFramework
115: .getKeyPositionTemplateForName(bodyLook)));
116: }
117:
118: private List getStoryComments() {
119: try {
120: return WebLogSystem.getCommentStore()
121: .getCommentsForStory(story.getId(),
122: WebLogConstants.SETTING_MAX_COMMENTS);
123: } catch (Exception e) {
124: throw new NestableRuntimeException(e);
125: }
126: }
127:
128: public Story getStory() {
129: return story;
130: }
131:
132: public void setStory(Story aStory) {
133: story = aStory;
134: }
135: }
|