[Swift-commit] r2818 - trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui
noreply at svn.ci.uchicago.edu
noreply at svn.ci.uchicago.edu
Sat Apr 4 16:15:59 CDT 2009
Author: hategan
Date: 2009-04-04 16:15:56 -0500 (Sat, 04 Apr 2009)
New Revision: 2818
Modified:
trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Button.java
trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Component.java
trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Container.java
trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/DefaultTableCellRenderer.java
trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Dialog.java
trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Frame.java
trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/LayeredContainer.java
trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Screen.java
trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Table.java
trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/TableColumn.java
Log:
better handling of focus/focus colors
Modified: trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Button.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Button.java 2009-04-04 21:15:02 UTC (rev 2817)
+++ trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Button.java 2009-04-04 21:15:56 UTC (rev 2818)
@@ -15,8 +15,8 @@
public Button(String label) {
setLabel(label);
- bgColor = ANSI.BLACK;
- fgColor = ANSI.WHITE;
+ bgColor = ANSI.WHITE;
+ fgColor = ANSI.BLACK;
}
public Button() {
@@ -43,21 +43,22 @@
context.lock();
try {
context.moveTo(sx, sy);
+ context.fgColor(getFgColor());
+ context.bgColor(getBgColor());
+ context.putChar('[');
if (this.hasFocus()) {
- context.putChar('[');
+ context.bgColor(ANSI.YELLOW);
}
- else {
- context.putChar(' ');
- }
context.spaces(pad);
twlabel.draw(context);
+ if (this.hasFocus()) {
+ context.bgColor(ANSI.YELLOW);
+ }
context.spaces(width - 2 - pad - len);
- if (this.hasFocus()) {
- context.putChar(']');
- }
- else {
- context.putChar(' ');
- }
+
+ context.bgColor(getBgColor());
+ context.fgColor(getFgColor());
+ context.putChar(']');
}
finally {
context.unlock();
Modified: trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Component.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Component.java 2009-04-04 21:15:02 UTC (rev 2817)
+++ trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Component.java 2009-04-04 21:15:56 UTC (rev 2818)
@@ -5,12 +5,14 @@
import java.io.IOException;
+import org.apache.log4j.Logger;
+
public class Component {
public static final int BOTTOM_LAYER = 0;
public static final int NORMAL_LAYER = 1;
public static final int TOP_LAYER = 2;
- protected int x, y, width, height, bgColor, fgColor;
+ protected int x, y, width, height, bgColor, fgColor, focusedBgColor;
protected int sx, sy;
private boolean visible, valid, focus, focusable;
private Screen screen;
@@ -19,6 +21,8 @@
public Component() {
visible = true;
+ focusable = true;
+ focusedBgColor = ANSI.YELLOW;
}
protected void redraw() {
@@ -117,6 +121,14 @@
this.fgColor = fgColor;
}
+ public int getFocusedBgColor() {
+ return focusedBgColor;
+ }
+
+ public void setFocusedBgColor(int focusedBgColor) {
+ this.focusedBgColor = focusedBgColor;
+ }
+
protected void draw(ANSIContext context) throws IOException {
}
@@ -191,15 +203,19 @@
if (parent.focus()) {
focus = parent.childFocused(this);
}
+ redraw();
}
return focus;
}
public boolean unfocus() {
- focus = false;
- Container parent = getParent();
- if (parent != null) {
- parent.childUnfocused(this);
+ if (focus) {
+ focus = false;
+ Container parent = getParent();
+ if (parent != null) {
+ parent.childUnfocused(this);
+ }
+ redraw();
}
return true;
}
@@ -234,4 +250,17 @@
public void setLayer(int layer) {
this.layer = layer;
}
+
+ public boolean focusNext() {
+ return false;
+ }
+
+ public boolean focusFirst() {
+ if (isFocusable()) {
+ return focus();
+ }
+ else {
+ return false;
+ }
+ }
}
Modified: trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Container.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Container.java 2009-04-04 21:15:02 UTC (rev 2817)
+++ trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Container.java 2009-04-04 21:15:56 UTC (rev 2818)
@@ -9,108 +9,173 @@
import java.util.List;
public class Container extends Component {
- protected List components;
- protected Component focused, oldFocused;
-
+ protected List components;
+ protected Component focused, oldFocused;
+ private Boolean focusable;
+
public Container() {
components = new ArrayList();
}
-
+
public void add(Component comp) {
- components.add(comp);
+ components.add(comp);
comp.setParent(this);
invalidate();
}
-
+
public void remove(Component comp) {
- components.remove(comp);
- if (focused == comp) {
- focused = null;
- }
- invalidate();
+ components.remove(comp);
+ if (focused == comp) {
+ focused = null;
+ }
+ invalidate();
}
-
+
+ protected void invalidate() {
+ super.invalidate();
+ focusable = null;
+ }
+
public List getComponents() {
- return components;
+ return components;
}
-
+
public void removeAll() {
- components.clear();
- invalidate();
+ components.clear();
+ invalidate();
}
-
+
protected void drawTree(ANSIContext context) throws IOException {
- super.drawTree(context);
+ super.drawTree(context);
Iterator i = components.iterator();
while (i.hasNext()) {
- Component c = (Component) i.next();
- if (c.isVisible()) {
- drawChild(c, context);
- }
+ Component c = (Component) i.next();
+ if (c.isVisible()) {
+ drawChild(c, context);
+ }
}
}
-
- protected void drawChild(Component c, ANSIContext context) throws IOException {
- c.drawTree(context);
+
+ protected void drawChild(Component c, ANSIContext context)
+ throws IOException {
+ c.drawTree(context);
}
- protected void validate() {
- if (isValid()) {
- return;
- }
- Iterator i = components.iterator();
- boolean focus = false;
+ protected void validate() {
+ if (isValid()) {
+ return;
+ }
+ Iterator i = components.iterator();
+ boolean focus = false;
while (i.hasNext()) {
- Component c = (Component) i.next();
- if (c.hasFocus() && !hasFocus()) {
- focus();
- }
+ Component c = (Component) i.next();
+ if (c.hasFocus() && !hasFocus()) {
+ focus();
+ }
c.validate();
}
super.validate();
- }
+ }
- public boolean childFocused(Component component) {
- oldFocused = focused;
- boolean f = true;
- if (focused != null) {
- f = focused.unfocus();
- if (f) {
- focused.focusLost();
- }
- }
- if (f) {
- focused = component;
- focused.focusGained();
- }
- return f;
- }
-
- public void childUnfocused(Component component) {
+ public boolean childFocused(Component component) {
+ oldFocused = focused;
+ boolean f = true;
+ if (focused != null) {
+ f = focused.unfocus();
+ if (f) {
+ focused.focusLost();
+ }
+ }
+ if (f) {
+ focused = component;
+ focused.focusGained();
+ }
+ return f;
+ }
+
+ public void childUnfocused(Component component) {
if (oldFocused != null && oldFocused != component) {
oldFocused.focus();
}
}
-
- public boolean keyboardEvent(Key key) {
- if (key.modALT() || key.isFunctionKey()) {
- Iterator i = components.iterator();
- while (i.hasNext()) {
- if (((Component) i.next()).keyboardEvent(key)) {
- return true;
- }
- }
- return false;
- }
- else if (focused != null) {
- return focused.keyboardEvent(key);
- }
- else {
- return false;
- }
- }
-
- public Component getFocusedComponent() {
- return focused;
- }
+
+ public boolean keyboardEvent(Key key) {
+ if (key.modALT() || key.isFunctionKey()) {
+ Iterator i = components.iterator();
+ while (i.hasNext()) {
+ if (((Component) i.next()).keyboardEvent(key)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ else if (focused != null) {
+ return focused.keyboardEvent(key);
+ }
+ else {
+ return false;
+ }
+ }
+
+ public Component getFocusedComponent() {
+ return focused;
+ }
+
+ public boolean unfocus() {
+ if (focused != null && !focused.unfocus()) {
+ return false;
+ }
+ return super.unfocus();
+ }
+
+ public boolean focusFirst() {
+ Iterator j = components.iterator();
+ while (j.hasNext()) {
+ Component comp = (Component) j.next();
+ if (comp.focusFirst()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public boolean focusNext() {
+ if (focused == null) {
+ return focusFirst();
+ }
+ else if (focused.focusNext()) {
+ return true;
+ }
+ Iterator i = components.iterator();
+ while (i.hasNext()) {
+ if (i.next() == focused) {
+ while (i.hasNext()) {
+ Component comp = (Component) i.next();
+ if (comp.isFocusable()) {
+ comp.focus();
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+ return false;
+ }
+
+ public boolean isFocusable() {
+ Boolean f = focusable;
+ if (f != null) {
+ return f.booleanValue();
+ }
+ Iterator i = components.iterator();
+ while (i.hasNext()) {
+ if (((Component) i.next()).isFocusable()) {
+ focusable = Boolean.TRUE;
+ return true;
+ }
+ }
+ //focusable = Boolean.FALSE;
+ return false;
+ }
+
}
Modified: trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/DefaultTableCellRenderer.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/DefaultTableCellRenderer.java 2009-04-04 21:15:02 UTC (rev 2817)
+++ trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/DefaultTableCellRenderer.java 2009-04-04 21:15:56 UTC (rev 2818)
@@ -18,19 +18,25 @@
public Component getComponent(Table table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
- setColors(table, isSelected);
+ setColors(table, isSelected, hasFocus);
label.setText(String.valueOf(value));
return label;
}
- private void setColors(Table table, boolean selected) {
+ private void setColors(Table table, boolean selected, boolean hasFocus) {
if (!selected) {
label.setBgColor(table.getBgColor());
label.setFgColor(table.getFgColor());
}
else {
- label.setBgColor(table.getHighlightBgColor());
- label.setFgColor(table.getHighlightFgColor());
+ if (hasFocus) {
+ label.setBgColor(table.getFocusedBgColor());
+ label.setFgColor(table.getFgColor());
+ }
+ else {
+ label.setBgColor(table.getHighlightBgColor());
+ label.setFgColor(table.getHighlightFgColor());
+ }
}
}
Modified: trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Dialog.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Dialog.java 2009-04-04 21:15:02 UTC (rev 2817)
+++ trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Dialog.java 2009-04-04 21:15:56 UTC (rev 2818)
@@ -3,47 +3,48 @@
*/
package org.griphyn.vdl.karajan.monitor.monitors.ansi.tui;
+import java.util.Iterator;
public class Dialog extends Frame {
- private Component sfocus;
+ private Component sfocus;
- public Dialog() {
- bgColor = ANSI.WHITE;
- fgColor = ANSI.BLACK;
- setFilled(true);
- }
+ public Dialog() {
+ bgColor = ANSI.WHITE;
+ fgColor = ANSI.BLACK;
+ setFilled(true);
+ }
- public void display(Screen screen) {
- sfocus = screen.getFocusedComponent();
- screen.add(this);
- focus();
- }
+ public void display(Screen screen) {
+ sfocus = screen.getFocusedComponent();
+ screen.add(this);
+ focusFirst();
+ }
- public void close() {
- getScreen().remove(this);
- setVisible(false);
- if (sfocus != null) {
- sfocus.focus();
- }
- }
+ public void close() {
+ getScreen().remove(this);
+ setVisible(false);
+ if (sfocus != null) {
+ sfocus.focus();
+ }
+ }
- public void center(Container c) {
- x = (c.getWidth() - width) / 2;
- y = (c.getHeight() - height) / 2;
- }
+ public void center(Container c) {
+ x = (c.getWidth() - width) / 2;
+ y = (c.getHeight() - height) / 2;
+ }
- public boolean keyboardEvent(Key key) {
- if (key.getKey() == Key.ESC) {
- close();
- return true;
- }
- else {
- return super.keyboardEvent(key);
- }
- }
+ public boolean keyboardEvent(Key key) {
+ if (key.getKey() == Key.ESC) {
+ close();
+ return true;
+ }
+ else {
+ return super.keyboardEvent(key);
+ }
+ }
- public static int displaySimpleDialog(Screen screen, String title, String msg,
- String[] buttons) {
+ public static int displaySimpleDialog(Screen screen, String title,
+ String msg, String[] buttons) {
final Dialog d = new Dialog();
d.setTitle(title);
Label l = new Label();
@@ -68,7 +69,8 @@
}
}
d.close();
- }});
+ }
+ });
d.add(bs[i]);
}
d.center(screen);
@@ -84,4 +86,25 @@
}
return r[0];
}
+
+ public boolean focusNext() {
+ if (focused == null) {
+ return focusFirst();
+ }
+ else if (focused.focusNext()) {
+ return true;
+ }
+ Iterator i = components.iterator();
+ while (i.hasNext()) {
+ if (i.next() == focused) {
+ while (i.hasNext()) {
+ Component comp = (Component) i.next();
+ if (comp.focusFirst()) {
+ return true;
+ }
+ }
+ }
+ }
+ return focusFirst();
+ }
}
Modified: trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Frame.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Frame.java 2009-04-04 21:15:02 UTC (rev 2817)
+++ trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Frame.java 2009-04-04 21:15:56 UTC (rev 2818)
@@ -21,11 +21,11 @@
context.bgColor(bgColor);
context.fgColor(fgColor);
if (filled) {
- context.filledFrame(sx, sy, width, height);
+ context.filledRect(sx + 1, sy + 1, width - 2, height - 2);
}
- else {
- context.frame(sx, sy, width, height);
- }
+
+ context.frame(sx, sy, width, height);
+ context.bgColor(bgColor);
if (title != null) {
int tl = title.length() + 2;
int space = width - tl;
Modified: trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/LayeredContainer.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/LayeredContainer.java 2009-04-04 21:15:02 UTC (rev 2817)
+++ trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/LayeredContainer.java 2009-04-04 21:15:56 UTC (rev 2818)
@@ -114,6 +114,20 @@
return keyboardEvent(key, TOP_LAYER) || keyboardEvent(key, NORMAL_LAYER)
|| keyboardEvent(key, BOTTOM_LAYER);
}
+ else if (key.equals(Key.TAB)) {
+ if (focused == null) {
+ focusFirst();
+ }
+ else {
+ if (focused.keyboardEvent(key)) {
+ return true;
+ }
+ else {
+ focused.focusNext();
+ }
+ }
+ return true;
+ }
else if (focused != null) {
return focused.keyboardEvent(key);
}
@@ -122,7 +136,50 @@
}
}
- protected boolean keyboardEvent(Key key, int layer) {
+ public boolean focusFirst() {
+ for (int i = 0; i < layers.length; i++) {
+ if (layers[i] != null) {
+ Iterator j = layers[i].iterator();
+ if (j.hasNext()) {
+ Component comp = (Component) j.next();
+ if (((Component) j.next()).focusFirst()) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+
+ public boolean focusNext() {
+ boolean found = false;
+ if (focused == null) {
+ return focusFirst();
+ }
+ else if (focused.focusNext()) {
+ return true;
+ }
+
+ for (int i = 0; i < layers.length; i++) {
+ if (layers[i] != null) {
+ Iterator j = layers[i].iterator();
+ while (j.hasNext()) {
+ if (found) {
+ if (((Component) j.next()).focusFirst()) {
+ return true;
+ }
+ }
+ if (j.next() == focused) {
+ found = true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ protected boolean keyboardEvent(Key key, int layer) {
if (layers[layer] == null) {
return false;
}
Modified: trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Screen.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Screen.java 2009-04-04 21:15:02 UTC (rev 2817)
+++ trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Screen.java 2009-04-04 21:15:56 UTC (rev 2818)
@@ -42,7 +42,7 @@
context.fgColor(fgColor);
drawTree(context);
if (status != null) {
- context.moveTo(0, height);
+ context.moveTo(1, height);
context.bgColor(ANSI.RED);
context.fgColor(ANSI.YELLOW);
context.text(status);
Modified: trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Table.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Table.java 2009-04-04 21:15:02 UTC (rev 2817)
+++ trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/Table.java 2009-04-04 21:15:56 UTC (rev 2818)
@@ -210,4 +210,18 @@
public int getHighlightBgColor() {
return fgColor;
}
+
+ public boolean isFocusable() {
+ return true;
+ }
+
+
+ public boolean focusFirst() {
+ focus();
+ return true;
+ }
+
+ public boolean focusNext() {
+ return false;
+ }
}
Modified: trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/TableColumn.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/TableColumn.java 2009-04-04 21:15:02 UTC (rev 2817)
+++ trunk/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/TableColumn.java 2009-04-04 21:15:56 UTC (rev 2818)
@@ -28,7 +28,7 @@
int fr = table.getFirstRow();
for (int i = 0; i < Math.min(model.getRowCount(), height - 2); i++) {
Component comp = table.getCellRenderer().getComponent(table,
- model.getValueAt(i + fr, index), i + fr == selectedRow, false,
+ model.getValueAt(i + fr, index), i + fr == selectedRow, getParent().hasFocus(),
i + fr, index);
comp.setAbsoluteLocation(sx, sy + i + 2);
comp.setSize(getWidth(), 1);
More information about the Swift-commit
mailing list