From 460bec23d304e476e4912e8fdf550d9bc92b48c8 Mon Sep 17 00:00:00 2001 From: Alan Liu Date: Thu, 20 Apr 2000 17:41:49 +0000 Subject: [PATCH] RichEdit control classes. This package creates AWT menu items, and contains an AWT TabRuler and text frame. X-SVN-Rev: 1182 --- .../ibm/richtext/awtui/AwtMenuBuilder.java | 238 ++++++++++++++++++ .../ibm/richtext/awtui/AwtMenuFactory.java | 116 +++++++++ .../richtext/awtui/MTabRulerComponent.java | 92 +++++++ .../com/ibm/richtext/awtui/MessageDialog.java | 67 +++++ .../com/ibm/richtext/awtui/NumberDialog.java | 155 ++++++++++++ .../com/ibm/richtext/awtui/ObjectDialog.java | 170 +++++++++++++ .../src/com/ibm/richtext/awtui/TabRuler.java | 131 ++++++++++ .../src/com/ibm/richtext/awtui/TextFrame.java | 128 ++++++++++ icu4j/src/com/ibm/richtext/awtui/package.html | 5 + 9 files changed, 1102 insertions(+) create mode 100755 icu4j/src/com/ibm/richtext/awtui/AwtMenuBuilder.java create mode 100755 icu4j/src/com/ibm/richtext/awtui/AwtMenuFactory.java create mode 100755 icu4j/src/com/ibm/richtext/awtui/MTabRulerComponent.java create mode 100755 icu4j/src/com/ibm/richtext/awtui/MessageDialog.java create mode 100755 icu4j/src/com/ibm/richtext/awtui/NumberDialog.java create mode 100755 icu4j/src/com/ibm/richtext/awtui/ObjectDialog.java create mode 100755 icu4j/src/com/ibm/richtext/awtui/TabRuler.java create mode 100755 icu4j/src/com/ibm/richtext/awtui/TextFrame.java create mode 100755 icu4j/src/com/ibm/richtext/awtui/package.html diff --git a/icu4j/src/com/ibm/richtext/awtui/AwtMenuBuilder.java b/icu4j/src/com/ibm/richtext/awtui/AwtMenuBuilder.java new file mode 100755 index 00000000000..ede917b1da9 --- /dev/null +++ b/icu4j/src/com/ibm/richtext/awtui/AwtMenuBuilder.java @@ -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: + * + */ + 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: + * + */ + public static final int STYLE = MenuBuilder.STYLE; + /** + * Id for a paragraph alignment menu. The menu has the following items: + * + */ + public static final int FLUSH = MenuBuilder.FLUSH; + /** + * Id for a menu that sets the KeyRemap + * on an MTextPanel. The menu has the following items: + * + */ + 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 About 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()); + } + }; + } +} \ No newline at end of file diff --git a/icu4j/src/com/ibm/richtext/awtui/AwtMenuFactory.java b/icu4j/src/com/ibm/richtext/awtui/AwtMenuFactory.java new file mode 100755 index 00000000000..0ad6d9d8023 --- /dev/null +++ b/icu4j/src/com/ibm/richtext/awtui/AwtMenuFactory.java @@ -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("-")); + } +} + diff --git a/icu4j/src/com/ibm/richtext/awtui/MTabRulerComponent.java b/icu4j/src/com/ibm/richtext/awtui/MTabRulerComponent.java new file mode 100755 index 00000000000..d6b47bc74af --- /dev/null +++ b/icu4j/src/com/ibm/richtext/awtui/MTabRulerComponent.java @@ -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. + *

+ * Users interact with MTabRulerComponent implementations as follows: + *

+ *

+ * 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(); +} diff --git a/icu4j/src/com/ibm/richtext/awtui/MessageDialog.java b/icu4j/src/com/ibm/richtext/awtui/MessageDialog.java new file mode 100755 index 00000000000..47c938de46b --- /dev/null +++ b/icu4j/src/com/ibm/richtext/awtui/MessageDialog.java @@ -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); + } +} diff --git a/icu4j/src/com/ibm/richtext/awtui/NumberDialog.java b/icu4j/src/com/ibm/richtext/awtui/NumberDialog.java new file mode 100755 index 00000000000..f3c976ff842 --- /dev/null +++ b/icu4j/src/com/ibm/richtext/awtui/NumberDialog.java @@ -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); + } + } +} diff --git a/icu4j/src/com/ibm/richtext/awtui/ObjectDialog.java b/icu4j/src/com/ibm/richtext/awtui/ObjectDialog.java new file mode 100755 index 00000000000..e3c6a9576fe --- /dev/null +++ b/icu4j/src/com/ibm/richtext/awtui/ObjectDialog.java @@ -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); + } + } +} diff --git a/icu4j/src/com/ibm/richtext/awtui/TabRuler.java b/icu4j/src/com/ibm/richtext/awtui/TabRuler.java new file mode 100755 index 00000000000..44825d5b384 --- /dev/null +++ b/icu4j/src/com/ibm/richtext/awtui/TabRuler.java @@ -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(); + } +} diff --git a/icu4j/src/com/ibm/richtext/awtui/TextFrame.java b/icu4j/src/com/ibm/richtext/awtui/TextFrame.java new file mode 100755 index 00000000000..2396fd8bf08 --- /dev/null +++ b/icu4j/src/com/ibm/richtext/awtui/TextFrame.java @@ -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(); + } +} \ No newline at end of file diff --git a/icu4j/src/com/ibm/richtext/awtui/package.html b/icu4j/src/com/ibm/richtext/awtui/package.html new file mode 100755 index 00000000000..57fcc41161a --- /dev/null +++ b/icu4j/src/com/ibm/richtext/awtui/package.html @@ -0,0 +1,5 @@ + + +Provides classes for building an AWT-based user interface for a TextPanel. + +