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.apache.commons.logging.*;
032: import org.wafer.weblog.om.*;
033: import org.wafer.weblog.servlet.*;
034:
035: public class Home extends ApplicationFrame {
036: private final class ViewCommentsAction implements ActionListener {
037: private Story story;
038:
039: public ViewCommentsAction(Story aStory) {
040: story = aStory;
041: }
042:
043: public void actionPerformed(ActionEvent e) {
044: WosFramework.showChildWindow(Home.this ,
045: new StoryViewWindow(story));
046: WosFramework.hide(Home.this );
047: }
048: }
049:
050: public Home() {
051: initialize();
052: }
053:
054: protected JComponent createBody() {
055: JPanel newBody = new JPanel();
056: newBody.setName("body");
057:
058: String lf = (String) WosFramework.getSessionContext().get(
059: "lookandfeel");
060: String bodyLook = lf != null && lf.equals("aqua") ? "Aqua.body"
061: : "Home";
062:
063: if (WosFramework.isActive())
064: newBody.setLayout(new PropagateTemplateLayoutByName(
065: WosFramework
066: .getKeyPositionTemplateForName(bodyLook)));
067: else
068: newBody.setLayout(new BorderLayout());
069:
070: JButton addStoryButton = new JButton("Add story");
071: addStoryButton.setName("addStoryButton");
072: addStoryButton.setBackground(new Color(0xD1, 0xDC, 0xEB));
073: addStoryButton.addActionListener(new ActionListener() {
074: public void actionPerformed(ActionEvent e) {
075: AddStoryView addStoryDialog = new AddStoryView();
076: addStoryDialog.setModal(true);
077: WosFramework.showAndExecute(Home.this , addStoryDialog,
078: "afterStoryAdd");
079: }
080: });
081:
082: JPanel storiesPanel = new JPanel();
083: storiesPanel.setName("storiesPanel");
084: storiesPanel.setLayout(new GridLayout(0, 1));
085:
086: newBody.add(addStoryButton, BorderLayout.NORTH);
087:
088: JScrollPane scrollPanel = new JScrollPane();
089: scrollPanel.setViewportView(storiesPanel);
090: newBody.add(scrollPanel, BorderLayout.CENTER);
091:
092: List stories = getRecentStories();
093: for (Iterator i = stories.iterator(); i.hasNext();) {
094: JPanel storyPanel = new JPanel(new BorderLayout());
095: storyPanel.setName("storyPanel");
096:
097: Story story = ((Story) i.next());
098:
099: StoryPanel storyView = new StoryPanel(story);
100: storyView.setName("story");
101:
102: JButton viewCommentsButton = new JButton("View Comments");
103: viewCommentsButton.setName("viewCommentsButton");
104: viewCommentsButton
105: .addActionListener(new ViewCommentsAction(story));
106: viewCommentsButton
107: .setBackground(new Color(0xD1, 0xDC, 0xEB));
108:
109: JButton addCommentButton = new JButton("Add Comment");
110: addCommentButton.setName("addCommentButton");
111: addCommentButton
112: .addActionListener(new AddStoryCommentAction(this ,
113: story));
114: addCommentButton.setBackground(new Color(0xD1, 0xDC, 0xEB));
115:
116: storyPanel.add(storyView, BorderLayout.NORTH);
117: storyPanel.add(viewCommentsButton, BorderLayout.WEST);
118: storyPanel.add(addCommentButton, BorderLayout.CENTER);
119:
120: storiesPanel.add(storyPanel);
121: }
122:
123: return newBody;
124: }
125:
126: public void afterAddComment(AddCommentView aView) {
127: initialize();
128: }
129:
130: public void afterStoryAdd(AddStoryView aView) {
131: initialize();
132: }
133:
134: private List getRecentStories() {
135: try {
136: StoryStore storyStore = WebLogSystem.getStoryStore();
137: return storyStore.getRecentStories(6);
138: } catch (Exception e) {
139: LogFactory.getLog(Home.class).error(
140: "Cannot get recent stories", e);
141: throw new NestableRuntimeException(e);
142: }
143: }
144:
145: public static void main(String[] args) throws Exception {
146: Home home = new Home();
147: home.setVisible(true);
148: }
149:
150: }
|