RichEdit control classes. This package creates AWT menu items,

and contains an AWT TabRuler and text frame.

X-SVN-Rev: 1182
This commit is contained in:
Alan Liu 2000-04-20 17:41:49 +00:00
parent 5cfa36a1fe
commit 460bec23d3
9 changed files with 1102 additions and 0 deletions

View file

@ -0,0 +1,238 @@
/*
* @(#)$RCSfile: AwtMenuBuilder.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:41:49 $
*
* (C) Copyright IBM Corp. 1998-1999. All Rights Reserved.
*
* The program is provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* IBM will not be liable for any damages suffered by you as a result
* of using the Program. In no event will IBM be liable for any
* special, indirect or consequential damages or lost profits even if
* IBM has been advised of the possibility of their occurrence. IBM
* will not be liable for any third party claims against you.
*/
package com.ibm.richtext.awtui;
import java.awt.Frame;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.Window;
import com.ibm.richtext.textpanel.MTextPanel;
import com.ibm.richtext.uiimpl.resources.FrameResources;
import com.ibm.richtext.uiimpl.*;
import com.ibm.richtext.uiimpl.DialogItem.DialogFactory;
// TO DO: Don't hard-code menu configurations. Instead, specify them with
// strings somehow. This is an improvement over what we had, and it'll do
// for now.
/**
* AwtMenuBuilder creates a set of AWT menus for interacting
* with an MTextPanel. Future versions of this class may allow
* clients to control the menu contents.
* @see MTextPanel
*/
public final class AwtMenuBuilder extends MenuBuilder {
static final String COPYRIGHT =
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
private static final AwtMenuBuilder INSTANCE = new AwtMenuBuilder();
/**
* Id for an Edit menu. The Edit menu has the following items:
* <ul>
* <li><b>Undo</b> - invoke undo() on the MTextPanel</li>
* <li><b>Redo</b> - invoke redo() on the MTextPanel</li>
* <li><b>Cut</b> - invoke cut() on the MTextPanel</li>
* <li><b>Copy</b> - invoke copy() on the MTextPanel</li>
* <li><b>Paste</b> - invoke paste() on the MTextPanel</li>
* <li><b>Clear</b> - invoke clear() on the MTextPanel</li>
* <li><b>Select All</b> - invoke selectAll() on the MTextPanel</li>
* </ul>
*/
public static final int EDIT = MenuBuilder.EDIT;
/**
* Id for the point sizes menu. The menu has items that set the size of a character
* in a typeface.
*/
public static final int SIZE = MenuBuilder.SIZE;
/**
* Id for a Style menu. The Style menu has the following items:
* <ul>
* <li><b>Plain</b> - remove <code>WEIGHT</code>,
* <code>POSTURE</code>,
* <code>UNDERLINE</code> and
* <code>STRIKETHROUGH</code> attributes from the
* current selection</li>
* <li><b>Bold</b> - add <code>{WEIGHT,WEIGHT_BOLD}</code> to
* the current selection</li>
* <li><b>Italic</b> - add <code>{POSTURE,POSTURE_ITALIC}</code> to
* the current selection</li>
* <li><b>Underline</b> - add <code>{UNDERLINE,UNDERLINE_ON}</code> to
* the current selection</li>
* <li><b>Strikethrough</b> - add <code>{STRIKETHROUGH,STRIKETHROUGH_ON}</code>
* to the current selection</li>
* <li><b>Font...</b> - display a dialog allowing the user to
* select a typeface (font family) for the current selection</li>
* <li><b>Forecolor...</b> - display a dialog allowing the user to
* select a foreground color for the current selection</li>
* <li><b>Backcolor...</b> - display a dialog allowing the user to
* select a background color for the current selection</li>
* </ul>
*/
public static final int STYLE = MenuBuilder.STYLE;
/**
* Id for a paragraph alignment menu. The menu has the following items:
* <ul>
* <li><b>Leading</b> - give selected paragraph(s) LEADING flush</li>
* <li><b>Center</b> - give selected paragraph(s) CENTER flush</li>
* <li><b>Trailing</b> - give selected paragraph(s) TRAILING flush</li>
* <li><b>Justified</b> - give selected paragraph(s) full justification</li>
* </ul>
*/
public static final int FLUSH = MenuBuilder.FLUSH;
/**
* Id for a menu that sets the KeyRemap
* on an MTextPanel. The menu has the following items:
* <ul>
* <li><b>Default</b> - set KeyRemap to identity remap</li>
* <li><b>Arabic</b> - set KeyRemap to Arabic transliteration</li>
* <li><b>Hebrew</b> - set KeyRemap to Hebrew transliteration</li>
* <li><b>Israel Nikud</b> - set KeyRemap to Israel Nikud</li>
* <li><b>Thai Ketmanee</b> - set KeyRemap to Thai Ketmanee</li>
* </ul>
*/
public static final int KEYMAP = MenuBuilder.KEYMAP;
/**
* Id for a menu that sets
* the primary run direction for a paragraph. Run direction can be left-to-right,
* right-to-left, or can use the default run direction from the Unicode bidi algorithm.
*/
public static final int BIDI = MenuBuilder.BIDI;
/**
* Id for a menu with an <b>About</b> item. When selected,
* the item displays a Frame containing some
* self-promotional text.
*/
public static final int ABOUT = MenuBuilder.ABOUT;
/**
* Return an instance of AwtMenuBuilder.
*/
public static AwtMenuBuilder getInstance() {
return INSTANCE;
}
private MenuBar fMenuBar;
private AwtMenuBuilder() {
}
/**
* Add a standard set of menus to the given menu bar. The menus
* will interact with the given MTextPanel.
* @param menuBar the MenuBar to which menus are added
* @param textPanel the MTextPanel with which the menus interact
* @param frame a Frame to use as the parent of any dialogs created by a
* a menu item. If null, menu items which create dialogs will be omitted.
*/
public void createMenus(MenuBar menuBar,
MTextPanel textPanel,
Frame frame) {
createMenus(menuBar, textPanel, frame, defaultMenus);
}
/**
* Add a set of menus to the given menu bar. The menus
* will interact with the given MTextPanel.
* @param menuBar the MenuBar to which menus are added
* @param textPanel the MTextPanel with which the menus interact
* @param frame a Frame to use as the parent of any dialogs created by a
* a menu item. If null, menu items which create dialogs will be omitted.
* @param menus an array of integer menu id's. Each element of the
* array must be one of this class's menu id constants. If null,
* the default menus are created.
*/
public void createMenus(MenuBar menuBar,
MTextPanel textPanel,
Frame frame,
int[] menus) {
if (menus == null) {
menus = defaultMenus;
}
synchronized (MItem.LOCK) {
fMenuBar = menuBar;
doCreateMenus(textPanel, frame, menus);
fMenuBar = null;
}
}
protected void handleAddMenu(String key) {
Menu menu = new Menu(ResourceUtils.getResourceString(key));
fMenuBar.add(menu);
MItem.setItemFactory(new AwtMenuFactory(menu));
}
protected DialogFactory createObjectDialogFactory(final String dialogTitle,
final String dialogMessage,
final Object key,
final boolean character,
final String[] names,
final Object[] values) {
final Frame dialogParent = fDialogParent;
return new DialogFactory() {
public Window createDialog(MTextPanel textPanel) {
return new ObjectDialog(dialogParent,
dialogTitle,
dialogMessage,
textPanel,
key,
character,
names,
values);
}
};
}
protected DialogFactory createNumberDialogFactory(final String dialogTitle,
final String dialogMessage,
final Object key,
final boolean character) {
final Frame dialogParent = fDialogParent;
return new DialogFactory() {
public Window createDialog(MTextPanel textPanel) {
return new NumberDialog(dialogParent,
dialogTitle,
dialogMessage,
textPanel,
key,
character,
1);
}
};
}
protected DialogFactory createAboutDialogFactory() {
return new DialogFactory() {
public Window createDialog(MTextPanel textPanel) {
String title = ResourceUtils.getResourceString(FrameResources.ABOUT_TITLE);
return new MessageDialog(title, AboutText.getAboutText());
}
};
}
}

