3261N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 0N/A * Redistribution and use in source and binary forms, with or without 0N/A * modification, are permitted provided that the following conditions 0N/A * - Redistributions of source code must retain the above copyright 0N/A * notice, this list of conditions and the following disclaimer. 0N/A * - Redistributions in binary form must reproduce the above copyright 0N/A * notice, this list of conditions and the following disclaimer in the 0N/A * documentation and/or other materials provided with the distribution. 0N/A * - Neither the name of Oracle nor the names of its 0N/A * contributors may be used to endorse or promote products derived 0N/A * from this software without specific prior written permission. 2362N/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 2362N/A * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 2362N/A * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 0N/A * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 0N/A * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 0N/A * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 0N/A * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 0N/A * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 0N/A * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 0N/A * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 0N/A * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0N/A * This source code is provided to illustrate the usage of a given feature 0N/A * or technique and has been deliberately simplified. Additional steps 0N/A * required for a production-quality application, such as security checks, 0N/A * input validation and proper error handling, might not be present in * Sample application using the simple text editor component that * supports only one font. * @author Timothy Prinzing private static final String[]
TOOLBAR_KEYS = {
"new",
"open",
"save",
"-",
"cut",
"copy",
"paste"};
private static final String[]
FILE_KEYS = {
"new",
"open",
"save",
"-",
"exit"};
private static final String[]
EDIT_KEYS = {
"cut",
"copy",
"paste",
"-",
"undo",
"redo"};
// Trying to set Nimbus look and feel // create the embedded JTextComponent // Add this as a listener for undoable edits. // install the command table * Fetch the list of actions supported by this * editor. It is implemented to return the list * of actions supported by the embedded JTextComponent * augmented with the actions defined locally. * Create an editor to represent the given document. * Fetch the editor contained in this panel * To shutdown when run as an application. This is a * fairly lame implementation. A more self-respecting * implementation would at least check to see if a save * Find the hosting frame, for the file-chooser dialog. if (p
instanceof Frame) {
* This is the hook through which all menu items are // need to do something reasonable here * Resets the undo manager. * Create the toolbar. By default this reads the * resource file for the definition of the toolbar. * Hook through which every toolbar item is created. * Create a button to go inside of the toolbar. By default this * will load an image resource. The image filename is relative to * the classpath (including the '.' directory if its a part of the * classpath), and may either be in a JAR file or a separate file. * @param key The key in the resource file to serve as the basis * Create the menubar for the app. By default this pulls the * definition of the menu from the associated resource file. * Create a menu for the app. By default this pulls the * definition of the menu from the associated resource file. // Yarked from JMenu, ideally this would be public. // Yarked from JMenu, ideally this would be public. * Listener for the edits on the current document. /** UndoManager that we add edits to. */ * Suffix applied to the key used in resource file * Suffix applied to the key used in resource file * Suffix applied to the key used in resource file * Suffix applied to the key used in resource file * lookups for tooltip text. * Messaged when the Document has created an edit, the edit is * added to <code>undo</code>, an instance of UndoManager. * FIXME - I'm not very useful yet // --- action implementations ----------------------------------- * Actions defined by the Notepad class "Could not open file: " + f,
* Really lame implementation of an exit command * Action that brings up a JFrame with a JTree showing the structure // Create a frame containing an instance of * Thread to load a file into the text storage model // initialize the statusbar char[]
buff =
new char[
4096];
"Could not open file: " +
msg,
// we are done... get rid of progressbar * Thread to save a document to file // initialize the statusbar "Could not save file: " +
msg,
// we are done... get rid of progressbar