You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by jo...@apache.org on 2008/05/02 04:29:03 UTC

svn commit: r652733 [6/6] - in /archiva/sandbox/commons-transfer: ./ commons-transfer-api/ commons-transfer-api/src/ commons-transfer-api/src/main/ commons-transfer-api/src/main/java/ commons-transfer-api/src/main/java/org/ commons-transfer-api/src/mai...

Added: archiva/sandbox/commons-transfer/commons-transfer-interactive/src/main/java/org/apache/archiva/commons/transfer/interactive/swing/UIUtils.java
URL: http://svn.apache.org/viewvc/archiva/sandbox/commons-transfer/commons-transfer-interactive/src/main/java/org/apache/archiva/commons/transfer/interactive/swing/UIUtils.java?rev=652733&view=auto
==============================================================================
--- archiva/sandbox/commons-transfer/commons-transfer-interactive/src/main/java/org/apache/archiva/commons/transfer/interactive/swing/UIUtils.java (added)
+++ archiva/sandbox/commons-transfer/commons-transfer-interactive/src/main/java/org/apache/archiva/commons/transfer/interactive/swing/UIUtils.java Thu May  1 19:28:57 2008
@@ -0,0 +1,65 @@
+package org.apache.archiva.commons.transfer.interactive.swing;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import javax.swing.JFrame;
+import javax.swing.UIManager;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * UIUtils
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class UIUtils
+{
+    private static final Log log = LogFactory.getLog( UIUtils.class );
+
+    public static void setDefaultLookAndFeel()
+    {
+        try
+        {
+            UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
+        }
+        catch ( Exception e )
+        {
+            log.warn( "Unable to set System Look and Feel.", e );
+        }
+
+        JFrame.setDefaultLookAndFeelDecorated( true );
+    }
+
+    public static void setJavaLookAndFeel()
+    {
+        try
+        {
+            UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
+        }
+        catch ( Exception e )
+        {
+            log.warn( "Unable to set Java Look and Feel.", e );
+        }
+
+        JFrame.setDefaultLookAndFeelDecorated( true );
+    }
+}

Propchange: archiva/sandbox/commons-transfer/commons-transfer-interactive/src/main/java/org/apache/archiva/commons/transfer/interactive/swing/UIUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/sandbox/commons-transfer/commons-transfer-interactive/src/main/java/org/apache/archiva/commons/transfer/interactive/swing/UIUtils.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: archiva/sandbox/commons-transfer/commons-transfer-interactive/src/main/java/org/apache/archiva/commons/transfer/interactive/swing/WindowHandler.java
URL: http://svn.apache.org/viewvc/archiva/sandbox/commons-transfer/commons-transfer-interactive/src/main/java/org/apache/archiva/commons/transfer/interactive/swing/WindowHandler.java?rev=652733&view=auto
==============================================================================
--- archiva/sandbox/commons-transfer/commons-transfer-interactive/src/main/java/org/apache/archiva/commons/transfer/interactive/swing/WindowHandler.java (added)
+++ archiva/sandbox/commons-transfer/commons-transfer-interactive/src/main/java/org/apache/archiva/commons/transfer/interactive/swing/WindowHandler.java Thu May  1 19:28:57 2008
@@ -0,0 +1,104 @@
+package org.apache.archiva.commons.transfer.interactive.swing;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.awt.Dimension;
+import java.awt.Point;
+import java.awt.Window;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.util.prefs.BackingStoreException;
+import java.util.prefs.Preferences;
+
+/**
+ * WindowHandler
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class WindowHandler
+    extends WindowAdapter
+{
+
+    private Preferences appPrefs;
+
+    public WindowHandler()
+    {
+        appPrefs = Preferences.userNodeForPackage( WindowHandler.class );
+    }
+
+    public void restore( Window win )
+    {
+        String prefix = win.getName();
+        if ( prefix == null )
+        {
+            throw new IllegalStateException( "Unable to restore window preferences from nameless window." );
+        }
+
+        WindowUtils.centerWindowOnScreen( win );
+
+        int x = appPrefs.getInt( prefix + ".x", win.getX() );
+        int y = appPrefs.getInt( prefix + ".y", win.getY() );
+
+        if ( WindowUtils.isResizable( win ) )
+        {
+            int width = appPrefs.getInt( prefix + ".width", win.getWidth() );
+            int height = appPrefs.getInt( prefix + ".height", win.getHeight() );
+            win.setBounds( x, y, width, height );
+        }
+    }
+
+    public void save( Window win )
+    {
+        String prefix = win.getName();
+        if ( prefix == null )
+        {
+            throw new IllegalStateException( "Unable to save window preferences from nameless window." );
+        }
+
+        Point location = win.getLocation();
+        appPrefs.putInt( prefix + ".x", location.x );
+        appPrefs.putInt( prefix + ".y", location.y );
+
+        if ( WindowUtils.isResizable( win ) )
+        {
+            Dimension dim = win.getSize();
+            appPrefs.putInt( prefix + ".width", dim.width );
+            appPrefs.putInt( prefix + ".height", dim.height );
+        }
+
+        try
+        {
+            appPrefs.flush();
+            appPrefs.sync();
+        }
+        catch ( BackingStoreException ignore )
+        {
+            /* ignore */
+        }
+    }
+
+    @Override
+    public void windowClosing( WindowEvent e )
+    {
+        super.windowClosing( e );
+        save( e.getWindow() );
+    }
+}

