Package org.jriaffe.blog

Source Code of org.jriaffe.blog.LicensePanel

/*
*
* 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.client.NotificationCenter;
import jriaffe.client.ui.components.ApplicationWindow;
import jriaffe.client.ui.components.PositionLayout;

import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* Created by IntelliJ IDEA.
* User: preisler
* Date: 4/21/11
* Time: 9:59 PM
*/
public class LicensePanel extends JPanel {

    NotificationCenter notify = NotificationCenter.getDefaultNotificationCenter();
    public static final String LICENSE_DECISION = "LICENCE_DECISION";

      public LicensePanel (URL licenseURL, boolean showButtons, boolean resizeWindow) {
          setLayout(new PositionLayout(new Dimension(10,10)));
          setOpaque(false);

          JTextPane description = new JTextPane();

          if (licenseURL != null) {
              try {
                  description.setPage(licenseURL);
              } catch (IOException ex) {
                  Logger.getLogger(LicensePanel.class.getName()).log(Level.SEVERE, null, ex);
                  System.exit(0);
              }
              //description.setPreferredSize(new Dimension(600,400));
          } else {
              Logger.getLogger(LicensePanel.class.getName()).log(Level.SEVERE, "Could not load license agreement");
              System.exit(0);
          }

          JScrollPane scrollPane = new JScrollPane();
          scrollPane.setViewportView(description);
          scrollPane.setPreferredSize(new Dimension(600, 400));
          add(scrollPane);

          if (showButtons) {
              JButton acceptButton = new JButton("I have read and accept the License.");
              acceptButton.setName("acceptButton");
              JButton rejectButton = new JButton("I do not accept the License.");
              rejectButton.setName("rejectButton");
              add(acceptButton);
              add(rejectButton);
          }

          Dimension d = this.getPreferredSize();
          d.setSize(d.getWidth() + 30, d.getHeight());
          if (resizeWindow) {
            notify.postNotification(ApplicationWindow.SET_WINDOW_SIZE, d);
          }
      }

      public String getPageTitle() {
          return "License Agreement";
      }

      public Object getEventHandler() {
          return this;
      }

      public void clickRejectButton() {
          accepted = false;
          notify.postNotification(LICENSE_DECISION, this);
          System.exit(0);
      }

      public void clickAcceptButton() {
          accepted = true;
          notify.postNotification(LICENSE_DECISION, this);
          SplashPanel view = new SplashPanel();
          notify.postNotification(ApplicationWindow.NOTIFY_ADD_PAGE, view);
          notify.postNotification(ApplicationWindow.NOTIFY_CLOSE_PAGE, this);
          notify.postNotification(ApplicationWindow.CHANGE_MAIN_PANEL, view);
      }

      public boolean getDecision() {
        return accepted;
      }

    private boolean accepted = false;
  }
TOP

Related Classes of org.jriaffe.blog.LicensePanel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.