My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
* Copyright (c) 2008, Kevin Stembridge
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.moneydance.modules.features.forecaster;

import java.awt.Image;
import java.awt.Toolkit;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;

import com.moneydance.apps.md.controller.FeatureModule;
import com.moneydance.modules.features.forecaster.homepage.ForecasterHomePageController;
import com.moneydance.modules.features.forecaster.util.AccountHelper;
import com.moneydance.modules.features.forecaster.window.ForecastWindowController;

/**
* This is a Moneydance feature module that allows the user to view a balance forecast
* for 1 or more of their accounts over a given period of time into the future. The
* forecast is based on transaction reminders that have been registered against the accounts.
*
* @author <a href="mailto:kevin.stembridge.dev@gmail.com">Kevin Stembridge</a>
* @author $LastChangedBy$
* @version $Revision$
* @since 27 Nov 2008
*
*
*/
public class Main extends FeatureModule {

public static final String APP_TITLE = "Forecaster";
private static final String COMMAND_SHOW_CONSOLE = "showconsole";

private ForecastWindowController forecastWindowController;
private ForecasterHomePageController forecastHomePageController;
private AccountHelper accountHelper;


/**
* Creates a new uninitialized Main.
*/
public Main() {
//do nothing
}


@Override
public void init() {

this.forecastHomePageController = new ForecasterHomePageController(getContext(), getAccountHelper());

try {
getContext().registerFeature(this, COMMAND_SHOW_CONSOLE, getIcon(), getName());
getContext().registerHomePageView(this, this.forecastHomePageController);
} catch (Exception e) {
e.printStackTrace();
}

}


@SuppressWarnings("unused")
private Image getIcon() {

if (true) {
//Just return null until a decent icon has been created
return null;
}

try {
ClassLoader cl = getClass().getClassLoader();
InputStream in = cl.getResourceAsStream("/com/moneydance/modules/features/forecaster/icon.gif");

if (in != null) {
ByteArrayOutputStream bout = new ByteArrayOutputStream(1000);
byte buf[] = new byte[256];
int n = 0;

while ((n = in.read(buf, 0, buf.length)) >= 0) {
bout.write(buf, 0, n);
}

return Toolkit.getDefaultToolkit().createImage(bout.toByteArray());

}

} catch (Throwable e) {
e.printStackTrace();
}

return null;

}


@Override
public String getName() {
return APP_TITLE;
}


/**
* Process an invocation of this module with the given URI. This is expected to
* be invoked from the EDT.
*/
@Override
public void invoke(String uri) {

String command = uri;
int theIdx = uri.indexOf('?');

if (theIdx >= 0) {
command = uri.substring(0, theIdx);
} else {
theIdx = uri.indexOf(':');
if (theIdx >= 0) {
command = uri.substring(0, theIdx);
}
}

if (command.equals(COMMAND_SHOW_CONSOLE)) {
showConsole();
}

}


/**
* Ensures that the datasetManager and forecastWindow are initialized then
* displays the window.
*/
private void showConsole() {

if (this.forecastWindowController == null) {
this.forecastWindowController = new ForecastWindowController(getContext(), getAccountHelper());
}

this.forecastWindowController.show();

}


@Override
public void cleanup() {

this.forecastWindowController.closeForecaster();
this.forecastHomePageController.closeForecaster();

}


private AccountHelper getAccountHelper() {

if (this.accountHelper == null) {
this.accountHelper = new AccountHelper(getContext());
}

return this.accountHelper;

}



}

Change log

r117 by kevin.stembridge.dev on Jan 9, 2012   Diff
[No log message]
Go to: 
Project members, sign in to write a code review

Older revisions

r101 by kevin.stembridge.dev on Dec 18, 2011   Diff
Account markers
r97 by kevin.stembridge.dev on Dec 14, 2011   Diff
ongoing dev
r92 by kevin.stembridge.dev on May 30, 2011   Diff
Removed System.err.println
All revisions of this file

File info

Size: 5210 bytes, 183 lines

File properties

svn:mime-type
text/plain
svn:eol-style
native
svn:keywords
Date Revision Author Id HeadURL
Powered by Google Project Hosting