/*
*
* 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
*
* - Neither the name of Oracle 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 OWNER 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.
*/
/*
* This source code is provided to illustrate the usage of a given feature
* or technique and has been deliberately simplified. Additional steps
* required for a production-quality application, such as security checks,
* input validation and proper error handling, might not be present in
* this sample code.
*/
/**
* Sample application using the simple text editor component that
* supports only one font.
*
* @author Timothy Prinzing
*/
@SuppressWarnings("serial")
private static boolean exitAfterFirstPaint;
static {
try {
properties = new Properties();
Locale.getDefault());
} catch (MissingResourceException | IOException e) {
+ "or resources/NotepadSystem.properties not found");
}
}
super.paintChildren(g);
if (exitAfterFirstPaint) {
}
}
@SuppressWarnings("OverridableMethodCallInConstructor")
Notepad() {
super(true);
// Trying to set Nimbus look and feel
try {
break;
}
}
}
setLayout(new BorderLayout());
// create the embedded JTextComponent
editor = createEditor();
// Add this as a listener for undoable edits.
// install the command table
}
}
}
exitAfterFirstPaint = true;
}
public void run() {
frame.setVisible(true);
}
});
}
/**
* 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.
*/
JTextComponent c = new JTextArea();
c.setDragEnabled(true);
return c;
}
/**
* Fetch the editor contained in this panel
*/
return editor;
}
/**
* 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
* was needed.
*/
}
}
/**
* Find the hosting frame, for the file-chooser dialog.
*/
if (p instanceof Frame) {
return (Frame) p;
}
}
return null;
}
/**
* This is the hook through which all menu items are
* created.
*/
}
}
if (a != null) {
mi.addActionListener(a);
} else {
mi.setEnabled(false);
}
return mi;
}
}
}
try {
} catch (MissingResourceException mre) {
}
return str;
}
}
return null;
}
/**
* Create a status bar
*/
// need to do something reasonable here
return status;
}
/**
* Resets the undo manager.
*/
protected void resetUndoManager() {
undoAction.update();
redoAction.update();
}
/**
* Create the toolbar. By default this reads the
* resource file for the definition of the toolbar.
*/
} else {
}
}
return toolbar;
}
/**
* Hook through which every toolbar item is created.
*/
return createToolbarButton(key);
}
/**
* 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
* of lookups.
*/
public float getAlignmentY() {
return 0.5f;
}
};
b.setRequestFocusEnabled(false);
}
if (a != null) {
b.setActionCommand(astr);
b.addActionListener(a);
} else {
b.setEnabled(false);
}
b.setToolTipText(tip);
}
return b;
}
/**
* Create the menubar for the app. By default this pulls the
* definition of the menu from the associated resource file.
*/
if (m != null) {
}
}
return mb;
}
/**
* Create a menu for the app. By default this pulls the
* definition of the menu from the associated resource file.
*/
menu.addSeparator();
} else {
}
}
return menu;
}
/**
* Get keys for menus
*/
switch (key) {
case "file":
return FILE_KEYS;
case "edit":
return EDIT_KEYS;
case "debug":
return DEBUG_KEYS;
default:
return null;
}
}
return MENUBAR_KEYS;
}
return TOOLBAR_KEYS;
}
// Yarked from JMenu, ideally this would be public.
return new ActionChangedListener(b);
}
// Yarked from JMenu, ideally this would be public.
super();
}
}
}
}
/**
* Listener for the edits on the current document.
*/
/** UndoManager that we add edits to. */
/**
* Suffix applied to the key used in resource file
* lookups for an image.
*/
/**
* Suffix applied to the key used in resource file
* lookups for a label.
*/
/**
* Suffix applied to the key used in resource file
* lookups for an action.
*/
/**
* 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.
*/
undoAction.update();
redoAction.update();
}
}
/**
* FIXME - I'm not very useful yet
*/
public StatusBar() {
super();
}
super.paint(g);
}
}
// --- action implementations -----------------------------------
/**
* Actions defined by the Notepad class
*/
new NewAction(),
new OpenAction(),
new SaveAction(),
new ExitAction(),
new ShowElementTreeAction(),
};
public UndoAction() {
super("Undo");
setEnabled(false);
}
try {
} catch (CannotUndoException ex) {
"Unable to undo", ex);
}
update();
redoAction.update();
}
protected void update() {
setEnabled(true);
} else {
setEnabled(false);
}
}
}
public RedoAction() {
super("Redo");
setEnabled(false);
}
try {
} catch (CannotRedoException ex) {
"Unable to redo", ex);
}
update();
undoAction.update();
}
protected void update() {
setEnabled(true);
} else {
setEnabled(false);
}
}
}
OpenAction() {
super(openAction);
}
return;
}
}
if (elementTreePanel != null) {
}
} else {
"Could not open file: " + f,
"Error opening file",
}
}
}
SaveAction() {
super(saveAction);
}
return;
}
}
}
NewAction() {
super(newAction);
}
super(nm);
}
}
revalidate();
}
}
/**
* Really lame implementation of an exit command
*/
ExitAction() {
super(exitAction);
}
}
}
/**
* Action that brings up a JFrame with a JTree showing the structure
* of the document.
*/
super(showElementTreeAction);
}
if (elementTreeFrame == null) {
// Create a frame containing an instance of
// ElementTreePanel.
try {
} catch (MissingResourceException mre) {
elementTreeFrame = new JFrame();
}
elementTreeFrame.setVisible(false);
}
});
}
elementTreeFrame.setVisible(true);
}
}
/**
* Thread to load a file into the text storage model
*/
setPriority(4);
this.f = f;
}
public void run() {
try {
// initialize the statusbar
status.revalidate();
// try to start reading
char[] buff = new char[4096];
int nch;
null);
}
} catch (IOException e) {
public void run() {
"Could not open file: " + msg,
"Error opening file",
}
});
} catch (BadLocationException e) {
}
// we are done... get rid of progressbar
status.revalidate();
if (elementTreePanel != null) {
public void run() {
}
});
}
}
File f;
}
/**
* Thread to save a document to file
*/
File f;
setPriority(4);
this.f = f;
}
@SuppressWarnings("SleepWhileHoldingLock")
public void run() {
try {
// initialize the statusbar
status.revalidate();
// start writing
text.setPartialReturn(true);
int offset = 0;
while (charsLeft > 0) {
try {
} catch (InterruptedException e) {
null, e);
}
}
} catch (IOException e) {
public void run() {
"Could not save file: " + msg,
"Error saving file",
}
});
} catch (BadLocationException e) {
}
// we are done... get rid of progressbar
status.revalidate();
}
}
}