Methods Summary |
---|
private org.apache.velocity.VelocityContext | createContext(java.util.Collection weatherCollection)
VelocityContext context = new VelocityContext();
int index = 1;
for (Iterator iterator = weatherCollection.iterator(); iterator.hasNext();) {
Weather weather = (Weather) iterator.next();
String day = "DAY" + index;
context.put(day, weather.getDay());
context.put(day + "_TEMP", weather.getTemperature());
context.put(day + "_HUMIDITY", weather.getHumidity());
context.put(day + "_PRESSURE", weather.getPressure());
index++;
}
return context;
|
private javax.swing.JEditorPane | createHtmlPanel()
JEditorPane editorPane = new JEditorPane();
HTMLEditorKit editorKit = new HTMLEditorKit();
editorKit.install(editorPane);
editorPane.setEditorKit(editorKit);
editorPane.setEditable(false);
return editorPane;
|
public void | displayWeather(java.lang.String html, java.util.Collection weather)
String result = html;
try {
VelocityContext context = createContext(weather);
result = processString(context, html);
} catch (Exception e){
e.printStackTrace();
}
htmlPane.setText(result);
|
public void | displayWeatherByFile(java.lang.String fileName, java.util.Collection weather)
displayWeather(readFile(fileName), weather);
|
public java.awt.Component | getComponent()
return new JScrollPane(htmlPane);
|
private java.lang.String | processString(org.apache.velocity.VelocityContext context, java.lang.String htmlText)
StringWriter writer = new StringWriter();
Properties properties = new Properties();
Velocity.init(properties);
Velocity.evaluate(context,
writer,
null,
htmlText);
return writer.getBuffer().toString();
|
private java.lang.String | readFile(java.lang.String fileName)
StringBuffer htmlBuffer = new StringBuffer();
try {
InputStream inputStream = WeatherPanel.class.getResourceAsStream(fileName);
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
while (true){
String line = reader.readLine();
if (line != null){
htmlBuffer.append(line);
} else {
break;
}
}
} catch (IOException iox){
iox.printStackTrace();
}
return htmlBuffer.toString();
|