Propchange: archiva/sandbox/commons-transfer/commons-transfer-interactive/src/main/java/org/apache/archiva/commons/transfer/interactive/swing/WindowHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/sandbox/commons-transfer/commons-transfer-interactive/src/main/java/org/apache/archiva/commons/transfer/interactive/swing/WindowHandler.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: archiva/sandbox/commons-transfer/commons-transfer-interactive/src/main/java/org/apache/archiva/commons/transfer/interactive/swing/WindowUtils.java
URL: http://svn.apache.org/viewvc/archiva/sandbox/commons-transfer/commons-transfer-interactive/src/main/java/org/apache/archiva/commons/transfer/interactive/swing/WindowUtils.java?rev=652733&view=auto
==============================================================================
--- archiva/sandbox/commons-transfer/commons-transfer-interactive/src/main/java/org/apache/archiva/commons/transfer/interactive/swing/WindowUtils.java (added)
+++ archiva/sandbox/commons-transfer/commons-transfer-interactive/src/main/java/org/apache/archiva/commons/transfer/interactive/swing/WindowUtils.java Thu May  1 19:28:57 2008
@@ -0,0 +1,78 @@
+package org.apache.archiva.commons.transfer.interactive.swing;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.awt.Component;
+import java.awt.Dialog;
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.awt.Point;
+import java.awt.Toolkit;
+import java.awt.Window;
+
+/**
+ * WindowUtils
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class WindowUtils
+{
+    public static void centerWindowOnParent( Window win )
+    {
+        Component comp = win.getParent();
+        if ( comp == null )
+        {
+            centerWindowOnScreen( win );
+            return;
+        }
+
+        win.setLocationRelativeTo( comp );
+        Dimension compSize = comp.getSize();
+        Point compCenter = new Point( compSize.width / 2, compSize.height / 2 );
+        Point winCenterRelative = new Point( win.getSize().width / 2, win.getSize().height / 2 );
+        win.setLocation( ( compCenter.x - winCenterRelative.x ), ( compCenter.y - winCenterRelative.y ) );
+    }
+
+    public static void centerWindowOnScreen( Window win )
+    {
+        Toolkit tk = Toolkit.getDefaultToolkit();
+        Dimension screenSize = tk.getScreenSize();
+        Point screenCenter = new Point( screenSize.width / 2, screenSize.height / 2 );
+        Point winCenterRelative = new Point( win.getSize().width / 2, win.getSize().height / 2 );
+        win.setLocation( ( screenCenter.x - winCenterRelative.x ), ( screenCenter.y - winCenterRelative.y ) );
+    }
+
+    public static boolean isResizable( Window win )
+    {
+        boolean resizable = false;
+
+        if ( win instanceof Frame )
+        {
+            resizable = ( (Frame) win ).isResizable();
+        }
+        else if ( win instanceof Dialog )
+        {
+            resizable = ( (Dialog) win ).isResizable();
+        }
+
+        return resizable;
+    }
+}

Propchange: archiva/sandbox/commons-transfer/commons-transfer-interactive/src/main/java/org/apache/archiva/commons/transfer/interactive/swing/WindowUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/sandbox/commons-transfer/commons-transfer-interactive/src/main/java/org/apache/archiva/commons/transfer/interactive/swing/WindowUtils.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: archiva/sandbox/commons-transfer/pom.xml
URL: http://svn.apache.org/viewvc/archiva/sandbox/commons-transfer/pom.xml?rev=652733&view=auto
==============================================================================
--- archiva/sandbox/commons-transfer/pom.xml (added)
+++ archiva/sandbox/commons-transfer/pom.xml Thu May  1 19:28:57 2008
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?><project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.archiva.commons.transfer</groupId>
+  <artifactId>commons-transfer-parent</artifactId>
+  <name>Commons Transfer :: Parent</name>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration>
+          <source>1.5</source>
+          <target>1.5</target>
+        </configuration>
+      </plugin>
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <includes>
+            <include>**/Test*.java</include>
+            <include>**/Test.java</include>
+            <include>**/*TestCase.java</include>
+          </includes>
+          <excludes>
+            <exclude>**/Abstract*.java</exclude>
+          </excludes>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  <modules>
+    <module>commons-transfer-api</module>
+    <module>commons-transfer-file</module>
+    <module>commons-transfer-interactive</module>
+    <module>commons-transfer-http</module>
+  </modules>
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+  <reporting>
+    <plugins>
+      <plugin>
+        <artifactId>maven-javadoc-plugin</artifactId>
+        <configuration>
+          <aggregate>true</aggregate>
+        </configuration>
+      </plugin>
+    </plugins>
+  </reporting>
+</project>

Propchange: archiva/sandbox/commons-transfer/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/sandbox/commons-transfer/pom.xml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Propchange: archiva/sandbox/commons-transfer/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml