Skip to content

Commit

Permalink
top artists view
Browse files Browse the repository at this point in the history
  • Loading branch information
camillol committed Nov 20, 2011
1 parent 282d724 commit 40c3388
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 9 deletions.
17 changes: 17 additions & 0 deletions Checkbox.pde
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,20 @@ class Checkbox extends Button {
}
}

class GlyphCheckbox extends Checkbox {
String glyph;
GlyphCheckbox(float x_, float y_, float w_, float h_, String glyph)
{
super(x_,y_,w_,h_);
this.glyph = glyph;
}

void drawContent(float lx, float ly) {
super.drawContent(lx, ly);
if (checked) fill(0);
else fill(fgColor);
textAlign(CENTER, CENTER);
text(glyph, 0, 0, w, h);
}
}

9 changes: 8 additions & 1 deletion Data.pde
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class Artist {
}
}

final static int UNKNOWN = 0;
final static int MALE = 1;
final static int FEMALE = 2;
final static int UNKNOWN = 4;
final static int DONTCARE = -1;

class User {
Expand Down Expand Up @@ -46,6 +46,13 @@ class UserFilter {
this.ageMax = ageMax;
this.country = country;
}

UserFilter() {
gender = DONTCARE;
ageMin = DONTCARE;
ageMax = DONTCARE;
country = null;
}
}

class Country {
Expand Down
8 changes: 7 additions & 1 deletion ListBox.pde
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
interface ListAction {
void itemClicked(ListBox lb, int index, Object item);
}

interface ListDataSource {
String getText(int index);
Object get(int index);
Expand Down Expand Up @@ -25,6 +29,7 @@ class ListBox extends View {
color selFgColor = color(255);

ListDataSource data;
ListAction action;
int scrollPos = 0;

float thumbClickPos = -1;
Expand All @@ -33,6 +38,7 @@ class ListBox extends View {
{
super(x_,y_,w_,h_);
data = data_;
action = null;
}

int maxScroll()
Expand Down Expand Up @@ -106,7 +112,7 @@ class ListBox extends View {
boolean contentClicked(float lx, float ly)
{
int index = constrain(int(ly/rowHeight) + scrollPos, 0, data.count()-1);
listClicked(this, index, data.get(index));
if (action != null) action.itemClicked(this, index, data.get(index));
return true;
}
}
Expand Down
44 changes: 44 additions & 0 deletions TopArtistView.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
class TopArtistView extends View {
UserFilter userFilter;
GlyphCheckbox maleCB;
GlyphCheckbox femaleCB;
GlyphCheckbox noGenderCB;
ListBox artistListbox;

TopArtistView(float x_, float y_, float w_, float h_)
{
super(x_,y_,w_,h_);
userFilter = new UserFilter();

maleCB = makeGenderCheckbox(MALE, "M", 0);
femaleCB = makeGenderCheckbox(FEMALE, "F", 1);
noGenderCB = makeGenderCheckbox(UNKNOWN, "?", 2);

artistListbox = new ListBox(0, 20, w, h-2, new MissingListDataSource("no artists"));
subviews.add(artistListbox);
}

GlyphCheckbox makeGenderCheckbox(final int flag, String letter, int idx)
{
GlyphCheckbox cb = new GlyphCheckbox(20*idx, 0, 20, 20, letter);
cb.checked = (userFilter.gender | flag) != 0;
cb.setAction(new Action<Button>() {
public void respond(Button b) {
Checkbox cb = (Checkbox)b;
if (cb.checked) userFilter.gender |= flag;
else userFilter.gender &= ~flag;
}
});
subviews.add(cb);
return cb;
}

void drawContent(float lx, float ly)
{
strokeWeight(1);
stroke(255);
noFill();
rect(0, 0, w, h);
}
}

12 changes: 5 additions & 7 deletions cs424p4.pde
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void setup()
/* setup UI */
rootView = new View(0, 0, width, height);

testCB = new Checkbox(100, 100, 20, 20);
testCB = new Checkbox(100, 400, 20, 20);
testCB.setAction(new Action<Button>() {
public void respond(Button b) {
Checkbox cb = (Checkbox)b;
Expand All @@ -36,14 +36,17 @@ void setup()
});
rootView.subviews.add(testCB);

Button testB = new Button(100, 200, 120, 20, "hello");
Button testB = new Button(100, 500, 120, 20, "hello");
testB.setAction(new Action<Button>() {
public void respond(Button b) {
println(b.title);
}
});
rootView.subviews.add(testB);

TopArtistView topArtists = new TopArtistView(20, 20, 400, 200);
rootView.subviews.add(topArtists);

// I want to add true multitouch support, but let's have this as a stopgap for now
addMouseWheelListener(new java.awt.event.MouseWheelListener() {
public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) {
Expand Down Expand Up @@ -85,8 +88,3 @@ void keyTyped()
if (focusView != null) focusView.keyTyped();
}

void listClicked(ListBox lb, int index, Object item)
{

}

0 comments on commit 40c3388

Please sign in to comment.