/* * [ViaForReceiver.java] * * Summary: Centralised logic that depends on the how the Replicator is delivered. * * Copyright: (c) 2003-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 7.6 2007-07-16 */ package com.mindprod.replicator; import com.mindprod.common18.ST; import com.mindprod.replicatorcommon.ViaCommon; import javax.swing.JFrame; import java.io.Serializable; import static java.lang.System.*; /** * Centralised logic that depends on the how the Replicator is delivered. *

* Distributed to receiver * * @author Roedy Green, Canadian Mind Products * @version 7.6 2007-07-16 * @since 2003-10-22 */ enum ViaForReceiver implements Serializable { /** * gets files from website */ @SuppressWarnings( { "EnumeratedConstantNamingConvention" } ) VIA_WEBSITE( ViaCommon.VIA_WEBSITE, ConfigForReceiver.WEBSITE_ZIP_URL, ConfigForReceiver.AUTHENTICATION.equals( "basic" ), false, false, false, 0, 0 ), /** * gets files from LAN */ @SuppressWarnings( { "EnumeratedConstantNamingConvention" } ) VIA_LAN( ViaCommon.VIA_LAN, ConfigForReceiver.LAN_ZIP_URL, ConfigForReceiver.AUTHENTICATION.equals( "basic" ), false, true, false, 50, 115 ), /** * gets files from website to relay to others. */ @SuppressWarnings( { "EnumeratedConstantNamingConvention" } ) VIA_RELAY( ViaCommon.VIA_RELAY, ConfigForReceiver.WEBSITE_ZIP_URL, ConfigForReceiver.AUTHENTICATION.equals( "basic" ), false, false, true, 0, 75 ), /** * TEST, gets files from sender's staging directory loops back to same machine. */ @SuppressWarnings( { "EnumeratedConstantNamingConvention" } ) VIA_TEST( ViaCommon.VIA_TEST, ConfigForReceiver.SUGGESTED_LAN_ZIP_URL, false, false, false, false, 0, 0 ), /** * CD, gets files from CD. */ @SuppressWarnings( { "EnumeratedConstantNamingConvention" } ) VIA_CD( ViaCommon.VIA_CD, ConfigForReceiver.SUGGESTED_LAN_ZIP_URL, false, true /* may elect to keep copy of zips from cd */, false, false, 0, 75 ); /** * Layout version number. */ private static final long serialVersionUID = 381L; private final String receiverZipURL; /** * corresponding ViaCommon code. */ private final ViaCommon viaCommon; /** * is authentication configurable */ private final boolean isAuthenticationConfigurable; /** * can you configure keep zips?L */ private final boolean isKeepZipsConfigurable; /** * true if can configure the LAN zip url */ private final boolean isLanZipUrlConfigurable; /** * true if user can configure whether should unpacks */ private final boolean isUnpackZipsConfigurable; /** * pixels of extra height for frame */ private final int extraHeight; /** * pixels of extra width for frame */ private final int extraWidth; /** * constructor * * @param viaCommon corresponding common enum * @param receiverZipURL which URL to download zips * @param isAuthenticationConfigurable true if user can configure authentication password * @param isKeepZipsConfigurable true if user configure whether to keep zips * @param isLanZipUrlConfigurable true if user can figure LAN url. * @param isUnpackZipsConfigurable true if user can configure whether to unpack zips. * @param extraWidth extra width pixels needed for frame. * @param extraHeight extra height pixels needed for frame. */ @SuppressWarnings( { "MethodParameterNamingConvention", "UnusedDeclaration" } ) ViaForReceiver( ViaCommon viaCommon, String receiverZipURL, boolean isAuthenticationConfigurable, boolean isKeepZipsConfigurable, boolean isLanZipUrlConfigurable, boolean isUnpackZipsConfigurable, int extraWidth, int extraHeight ) { assert viaCommon != null : "viaCommon null"; this.viaCommon = viaCommon; if ( ST.isEmpty( receiverZipURL ) ) { err.println( "program bug: ViaForReceiver constructor receiverZipURL empty." ); Replicator.die(); } this.receiverZipURL = receiverZipURL; this.isAuthenticationConfigurable = isAuthenticationConfigurable; this.isKeepZipsConfigurable = isKeepZipsConfigurable; this.isLanZipUrlConfigurable = isLanZipUrlConfigurable; this.isUnpackZipsConfigurable = isUnpackZipsConfigurable; this.extraWidth = extraWidth; this.extraHeight = extraHeight; } /** * convert from string to enum form of via. * * @param viaString string form of how client deployed. * * @return enum of how client deployed. */ public static ViaForReceiver valueOfAlias( String viaString ) { return values()[ ViaCommon.valueOfAlias( viaString ).ordinal() ]; } /** * convert via enum to long string description. * * @return long string form of enum */ public String getDescription() { return viaCommon.getDescription(); } /** * get URL to fetch zips. * * @return url to fetch zips. */ public String getReceiverZipURL() { return receiverZipURL; } /** * Is user allowed to key a userid/password? * * @return true if he is allowed to key them. */ public boolean isAuthenticationConfigurable() { return isAuthenticationConfigurable; } /** * Is user allowed to configure whether to keep zips with this via? * * @return true if we are allowed to configure keep zips viaCode */ public boolean isKeepZipsConfigurable() { return isKeepZipsConfigurable; } /** * Is user allowed to key the LAN Zip URL? * * @return true if he is allowed to key it. */ public boolean isLANZipURLConfigurable() { return isLanZipUrlConfigurable; } /** * online vs offline processing. * * @return true if can process zips without an Internet connection. */ @SuppressWarnings( { "BooleanMethodIsAlwaysInverted" } ) public boolean isOfflineAllowed() { return viaCommon.isOfflineAllowed(); } /** * is whether we unpack zips for this via configurable? * * @return true if we unpack zips by default for this viaCode */ public boolean isUnpackZipsConfigurable() { return isUnpackZipsConfigurable; } /** * Set the frame just big enough for the various fields needed for this mode of operation. * * @param theFrame JFrame for the Replicator */ public void setFrameSize( JFrame theFrame ) { // size includes title bar and menu bar final int width = 730 + extraWidth; final int height = 375 /* basic */ + 25 /* for menubar */ + 25 /* for frame */ + extraHeight + ( isAuthenticationConfigurable ? 105 : 0 ); theFrame.setSize( width, height ); } /** * convert via enum to string. * * @return string form of enum. */ public String toString() { return viaCommon.toString(); } }