View file

@ -0,0 +1,116 @@
/*
* @(#)$RCSfile: AwtMenuFactory.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:41:49 $
*
* (C) Copyright IBM Corp. 1998-1999. All Rights Reserved.
*
* The program is provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* IBM will not be liable for any damages suffered by you as a result
* of using the Program. In no event will IBM be liable for any
* special, indirect or consequential damages or lost profits even if
* IBM has been advised of the possibility of their occurrence. IBM
* will not be liable for any third party claims against you.
*/
package com.ibm.richtext.awtui;
import java.awt.CheckboxMenuItem;
import java.awt.Menu;
import java.awt.MenuItem;
import java.awt.MenuShortcut;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import com.ibm.richtext.uiimpl.resources.MenuData;
import com.ibm.richtext.uiimpl.MItem;
import com.ibm.richtext.uiimpl.MItem.ItemFactory;
final class AwtMenuFactory implements ItemFactory {
static final String COPYRIGHT =
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
private final class AwtMItem extends MItem {
private MenuItem fItem;
AwtMItem(MenuItem item) {
fItem = item;
try {
CheckboxMenuItem chItem = (CheckboxMenuItem) fItem;
chItem.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
handleSelected();
}
});
}
catch(ClassCastException e) {
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
handleSelected();
}
});
}
}
// Ack - how do you do this from inner classes??
protected void handleSelected() {
super.handleSelected();
}
public final void setEnabled(boolean enabled) {
fItem.setEnabled(enabled);
}
public void setState(boolean checked) {
try {
CheckboxMenuItem item = (CheckboxMenuItem) fItem;
item.setState(checked);
}
catch(ClassCastException e) {
throw new Error("Cannot perform setChecked on non-checkbox item");
}
}
}
private Menu fMenu;
AwtMenuFactory(Menu menu) {
fMenu = menu;
}
private MItem handleCreate(MenuItem item,
MenuData menuData) {
if (menuData.hasShortcut()) {
item.setShortcut(new MenuShortcut(menuData.getShortcutChar()));
}
fMenu.add(item);
return new AwtMItem(item);
}
public MItem createItem(MenuData menuData) {
return handleCreate(new MenuItem(menuData.getName()), menuData);
}
public MItem createCheckboxItem(MenuData menuData) {
return handleCreate(new CheckboxMenuItem(menuData.getName()), menuData);
}
public void createSeparator() {
fMenu.add(new MenuItem("-"));
}
}

