[Schmitzm-commits] r1646 - in trunk/schmitzm-core/src/main: java/de/schmitzm/net/mail java/de/schmitzm/swing resources/de/schmitzm/net/mail/resource/locales resources/de/schmitzm/swing/resource/icons/small resources/de/schmitzm/swing/resource/locales
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Jul 22 13:26:40 CEST 2011
Author: mojays
Date: 2011-07-22 13:26:39 +0200 (Fri, 22 Jul 2011)
New Revision: 1646
Added:
trunk/schmitzm-core/src/main/java/de/schmitzm/swing/AbstractActionTextPanel.java
trunk/schmitzm-core/src/main/java/de/schmitzm/swing/URLAddressPanel.java
trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/small/world.png
trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/small/world2.png
Modified:
trunk/schmitzm-core/src/main/java/de/schmitzm/net/mail/MailUtil.java
trunk/schmitzm-core/src/main/java/de/schmitzm/swing/MailAddressPanel.java
trunk/schmitzm-core/src/main/resources/de/schmitzm/net/mail/resource/locales/MailResourceBundle.properties
trunk/schmitzm-core/src/main/resources/de/schmitzm/net/mail/resource/locales/MailResourceBundle_de.properties
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 AbstractActionTextPanel and URLAddressPanel
Added some general icons.
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/net/mail/MailUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/net/mail/MailUtil.java 2011-07-21 23:01:51 UTC (rev 1645)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/net/mail/MailUtil.java 2011-07-22 11:26:39 UTC (rev 1646)
@@ -3,6 +3,7 @@
import java.awt.Desktop;
import java.awt.GraphicsEnvironment;
import java.net.URI;
+import java.net.URISyntaxException;
import java.util.Date;
import java.util.Locale;
import java.util.Properties;
@@ -18,6 +19,7 @@
import javax.mail.internet.MimeMessage;
import javax.swing.JOptionPane;
+import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import de.schmitzm.lang.LangUtil;
@@ -193,7 +195,7 @@
}
}
- /**
+ /**
* Opens the local mail client with a new mail for an exception.
*
* @param mailDestAddr
@@ -266,4 +268,57 @@
}
+ /**
+ * Opens the local web browser with a new url address. Does
+ * nothing if given url is <code>null</code>.
+ *
+ * @param uri
+ * destination address to open in browser
+ * @return <code>true</code> if the browse was opened successfully
+ */
+ public static boolean openDesktopBrowser(URI uri) {
+ if ( uri == null )
+ return false;
+
+ if ( !Desktop.isDesktopSupported()
+ || !Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
+ if (!GraphicsEnvironment.isHeadless()) {
+ JOptionPane.showMessageDialog(
+ null, RESOURCE.getString("MailUtil.DesktopBrowser.NotSupported"));
+ } else {
+ log.info("java.awt.Desktop noch available on this system to open an URL in browser.");
+ }
+ return false;
+ }
+
+ try {
+ Desktop.getDesktop().browse(uri);
+ return true;
+ } catch (Exception err) {
+ ExceptionDialog.show(null, err, null,
+ RESOURCE.getString("MailUtil.DesktopBrowser.BrowseError"));
+ return false;
+ }
+ }
+
+ /**
+ * Opens the local web browser with a new url address. Does nothing
+ * when {@code null} or empty string is given.
+ *
+ * @param websiteAddr
+ * destination address to open in browser
+ * @return <code>true</code> if the browse was opened successfully
+ */
+ public static boolean openDesktopBrowser(String websiteAddr) {
+ if ( StringUtils.trimToNull(websiteAddr) == null )
+ return false;
+ try {
+ return openDesktopBrowser( new URI(websiteAddr) );
+ } catch (URISyntaxException err) {
+ ExceptionDialog.show(null, err, null,
+ RESOURCE.getString("MailUtil.DesktopBrowser.BrowseError"));
+ return false;
+ }
+
+ }
}
Added: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/AbstractActionTextPanel.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/AbstractActionTextPanel.java 2011-07-21 23:01:51 UTC (rev 1645)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/AbstractActionTextPanel.java 2011-07-22 11:26:39 UTC (rev 1646)
@@ -0,0 +1,123 @@
+package de.schmitzm.swing;
+
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.event.ActionEvent;
+
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+import javax.swing.JFormattedTextField;
+import javax.swing.text.JTextComponent;
+
+import de.schmitzm.net.mail.MailUtil;
+
+/**
+ * Abstract panel which which accepts some text in a {@link JTextComponent}
+ * and provides a button to do some action with the text.
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
+ *
+ */
+public abstract class AbstractActionTextPanel extends AbstractTextPanel {
+ /** Button to perform the action */
+ protected JButton button;
+ /** Text field to enter some text. */
+ protected JTextComponent textField;
+ /** Icon for the button */
+ protected ImageIcon icon;
+ /** Action to perform something with the text on button click */
+ protected Action buttonAction;
+
+ /**
+ * Creates a new text field.
+ * {@link #init(String, String, ImageIcon, String)} must be
+ * called manually by the sub-class constructor!
+ */
+ protected AbstractActionTextPanel() {
+ super( new BorderLayout() );
+ }
+
+ /**
+ * Creates a new text field.
+ * @param buttonText text for action on button or in menu (if icon
+ * is specified, the button shows only the icon!)
+ * @param tooltipText tooltip for the button
+ * @param buttonIcon icon to show on the button (optional)
+ * @param actionCommand action command for the action event (if
+ * {@code null}, "BUTTON_ACTION" is used)
+ */
+ public AbstractActionTextPanel(String buttonText, String tooltipText, ImageIcon buttonIcon, String actionCommand) {
+ this();
+ init(buttonText,tooltipText,buttonIcon,actionCommand);
+ }
+
+ /**
+ * Initializes the panel. Called by the constructor.
+ * @param buttonText text for action on button or in menu (if icon
+ * is specified, the button shows only the icon!)
+ * @param tooltipText tooltip for the button
+ * @param buttonIcon icon to show on the button (optional)
+ * @param actionCommand action command for the action event (if
+ * {@code null}, "BUTTON_ACTION" is used)
+ */
+ protected void init(String buttonText, String tooltipText, ImageIcon buttonIcon, String actionCommand) {
+ if ( buttonText == null )
+ buttonText = "...";
+ if ( tooltipText == null )
+ tooltipText = buttonText;
+ if ( actionCommand == null )
+ actionCommand = "BUTTON_ACTION";
+
+ this.icon = buttonIcon;
+ this.textField = createTextComponent();
+ this.buttonAction = new AbstractAction(buttonText,buttonIcon) {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ performAction(e,getText());
+ }
+ };
+ buttonAction.putValue(AbstractAction.SMALL_ICON, buttonIcon);
+ buttonAction.putValue(AbstractAction.SHORT_DESCRIPTION, tooltipText);
+ buttonAction.putValue(AbstractAction.ACTION_COMMAND_KEY,actionCommand);
+ buttonAction.putValue(AbstractAction.NAME, buttonText);
+
+ this.button = new JButton(buttonAction);
+ button.getInsets().top = 1;
+ button.getInsets().bottom = 1;
+ if ( buttonIcon != null ) {
+ button.setPreferredSize(new Dimension(buttonIcon.getIconWidth()+15,textField.getPreferredSize().height) );
+// button.setMaximumSize(new Dimension(buttonIcon.getIconWidth()+15,textField.getPreferredSize().height) );
+ button.setText(null); // Show only the icon
+ }
+
+ add( textField, BorderLayout.CENTER );
+ add( button, BorderLayout.EAST );
+ }
+
+
+ /**
+ * Creates the text component to specify the text.
+ */
+ public abstract JTextComponent createTextComponent();
+
+ /**
+ * Piped to {@link #textField}.
+ */
+ public void setText(String text) {
+ textField.setText(text);
+ }
+
+ /**
+ * Piped to {@link #textField}.
+ */
+ public String getText() {
+ return textField.getText();
+ }
+
+ /**
+ * Called by the {@link #buttonAction} with {@link #getText()} as
+ * parameter.
+ */
+ protected abstract void performAction(ActionEvent e, String text);
+}
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/MailAddressPanel.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/MailAddressPanel.java 2011-07-21 23:01:51 UTC (rev 1645)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/MailAddressPanel.java 2011-07-22 11:26:39 UTC (rev 1646)
@@ -1,84 +1,121 @@
package de.schmitzm.swing;
-import java.awt.BorderLayout;
-import java.awt.Dimension;
import java.awt.event.ActionEvent;
-import javax.swing.AbstractAction;
-import javax.swing.Action;
-import javax.swing.ImageIcon;
-import javax.swing.JButton;
-import javax.swing.JFormattedTextField;
+import javax.swing.text.JTextComponent;
import de.schmitzm.net.mail.MailUtil;
/**
- * {@link JFormattedTextField} which accepts a mail address and
- * provides a button to create a e-mail with the standard mail
+ * Panel with {@link MailAddressTextField} which accepts a mail address and
+ * which provides a button to create a e-mail with the standard mail
* program of the OS.
* @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
*
*/
-public class MailAddressPanel extends AbstractTextPanel {
+public class MailAddressPanel extends AbstractActionTextPanel {
- protected JButton mailButton;
- protected MailAddressTextField mailTextField;
- protected ImageIcon mailIcon = SwingUtil.createImageIconFromResourcePath(SwingUtil.class, "resource/icons/small/mail2.gif", null);
- protected Action mailAction;
-
/**
* Creates a new text field.
*/
public MailAddressPanel() {
- super( new BorderLayout() );
- mailTextField = new MailAddressTextField();
-
- mailAction = new AbstractAction("Mail",mailIcon) {
- @Override
- public void actionPerformed(ActionEvent e) {
- performMailAction(getText(), null, null);
- }
- };
- mailAction.putValue(AbstractAction.SMALL_ICON, mailIcon);
- mailAction.putValue(AbstractAction.SHORT_DESCRIPTION, "Mail");
- mailAction.putValue(AbstractAction.ACTION_COMMAND_KEY,"MAIL");
- mailAction.putValue(AbstractAction.NAME, "Mail");
-
- mailButton = new JButton(mailAction);
- mailButton.getInsets().top = 1;
- mailButton.getInsets().bottom = 1;
- mailButton.setPreferredSize(new Dimension(mailIcon.getIconWidth()+15,mailTextField.getPreferredSize().height) );
- mailButton.setText(null);
-
- add( mailTextField, BorderLayout.CENTER );
- add( mailButton, BorderLayout.EAST );
+ super();
+ init(
+ SwingUtil.R("MailAddressPanel.Button.Label"),
+ SwingUtil.R("MailAddressPanel.Button.Tooltip"),
+ SwingUtil.createImageIconFromResourcePath(SwingUtil.class, "resource/icons/small/mail2.gif", null),
+ "MAIL"
+ );
}
-
+
/**
- * Piped to {@link #mailTextField}.
+ * Creates the text component to specify the text.
+ * @return a new instance of {@link MailAddressPanel}
*/
- public void setText(String text) {
- mailTextField.setText(text);
+ public JTextComponent createTextComponent() {
+ return new MailAddressTextField();
}
/**
- * Piped to {@link #mailTextField}.
+ * Called by the button action.
+ * Pipes call to {@link #performMailAction(String, String, String)}
+ * with subject/body <code>null</code>.
*/
- public String getText() {
- return mailTextField.getText();
+ protected void performAction(ActionEvent e, String destAddr) {
+ performMailAction(destAddr, null, null);
}
-
+
/**
- * Called by the {@link #mailAction} with {@link #getText()} as
- * destination address and subject/body <code>null</code>.
+ * Called by the {@link #performAction(ActionEvent, String)}
+ * with subject/body <code>null</code>.
* This method simply pipes these 3 parameters to
* {@link MailUtil#sendDesktopMail(String, String, String)}.<br>
- * Sub-classes can override this method to set an application
- * dependent subject or body.
- *
+ * Sub-classes can override this method (and call super) to
+ * set an application dependent subject or body.
*/
protected void performMailAction(String destAddr, String subject, String body) {
MailUtil.sendDesktopMail(
- getText(), subject, body);
+ destAddr, subject, body);
}
+
+// protected JButton mailButton;
+// protected MailAddressTextField mailTextField;
+// protected ImageIcon mailIcon = SwingUtil.createImageIconFromResourcePath(SwingUtil.class, "resource/icons/small/mail2.gif", null);
+// protected Action mailAction;
+//
+// /**
+// * Creates a new text field.
+// */
+// public MailAddressPanel() {
+// super( new BorderLayout() );
+// mailTextField = new MailAddressTextField();
+//
+// mailAction = new AbstractAction("Mail",mailIcon) {
+// @Override
+// public void actionPerformed(ActionEvent e) {
+// performMailAction(getText(), null, null);
+// }
+// };
+// mailAction.putValue(AbstractAction.SMALL_ICON, mailIcon);
+// mailAction.putValue(AbstractAction.SHORT_DESCRIPTION, "Mail");
+// mailAction.putValue(AbstractAction.ACTION_COMMAND_KEY,"MAIL");
+// mailAction.putValue(AbstractAction.NAME, "Mail");
+//
+// mailButton = new JButton(mailAction);
+// mailButton.getInsets().top = 1;
+// mailButton.getInsets().bottom = 1;
+// mailButton.setPreferredSize(new Dimension(mailIcon.getIconWidth()+15,mailTextField.getPreferredSize().height) );
+// mailButton.setText(null);
+//
+// add( mailTextField, BorderLayout.CENTER );
+// add( mailButton, BorderLayout.EAST );
+// }
+//
+// /**
+// * Piped to {@link #mailTextField}.
+// */
+// public void setText(String text) {
+// mailTextField.setText(text);
+// }
+//
+// /**
+// * Piped to {@link #mailTextField}.
+// */
+// public String getText() {
+// return mailTextField.getText();
+// }
+//
+// /**
+// * Called by the {@link #mailAction} with {@link #getText()} as
+// * destination address and subject/body <code>null</code>.
+// * This method simply pipes these 3 parameters to
+// * {@link MailUtil#sendDesktopMail(String, String, String)}.<br>
+// * Sub-classes can override this method to set an application
+// * dependent subject or body.
+// *
+// */
+// protected void performMailAction(String destAddr, String subject, String body) {
+// MailUtil.sendDesktopMail(
+// getText(), subject, body);
+// }
}
Added: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/URLAddressPanel.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/URLAddressPanel.java 2011-07-21 23:01:51 UTC (rev 1645)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/URLAddressPanel.java 2011-07-22 11:26:39 UTC (rev 1646)
@@ -0,0 +1,48 @@
+package de.schmitzm.swing;
+
+import java.awt.event.ActionEvent;
+
+import javax.swing.JTextField;
+import javax.swing.text.JTextComponent;
+
+import de.schmitzm.net.mail.MailUtil;
+
+/**
+ * {@link JTextField} which accepts a internet address and
+ * provides a button to open the URL with the standard browser
+ * of the OS.
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
+ */
+public class URLAddressPanel extends AbstractActionTextPanel {
+
+ /**
+ * Creates a new text field.
+ */
+ public URLAddressPanel() {
+ super();
+ init(
+ SwingUtil.R("URLAddressPanel.Button.Label"),
+ SwingUtil.R("URLAddressPanel.Button.Tooltip"),
+ SwingUtil.createImageIconFromResourcePath(SwingUtil.class, "resource/icons/small/world2.png", null),
+ "OPEN_URL"
+ );
+ }
+
+ /**
+ * Creates the text component to specify the text.
+ * @return a new instance of {@link JTextField}
+ */
+ public JTextComponent createTextComponent() {
+ return new JTextField();
+ }
+
+ /**
+ * Called by the button action.
+ * Pipes call to {@link #performMailAction(String, String, String)}
+ * with subject/body <code>null</code>.
+ */
+ protected void performAction(ActionEvent e, String destAddr) {
+ MailUtil.openDesktopBrowser(destAddr);
+ }
+
+}
Modified: trunk/schmitzm-core/src/main/resources/de/schmitzm/net/mail/resource/locales/MailResourceBundle.properties
===================================================================
--- trunk/schmitzm-core/src/main/resources/de/schmitzm/net/mail/resource/locales/MailResourceBundle.properties 2011-07-21 23:01:51 UTC (rev 1645)
+++ trunk/schmitzm-core/src/main/resources/de/schmitzm/net/mail/resource/locales/MailResourceBundle.properties 2011-07-22 11:26:39 UTC (rev 1646)
@@ -35,3 +35,5 @@
MailUtil.DesktopMail.NotSupported=Mailing is not supported on your operating system!
MailUtil.DesktopMail.CreationError=Error during creation of exception mail
+MailUtil.DesktopBrowser.NotSupported=Opening an URL in browser is not supported on your operating system!
+MailUtil.DesktopBrowser.BrowseError=Error during browsing the URL
Modified: trunk/schmitzm-core/src/main/resources/de/schmitzm/net/mail/resource/locales/MailResourceBundle_de.properties
===================================================================
--- trunk/schmitzm-core/src/main/resources/de/schmitzm/net/mail/resource/locales/MailResourceBundle_de.properties 2011-07-21 23:01:51 UTC (rev 1645)
+++ trunk/schmitzm-core/src/main/resources/de/schmitzm/net/mail/resource/locales/MailResourceBundle_de.properties 2011-07-22 11:26:39 UTC (rev 1646)
@@ -60,3 +60,5 @@
MailUtil.DesktopMail.NotSupported=Mailen wird von Ihrem Betriebssystem leider nicht unterst\u00FCtzt.
MailUtil.DesktopMail.CreationError=Fehler beim Erstellen der Fehler-Mail
+MailUtil.DesktopBrowser.NotSupported=Das \u00D6ffnen einer URL im Browser wird von Ihrem Betriebssystem leider nicht unterst\u00FCtzt.
+MailUtil.DesktopBrowser.BrowseError=Fehler beim \u00D6ffnen der URL im Browser
Added: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/small/world.png
===================================================================
(Binary files differ)
Property changes on: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/small/world.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/small/world2.png
===================================================================
(Binary files differ)
Property changes on: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/small/world2.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
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 2011-07-21 23:01:51 UTC (rev 1645)
+++ trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle.properties 2011-07-22 11:26:39 UTC (rev 1646)
@@ -269,3 +269,8 @@
DatabaseLoginDialog.DatabaseName=Database name
DatabaseLoginDialog.UserName=User name
DatabaseLoginDialog.Password=Password
+
+MailAddressPanel.Button.Label=Mail
+MailAddressPanel.Button.Tooltip=Create mail
+URLAddressPanel.Button.Label=Browse
+URLAddressPanel.Button.Tooltip=Open URL in browser
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 2011-07-21 23:01:51 UTC (rev 1645)
+++ trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle_de.properties 2011-07-22 11:26:39 UTC (rev 1646)
@@ -242,3 +242,8 @@
DatabaseLoginDialog.DatabaseName=Name der Datenbank-Instanz
DatabaseLoginDialog.UserName=Benutzername
DatabaseLoginDialog.Password=Passwort
+
+MailAddressPanel.Button.Label=Mail
+MailAddressPanel.Button.Tooltip=Neue E-Mail erstellen
+URLAddressPanel.Button.Label=\u00D6ffnen
+URLAddressPanel.Button.Tooltip=URL in Browser \u00D6ffnen
More information about the Schmitzm-commits
mailing list