Commit 16c78731 authored by Chad Barb's avatar Chad Barb

parent ce248568
......@@ -21,6 +21,8 @@ class Expando extends Component
text = t;
expanded = true;
setCursor( Cursor.getPredefinedCursor( Cursor.HAND_CURSOR ) );
enableEvents( AWTEvent.MOUSE_EVENT_MASK );
enableEvents( AWTEvent.MOUSE_MOTION_EVENT_MASK );
}
......@@ -57,6 +59,7 @@ class Expando extends Component
int stringWidth = fm.stringWidth(text);
return new Dimension(16 + 4 + stringWidth, 16);
}
g.dispose();
}
return new Dimension(32, 32);
......
import java.awt.*;
import java.awt.event.*;
class Linko extends Canvas
class FlatButton extends Canvas
{
String text;
boolean mouseIsOver;
ActionListener myActionListener;
private static Color lightBlue;
private static Color darkerBlue;
static {
lightBlue = new Color( 0.7f, 0.7f, 1.0f );
lightBlue = new Color( 0.7f, 0.7f, 1.0f );
darkerBlue = new Color( 0.4f, 0.4f, 0.6f );
}
public Linko( String t )
public FlatButton( String t )
{
super();
setCursor( Cursor.getPredefinedCursor( Cursor.HAND_CURSOR ) );
text = t;
mouseIsOver = false;
myActionListener = null;
......@@ -26,17 +29,23 @@ class Linko extends Canvas
myActionListener = e;
}
protected void clicked() {
ActionEvent ce = new ActionEvent( this,
ActionEvent.ACTION_PERFORMED,
"clicked" );
if (myActionListener != null) {
myActionListener.actionPerformed( ce );
}
}
protected void processMouseEvent( MouseEvent e ) {
if (e.getID() == MouseEvent.MOUSE_ENTERED) {
mouseIsOver = true;
} else if (e.getID() == MouseEvent.MOUSE_EXITED) {
mouseIsOver = false;
} else if (e.getID() == MouseEvent.MOUSE_PRESSED) {
ActionEvent ce = new ActionEvent( this,
ActionEvent.ACTION_PERFORMED,
"clicked" );
if (myActionListener != null) {
myActionListener.actionPerformed( ce );
if (isEnabled()) {
clicked();
}
}
repaint();
......@@ -50,18 +59,30 @@ class Linko extends Canvas
FontMetrics fm = g.getFontMetrics();
if (fm != null) {
int stringWidth = fm.stringWidth(text);
return new Dimension( stringWidth, fm.getHeight() + 2 );
//return new Dimension( stringWidth + 12, fm.getHeight() + 6 );
return new Dimension( 640 - 480 - 16, fm.getHeight() + 8 );
}
g.dispose();
}
System.out.println("Crap.");
return new Dimension(200, 40);
}
public Dimension getMinimumSize() { return getPreferredSize(); }
public Dimension getMaximumSize() { return getPreferredSize(); }
public void setEnabled( boolean en )
{
/*
if (en) {
setCursor( Cursor.getPredefinedCursor( Cursor.HAND_CURSOR ) );
} else {
setCursor( Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR ) );
}
*/
super.setEnabled( en );
repaint();
}
public void paint( Graphics g )
{
FontMetrics fm = g.getFontMetrics();
......@@ -72,20 +93,31 @@ class Linko extends Canvas
Dimension size = getSize();
int begin = size.width / 2 - stringWidth / 2;
int end = size.width / 2 + stringWidth / 2;
int begin = size.width / 2 - stringWidth / 2 - 2;
//int end = size.width / 2 + stringWidth / 2;
if (isEnabled()) {
if (mouseIsOver) {
g.setColor( lightBlue );
} else {
g.setColor( darkerBlue );
}
g.fillRect( 0, 0, size.width, size.height );
g.setColor( Color.black );
} else {
g.setColor( Color.darkGray );
}
if (mouseIsOver) {
g.drawRect( 0, 0, size.width - 1, size.height - 1);
if (isEnabled()) {
g.setColor( Color.white );
g.drawLine( begin, stringHeight + 2, end, stringHeight + 2 );
} else {
g.setColor( lightBlue );
g.setColor( Color.lightGray );
}
g.drawString( text, (size.width / 2) - (stringWidth / 2), fm.getHeight() );
// g.drawLine( begin, stringHeight + 2, end, stringHeight + 2 );
g.drawString( text, begin, size.height / 2 + fm.getHeight() / 3 );
}
};
......@@ -9,7 +9,7 @@ public class IFacePropertiesArea extends PropertiesArea
public IFacePropertiesArea()
{
super();
addProperty("ip", "IP address:","<auto>");
addProperty("ip", "IP address:","<auto>", false, false);
}
};
......
......@@ -6,7 +6,16 @@ implements ImageObserver {
abstract public String getIconName();
protected Image loadIcon() {
return Netbuild.getImage( getIconName() );
Image i = Netbuild.getImage( getIconName() );
/*
if (i != null) {
System.out.println("loadIcon(): " + i.toString() );
} else {
System.out.println("loadIcon(): NULL" );
}
*/
return i;
//return null;
}
public void drawIcon( Graphics g, Image icon ) {
......
......@@ -9,8 +9,8 @@ public class LanLinkPropertiesArea extends PropertiesArea
public LanLinkPropertiesArea()
{
super();
addProperty("bandwidth", "bandwidth(Mb/s):", "100");
addProperty("latency", "latency(ms):", "0");
addProperty("loss", "loss rate(0.0-1.0):", "0.0");
addProperty("bandwidth", "bandwidth(Mb/s):", "100", false, false);
addProperty("latency", "latency(ms):", "0", false, false);
addProperty("loss", "loss rate(0.0-1.0):", "0.0", false, false);
}
};
......@@ -9,9 +9,9 @@ public class LanPropertiesArea extends PropertiesArea
public LanPropertiesArea()
{
super();
addProperty("name", "name:","");
addProperty("bandwidth", "bandwidth(Mb/s):", "100");
addProperty("latency", "latency(ms):", "0");
addProperty("loss", "loss rate(0.0 - 1.0):", "0.0");
addProperty("name", "name:","", true, false);
addProperty("bandwidth", "bandwidth(Mb/s):", "100", false, false);
addProperty("latency", "latency(ms):", "0", false, false);
addProperty("loss", "loss rate(0.0 - 1.0):", "0.0", false, false);
}
};
......@@ -9,9 +9,9 @@ public class LinkPropertiesArea extends PropertiesArea
public LinkPropertiesArea()
{
super();
addProperty("name", "name:", "");
addProperty("bandwidth", "bandwidth(Mb/s):", "100");
addProperty("latency", "latency(ms):", "0");
addProperty("loss", "loss rate(0.0 - 1.0):", "0.0");
addProperty("name", "name:", "", true, false);
addProperty("bandwidth", "bandwidth(Mb/s):", "100", false, false);
addProperty("latency", "latency(ms):", "0", false, false);
addProperty("loss", "loss rate(0.0 - 1.0):", "0.0", false, false);
}
};
......@@ -8,6 +8,17 @@ class MagicTextField implements TextListener, FocusListener {
private boolean zapped;
private boolean wasAuto;
private boolean alphaAllowed;
private boolean specialAllowed; // '+' and '_'
private boolean numAllowed;
private static Color darkGreen;
static {
// darkGreen = new Color( 0.20f, 0.55f, 0.20f );
darkGreen = new Color( 0.0f, 0.33f, 0.0f );
}
public void focusGained( FocusEvent f ) {
tf.selectAll();
}
......@@ -15,11 +26,15 @@ class MagicTextField implements TextListener, FocusListener {
public void focusLost( FocusEvent f ) {
}
public MagicTextField() {
tf = new TextField();
public MagicTextField(boolean nAlphaAllowed, boolean nNumAllowed, boolean nSpecialAllowed) {
tf = new TextField();
tf.addTextListener( this );
tf.addFocusListener( this );
wasAuto = false;
alphaAllowed = nAlphaAllowed;
numAllowed = nNumAllowed;
specialAllowed = nSpecialAllowed;
}
public void setText( String t ) {
......@@ -28,12 +43,23 @@ class MagicTextField implements TextListener, FocusListener {
tf.setText( t );
}
private boolean isAlphic( char c ) {
return "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(c, 0) != -1;
}
private boolean isNumeric( char c ) {
return "0123456789".indexOf(c, 0) != -1;
}
public void textValueChanged( TextEvent e ) {
if (0 == tf.getText().compareTo("<auto>")) {
String newText = tf.getText();
if (0 == newText.compareTo("<auto>")) {
//wasAuto = true;
tf.setForeground( Color.blue );
} else if (0 == tf.getText().compareTo("<multiple>")) {
tf.setForeground( Color.lightGray );
} else if (0 == newText.compareTo("<multiple>")) {
tf.setForeground( darkGreen );
//tf.setForeground( Color.green );
} else {
tf.setForeground( Color.black );
if (wasAuto) {
......@@ -41,7 +67,51 @@ class MagicTextField implements TextListener, FocusListener {
//tf.setText( "" );
//tf.dispatchEvent( e );
}
int caret = tf.getCaretPosition();
int i = 0;
// in perl, this would be one line.
String rep = newText;
while ( i != rep.length() ) {
char c = rep.charAt(i);
// valid if:
// alphaAllowed and its alphanumeric (or '-')
// (but not numeric or '-' if it is the first char)
// numAllowed and its numeric or "."
if (alphaAllowed && c == ' ') {
rep = rep.replace(' ', '-');
i++;
} else if ((alphaAllowed &&
(isAlphic( c ) || (i != 0 && (isNumeric(c) || c == '-')))) ||
(specialAllowed && i != 0 &&
(c == '_' || c == '+')) ||
(numAllowed &&
(isNumeric( c ) || c == '.'))) {
// legit.
i++;
} else {
// utter crap.
caret--;
if (i == rep.length() - 1) {
rep = rep.substring( 0, i );
} else {
rep = rep.substring(0, i) +
rep.substring(i + 1, rep.length());
}
}
}
if (rep.compareTo( newText ) != 0) {
tf.setText( rep );
}
try {
tf.setCaretPosition( caret );
} catch ( Exception ex ) {}
}
}
};
This diff is collapsed.
......@@ -10,8 +10,8 @@ public class NodePropertiesArea extends PropertiesArea
public NodePropertiesArea()
{
super();
addProperty("name", "name:","");
addProperty("hardware", "hardware:","<auto>");
addProperty("osid", "os id:","<auto>");
addProperty("name", "name:","", true, false);
addProperty("hardware", "hardware:","<auto>", true, false );
addProperty("osid", "os id:","<auto>", true, true );
}
};
......@@ -7,6 +7,7 @@ import java.util.Enumeration;
public class Palette {
private Thingee newNode;
private Thingee newLAN;
private Thingee copier;
private Thingee trash;
public Palette() {
......@@ -29,11 +30,19 @@ public class Palette {
trash.trashable = false; // very zen.
trash.moveable = false;
trash.propertyEditable = false;
copier = new Thingee( "copier" );
copier.move( 40, 340 );
copier.linkable = false;
copier.trashable = false;
copier.moveable = false;
copier.propertyEditable = false;
}
public void paint( Graphics g ) {
newNode.draw( g );
newLAN.draw( g );
//copier.draw( g );
trash.draw( g );
}
......@@ -41,6 +50,11 @@ public class Palette {
return trash.clicked(x, y);
}
public boolean hitCopier( int x, int y ) {
return false;
//return copier.clicked(x, y);
}
public Thingee clicked( int x, int y ) {
if (newNode.clicked(x, y)) {
return newNode;
......
......@@ -18,11 +18,14 @@ abstract synchronized class PropertiesArea extends Panel implements TextListener
private Vector currentThingees;
private static Color darkBlue;
private static Color disabledBox;
public boolean isStarted() { return started; }
static {
darkBlue = new Color( 0.3f, 0.3f, 0.5f );
// disabledBox = new Color( 0.5f, 0.5f, 0.65f );
disabledBox = new Color( 0.7f, 0.7f, 0.85f );
}
private void setVisibleAll( boolean b ) {
......@@ -53,9 +56,10 @@ abstract synchronized class PropertiesArea extends Panel implements TextListener
}
}
private MagicTextField addField( String name ) {
MagicTextField tf = new MagicTextField();
private MagicTextField addField( String name, boolean alphic, boolean special, final String def ) {
final MagicTextField tf = new MagicTextField( alphic, !alphic, special );
Label l = new Label(name);
l.setForeground( Color.white );
tf.tf.setBackground( Color.white );
......@@ -65,9 +69,35 @@ abstract synchronized class PropertiesArea extends Panel implements TextListener
child.add( tf.tf );
tf.tf.addTextListener( this );
if (name.compareTo("name:") != 0) {
final PropertiesArea propertiesArea = this;
FlatButton fb = new FlatButton("default") {
public Dimension getPreferredSize() {
return new Dimension( 72, 18 );
}
protected void clicked() {
boolean wasDis = !tf.tf.isEditable();
if (wasDis) { tf.tf.setEditable( true ); }
tf.tf.setText( def );
propertiesArea.upload();
if (wasDis) { tf.tf.setEditable( false ); }
}
};
Panel p = new Panel();
p.setLayout( new FlowLayout( FlowLayout.RIGHT, 0, 0) );
p.add( fb );
childLayout.setConstraints( p, gbc );
child.add( p );
fb.setVisible( true );
}
tf.tf.setVisible( true );
l.setVisible( true );
return tf;
}
......@@ -77,21 +107,26 @@ abstract synchronized class PropertiesArea extends Panel implements TextListener
public String name;
public String def;
public MagicTextField textField;
public boolean alphic;
}
public void textValueChanged( TextEvent e ) {
upload();
if (nameEdit != null
if (nameEdit != null && e.getSource() != null
&& e.getSource() == nameEdit.tf) { // hack.
getParent().repaint();
Component parent = getParent();
if (parent != null) {
parent.repaint();
}
}
}
public void addProperty( String name, String desc, String def ) {
public void addProperty( String name, String desc, String def, boolean alphic, boolean special ) {
Property p = new Property();
p.name = name;
p.def = def;
p.textField = addField( desc );
p.alphic = alphic;
p.textField = addField( desc, alphic, special, def );
if (0 == name.compareTo("name")) { nameEdit = p.textField; }
propertyList.addElement( p );
}
......@@ -169,13 +204,18 @@ abstract synchronized class PropertiesArea extends Panel implements TextListener
public abstract boolean iCare( Thingee t );
public abstract String getName();
private void download() {
private synchronized void download() {
System.out.println( "PropertiesArea.download(): Beginning");
Enumeration et = Thingee.selectedElements();
currentThingees = new Vector();
//currentThingees = new Vector();
currentThingees = null;
Vector cThingees = new Vector();
int thingsICareAbout = 0;
MagicTextField ipEdit = null;
boolean first = true;
while (et.hasMoreElements()) {
Thingee t = (Thingee)et.nextElement();
......@@ -184,10 +224,15 @@ abstract synchronized class PropertiesArea extends Panel implements TextListener
Enumeration e = propertyList.elements();
thingsICareAbout++;
currentThingees.addElement( t );
cThingees.addElement( t );
while (e.hasMoreElements()) {
Property p = (Property)e.nextElement();
if (p.name.compareTo("ip") == 0) {
ipEdit = p.textField;
}
String value = t.getProperty( p.name, p.def );
if (first) {
......@@ -200,23 +245,42 @@ abstract synchronized class PropertiesArea extends Panel implements TextListener
}
}
if (nameEdit != null) {
if (thingsICareAbout > 1) {
if (thingsICareAbout > 1) {
if (nameEdit != null) {
nameEdit.tf.setEditable( false );
nameEdit.tf.setBackground( darkBlue );
} else {
nameEdit.tf.setBackground( disabledBox );
}
if (ipEdit != null) {
ipEdit.tf.setEditable( false );
ipEdit.tf.setBackground( disabledBox );
}
} else {
if (nameEdit != null) {
nameEdit.tf.setEditable( true );
nameEdit.tf.setBackground( Color.white );
}
if (ipEdit != null) {
ipEdit.tf.setEditable( true );
ipEdit.tf.setBackground( Color.white );
}
}
currentThingees = cThingees;
System.out.println( "PropertiesArea.download(): Ending");
}
private void upload() {
private synchronized void upload() {
System.out.println("Upload begins..");
if (currentThingees == null) { return; }
Enumeration et = currentThingees.elements();
boolean needRedraw = false;
while (et.hasMoreElements()) {
System.out.println( "PropertiesArea.upload(): Regarding a thingee.");
Thingee t = (Thingee)et.nextElement();
//if (iCare(t)) {
......@@ -227,12 +291,24 @@ abstract synchronized class PropertiesArea extends Panel implements TextListener
if (p.textField.tf.isEditable()) {
String s = p.textField.tf.getText();
if (0 != s.compareTo("<multiple>")) {
if (p.name.compareTo("name") == 0 &&
t.getName().compareTo( s ) != 0) {
needRedraw = true;
}
System.out.println(
"PA.upload(): Setting prop \"" +
p.name +
"\" to \"" + s + "\"." );
t.setProperty(p.name, s);
}
}
}
//}
}
if (needRedraw) {
Netbuild.redrawAll();
}
System.out.println("Upload ends..");
}
public void refresh() {
......
......@@ -40,19 +40,36 @@ class Thingee {
static private Dictionary names;
private Dictionary properties;
protected Dictionary properties;
public void copyProps( Thingee t ) {
Enumeration e = t.properties.keys();
while (e.hasMoreElements()) {
String s = (String)e.nextElement();
properties.put( new String(s), t.properties.get( s ) );
}
}
static public String genName( String name ) {
/*
if (names.get( name ) == null) {
return name;
}
*/
int num = 0;
String n;
String n = new String();
do {
n = name + NumberFormat.getInstance().format(num);
num++;
} while(names.get( n ) != null);
return n;
return new String(n);
}
public String getProperty( String name, String def ) {
public synchronized String getProperty( String name, String def ) {
if (0 == name.compareTo("name")) {
// note that the name _can_ be blank.
return this.name;
......@@ -65,11 +82,11 @@ class Thingee {
}
}
public void setProperty( String name, String value ) {
public synchronized void setProperty( String name, String value ) {
if (0 == name.compareTo("name")) {
setName( value );
setName( new String(value) );
} else {
properties.put( name, value );
properties.put( new String(name), new String(value) );
}
}
......@@ -102,15 +119,17 @@ class Thingee {
}
public void setName( String newName ) {
System.out.println("Thingee.setName(): Renamed from \"" + name +
"\" to \"" + newName + "\"" );
names.remove( name );
names.put( newName, new Integer(1) );
name = new String( newName );
names.put( name, new Integer(1) );
stringWidthValid = false;
}
public Thingee(String newName) {
name = new String( newName );
names.put( newName, new Integer(1) );
names.put( name, new Integer(1) );
properties = new Hashtable();
stringWidth = 128;
stringWidthValid = false;
......
......@@ -7,6 +7,7 @@ public class WorkArea {
private Vector iFaceThingees;
public WorkArea() {
super();
thingees = new Vector();
linkThingees = new Vector();
iFaceThingees = new Vector();
......@@ -29,6 +30,32 @@ public class WorkArea {
String s;
String n;
Dictionary names;
boolean good = false;
while (!good) {
names = new Hashtable();
good = true;
e = thingees.elements();
while (good && e.hasMoreElements()) {
Thingee t = (Thingee)e.nextElement();
if (t.getName().compareTo("") == 0) {
good = false;
// t += "# WARNING! Changed name for
t.setName( t.genName( "gen_name_" ) );
Netbuild.setStatus("!Duplicate and/or blank names were changed.");
} else if (names.get(t.getName()) != null) {
good = false;
t.setName( t.genName( t.getName() ) );
Netbuild.redrawAll();
Netbuild.setStatus("!Duplicate and/or blank names were changed.");
} else {
names.put(t.getName(), t );
}
}
}
e = thingees.elements();
while ( e.hasMoreElements()) {
Thingee t = (Thingee)e.nextElement();
......@@ -40,6 +67,11 @@ public class WorkArea {
0 != s.compareTo("")) {
r += "tb-set-node-os $" + n + " " + s + "\n";
}
s = t.getProperty( "hardware", "" );
if (0 != s.compareTo("<auto>") &&
0 != s.compareTo("")) {
r += "tb-set-hardware $" + n + " " + s + "\n";
}
}
}
......@@ -49,6 +81,7 @@ public class WorkArea {
while (e.hasMoreElements()) {
Thingee t1 = (Thingee)e.nextElement();
if (!(t1 instanceof LanLinkThingee)) {
// it's a node link
LinkThingee t =