From 8e40cd53b6b1579e383bd5e993cb3c35ce4583c4 Mon Sep 17 00:00:00 2001 From: James Moger Date: Thu, 27 Oct 2011 08:16:46 -0400 Subject: [PATCH] Add version number and date to ServerStatus. Conditionally hide status. --- src/com/gitblit/client/GitblitPanel.java | 12 +++++---- src/com/gitblit/client/StatusPanel.java | 27 ++++++++++++++++--- src/com/gitblit/models/ServerStatus.java | 26 +++++++++++------- .../gitblit/wicket/GitBlitWebApp.properties | 4 ++- 4 files changed, 50 insertions(+), 19 deletions(-) diff --git a/src/com/gitblit/client/GitblitPanel.java b/src/com/gitblit/client/GitblitPanel.java index 9eb896bc..23aadb86 100644 --- a/src/com/gitblit/client/GitblitPanel.java +++ b/src/com/gitblit/client/GitblitPanel.java @@ -530,11 +530,13 @@ public class GitblitPanel extends JPanel implements CloseTabListener { Utils.packColumns(settingsTable, 5); } else { // remove the settings tab - String settingsTitle = Translation.get("gb.settings"); - for (int i = 0; i < tabs.getTabCount(); i++) { - if (tabs.getTitleAt(i).equals(settingsTitle)) { - tabs.removeTabAt(i); - break; + String[] titles = { Translation.get("gb.settings"), Translation.get("gb.status") }; + for (String title : titles) { + for (int i = 0; i < tabs.getTabCount(); i++) { + if (tabs.getTitleAt(i).equals(title)) { + tabs.removeTabAt(i); + break; + } } } } diff --git a/src/com/gitblit/client/StatusPanel.java b/src/com/gitblit/client/StatusPanel.java index 551d865d..0cc530ef 100644 --- a/src/com/gitblit/client/StatusPanel.java +++ b/src/com/gitblit/client/StatusPanel.java @@ -27,8 +27,10 @@ import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; +import com.gitblit.Constants; import com.gitblit.models.ServerStatus; import com.gitblit.utils.ByteFormat; +import com.gitblit.utils.TimeUtils; /** * This panel displays the server status. @@ -46,6 +48,8 @@ public class StatusPanel extends JPanel { private JLabel heapUsed; private PropertiesTableModel model; private HeaderPanel headerPanel; + private JLabel version; + private JLabel releaseDate; public StatusPanel() { super(); @@ -58,6 +62,8 @@ public class StatusPanel extends JPanel { } private void initialize() { + version = new JLabel(); + releaseDate = new JLabel(); bootDate = new JLabel(); servletContainer = new JLabel(); @@ -65,7 +71,17 @@ public class StatusPanel extends JPanel { heapAllocated = new JLabel(); heapUsed = new JLabel(); - JPanel fieldsPanel = new JPanel(new GridLayout(0, 1)); + JPanel fieldsPanel = new JPanel(new GridLayout(0, 1, 0, 5)) { + + private static final long serialVersionUID = 1L; + + @Override + public Insets getInsets() { + return insets; + } + }; + fieldsPanel.add(createFieldPanel("gb.version", version)); + fieldsPanel.add(createFieldPanel("gb.releaseDate", releaseDate)); fieldsPanel.add(createFieldPanel("gb.bootDate", bootDate)); fieldsPanel.add(createFieldPanel("gb.servletContainer", servletContainer)); fieldsPanel.add(createFieldPanel("gb.heapUsed", heapUsed)); @@ -90,10 +106,10 @@ public class StatusPanel extends JPanel { } private JPanel createFieldPanel(String key, JLabel valueLabel) { - JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 5)); + JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0)); JLabel textLabel = new JLabel(Translation.get(key)); textLabel.setFont(textLabel.getFont().deriveFont(Font.BOLD)); - textLabel.setPreferredSize(new Dimension(120, valueLabel.getFont().getSize() + 4)); + textLabel.setPreferredSize(new Dimension(120, 10)); panel.add(textLabel); panel.add(valueLabel); return panel; @@ -106,7 +122,10 @@ public class StatusPanel extends JPanel { public void setStatus(ServerStatus status) { headerPanel.setText(Translation.get("gb.status")); - bootDate.setText(status.bootDate.toString()); + version.setText(Constants.NAME + (status.isGO ? " GO v" : " WAR v") + status.version); + releaseDate.setText(status.releaseDate); + bootDate.setText(status.bootDate.toString() + " (" + TimeUtils.timeAgo(status.bootDate) + + ")"); servletContainer.setText(status.servletContainer); ByteFormat byteFormat = new ByteFormat(); heapMaximum.setText(byteFormat.format(status.heapMaximum)); diff --git a/src/com/gitblit/models/ServerStatus.java b/src/com/gitblit/models/ServerStatus.java index 1c40b5f4..3e7e8d82 100644 --- a/src/com/gitblit/models/ServerStatus.java +++ b/src/com/gitblit/models/ServerStatus.java @@ -20,6 +20,8 @@ import java.util.Date; import java.util.Map; import java.util.TreeMap; +import com.gitblit.Constants; + /** * ServerStatus encapsulates runtime status information about the server * including some information about the system environment. @@ -32,26 +34,32 @@ public class ServerStatus implements Serializable { private static final long serialVersionUID = 1L; public final Date bootDate; - + + public final String version; + + public final String releaseDate; + public final boolean isGO; - + public final Map systemProperties; public final long heapMaximum; public volatile long heapAllocated; - + public volatile long heapFree; - + public String servletContainer; public ServerStatus(boolean isGO) { - bootDate = new Date(); + this.bootDate = new Date(); + this.version = Constants.VERSION; + this.releaseDate = Constants.VERSION_DATE; this.isGO = isGO; - - heapMaximum = Runtime.getRuntime().maxMemory(); - - systemProperties = new TreeMap(); + + this.heapMaximum = Runtime.getRuntime().maxMemory(); + + this.systemProperties = new TreeMap(); put("file.encoding"); put("java.home"); put("java.io.tmpdir"); diff --git a/src/com/gitblit/wicket/GitBlitWebApp.properties b/src/com/gitblit/wicket/GitBlitWebApp.properties index 715cb156..267fb564 100644 --- a/src/com/gitblit/wicket/GitBlitWebApp.properties +++ b/src/com/gitblit/wicket/GitBlitWebApp.properties @@ -173,4 +173,6 @@ gb.servletContainer = servlet container gb.heapMaximum = maximum heap gb.heapAllocated = allocated heap gb.heapUsed = used heap -gb.free = free \ No newline at end of file +gb.free = free +gb.version = version +gb.releaseDate = release date \ No newline at end of file -- 2.39.5