View file

@ -0,0 +1,92 @@
/*
* @(#)$RCSfile: MTabRulerComponent.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:41:49 $
*
* (C) Copyright IBM Corp. 1998-1999. All Rights Reserved.
*
* The program is provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* IBM will not be liable for any damages suffered by you as a result
* of using the Program. In no event will IBM be liable for any
* special, indirect or consequential damages or lost profits even if
* IBM has been advised of the possibility of their occurrence. IBM
* will not be liable for any third party claims against you.
*/
package com.ibm.richtext.awtui;
import java.awt.Color;
import com.ibm.richtext.styledtext.MTabRuler;
import com.ibm.richtext.textpanel.MTextPanel;
/**
* MTabRulerComponent is implemented by components which provide a tab-ruler
* interface for interacting with an MTextPanel.
* <p>
* Users interact with MTabRulerComponent implementations as follows:
* <ul>
* <li>The leading margin can be set by dragging the bottom half
* of the leftmost triangle. The first-line indent will "stick" with
* the leading margin.</li>
* <li>The first-line indent can be set by dragging the top half of the
* leftmost triangle. The first-line indent applies to the first line of
* a paragraph.</li>
* <li>The trailing margin can be set by dragging the rightmost triangle.</li>
* <li>Tabs can be added to the ruler by clicking the mouse on the ruler with the
* control key pressed. Four kinds of tabs are provided: leading, trailing, center,
* and decimal. The type of a tab can be changed by double-clicking the tab.</li>
* <li>Tabs can be repositioned by dragging them with the mouse.</li>
* </ul>
* <p>
* MTabRulerComponent's appearance will reflect the paragraph styles in the
* first selected paragraph. Style changes performed with an
* MTabRulerComponent will apply to all selected paragraphs.
*/
public interface MTabRulerComponent {
static final String COPYRIGHT =
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
/**
* Listen to the given MTextPanel and reflect its changes,
* and update its paragraph styles when TabRuler is
* manipulated.
* @param textPanel the MTextPanel to listen to
*/
public void listenToTextPanel(MTextPanel textPanel);
/**
* Return the background color of this TabRuler.
* @return the background color of this TabRuler
*/
public Color getBackColor();
/**
* Set the background color of this TabRuler.
* @param backColor the new background color of this TabRuler
*/
public void setBackColor(Color backColor);
/**
* Return the MTabRuler represented by this TabRuler.
* @return the MTabRuler represented by this TabRuler
*/
public MTabRuler getRuler();
/**
* Return the leading margin of this TabRuler.
* @return the leading margin of this TabRuler
*/
public int getLeadingMargin();
/**
* Return the first line indent of this TabRuler.
* @return the first line indent of this TabRuler
*/
public int getFirstLineIndent();
/**
* Return the trailing margin of this TabRuler.
* @return the trailing margin of this TabRuler
*/
public int getTrailingMargin();
}

