Object subclass: #CurrencyConverter instanceVariableNames: 'selection ' classVariableNames: 'Currencies ' poolDictionaries: '' category: 'LMExample'! !CurrencyConverter methodsFor: 'accessing'! findName: aString | coll line | line := Currencies findFirst: [ :el | (el findString: aString) > 0 ]. coll := (Currencies at: line) findTokens: '.'. ^(coll at:1) withBlanksTrimmed.! ! !CurrencyConverter methodsFor: 'accessing' stamp: 'Friedrich 10/1/2003 15:40'! findNameBak: aString | coll line | line := Currencies findFirst: [:el | coll := el findTokens: '.'. (coll at: 2) withBlanksTrimmed = aString]. coll := (Currencies at: line) findTokens: '.'. ^(coll at:1) withBlanksTrimmed.! ! !CurrencyConverter methodsFor: 'accessing' stamp: 'Friedrich 10/2/2003 16:27'! getCurrencyLine: anIndex ^Currencies at: anIndex.! ! !CurrencyConverter methodsFor: 'accessing'! getCurrencyLine: anIndex pos: apos | entry coll | entry := self getCurrencyLine: anIndex. coll := entry findTokens: '.'. pos) withBlanksTrimmed. ! ! !CurrencyConverter methodsFor: 'accessing' stamp: 'Friedrich 10/1/2003 15:10'! getCurrencyName: anIndex ^ self getCurrencyLine: anIndex pos: 1.! ! !CurrencyConverter methodsFor: 'accessing'! getCurrencySymbol: anIndex ^ self getCurrencyLine: anIndex pos: 2 ! ! !CurrencyConverter methodsFor: 'creation'! initialize CurrencyConverter initializeClassVariables. ! ! !CurrencyConverter methodsFor: 'as yet unclassified' stamp: 'Friedrich 10/2/2003 08:24'! buildDateForToday | today | today := Date today. ^today printFormat: #(1 2 3 $. 1 1 2) ! ! !CurrencyConverter methodsFor: 'as yet unclassified'! buildQueryFrom: from to: to howMuch: amount date: date | result | result := 'http://www.oanda.com/convert/classic?user=printable&exch=', (from asString), '&value=', (amount asString), '&expr=', (to asString), '&date_fmt=normal&date=', (date asString), '&lang=en'. ^result.! ! 03 10:42'! calculateExchangeFrom: from to: to amount: amount "Workhorse, queries a server for the current exchange rate of today, and checks the returned string." | query result content date match | date := self buildDateForToday. query := self buildQueryFrom: from to: to howMuch: amount date: date. match := (amount asString), ' ', (self findName: from) asString, ' = [0-9\.]+ ', (self findName: to) asString. content := self runQuery: query. result := (content reMatch: match) match. ^result. ! ! !CurrencyConverter methodsFor: 'as yet unclassified'! runQuery: aQuery | result | result := (HTTPSocket httpGet: aQuery) contents. ^result.! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! CurrencyConverter class instanceVariableNames: ''! !CurrencyConverter class methodsFor: 'as yet unclassified' stamp: 'Friedrich 10/1/2003 13:08'! currencies ^ Currencies.! ! !CurrencyConverter class methodsFor: 'as yet unclassified'! initializeClassVariables rom: { 'Afghanistan Afghani . AFA'. 'Albanian Lek . ALL'. 'Algerian Dinar . DZD'. 'Andorran Franc . ADF'. 'Andorran Peseta . ADP'. 'Angolan New Kwanza . AON'. 'Argentine Peso . ARS'. 'Aruban Florin . AWG'. 'Australian Dollar . AUD'. 'Austrian Schilling . ATS'. 'Bahamanian Dollar . BSD'. 'Bahraini Dinar . BHD'. 'Bangladeshi Taka . BDT'. 'Barbados Dollar . BBD'. 'Belgian Franc . BEF'. 'Belize Dollar . BZD'. 'Bermudian Dollar . BMD'. 'Bhutan Ngultrum . BTN'. 'Bolivian Boliviano . BOB'. 'Botswana Pula . BWP'. 'Brazilian Real . BRL'. 'British Pound . GBP'. 'Brunei Dollar . BND'. 'Bulgarian Lev . BGL'. 'Burundi Franc . BIF'. 'CFA Franc BCEAO . XOF'. 'CFA Franc BEAC . XAF'. 'CFP Franc . XPF'. 'Cambodian Riel . KHR'. 'Canadian Dollar . CAD'. 'Cape Verde Escudo . CVE'. 'Cayman Islands Dollar . KYD'. 'Chilean Peso . CLP'. 'Chinese Yuan Renminbi . CNY'. 'Colombian Peso . COP'. 'Comoros Franc . KMF'. 'Costa Rican Colon . CRC'. 'Croatian Kuna . HRK'. 'Cuban Peso . CUP'. 'Cyprus Pound . CYP'. 'Czech Koruna . CZK'. 'Danish Krone . DKK'. 'Djibouti Franc . DJF'. 'Dominican R. Peso . DOP'. 'Dutch Guilder . NLG'. 'ECU . XEU'. 'East Caribbean Dollar . XCD'. 'Ecuador Sucre . ECS'. 'Egyptian Pound . EGP'. 'El Salvador Colon . SVC'. 'Estonian Kroon . EEK'. 'Ethiopian Birr . ETB'. 'Euro . EUR'. 'Falkland Islands Pound . FKP'. 'Fiji Dollar . FJD'. 'Finnish Markka . FIM'. 'French Franc . FRF'. 'Gambian Dalasi . GMD'. 'German Mark . DEM'. 'Ghanaian Cedi . GHC'. 'Gibraltar Pound . GIP'. 'Greek Drachma . GRD'. 'Guatemalan Quetzal . GTQ'. 'Guinea Franc . GNF'. 'Guyanese Dollar . GYD'. 'Haitian Gourde . HTG'. 'Honduran Lempira . HNL'. 'Hong Kong Dollar . HKD'. 'Hungarian Forint . HUF'. 'Iceland Krona . ISK'. 'Indian Rupee . INR'. 'Indonesian Rupiah . IDR'. 'Iranian Rial . IRR'. 'Iraqi Dinar . IQD'. 'Irish Punt . IEP'. 'Israeli New Shekel . ILS'. 'Italian Lira . ITL'. 'Jamaican Dollar . JMD'. 'Japanese Yen . JPY'. 'Jordanian Dinar . JOD'. 'Kazakhstan Tenge . KZT'. 'Kenyan Shilling . KES'. 'Kuwaiti Dinar . KWD'. 'Lao Kip . LAK'. 'Latvian Lats . LVL'. 'Lebanese Pound . LBP'. 'Lesotho Loti . LSL'. 'Liberian Dollar . LRD'. 'Libyan Dinar . LYD'. 'Lithuanian Litas . LTL'. 'Luxembourg Franc . LUF'. 'Macau Pataca . MOP'. 'Malagasy Franc . MGF'. 'Malawi Kwacha . MWK'. 'Malaysian Ringgit . MYR'. 'Maldive Rufiyaa . MVR'. 'Maltese Lira . MTL'. 'Mauritanian Ouguiya . MRO'. 'Mauritius Rupee . MUR'. 'Mexican Peso . MXN'. 'Mongolian Tugrik . MNT'. 'Moroccan Dirham . MAD'. 'Mozambique Metical . MZM'. 'Myanmar Kyat . MMK'. 'NL Antillian Guilder . ANG'. 'Namibia Dollar . NAD'. 'Nepalese Rupee . NPR'. 'New Zealand Dollar . NZD'. uan Cordoba Oro . NIO'. 'Nigerian Naira . NGN'. 'North Korean Won . KPW'. 'Norwegian Kroner . NOK'. 'Omani Rial . OMR'. 'Pakistan Rupee . PKR'. 'Panamanian Balboa . PAB'. 'Papua New Guinea Kina . PGK'. 'Paraguay Guarani . PYG'. 'Peruvian Nuevo Sol . PEN'. 'Philippine Peso . PHP'. 'Polish Zloty . PLN'. 'Portuguese Escudo . PTE'. 'Qatari Rial . QAR'. 'Romanian Leu . ROL'. 'Russian Rouble . RUB'. 'Samoan Tala . WST'. 'Sao Tome/Principe Dobra . STD'. 'Saudi Riyal . SAR'. 'Seychelles Rupee . SCR'. 'Sierra Leone Leone . SLL'. 'Singapore Dollar . SGD'. 'Slovak Koruna . SKK'. 'Slovenian Tolar . SIT'. 'Solomon Islands Dollar . SBD'. 'Somali Shilling . SOS'. 'South African Rand . ZAR'. 'South-Korean Won . KRW'. 'Spanish Peseta . ESP'. 'Sri Lanka Rupee . LKR'. 'St. Helena Pound . SHP'. 'Sudanese Dinar . SDD'. 'Sudanese Pound . SDP'. 'Suriname Guilder . SRG'. . 'Swedish Krona . SEK'. 'Swiss Franc . CHF'. 'Syrian Pound . SYP'. 'Taiwan Dollar . TWD'. 'Tanzanian Shilling . TZS'. 'Thai Baht . THB'. 'Tonga Pa''anga . TOP'. 'Trinidad/Tobago Dollar . TTD'. 'Tunisian Dinar . TND'. 'Turkish Lira . TRL'. 'Uganda Shilling . UGS'. 'Ukraine Hryvnia . UAH'. 'Uruguayan Peso . UYP'. 'US Dollar . USD'. 'Utd. Arab Emir. Dirham . AED'. 'Vanuatu Vatu . VUV'. 'Venezuelan Bolivar . VEB'. 'Vietnamese Dong . VND'. 'Yugoslav Dinar . YUN'. 'Zambian Kwacha . ZMK'. 'Zimbabwe Dollar . ZWD' }.! ! !CurrencyConverter class methodsFor: 'as yet unclassified' stamp: 'Friedrich 10/1/2003 13:05'! new ^super new initialize.! ! AlignmentMorph subclass: #CurrencyConverterView instanceVariableNames: 'fromIndex toIndex currencyConverter output ' classVariableNames: '' poolDictionaries: '' category: 'LMExample'! !CurrencyConverterView methodsFor: 'private'! addButtonRow | row | row := AlignmentMorph newRow ellInset: 4; vResizing: #shrinkWrap; hResizing: #spaceFill; color: Color transparent. row addMorphBack: (Morph new extent: 4 @ 1; color: Color transparent). row addMorphBack: (self buttonName: 'Exchange Rate' action: #calculateExchange). row addMorphBack: (self buttonName: 'Close' action: #closeApplication). self addMorphBack: row. ! ! !CurrencyConverterView methodsFor: 'private'! addListViewRow | row lv| row := AlignmentMorph newRow vResizing: #shrinkWrap; color: Color transparent. row addMorphBack: (Morph new extent: 4 @ 1; color: Color transparent). row cellInset: 4. lv := PluggableListMorph on: self list: nil selected: #fromIndex changeSelected: #fromIndex:. lv list: self list. row addMorphBack: lv; addMorphBack: (Morph new extent: 8 @ 1; color: Color transparent). lv := PluggableListMorph on: self list: nil selected: #toIndex changeSelected: #toIndex:. t: self list. row addMorphBack: lv; addMorphBack: (Morph new extent: 4 @ 1; color: Color transparent). self addMorphBack: row. ^self. ! ! !CurrencyConverterView methodsFor: 'private'! addOutputRow | row text| row := AlignmentMorph newRow cellInset: 4; vResizing: #shrinkWrap; hResizing: #spaceFill; color: Color transparent. row addMorphBack: (Morph new extent: 4 @ 1; color: Color transparent). text := TextMorph new contents: 'Exchange Rate: '. row addMorphBack: text. "row addMorphBack: (Morph new extent: 4 @ 1; color: Color transparent)." output := TextMorph new contents: 'Will be changed by an button action'. row addMorphBack: output. self addMorphBack: row. ! ! !CurrencyConverterView methodsFor: 'private'! buttonName: aString action: aSymbol ^ SimpleButtonMorph new target: self; label: aString; actionSelector: aSymbol; color: (Color gray: 0.9); "old color" borderColor: #raised.! ! !CurrencyConverterView methodsFor: 'private'! alizeGUI super initialize. self hResizing: #shrinkWrap; vResizing: #shrinkWrap. borderWidth _ 2. self listDirection: #topToBottom. self cornerStyle: #rounded. self layoutInset: 4. self cellInset: 10. self addListViewRow. self addOutputRow. self addButtonRow. ^self.! ! !CurrencyConverterView methodsFor: 'initialization'! initialize fromIndex := 157. "US Dollar" toIndex := 53. "Should be EUR" currencyConverter := CurrencyConverter new. self initializeGUI.! ! !CurrencyConverterView methodsFor: 'accessing' stamp: 'Friedrich 10/2/2003 17:44'! fromIndex ^fromIndex.! ! !CurrencyConverterView methodsFor: 'accessing'! fromIndex: aNumber fromIndex := aNumber. Transcript show: 'fromIndex: ' , fromIndex asString; cr. self changed: #fromIndex.! ! !CurrencyConverterView methodsFor: 'accessing' stamp: 'Friedrich 10/2/2003 17:49'! list ^CurrencyConverter currencies.! ! !CurrencyConverterView methodsFor: 'accessing' stamp: 'Friedrich 10/2/2003 17:47'! toIndex ^toIndex.! ! onverterView methodsFor: 'accessing'! toIndex: aNumber toIndex := aNumber. Transcript show: 'toIndex: ' , toIndex asString; cr. self changed: #toIndex.! ! !CurrencyConverterView methodsFor: 'as yet unclassified'! calculateExchange | result amount from to | amount := 1. from := currencyConverter getCurrencySymbol: fromIndex. to := currencyConverter getCurrencySymbol: toIndex. result := currencyConverter calculateExchangeFrom: from to: to amount: amount. output contents: result. ! ! !CurrencyConverterView methodsFor: 'as yet unclassified'! closeApplication self delete.! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! CurrencyConverterView class instanceVariableNames: ''! !CurrencyConverterView class methodsFor: 'as yet unclassified' stamp: 'Friedrich 10/2/2003 17:43'! new ^super new initialize.! ! !CurrencyConverterView class methodsFor: 'as yet unclassified'! test | ccv row from to | ccv := CurrencyConverterView new. row := AlignmentMorph newRow vResizing: #shrinkWrap; color: Color transparent. row cellInset: 4. from := PluggableListMorph on: ccv list: nil selected: #fromIndex changeSelected: #fromIndex:. from list: ccv list. row addMorphBack: from; addMorphBack: (Morph new extent: 50 @ 1; color: Color transparent). to := PluggableListMorph on: ccv list: nil selected: #toIndex changeSelected: #toIndex:. to list: ccv list. row addMorphBack: to. ^ row. ! !