From c8ee127b165041665eb28fb0d7807d292ab29e97 Mon Sep 17 00:00:00 2001 From: Miguel Carvalho Date: Mon, 4 Nov 2024 08:37:59 +0000 Subject: [PATCH 1/6] gui/ChronometerPanel: Change GroupLayout to MigLayout enabling button resize horizontally. --- .../pt/lsts/neptus/gui/ChronometerPanel.java | 42 +++++++------------ 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/src/java/pt/lsts/neptus/gui/ChronometerPanel.java b/src/java/pt/lsts/neptus/gui/ChronometerPanel.java index ceeba2a9f1..0f6f28aa8a 100644 --- a/src/java/pt/lsts/neptus/gui/ChronometerPanel.java +++ b/src/java/pt/lsts/neptus/gui/ChronometerPanel.java @@ -65,6 +65,7 @@ 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; @@ -144,34 +145,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( + "debug, 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() { From 8db390490dfbba4ab9d825f61ccd1dc150388782 Mon Sep 17 00:00:00 2001 From: Miguel Carvalho Date: Mon, 4 Nov 2024 08:49:16 +0000 Subject: [PATCH 2/6] gui/ChronometerPanel: Disabled MigLayout's debug mode. --- src/java/pt/lsts/neptus/gui/ChronometerPanel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/java/pt/lsts/neptus/gui/ChronometerPanel.java b/src/java/pt/lsts/neptus/gui/ChronometerPanel.java index 0f6f28aa8a..eb1972be4f 100644 --- a/src/java/pt/lsts/neptus/gui/ChronometerPanel.java +++ b/src/java/pt/lsts/neptus/gui/ChronometerPanel.java @@ -146,7 +146,7 @@ public ChronometerPanel() { private void initialize() { setBackground(COLOR_OK); MigLayout migLayout = new MigLayout( - "debug, fillx, insets 0", + "fillx, insets 0", "[][]", "[grow]0[fill]" //, 20:20:30 ); From ab0c743a7720f8557c4bef8beedb721bcc14c0f0 Mon Sep 17 00:00:00 2001 From: Miguel Carvalho Date: Mon, 11 Nov 2024 11:16:25 +0000 Subject: [PATCH 3/6] gui/ClockCounter: Fixed label clipping across resolutions. --- src/java/pt/lsts/neptus/gui/ClockCounter.java | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/java/pt/lsts/neptus/gui/ClockCounter.java b/src/java/pt/lsts/neptus/gui/ClockCounter.java index 8dceb7e224..68d50c9e79 100644 --- a/src/java/pt/lsts/neptus/gui/ClockCounter.java +++ b/src/java/pt/lsts/neptus/gui/ClockCounter.java @@ -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); @@ -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); @@ -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); From 8a9ec50e7cce5ee3c72b20c9e834880c876e9831 Mon Sep 17 00:00:00 2001 From: Miguel Carvalho Date: Tue, 12 Nov 2024 09:39:54 +0000 Subject: [PATCH 4/6] gui/ClockCounter: Cleaned string concatenation spaces. --- src/java/pt/lsts/neptus/gui/ClockCounter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/java/pt/lsts/neptus/gui/ClockCounter.java b/src/java/pt/lsts/neptus/gui/ClockCounter.java index 68d50c9e79..4eaecf6477 100644 --- a/src/java/pt/lsts/neptus/gui/ClockCounter.java +++ b/src/java/pt/lsts/neptus/gui/ClockCounter.java @@ -128,7 +128,7 @@ 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); From b9d02c1dff19b8fc23f93ea23d6367478a00595b Mon Sep 17 00:00:00 2001 From: Paulo Dias Date: Tue, 12 Nov 2024 10:45:08 +0000 Subject: [PATCH 5/6] gui/ChronometerPanel: Fix typo. --- .../pt/lsts/neptus/gui/ChronometerPanel.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/java/pt/lsts/neptus/gui/ChronometerPanel.java b/src/java/pt/lsts/neptus/gui/ChronometerPanel.java index eb1972be4f..9dca41efa7 100644 --- a/src/java/pt/lsts/neptus/gui/ChronometerPanel.java +++ b/src/java/pt/lsts/neptus/gui/ChronometerPanel.java @@ -102,7 +102,7 @@ public class ChronometerPanel extends JPanel implements ActionListener { 16, 16); public static enum CronState { - STOPED, + STOPPED, STARTED, PAUSED }; @@ -120,7 +120,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; @@ -346,7 +346,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; } @@ -414,7 +414,7 @@ else if (aCommand.equalsIgnoreCase(ACTION_COUNTDOWN)) { } } else if (aCommand.equalsIgnoreCase(ACTION_RESET)) { - if (cState == CronState.STOPED) { + if (cState == CronState.STOPPED) { setMaxSecs(0L); } } @@ -459,7 +459,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(); @@ -477,7 +477,7 @@ else if (cState == CronState.STARTED) { } else if (event == CronEvent.STOP) { msEnd = System.currentTimeMillis(); - cState = CronState.STOPED; + cState = CronState.STOPPED; stopDisplayUpdate(); updateDisplay(); alreadyReported = false; @@ -491,7 +491,7 @@ else if (cState == CronState.PAUSED) { } else if (event == CronEvent.STOP) { msEnd = msStop; - cState = CronState.STOPED; + cState = CronState.STOPPED; stopDisplayUpdate(); updateDisplay(); } @@ -558,7 +558,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); From f1e3cee08593ff7a5ff21172e19f7d4f5a3f9967 Mon Sep 17 00:00:00 2001 From: Paulo Dias Date: Tue, 12 Nov 2024 10:45:24 +0000 Subject: [PATCH 6/6] gui/ChronometerPanel: Removed unused imports. --- src/java/pt/lsts/neptus/gui/ChronometerPanel.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/java/pt/lsts/neptus/gui/ChronometerPanel.java b/src/java/pt/lsts/neptus/gui/ChronometerPanel.java index 9dca41efa7..dfb87d66b0 100644 --- a/src/java/pt/lsts/neptus/gui/ChronometerPanel.java +++ b/src/java/pt/lsts/neptus/gui/ChronometerPanel.java @@ -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; @@ -61,7 +60,6 @@ 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;