|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Change size of text field in Smart Dashboard?
Greetings!
We're trying to bring the RPM of our shooter back to the driver station during the match. But, the size of the standard text field on the smart dashboard is way too small. I've looked at the text properties, but I don't see a text font/size property. Is there a way to modify the text display in the smart dashboard to change the font size and color? We're a C++ team. But, we've got Java folks as well which is why we're looking at the smart dashboard. TIA, Mike |
|
#2
|
||||
|
||||
|
Re: Change size of text field in Smart Dashboard?
There is currently a bug filed in the SmartDashboard tracker.
|
|
#3
|
||||
|
||||
|
Re: Change size of text field in Smart Dashboard?
I actually wrote a little extension for my team that replaces Label and can read values from a NetworkTable, inserting them into a string. I don't know if C++ has a NetworkTable implementation, but if so this might be helpful.
Most of the properties are self-explanatory, but two things you want to keep in mind:
And now, the code: Code:
package storm.smartdashboard;
import edu.wpi.first.smartdashboard.gui.StaticWidget;
import edu.wpi.first.smartdashboard.properties.*;
import edu.wpi.first.wpilibj.networking.NetworkTable;
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JLabel;
/**
* @author Joe Doyle (Ginto8)
*/
public class SmartLabel extends StaticWidget {
public static final String NAME = "Smart Label";
private static NetworkTable SMARTDASHBOARD_FEEDBACK;
private static String format(String s, boolean plusPositive) {
String ret = "";
int start = 0, end = 0;
while (true) {
start = s.indexOf("%", end);
if (start < 0) {
break;
}
ret += s.substring(end, start);
end = s.indexOf("%", start + 1);
if (end < 0) {
end = start;
break;
}
String key = s.substring(start + 1, end);
Object value = SMARTDASHBOARD_FEEDBACK.getValue(key, null);
if (value == null) {
++end;
ret += s.substring(start, end);
continue;
}
String out = value.toString();
if (plusPositive) {
Double asDouble = (Double) value;
Integer asInteger = (Integer) value;
if (value instanceof Double && asDouble.doubleValue() >= 0) {
out = "+" + out;
} else if (value instanceof Integer && asInteger.intValue() >= 0) {
out = "+" + out;
}
}
ret += out;
++end;
start = end;
}
ret += s.substring(end);
return ret;
}
public final StringProperty netTable = new StringProperty(this, "Network Table","Feedback");
public final StringProperty text = new StringProperty(this, "Format String", "%DEFAULT%");
public final DoubleProperty fontSize = new DoubleProperty(this,"Font Size",12);
public final BooleanProperty plusPositive = new BooleanProperty(this,"Always show sign",false);
public final MultiProperty horizontal = new MultiProperty(this, "Horizontal Alignment");
public final MultiProperty vertical = new MultiProperty(this, "Vertical Alignment");
public final ColorProperty textColor = new ColorProperty(this,"Text Color",Color.black);
private volatile JLabel label;
Thread updateThread;
public SmartLabel() {
this.horizontal.add("Left", Integer.valueOf(2));
this.horizontal.add("Center", Integer.valueOf(0));
this.horizontal.add("Right", Integer.valueOf(4));
this.horizontal.setDefault("Center");
this.vertical.add("Up", Integer.valueOf(1));
this.vertical.add("Center", Integer.valueOf(0));
this.vertical.add("Down", Integer.valueOf(3));
this.vertical.setDefault("Center");
updateThread = new Thread() {
@Override
public void run() {
while(true) {
update();
try {
Thread.sleep(1000 / 5);
} catch (InterruptedException ex) {
}
}
}
};
}
private synchronized void update() {
this.label.setText(format(this.text.getValue(),plusPositive.getValue()));
}
@Override
public void init() {
setLayout(new BorderLayout());
SMARTDASHBOARD_FEEDBACK = NetworkTable.getTable(netTable.getValue());
this.label = new JLabel(format(this.text.getValue(),plusPositive.getValue()));
this.label.setHorizontalAlignment(((Integer) this.horizontal.getValue()).intValue());
this.label.setVerticalAlignment(((Integer) this.vertical.getValue()).intValue());
this.label.setFont(label.getFont().deriveFont(fontSize.getValue().floatValue()));
this.label.setForeground(this.textColor.getValue());
add(this.label, "Center");
updateThread.start();
}
@Override
public void propertyChanged(Property property) {
if (property == this.text || property == plusPositive) {
update();
} else if(property == this.fontSize) {
this.label.setFont(label.getFont().deriveFont(fontSize.getValue().floatValue()));
} else if (property == this.horizontal) {
this.label.setHorizontalAlignment(((Integer) this.horizontal.getValue()).intValue());
} else if (property == this.vertical) {
this.label.setVerticalAlignment(((Integer) this.vertical.getValue()).intValue());
} else if(property == this.textColor) {
this.label.setForeground(this.textColor.getValue());
} else if(property == this.netTable) {
SMARTDASHBOARD_FEEDBACK = NetworkTable.getTable(netTable.getValue());
}
}
}
|
|
#4
|
|||
|
|||
|
Re: Change size of text field in Smart Dashboard?
If you change your field to a "formatted field" and check the properties menu, text size is an editable number.
|
|
#5
|
||||
|
||||
|
Re: Change size of text field in Smart Dashboard?
Quote:
Mike |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|