1 /******************************************************************************* 2 * Copyright (c) 2010 - 2013 by Timotei Dolean <timotei21@gmail.com> 3 * 4 * This program and the accompanying materials are made available 5 * under the terms of the Eclipse Public License v1.0 6 * which accompanies this distribution, and is available at 7 * http://www.eclipse.org/legal/epl-v10.html 8 *******************************************************************************/ 9 package org.wesnoth.wizards.campaign; 10 11 import org.eclipse.swt.SWT; 12 import org.eclipse.swt.events.ModifyEvent; 13 import org.eclipse.swt.events.ModifyListener; 14 import org.eclipse.swt.layout.GridData; 15 import org.eclipse.swt.layout.GridLayout; 16 import org.eclipse.swt.widgets.Button; 17 import org.eclipse.swt.widgets.Composite; 18 import org.eclipse.swt.widgets.Label; 19 import org.eclipse.swt.widgets.Text; 20 21 import org.wesnoth.Messages; 22 import org.wesnoth.wizards.WizardPageTemplate; 23 24 /** 25 * Page 1 for the New Campaign Wizard 26 */ 27 public class CampaignPage1 extends WizardPageTemplate 28 { 29 private Text txtCampaignName_; 30 private Text txtVersion_; 31 private Text txtTranslationDir_; 32 private Text txtAuthor_; 33 private Text txtEmail_; 34 private Text txtDescription_; 35 private Text txtPassphrase_; 36 private Text txtIcon_; 37 private Button chkMultiCampaign_; 38 private Button chkGeneratePBL_; 39 40 /** 41 * Creates a new {@link CampaignPage1} 42 */ CampaignPage1( )43 public CampaignPage1( ) 44 { 45 super( "campaignPage1" ); //$NON-NLS-1$ 46 setTitle( Messages.CampaignPage1_1 ); 47 setDescription( Messages.CampaignPage1_2 ); 48 setPageComplete( false ); 49 } 50 51 @Override createControl( Composite parent )52 public void createControl( Composite parent ) 53 { 54 super.createControl( parent ); 55 Composite container = new Composite( parent, SWT.NULL ); 56 57 setControl( container ); 58 ModifyListener updatePageCompleteListener = new ModifyListener( ) { 59 @Override 60 public void modifyText( ModifyEvent e ) 61 { 62 updateIsPageComplete( ); 63 } 64 }; 65 container.setLayout( new GridLayout( 3, false ) ); 66 67 Label _lblCampaignName = new Label( container, SWT.NONE ); 68 _lblCampaignName.setText( Messages.CampaignPage1_3 ); 69 70 txtCampaignName_ = new Text( container, SWT.BORDER ); 71 GridData gd_txtCampaignName_ = new GridData( SWT.FILL, SWT.CENTER, 72 false, false, 1, 1 ); 73 gd_txtCampaignName_.heightHint = 15; 74 txtCampaignName_.setLayoutData( gd_txtCampaignName_ ); 75 txtCampaignName_.addModifyListener( updatePageCompleteListener ); 76 new Label( container, SWT.NONE ); 77 78 Label lblVersion = new Label( container, SWT.NONE ); 79 lblVersion.setText( Messages.CampaignPage1_4 ); 80 81 txtVersion_ = new Text( container, SWT.BORDER ); 82 txtVersion_.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, false, 83 false, 1, 1 ) ); 84 txtVersion_.addModifyListener( updatePageCompleteListener ); 85 86 Label lblFormat = new Label( container, SWT.NONE ); 87 lblFormat.setToolTipText( Messages.CampaignPage1_5 ); 88 lblFormat.setText( Messages.CampaignPage1_6 ); 89 90 Label lblTranslationsDir = new Label( container, SWT.NONE ); 91 lblTranslationsDir.setText( Messages.CampaignPage1_7 ); 92 93 txtTranslationDir_ = new Text( container, SWT.BORDER ); 94 txtTranslationDir_.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, 95 false, false, 1, 1 ) ); 96 97 chkMultiCampaign_ = new Button( container, SWT.CHECK ); 98 GridData gd_chkMultiCampaign_ = new GridData( SWT.LEFT, SWT.CENTER, 99 false, false, 2, 1 ); 100 gd_chkMultiCampaign_.widthHint = 236; 101 chkMultiCampaign_.setLayoutData( gd_chkMultiCampaign_ ); 102 chkMultiCampaign_.setText( Messages.CampaignPage1_10 ); 103 new Label( container, SWT.NONE ); 104 105 chkGeneratePBL_ = new Button( container, SWT.CHECK ); 106 chkGeneratePBL_.setLayoutData( new GridData( SWT.LEFT, SWT.CENTER, 107 false, false, 3, 1 ) ); 108 chkGeneratePBL_.setText( Messages.CampaignPage1_11 ); 109 110 Label lblAuthor = new Label( container, SWT.NONE ); 111 lblAuthor.setText( Messages.CampaignPage1_12 ); 112 113 txtAuthor_ = new Text( container, SWT.BORDER ); 114 txtAuthor_.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, false, 115 false, 1, 1 ) ); 116 new Label( container, SWT.NONE ); 117 118 Label lblDescription = new Label( container, SWT.NONE ); 119 lblDescription.setText( Messages.CampaignPage1_13 ); 120 121 txtEmail_ = new Text( container, SWT.BORDER ); 122 txtEmail_.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, false, 123 false, 1, 1 ) ); 124 new Label( container, SWT.NONE ); 125 126 Label lblDescription_1 = new Label( container, SWT.NONE ); 127 lblDescription_1.setText( Messages.CampaignPage1_14 ); 128 129 txtDescription_ = new Text( container, SWT.BORDER ); 130 txtDescription_.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, 131 false, false, 1, 1 ) ); 132 new Label( container, SWT.NONE ); 133 134 Label lblIcon = new Label( container, SWT.NONE ); 135 lblIcon.setText( Messages.CampaignPage1_15 ); 136 137 txtPassphrase_ = new Text( container, SWT.BORDER ); 138 txtPassphrase_.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, 139 false, false, 1, 1 ) ); 140 new Label( container, SWT.NONE ); 141 142 Label lblIcon_1 = new Label( container, SWT.NONE ); 143 lblIcon_1.setText( Messages.CampaignPage1_16 ); 144 145 txtIcon_ = new Text( container, SWT.BORDER ); 146 GridData gd_txtIcon_ = new GridData( SWT.FILL, SWT.CENTER, false, 147 false, 1, 1 ); 148 gd_txtIcon_.widthHint = 163; 149 txtIcon_.setLayoutData( gd_txtIcon_ ); 150 151 Label lblRelativeToThe_1 = new Label( container, SWT.NONE ); 152 GridData gd_lblRelativeToThe_1 = new GridData( SWT.FILL, SWT.CENTER, 153 false, false, 1, 1 ); 154 gd_lblRelativeToThe_1.widthHint = 285; 155 lblRelativeToThe_1.setLayoutData( gd_lblRelativeToThe_1 ); 156 lblRelativeToThe_1.setToolTipText( Messages.CampaignPage1_17 ); 157 lblRelativeToThe_1.setText( Messages.CampaignPage1_18 ); 158 159 updateIsPageComplete( ); 160 } 161 162 /** 163 * Checks the mandatory fields and updates the isPageComplete status 164 */ updateIsPageComplete( )165 public void updateIsPageComplete( ) 166 { 167 setPageComplete( false ); 168 if( txtCampaignName_.getText( ).isEmpty( ) ) { 169 setErrorMessage( Messages.CampaignPage1_19 ); 170 return; 171 } 172 173 // match the pattern x.y.z 174 if( txtVersion_.getText( ).isEmpty( ) 175 || ! ( txtVersion_.getText( ) 176 .matches( "[\\d]+\\.[\\d]+\\.\\d[\\w\\W\\d\\D\\s\\S]*" ) ) ) //$NON-NLS-1$ 177 { 178 setErrorMessage( Messages.CampaignPage1_21 ); 179 return; 180 } 181 182 setErrorMessage( null ); 183 setPageComplete( true ); 184 } 185 186 /** 187 * @return the Campaign Name 188 */ getCampaignName( )189 public String getCampaignName( ) 190 { 191 return txtCampaignName_.getText( ); 192 } 193 194 /** 195 * @return the author 196 */ getAuthor( )197 public String getAuthor( ) 198 { 199 return txtAuthor_.getText( ); 200 } 201 202 /** 203 * @return the version 204 */ getVersion( )205 public String getVersion( ) 206 { 207 return txtVersion_.getText( ); 208 } 209 210 /** 211 * @return the description 212 */ getCampaignDescription( )213 public String getCampaignDescription( ) 214 { 215 return txtDescription_.getText( ); 216 } 217 218 /** 219 * @return the Icon 220 */ getIconPath( )221 public String getIconPath( ) 222 { 223 return txtIcon_.getText( ); 224 } 225 226 /** 227 * @return the email 228 */ getEmail( )229 public String getEmail( ) 230 { 231 return txtEmail_.getText( ); 232 } 233 234 /** 235 * @return the passphrase 236 */ getPassphrase( )237 public String getPassphrase( ) 238 { 239 return txtPassphrase_.getText( ); 240 } 241 242 /** 243 * @return the translation directory 244 */ getTranslationDir( )245 public String getTranslationDir( ) 246 { 247 return txtTranslationDir_.getText( ); 248 } 249 250 /** 251 * @return true if the campaign is multiplayer 252 */ isMultiplayer( )253 public boolean isMultiplayer( ) 254 { 255 return chkMultiCampaign_.getSelection( ); 256 } 257 258 /** 259 * 260 * @return true to create the pbl file 261 */ needsPBLFile( )262 public boolean needsPBLFile( ) 263 { 264 return chkGeneratePBL_.getSelection( ); 265 } 266 } 267