Permalink
Browse files

Pivot StockeTracker in maven, initial version. Matched blog on michae…

…lbushe.wordpress.com titled 'Creating an Apache Pivot App using Maven'
  • Loading branch information...
michaelbushe committed Dec 22, 2009
1 parent e2c15dd commit a37d825904a32d935f6f4111fb96afcc928878de
Showing with 1,178 additions and 0 deletions.
  1. +78 −0 pivotStockTracker/beforeEventBus/stocktracker/pom.xml
  2. +42 −0 ...tBus/stocktracker/src/main/java/org/eventbus/tutorials/pivot/stocktracker/ChangeCellRenderer.java
  3. +140 −0 ...foreEventBus/stocktracker/src/main/java/org/eventbus/tutorials/pivot/stocktracker/StockQuote.java
  4. +82 −0 ...EventBus/stocktracker/src/main/java/org/eventbus/tutorials/pivot/stocktracker/StockQuoteView.java
  5. +405 −0 ...reEventBus/stocktracker/src/main/java/org/eventbus/tutorials/pivot/stocktracker/StockTracker.java
  6. +31 −0 ...ntBus/stocktracker/src/main/resources/org/eventbus/tutorials/pivot/stocktracker/StockTracker.json
  7. +31 −0 ...us/stocktracker/src/main/resources/org/eventbus/tutorials/pivot/stocktracker/StockTracker_fr.json
  8. +31 −0 ...us/stocktracker/src/main/resources/org/eventbus/tutorials/pivot/stocktracker/StockTracker_it.json
  9. BIN .../beforeEventBus/stocktracker/src/main/resources/org/eventbus/tutorials/pivot/stocktracker/add.png
  10. BIN ...foreEventBus/stocktracker/src/main/resources/org/eventbus/tutorials/pivot/stocktracker/delete.png
  11. BIN ...oreEventBus/stocktracker/src/main/resources/org/eventbus/tutorials/pivot/stocktracker/go-down.png
  12. BIN ...eforeEventBus/stocktracker/src/main/resources/org/eventbus/tutorials/pivot/stocktracker/go-up.png
  13. +42 −0 ...tocktracker/src/main/resources/org/eventbus/tutorials/pivot/stocktracker/stocktracker.detail.wtkx
  14. +42 −0 ...cktracker/src/main/resources/org/eventbus/tutorials/pivot/stocktracker/stocktracker.detail.wtkx-e
  15. +127 −0 ...ntBus/stocktracker/src/main/resources/org/eventbus/tutorials/pivot/stocktracker/stocktracker.wtkx
  16. +127 −0 ...Bus/stocktracker/src/main/resources/org/eventbus/tutorials/pivot/stocktracker/stocktracker.wtkx-e
