[12057] | 1 | /**
|
---|
| 2 | *#########################################################################
|
---|
| 3 | *
|
---|
| 4 | * A component of the Gatherer application, part of the Greenstone digital
|
---|
| 5 | * library suite from the New Zealand Digital Library Project at the
|
---|
| 6 | * University of Waikato, New Zealand.
|
---|
| 7 | *
|
---|
| 8 | * Copyright (C) 2006 New Zealand Digital Library Project
|
---|
| 9 | *
|
---|
| 10 | * <BR><BR>
|
---|
| 11 | *
|
---|
| 12 | * This program is free software; you can redistribute it and/or modify
|
---|
| 13 | * it under the terms of the GNU General Public License as published by
|
---|
| 14 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 15 | * (at your option) any later version.
|
---|
| 16 | *
|
---|
| 17 | * <BR><BR>
|
---|
| 18 | *
|
---|
| 19 | * This program is distributed in the hope that it will be useful,
|
---|
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 22 | * GNU General Public License for more details.
|
---|
| 23 | *
|
---|
| 24 | * <BR><BR>
|
---|
| 25 | *
|
---|
| 26 | * You should have received a copy of the GNU General Public License
|
---|
| 27 | * along with this program; if not, write to the Free Software
|
---|
| 28 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 29 | *########################################################################
|
---|
| 30 | */
|
---|
| 31 | package org.greenstone.gatherer.gui;
|
---|
| 32 |
|
---|
| 33 | import java.awt.*;
|
---|
| 34 | import java.awt.event.*;
|
---|
| 35 | import javax.swing.*;
|
---|
| 36 | import org.greenstone.gatherer.Configuration;
|
---|
| 37 | import org.greenstone.gatherer.Gatherer;
|
---|
| 38 | import org.greenstone.gatherer.collection.Collection;
|
---|
[13592] | 39 | import org.greenstone.gatherer.greenstone.LocalLibraryServer;
|
---|
[12057] | 40 | import org.greenstone.gatherer.util.StaticStrings;
|
---|
| 41 |
|
---|
| 42 |
|
---|
| 43 | public class PreviewButton
|
---|
| 44 | extends GLIButton {
|
---|
| 45 |
|
---|
| 46 |
|
---|
| 47 | static final public int HOME_PAGE = 1;
|
---|
| 48 | static final public int SEARCH_PAGE = 2;
|
---|
| 49 | static final public int CLASSIFIER_PAGE = 3;
|
---|
| 50 | static final public int DOCUMENT_PAGE = 4;
|
---|
| 51 |
|
---|
| 52 | private String preview_address;
|
---|
| 53 | private int page_type = HOME_PAGE;
|
---|
| 54 | private boolean variable_preview = false;
|
---|
| 55 |
|
---|
| 56 | private PreviewButtonOwner owner = null;
|
---|
| 57 | public PreviewButton() {
|
---|
| 58 | super();
|
---|
| 59 | PreviewButtonListener pbl = new PreviewButtonListener();
|
---|
| 60 | addActionListener(pbl);
|
---|
| 61 | }
|
---|
[12116] | 62 | public PreviewButton(String text, String tooltip) {
|
---|
| 63 | super(text, tooltip);
|
---|
| 64 | PreviewButtonListener pbl = new PreviewButtonListener();
|
---|
| 65 | addActionListener(pbl);
|
---|
| 66 | }
|
---|
[12057] | 67 |
|
---|
| 68 | public void setOwner(PreviewButtonOwner o) {
|
---|
| 69 | owner = o;
|
---|
| 70 | }
|
---|
| 71 | public void setVariablePreview(boolean vp) {
|
---|
| 72 | variable_preview = vp;
|
---|
| 73 | }
|
---|
| 74 | protected void configureHomeURL() {
|
---|
| 75 | // set up the home page for the current collection
|
---|
| 76 | Collection current_collection = Gatherer.c_man.getCollection();
|
---|
| 77 | if (Gatherer.GS3) {
|
---|
| 78 | // don't do anything fancy here
|
---|
| 79 | preview_address = Configuration.library_url.toString() + Configuration.getServletPath()+ "?a=p&sa=about&c=" + current_collection.getName()+"&l="+Configuration.getLanguage();
|
---|
| 80 | return;
|
---|
| 81 | }
|
---|
| 82 | preview_address = Configuration.library_url.toString()+"?c="+current_collection.getName()+"&l="+Configuration.getLanguage();
|
---|
| 83 |
|
---|
| 84 | String main_args = "&a=p&p=about";
|
---|
| 85 | /* this code is for switching the preview page depending on what
|
---|
| 86 | is currently active. but it is not complete yet
|
---|
| 87 | String main_args = null;
|
---|
| 88 | String params = null;
|
---|
| 89 | if (!variable_preview || owner == null) {
|
---|
| 90 | main_args = "&a=p&p=about";
|
---|
| 91 | } else {
|
---|
| 92 | page_type = owner.getPageType();
|
---|
| 93 | params = owner.getPageParams();
|
---|
| 94 |
|
---|
| 95 | switch (page_type) {
|
---|
| 96 | case SEARCH_PAGE:
|
---|
| 97 | main_args = "&a=q&q="+params;
|
---|
| 98 | break;
|
---|
| 99 | case CLASSIFIER_PAGE:
|
---|
| 100 | main_args = "&a=d&cl="+params;
|
---|
| 101 | break;
|
---|
| 102 | case DOCUMENT_PAGE:
|
---|
| 103 | main_args = "&a=d&d="+params;
|
---|
| 104 | break;
|
---|
| 105 | case HOME_PAGE:
|
---|
| 106 | default:
|
---|
| 107 | main_args = "&a=p&p=about";
|
---|
| 108 |
|
---|
| 109 |
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 |
|
---|
| 113 | }
|
---|
| 114 | */
|
---|
| 115 | preview_address += main_args+StaticStrings.TIMESTAMP_ARGUMENT + System.currentTimeMillis();
|
---|
| 116 |
|
---|
| 117 | }
|
---|
| 118 | private class PreviewButtonListener
|
---|
| 119 | implements ActionListener {
|
---|
| 120 |
|
---|
| 121 | public void actionPerformed(ActionEvent event) {
|
---|
[12805] | 122 | Gatherer.c_man.saveCollection();
|
---|
[12057] | 123 |
|
---|
| 124 | configureHomeURL();
|
---|
| 125 | // check that the local library server is still running - doesn't do anything if its not supposed to be running
|
---|
[13592] | 126 | // !! Don't like this here
|
---|
[12057] | 127 | LocalLibraryServer.checkServerRunning();
|
---|
| 128 |
|
---|
| 129 | Gatherer.spawnBrowser(preview_address);
|
---|
| 130 |
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | }
|
---|