[go: up one dir, main page]

Menu

[r99]: / decker / view / UIBorder.java  Maximize  Restore  History

Download this file

136 lines (123 with data), 4.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package decker.view;
import decker.model.*;
import java.awt.*;
final class UIBorder extends DisplayedComponent
{
public static boolean PRINT_ILLEGAL_BORDER_SIZE_WARNING = false;
private Color left, top, right, bottom, background;
private int thickness;
boolean inverted;
UIBorder (final DisplayedComponent _parent, final DisplayedComponent current_clip_source, final boolean use_default_background_color) {
super(null, _parent, current_clip_source);
final Structure global_values = ScriptNode.getStackEntry(ScriptNode.RULESET_STACK_SLOT).get("GLOBAL_VALUES").structure();;
left = AbstractView.getColor(global_values.get("BORDER_COLOR1").string());
top = left;
right = AbstractView.getColor(global_values.get("BORDER_COLOR2").string());
bottom = right;
inverted = false;
thickness = 2;
Value v;
if ((v=ScriptNode.getValue("DEFAULT_BORDER_THICKNESS")).type() == Value.INTEGER)
thickness = v.integer();
if (use_default_background_color)
background = AbstractView.getColor(global_values.get("BACKGROUND_COLOR").string());
}
UIBorder (final Value _component, final DisplayedComponent _parent, final DisplayedComponent current_clip_source) {
super(_component, _parent, current_clip_source);
updateBorder();
updateChildren(current_clip_source);
}
void draw (final Graphics g) {
final int t = thickness;
// don't draw the border if it has a negative size
if (w < 2*t || h < 2*t) {
if (PRINT_ILLEGAL_BORDER_SIZE_WARNING) {
PRINT_ILLEGAL_BORDER_SIZE_WARNING = false; // print the warning only once
new RuntimeException("Warning in UIBorder.draw() : negative border size. x="+x+" y="+y+" w="+w+" h="+h).printStackTrace();
}
return;
}
// draw the background
if (background != null && w-2*t > 0 && h-2*t > 0) {
g.setColor(background);
g.fillRect(x+t, y+t, w-2*t, h-2*t);
}
// draw the border
final int w1 = w-1, h1 = h-1;
if (!inverted) {
// draw the top border
g.setColor(top);
for (int i = t; --i >= 0; )
g.drawLine(x+i, y+i, x+w1-i, y+i);
// draw the left border
g.setColor(left);
for (int i = t; --i >= 0; )
g.drawLine(x+i, y+i+1, x+i, y+h1-i);
// draw the right border
g.setColor(right);
for (int i = t; --i >= 0; )
g.drawLine(x+w1-i, y+i+1, x+w1-i, y+h1-i);
// draw the bottom border
g.setColor(bottom);
for (int i = t; --i >= 0; )
g.drawLine(x+i+1, y+h1-i, x+w1-i-1, y+h1-i);
}
else {
// draw the bottom border
g.setColor(top);
for (int i = t; --i >= 0; )
g.drawLine(x+i, y+h1-i, x+w1-i, y+h1-i);
// draw the right border
g.setColor(left);
for (int i = t; --i >= 0; )
g.drawLine(x+w1-i, y+i, x+w1-i, y+h1-i-1);
// draw the left border
g.setColor(right);
for (int i = t; --i >= 0; )
g.drawLine(x+i, y+i+1, x+i, y+h1-i-1);
// draw the top border
g.setColor(bottom);
for (int i = t; --i >= 0; )
g.drawLine(x+i, y+i, x+w1-i-1, y+i);
}
// draw the child components
final DisplayedComponent[] c = child;
final int cc = child_count;
for (int i = 0; i < cc; i++)
c[i].draw(g);
}
void update (final int customSettings, final DisplayedComponent current_clip_source) {
super.update(customSettings, current_clip_source);
updateBorder();
}
private void updateBorder () {
if (component != null && component.type() == Value.STRUCTURE && component.get("structure_type").equals("BORDER")) {
Value v;
inverted = component.get("inverted").equals(true);
background = AbstractView.getColor(component.get("background_color").toString());
Value vtc = component.get("top_color"), vlc = component.get("left_color"), vrc = component.get("right_color"), vbc = component.get("bottom_color");
if (vtc.equalsConstant("UNDEFINED"))
vtc = vlc;
else if (vlc.equalsConstant("UNDEFINED"))
vlc = vtc;
if (vrc.equalsConstant("UNDEFINED")) {
if (!vbc.equalsConstant("UNDEFINED"))
vrc = vbc;
else
vrc = vlc;
}
if (vbc.equalsConstant("UNDEFINED"))
vbc = vrc;
left = AbstractView.getColor(vlc.toString());
top = AbstractView.getColor(vtc.toString());
right = AbstractView.getColor(vrc.toString());
bottom = AbstractView.getColor(vbc.toString());
// determine the line thickness
thickness = 2;
if ((v=component.get("thickness")).type() == Value.INTEGER)
thickness = v.integer();
else if ((v=ScriptNode.getValue("DEFAULT_BORDER_THICKNESS")).type() == Value.INTEGER)
thickness = v.integer();
}
}
}