View file

@ -0,0 +1,67 @@
/*
* @(#)$RCSfile: MessageDialog.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:41:49 $
*
* (C) Copyright IBM Corp. 1998-1999. All Rights Reserved.
*
* The program is provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* IBM will not be liable for any damages suffered by you as a result
* of using the Program. In no event will IBM be liable for any
* special, indirect or consequential damages or lost profits even if
* IBM has been advised of the possibility of their occurrence. IBM
* will not be liable for any third party claims against you.
*/
package com.ibm.richtext.awtui;
import java.awt.Color;
import java.awt.Frame;
import java.awt.CardLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import com.ibm.richtext.styledtext.MConstText;
import com.ibm.richtext.textpanel.TextPanel;
import com.ibm.richtext.textpanel.TextPanelSettings;
/**
* MessageDialog is a simple Frame which displays a styled
* text message in a TextPanel.
* The text in the message is not selectable or editable.
* @see MConstText
* @see TextPanel
*/
public final class MessageDialog extends Frame {
static final String COPYRIGHT =
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
/**
* Create a new MessageDialog.
* @param title the dialog's title
* @param message the text which will appear in the dialog
*/
public MessageDialog(String title, MConstText message)
{
super(title);
setLayout(new CardLayout());
TextPanelSettings settings = TextPanel.getDefaultSettings();
settings.setScrollable(false);
settings.setSelectable(false);
TextPanel panel = new TextPanel(settings, message, null);
panel.setBackground(Color.black);
add("Center", panel);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
setVisible(false);
dispose();
}
});
setSize(450,320);
}
}

View file

@ -0,0 +1,155 @@
/*
* @(#)$RCSfile: NumberDialog.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:41:49 $
*
* (C) Copyright IBM Corp. 1998-1999. All Rights Reserved.
*
* The program is provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* IBM will not be liable for any damages suffered by you as a result
* of using the Program. In no event will IBM be liable for any
* special, indirect or consequential damages or lost profits even if
* IBM has been advised of the possibility of their occurrence. IBM
* will not be liable for any third party claims against you.
*/
package com.ibm.richtext.awtui;
import java.awt.FlowLayout;
import java.awt.Dialog;
import java.awt.TextField;
import java.awt.Button;
import java.awt.Frame;
import java.awt.Panel;
import java.awt.Label;
import java.text.NumberFormat;
import java.text.ParseException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;
import com.ibm.richtext.uiimpl.resources.FrameResources;
import com.ibm.richtext.uiimpl.MenuItemSet;
import com.ibm.richtext.uiimpl.ResourceUtils;
import com.ibm.richtext.styledtext.StyleModifier;
import com.ibm.richtext.textpanel.MTextPanel;
/**
* Simple dialog which gets a number, and sends an appropriate command
*/
final class NumberDialog extends Dialog implements ActionListener
{
static final String COPYRIGHT =
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
private MTextPanel fTextPanel;
private TextField fInput = null;
private Button fOKButton = null;
private Button fCancelButton = null;
private boolean fCharacter;
private Object fKey;
private float fMultiplier;
/**
* @param multiplier the factor by which to multiply the user's
* selection before creating the attribute value. This
* is useful for subscripting.
*/
NumberDialog(Frame parent,
String title,
String message,
MTextPanel textPanel,
Object key,
boolean character,
float multiplier) {
super(parent, title, false);
fTextPanel = textPanel;
fKey = key;
fCharacter = character;
fMultiplier = multiplier;
setLayout(new java.awt.GridLayout(2,1));
Panel panel = new Panel();
panel.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 15));
fInput = new TextField(5);
panel.add(new Label(message));
panel.add(fInput);
add("Center", panel);
fCancelButton = new Button(ResourceUtils.getResourceString(FrameResources.CANCEL));
fOKButton = new Button(ResourceUtils.getResourceString(FrameResources.OK));
Panel p = new Panel();
p.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
p.add(fCancelButton);
p.add(fOKButton);
add("South", p);
pack();
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
closeWindow(false);
}
});
fOKButton.addActionListener(this);
fCancelButton.addActionListener(this);
}
private void closeWindow(boolean sendAction) {
setVisible(false);
int num = 0;
if (sendAction) {
try {
String text = fInput.getText();
num = NumberFormat.getInstance().parse(text).intValue();
}
catch (ParseException exception) {
sendAction = false;
}
}
if (sendAction) {
sendAction(num);
}
dispose();
}
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source == fOKButton) {
closeWindow(true);
}
else if (source == fCancelButton) {
closeWindow(false);
}
else {
throw new IllegalArgumentException("Invalid ActionEvent!");
}
}
/**
* Handle the user input
* @param the number the user typed in
*/
private void sendAction(int number) {
float num = number * fMultiplier;
StyleModifier modifier = StyleModifier.createAddModifier(
fKey,
new Float(num));
if (fCharacter == MenuItemSet.CHARACTER) {
fTextPanel.modifyCharacterStyleOnSelection(modifier);
}
else {
fTextPanel.modifyParagraphStyleOnSelection(modifier);
}
}
}

View file

