/* * MyInternalFrame.java * * * ==================================================== Professional Data Security (PDS) http://crypto.brettlee.com ==================================================== Copyright (c) 2009-2011, Brett Lee All rights reserved. Portions Copyright (C) 1995-2008, Sun Microsystems, Inc. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the ORGANIZATION nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ============================================================================= */ package com.brettlee.crypto; import java.awt.Color; import java.util.HashMap; import javax.swing.Action; import javax.swing.JInternalFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.event.InternalFrameEvent; import javax.swing.event.InternalFrameListener; import javax.swing.text.StyledEditorKit; /** * MyInternalFrame :: Used to override JInternalFrame: * adding a CryptoFile to the Internal Frame * adding a listener to the Internal Frame so unsaved changes can be noticed * */ class MyInternalFrame extends JInternalFrame implements InternalFrameListener { /** * */ private final Gui mGui; CryptoFile cryptoFile; HashMap actions; public MyInternalFrame(Gui theGui, CryptoFile relatedCryptoFile) { super(relatedCryptoFile.getFullyPathedFileName(), true, true, true, true ); mGui = theGui; cryptoFile = relatedCryptoFile; addInternalFrameListener(this); JMenu fontMenu = createFontMenu(); JMenuBar menuBar = new JMenuBar(); menuBar.add(fontMenu); setJMenuBar(menuBar); setTitle(cryptoFile.getFileName() + " - " + cryptoFile.getFullyPathedFileName() ); } CryptoFile getCryptoFile() { return cryptoFile; } public void internalFrameDeactivated(InternalFrameEvent e) { } public void internalFrameActivated (InternalFrameEvent e) { } public void internalFrameClosed(InternalFrameEvent e) { } public void internalFrameOpened(InternalFrameEvent e) { } public void internalFrameIconified(InternalFrameEvent e) { } public void internalFrameDeiconified(InternalFrameEvent e) { } public void internalFrameClosing(InternalFrameEvent e) { // System.out.println("Internal Frame Event - Closing the internal frame..."); // Get Selected Internal Frame if ( mGui.desktopPane.getSelectedFrame() instanceof MyInternalFrame ) { // All Internal Frames are this type MyInternalFrame mif = (MyInternalFrame) mGui.desktopPane.getSelectedFrame(); mGui.closeInternalFrame( mif ); } } // From the java Swing Tutorials - TextComponentDemo.java // // Create the font menu. protected JMenu createFontMenu() { JMenu menu = new JMenu("Text Format"); Action action = new StyledEditorKit.BoldAction(); action.putValue(Action.NAME, "Bold"); menu.add(action); action = new StyledEditorKit.ItalicAction(); action.putValue(Action.NAME, "Italic"); menu.add(action); action = new StyledEditorKit.UnderlineAction(); action.putValue(Action.NAME, "Underline"); menu.add(action); menu.addSeparator(); menu.add(new StyledEditorKit.FontSizeAction("10", 10)); menu.add(new StyledEditorKit.FontSizeAction("11", 11)); menu.add(new StyledEditorKit.FontSizeAction("12", 12)); menu.add(new StyledEditorKit.FontSizeAction("14", 14)); menu.add(new StyledEditorKit.FontSizeAction("16", 16)); menu.add(new StyledEditorKit.FontSizeAction("18", 18)); menu.add(new StyledEditorKit.FontSizeAction("20", 20)); menu.addSeparator(); menu.add(new StyledEditorKit.FontFamilyAction("Arial", "Arial")); menu.add(new StyledEditorKit.FontFamilyAction("Arial Narrow", "Arial Narrow")); menu.add(new StyledEditorKit.FontFamilyAction("Courier", "Courier")); menu.add(new StyledEditorKit.FontFamilyAction("Times New Roman", "Times New Roman")); menu.add(new StyledEditorKit.FontFamilyAction("Verdana", "Verdana")); menu.addSeparator(); menu.add(new StyledEditorKit.ForegroundAction("Red", Color.red)); menu.add(new StyledEditorKit.ForegroundAction("Green", Color.green)); menu.add(new StyledEditorKit.ForegroundAction("Blue", Color.blue)); menu.add(new StyledEditorKit.ForegroundAction("Black", Color.black)); return menu; } }