harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjanu...@apache.org
Subject svn commit: r672793 - in /harmony/enhanced/jdktools/trunk/modules: samsa/ tools/src/main/java/org/apache/harmony/tools/policytool/ tools/src/main/java/org/apache/harmony/tools/policytool/control/ tools/src/main/java/org/apache/harmony/tools/policytool/...
Date Mon, 30 Jun 2008 15:23:04 GMT
Author: sjanuary
Date: Mon Jun 30 08:23:03 2008
New Revision: 672793

URL: http://svn.apache.org/viewvc?rev=672793&view=rev
Log:
Apply initial patch for HARMONY-5886 (The well known policytool tool for Harmony)

Added:
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/Consts.java   (with props)
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/Main.java   (with props)
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/control/
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/control/Controller.java   (with props)
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/control/PolicyFileHandler.java   (with props)
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/CommentEntry.java   (with props)
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/KeystoreEntry.java   (with props)
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/KeystorePasswordURLEntry.java   (with props)
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/PolicyEntry.java   (with props)
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/DirectTextEditorPanel.java   (with props)
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/EditorPanel.java   (with props)
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/GraphicalEditorPanel.java   (with props)
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/MainFrame.java   (with props)
Modified:
    harmony/enhanced/jdktools/trunk/modules/samsa/build.xml

Modified: harmony/enhanced/jdktools/trunk/modules/samsa/build.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/samsa/build.xml?rev=672793&r1=672792&r2=672793&view=diff
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/samsa/build.xml (original)
+++ harmony/enhanced/jdktools/trunk/modules/samsa/build.xml Mon Jun 30 08:23:03 2008
@@ -84,6 +84,9 @@
         <copy file="${hy.samsa.exe}" tofile="${jdktools.deploy.dir}/bin/unpack200${exe.suffix}" />
         <chmod file="${jdktools.deploy.dir}/bin/unpack200${exe.suffix}" perm="ugo+x" />
 
+        <copy file="${hy.samsa.exe}" tofile="${jdktools.deploy.dir}/bin/policytool${exe.suffix}" />
+        <chmod file="${jdktools.deploy.dir}/bin/policytool${exe.suffix}" perm="ugo+x" />
+
     </target>
 
     <!-- copy windows javaw executable -->

Added: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/Consts.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/Consts.java?rev=672793&view=auto
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/Consts.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/Consts.java Mon Jun 30 08:23:03 2008
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+
+package org.apache.harmony.tools.policytool;
+
+/**
+ * Holds general and application-wide constants.
+ */
+public class Consts {
+	
+	/** Name of the application. */
+	public static final String APPLICATION_NAME = "Policytool";
+	
+	/** X coordinate of the main frame on startup. */
+	public static final int MAIN_FRAME_START_POS_X = 200;
+	/** Y coordinate of the main frame on startup. */
+	public static final int MAIN_FRAME_START_POS_Y = 100;
+	
+	/** Font size in the direct editing panel.     */
+	public static final int DIRECT_EDITING_FONT_SIZE = 13;
+	
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/Consts.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/Consts.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/Main.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/Main.java?rev=672793&view=auto
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/Main.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/Main.java Mon Jun 30 08:23:03 2008
@@ -0,0 +1,100 @@
+/*
+ * 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.
+ */
+
+package org.apache.harmony.tools.policytool;
+
+import org.apache.harmony.tools.policytool.view.MainFrame;
+
+/**
+ * The main class that parses command line parameters, and starts the GUI if everything everything is ok.
+ * 
+ */
+public class Main {
+	
+	/** Name of policy file to be loaded initially. */
+	private static String policyFileName;
+	
+    /**
+     * Entry point of the program.
+     * 
+     * @param arguments used to take arguments from the running environment
+     */
+    public static void main( final String[] arguments ) {
+    	
+    	if ( processArguments( arguments ) ) {
+    		if ( policyFileName == null )
+    			new MainFrame().setVisible( true );
+    		else
+    			new MainFrame( policyFileName ).setVisible( true );
+    	}
+    	
+    }
+    
+    /**
+     * Processes the command line arguments.<br>
+     * Currently only one option is supported:
+     * <pre><code>    [-file file]</code></pre>
+     * for specifying the name of a policy file to be loaded initially.
+     * 
+     * @param arguments arguments taken from the running environment
+     * @return true if arguments were processed successfully and launching the GUI is allowed;<br>
+     *         false if there were missing or invalid arguments, or no GUI launch is needed
+     */
+    private static boolean processArguments( final String[] arguments ) {
+    	if ( arguments.length == 0 )
+    		return true;
+    	
+    	else {
+    		if ( arguments[ 0 ].startsWith( "-" ) ) // If it is a "real" option
+	    		if ( arguments[ 0 ].equalsIgnoreCase( "-file" ) ) {
+	    			if ( arguments.length < 2 ) {   // policy file name must be provided
+	    				printErrorMessageAndUsage( "Missing policy file name!" );
+	    				return false;
+	    			}
+	    			else {
+	    				policyFileName = arguments[ 1 ];
+	    				return true;
+	    			}
+	    		}
+	    		else {
+	    			printErrorMessageAndUsage( "Illegal option: " + arguments[ 0 ] );
+	    			return false;
+	    		}
+    		else
+    			return true;  // else the arguments are ignored
+    	}
+    }
+    
+    /**
+     * Prints an error message to the standard output followed by the program ussage.
+     * @param errorMessage error message to be printed
+     */
+    private static void printErrorMessageAndUsage( final String errorMessage ) {
+    	System.out.println( errorMessage );
+    	printUsage();
+    }
+    
+    /**
+     * Prints the program usage to the standard output.
+     */
+    private static void printUsage() {
+    	System.out.println( "Usage: policytool [options]" );
+    	System.out.println();
+    	System.out.println( "  [-file <file>]    name of policy file to be loaded initially" );
+    }
+    
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/Main.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/Main.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/control/Controller.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/control/Controller.java?rev=672793&view=auto
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/control/Controller.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/control/Controller.java Mon Jun 30 08:23:03 2008
@@ -0,0 +1,211 @@
+/*
+ * 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.
+ */
+
+package org.apache.harmony.tools.policytool.control;
+
+import java.awt.Component;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.File;
+
+import javax.swing.JFileChooser;
+import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
+import javax.swing.JTabbedPane;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+
+import org.apache.harmony.tools.policytool.view.EditorPanel;
+import org.apache.harmony.tools.policytool.view.MainFrame.MenuItemEnum;
+
+/**
+ * The controller handles the user actions, drives the GUI and connects it to the model.
+ */
+public class Controller implements ChangeListener, ActionListener{
+	
+	/** Reference to the main frame component.    */
+	private final Component     mainFrame;
+	/** Array of the editor panels.               */
+	private final EditorPanel[] editorPanels;
+	/** Reference to the active editor panel.     */
+	private EditorPanel         activeEditorPanel;
+	
+	/** Reference to the keystore edit menu item. */
+	private JMenuItem           keystoreEditMenuItem;
+	
+	/** The currently edited policy file.         */
+	private File editedPolicyFile;
+	
+	/**
+	 * Creates a new Controller.
+	 * @param mainFrame reference to the main frame component
+	 * @param editorPanels array of the editor panels
+	 * @param policyFileName policy file name to be loaded initially
+	 */
+	public Controller( final Component mainFrame, final EditorPanel[] editorPanels, final String policyFileName ) {
+		this.mainFrame    = mainFrame;
+		this.editorPanels = editorPanels;
+		activeEditorPanel = editorPanels[ 0 ];
+		
+		PolicyFileHandler.setDialogParentComponent( mainFrame );
+		
+		editedPolicyFile = new File( policyFileName );
+		activeEditorPanel.loadPolicyText( PolicyFileHandler.loadPoilcyFile( editedPolicyFile ) );
+	}
+	
+	/**
+	 * Returns the array of editor panels.
+	 * @return the array of editor panels
+	 */
+	public EditorPanel[] getEditorPanels() {
+		return editorPanels;
+	}
+	
+	/**
+	 * Sets the keystore edit menu item.
+	 * @param keystoreEditMenuItem the keystore edit menu item
+	 */
+	public void setKeystoreEditMenuItem( final JMenuItem keystoreEditMenuItem ) {
+		this.keystoreEditMenuItem = keystoreEditMenuItem;
+		keystoreEditMenuItem.setEnabled( activeEditorPanel.supportsGraphicalKeystoreEdit() );
+	}
+	
+	/**
+	 * Exits from the program.<br>
+	 * There might be unsaved changes in which case confirmation will be asked.
+	 */
+	public void exit() {
+		boolean exitOk = false;
+		
+		if ( activeEditorPanel.getHasDirty() ) {
+			
+			switch ( JOptionPane.showConfirmDialog( mainFrame, "There are unsaved changes. Save before exit?", "Warning", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE ) ) {
+			
+			case JOptionPane.YES_OPTION:
+				final JFileChooser fileChooser = new JFileChooser();
+				
+				if ( editedPolicyFile == null ) {
+					if ( fileChooser.showSaveDialog( mainFrame ) == JFileChooser.APPROVE_OPTION )
+						editedPolicyFile = fileChooser.getSelectedFile();
+				}
+				if ( editedPolicyFile != null ) {
+					if ( !PolicyFileHandler.savePolicyFile( editedPolicyFile, activeEditorPanel.getPolicyText() ) ) {
+						switch ( JOptionPane.showConfirmDialog( mainFrame, "Saving failed. Do you still want to exit?", "Warning", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE ) ) {
+						case JOptionPane.YES_OPTION:
+							exitOk = true;
+							break;
+							
+						case JOptionPane.NO_OPTION:
+						case JOptionPane.CLOSED_OPTION:
+							// We chose not to exit. exitOk = false
+							break;
+						}
+					}
+					else {// Changes saved successfully
+						activeEditorPanel.setHasDirty( false );						
+						exitOk = true;
+					}
+				}
+				break;
+				
+			case JOptionPane.NO_OPTION:
+				exitOk = true;
+				break;
+				
+			case JOptionPane.CANCEL_OPTION:
+			case JOptionPane.CLOSED_OPTION:
+				// We chose not to exit. exitOk = false
+				break;
+				
+			}
+			
+		}
+		else
+			exitOk = true;
+		
+		if ( exitOk )
+			System.exit( 0 );
+	}
+	
+	/**
+	 * Handles change events of the editors tabbed pane.
+	 * @param ce details of the change event
+	 */
+	public void stateChanged( final ChangeEvent ce ) {
+		final EditorPanel newActiveEditorPanel = (EditorPanel) ( (JTabbedPane) ce.getSource() ).getSelectedComponent();
+		
+		newActiveEditorPanel.loadPolicyText( activeEditorPanel.getPolicyText() );
+		newActiveEditorPanel.setHasDirty   ( activeEditorPanel.getHasDirty  () );
+		activeEditorPanel = newActiveEditorPanel;
+		
+		keystoreEditMenuItem.setEnabled( activeEditorPanel.supportsGraphicalKeystoreEdit() );
+	}
+	
+	/**
+	 * Handles the action events of the menu items.
+	 * @param ae details of the action event
+	 */
+	public void actionPerformed( final ActionEvent ae ) {
+		// The action command is the ordinal of the menu item enum.
+		final MenuItemEnum menuItemEnum = MenuItemEnum.values()[ Integer.parseInt( ae.getActionCommand() ) ];
+		
+		final JFileChooser fileChooser = new JFileChooser();
+		switch ( menuItemEnum ) {
+		
+		case NEW :
+			break;
+			
+		case OPEN :
+			if ( fileChooser.showOpenDialog( mainFrame ) == JFileChooser.APPROVE_OPTION ) {
+				editedPolicyFile = fileChooser.getSelectedFile();
+				activeEditorPanel.loadPolicyText( PolicyFileHandler.loadPoilcyFile( editedPolicyFile ) );
+			}
+			break;
+			
+		case SAVE :
+			if ( editedPolicyFile == null ) {
+				if ( fileChooser.showSaveDialog( mainFrame ) == JFileChooser.APPROVE_OPTION )
+					editedPolicyFile = fileChooser.getSelectedFile();
+			}
+			if ( editedPolicyFile != null )
+				if ( PolicyFileHandler.savePolicyFile( editedPolicyFile, activeEditorPanel.getPolicyText() ) )
+					activeEditorPanel.setHasDirty( false );						
+			break;
+			
+		case SAVE_AS :
+			if ( fileChooser.showSaveDialog( mainFrame ) == JFileChooser.APPROVE_OPTION ) {
+				editedPolicyFile = fileChooser.getSelectedFile();
+				if ( PolicyFileHandler.savePolicyFile( editedPolicyFile, activeEditorPanel.getPolicyText() ) )
+					activeEditorPanel.setHasDirty( false );						
+			}
+			break;
+			
+		case VIEW_WARNING_LOG :
+			break;
+			
+		case EXIT :
+			exit();
+			break;
+			
+		case EDIT :
+			break;
+			
+		}
+		
+	}
+	
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/control/Controller.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/control/Controller.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/control/PolicyFileHandler.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/control/PolicyFileHandler.java?rev=672793&view=auto
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/control/PolicyFileHandler.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/control/PolicyFileHandler.java Mon Jun 30 08:23:03 2008
@@ -0,0 +1,138 @@
+/*
+ * 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.
+ */
+
+package org.apache.harmony.tools.policytool.control;
+
+import java.awt.Component;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
+
+import javax.swing.JOptionPane;
+
+/**
+ * This class is responsible to read policy text from and write policy text to policy files.<br>
+ * We're aware of the UTF-8 policy file encoding. 
+ */
+public class PolicyFileHandler {
+	
+	/** Encoding of the policy file by the specification. */
+	private static final String POLICY_FILE_ENCODING = "UTF-8";
+	
+	/** Platform dependent line separator. */
+	private static final String LINE_SEPARATOR = System.getProperty( "line.separator" );
+	
+	/** Parent component to be used when displaying dialogs. */
+	private static Component dialogParentComponent;
+	
+	/**
+	 * Sets the parent component to be used when displaying dialogs.
+	 * @param dialogParentComponent component to be used when displaying dialogs
+	 */
+	public static void setDialogParentComponent( final Component dialogParentComponent ) {
+		PolicyFileHandler.dialogParentComponent = dialogParentComponent;
+	}
+	
+	/**
+	 * Loads the content of a policy file.
+	 * @param policyFile policy file whose content to be loaded
+	 * @return the policy text within the given policy file
+	 */
+	public static String loadPoilcyFile( final File policyFile ) {
+		final StringBuilder policyTextBuilder = new StringBuilder();
+		
+		BufferedReader input = null;
+		try {
+			
+			input = new BufferedReader( new InputStreamReader( new FileInputStream( policyFile ), POLICY_FILE_ENCODING ) );
+			String line;
+			while ( ( line = input.readLine() ) != null )
+				policyTextBuilder.append( line ).append( LINE_SEPARATOR );
+			
+		}
+		catch ( final FileNotFoundException fnfe ) {
+			JOptionPane.showMessageDialog( dialogParentComponent, "The file does not exist!", "Error", JOptionPane.ERROR_MESSAGE );
+			return null;
+		}
+		catch ( final UnsupportedEncodingException uee ) {
+			// This should never happen.
+			uee.printStackTrace();
+			return null;
+		}
+		catch ( final IOException ie ) {
+			JOptionPane.showMessageDialog( dialogParentComponent, new String[] { "I/O error occured, can't read the file!", ie.getMessage() }, "Error", JOptionPane.ERROR_MESSAGE );
+			return null;
+		}
+		finally {
+			if ( input != null )
+				try {
+					input.close();
+				}
+				catch ( final IOException ie ) {
+					ie.printStackTrace();
+				}
+		}
+		
+		return policyTextBuilder.toString();
+	}
+	
+	/**
+	 * Saves policy text to a policy file.
+	 * @param policyFile policy file to save to
+	 * @param policyText policy text to be saved
+	 * @return true, if saving was successful; false otherwise
+	 */
+	public static boolean savePolicyFile( final File policyFile, final String policyText ) {
+		OutputStreamWriter output = null;
+		try {
+			output = new OutputStreamWriter( new FileOutputStream( policyFile ), POLICY_FILE_ENCODING );
+			
+			output.write( policyText );
+			
+			return true;
+		}
+		catch ( final UnsupportedEncodingException uee ) {
+			// This should never happen.
+			uee.printStackTrace();
+		}
+		catch ( final FileNotFoundException ffe ) {
+			JOptionPane.showMessageDialog( dialogParentComponent, new String[] { "Cannot open file for writing!", ffe.getMessage() }, "Error", JOptionPane.ERROR_MESSAGE );
+			ffe.printStackTrace();
+		} catch ( final IOException ie ) {
+			JOptionPane.showMessageDialog( dialogParentComponent, new String[] { "Write error!", ie.getMessage() }, "Error", JOptionPane.ERROR_MESSAGE );
+			ie.printStackTrace();
+		} 
+		finally {
+			if ( output != null )
+				try {
+					output.close();
+				}
+				catch ( final IOException ie ) {
+					ie.printStackTrace();
+				}
+		}
+		
+		return false;
+	}
+	
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/control/PolicyFileHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/control/PolicyFileHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/CommentEntry.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/CommentEntry.java?rev=672793&view=auto
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/CommentEntry.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/CommentEntry.java Mon Jun 30 08:23:03 2008
@@ -0,0 +1,51 @@
+/*
+ * 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.
+ */
+
+package org.apache.harmony.tools.policytool.model;
+
+/**
+ * Represents a comment entry which does not modify the access granted by the policy text which this belongs to.<br>
+ * It may exist to:
+ * <ul>
+ *     <li>separate, tag the policy text
+ *     <li>hold informations, comments for the author or the user of the policy text
+ * </ul> 
+ */
+public class CommentEntry extends PolicyEntry {
+	
+	/** Comment entries are not tokenized just holds the entry text "as is". */
+	private String entryText;
+	
+	/**
+	 * Creates a new CommentEntry.
+	 * @param entryText policy entry text of the entry
+	 */
+	public CommentEntry( final String entryText ) {
+		setText( entryText );
+	}
+	
+	@Override
+	public String getText() {
+		return entryText;
+	}
+	
+	@Override
+	public void setText( final String entryText ) {
+		this.entryText = entryText;
+	}
+	
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/CommentEntry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/CommentEntry.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/KeystoreEntry.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/KeystoreEntry.java?rev=672793&view=auto
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/KeystoreEntry.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/KeystoreEntry.java Mon Jun 30 08:23:03 2008
@@ -0,0 +1,78 @@
+/*
+ * 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.
+ */
+
+package org.apache.harmony.tools.policytool.model;
+
+/**
+ * Represents the keystore entry of the policy text.<br>
+ * There may be several keystore entries in a policy text, but only the first one is interpreted and used, the rest are ignored.<br>
+ * The keystore entry must be provided if:
+ * <ul>
+ *     <li>there are grant entries which specify signer aliases
+ *     <li>or there are grant entries which specify principal aliases
+ * </ul>
+ * @see KeystorePasswordURLEntry
+ */
+public class KeystoreEntry extends PolicyEntry {
+	
+	/** Keyword of the keystore entry in the policy text. */
+	public static final String KEYWORD = "keystore";
+	
+	/** URL of the keystore.      */
+	private String url;
+	/** Type of the keystore.     */
+	private String type;
+	/** Provider of the keystore. */
+	private String provider;
+	
+	@Override
+	public String getText() {
+		final StringBuilder textBuilder = new StringBuilder( KEYWORD );
+		boolean firstParamAdded = false;
+		
+		if ( url != null ) {
+			textBuilder.append( " \"" ).append( url ).append( '"' );
+			firstParamAdded = true;
+		}
+		
+		if ( type != null ) {
+			if ( firstParamAdded )
+				textBuilder.append( ',' );
+			else
+				firstParamAdded = true;
+			textBuilder.append( " \"" ).append( type ).append( '"' );
+		}
+		
+		if ( provider != null ) {
+			if ( firstParamAdded )
+				textBuilder.append( ',' );
+			else
+				firstParamAdded = true;
+			textBuilder.append( " \"" ).append( provider ).append( '"' );
+		}
+		
+		textBuilder.append( TERMINATOR_CHAR );
+		
+		return textBuilder.toString();
+	}
+	
+	@Override
+	public void setText( final String entryText ) {
+		// TODO Auto-generated method stub
+	}
+	
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/KeystoreEntry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/KeystoreEntry.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/KeystorePasswordURLEntry.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/KeystorePasswordURLEntry.java?rev=672793&view=auto
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/KeystorePasswordURLEntry.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/KeystorePasswordURLEntry.java Mon Jun 30 08:23:03 2008
@@ -0,0 +1,46 @@
+/*
+ * 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.
+ */
+
+package org.apache.harmony.tools.policytool.model;
+
+/**
+ * Represents the keystore password URL entry of the policy text.<br>
+ * Just as keystore entry there may be several keystore password URL entries in a policy text,
+ * but only the first one is interpreted and used, the rest are ignored.<br>
+ * The entry specifies the location of the keystore password.<br>
+ * The entry should be put next the the keystore entry.
+ * @see KeystoreEntry
+ */
+public class KeystorePasswordURLEntry extends PolicyEntry {
+	
+	/** Keyword of the keystore password URL entry in the policy text. */
+	public static final String KEYWORD = "keystorePasswordURL";
+	
+	/** URL of the keystore password. */
+	private String url;
+	
+	@Override
+	public String getText() {
+		return KEYWORD + " \"" + url + '\"' + TERMINATOR_CHAR;
+	}
+	
+	@Override
+	public void setText( final String entryText ) {
+		// TODO Auto-generated method stub
+	}
+	
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/KeystorePasswordURLEntry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/KeystorePasswordURLEntry.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/PolicyEntry.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/PolicyEntry.java?rev=672793&view=auto
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/PolicyEntry.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/PolicyEntry.java Mon Jun 30 08:23:03 2008
@@ -0,0 +1,40 @@
+/*
+ * 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.
+ */
+
+package org.apache.harmony.tools.policytool.model;
+
+/**
+ * Abstract ancestor to represent a policy entry.
+ */
+public abstract class PolicyEntry {
+	
+	/** Terminator character of the policy entry texts. */
+	public static final char TERMINATOR_CHAR = ';';
+	
+	/**
+	 * Returns the policy entry text.
+	 * @return the policy entry text
+	 */
+	public abstract String getText();
+	
+	/**
+	 * Sets the policy entry text.
+	 * @param entryText policy entry text to be set
+	 */
+	public abstract void setText( final String entryText );
+	
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/PolicyEntry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/PolicyEntry.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/DirectTextEditorPanel.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/DirectTextEditorPanel.java?rev=672793&view=auto
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/DirectTextEditorPanel.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/DirectTextEditorPanel.java Mon Jun 30 08:23:03 2008
@@ -0,0 +1,77 @@
+/*
+ * 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.
+ */
+
+package org.apache.harmony.tools.policytool.view;
+
+import java.awt.BorderLayout;
+import java.awt.Font;
+
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
+
+import org.apache.harmony.tools.policytool.Consts;
+
+/**
+ * An editor panel which provides an interface for direct editing the policy text.
+ */
+public class DirectTextEditorPanel extends EditorPanel {
+	
+	/** Text area for direct editing the policy text. */
+	private final JTextArea policyTextTextArea = new JTextArea();
+	
+	/**
+	 * Creates a new DirectTextEditorPanel.<br>
+	 * Sets a BorderLayout as the layout manager.
+	 */
+	public DirectTextEditorPanel() {
+		super( new BorderLayout(), false );
+		
+		policyTextTextArea.setFont( new Font( "Courier New", Font.PLAIN, Consts.DIRECT_EDITING_FONT_SIZE ) );
+		
+		// We want to track changes of the document so we can ask confirmation on exit
+		policyTextTextArea.getDocument().addDocumentListener( new DocumentListener() {
+			public void changedUpdate( final DocumentEvent de ) {
+			}
+			public void insertUpdate ( final DocumentEvent de ) {
+				setHasDirty( true );
+			}
+			public void removeUpdate ( final DocumentEvent de ) {
+				setHasDirty( true );
+			}
+		} );
+		
+		add( new JScrollPane( policyTextTextArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS ), BorderLayout.CENTER );
+	}
+	
+	@Override
+	public String getPanelTitle() {
+		return "Direct editing";
+	}
+	
+	@Override
+	public void loadPolicyText( final String policyText ) {
+		policyTextTextArea.setText( policyText );
+	}
+	
+	@Override
+	public String getPolicyText() {
+		return policyTextTextArea.getText();
+	}
+	
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/DirectTextEditorPanel.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/DirectTextEditorPanel.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/EditorPanel.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/EditorPanel.java?rev=672793&view=auto
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/EditorPanel.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/EditorPanel.java Mon Jun 30 08:23:03 2008
@@ -0,0 +1,87 @@
+/*
+ * 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.
+ */
+
+package org.apache.harmony.tools.policytool.view;
+
+import java.awt.LayoutManager;
+
+import javax.swing.JPanel;
+
+/**
+ * Defines an abstract editor panel which can provide a GUI for editing a policy text.
+ */
+public abstract class EditorPanel extends JPanel {
+	
+	/** Tells whether this editor panel has unsaved changes.              */
+	protected boolean hasDirty;
+	/** Tells whether this editor panel supports graphical keystore edit. */
+	protected boolean supportsGraphicalKeystoreEdit;
+	
+	/**
+	 * Creates a new EditorPanel.<br>
+	 * Awaits a layout manager to be sent to the super class.
+	 * @param layoutManager layout manager to be used
+	 * @param supportsGraphicalKeystoreEdit true if this editor panel supports graphical keystore edit; false otherwise
+	 */
+	public EditorPanel( final LayoutManager layoutManager, final boolean supportsGraphicalKeystoreEdit ) {
+		super( layoutManager );
+		this.supportsGraphicalKeystoreEdit = supportsGraphicalKeystoreEdit;
+	}
+	
+	/**
+	 * Returns the title of the panel.
+	 * @return the title of the panel
+	 */
+	public abstract String getPanelTitle();
+	
+	/**
+	 * Loads the specified policy text into the editor panel.
+	 * @param policyText policy text to be loaded
+	 */
+	public abstract void loadPolicyText( final String policyText );
+	
+	/**
+	 * Returns the policy text hold by this editor panel.
+	 * @return the policy text hold by this editor panel
+	 */
+	public abstract String getPolicyText();
+	
+	/**
+	 * Tells whether this editor panel has unsaved changes.
+	 * @return true if the editor panel has unsaved changes
+	 */
+	public boolean getHasDirty() {
+		return hasDirty;
+	}
+	
+	/**
+	 * Sets the hasDirty property.
+	 * @param hasDirty value of hasDirty to be set
+	 */
+	public void setHasDirty( final boolean hasDirty ) {
+		this.hasDirty = hasDirty;
+	}
+	
+	/**
+	 * Tells whether this editor panel supports graphical keystore edit.
+	 * @return true if this editor panel supports graphical keystore edit; false otherwise
+	 */
+	public boolean supportsGraphicalKeystoreEdit() {
+		return supportsGraphicalKeystoreEdit;
+	}
+	
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/EditorPanel.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/EditorPanel.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/GraphicalEditorPanel.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/GraphicalEditorPanel.java?rev=672793&view=auto
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/GraphicalEditorPanel.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/GraphicalEditorPanel.java Mon Jun 30 08:23:03 2008
@@ -0,0 +1,59 @@
+/*
+ * 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.
+ */
+
+package org.apache.harmony.tools.policytool.view;
+
+import java.awt.BorderLayout;
+import java.util.List;
+
+import org.apache.harmony.tools.policytool.model.PolicyEntry;
+
+/**
+ * An editor panel which provides an interface for direct editing the policy text.
+ */
+public class GraphicalEditorPanel extends EditorPanel {
+	
+	/** Holds the invalid policy text or null if the loaded policy text is valid.        */
+	private String invalidPolicyText;
+	
+	/** The list of the policy text's entries or null if invalid policy text was loaded. */
+	private List< PolicyEntry > policyEntryList;
+	
+	/**
+	 * Creates a new GraphicalEditorPanel.<br>
+	 * Sets a BorderLayout as the layout manager.
+	 */
+	public GraphicalEditorPanel() {
+		super( new BorderLayout(), true );
+	}
+	
+	@Override
+	public String getPanelTitle() {
+		return "Graphical editing";
+	}
+	
+	@Override
+	public void loadPolicyText( final String policyText ) {
+		this.invalidPolicyText = policyText;
+	}
+	
+	@Override
+	public String getPolicyText() {
+		return invalidPolicyText;
+	}
+	
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/GraphicalEditorPanel.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/GraphicalEditorPanel.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/MainFrame.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/MainFrame.java?rev=672793&view=auto
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/MainFrame.java (added)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/MainFrame.java Mon Jun 30 08:23:03 2008
@@ -0,0 +1,197 @@
+/*
+ * 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.
+ */
+
+package org.apache.harmony.tools.policytool.view;
+
+import java.awt.BorderLayout;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import javax.swing.JFrame;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JMenuItem;
+import javax.swing.JTabbedPane;
+
+import org.apache.harmony.tools.policytool.Consts;
+import org.apache.harmony.tools.policytool.control.Controller;
+
+/**
+ * This is the main frame of policytool.
+ */
+public class MainFrame extends JFrame {
+	
+	/**
+	 * Creates a new <code>MainFrame</code> with no initial poilcy file.
+	 */
+	public MainFrame() {
+		this( null );
+	}
+	
+	/**
+	 * Creates a new <code>MainFrame</code>.
+	 * @param policyFileName policy file name to be loaded initially
+	 */
+	public MainFrame( final String policyFileName ) {
+		super( Consts.APPLICATION_NAME );
+		
+		final EditorPanel[] editorPanels = new EditorPanel[] { new GraphicalEditorPanel(), new DirectTextEditorPanel() };
+		final Controller    controller   = new Controller( this, editorPanels, policyFileName );
+		
+		buildGUI( controller );
+		
+		setLocation( Consts.MAIN_FRAME_START_POS_X, Consts.MAIN_FRAME_START_POS_X );
+		setSize( 400, 400 );
+		setDefaultCloseOperation( DO_NOTHING_ON_CLOSE );
+		addWindowListener( new WindowAdapter() {
+			public void windowClosing( final WindowEvent we ) {
+				controller.exit();
+			}
+		} );
+	}
+	
+	/**
+	 * Builds the graphical user interface of the main frame.
+	 * @param controller reference to the controller
+	 */
+	private void buildGUI( final Controller controller ) {
+		buildMenusAndMenuBar( controller );
+		buildTabbedPane     ( controller );
+	}
+	
+	/**
+	 * Menu items of policytool.
+	 */
+	public static enum MenuItemEnum {
+		/** File menu                  */
+		FILE            ( true, "File"       ),
+		/** New menu item              */
+		NEW             ( "New"              ),
+		/** Save menu item             */
+		OPEN            ( "Open"             ),
+		/** Save menu item             */
+		SAVE            ( "Save"             ),
+		/** Save as menu item          */
+		SAVE_AS         ( "Save As...", 'a'  ),
+		/** View warning log menu item */
+		VIEW_WARNING_LOG( "View Warning Log" ),
+		/** Exit menu item             */
+		EXIT            ( "Exit", 'x'        ),
+		/** KeyStore menu              */
+		KEY_STORE       ( true, "KeyStore"   ),
+		/** Edit menu item             */
+		EDIT            ( "Edit"             );
+		
+		/** If true, then this represents a menu instead of a menu item. */
+		public final boolean isMenu;
+		/** Text of the menu item.                                       */
+		public final String  text;
+		/** Mnemonic for the menu item.                                  */
+		public final char    mnemonic;
+		
+		/**
+		 * Creates a new MenuItemEnum with a default mnemonic of the first character of its text.
+		 * @param isMenu indicating if this will be a menu
+		 * @param text text of the menu item
+		 */
+		private MenuItemEnum( final boolean isMenu, final String text ) {
+			this( isMenu, text, text.charAt( 0 ) );
+		}
+		
+		/**
+		 * Creates a new MenuItemEnum with a default mnemonic of the first character of its text.
+		 * @param text text of the menu item
+		 */
+		private MenuItemEnum( final String text ) {
+			this( false, text, text.charAt( 0 ) );
+		}
+		
+		/**
+		 * Creates a new MenuItemEnum.
+		 * @param text text of the menu item
+		 * @param mnemonic mnemonic for the menu item
+		 */
+		private MenuItemEnum( final String text, final char mnemonic ) {
+			this( false, text, mnemonic );
+		}
+		
+		/**
+		 * Creates a new MenuItemEnum.
+		 * @param isMenu indicating if this will be a menu
+		 * @param text text of the menu item
+		 * @param mnemonic mnemonic for the menu item
+		 */
+		private MenuItemEnum( final boolean isMenu, final String text, final char mnemonic ) {
+			this.isMenu   = isMenu;
+			this.text     = text;
+			this.mnemonic = mnemonic;
+		}
+		
+	};
+	
+	/**
+	 * Builds the menus and the menu bar.
+	 * @param controller reference to the controller 
+	 */
+	private void buildMenusAndMenuBar( final Controller controller ) {
+		final JMenuBar menuBar = new JMenuBar();
+		
+		JMenu menu = null;
+		for ( final MenuItemEnum menuItemEnum : MenuItemEnum.values() ) {
+			if ( menuItemEnum.isMenu ) {
+				menu = new JMenu( menuItemEnum.text );
+				menu.setMnemonic( menuItemEnum.mnemonic );
+				menuBar.add( menu );
+			}
+			else {
+				final JMenuItem menuItem = new JMenuItem( menuItemEnum.text );
+				menuItem.setMnemonic( menuItemEnum.mnemonic );
+				menuItem.addActionListener( controller );
+				menuItem.setActionCommand( Integer.toString( menuItemEnum.ordinal() ) );
+				menu.add( menuItem );
+				if ( menuItemEnum == MenuItemEnum.EDIT )
+					controller.setKeystoreEditMenuItem( menuItem );
+			}
+		}
+		
+		setJMenuBar( menuBar );
+	}
+	
+	/**
+	 * Builds the tabbed pane containing the editor panels.
+	 * @param controller reference to the controller 
+	 */
+	private void buildTabbedPane( final Controller controller ) {
+		final JTabbedPane   tabbedPane   = new JTabbedPane();
+		final EditorPanel[] editorPanels = controller.getEditorPanels();
+		
+		for ( int i = 0; i < editorPanels.length; i++ ) {
+			final EditorPanel editorPanel = editorPanels[ i ];
+			final String      panelTitle  = (i+1) + " " + editorPanel.getPanelTitle();
+			
+			tabbedPane.addTab( panelTitle, editorPanel );
+			
+			if ( i < 9 ) // We only set 1..9 mnemonic characters
+				tabbedPane.setMnemonicAt( i, '1' + i );
+		}
+		
+		tabbedPane.addChangeListener( controller );
+		
+		add( tabbedPane , BorderLayout.CENTER );
+	}
+	
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/MainFrame.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/MainFrame.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message