@ -0,0 +1,170 @@
/*
* @(#)$RCSfile: ObjectDialog.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:41:49 $
*
* (C) Copyright IBM Corp. 1998-1999. All Rights Reserved.
*
* The program is provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* IBM will not be liable for any damages suffered by you as a result
* of using the Program. In no event will IBM be liable for any
* special, indirect or consequential damages or lost profits even if
* IBM has been advised of the possibility of their occurrence. IBM
* will not be liable for any third party claims against you.
*/
package com.ibm.richtext.awtui;
import java.util.Hashtable;
import com.ibm.textlayout.attributes.AttributeMap;
import com.ibm.textlayout.attributes.AttributeSet;
import com.ibm.richtext.styledtext.StyleModifier;
import com.ibm.richtext.textpanel.MTextPanel;
import com.ibm.richtext.uiimpl.MenuItemSet;
import com.ibm.richtext.uiimpl.resources.FrameResources;
import com.ibm.richtext.uiimpl.ResourceUtils;
import java.awt.Dialog;
import java.awt.Frame;
import java.awt.Button;
import java.awt.Choice;
import java.awt.Label;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Panel;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;
/**
* Simple dialog which gets a color
*/
final class ObjectDialog extends Dialog implements ActionListener
{
static final String COPYRIGHT =
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
private final MTextPanel fTextPanel;
private final Object fKey;
private boolean fCharacter;
private final Button fOKButton;
private final Button fCancelButton;
private final Choice fItems;
private final Hashtable fNameToValueMap;
/**
* Construct a new ColorDialog.
* @param parent the dialog's parent frame
* @param title the dialogs title
* @param message the message displayed next to the input box
*/
ObjectDialog(Frame parent,
String title,
String message,
MTextPanel textPanel,
Object key,
boolean character,
String[] names,
Object[] values) {
super(parent, title, false);
fTextPanel = textPanel;
fKey = key;
fCharacter = character;
setLayout(new GridLayout(2, 1));
Panel panel = new Panel();
panel.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
fItems = new Choice();
if (names.length != values.length) {
throw new IllegalArgumentException("Must have same number of names and values.");
}
fNameToValueMap = new Hashtable(names.length);
for (int i=0; i < names.length; i++) {
fItems.add(names[i]);
if (values[i] != null) {
fNameToValueMap.put(names[i], values[i]);
}
}
panel.add(new Label(message));
panel.add(fItems);
add("North", panel);
fCancelButton = new Button(ResourceUtils.getResourceString(FrameResources.CANCEL));
fOKButton = new Button(ResourceUtils.getResourceString(FrameResources.OK));
Panel p = new Panel();
p.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
p.add(fCancelButton);
p.add(fOKButton);
add("South", p);
pack();
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
closeWindow(false);
}
});
fOKButton.addActionListener(this);
fCancelButton.addActionListener(this);
}
private void closeWindow(boolean sendAction) {
setVisible(false);
if (sendAction) {
Object value = fNameToValueMap.get(fItems.getSelectedItem());
sendAction(value);
}
dispose();
}
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source == fOKButton) {
closeWindow(true);
}
else if (source == fCancelButton) {
closeWindow(false);
}
else {
throw new IllegalArgumentException("Invalid ActionEvent!");
}
}
/**
* Handle the user input
* @param obj the value object
*/
private void sendAction(Object value) {
StyleModifier modifier;
if (value != null) {
modifier = StyleModifier.createAddModifier(fKey, value);
}
else {
AttributeSet set = new AttributeSet(fKey);
modifier = StyleModifier.createRemoveModifier(set);
}
if (fCharacter == MenuItemSet.CHARACTER) {
fTextPanel.modifyCharacterStyleOnSelection(modifier);
}
else {
fTextPanel.modifyParagraphStyleOnSelection(modifier);
}
}
}

View file

@ -0,0 +1,131 @@
/*
* @(#)$RCSfile: TabRuler.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:41:49 $
*
* (C) Copyright IBM Corp. 1998-1999. All Rights Reserved.
*
* The program is provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* IBM will not be liable for any damages suffered by you as a result
* of using the Program. In no event will IBM be liable for any
* special, indirect or consequential damages or lost profits even if
* IBM has been advised of the possibility of their occurrence. IBM
* will not be liable for any third party claims against you.
*/
package com.ibm.richtext.awtui;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import com.ibm.richtext.textpanel.MTextPanel;
import com.ibm.richtext.uiimpl.TabRulerImpl;
import com.ibm.richtext.styledtext.MTabRuler;
/**
* TabRuler is an implementation of MTabRulerComponent in an AWT component.
*/
public final class TabRuler extends Component implements MTabRulerComponent {
static final String COPYRIGHT =
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
private TabRulerImpl fImpl;
/**
* Create a new TabRuler.
* @param baseline the y-coordinate of the ruler's baseline
* @param origin the x-coordinate in this Component where
* the left margin appears
* @param textPanel the MTextPanel to listen to. This TabRuler
* will reflect the MTextPanel's paragraph styles, and update
* the paragraph styles when manipulated.
*/
public TabRuler(int baseline, int origin, MTextPanel textPanel) {
fImpl = new TabRulerImpl(baseline, origin, textPanel, this);
}
/**
* Listen to the given MTextPanel and reflect its changes,
* and update its paragraph styles when TabRuler is
* manipulated.
* @param textPanel the MTextPanel to listen to
*/
public void listenToTextPanel(MTextPanel textPanel) {
fImpl.listenToTextPanel(textPanel);
}
/**
* Return the background color of this TabRuler.
* @return the background color of this TabRuler
*/
public Color getBackColor() {
return fImpl.getBackColor();
}
/**
* Set the background color of this TabRuler.
* @param backColor the new background color of this TabRuler
*/
public void setBackColor(Color backColor) {
fImpl.setBackColor(backColor);
}
/**
* Return the MTabRuler represented by this TabRuler.
* @return the MTabRuler represented by this TabRuler
*/
public MTabRuler getRuler() {
return fImpl.getRuler();
}
/**
* Return the leading margin of this TabRuler.
* @return the leading margin of this TabRuler
*/
public int getLeadingMargin() {
return fImpl.getLeadingMargin();
}
/**
* Return the first line indent of this TabRuler.
* @return the first line indent of this TabRuler
*/
public int getFirstLineIndent() {
return fImpl.getFirstLineIndent();
}
/**
* Return the trailing margin of this TabRuler.
* @return the trailing margin of this TabRuler
*/
public final int getTrailingMargin() {
return fImpl.getTrailingMargin();
}
// The following are Component methods which need to be delegated to
// the implementation:
public void paint(Graphics g) {
fImpl.paint(g);
}
public Dimension getPreferredSize() {
return fImpl.getPreferredSize();
}
public Dimension getMinimumSize() {
return fImpl.getMinimumSize();
}
}

