33 |
*/ |
*/ |
34 |
public class LastOpDecorator implements FallbackSceneDecorator { |
public class LastOpDecorator implements FallbackSceneDecorator { |
35 |
String rcsid = "$Id$"; |
String rcsid = "$Id$"; |
36 |
public static boolean dbg = false; |
public static boolean dbg = true; |
37 |
private static void pa(String s) { System.err.println(s); } |
private static void pa(String s) { System.err.println(s); } |
38 |
|
|
39 |
static TextStyle style = |
static TextStyle style = |
40 |
GraphicsAPI.getInstance().getTextStyle("SansSerif", Font.PLAIN, 16); |
GraphicsAPI.getInstance().getTextStyle("SansSerif", Font.PLAIN, 16); |
41 |
static Object key = new Object(); |
static Object key = new Object(); |
42 |
|
static SimpleLinebreaker breaker = new SimpleLinebreaker(); |
43 |
|
static CellVobFactory cvf = new CellVobFactory(); |
44 |
|
|
45 |
int padding = 15; |
int padding = 15; |
46 |
|
|
47 |
public void render(VobScene sc, int into, Fallback fallback, Fallback.Win win) { |
public void render(VobScene sc, int into, Fallback fallback, Fallback.Win win) { |
48 |
Dimension size = sc.getSize(); |
Dimension size = sc.getSize(); |
49 |
|
|
50 |
String s; |
HChain ch = new LinebreakableChain(); |
51 |
|
cvf.setCenter(win.cursor); |
52 |
|
|
53 |
if(dbg) pa("fallback.binder.directOp: "+fallback.binder.directOp); |
if(dbg) pa("fallback.binder.directOp: "+fallback.binder.directOp); |
54 |
|
|
55 |
if(fallback.mode == fallback.NORMAL) { |
if(fallback.mode == fallback.NORMAL) { |
56 |
switch(fallback.binder.directOp) { |
switch(fallback.binder.directOp) { |
57 |
case FallbackBinder.NONE: return; |
case FallbackBinder.NONE: return; |
58 |
case FallbackBinder.CONNECT: |
case FallbackBinder.CONNECT: |
59 |
s = "Connect [where?] to " + cell(win.other.cursor); |
ch.addBox(text("Connect [where?] to ")); |
60 |
|
ch.addBox(cell(win.other.cursor, win)); |
61 |
break; |
break; |
62 |
case FallbackBinder.DISCONNECT: |
case FallbackBinder.DISCONNECT: |
63 |
s = "Break [which connection?]"; break; |
ch.addBox(text("Break [which connection?]")); break; |
64 |
case FallbackBinder.HOP: |
case FallbackBinder.HOP: |
65 |
s = "Hop [in which direction?]"; break; |
ch.addBox(text("Hop [in which direction?]")); break; |
66 |
case FallbackBinder.NEW: |
case FallbackBinder.NEW: |
67 |
s = "Create a new cell [where?]"; break; |
ch.addBox(text("Create a new cell [where?]")); break; |
68 |
case FallbackBinder.CLONE_R: |
case FallbackBinder.CLONE_R: |
69 |
s = "Clone " + cell(fallback.windows[1].cursor) + " [where?]"; |
ch.addBox(text("Clone ")); |
70 |
|
ch.addBox(cell(fallback.windows[1].cursor, win)); |
71 |
|
ch.addBox(text(" [where?]", 2)); |
72 |
break; |
break; |
73 |
case FallbackBinder.CLONE_L: |
case FallbackBinder.CLONE_L: |
74 |
s = "Clone " + cell(fallback.windows[0].cursor) + " [where?]"; |
ch.addBox(text("Clone ")); |
75 |
|
ch.addBox(cell(fallback.windows[0].cursor, win)); |
76 |
|
ch.addBox(text(" [where?]", 2)); |
77 |
break; |
break; |
78 |
default: |
default: |
79 |
throw new IllegalArgumentException("DirOp not known: " + |
throw new IllegalArgumentException("DirOp not known: " + |
80 |
fallback.binder.directOp); |
fallback.binder.directOp); |
81 |
} |
} |
82 |
} else if(fallback.mode == fallback.TEXT_1) |
} else if(fallback.mode == fallback.TEXT_1) |
83 |
s = "Text edit mode (press Tab to finish editing)."; |
ch.addBox(text("Text edit mode (press Tab to finish editing).")); |
84 |
else if(fallback.mode == fallback.SEARCH) |
else if(fallback.mode == fallback.SEARCH) |
85 |
s = "Search for: " + fallback.binder.buffer; |
ch.addBox(text("Search for: " + fallback.binder.buffer)); |
86 |
else return; |
else return; |
87 |
|
|
88 |
int w = (int)style.getWidth(s, 1.0f); |
float w = size.width - 2*padding; |
89 |
int h = (int)style.getHeight(1.0f); |
HBroken br = breaker.breakLines(ch, w, 1.0f); |
90 |
|
float h = br.getHeight(); |
|
int x = padding; |
|
|
int y = size.height - padding - h; |
|
91 |
|
|
92 |
TextVob vob = new TextVob(style, s); |
float x = padding; |
93 |
|
float y = size.height - padding - h; |
94 |
|
|
95 |
int cs = sc.coords.coordsys(into, key, 0, x, y, w, h); |
int cs = sc.coords.coordsys(into, key, 0, x, y, w, h); |
|
sc.map.put(vob, cs); |
|
96 |
|
|
97 |
if(dbg) pa("Put "+vob+" in cs "+cs+" @ "+x+" "+y+" "+w+" "+h+" ("+size+")"); |
br.put(sc, cs); |
|
} |
|
98 |
|
|
99 |
/** Format a cell's text as part of an opstring. */ |
if(dbg) pa("Put "+br+" "+ch.length()+" in cs "+cs+" @ "+x+" "+y+" "+w+" "+h+" ("+size+")"); |
100 |
String cell(Cell c) { |
} |
|
if(c == null) return "[which cell?]"; |
|
101 |
|
|
102 |
String t = c.t(); |
/** Get the HBox for some text. */ |
103 |
|
HBox text(String s, int i) { |
104 |
|
return new TextVob(style, 1.0f, s, new Integer(i)); |
105 |
|
} |
106 |
|
|
107 |
// Show only first line |
HBox text(String s) { return text(s, 1); } |
|
int n = t.indexOf('\n'); |
|
|
if(n > 0) |
|
|
t = t.substring(0, n); |
|
108 |
|
|
109 |
// Enclose in '' |
/** Get the HBox for a cell (as part of the cell's opstring). */ |
110 |
t = "'" + t + "'"; |
HBox cell(Cell c, ViewContext context) { |
111 |
|
if(c == null) return text("[which cell?]"); |
112 |
|
|
113 |
return "cell " + t; |
return new CellHBox(c, cvf, context); |
114 |
} |
} |
115 |
} |
} |