OCCRA
Go to Post "FIRST" is not a verb (yet - give us time, and we will see what happens). - dlavery [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Events   CD-Media   CD-Spy   FRC-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 04-15-2012, 06:57 AM
taichichuan's Avatar
taichichuan taichichuan is offline
Software Mentor
AKA: Mike Anderson
FRC #0116 (Epsilon Delta)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2010
Location: Herndon, VA
Posts: 252
taichichuan is a glorious beacon of lighttaichichuan is a glorious beacon of lighttaichichuan is a glorious beacon of lighttaichichuan is a glorious beacon of lighttaichichuan is a glorious beacon of light
Send a message via AIM to taichichuan
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   Spotlight this post!  
Unread 04-15-2012, 08:25 AM
virtuald virtuald is offline
Registered User
AKA: Dustin Spicuzza
FRC #1418
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Northern Virginia
Posts: 513
virtuald is a splendid one to beholdvirtuald is a splendid one to beholdvirtuald is a splendid one to beholdvirtuald is a splendid one to beholdvirtuald is a splendid one to beholdvirtuald is a splendid one to behold
Re: Change size of text field in Smart Dashboard?

There is currently a bug filed in the SmartDashboard tracker.
__________________
Co-maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables (NetworkTables for Python)

Team #1418: 2014 VA Regional: Finalists, #2 seed overall, Industrial Design Award; DC Regional: Finalists, #6 alliance captain
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


FRC Software Resources (including 2014 python code): http://www.virtualroadside.com/FRC/
WPILib Doxygen Repo: http://www.virtualroadside.com/WPILib/index.html
  #3   Spotlight this post!  
Unread 04-16-2012, 07:34 PM
Ginto8's Avatar
Ginto8 Ginto8 is offline
Programming Lead
AKA: Joe Doyle
FRC #2729 (Storm)
Team Role: Programmer
 
Join Date: Oct 2010
Rookie Year: 2010
Location: Marlton, NJ
Posts: 174
Ginto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of light
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:
  • Network Table is the name of the chosen network table. To access it on the robot side, use NetworkTable.getTable("My table name"). The robot-end and SmartDashboard-end names must be the same for this to work.
  • The format string acts like a normal label string, except that everything within % symbols is treated as a key, and gets replaced with the contents of that NetworkTable entry. For example, a format string "Shooter speed: %shooter.rpm%rpm" will display as "Shooter speed: 50000rpm" when your motor is about to explode.

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   Spotlight this post!  
Unread 04-16-2012, 11:55 PM
Gigakaiser's Avatar
Gigakaiser Gigakaiser is offline
Registered User
AKA: Brandon Hjelstrom
FRC #0987 (High Rollers)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Las Vegas
Posts: 65
Gigakaiser has a spectacular aura aboutGigakaiser has a spectacular aura about
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.
__________________
FRC Team 987 - It's not enough
  #5   Spotlight this post!  
Unread 04-17-2012, 06:36 AM
taichichuan's Avatar
taichichuan taichichuan is offline
Software Mentor
AKA: Mike Anderson
FRC #0116 (Epsilon Delta)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2010
Location: Herndon, VA
Posts: 252
taichichuan is a glorious beacon of lighttaichichuan is a glorious beacon of lighttaichichuan is a glorious beacon of lighttaichichuan is a glorious beacon of lighttaichichuan is a glorious beacon of light
Send a message via AIM to taichichuan
Re: Change size of text field in Smart Dashboard?

Quote:
Originally Posted by Gigakaiser View Post
If you change your field to a "formatted field" and check the properties menu, text size is an editable number.
Thanks, Radical. I'll take a look at that.

Mike
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 06:18 AM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi