Skip to content

Commit

Permalink
Merge branch 'fix/chronometer' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
paulosousadias committed Nov 12, 2024
2 parents 51e472f + f1e3cee commit 0350ceb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 50 deletions.
60 changes: 22 additions & 38 deletions src/java/pt/lsts/neptus/gui/ChronometerPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import java.util.regex.Pattern;

import javax.swing.AbstractAction;
import javax.swing.GroupLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
Expand All @@ -61,10 +60,10 @@
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.text.DefaultFormatter;

import net.miginfocom.swing.MigLayout;
import pt.lsts.neptus.gui.ClockCounter.ClockState;
import pt.lsts.neptus.i18n.I18n;
import pt.lsts.neptus.util.GuiUtils;
Expand Down Expand Up @@ -101,7 +100,7 @@ public class ChronometerPanel extends JPanel implements ActionListener {
16, 16);

public static enum CronState {
STOPED,
STOPPED,
STARTED,
PAUSED
};
Expand All @@ -119,7 +118,7 @@ public static enum CronEvent {

private long maxSecs = -1;

protected CronState cState = CronState.STOPED;
protected CronState cState = CronState.STOPPED;

// private Timer timer = new Timer(this.getClass().getSimpleName() + ": " + this.hashCode(), true);
// private TimerTask tTask = null;
Expand All @@ -144,34 +143,19 @@ public ChronometerPanel() {

private void initialize() {
setBackground(COLOR_OK);
GroupLayout layout = new GroupLayout(this);
this.setLayout(layout);
layout.setAutoCreateGaps(false);
layout.setAutoCreateContainerGaps(false);

layout.setHorizontalGroup(layout
.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup().addComponent(getDisplay()))
.addGroup(
layout.createSequentialGroup().addComponent(getStartStopToggleButton())
.addComponent(getPauseResumeToggleButton()).addComponent(getAlarmValueButton())
.addComponent(getCountdownToggleButton()).addGap(10)
.addComponent(getLabelPanel())));

layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER).addGroup(
layout.createSequentialGroup()
.addComponent(getDisplay())
.addGroup(
layout.createParallelGroup(GroupLayout.Alignment.CENTER)
.addComponent(getStartStopToggleButton())
.addComponent(getPauseResumeToggleButton()).addComponent(getAlarmValueButton())
.addComponent(getCountdownToggleButton())
.addComponent(getLabelPanel()))));

layout.linkSize(SwingConstants.HORIZONTAL, getStartStopToggleButton(), getPauseResumeToggleButton(),
getAlarmValueButton(), getCountdownToggleButton()/* , getResetButton() */);
layout.linkSize(SwingConstants.VERTICAL, getStartStopToggleButton(), getPauseResumeToggleButton(),
getAlarmValueButton(), getCountdownToggleButton()/* , getResetButton() */);
MigLayout migLayout = new MigLayout(
"fillx, insets 0",
"[][]",
"[grow]0[fill]" //, 20:20:30
);
this.setLayout(migLayout);
this.add(getDisplay(), "span, grow, wrap");
this.add(getStartStopToggleButton(), "w 20:20:60, h 0:20:30, split 6, gapright 0, grow, top");
this.add(getPauseResumeToggleButton(), "w 20:20:60, h 0:20:30, gapright 0, grow, top");
this.add(getAlarmValueButton(), "w 20:20:60, h 0:20:30, gapright 0, grow, top");
this.add(getCountdownToggleButton(), "w 20:20:60, h 0:20:30, gapright 0, grow, top");
this.add(getResetButton(), "w 20:20:60, h 0:20:30, gapright 0, grow, top");
this.add(getLabelPanel(), "grow");
}

public void hideButtons() {
Expand Down Expand Up @@ -360,7 +344,7 @@ public long getMilliSecTime() {
msTime = System.currentTimeMillis() - msStart + msAcum;
else if (cState == CronState.PAUSED)
msTime = msStop - msStart + msAcum;
else if (cState == CronState.STOPED)
else if (cState == CronState.STOPPED)
msTime = msEnd - msStart + msAcum;
return msTime;
}
Expand Down Expand Up @@ -428,7 +412,7 @@ else if (aCommand.equalsIgnoreCase(ACTION_COUNTDOWN)) {
}
}
else if (aCommand.equalsIgnoreCase(ACTION_RESET)) {
if (cState == CronState.STOPED) {
if (cState == CronState.STOPPED) {
setMaxSecs(0L);
}
}
Expand Down Expand Up @@ -473,7 +457,7 @@ public void keyReleased(KeyEvent e) {
}

protected void updateState(CronEvent event) {
if (cState == CronState.STOPED) {
if (cState == CronState.STOPPED) {
if (event == CronEvent.START) {
msTime = 0;
msStart = System.currentTimeMillis();
Expand All @@ -491,7 +475,7 @@ else if (cState == CronState.STARTED) {
}
else if (event == CronEvent.STOP) {
msEnd = System.currentTimeMillis();
cState = CronState.STOPED;
cState = CronState.STOPPED;
stopDisplayUpdate();
updateDisplay();
alreadyReported = false;
Expand All @@ -505,7 +489,7 @@ else if (cState == CronState.PAUSED) {
}
else if (event == CronEvent.STOP) {
msEnd = msStop;
cState = CronState.STOPED;
cState = CronState.STOPPED;
stopDisplayUpdate();
updateDisplay();
}
Expand Down Expand Up @@ -572,7 +556,7 @@ else if (getMaxSecs() > 0 && getCountdownToggleButton().getState()) {

if (cState == CronState.STARTED)
getDisplay().setState(ClockState.START);
else if (cState == CronState.STOPED)
else if (cState == CronState.STOPPED)
getDisplay().setState(ClockState.STOP);
else if (cState == CronState.PAUSED)
getDisplay().setState(ClockState.PAUSE);
Expand Down
21 changes: 9 additions & 12 deletions src/java/pt/lsts/neptus/gui/ClockCounter.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,7 @@ public void paint(Graphics g) {
RoundRectangle2D rrect = new RoundRectangle2D.Double(2,2,getWidth()-4,getHeight()-4, 10, 10);
g2d.fill(rrect);

g2d.setFont(new Font("Arial", Font.BOLD, 8));

String tt = "00" + HOURS_SEPARATOR +"00" + MINUTES_SEPARATOR +"00" + SECONDS_SEPARATOR;
Rectangle2D sB1 = g2d.getFontMetrics().getStringBounds(tt, g2d);
g2d.setFont(new Font("Arial", Font.BOLD, 10));

long hr = (long) (getSecs()/60.0/60.0);
long mi = (long) ((getSecs()/60.0)%60.0);
Expand All @@ -131,16 +128,16 @@ public void paint(Graphics g) {
miS = "0" + miS;
if (secS.length() == 1)
secS = "0" + secS;
String time = " " +hrS + HOURS_SEPARATOR + miS + MINUTES_SEPARATOR + secS + SECONDS_SEPARATOR;
String time = " " + hrS + HOURS_SEPARATOR + miS + MINUTES_SEPARATOR + secS + SECONDS_SEPARATOR + " ";

Rectangle2D sB2 = g2d.getFontMetrics().getStringBounds(time, g2d);

double scale;
double sw0 = w / sB1.getWidth();
double sh0 = h / sB1.getHeight();
scale = (sw0 < sh0)?sw0:sh0;
w = (int) (w * 1/scale);
h = (int) (h * 1/scale);
double sw0 = w / sB2.getWidth();
double sh0 = h / sB2.getHeight();
scale = Math.min(sw0, sh0);
w = (int) (w/scale);
h = (int) (h/scale);

//AffineTransform pre = g2d.getTransform();
g2d.scale(scale, scale);
Expand All @@ -150,10 +147,10 @@ public void paint(Graphics g) {
//Ellipse2D ellis = new Ellipse2D.Double(0, 0, 2, 2);
//g2d.setColor(Color.CYAN);
//g2d.fill(ellis);

g2d.setColor(COLOR_FORE);
g.drawString(time, (int) (-sB2.getWidth()/2), (int) (sB2.getHeight()/2));

g2d.translate(w/2, -h/2);
if (getState() == ClockState.START)
g2d.fill(SHAPE_PLAY);
Expand Down

0 comments on commit 0350ceb

Please sign in to comment.