Skip to content

Commit

Permalink
Modifying
Browse files Browse the repository at this point in the history
  • Loading branch information
jenikm committed Nov 22, 2011
1 parent d28fd42 commit 42badbd
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 16 deletions.
58 changes: 49 additions & 9 deletions ArtistDetailView.pde
@@ -1,11 +1,53 @@
import java.util.*;

class ArtistDetailView extends View {
class SimilarArtistEntry implements TableDataSource{
ArrayList<Artist> artists;

SimilarArtistEntry(ArrayList<Artist> artists){
this.artists = artists;
}
String getText(int index, int column){
Artist artist = artists.get(index);
if(column == 0){
return artist.name;
}
else{
return artist.image_url;
}
}

PImage getImage(int index, int column){
Artist artist = artists.get(index);
if(column == 1){
return artist.image;
}
else{
return null;
}
}

Object get(int index){
return new Object();
}

int count(){
return artists.size();
}
boolean selected(int index){
return false;
}
}

class ArtistInfo implements TableDataSource{
Artist artist;
ArtistInfo(Artist artist){
this.artist = artist;
}

PImage getImage(int index, int column){
return null;
}
String getText(int index, int column){
fill(255);
if(index == 0){
Expand Down Expand Up @@ -46,9 +88,9 @@ class ArtistDetailView extends View {
int ROW_3 = 400;
int COLUMN_1 = 20;
int COLUMN_2 = 400;
int COLUMN_3 = 600;

Artist artist;
PImage artist_image;
PieChart genderPieChart;
TableView artist_info;

Expand All @@ -69,13 +111,9 @@ class ArtistDetailView extends View {
{
artist = a;
if (artist == null) {
artist_image = data.getMissingImage();
genderPieChart.data = new MissingPieChartDataSource();
artist_info.data = new MissingTableDataSource("no data");
} else {
ArrayList<String> image_urls = artist.getImageUrls();
if(image_urls.size() > 0) artist_image = loadImage(image_urls.get(0), "jpg");
else artist_image = data.getMissingImage();
genderPieChart.data = artist.getGenderBreakdown();
artist_info.data = new ArtistInfo(artist);
}
Expand Down Expand Up @@ -111,10 +149,12 @@ class ArtistDetailView extends View {
}

void addSimilarArtistsChart(){

ArrayList<Artist> similar = artist.similar();
TableView artist_info = new TableView(COLUMN_1, ROW_3, 300, 200, Arrays.asList(
new TableColumn("Fact", 100), new TableColumn("Value", 100)), new ArtistInfo(artist));
TableView similar_artist_table = new TableView(COLUMN_3, ROW_1, 300, 400, Arrays.asList(
new TableColumn("Name", 100), new TableColumn("Image", 100, true)), new SimilarArtistEntry(similar));
this.subviews.add(artist_info);

}

void drawTitle(){
Expand All @@ -126,8 +166,8 @@ class ArtistDetailView extends View {
}

void drawImage(){
if(artist_image!=null)
image(artist_image, COLUMN_1, ROW_2);
if(artist!=null)
image(artist.getImage(), COLUMN_1, ROW_2);
}

void drawSongs(){
Expand Down
24 changes: 20 additions & 4 deletions Data.pde
Expand Up @@ -2,8 +2,9 @@ import org.json.*;
import java.util.*;
import java.util.concurrent.*;



String missingImageUrl(){
return host + "assets/photo_not_available.jpg";
}
public Artist findArtist(int id){
String request = host + "artists/" + id + ".json";
println(request);
Expand All @@ -22,6 +23,7 @@ class Artist {
String mbid;
String name;
String image_url;
PImage image;

ArrayList<ArtistAgeBreakdown> age_breakdown;
ArrayList<Artist> similar;
Expand All @@ -41,6 +43,20 @@ class Artist {
this.name = name;
}

PImage getImage(){
if(image == null){
if(image_url == null){
ArrayList<String> image_urls = this.getImageUrls();
if(image_urls.size() > 0)
image_url = image_urls.get(0);
else
image_url = missingImageUrl();
}
image = loadImage(image_url, "jpg");
}
return image;
}

ArrayList<Artist> similar(){
if(similar == null){
similar = new ArrayList<Artist>();
Expand Down Expand Up @@ -403,11 +419,10 @@ class WebDataSource {
}
});
}

PImage getMissingImage()
{
if (missingImage == null) {
missingImage = loadImage(baseURL + "assets/photo_not_available.jpg", "jpg");
missingImage = loadImage(missingImageUrl(), "jpg");
}
return missingImage;
}
Expand Down Expand Up @@ -441,3 +456,4 @@ String songtoMbid(String song){
xml.getChild(0).getChild(3).getChild(0).getContent(),
xml.getChild(0).getChild(3).getChild(1).getContent());
}

15 changes: 13 additions & 2 deletions TableView.pde
Expand Up @@ -4,6 +4,7 @@ interface TableAction {

interface TableDataSource {
String getText(int index, int column);
PImage getImage(int index, int column);
Object get(int index);
int count();
boolean selected(int index);
Expand All @@ -17,18 +18,25 @@ class MissingTableDataSource implements TableDataSource {
Object get(int index) { return null; }
int count() { return 1; }
boolean selected(int index) { return false; }
PImage getImage(int index, int column){return null;}
}

class TableColumn {
String label;
float w;
int align;
boolean imagable;

TableColumn(String label, float w, int align) {
this.label = label;
this.w = w;
this.align = align;
}

TableColumn(String label, float w, int align, boolean imagable){
this(label, w, align);
this.imagable = imagable;
}

TableColumn(String label, float w) {
this(label, w, LEFT);
Expand Down Expand Up @@ -88,7 +96,7 @@ class TableView extends View {
this.data = data;
action = null;
}

int maxScroll()
{
return max(data.count() - int(h/rowHeight), 0);
Expand Down Expand Up @@ -154,7 +162,10 @@ class TableView extends View {
void drawCell(int i, int j, TableColumn col, float colx)
{
textAlign(col.align, CENTER);
text(data.getText(i, j), colx + MARGIN, 0, col.w - MARGIN*2, rowHeight);
if(col.imagable)
image(data.getImage(i,j), colx + MARGIN, 0);
else
text(data.getText(i, j), colx + MARGIN, 0, col.w - MARGIN*2, rowHeight);
}

boolean contentPressed(float lx, float ly)
Expand Down
1 change: 1 addition & 0 deletions TopArtistView.pde
Expand Up @@ -168,6 +168,7 @@ class TopArtistView extends View implements TableDataSource {

reloadArtists();
}
PImage getImage(int index, int column){return null;}

int stringToAge(String s)
{
Expand Down
2 changes: 1 addition & 1 deletion cs424p4.pde
Expand Up @@ -59,7 +59,7 @@ void setup()

View artistDetailPane = mainTabView.tabs.get(1).pane;
/* Eugine, add artist detail views to artistDetailPane.subviews */
Artist artist = findArtist(4112);
Artist artist = findArtist(154704);
ArtistDetailView artistDetailView = new ArtistDetailView(0,0,width,height);
artistDetailView.setArtist(artist);
artistDetailPane.subviews.add(artistDetailView);
Expand Down

0 comments on commit 42badbd

Please sign in to comment.