@@ -0,0 +1,78 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.eventbus.tutorial.pivot</groupId>
+ <artifactId>stocktracker</artifactId>
+ <packaging>jar</packaging>
+ <version>1.0-SNAPSHOT</version>
+ <name>stocktracker</name>
+ <url>http://maven.apache.org</url>
+ <build>
+ <sourceDirectory>src</sourceDirectory>
+ <testSourceDirectory>test/src</testSourceDirectory>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>attached</goal>
+ </goals>
+ <phase>package</phase>
+ <configuration>
+ <descriptorRefs>
+ <descriptorRef>jar-with-dependencies</descriptorRef>
+ </descriptorRefs>
+ <archive>
+ <manifest>
+ <mainClass>org.eventbus.tutorials.pivot.stocktracker.StockTracker</mainClass>
+ </manifest>
+ </archive>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.pivot</groupId>
+ <artifactId>pivot-core</artifactId>
+ <version>1.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.pivot</groupId>
+ <artifactId>pivot-wtk</artifactId>
+ <version>1.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.pivot</groupId>
+ <artifactId>pivot-web</artifactId>
+ <version>1.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.pivot</groupId>
+ <artifactId>pivot-wtk-terra</artifactId>
+ <version>1.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.pivot</groupId>
+ <artifactId>pivot-charts</artifactId>
+ <version>1.4</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.eventbus.tutorials.pivot.stocktracker;
+
+import java.awt.Color;
+
+import org.apache.pivot.wtk.TableView;
+import org.apache.pivot.wtk.content.TableViewNumberCellRenderer;
+
+public class ChangeCellRenderer extends TableViewNumberCellRenderer {
+ public static final Color UP_COLOR = new Color(0x00, 0x80, 0x00);
+ public static final Color DOWN_COLOR = new Color(0xff, 0x00, 0x00);
+
+ @Override
+ public void render(Object value, int rowIndex, int columnIndex,
+ TableView tableView, String columnName,
+ boolean rowSelected, boolean rowHighlighted, boolean rowDisabled) {
+ super.render(value, rowIndex, columnIndex, tableView, columnName,
+ rowSelected, rowHighlighted, rowDisabled);
+
+ if (value != null
+ && !rowSelected) {
+ StockQuote stockQuote = (StockQuote)value;
+ float change = stockQuote.getChange();
+ getStyles().put("color", change < 0 ? DOWN_COLOR : UP_COLOR);
+ }
+ }
+}
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.eventbus.tutorials.pivot.stocktracker;
+
+public class StockQuote {
+ private String symbol = null;
+ private String companyName = null;
+ private float value = 0;
+ private float openingValue = 0;
+ private float highValue = 0;
+ private float lowValue = 0;
+ private float change = 0;
+ private float volume = 0;
+
+ public String getSymbol() {
+ return symbol;
+ }
+
+ public void setSymbol(String symbol) {
+ this.symbol = symbol;
+ }
+
+ public String getCompanyName() {
+ return companyName;
+ }
+
+ public void setCompanyName(String companyName) {
+ this.companyName = companyName;
+ }
+
+ public float getValue() {
+ return value;
+ }
+
+ public void setValue(float value) {
+ this.value = value;
+ }
+
+ public void setValue(String value) {
+ try {
+ setValue(Float.parseFloat(value));
+ } catch(NumberFormatException exception) {
+ setValue(Float.NaN);
+ }
+ }
+
+ public float getOpeningValue() {
+ return openingValue;
+ }
+
+ public void setOpeningValue(float openingValue) {
+ this.openingValue = openingValue;
+ }
+
+ public void setOpeningValue(String openingValue) {
+ try {
+ setOpeningValue(Float.parseFloat(openingValue));
+ } catch(NumberFormatException exception) {
+ setOpeningValue(Float.NaN);
+ }
+ }
+
+ public float getHighValue() {
+ return highValue;
+ }
+
+ public void setHighValue(float highValue) {
+ this.highValue = highValue;
+ }
+
+ public void setHighValue(String highValue) {
+ try {
+ setHighValue(Float.parseFloat(highValue));
+ } catch(NumberFormatException exception) {
+ setHighValue(Float.NaN);
+ }
+ }
+
+ public float getLowValue() {
+ return lowValue;
+ }
+
+ public void setLowValue(float lowValue) {
+ this.lowValue = lowValue;
+ }
+
+ public void setLowValue(String lowValue) {
+ try {
+ setLowValue(Float.parseFloat(lowValue));
+ } catch(NumberFormatException exception) {
+ setLowValue(Float.NaN);
+ }
+ }
+
+ public float getChange() {
+ return change;
+ }
+
+ public void setChange(float change) {
+ this.change = change;
+ }
+
+ public void setChange(String change) {
+ try {
+ setChange(Float.parseFloat(change));
+ } catch(NumberFormatException exception) {
+ setChange(Float.NaN);
+ }
+ }
+
+ public float getVolume() {
+ return volume;
+ }
+
+ public void setVolume(float volume) {
+ this.volume = volume;
+ }
+
+ public void setVolume(String volume) {
+ try {
+ setVolume(Float.parseFloat(volume));
+ } catch(NumberFormatException exception) {
+ setVolume(Float.NaN);
+ }
+ }
+}
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.eventbus.tutorials.pivot.stocktracker;
+
+import java.text.DecimalFormat;
+
+import org.apache.pivot.beans.BeanDictionary;
+
+public class StockQuoteView extends BeanDictionary {
+ private static final DecimalFormat valueFormat = new DecimalFormat("$0.00");
+ private static final DecimalFormat changeFormat = new DecimalFormat("+0.00;-0.00");
+ private static final DecimalFormat volumeFormat = new DecimalFormat();
+
+ public StockQuoteView(StockQuote stockQuote) {
+ super(stockQuote);
+ }
+
+ @Override
+ public Object get(String key) {
+ if (key == null) {
+ throw new IllegalArgumentException("key is null.");
+ }
+
+ Object value = null;
+ StockQuote stockQuote = (StockQuote)getBean();
+
+ if (stockQuote == null) {
+ value = "";
+ } else {
+ value = super.get(key);
+
+ if (key.equals("value")
+ || key.equals("openingValue")
+ || key.equals("highValue")
+ || key.equals("lowValue")) {
+ try {
+ Float floatValue = (Float)value;
+ if (floatValue.isNaN()) {
+ value = "n/a";
+ } else {
+ value = valueFormat.format(floatValue);
+ }
+ } catch(Exception exception) {
+ value = "";
+ }
+ } else if (key.equals("change")) {
+ try {
+ value = changeFormat.format(value);
+ } catch(Exception exception) {
+ value = "";
+ }
+ } else if (key.equals("volume")) {
+ try {
+ value = volumeFormat.format(value);
+ } catch(Exception exception) {
+ value = "";
+ }
+ } else {
+ if (value != null) {
+ value = value.toString();
+ }
+ }
+ }
+
+ return value;
+ }
+}
+
Oops, something went wrong.

0 comments on commit a37d825

Please sign in to comment.