/*
*
* Copyright 2012 Chad Preisler
*
* This file is part of jriaffeBlog.
*
* jriaffeBlog is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* jriaffeBlog is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with jriaffeBlog. If not, see <http://www.gnu.org/licenses/>.
*
*/
package org.jriaffe.blog;
import jriaffe.bind.Binder;
import jriaffe.client.NotificationCenter;
import jriaffe.client.ui.components.*;
import org.jriaffe.blog.dialogs.PublishDialogDelegate;
import org.jriaffe.blog.dialogs.SimpleDialog;
import org.jriaffe.blog.domain.Blog;
import org.jriaffe.blog.panels.BlogEntryPanel;
import org.jriaffe.blog.panels.BlogPropertyOverlay;
import org.jriaffe.blog.panels.EntriesViewPanel;
import org.jriaffe.blog.WindowStyle;
import org.jriaffe.blog.service.BlogService;
import javax.swing.*;
import java.awt.*;
/**
* Created by IntelliJ IDEA.
* User: preisler
* Date: 4/23/11
* Time: 12:06 PM
*
* Main panel that holds blog entry panel left menu bar.
*/
public class BlogPanel extends JPanel {
private static NotificationCenter notify = NotificationCenter.getDefaultNotificationCenter();
public static String BLOG_PANEL_CLICKED = "blogPanelClicked";
public static String CLOSE_CURRENT_POPUP = "closeCurrentPopupPanel";
public static BlogPanel init(Blog blog) {
BlogPanel panel = new BlogPanel(blog);
panel.registerListeners();
return panel;
}
public BlogPanel(Blog blog) {
setOpaque(false);
this.blog = blog;
this.entryPanel = new BlogEntryPanel(this.blog, leftPanel.getPreferredSize().getWidth());
try {
notify.addObserver(this.entryPanel, "blogEntryDeleted", BlogService.BLOG_ENTRY_DELETED, null);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
FormLayout layout = new FormLayout();
setLayout(layout);
FormLayoutConstraints leftConstraint = new FormLayoutConstraints();
leftConstraint.setZone(FormLayoutConstraints.Zone.WEST);
BindUtility.bindPanel(leftPanel);
this.add(leftPanel);
BindUtility.bindPanel(entryPanel);
add(entryPanel);
}
public void registerListeners() {
try {
notify.addObserver(this, "appWindowResized", ApplicationWindow.NOTIFY_WINDOW_RESIZED, null);
notify.addObserver(this, "currentPanelClosed", EntriesViewPanel.ENTRIES_VIEW_PANEL_CLOSED, null);
notify.addObserver(this, "closeCurrentPopupPanel", CLOSE_CURRENT_POPUP, null);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
public Object getEventHandler() {
return this;
}
public void init(Binder binder) {
}
public String getPageTitle() {
return blog.getTitle();
}
//left panel handlers
public void clickNewEntry() {
//TODO: add a dialog to save current entry before doing new entry
entryPanel.newEntry();
}
public void closeCurrentPopupPanel(String message, Object o) {
if (currentPopupPanel != null) {
notify.postNotification(ApplicationWindow.NOTIFY_REMOVE_POPUP, currentPopupPanel.getContent());
currentPopupPanel = null;
}
}
public void currentPanelClosed(String message, Object o) {
if (currentPopupPanel != null && o == currentPopupPanel.getContent()) {
currentPopupPanel = null;
}
}
public void clickPublish() {
Object dialog = SimpleDialog.init(new PublishDialogDelegate(blog));
notify.postNotification(ApplicationWindow.NOTIFY_DISPLAY_POPUP, dialog);
}
public void clickEntries() {
closeCurrentPopupPanel("", null);
EntriesViewPanel entriesView = EntriesViewPanel.initPanel(blog);
PopupPanel panel = PopupPanel.initPlainPanel(entriesView);
currentPopupPanel = panel;
WindowUtilities.displayPopup(panel, PanelAnimator.Style.SLIDE_RIGHT, leftPanel.getWidth(), 2, 200);
}
public void clickThemeSettings() {
System.out.println("Theme Settings");
}
public void clickBlogSettings() {
closeCurrentPopupPanel("", null);
BlogPropertyOverlay blogPropertyPanel = BlogPropertyOverlay.init(blog);
PopupPanel panel = PopupPanel.initPlainPanel(blogPropertyPanel);
currentPopupPanel = panel;
WindowUtilities.displayPopup(panel, PanelAnimator.Style.SLIDE_RIGHT, leftPanel.getWidth(), 2, 300);
}
public void appWindowResized(String message, Object o) {
leftPanel.windowResized();
entryPanel.windowResized();
leftPanel.revalidate();
entryPanel.revalidate();
notify.postNotification(ApplicationWindow.NOTIFY_REDRAW_CONTENT, this);
}
public void onDisplay() {
entryPanel.onDisplay();
notify.postNotification(ApplicationWindow.SET_WINDOW_CURSOR, Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
private GradientPainter painter = new GradientPainter(WindowStyle.getBlogEntryBackgroundLight(), WindowStyle.getBlogEntryBackgroundDark());
private Blog blog;
private BlogLeftSidePanel leftPanel = new BlogLeftSidePanel(this);
private BlogEntryPanel entryPanel;
private PopupPanel currentPopupPanel;
}