[Schmitzm-commits] r1913 - in trunk/schmitzm-core/src/main: java/de/schmitzm/swing resources/de/schmitzm/swing/resource/locales
scm-commit at wald.intevation.org
scm-commit at wald.intevation.org
Mon Mar 26 23:48:15 CEST 2012
Author: mojays
Date: 2012-03-26 23:48:15 +0200 (Mon, 26 Mar 2012)
New Revision: 1913
Added:
trunk/schmitzm-core/src/main/java/de/schmitzm/swing/InfoDialog.java
Modified:
trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle.properties
trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle_de.properties
Log:
New InfoDialog (default class for "About..." dialog)
Added: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/InfoDialog.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/InfoDialog.java (rev 0)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/InfoDialog.java 2012-03-26 21:48:15 UTC (rev 1913)
@@ -0,0 +1,262 @@
+/**
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ *
+ * This file is part of the SCHMITZM library - a collection of utility
+ * classes based on Java 1.6, focusing (not only) on Java Swing
+ * and the Geotools library.
+ *
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Martin O. J. Schmitz - initial API and implementation
+ * Stefan A. Tzeggai - additional utility classes
+ */
+package de.schmitzm.swing;
+
+import java.awt.BorderLayout;
+import java.awt.Frame;
+import java.sql.DatabaseMetaData;
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.TimeZone;
+
+import javax.swing.JScrollPane;
+
+import de.schmitzm.lang.LangUtil;
+import de.schmitzm.swing.table.AbstractTableModel;
+
+/**
+ * Super class for an application information dialog ("About..."), which
+ * shows application information in a table.
+ * @author Martin O.J. Schmitz
+ *
+ */
+public class InfoDialog extends OkCancelDialog {
+
+ /** Table which contains the information. */
+ protected InfoTableModel infoTableModel;
+ /** Table model providing the information. */
+ protected SortableJTable infoTable;
+
+ /**
+ * Creates a new dialog
+ * @param owner parent window
+ */
+ public InfoDialog(Frame owner) {
+ super(owner, SwingUtil.R("InfoDialog.Title"),true);
+ }
+
+
+ /**
+ * Initialisiert die GUI.
+ */
+ @Override
+ protected void init() {
+ super.init();
+ // Remove cancel button
+ buttonPanel.remove( cancelButton );
+
+ infoTableModel = new InfoTableModel();
+ infoTable = new SortableJTable( infoTableModel );
+// infoTable.setTableHeader(null);
+ infoTable.getColumnModel().getColumn(0).setPreferredWidth(100);
+ infoTable.setAutoGrowColums(true);
+ getContentPane().add(new JScrollPane(infoTable), BorderLayout.CENTER);
+
+ pack();
+ }
+
+ /**
+ * Creates the table model instance.
+ */
+ protected InfoTableModel createTableModel() {
+ return new InfoTableModel();
+ }
+
+ /**
+ * Returns the table model which provides the information.
+ */
+ public InfoTableModel getTableModel() {
+ return infoTableModel;
+ }
+
+ /**
+ * Updates the information in the table model.
+ */
+ public void updateInformation() {
+ infoTableModel.updateInformation();
+ }
+
+ /**
+ * Table model providing the information for the {@link InfoDialog} table.
+ * The model provides two columns, one for the information caption and the
+ * second for the information value.<br>
+ * This default implementation provides:
+ * <ul>
+ * <li>Program version number</li>
+ * <li>Program version date</li>
+ * <li>Java version</li>
+ * <li>JVM memory (total/used/free)</li>
+ * <li>Timezone</li>
+ * </ul>
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
+ */
+ public static class InfoTableModel extends AbstractTableModel {
+ /** Column headers */
+ protected List<String> COL_NAMES;
+ /** Row titles */
+ protected List<String> ROW_NAMES;
+
+ /** Holds the application version number. Must be set by sub class
+ * in {@link #updateInformation()} or by {@link #setVersionNo(Object)}. */
+ protected Object versionNo = "";
+
+ /** Holds the application version date. Must be set by sub class
+ * in {@link #updateInformation()} or by {@link #setVersionDate(Object)} . */
+ protected Object versionDate = "";
+
+ /** Format zur Anzeige des JVM-Speichers */
+ private static final DecimalFormat MEM_FORMAT = new DecimalFormat("0.0");
+
+ /** Metadaten der JDBC-Verbindung. */
+ private DatabaseMetaData connMetaData = null;
+
+ public InfoTableModel() {
+ super();
+ initRows();
+ }
+
+ /**
+ * Initializes the row captions in {@link #ROW_NAMES}. Called by
+ * the constructor. Sub classes can override this method to
+ * add additional information rows.
+ */
+ protected void initRows() {
+ ROW_NAMES = new ArrayList<String>();
+ ROW_NAMES.add(SwingUtil.R("InfoDialog.Program.Version.Number"));
+ ROW_NAMES.add(SwingUtil.R("InfoDialog.Program.Version.Date"));
+ ROW_NAMES.add(SwingUtil.R("InfoDialog.Java.Version"));
+ ROW_NAMES.add(SwingUtil.R("InfoDialog.JVM.Memory"));
+ ROW_NAMES.add(SwingUtil.R("InfoDialog.Timezone"));
+ }
+
+ /**
+ * Initializes the header column captions in {@link #COL_NAMES}. Called by
+ * the constructor. Sub classes can override this method to
+ * add additional information columns.
+ */
+ protected void initColumns() {
+ COL_NAMES = new ArrayList<String>();
+ COL_NAMES.add(SwingUtil.R("InfoDialog.Header.Parameter"));
+ COL_NAMES.add(SwingUtil.R("InfoDialog.Header.Value"));
+ }
+
+ /**
+ * Returns the column names as string array.
+ * @see #COL_NAMES
+ */
+ @Override
+ public String[] createColumnNames() {
+ if ( COL_NAMES == null )
+ initColumns();
+ return COL_NAMES.toArray(new String[0]);
+ }
+
+ /**
+ * Returns the number of table rows.
+ * @see #ROW_NAMES
+ */
+ @Override
+ public int getRowCount() {
+ if ( ROW_NAMES == null )
+ return 0;
+ return ROW_NAMES.size();
+ }
+
+ /**
+ * Returns the version number.
+ */
+ public Object getVersionNo() {
+ return versionNo;
+ }
+
+ /**
+ * Sets the version number.
+ */
+ public void setVersionNo(Object versionNo) {
+ this.versionNo = versionNo;
+ }
+
+ /**
+ * Returns the version date.
+ */
+ public Object getVersionDate() {
+ return versionDate;
+ }
+
+ /**
+ * Sets the version date.
+ */
+ public void setVersionDate(Object versionDate) {
+ this.versionDate = versionDate;
+ }
+
+ /**
+ * Updates the (meta) information of the dialog. This default implementation does
+ * nothing but calling {@link #fireTableDataChanged()}. Sub classes can
+ * override this method to determine advanced information (e.g. JDBC meta data)
+ * before calling {@link #fireTableDataChanged()}.
+ */
+ public void updateInformation() {
+ fireTableDataChanged();
+ }
+
+ /**
+ * Returns a table value.
+ */
+ @Override
+ public Object getValueAt(int row, int col) {
+ if ( col == 0 )
+ return ROW_NAMES.get(row);
+ else
+ try {
+ switch( row ) {
+ case 0: return versionNo;
+ case 1: return versionDate;
+ case 2: return System.getProperty("java.version");
+ case 3: long freeMem = Runtime.getRuntime().freeMemory();
+ long totMem = Runtime.getRuntime().totalMemory();
+ long usedMem = totMem - freeMem;
+ double freeMemPerc = freeMem * 100.0 / totMem;
+ return MEM_FORMAT.format( totMem*1.0/LangUtil.MB_BYTES ) + " / " +
+ MEM_FORMAT.format( usedMem*1.0/LangUtil.MB_BYTES ) + " / " +
+ MEM_FORMAT.format( freeMem*1.0/LangUtil.MB_BYTES ) + " MB (" +
+ MEM_FORMAT.format( freeMemPerc ) + "% "+SwingUtil.R("InfoDialog.JVM.Memory.available")+")";
+ case 4: return LangUtil.getTimezoneDescription(TimeZone.LONG);
+ }
+ } catch (Exception err) {
+ return "<"+SwingUtil.R("Error")+": "+err.getMessage()+">";
+ }
+ return null;
+ }
+ }
+
+
+}
Modified: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle.properties
===================================================================
--- trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle.properties 2012-03-25 08:08:54 UTC (rev 1912)
+++ trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle.properties 2012-03-26 21:48:15 UTC (rev 1913)
@@ -283,3 +283,14 @@
SwingUtil.openDesktopFile.not.supported=Your operating system does not support opening files!
SwingUtil.openDesktopFile.file.not.found.general=The file can not be found.
SwingUtil.openDesktopFile.file.not.found=The file can not be found: ${0}
+
+InfoDialog.Title=Info...
+InfoDialog.Header.Parameter=Parameter
+InfoDialog.Header.Value=Value
+InfoDialog.Program.Version.Number=Program version
+InfoDialog.Program.Version.Date=Program version date
+InfoDialog.Java.Version=Java version
+InfoDialog.JVM.Memory=JVM memory total / used / free
+InfoDialog.JVM.Memory.available=available
+InfoDialog.Timezone=Timezone
+
Modified: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle_de.properties
===================================================================
--- trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle_de.properties 2012-03-25 08:08:54 UTC (rev 1912)
+++ trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle_de.properties 2012-03-26 21:48:15 UTC (rev 1913)
@@ -256,3 +256,13 @@
SwingUtil.openDesktopFile.not.supported=Das Öffnen einer Datei wird von Ihrem Betriebssystem nicht unterstützt.
SwingUtil.openDesktopFile.file.not.found.general=Die Datei ist nicht vorhanden.
SwingUtil.openDesktopFile.file.not.found=Die Datei ist nicht vorhanden: ${0}
+
+InfoDialog.Title=Info...
+InfoDialog.Header.Parameter=Parameter
+InfoDialog.Header.Value=Wert
+InfoDialog.Program.Version.Number=Programm-Version
+InfoDialog.Program.Version.Date=Programm-Version Datum
+InfoDialog.Java.Version=Java-Version
+InfoDialog.JVM.Memory=JVM Speicher gesamt / belegt / frei
+InfoDialog.JVM.Memory.available=verfügbar
+InfoDialog.Timezone=Zeitzone
More information about the Schmitzm-commits
mailing list