View file

@ -0,0 +1,128 @@
/*
* @(#)$RCSfile: TextFrame.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:41:49 $
*
* (C) Copyright IBM Corp. 1998-1999. All Rights Reserved.
*
* The program is provided "as is" without any warranty express or
* implied, including the warranty of non-infringement and the implied
* warranties of merchantibility and fitness for a particular purpose.
* IBM will not be liable for any damages suffered by you as a result
* of using the Program. In no event will IBM be liable for any
* special, indirect or consequential damages or lost profits even if
* IBM has been advised of the possibility of their occurrence. IBM
* will not be liable for any third party claims against you.
*/
package com.ibm.richtext.awtui;
import com.ibm.richtext.textpanel.MTextPanel;
import com.ibm.richtext.textpanel.TextPanel;
import com.ibm.richtext.styledtext.MConstText;
import com.ibm.richtext.styledtext.StyleModifier;
import com.ibm.richtext.uiimpl.ResourceUtils;
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
/**
* TextFrame is a Frame containing an editable TextPanel, a set of standard
* menus, and a TabRuler. This class can be used as-is, but is
* primarily intended to be a simple example of how to use the other classes
* in this package.
* @see com.ibm.richtext.textpanel.TextPanel
* @see AwtMenuBuilder
* @see TabRuler
*/
public final class TextFrame extends Frame {
static final String COPYRIGHT =
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
private TextPanel fTextPanel;
/**
* Create a new TextFrame with no text and no title.
*/
public TextFrame() {
super();
init(null, Toolkit.getDefaultToolkit().getSystemClipboard());
}
/**
* Create a new TextFrame with no text and the given title.
* @param title the title of this Frame
*/
public TextFrame(String title) {
super(title);
init(null, Toolkit.getDefaultToolkit().getSystemClipboard());
}
/**
* Create a new TextFrame with the given text and title, whose
* TextPanel will use the given clipboard.
* @param text the initial text in the TextPanel. If null the
* TextPanel will initially be empty
* @param title the title of this Frame
* @param clipboard the Clipboard which the TextPanel will use.
* If null the TextPanel will use a private Clipboard
*/
public TextFrame(MConstText text,
String title,
Clipboard clipboard) {
super(title);
init(text, clipboard);
}
private void init(MConstText text, Clipboard clipboard) {
fTextPanel = new TextPanel(text, clipboard);
TabRuler tabRuler = new TabRuler(14, 10, fTextPanel);
createMenus();
setLayout(new BorderLayout());
add(fTextPanel, "Center");
add(tabRuler, "North");
pack();
}
private void createMenus() {
MenuBar menuBar = new MenuBar();
AwtMenuBuilder.getInstance().createMenus(menuBar, fTextPanel, this);
setMenuBar(menuBar);
}
/**
* Return the MTextPanel in this frame.
*/
public MTextPanel getTextPanel() {
return fTextPanel;
}
public static void main(String[] args) {
TextFrame frame = new TextFrame();
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.setSize(550, 700);
frame.show();
}
}

View file

@ -0,0 +1,5 @@
<html>
<body bgcolor="white">
Provides classes for building an AWT-based user interface for a TextPanel.
</body>
</html>