created mirror
This commit is contained in:
162
Modules/daytimedemo/Calendar2.zob
Normal file
162
Modules/daytimedemo/Calendar2.zob
Normal file
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
Calendar2.zob
|
||||
*
|
||||
* Copyright (c) 2000, Ted Nelson and Tuomas Lukka
|
||||
*
|
||||
* You may use and distribute under the terms of either the GNU Lesser
|
||||
* General Public License, either version 2 of the license or,
|
||||
* at your choice, any later version. Alternatively, you may use and
|
||||
* distribute under the terms of the XPL.
|
||||
*
|
||||
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
|
||||
* the licenses.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README
|
||||
* file for more details.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Written by Tuomas Lukka
|
||||
*/
|
||||
package org.gzigzag.module;
|
||||
import org.gzigzag.*;
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
public class Calendar2 implements FlobView, ZOb {
|
||||
public static boolean dbg = false;
|
||||
static final void p(String s) { if(dbg) System.out.println(s); }
|
||||
static final void pa(String s) { System.out.println(s); }
|
||||
|
||||
static public ZZModule module = new ZZModule() {
|
||||
public ZOb newZOb(String id) {
|
||||
if(id.equals("R"))
|
||||
return new Calendar2();
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
STRUCTPARAMS {
|
||||
Font nfont
|
||||
= new Font("SansSerif", Font.PLAIN, 16);
|
||||
|
||||
Font bfont
|
||||
= new Font("SansSerif", Font.BOLD, 16);
|
||||
}
|
||||
|
||||
FontMetrics nfm, bfm;
|
||||
|
||||
INITIALIZE {
|
||||
nfm = FONTMETRICS(nfont);
|
||||
bfm = FONTMETRICS(bfont);
|
||||
}
|
||||
|
||||
final String[] txts = new String[] {
|
||||
"Vk", "M", "T", "K", "T", "P", "L", "S"
|
||||
};
|
||||
|
||||
public void raster(FlobSet into, FlobFactory fact,
|
||||
ZZCell view, String[] dims, ZZCell accursed) {
|
||||
|
||||
Dimension s = into.getSize();
|
||||
|
||||
final int x = s.width/2 / 10;
|
||||
final int y = s.height / 10;
|
||||
final int w = s.width/2 - 2 * x;
|
||||
final int h = s.height - 2 * y;
|
||||
|
||||
final int x2 = x + s.width/2;
|
||||
|
||||
final int xm = w / 8;
|
||||
final int ym = h / 7;
|
||||
|
||||
Dimension c = fact.getSize(null, 1);
|
||||
int cw = c.width;
|
||||
int ch = c.height;
|
||||
|
||||
// Find the first day of the month
|
||||
|
||||
ZZCell curday = accursed.h("d.event").h("d.events");
|
||||
ZZCell mfirst = curday.h("d.day");
|
||||
|
||||
|
||||
|
||||
|
||||
if(mfirst.s("d.weekday") == null) {
|
||||
into.add(new Renderable() {
|
||||
{ d = 1; }
|
||||
public void render(Graphics g) {
|
||||
g.setColor(Color.red);
|
||||
g.setFont(new Font("SansSerif", Font.BOLD, 32));
|
||||
g.drawString("Not calendar data", 20, 40);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
int day = Integer.parseInt(mfirst.s("d.weekday").t());
|
||||
final int week = Integer.parseInt(mfirst.s("d.weekday",2).t());
|
||||
|
||||
into.add(new Renderable() {
|
||||
{ d = 50; }
|
||||
public void render(Graphics g) {
|
||||
Color old = g.getColor();
|
||||
g.setColor(Color.gray);
|
||||
g.setFont(nfont);
|
||||
g.drawRect(x, y, w, h);
|
||||
g.drawLine(x+xm, y, x+xm, y+h);
|
||||
g.drawLine(x, y+ym, x+w, y+ym);
|
||||
int fh = nfm.getHeight();
|
||||
for(int i=0; i<8; i++) {
|
||||
int tw = nfm.stringWidth(txts[i]);
|
||||
g.drawString(txts[i], x+(xm-tw)/2+i*xm, y+(ym+fh)/2);
|
||||
}
|
||||
for(int i=0; i<6; i++) {
|
||||
int tw = nfm.stringWidth(""+(i+week));
|
||||
g.drawString(""+(i+week), x+(xm-tw)/2, y+(ym+fh)/2+(i+1)*ym);
|
||||
}
|
||||
g.setColor(new Color(0xb0b0b0));
|
||||
for(int i=0; i<5; i++) {
|
||||
g.drawLine(x, y+(2+i)*ym, x+w, y+(2+i)*ym);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
LoopDetector l = new LoopDetector();
|
||||
int row = 0;
|
||||
for(ZZCell mday = mfirst; mday != null; mday = mday.s("d.day")) {
|
||||
l.detect(mday);
|
||||
boolean hasEv = (mday.s("d.events") != null);
|
||||
|
||||
fact.makeFlob(into, mday, mday, (hasEv ? (float)1.8 : 1),
|
||||
x+1+(1+day)*xm, y+1+(1+row)*ym, 2, xm-2, ym-2);
|
||||
|
||||
if(mday == curday) {
|
||||
// Ring it
|
||||
|
||||
}
|
||||
day += 1;
|
||||
if(day >= 7) row ++;
|
||||
day %= 7;
|
||||
}
|
||||
|
||||
row = 0;
|
||||
int fh = nfm.getHeight();
|
||||
for(ZZCell curev = curday.s("d.events");
|
||||
curev != null && curev != curday;
|
||||
curev = curev.s("d.events")) {
|
||||
fact.makeFlob(into, curev, curev, 1,
|
||||
x2 + 10, y + (ch+2)*row, 1, w-10-cw, ch);
|
||||
ZZCell txt = curev.s("d.event");
|
||||
fact.makeFlob(into, txt, txt, 1,
|
||||
x2 + w - cw, y + (ch+2)*row, 1, cw, ch);
|
||||
row ++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
// vim: set syntax=java :
|
||||
|
||||
116
Modules/daytimedemo/ClockCellView.zob
Normal file
116
Modules/daytimedemo/ClockCellView.zob
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
ClockCellView.zob
|
||||
*
|
||||
* Copyright (c) 2001, Benja Fallenstein
|
||||
*
|
||||
* You may use and distribute under the terms of either the GNU Lesser
|
||||
* General Public License, either version 2 of the license or,
|
||||
* at your choice, any later version. Alternatively, you may use and
|
||||
* distribute under the terms of the XPL.
|
||||
*
|
||||
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
|
||||
* the licenses.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README
|
||||
* file for more details.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Written by Benja Fallenstein
|
||||
*/
|
||||
|
||||
package org.gzigzag.module;
|
||||
import org.gzigzag.*;
|
||||
import java.util.*;
|
||||
import java.awt.*;
|
||||
|
||||
/** A cell view that shows the daytime demo clock, using a scene flob.
|
||||
* For use with ideosyncratic cell view. Create the cell to be shown as a
|
||||
* clock. Posward on d.3, connect the clock cell to a d.2 rank of appointments
|
||||
* in the regular DayTimeDemo structure (see DayTimeDemo.zob and the
|
||||
* CyberText article pictures). Then, from the clock cell negwards on
|
||||
* d.cellview create a new cell and write the cell view's name, e.g.
|
||||
* "Clock Cellview," in it. From that cell, create a new cell poswards on d.1
|
||||
* and write "DayTimeDemo.C" (of course w/o quotes) in it. Use F2 to switch
|
||||
* to the ideosyncratic cell view, and the clock cell should change its
|
||||
* appereance to a DayTimeDemo clock. (Best viewed with StretchVanishing or
|
||||
* Quad view, so that it's not shown that small.)
|
||||
*/
|
||||
|
||||
public class ClockCellView implements FlobFactory, ZOb {
|
||||
public static final String rcsid = "$Id: ClockCellView.zob,v 1.3 2001/03/18 17:50:16 bfallenstein Exp $";
|
||||
public static boolean dbg = false;
|
||||
private static void p(String s) { if(dbg) ZZLogger.log(s); }
|
||||
private static void pa(String s) { ZZLogger.log(s); }
|
||||
|
||||
STRUCTPARAMS {
|
||||
Font txtfont
|
||||
= new Font("Serif", Font.BOLD, 14);
|
||||
|
||||
Font clkfont
|
||||
= new Font("SansSerif", Font.PLAIN, 11);
|
||||
}
|
||||
|
||||
public Dimension getSize(ZZCell c, float fract) {
|
||||
return new Dimension((int)(150*fract), (int)(150*fract));
|
||||
}
|
||||
|
||||
DayTimeDemo dtd = new DayTimeDemo();
|
||||
|
||||
INITIALIZE {
|
||||
dtd.txtfont = txtfont;
|
||||
dtd.clkfont = clkfont;
|
||||
dtd.txtfm = FONTMETRICS(txtfont);
|
||||
dtd.clkfm = FONTMETRICS(clkfont);
|
||||
}
|
||||
|
||||
public Flob makeFlob(FlobSet into, ZZCell c, ZZCell handleCell,
|
||||
float fract,
|
||||
int x, int y, int d, int w, int h) {
|
||||
|
||||
FlobSet sc = new FlobSet(new Dimension(w, h), Color.white, Color.black,
|
||||
ScalableFont.fmComp);
|
||||
dtd.raster(sc, null, null, null, c.getRootclone().h("d.3", 1));
|
||||
|
||||
SceneFlob sf = new SimpleSceneFlob(x, y, d, w, h, c, sc);
|
||||
CellFlobFactory1.addSolidColors(into, sf, sf);
|
||||
into.add(sf);
|
||||
return sf;
|
||||
}
|
||||
|
||||
public Flob placeFlob(FlobSet into, ZZCell c, ZZCell handleCell,
|
||||
float fract,
|
||||
int x, int y, int depth,
|
||||
float xfract, float yfract) {
|
||||
Dimension d = getSize(c, fract);
|
||||
return makeFlob(into, c, handleCell, fract,
|
||||
(int)(x-xfract*d.width),
|
||||
(int)(y-yfract*d.height),
|
||||
depth, d.width, d.height);
|
||||
}
|
||||
|
||||
public Flob centerFlob(FlobSet into, ZZCell c, ZZCell handleCell,
|
||||
float fract, Point p, int xalign, int yalign,
|
||||
int depth, Dimension d) {
|
||||
if(d == null) d = getSize(c, fract);
|
||||
int x, y;
|
||||
x = p.x - d.width/2; y = p.y - d.height/2;
|
||||
|
||||
if(xalign < 0) x = p.x;
|
||||
if(xalign > 0) x = p.x - d.width;
|
||||
if(yalign < 0) y = p.y;
|
||||
if(yalign > 0) y = p.y - d.height;
|
||||
p("centerFlob "+p+" "+d+" at "+x+" "+y+" align "+xalign+" "+yalign);
|
||||
return makeFlob(into, c, handleCell, fract, x, y,
|
||||
depth, d.width, d.height);
|
||||
}
|
||||
public Flob centerFlob(FlobSet into, ZZCell c, ZZCell handleCell,
|
||||
float fract, Point p, int xalign, int yalign, int depth) {
|
||||
return centerFlob(into, c, handleCell, fract, p, xalign, yalign,
|
||||
depth, null);
|
||||
}
|
||||
}
|
||||
|
||||
// vim: set syntax=java :
|
||||
174
Modules/daytimedemo/DayTimeDemo.zob
Normal file
174
Modules/daytimedemo/DayTimeDemo.zob
Normal file
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
DayTimeDemo.zob
|
||||
*
|
||||
* Copyright (c) 2000, Ted Nelson and Tuomas Lukka
|
||||
*
|
||||
* You may use and distribute under the terms of either the GNU Lesser
|
||||
* General Public License, either version 2 of the license or,
|
||||
* at your choice, any later version. Alternatively, you may use and
|
||||
* distribute under the terms of the XPL.
|
||||
*
|
||||
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
|
||||
* the licenses.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README
|
||||
* file for more details.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Written by Tuomas Lukka
|
||||
*/
|
||||
package org.gzigzag.module;
|
||||
import org.gzigzag.*;
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
/** A simple raster showing times of day along a circle.
|
||||
* The structure is described along three dimensions:
|
||||
* hierarchy, sibling and cross-reference (d.1, d.2 and d.3 by default).
|
||||
* On these, the hierarchy is arranged as a corner list with an empty
|
||||
* corner cell, and the cross-references are simply siblings
|
||||
* connected.
|
||||
* <p>
|
||||
* The structure is specified as a rank on d.2 of d.1 lists:
|
||||
* start, end, type, text. Type's root clone will have the color
|
||||
* of the type on d.1.
|
||||
* <p>
|
||||
* The whole rank on d.2 is read.
|
||||
*/
|
||||
|
||||
public class DayTimeDemo implements FlobView, ZOb {
|
||||
public static boolean dbg = false;
|
||||
static final void p(String s) { if(dbg) System.out.println(s); }
|
||||
static final void pa(String s) { System.out.println(s); }
|
||||
|
||||
static public ZZModule module = new ZZModule() {
|
||||
public ZOb newZOb(String id) {
|
||||
if(id.equals("R"))
|
||||
return new DayTimeDemo();
|
||||
if(id.equals("C"))
|
||||
return new ClockCellView();
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
STRUCTPARAMS {
|
||||
Font txtfont
|
||||
= new Font("Serif", Font.BOLD, 14);
|
||||
|
||||
Font clkfont
|
||||
= new Font("SansSerif", Font.PLAIN, 11);
|
||||
}
|
||||
|
||||
FontMetrics txtfm, clkfm;
|
||||
|
||||
INITIALIZE {
|
||||
txtfm = FONTMETRICS(txtfont);
|
||||
clkfm = FONTMETRICS(clkfont);
|
||||
}
|
||||
|
||||
static final String next = "d.2";
|
||||
static final String hier = "d.1";
|
||||
static final String cross = "d.3";
|
||||
|
||||
static final int time2deg(String time) {
|
||||
int i = time.indexOf(":");
|
||||
if(i < 0) return 0;
|
||||
String t1 = time.substring(0,i);
|
||||
String t2 = time.substring(i+1);
|
||||
int h = -1;
|
||||
int m = -1;
|
||||
try {
|
||||
h = Integer.parseInt(t1);
|
||||
m = Integer.parseInt(t2);
|
||||
} catch(NumberFormatException e) {
|
||||
System.out.println("Exc: "+e);
|
||||
}
|
||||
return -(int)(360 * (h*60.0 + m) / (24*60)) - 90;
|
||||
}
|
||||
|
||||
static final Point deg2pt(int deg, int w, int h) {
|
||||
return new Point((int)(w/2*Math.cos(deg * Math.PI / 180)),
|
||||
-(int)(h/2*Math.sin(deg * Math.PI / 180)));
|
||||
}
|
||||
|
||||
public void raster(FlobSet into, FlobFactory fact,
|
||||
ZZCell view, String[] dims, ZZCell accursed) {
|
||||
|
||||
Dimension s = into.getSize();
|
||||
|
||||
final int x = s.width / 10;
|
||||
final int y = s.height / 10;
|
||||
final int w = s.width - 2 * x;
|
||||
final int h = s.height - 2 * y;
|
||||
|
||||
// Clock face.
|
||||
into.add(new Renderable() {
|
||||
{ d = 50; }
|
||||
public void render(Graphics g) {
|
||||
Color old = g.getColor();
|
||||
g.setColor(Color.black);
|
||||
g.setFont(clkfont);
|
||||
for(int i=0; i<24; i++) {
|
||||
int and = time2deg(i+":00");
|
||||
// g.fillArc(x, y, w, h, and, 1);
|
||||
Point p = deg2pt(and, w, h);
|
||||
p.x *= 1.05;
|
||||
p.y *= 1.05;
|
||||
p.translate(x+w/2, y+h/2);
|
||||
g.drawLine(x+w/2, y+h/2, p.x, p.y);
|
||||
if(i % 2 == 0) {
|
||||
String str = i+":00";
|
||||
g.drawString(str, p.x - clkfm.stringWidth(str)/2 , p.y);
|
||||
}
|
||||
}
|
||||
g.setColor(old);
|
||||
}
|
||||
});
|
||||
|
||||
for(
|
||||
ZZCell cur = accursed.h("d.1", -1).h("d.2", -1);
|
||||
cur != null;
|
||||
cur = cur.s("d.2", 1)) {
|
||||
ZZCell c = cur;
|
||||
String start = c.getText(); c = c.s("d.1", 1);
|
||||
String end = c.getText(); c = c.s("d.1", 1);
|
||||
ZZCell meet = c.h("d.clone", -1).s("d.1", 1);
|
||||
String col = "0xffffff";
|
||||
if(meet != null) col = meet.getText();
|
||||
c = c.s("d.1", 1);
|
||||
|
||||
final String text = c.getText();
|
||||
final int sang = time2deg(start);
|
||||
final int eang = time2deg(end);
|
||||
final Color color = Color.decode(col);
|
||||
|
||||
// now, render it.
|
||||
into.add(new Renderable() {
|
||||
{ d = 50; }
|
||||
public void render(Graphics g) {
|
||||
g.setColor(color);
|
||||
g.fillArc(x, y, w, h, sang, eang-sang);
|
||||
}});
|
||||
into.add(new Renderable() {
|
||||
{ d = 45; }
|
||||
public void render(Graphics g) {
|
||||
g.setFont(txtfont);
|
||||
Point p = deg2pt((sang+eang)/2, w, h);
|
||||
p.x *= 0.8;
|
||||
p.y *= 0.8;
|
||||
p.translate(x+w/2, y+h/2);
|
||||
g.setColor(Color.black);
|
||||
g.drawString(text, p.x, p.y);
|
||||
g.fillOval(p.x-8, p.y-8, 8, 8);
|
||||
}});
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
// vim: set syntax=java :
|
||||
Reference in New Issue
Block a user