RichEdit control. UI implementation shared between AWT and Swing.
X-SVN-Rev: 1192
This commit is contained in:
parent
e9f426a35d
commit
c4a2d01698
65
icu4j/src/com/ibm/richtext/uiimpl/AboutText.java
Executable file
65
icu4j/src/com/ibm/richtext/uiimpl/AboutText.java
Executable file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* @(#)$RCSfile: AboutText.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:52:32 $
|
||||
*
|
||||
* (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.uiimpl;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import com.ibm.richtext.uiimpl.resources.FrameResources;
|
||||
|
||||
import com.ibm.richtext.styledtext.MConstText;
|
||||
import com.ibm.richtext.styledtext.StyledText;
|
||||
import com.ibm.richtext.styledtext.StyleModifier;
|
||||
|
||||
import com.ibm.textlayout.attributes.AttributeMap;
|
||||
import com.ibm.textlayout.attributes.TextAttribute;
|
||||
|
||||
public final class AboutText {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private static final Color[] COLORS = {
|
||||
Color.red, Color.blue, Color.white, Color.green
|
||||
};
|
||||
|
||||
public static MConstText getAboutText() {
|
||||
|
||||
String text = ResourceUtils.getResourceString(FrameResources.ABOUT_TEXT);
|
||||
StyledText styledText = new StyledText(text, AttributeMap.EMPTY_ATTRIBUTE_MAP);
|
||||
|
||||
int length = styledText.length();
|
||||
int i=0;
|
||||
|
||||
for (int paragraphStart = 0, paragraphLimit;
|
||||
paragraphStart < length;
|
||||
paragraphStart = paragraphLimit) {
|
||||
|
||||
paragraphLimit = styledText.paragraphLimit(paragraphStart);
|
||||
StyleModifier modifier = StyleModifier.createAddModifier(
|
||||
TextAttribute.FOREGROUND,
|
||||
COLORS[(i++)%COLORS.length]);
|
||||
styledText.modifyCharacterStyles(paragraphStart,
|
||||
paragraphLimit,
|
||||
modifier);
|
||||
}
|
||||
|
||||
StyleModifier modifier = StyleModifier.createAddModifier(
|
||||
TextAttribute.LINE_FLUSH,
|
||||
TextAttribute.FLUSH_CENTER);
|
||||
|
||||
styledText.modifyParagraphStyles(0, text.length(), modifier);
|
||||
|
||||
return styledText;
|
||||
}
|
||||
}
|
99
icu4j/src/com/ibm/richtext/uiimpl/BooleanStyleMenuItem.java
Executable file
99
icu4j/src/com/ibm/richtext/uiimpl/BooleanStyleMenuItem.java
Executable file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* @(#)$RCSfile: BooleanStyleMenuItem.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:52:32 $
|
||||
*
|
||||
* (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.uiimpl;
|
||||
|
||||
import java.util.EventObject;
|
||||
|
||||
import com.ibm.textlayout.attributes.AttributeSet;
|
||||
import com.ibm.richtext.styledtext.StyleModifier;
|
||||
|
||||
import com.ibm.richtext.textpanel.MTextPanel;
|
||||
import com.ibm.richtext.textpanel.TextPanelEvent;
|
||||
import com.ibm.richtext.uiimpl.resources.MenuData;
|
||||
|
||||
public final class BooleanStyleMenuItem extends SingleCheckMenuItem {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
|
||||
private final Object fKey;
|
||||
private final boolean fCharacter;
|
||||
|
||||
private final Object fOnValue;
|
||||
|
||||
public BooleanStyleMenuItem(Object style,
|
||||
Object onValue,
|
||||
MenuData menuData,
|
||||
boolean character) {
|
||||
|
||||
super(menuData);
|
||||
if (onValue == null) {
|
||||
throw new IllegalArgumentException("On value cannot be null");
|
||||
}
|
||||
|
||||
fKey = style;
|
||||
fCharacter = character;
|
||||
|
||||
fOnValue = onValue;
|
||||
fItem.addListener(new EventListener() {
|
||||
public void eventOccurred(EventObject event) {
|
||||
StyleModifier modifier;
|
||||
MTextPanel panel = getTextPanel();
|
||||
if (panel == null) {
|
||||
throw new Error("Menu item is enabled when panel is null!");
|
||||
}
|
||||
if (continuousAndCommand()) {
|
||||
AttributeSet set = new AttributeSet(fKey);
|
||||
modifier = StyleModifier.createRemoveModifier(set);
|
||||
}
|
||||
else {
|
||||
modifier = StyleModifier.createAddModifier(fKey, fOnValue);
|
||||
}
|
||||
|
||||
if (fCharacter == CHARACTER) {
|
||||
panel.modifyCharacterStyleOnSelection(modifier);
|
||||
}
|
||||
else {
|
||||
panel.modifyParagraphStyleOnSelection(modifier);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean continuousAndCommand() {
|
||||
|
||||
MTextPanel panel = getTextPanel();
|
||||
|
||||
Object value = (fCharacter == CHARACTER)?
|
||||
panel.getCharacterStyleOverSelection(fKey) :
|
||||
panel.getParagraphStyleOverSelection(fKey);
|
||||
return fOnValue.equals(value);
|
||||
}
|
||||
|
||||
protected void setChecked() {
|
||||
|
||||
fItem.setState(continuousAndCommand());
|
||||
}
|
||||
|
||||
public boolean respondsToEventType(int type) {
|
||||
|
||||
return type == TextPanelEvent.SELECTION_STYLES_CHANGED;
|
||||
}
|
||||
|
||||
public final void textEventOccurred(TextPanelEvent event) {
|
||||
|
||||
setChecked();
|
||||
}
|
||||
}
|
96
icu4j/src/com/ibm/richtext/uiimpl/ChoiceMenuItemSet.java
Executable file
96
icu4j/src/com/ibm/richtext/uiimpl/ChoiceMenuItemSet.java
Executable file
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* @(#)$RCSfile: ChoiceMenuItemSet.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:52:32 $
|
||||
*
|
||||
* (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.uiimpl;
|
||||
|
||||
import java.util.EventObject;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
import com.ibm.textlayout.attributes.AttributeSet;
|
||||
import com.ibm.richtext.styledtext.StyleModifier;
|
||||
|
||||
import com.ibm.richtext.textpanel.MTextPanel;
|
||||
import com.ibm.richtext.textpanel.TextPanelEvent;
|
||||
import com.ibm.richtext.uiimpl.resources.MenuData;
|
||||
|
||||
public abstract class ChoiceMenuItemSet extends MenuItemSet {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private MItem[] fItems;
|
||||
private Hashtable fItemToStyleMap;
|
||||
|
||||
ChoiceMenuItemSet(Object[] values,
|
||||
MenuData[] menuData) {
|
||||
|
||||
if (values.length != menuData.length) {
|
||||
throw new IllegalArgumentException(
|
||||
"Values and names must have equal length");
|
||||
}
|
||||
|
||||
fItems = new MItem[menuData.length];
|
||||
fItemToStyleMap = new Hashtable(menuData.length);
|
||||
|
||||
EventListener listener = new EventListener() {
|
||||
public void eventOccurred(EventObject event) {
|
||||
handleValueSelected(fItemToStyleMap.get(event.getSource()));
|
||||
}
|
||||
};
|
||||
|
||||
for (int i=0; i < menuData.length; i++) {
|
||||
fItems[i] = MItem.createCheckboxItem(menuData[i]);
|
||||
if (values[i] != null) {
|
||||
fItemToStyleMap.put(fItems[i], values[i]);
|
||||
}
|
||||
fItems[i].addListener(listener);
|
||||
fItems[i].setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void handleValueSelected(Object item);
|
||||
protected abstract Object getCurrentValue();
|
||||
|
||||
protected final void setChecked() {
|
||||
|
||||
Object value = getCurrentValue();
|
||||
|
||||
for (int i=0; i < fItems.length; i++) {
|
||||
Object itemVal = fItemToStyleMap.get(fItems[i]);
|
||||
if (itemVal == null) {
|
||||
fItems[i].setState(value == null);
|
||||
}
|
||||
else {
|
||||
fItems[i].setState(itemVal.equals(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected final void textPanelChanged() {
|
||||
|
||||
MTextPanel textPanel = getTextPanel();
|
||||
if (textPanel == null) {
|
||||
for (int i=0; i < fItems.length; i++) {
|
||||
fItems[i].setEnabled(false);
|
||||
fItems[i].setState(false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int i=0; i < fItems.length; i++) {
|
||||
fItems[i].setEnabled(true);
|
||||
setChecked();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
195
icu4j/src/com/ibm/richtext/uiimpl/CommandMenuItem.java
Executable file
195
icu4j/src/com/ibm/richtext/uiimpl/CommandMenuItem.java
Executable file
@ -0,0 +1,195 @@
|
||||
/*
|
||||
* @(#)$RCSfile: CommandMenuItem.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:52:32 $
|
||||
*
|
||||
* (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.uiimpl;
|
||||
|
||||
import java.util.EventObject;
|
||||
|
||||
import com.ibm.richtext.textpanel.MTextPanel;
|
||||
import com.ibm.richtext.textpanel.TextPanelEvent;
|
||||
import com.ibm.richtext.uiimpl.resources.MenuData;
|
||||
|
||||
public abstract class CommandMenuItem extends MenuItemSet {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private /*final*/ MItem fItem;
|
||||
|
||||
protected abstract boolean isEnabled();
|
||||
protected abstract void performAction();
|
||||
|
||||
protected CommandMenuItem(MenuData data) {
|
||||
|
||||
this(data, false);
|
||||
}
|
||||
|
||||
protected CommandMenuItem(MenuData data, boolean enableByDefault) {
|
||||
|
||||
fItem = MItem.createItem(data);
|
||||
fItem.addListener(new EventListener() {
|
||||
public void eventOccurred(EventObject event) {
|
||||
performAction();
|
||||
}
|
||||
});
|
||||
fItem.setEnabled(enableByDefault);
|
||||
}
|
||||
|
||||
protected void textPanelChanged() {
|
||||
|
||||
MTextPanel textPanel = getTextPanel();
|
||||
if (textPanel == null) {
|
||||
fItem.setEnabled(false);
|
||||
}
|
||||
else {
|
||||
fItem.setEnabled(isEnabled());
|
||||
}
|
||||
}
|
||||
|
||||
public final void textEventOccurred(TextPanelEvent event) {
|
||||
|
||||
fItem.setEnabled(isEnabled());
|
||||
}
|
||||
|
||||
public static final class CutCopyClear extends CommandMenuItem {
|
||||
|
||||
public static final int CUT = 0;
|
||||
public static final int COPY = 1;
|
||||
public static final int CLEAR = 2;
|
||||
|
||||
private final int fKind;
|
||||
|
||||
public CutCopyClear(MenuData menuData, int kind) {
|
||||
|
||||
super(menuData);
|
||||
if (kind != CUT && kind != COPY && kind != CLEAR) {
|
||||
throw new IllegalArgumentException("Invalid menu kind");
|
||||
}
|
||||
fKind = kind;
|
||||
}
|
||||
|
||||
protected boolean isEnabled() {
|
||||
|
||||
MTextPanel panel = getTextPanel();
|
||||
return panel.getSelectionStart() != panel.getSelectionEnd();
|
||||
}
|
||||
|
||||
public boolean respondsToEventType(int type) {
|
||||
|
||||
return type == TextPanelEvent.SELECTION_EMPTY_CHANGED;
|
||||
}
|
||||
|
||||
protected void performAction() {
|
||||
|
||||
MTextPanel panel = getTextPanel();
|
||||
switch (fKind) {
|
||||
case CUT:
|
||||
panel.cut();
|
||||
break;
|
||||
case COPY:
|
||||
panel.copy();
|
||||
break;
|
||||
case CLEAR:
|
||||
panel.clear();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final class UndoRedo extends CommandMenuItem {
|
||||
|
||||
public static final boolean UNDO = true;
|
||||
public static final boolean REDO = false;
|
||||
|
||||
private boolean fKind;
|
||||
|
||||
public UndoRedo(MenuData menuData, boolean kind) {
|
||||
|
||||
super(menuData);
|
||||
fKind = kind;
|
||||
}
|
||||
|
||||
protected boolean isEnabled() {
|
||||
|
||||
MTextPanel panel = getTextPanel();
|
||||
if (fKind == UNDO) {
|
||||
return panel.canUndo();
|
||||
}
|
||||
else {
|
||||
return panel.canRedo();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean respondsToEventType(int type) {
|
||||
|
||||
return type == TextPanelEvent.UNDO_STATE_CHANGED;
|
||||
}
|
||||
|
||||
protected void performAction() {
|
||||
|
||||
MTextPanel panel = getTextPanel();
|
||||
if (fKind == UNDO) {
|
||||
panel.undo();
|
||||
}
|
||||
else {
|
||||
panel.redo();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Paste extends CommandMenuItem {
|
||||
|
||||
public Paste(MenuData menuData) {
|
||||
|
||||
super(menuData);
|
||||
}
|
||||
|
||||
protected boolean isEnabled() {
|
||||
|
||||
return getTextPanel().clipboardNotEmpty();
|
||||
}
|
||||
|
||||
public boolean respondsToEventType(int type) {
|
||||
|
||||
return type == TextPanelEvent.CLIPBOARD_CHANGED;
|
||||
}
|
||||
|
||||
protected void performAction() {
|
||||
|
||||
getTextPanel().paste();
|
||||
}
|
||||
}
|
||||
|
||||
public static final class SelectAll extends CommandMenuItem {
|
||||
|
||||
public SelectAll(MenuData menuData) {
|
||||
|
||||
super(menuData);
|
||||
}
|
||||
|
||||
protected boolean isEnabled() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean respondsToEventType(int type) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void performAction() {
|
||||
|
||||
getTextPanel().selectAll();
|
||||
}
|
||||
}
|
||||
}
|
74
icu4j/src/com/ibm/richtext/uiimpl/DialogItem.java
Executable file
74
icu4j/src/com/ibm/richtext/uiimpl/DialogItem.java
Executable file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* @(#)$RCSfile: DialogItem.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:52:32 $
|
||||
*
|
||||
* (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.uiimpl;
|
||||
|
||||
import java.awt.Window;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
import com.ibm.richtext.textpanel.MTextPanel;
|
||||
import com.ibm.richtext.textpanel.TextPanelEvent;
|
||||
import com.ibm.richtext.uiimpl.resources.MenuData;
|
||||
|
||||
public final class DialogItem extends CommandMenuItem {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
public static abstract class DialogFactory {
|
||||
|
||||
public abstract Window createDialog(MTextPanel textPanel);
|
||||
}
|
||||
|
||||
private DialogFactory fDialogFactory;
|
||||
private Window fDialog = null;
|
||||
|
||||
public DialogItem(MenuData menuData,
|
||||
DialogFactory dialogFactory) {
|
||||
|
||||
super(menuData, true);
|
||||
fDialogFactory = dialogFactory;
|
||||
}
|
||||
|
||||
protected void textPanelChanged() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
protected boolean isEnabled() {
|
||||
|
||||
// should never get called...
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean respondsToEventType(int type) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void performAction() {
|
||||
|
||||
if (fDialog == null) {
|
||||
MTextPanel panel = getTextPanel();
|
||||
if (panel != null) {
|
||||
fDialog = fDialogFactory.createDialog(panel);
|
||||
fDialog.addWindowListener(new WindowAdapter() {
|
||||
public void windowClosed(WindowEvent e) {
|
||||
fDialog = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
fDialog.show();
|
||||
}
|
||||
}
|
24
icu4j/src/com/ibm/richtext/uiimpl/EventListener.java
Executable file
24
icu4j/src/com/ibm/richtext/uiimpl/EventListener.java
Executable file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* @(#)$RCSfile: EventListener.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:52:32 $
|
||||
*
|
||||
* (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.uiimpl;
|
||||
|
||||
import java.util.EventObject;
|
||||
|
||||
public interface EventListener {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
public void eventOccurred(EventObject event);
|
||||
}
|
66
icu4j/src/com/ibm/richtext/uiimpl/FontList.java
Executable file
66
icu4j/src/com/ibm/richtext/uiimpl/FontList.java
Executable file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* @(#)$RCSfile: FontList.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:52:32 $
|
||||
*
|
||||
* (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.
|
||||
*/
|
||||
// Requires Java2
|
||||
package com.ibm.richtext.uiimpl;
|
||||
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.Vector;
|
||||
|
||||
final class FontList {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
|
||||
private static final String[] stripThese = {
|
||||
".bold", ".bolditalic", ".italic"
|
||||
};
|
||||
|
||||
public static String[] getFontList() {
|
||||
|
||||
String[] names = GraphicsEnvironment.getLocalGraphicsEnvironment()
|
||||
.getAvailableFontFamilyNames();
|
||||
Vector v = new Vector(names.length);
|
||||
for (int i=0; i < names.length; i++) {
|
||||
v.addElement(names[i]);
|
||||
}
|
||||
|
||||
Collections.sort(v);
|
||||
|
||||
String last = "";
|
||||
|
||||
Iterator iter = v.listIterator();
|
||||
while (iter.hasNext()) {
|
||||
String current = (String) iter.next();
|
||||
testSuffixes: for (int i=0; i < stripThese.length; i++) {
|
||||
if (current.endsWith(stripThese[i])) {
|
||||
int baseLen = current.length()-stripThese[i].length();
|
||||
String base = current.substring(0, baseLen);
|
||||
if (base.equalsIgnoreCase(last)) {
|
||||
iter.remove();
|
||||
current = last;
|
||||
break testSuffixes;
|
||||
}
|
||||
}
|
||||
}
|
||||
last = current;
|
||||
}
|
||||
|
||||
String[] result = new String[v.size()];
|
||||
v.copyInto(result);
|
||||
return result;
|
||||
}
|
||||
}
|
61
icu4j/src/com/ibm/richtext/uiimpl/KeymapMenuItemSet.java
Executable file
61
icu4j/src/com/ibm/richtext/uiimpl/KeymapMenuItemSet.java
Executable file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* @(#)$RCSfile: KeymapMenuItemSet.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:52:32 $
|
||||
*
|
||||
* (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.uiimpl;
|
||||
|
||||
import com.ibm.richtext.textpanel.KeyRemap;
|
||||
import com.ibm.richtext.textpanel.TextPanelEvent;
|
||||
import com.ibm.richtext.textpanel.MTextPanel;
|
||||
import com.ibm.richtext.uiimpl.resources.MenuData;
|
||||
|
||||
public final class KeymapMenuItemSet extends ChoiceMenuItemSet {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
public KeymapMenuItemSet(KeyRemap[] values,
|
||||
MenuData[] menuData) {
|
||||
|
||||
super(values, menuData);
|
||||
}
|
||||
|
||||
protected void handleValueSelected(Object value) {
|
||||
|
||||
MTextPanel textPanel = getTextPanel();
|
||||
if (textPanel == null) {
|
||||
throw new Error("Menu item is enabled when panel is null!");
|
||||
}
|
||||
|
||||
textPanel.setKeyRemap((KeyRemap) value);
|
||||
}
|
||||
|
||||
protected Object getCurrentValue() {
|
||||
|
||||
MTextPanel textPanel = getTextPanel();
|
||||
if (textPanel == null) {
|
||||
throw new Error("Shouldn't call this without a text panel!");
|
||||
}
|
||||
return textPanel.getKeyRemap();
|
||||
}
|
||||
|
||||
public void textEventOccurred(TextPanelEvent event) {
|
||||
|
||||
setChecked();
|
||||
}
|
||||
|
||||
public boolean respondsToEventType(int type) {
|
||||
|
||||
return type == TextPanelEvent.KEYREMAP_CHANGED;
|
||||
}
|
||||
|
||||
}
|
87
icu4j/src/com/ibm/richtext/uiimpl/MItem.java
Executable file
87
icu4j/src/com/ibm/richtext/uiimpl/MItem.java
Executable file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* @(#)$RCSfile: MItem.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:52:32 $
|
||||
*
|
||||
* (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.uiimpl;
|
||||
|
||||
import java.util.Vector;
|
||||
import java.util.EventObject;
|
||||
|
||||
import com.ibm.richtext.uiimpl.resources.MenuData;
|
||||
|
||||
public abstract class MItem {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private Vector fListeners = new Vector(2);
|
||||
private EventObject fEvent = new EventObject(this);
|
||||
|
||||
public abstract void setEnabled(boolean enabled);
|
||||
public abstract void setState(boolean checked);
|
||||
|
||||
public final void addListener(EventListener listener) {
|
||||
|
||||
fListeners.addElement(listener);
|
||||
}
|
||||
|
||||
public final void removeListener(EventListener listener) {
|
||||
|
||||
fListeners.removeElement(listener);
|
||||
}
|
||||
|
||||
protected void handleSelected() {
|
||||
|
||||
int length = fListeners.size();
|
||||
for (int i=0; i < length; i++) {
|
||||
EventListener l = (EventListener) fListeners.elementAt(i);
|
||||
l.eventOccurred(fEvent);
|
||||
}
|
||||
}
|
||||
|
||||
// factory stuff
|
||||
|
||||
/**
|
||||
* Clients should synchronize on LOCK while setting and using
|
||||
* global factory.
|
||||
*/
|
||||
public static final Object LOCK = new Object();
|
||||
|
||||
public static interface ItemFactory {
|
||||
|
||||
public MItem createItem(MenuData menuData);
|
||||
public MItem createCheckboxItem(MenuData menuData);
|
||||
public void createSeparator();
|
||||
}
|
||||
|
||||
private static ItemFactory fgFactory;
|
||||
|
||||
public static MItem createItem(MenuData menuData) {
|
||||
|
||||
return fgFactory.createItem(menuData);
|
||||
}
|
||||
|
||||
public static MItem createCheckboxItem(MenuData menuData) {
|
||||
|
||||
return fgFactory.createCheckboxItem(menuData);
|
||||
}
|
||||
|
||||
public static void setItemFactory(ItemFactory factory) {
|
||||
|
||||
fgFactory = factory;
|
||||
}
|
||||
|
||||
public static ItemFactory getItemFactory() {
|
||||
|
||||
return fgFactory;
|
||||
}
|
||||
}
|
368
icu4j/src/com/ibm/richtext/uiimpl/MenuBuilder.java
Executable file
368
icu4j/src/com/ibm/richtext/uiimpl/MenuBuilder.java
Executable file
@ -0,0 +1,368 @@
|
||||
/*
|
||||
* @(#)$RCSfile: MenuBuilder.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:52:32 $
|
||||
*
|
||||
* (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.uiimpl;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Frame;
|
||||
|
||||
import java.awt.Window;
|
||||
import java.text.NumberFormat;
|
||||
|
||||
import com.ibm.richtext.styledtext.MConstText;
|
||||
|
||||
import com.ibm.textlayout.attributes.AttributeMap;
|
||||
import com.ibm.textlayout.attributes.TextAttribute;
|
||||
import com.ibm.richtext.textpanel.MTextPanel;
|
||||
import com.ibm.richtext.textpanel.KeyRemap;
|
||||
|
||||
import com.ibm.richtext.uiimpl.resources.FrameResources;
|
||||
import com.ibm.richtext.uiimpl.resources.MenuData;
|
||||
|
||||
import com.ibm.richtext.uiimpl.DialogItem.DialogFactory;
|
||||
|
||||
public abstract class MenuBuilder {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
|
||||
protected static final int EDIT = 0;
|
||||
protected static final int SIZE = 1;
|
||||
protected static final int STYLE = 2;
|
||||
protected static final int FLUSH = 3;
|
||||
protected static final int KEYMAP = 4;
|
||||
protected static final int BIDI = 5;
|
||||
protected static final int ABOUT = 6;
|
||||
|
||||
private Color[] colors = { Color.black, Color.white, Color.green, Color.blue,
|
||||
Color.cyan, Color.gray, Color.darkGray, Color.lightGray,
|
||||
Color.magenta, Color.orange, Color.pink, Color.red,
|
||||
Color.yellow, null };
|
||||
private String[] colorNames = {
|
||||
ResourceUtils.getResourceString(FrameResources.BLACK),
|
||||
ResourceUtils.getResourceString(FrameResources.WHITE),
|
||||
ResourceUtils.getResourceString(FrameResources.GREEN),
|
||||
ResourceUtils.getResourceString(FrameResources.BLUE),
|
||||
ResourceUtils.getResourceString(FrameResources.CYAN),
|
||||
ResourceUtils.getResourceString(FrameResources.GRAY),
|
||||
ResourceUtils.getResourceString(FrameResources.DARK_GRAY),
|
||||
ResourceUtils.getResourceString(FrameResources.LIGHT_GRAY),
|
||||
ResourceUtils.getResourceString(FrameResources.MAGENTA),
|
||||
ResourceUtils.getResourceString(FrameResources.ORANGE),
|
||||
ResourceUtils.getResourceString(FrameResources.PINK),
|
||||
ResourceUtils.getResourceString(FrameResources.RED),
|
||||
ResourceUtils.getResourceString(FrameResources.YELLOW),
|
||||
ResourceUtils.getResourceString(FrameResources.NONE)
|
||||
};
|
||||
|
||||
protected int[] defaultMenus = { EDIT,
|
||||
SIZE,
|
||||
STYLE,
|
||||
FLUSH,
|
||||
KEYMAP,
|
||||
BIDI,
|
||||
ABOUT };
|
||||
|
||||
protected MTextPanel fTextPanel;
|
||||
protected Frame fDialogParent;
|
||||
|
||||
protected MenuBuilder() {
|
||||
}
|
||||
|
||||
protected final void doCreateMenus(MTextPanel textPanel, Frame frame, int[] menus) {
|
||||
|
||||
fTextPanel = textPanel;
|
||||
fDialogParent = frame;
|
||||
|
||||
for (int i=0; i < menus.length; i++) {
|
||||
switch(menus[i]) {
|
||||
case EDIT:
|
||||
createEditMenu();
|
||||
break;
|
||||
case SIZE:
|
||||
createSizeMenu();
|
||||
break;
|
||||
case STYLE:
|
||||
createStyleMenu();
|
||||
break;
|
||||
case FLUSH:
|
||||
createFlushMenu();
|
||||
break;
|
||||
case KEYMAP:
|
||||
createKeymapMenu();
|
||||
break;
|
||||
case BIDI:
|
||||
createBidiMenu();
|
||||
break;
|
||||
case ABOUT:
|
||||
createAboutMenu();
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Illegal menu: " + menus[i]);
|
||||
}
|
||||
}
|
||||
|
||||
fTextPanel = null;
|
||||
fDialogParent = null;
|
||||
}
|
||||
|
||||
protected abstract void handleAddMenu(String key);
|
||||
|
||||
protected abstract DialogFactory createObjectDialogFactory(String dialogTitle,
|
||||
String dialogText,
|
||||
Object key,
|
||||
boolean character,
|
||||
String[] names,
|
||||
Object[] values);
|
||||
|
||||
protected abstract DialogFactory createNumberDialogFactory(String dialogTitle,
|
||||
String dialogText,
|
||||
Object key,
|
||||
boolean character);
|
||||
|
||||
protected abstract DialogFactory createAboutDialogFactory();
|
||||
|
||||
private void createEditMenu() {
|
||||
|
||||
handleAddMenu(FrameResources.EDIT);
|
||||
|
||||
new CommandMenuItem.UndoRedo(ResourceUtils.getMenuData(FrameResources.UNDO),
|
||||
CommandMenuItem.UndoRedo.UNDO).setTextPanel(fTextPanel);
|
||||
new CommandMenuItem.UndoRedo(ResourceUtils.getMenuData(FrameResources.REDO),
|
||||
CommandMenuItem.UndoRedo.REDO).setTextPanel(fTextPanel);
|
||||
MItem.getItemFactory().createSeparator();
|
||||
new CommandMenuItem.CutCopyClear(ResourceUtils.getMenuData(FrameResources.CUT),
|
||||
CommandMenuItem.CutCopyClear.CUT).setTextPanel(fTextPanel);
|
||||
new CommandMenuItem.CutCopyClear(ResourceUtils.getMenuData(FrameResources.COPY),
|
||||
CommandMenuItem.CutCopyClear.COPY).setTextPanel(fTextPanel);
|
||||
new CommandMenuItem.Paste(ResourceUtils.getMenuData(FrameResources.PASTE)).setTextPanel(fTextPanel);
|
||||
new CommandMenuItem.CutCopyClear(ResourceUtils.getMenuData(FrameResources.CLEAR),
|
||||
CommandMenuItem.CutCopyClear.CLEAR).setTextPanel(fTextPanel);
|
||||
MItem.getItemFactory().createSeparator();
|
||||
new CommandMenuItem.SelectAll(ResourceUtils.getMenuData(FrameResources.SELECT_ALL)).setTextPanel(fTextPanel);
|
||||
}
|
||||
|
||||
private static final float[] DEFAULT_SIZES =
|
||||
{9, 10, 12, 14, 18, 24, 36, 48, 72};
|
||||
|
||||
private void createSizeMenu() {
|
||||
|
||||
createSizeMenu(DEFAULT_SIZES);
|
||||
}
|
||||
|
||||
private void createSizeMenu(float[] sizes) {
|
||||
|
||||
handleAddMenu(FrameResources.SIZE);
|
||||
|
||||
if (sizes != DEFAULT_SIZES) {
|
||||
|
||||
sizes = (float[]) sizes.clone();
|
||||
if (sizes.length == 0) {
|
||||
throw new IllegalArgumentException("sizes array has zero length");
|
||||
}
|
||||
|
||||
float lastValue = sizes[0];
|
||||
for (int i=1; i < sizes.length; i++) {
|
||||
if (sizes[i] >= lastValue) {
|
||||
throw new IllegalArgumentException(
|
||||
"sizes array must be increasing");
|
||||
}
|
||||
lastValue = sizes[i];
|
||||
}
|
||||
}
|
||||
|
||||
Float[] values = new Float[sizes.length];
|
||||
MenuData[] mData = new MenuData[sizes.length];
|
||||
NumberFormat fmt = NumberFormat.getNumberInstance();
|
||||
|
||||
for (int i=0; i < sizes.length; i++) {
|
||||
values[i] = new Float(sizes[i]);
|
||||
mData[i] = new MenuData(fmt.format(sizes[i]));
|
||||
}
|
||||
|
||||
new StyleMenuItemSet(TextAttribute.SIZE,
|
||||
values,
|
||||
mData,
|
||||
MenuItemSet.CHARACTER).setTextPanel(fTextPanel);
|
||||
|
||||
if (fDialogParent != null) {
|
||||
String dialogTitle = ResourceUtils.getResourceString(FrameResources.SET_SIZE_TITLE);
|
||||
String dialogText = ResourceUtils.getResourceString(FrameResources.SET_SIZE_LABEL);
|
||||
DialogFactory factory = createNumberDialogFactory(dialogTitle,
|
||||
dialogText,
|
||||
TextAttribute.SIZE,
|
||||
MenuItemSet.CHARACTER);
|
||||
|
||||
new DialogItem(ResourceUtils.getMenuData(FrameResources.OTHER_DIALOG),
|
||||
factory).setTextPanel(fTextPanel);
|
||||
}
|
||||
}
|
||||
|
||||
private void createStyleMenu() {
|
||||
|
||||
handleAddMenu(FrameResources.STYLE);
|
||||
|
||||
Object[] keys = { TextAttribute.WEIGHT,
|
||||
TextAttribute.POSTURE,
|
||||
TextAttribute.UNDERLINE,
|
||||
TextAttribute.STRIKETHROUGH };
|
||||
Object[] values = { TextAttribute.WEIGHT_BOLD,
|
||||
TextAttribute.POSTURE_OBLIQUE,
|
||||
TextAttribute.UNDERLINE_ON,
|
||||
TextAttribute.STRIKETHROUGH_ON };
|
||||
MenuData[] mData = { ResourceUtils.getMenuData(FrameResources.BOLD),
|
||||
ResourceUtils.getMenuData(FrameResources.ITALIC),
|
||||
ResourceUtils.getMenuData(FrameResources.UNDERLINE),
|
||||
ResourceUtils.getMenuData(FrameResources.STRIKETHROUGH) };
|
||||
|
||||
new SubtractStyleMenuItem(keys,
|
||||
ResourceUtils.getMenuData(FrameResources.PLAIN),
|
||||
MenuItemSet.CHARACTER).setTextPanel(fTextPanel);
|
||||
|
||||
for (int i=0; i < keys.length; i++) {
|
||||
new BooleanStyleMenuItem(keys[i],
|
||||
values[i],
|
||||
mData[i],
|
||||
MenuItemSet.CHARACTER).setTextPanel(fTextPanel);
|
||||
}
|
||||
|
||||
if (fDialogParent != null) {
|
||||
|
||||
MItem.getItemFactory().createSeparator();
|
||||
|
||||
String[] fonts = FontList.getFontList();
|
||||
String title = ResourceUtils.getResourceString(FrameResources.SET_FONT_TITLE);
|
||||
String label = ResourceUtils.getResourceString(FrameResources.SET_FONT_LABEL);
|
||||
|
||||
DialogFactory fontF = createObjectDialogFactory(title,
|
||||
label,
|
||||
TextAttribute.FAMILY,
|
||||
StyleMenuItemSet.CHARACTER,
|
||||
fonts,
|
||||
fonts);
|
||||
new DialogItem(ResourceUtils.getMenuData(FrameResources.FONT_DIALOG),
|
||||
fontF).setTextPanel(fTextPanel);
|
||||
|
||||
DialogFactory foregroundF = createColorDialogFactory(true);
|
||||
DialogFactory backgroundF = createColorDialogFactory(false);
|
||||
|
||||
new DialogItem(ResourceUtils.getMenuData(FrameResources.FORECOLOR_DIALOG),
|
||||
foregroundF).setTextPanel(fTextPanel);
|
||||
new DialogItem(ResourceUtils.getMenuData(FrameResources.BACKCOLOR_DIALOG),
|
||||
backgroundF).setTextPanel(fTextPanel);
|
||||
}
|
||||
}
|
||||
|
||||
private DialogFactory createColorDialogFactory(boolean foreground) {
|
||||
|
||||
String title;
|
||||
String message;
|
||||
Object key;
|
||||
|
||||
if (foreground) {
|
||||
title = ResourceUtils.getResourceString(FrameResources.SET_FOREGROUND_TITLE);
|
||||
message = ResourceUtils.getResourceString(FrameResources.SET_FOREGROUND_LABEL);
|
||||
key = TextAttribute.FOREGROUND;
|
||||
}
|
||||
else {
|
||||
title = ResourceUtils.getResourceString(FrameResources.SET_BACKGROUND_TITLE);
|
||||
message = ResourceUtils.getResourceString(FrameResources.SET_BACKGROUND_LABEL);
|
||||
key = TextAttribute.BACKGROUND;
|
||||
}
|
||||
return createObjectDialogFactory(title,
|
||||
message,
|
||||
key,
|
||||
StyleMenuItemSet.CHARACTER,
|
||||
colorNames,
|
||||
colors);
|
||||
}
|
||||
|
||||
private void createFontMenu() {
|
||||
|
||||
handleAddMenu(FrameResources.FONT);
|
||||
|
||||
String[] fonts = FontList.getFontList();
|
||||
MenuData[] mData = new MenuData[fonts.length];
|
||||
for (int i=0; i < mData.length; i++) {
|
||||
mData[i] = new MenuData(fonts[i]);
|
||||
}
|
||||
|
||||
new StyleMenuItemSet(TextAttribute.FAMILY,
|
||||
fonts,
|
||||
mData,
|
||||
StyleMenuItemSet.CHARACTER).setTextPanel(fTextPanel);
|
||||
}
|
||||
|
||||
private void createFlushMenu() {
|
||||
|
||||
handleAddMenu(FrameResources.FLUSH);
|
||||
|
||||
Object[] values = { TextAttribute.FLUSH_LEADING,
|
||||
TextAttribute.FLUSH_CENTER,
|
||||
TextAttribute.FLUSH_TRAILING,
|
||||
TextAttribute.FULLY_JUSTIFIED };
|
||||
MenuData[] mData = { ResourceUtils.getMenuData(FrameResources.LEADING),
|
||||
ResourceUtils.getMenuData(FrameResources.CENTER),
|
||||
ResourceUtils.getMenuData(FrameResources.TRAILING),
|
||||
ResourceUtils.getMenuData(FrameResources.JUSTIFIED) };
|
||||
|
||||
new StyleMenuItemSet(TextAttribute.LINE_FLUSH,
|
||||
values,
|
||||
mData,
|
||||
MenuItemSet.PARAGRAPH).setTextPanel(fTextPanel);
|
||||
}
|
||||
|
||||
private void createKeymapMenu() {
|
||||
|
||||
handleAddMenu(FrameResources.KEYMAP);
|
||||
|
||||
KeyRemap[] values = { KeyRemap.getIdentityRemap(),
|
||||
KeyRemap.getArabicTransliteration(),
|
||||
KeyRemap.getHebrewTransliteration(),
|
||||
KeyRemap.getIsraelNikud(),
|
||||
KeyRemap.getThaiKetmanee() };
|
||||
MenuData[] mData = { ResourceUtils.getMenuData(FrameResources.DEFAULT),
|
||||
ResourceUtils.getMenuData(FrameResources.ARABIC),
|
||||
ResourceUtils.getMenuData(FrameResources.HEBREW),
|
||||
ResourceUtils.getMenuData(FrameResources.ISRAEL_NIKUD),
|
||||
ResourceUtils.getMenuData(FrameResources.THAI_KETMANEE) };
|
||||
|
||||
new KeymapMenuItemSet(values, mData).setTextPanel(fTextPanel);
|
||||
}
|
||||
|
||||
private void createBidiMenu() {
|
||||
|
||||
handleAddMenu(FrameResources.BIDI);
|
||||
|
||||
Object[] values = { null,
|
||||
TextAttribute.RUN_DIRECTION_LTR,
|
||||
TextAttribute.RUN_DIRECTION_RTL };
|
||||
MenuData[] mData = { ResourceUtils.getMenuData(FrameResources.DEFAULT_DIRECTION),
|
||||
ResourceUtils.getMenuData(FrameResources.LTR_DIRECTION),
|
||||
ResourceUtils.getMenuData(FrameResources.RTL_DIRECTION), };
|
||||
|
||||
new StyleMenuItemSet(TextAttribute.RUN_DIRECTION,
|
||||
values,
|
||||
mData,
|
||||
MenuItemSet.PARAGRAPH).setTextPanel(fTextPanel);
|
||||
}
|
||||
|
||||
private void createAboutMenu() {
|
||||
|
||||
handleAddMenu(FrameResources.ABOUT_MENU);
|
||||
|
||||
new DialogItem(ResourceUtils.getMenuData(FrameResources.ABOUT_ITEM),
|
||||
createAboutDialogFactory()).setTextPanel(fTextPanel);
|
||||
}
|
||||
}
|
54
icu4j/src/com/ibm/richtext/uiimpl/MenuItemSet.java
Executable file
54
icu4j/src/com/ibm/richtext/uiimpl/MenuItemSet.java
Executable file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* @(#)$RCSfile: MenuItemSet.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:52:32 $
|
||||
*
|
||||
* (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.uiimpl;
|
||||
|
||||
import com.ibm.richtext.textpanel.MTextPanel;
|
||||
import com.ibm.richtext.textpanel.TextPanelEvent;
|
||||
import com.ibm.richtext.textpanel.TextPanelListener;
|
||||
import com.ibm.richtext.uiimpl.resources.MenuData;
|
||||
|
||||
public abstract class MenuItemSet implements TextPanelListener {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
public static final boolean CHARACTER = true;
|
||||
public static final boolean PARAGRAPH = false;
|
||||
|
||||
private MTextPanel fTextPanel = null;
|
||||
|
||||
public abstract void textEventOccurred(TextPanelEvent event);
|
||||
public abstract boolean respondsToEventType(int type);
|
||||
|
||||
public final void setTextPanel(MTextPanel textPanel) {
|
||||
|
||||
if (fTextPanel != null) {
|
||||
fTextPanel.removeListener(this);
|
||||
}
|
||||
fTextPanel = textPanel;
|
||||
if (fTextPanel != null) {
|
||||
fTextPanel.addListener(this);
|
||||
}
|
||||
|
||||
textPanelChanged();
|
||||
}
|
||||
|
||||
public final MTextPanel getTextPanel() {
|
||||
|
||||
return fTextPanel;
|
||||
}
|
||||
|
||||
protected void textPanelChanged() {
|
||||
}
|
||||
}
|
48
icu4j/src/com/ibm/richtext/uiimpl/ResourceUtils.java
Executable file
48
icu4j/src/com/ibm/richtext/uiimpl/ResourceUtils.java
Executable file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* @(#)$RCSfile: ResourceUtils.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:52:32 $
|
||||
*
|
||||
* (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.uiimpl;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.MissingResourceException;
|
||||
|
||||
import com.ibm.richtext.uiimpl.resources.FrameResources;
|
||||
import com.ibm.richtext.uiimpl.resources.MenuData;
|
||||
|
||||
public class ResourceUtils {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private static ResourceBundle BUNDLE;
|
||||
static {
|
||||
try {
|
||||
BUNDLE = ResourceBundle.getBundle("com.ibm.richtext.uiimpl.resources.FrameResources");
|
||||
}
|
||||
catch(MissingResourceException e) {
|
||||
System.out.println("Couldn't load resourceXXX. " +
|
||||
"Exception: " + e);
|
||||
BUNDLE = new FrameResources();
|
||||
}
|
||||
}
|
||||
|
||||
public static MenuData getMenuData(String key) {
|
||||
|
||||
return (MenuData) BUNDLE.getObject(key);
|
||||
}
|
||||
|
||||
public static String getResourceString(String key) {
|
||||
|
||||
return BUNDLE.getString(key);
|
||||
}
|
||||
}
|
46
icu4j/src/com/ibm/richtext/uiimpl/SingleCheckMenuItem.java
Executable file
46
icu4j/src/com/ibm/richtext/uiimpl/SingleCheckMenuItem.java
Executable file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* @(#)$RCSfile: SingleCheckMenuItem.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:52:32 $
|
||||
*
|
||||
* (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.uiimpl;
|
||||
|
||||
import com.ibm.richtext.textpanel.MTextPanel;
|
||||
import com.ibm.richtext.textpanel.TextPanelEvent;
|
||||
import com.ibm.richtext.uiimpl.resources.MenuData;
|
||||
|
||||
public abstract class SingleCheckMenuItem extends MenuItemSet {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
protected MItem fItem;
|
||||
|
||||
SingleCheckMenuItem(MenuData menuData) {
|
||||
|
||||
fItem = MItem.createCheckboxItem(menuData);
|
||||
}
|
||||
|
||||
abstract void setChecked();
|
||||
|
||||
protected final void textPanelChanged() {
|
||||
|
||||
MTextPanel textPanel = getTextPanel();
|
||||
if (textPanel == null) {
|
||||
fItem.setEnabled(false);
|
||||
fItem.setState(false);
|
||||
}
|
||||
else {
|
||||
fItem.setEnabled(true);
|
||||
setChecked();
|
||||
}
|
||||
}
|
||||
}
|
90
icu4j/src/com/ibm/richtext/uiimpl/StyleMenuItemSet.java
Executable file
90
icu4j/src/com/ibm/richtext/uiimpl/StyleMenuItemSet.java
Executable file
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* @(#)$RCSfile: StyleMenuItemSet.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:52:32 $
|
||||
*
|
||||
* (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.uiimpl;
|
||||
|
||||
import com.ibm.textlayout.attributes.AttributeSet;
|
||||
import com.ibm.richtext.styledtext.StyleModifier;
|
||||
|
||||
import com.ibm.richtext.textpanel.MTextPanel;
|
||||
import com.ibm.richtext.textpanel.TextPanelEvent;
|
||||
import com.ibm.richtext.uiimpl.resources.MenuData;
|
||||
|
||||
public final class StyleMenuItemSet extends ChoiceMenuItemSet {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
|
||||
private Object fKey;
|
||||
private boolean fCharacter;
|
||||
|
||||
public StyleMenuItemSet(Object style,
|
||||
Object[] values,
|
||||
MenuData[] menuData,
|
||||
boolean character) {
|
||||
|
||||
super(values, menuData);
|
||||
fKey = style;
|
||||
fCharacter = character;
|
||||
}
|
||||
|
||||
protected void handleValueSelected(Object value) {
|
||||
|
||||
MTextPanel textPanel = getTextPanel();
|
||||
if (textPanel == null) {
|
||||
throw new Error("Menu item is enabled when panel is null!");
|
||||
}
|
||||
|
||||
StyleModifier modifier;
|
||||
if (value == null) {
|
||||
AttributeSet set = new AttributeSet(fKey);
|
||||
modifier = StyleModifier.createRemoveModifier(set);
|
||||
}
|
||||
else {
|
||||
modifier = StyleModifier.createAddModifier(fKey, value);
|
||||
}
|
||||
|
||||
if (fCharacter == CHARACTER) {
|
||||
textPanel.modifyCharacterStyleOnSelection(modifier);
|
||||
}
|
||||
else {
|
||||
textPanel.modifyParagraphStyleOnSelection(modifier);
|
||||
}
|
||||
}
|
||||
|
||||
protected Object getCurrentValue() {
|
||||
|
||||
MTextPanel textPanel = getTextPanel();
|
||||
if (textPanel == null) {
|
||||
throw new Error("Shouldn't call this without a text panel!");
|
||||
}
|
||||
|
||||
if (fCharacter == CHARACTER) {
|
||||
return textPanel.getCharacterStyleOverSelection(fKey);
|
||||
}
|
||||
else {
|
||||
return textPanel.getParagraphStyleOverSelection(fKey);
|
||||
}
|
||||
}
|
||||
|
||||
public void textEventOccurred(TextPanelEvent event) {
|
||||
|
||||
setChecked();
|
||||
}
|
||||
|
||||
public boolean respondsToEventType(int type) {
|
||||
|
||||
return type == TextPanelEvent.SELECTION_STYLES_CHANGED;
|
||||
}
|
||||
}
|
104
icu4j/src/com/ibm/richtext/uiimpl/SubtractStyleMenuItem.java
Executable file
104
icu4j/src/com/ibm/richtext/uiimpl/SubtractStyleMenuItem.java
Executable file
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* @(#)$RCSfile: SubtractStyleMenuItem.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:52:32 $
|
||||
*
|
||||
* (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.uiimpl;
|
||||
|
||||
import java.util.EventObject;
|
||||
|
||||
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.textpanel.TextPanelEvent;
|
||||
import com.ibm.richtext.uiimpl.resources.MenuData;
|
||||
|
||||
public final class SubtractStyleMenuItem extends SingleCheckMenuItem {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private final Object[] fKeys;
|
||||
|
||||
private final boolean fCharacter;
|
||||
|
||||
public SubtractStyleMenuItem(Object[] keys,
|
||||
MenuData menuData,
|
||||
boolean character) {
|
||||
|
||||
super(menuData);
|
||||
|
||||
fKeys = (Object[]) keys.clone();
|
||||
fCharacter = character;
|
||||
|
||||
AttributeSet keySet = new AttributeSet(keys);
|
||||
final StyleModifier modifier = StyleModifier.createRemoveModifier(keySet);
|
||||
|
||||
fItem.addListener(new EventListener() {
|
||||
public void eventOccurred(EventObject event) {
|
||||
MTextPanel panel = getTextPanel();
|
||||
if (panel == null) {
|
||||
throw new Error("Menu item is enabled when panel is null!");
|
||||
}
|
||||
|
||||
if (fCharacter == CHARACTER) {
|
||||
panel.modifyCharacterStyleOnSelection(modifier);
|
||||
}
|
||||
else {
|
||||
panel.modifyParagraphStyleOnSelection(modifier);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static boolean objectsAreEqual(Object lhs, Object rhs) {
|
||||
|
||||
if (lhs == null) {
|
||||
return rhs == null;
|
||||
}
|
||||
else {
|
||||
return lhs.equals(rhs);
|
||||
}
|
||||
}
|
||||
|
||||
protected void setChecked() {
|
||||
|
||||
MTextPanel panel = getTextPanel();
|
||||
AttributeMap defaults = panel.getDefaultValues();
|
||||
|
||||
for (int i=0; i < fKeys.length; i++) {
|
||||
Object defaultV = defaults.get(fKeys[i]);
|
||||
|
||||
Object value = (fCharacter == CHARACTER)?
|
||||
panel.getCharacterStyleOverSelection(fKeys[i]) :
|
||||
panel.getParagraphStyleOverSelection(fKeys[i]);
|
||||
|
||||
if (!objectsAreEqual(defaultV, value)) {
|
||||
fItem.setState(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
fItem.setState(true);
|
||||
}
|
||||
|
||||
public boolean respondsToEventType(int type) {
|
||||
|
||||
return type == TextPanelEvent.SELECTION_STYLES_CHANGED;
|
||||
}
|
||||
|
||||
public final void textEventOccurred(TextPanelEvent event) {
|
||||
|
||||
setChecked();
|
||||
}
|
||||
}
|
906
icu4j/src/com/ibm/richtext/uiimpl/TabRulerImpl.java
Executable file
906
icu4j/src/com/ibm/richtext/uiimpl/TabRulerImpl.java
Executable file
@ -0,0 +1,906 @@
|
||||
/*
|
||||
* @(#)$RCSfile: TabRulerImpl.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:52:32 $
|
||||
*
|
||||
* (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.uiimpl;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Image;
|
||||
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.MouseMotionListener;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.InputEvent;
|
||||
|
||||
import com.ibm.textlayout.attributes.AttributeMap;
|
||||
import com.ibm.textlayout.attributes.TextAttribute;
|
||||
|
||||
import com.ibm.richtext.styledtext.MTabRuler;
|
||||
import com.ibm.richtext.styledtext.StandardTabRuler;
|
||||
import com.ibm.richtext.styledtext.TabStop;
|
||||
import com.ibm.richtext.styledtext.StyleModifier;
|
||||
|
||||
import com.ibm.richtext.textpanel.TextPanelListener;
|
||||
import com.ibm.richtext.textpanel.MTextPanel;
|
||||
import com.ibm.richtext.textpanel.TextPanel;
|
||||
import com.ibm.richtext.textpanel.TextPanelEvent;
|
||||
|
||||
/**
|
||||
* TabRuler is a Component which presents a user interface for
|
||||
* setting the leading margin, trailing margin, first line indent,
|
||||
* and tab types and positions.
|
||||
* <p>
|
||||
* TabRuler does not implement TextPanelListener directly; however,
|
||||
* it can receive updates from a MTextPanel. To have a TabRuler listen
|
||||
* to a panel, call <code>listenToPanel</code>. TabRuler responds to
|
||||
* user manipulation by modifying the paragraph styles on its MTextPanel
|
||||
* (if any).
|
||||
*/
|
||||
public final class TabRulerImpl implements MouseListener, MouseMotionListener
|
||||
{
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private static final class TabStopBuffer {
|
||||
public int fPosition;
|
||||
public byte fType;
|
||||
|
||||
TabStopBuffer(int position, byte type) {
|
||||
fPosition = position;
|
||||
fType = type;
|
||||
}
|
||||
|
||||
TabStopBuffer(TabStop tab) {
|
||||
this(tab.getPosition(), tab.getType());
|
||||
}
|
||||
|
||||
TabStop getTabStop() {
|
||||
return new TabStop(fPosition, fType);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class TabRulerModifier extends StyleModifier {
|
||||
|
||||
private TabStop fOldTab; // tab to remove
|
||||
private TabStop fNewTab; // tab to add
|
||||
private AttributeMap fPanelDefaults;
|
||||
|
||||
TabRulerModifier(TabStop oldTab,
|
||||
TabStop newTab,
|
||||
AttributeMap panelDefaults) {
|
||||
fOldTab = oldTab;
|
||||
fNewTab = newTab;
|
||||
fPanelDefaults = panelDefaults;
|
||||
}
|
||||
|
||||
public AttributeMap modifyStyle(AttributeMap oldStyle) {
|
||||
|
||||
MTabRuler oldRuler = (MTabRuler) getWithDefault(TextAttribute.TAB_RULER,
|
||||
oldStyle,
|
||||
fPanelDefaults);
|
||||
MTabRuler ruler = oldRuler;
|
||||
|
||||
if (fOldTab != null) {
|
||||
if (ruler.containsTab(fOldTab)) {
|
||||
ruler = ruler.removeTab(fOldTab.getPosition());
|
||||
}
|
||||
}
|
||||
if (fNewTab != null) {
|
||||
ruler = ruler.addTab(fNewTab);
|
||||
}
|
||||
|
||||
if (ruler != oldRuler) {
|
||||
return oldStyle.addAttribute(TextAttribute.TAB_RULER, ruler);
|
||||
}
|
||||
else {
|
||||
return oldStyle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final class ImageCache {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private Image fImage = null;
|
||||
private boolean fIsValid = false;
|
||||
private Component fComponent; // workaround for compiler bug,
|
||||
// should just be able to say Component.this
|
||||
// if this were not a static class
|
||||
|
||||
ImageCache(Component component) {
|
||||
|
||||
fComponent = component;
|
||||
}
|
||||
|
||||
Graphics getGraphics(int width, int height) {
|
||||
|
||||
if (width <= 0 || height <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Image image = fImage;
|
||||
if (image == null || image.getWidth(fComponent) < width
|
||||
|| image.getHeight(fComponent) < height) {
|
||||
image = fComponent.createImage(width, height);
|
||||
}
|
||||
Graphics g = image.getGraphics();
|
||||
fImage = image;
|
||||
return g;
|
||||
}
|
||||
|
||||
void drawImage(Graphics g, int x, int y, Color color) {
|
||||
|
||||
if (!fIsValid) {
|
||||
throw new Error("Drawing image when not valid");
|
||||
}
|
||||
g.drawImage(fImage, x, y, color, fComponent);
|
||||
}
|
||||
|
||||
boolean isValid() {
|
||||
|
||||
return fIsValid;
|
||||
}
|
||||
|
||||
void setValid(boolean isValid) {
|
||||
|
||||
fIsValid = isValid;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This class listens to a MTextPanel for changes which
|
||||
* affect a TabRuler's appearance, and updates the TabRuler
|
||||
* as necessary.
|
||||
* @see TabRuler
|
||||
* @see com.ibm.richtext.textpanel.MTextPanel
|
||||
*/
|
||||
private static final class Updater implements TextPanelListener {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private TabRulerImpl fTabRuler;
|
||||
private MTextPanel fTextPanel;
|
||||
|
||||
/**
|
||||
* Create a new TabRulerUpdater.
|
||||
* @param tabRuler the TabRuler to update when a change occurs
|
||||
* in the MTextPanel
|
||||
*/
|
||||
Updater(TabRulerImpl tabRuler) {
|
||||
|
||||
fTabRuler = tabRuler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove self as listener from previous MTextPanel,
|
||||
* set current MTextPanel and listen to it (if not null).
|
||||
*/
|
||||
void setTextPanel(MTextPanel textPanel) {
|
||||
|
||||
if (fTextPanel != null) {
|
||||
fTextPanel.removeListener(this);
|
||||
}
|
||||
|
||||
fTextPanel = textPanel;
|
||||
|
||||
if (fTextPanel != null) {
|
||||
fTextPanel.addListener(this);
|
||||
setAll();
|
||||
}
|
||||
}
|
||||
|
||||
private void setAll() {
|
||||
|
||||
int offset = fTextPanel.getSelectionStart();
|
||||
boolean leftToRight = fTextPanel.paragraphIsLeftToRight(offset);
|
||||
AttributeMap style = fTextPanel.getText().paragraphStyleAt(offset);
|
||||
fTabRuler.set(style, false);
|
||||
fTabRuler.setFormatWidth(fTextPanel.getFormatWidth(), false);
|
||||
fTabRuler.setLeftToRight(leftToRight, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* TextPanelListener method. This class responds to text
|
||||
* changes by updating its TabRuler.
|
||||
*/
|
||||
public void textEventOccurred(TextPanelEvent event) {
|
||||
|
||||
int changeCode = event.getID();
|
||||
|
||||
if (changeCode == event.SELECTION_STYLES_CHANGED ||
|
||||
changeCode == event.TEXT_CHANGED) {
|
||||
|
||||
int offset = fTextPanel.getSelectionStart();
|
||||
AttributeMap style = fTextPanel.getText().paragraphStyleAt(offset);
|
||||
boolean leftToRight = fTextPanel.paragraphIsLeftToRight(offset);
|
||||
fTabRuler.set(style, false);
|
||||
fTabRuler.setLeftToRight(leftToRight, true);
|
||||
}
|
||||
else if (changeCode == event.FORMAT_WIDTH_CHANGED) {
|
||||
|
||||
fTabRuler.setFormatWidth(fTextPanel.getFormatWidth(), true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TextPanelListener method.
|
||||
*/
|
||||
public boolean respondsToEventType(int type) {
|
||||
|
||||
return type == TextPanelEvent.SELECTION_STYLES_CHANGED ||
|
||||
type == TextPanelEvent.TEXT_CHANGED ||
|
||||
type == TextPanelEvent.FORMAT_WIDTH_CHANGED;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The default background color for TabRulers.
|
||||
* @see #setBackColor
|
||||
*/
|
||||
public static final Color DEFAULT_BACK_COLOR = Color.lightGray;
|
||||
|
||||
private static final int kTrackNone = 0;
|
||||
private static final int kTrackTab = 1;
|
||||
private static final int kTrackLM = 2;
|
||||
private static final int kTrackFLI = 3;
|
||||
private static final int kTrackTM = 4;
|
||||
|
||||
private Component fHost;
|
||||
private MTabRuler fRuler;
|
||||
private int fLeadingMargin;
|
||||
private int fFirstLineIndent;
|
||||
private int fFormatWidth;
|
||||
private int fTrailingMarginPosition; // opposite of actual trailing margin
|
||||
private boolean fLeftToRight;
|
||||
private int fBaseline;
|
||||
private int fOrigin;
|
||||
private Color fBackColor = DEFAULT_BACK_COLOR;
|
||||
|
||||
private int fTrackItem; // 0 - none, 1 - tab, 2 - lm, 3 - fli, 4 - tm
|
||||
private TabStopBuffer fTrackTab;
|
||||
private TabStop fOldTab;
|
||||
private int fTrackDelta;
|
||||
private boolean fTrackVisible;
|
||||
private Updater fUpdater;
|
||||
private MTextPanel fTextPanel = null;
|
||||
|
||||
private ImageCache fImageCache;
|
||||
|
||||
/**
|
||||
* 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 TabRulerImpl(int baseline,
|
||||
int origin,
|
||||
MTextPanel textPanel,
|
||||
Component host) {
|
||||
|
||||
fHost = host;
|
||||
fImageCache = new ImageCache(host);
|
||||
fUpdater = new Updater(this);
|
||||
fBaseline = baseline;
|
||||
fOrigin = origin;
|
||||
host.addMouseListener(this);
|
||||
host.addMouseMotionListener(this);
|
||||
if (textPanel != null) {
|
||||
listenToTextPanel(textPanel);
|
||||
}
|
||||
else {
|
||||
fRuler = new StandardTabRuler();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
|
||||
fTextPanel = textPanel;
|
||||
fUpdater.setTextPanel(textPanel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the background color of this TabRuler.
|
||||
* @return the background color of this TabRuler
|
||||
*/
|
||||
public Color getBackColor() {
|
||||
|
||||
return fBackColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the background color of this TabRuler.
|
||||
* @param backColor the new background color of this TabRuler
|
||||
*/
|
||||
public void setBackColor(Color backColor) {
|
||||
|
||||
if (!backColor.equals(fBackColor)) {
|
||||
fBackColor = backColor;
|
||||
Graphics g = fHost.getGraphics();
|
||||
if (g != null) {
|
||||
paint(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Object getWithDefault(Object key,
|
||||
AttributeMap style,
|
||||
AttributeMap defaults) {
|
||||
Object value = style.get(key);
|
||||
if (value == null) {
|
||||
value = defaults.get(key);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private static float getFloatWithDefault(Object key,
|
||||
AttributeMap style,
|
||||
AttributeMap defaults) {
|
||||
Object value = getWithDefault(key, style, defaults);
|
||||
return ((Float)value).floatValue();
|
||||
}
|
||||
|
||||
private void setLeftToRight(boolean leftToRight, boolean update) {
|
||||
|
||||
if (fLeftToRight != leftToRight) {
|
||||
|
||||
fLeftToRight = leftToRight;
|
||||
redrawSelf(update);
|
||||
}
|
||||
}
|
||||
|
||||
private void setFormatWidth(int formatWidth, boolean update) {
|
||||
|
||||
if (fFormatWidth != formatWidth) {
|
||||
|
||||
fTrailingMarginPosition += (formatWidth - fFormatWidth);
|
||||
fFormatWidth = formatWidth;
|
||||
redrawSelf(update);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set TabRuler from values in paragraphStyle. Only TabRulerUpdater
|
||||
* should call this method.
|
||||
* @param paragraphStyle the paragraph style which the TabRuler will
|
||||
* reflect
|
||||
*/
|
||||
private void set(AttributeMap paragraphStyle, boolean update) {
|
||||
|
||||
AttributeMap panelDefaults;
|
||||
|
||||
if (fTextPanel==null) {
|
||||
panelDefaults = TextPanel.getDefaultSettings().getDefaultValues();
|
||||
}
|
||||
else {
|
||||
panelDefaults = fTextPanel.getDefaultValues();
|
||||
}
|
||||
|
||||
int leadingMargin = (int) getFloatWithDefault(TextAttribute.LEADING_MARGIN,
|
||||
paragraphStyle,
|
||||
panelDefaults);
|
||||
int firstLineIndent = (int) getFloatWithDefault(TextAttribute.FIRST_LINE_INDENT,
|
||||
paragraphStyle,
|
||||
panelDefaults);
|
||||
int trailingMargin = (int) getFloatWithDefault(TextAttribute.TRAILING_MARGIN,
|
||||
paragraphStyle,
|
||||
panelDefaults);
|
||||
|
||||
MTabRuler ruler = (MTabRuler) getWithDefault(TextAttribute.TAB_RULER,
|
||||
paragraphStyle,
|
||||
panelDefaults);
|
||||
|
||||
int ourFli = leadingMargin + firstLineIndent;
|
||||
int ourTmp = fFormatWidth - trailingMargin;
|
||||
|
||||
if (leadingMargin == fLeadingMargin &&
|
||||
fFirstLineIndent == ourFli &&
|
||||
fTrailingMarginPosition == ourTmp &&
|
||||
ruler.equals(fRuler)) {
|
||||
return;
|
||||
}
|
||||
|
||||
fLeadingMargin = leadingMargin;
|
||||
fFirstLineIndent = ourFli;
|
||||
fTrailingMarginPosition = ourTmp;
|
||||
fRuler = ruler;
|
||||
|
||||
redrawSelf(update);
|
||||
}
|
||||
|
||||
private void redrawSelf(boolean drawNow) {
|
||||
|
||||
fImageCache.setValid(false);
|
||||
|
||||
Graphics g = fHost.getGraphics();
|
||||
if (g != null)
|
||||
paint(g);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return debugging info.
|
||||
*/
|
||||
public String toString() {
|
||||
|
||||
return "TabRuler{fLeadingMargin="+fLeadingMargin+
|
||||
"}{fFirstLineIndent="+fFirstLineIndent+
|
||||
"}{fFormatWidth="+fFormatWidth+
|
||||
"}{fTrailingMarginPosition="+fTrailingMarginPosition+
|
||||
"}{fRuler="+fRuler+
|
||||
"}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the MTabRuler represented by this TabRuler.
|
||||
* @return the MTabRuler represented by this TabRuler
|
||||
*/
|
||||
public MTabRuler getRuler()
|
||||
{
|
||||
return fRuler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the leading margin of this TabRuler.
|
||||
* @return the leading margin of this TabRuler
|
||||
*/
|
||||
public int getLeadingMargin()
|
||||
{
|
||||
return fLeadingMargin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the first line indent of this TabRuler.
|
||||
* @return the first line indent of this TabRuler
|
||||
*/
|
||||
public int getFirstLineIndent()
|
||||
{
|
||||
return fFirstLineIndent - fLeadingMargin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the trailing margin of this TabRuler.
|
||||
* @return the trailing margin of this TabRuler
|
||||
*/
|
||||
public final int getTrailingMargin()
|
||||
{
|
||||
return fFormatWidth - fTrailingMarginPosition;
|
||||
}
|
||||
|
||||
private int visualToRulerPos(int visPos) {
|
||||
|
||||
if (fLeftToRight) {
|
||||
return visPos - fOrigin;
|
||||
}
|
||||
else {
|
||||
return fOrigin + fFormatWidth - visPos;
|
||||
}
|
||||
}
|
||||
|
||||
private int rulerToVisualPos(int rulerPos) {
|
||||
|
||||
if (fLeftToRight) {
|
||||
return fOrigin + rulerPos;
|
||||
}
|
||||
else {
|
||||
return fOrigin + fFormatWidth - rulerPos;
|
||||
}
|
||||
}
|
||||
|
||||
private int dirMult() {
|
||||
|
||||
return fLeftToRight? 1 : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tabPosition the logical (ruler) position of the tab
|
||||
*/
|
||||
private void drawTab(Graphics g, int tabPosition, byte tabType, int tabTop, int tabBottom)
|
||||
{
|
||||
int pos = rulerToVisualPos(tabPosition);
|
||||
int wid = 0;
|
||||
switch (tabType) {
|
||||
case TabStop.kLeading: wid = 3; break;
|
||||
case TabStop.kCenter: wid = 0; break;
|
||||
case TabStop.kTrailing: wid = -3; break;
|
||||
case TabStop.kDecimal: wid = 0; break;
|
||||
default: break;
|
||||
}
|
||||
wid *= dirMult();
|
||||
|
||||
if (tabType != TabStop.kAuto) {
|
||||
g.drawLine(pos, tabTop, pos, tabBottom);
|
||||
if (wid != 0)
|
||||
g.drawLine(pos, tabBottom, pos + wid, tabBottom);
|
||||
}
|
||||
g.drawLine(pos-2, tabTop+2, pos, tabTop);
|
||||
g.drawLine(pos, tabTop, pos+2, tabTop+2);
|
||||
if (tabType == TabStop.kDecimal) {
|
||||
g.drawLine(pos + 3, tabBottom, pos + 4, tabBottom);
|
||||
}
|
||||
}
|
||||
|
||||
private void drawLM(Graphics g)
|
||||
{
|
||||
int pos = rulerToVisualPos(fLeadingMargin);
|
||||
int[] xpts = { pos, pos, pos + (4*dirMult()), pos };
|
||||
int[] ypts = { fBaseline + 12, fBaseline + 7, fBaseline + 7, fBaseline + 12 };
|
||||
g.fillPolygon(xpts, ypts, 3);
|
||||
g.drawPolygon(xpts, ypts, 4);
|
||||
}
|
||||
|
||||
private void drawFLI(Graphics g)
|
||||
{
|
||||
int pos = rulerToVisualPos(fFirstLineIndent);
|
||||
int[] xpts = { pos, pos, pos + (4*dirMult()), pos };
|
||||
int[] ypts = { fBaseline, fBaseline + 5, fBaseline + 5, fBaseline };
|
||||
g.fillPolygon(xpts, ypts, 3);
|
||||
g.drawPolygon(xpts, ypts, 4);
|
||||
}
|
||||
|
||||
private void drawRM(Graphics g)
|
||||
{
|
||||
int pos = rulerToVisualPos(fTrailingMarginPosition);
|
||||
int[] xpts = { pos, pos, pos - (6*dirMult()), pos };
|
||||
int[] ypts = { fBaseline, fBaseline + 12, fBaseline + 6, fBaseline };
|
||||
g.fillPolygon(xpts, ypts, 3);
|
||||
g.drawPolygon(xpts, ypts, 4);
|
||||
}
|
||||
|
||||
private static int alignInt(int value) {
|
||||
|
||||
return (int)((int)(value / 4.5) * 4.5);
|
||||
}
|
||||
|
||||
private static final int[] fgLengths = { 10, 2, 4, 2, 6, 2, 4, 2 };
|
||||
|
||||
/**
|
||||
* Component method override.
|
||||
*/
|
||||
public void paint(Graphics g)
|
||||
{
|
||||
Dimension size = fHost.getSize();
|
||||
|
||||
int width = size.width;
|
||||
int baseline = fBaseline;
|
||||
int baseline2 = baseline + 2;
|
||||
int baseline10 = baseline + 10;
|
||||
int baseline12 = baseline + 12;
|
||||
|
||||
if (!fImageCache.isValid()) {
|
||||
|
||||
Graphics gCache = fImageCache.getGraphics(width, baseline12 + 1);
|
||||
if (gCache == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// set background color
|
||||
|
||||
gCache.setColor(fBackColor);
|
||||
gCache.setPaintMode();
|
||||
gCache.fillRect(0, 0, width, baseline12 + 1);
|
||||
|
||||
// paint ticks
|
||||
|
||||
gCache.setColor(Color.black);
|
||||
gCache.drawLine(0, 0, width, 0);
|
||||
gCache.drawLine(0, baseline, width, baseline);
|
||||
|
||||
int[] lengths = fgLengths;
|
||||
|
||||
int index = 0;
|
||||
int inchnum = 0;
|
||||
FontMetrics fm = null;
|
||||
if (!fLeftToRight) {
|
||||
fm = gCache.getFontMetrics();
|
||||
}
|
||||
|
||||
for (int i = 0; i < fFormatWidth; i += 9) {
|
||||
int len = lengths[index];
|
||||
int pos = rulerToVisualPos(i);
|
||||
gCache.drawLine(pos, baseline, pos, baseline - len);
|
||||
|
||||
if (index == 0) {
|
||||
String str = Integer.toString(inchnum++);
|
||||
int drawX;
|
||||
if (fLeftToRight) {
|
||||
drawX = pos + 2;
|
||||
}
|
||||
else {
|
||||
drawX = pos - fm.stringWidth(str) - 2;
|
||||
}
|
||||
|
||||
gCache.drawString(str, drawX, baseline - 2);
|
||||
}
|
||||
|
||||
if (++index == lengths.length)
|
||||
index = 0;
|
||||
}
|
||||
|
||||
// paint tabs
|
||||
TabStop tab = fRuler.firstTab();
|
||||
while (tab != null && tab.getPosition() < fTrailingMarginPosition) {
|
||||
boolean dodraw = true;
|
||||
if (tab.getType() == TabStop.kAuto) {
|
||||
if (tab.getPosition() <= Math.max(fLeadingMargin, fFirstLineIndent))
|
||||
dodraw = false;
|
||||
else if (tab.getPosition() >= fTrailingMarginPosition)
|
||||
dodraw = false;
|
||||
}
|
||||
|
||||
if (dodraw)
|
||||
drawTab(gCache, tab.getPosition(), tab.getType(), baseline2, baseline10);
|
||||
|
||||
tab = fRuler.nextTab(tab.getPosition());
|
||||
}
|
||||
|
||||
gCache.drawLine(0, baseline12, width, baseline12);
|
||||
|
||||
// paint others except for tracked item
|
||||
if (fTrackItem != kTrackLM) drawLM(gCache);
|
||||
if (fTrackItem != kTrackTM) drawRM(gCache);
|
||||
if (fTrackItem != kTrackFLI && fTrackItem != kTrackLM) drawFLI(gCache);
|
||||
fImageCache.setValid(true);
|
||||
}
|
||||
|
||||
fImageCache.drawImage(g, 0, 0, Color.lightGray);
|
||||
|
||||
switch (fTrackItem) {
|
||||
case kTrackTab: if (fTrackVisible) drawTab(g, fTrackTab.fPosition, fTrackTab.fType, baseline2, baseline10); break;
|
||||
case kTrackLM: drawLM(g); drawFLI(g); break;
|
||||
case kTrackTM: drawRM(g); break;
|
||||
case kTrackFLI: drawFLI(g); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* MouseListener method.
|
||||
*/
|
||||
public void mouseClicked(MouseEvent e) {}
|
||||
/**
|
||||
* MouseListener method.
|
||||
*/
|
||||
public void mouseEntered(MouseEvent e) {}
|
||||
/**
|
||||
* MouseListener method.
|
||||
*/
|
||||
public void mouseExited(MouseEvent e) {}
|
||||
|
||||
/**
|
||||
* MouseListener method.
|
||||
*/
|
||||
public void mousePressed(MouseEvent e)
|
||||
{
|
||||
// find out if we hit a tabstop
|
||||
int x = visualToRulerPos(e.getX());
|
||||
int y = e.getY();
|
||||
|
||||
if (y > fBaseline && y < fBaseline + 12) {
|
||||
if (y >= fBaseline + 7 && x >= fLeadingMargin - 3 && x <= fLeadingMargin + 3) {
|
||||
fTrackItem = kTrackLM;
|
||||
fTrackDelta = fLeadingMargin - x;
|
||||
} else if (y < fBaseline + 7 && x >= fFirstLineIndent - 3 && x <= fFirstLineIndent + 3) {
|
||||
fTrackItem = kTrackFLI;
|
||||
fTrackDelta = fFirstLineIndent - x;
|
||||
} else if (x >= fTrailingMarginPosition - 3 && x <= fTrailingMarginPosition + 3) {
|
||||
fTrackItem = kTrackTM;
|
||||
fTrackDelta = fTrailingMarginPosition - x;
|
||||
} else if (e.isControlDown()) {
|
||||
fTrackItem = kTrackTab;
|
||||
fTrackTab = new TabStopBuffer(alignInt(x), TabStop.kLeading);
|
||||
fTrackDelta = fTrackTab.fPosition - x;
|
||||
fTrackVisible = true;
|
||||
} else {
|
||||
TabStop tab = fRuler.firstTab();
|
||||
while (tab.getType() != TabStop.kAuto) {
|
||||
if (x < tab.getPosition() - 3)
|
||||
break;
|
||||
if (x < tab.getPosition() + 3) {
|
||||
fOldTab = tab;
|
||||
fTrackTab = new TabStopBuffer(tab);
|
||||
fRuler = fRuler.removeTab(fOldTab.getPosition());
|
||||
|
||||
if (e.getClickCount() > 1) {
|
||||
switch (fTrackTab.fType) {
|
||||
case TabStop.kLeading: fTrackTab.fType = TabStop.kCenter; break;
|
||||
case TabStop.kCenter: fTrackTab.fType = TabStop.kTrailing; break;
|
||||
case TabStop.kTrailing: fTrackTab.fType = TabStop.kDecimal; break;
|
||||
case TabStop.kDecimal: fTrackTab.fType = TabStop.kLeading; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
fTrackItem = kTrackTab;
|
||||
fTrackDelta = tab.getPosition() - x;
|
||||
fTrackVisible = true;
|
||||
break;
|
||||
}
|
||||
|
||||
tab = fRuler.nextTab(tab.getPosition());
|
||||
}
|
||||
}
|
||||
|
||||
if (fTrackItem != kTrackNone) {
|
||||
fImageCache.setValid(false);
|
||||
paint(fHost.getGraphics());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* MouseListener method.
|
||||
*/
|
||||
public void mouseDragged(MouseEvent e)
|
||||
{
|
||||
int x = visualToRulerPos(e.getX());
|
||||
int y = e.getY();
|
||||
|
||||
if (fTrackItem != kTrackNone) {
|
||||
boolean repaint = false;
|
||||
boolean inrange = y > fBaseline && y < fBaseline + 12;
|
||||
boolean inbigrange = y > 0 && y < fHost.getSize().height + 20;
|
||||
int newpos = alignInt(x + fTrackDelta);
|
||||
if (newpos < 0)
|
||||
newpos = 0;
|
||||
|
||||
switch (fTrackItem) {
|
||||
case kTrackTab: {
|
||||
if (inrange) {
|
||||
repaint = !fTrackVisible;
|
||||
fTrackVisible = true;
|
||||
if (newpos != fTrackTab.fPosition) {
|
||||
fTrackTab.fPosition = newpos;
|
||||
repaint = true;
|
||||
}
|
||||
} else if (fTrackVisible) {
|
||||
fTrackVisible = false;
|
||||
repaint = true;
|
||||
}
|
||||
} break;
|
||||
|
||||
/* It would be nice to optionally track the margin 'independently' of the first line indent.
|
||||
Unfortunately this makes for more work when we have multiple paragraph styles selected.
|
||||
Since internally the first line indent is relative to the margin, moving the margin
|
||||
independently so that all affected paragraphs share the same margin but retain first
|
||||
line indents in the 'same' positions means that I need to also adjust the first line
|
||||
indents in each paragraph by some delta. I'm not ready to do that yet. */
|
||||
|
||||
case kTrackLM: {
|
||||
if (inbigrange && newpos != fLeadingMargin) {
|
||||
fFirstLineIndent += newpos - fLeadingMargin;
|
||||
fLeadingMargin = newpos;
|
||||
repaint = true;
|
||||
}
|
||||
} break;
|
||||
|
||||
case kTrackFLI: {
|
||||
if (inbigrange && newpos != fFirstLineIndent) {
|
||||
fFirstLineIndent = newpos;
|
||||
repaint = true;
|
||||
}
|
||||
} break;
|
||||
|
||||
case kTrackTM: {
|
||||
if (inbigrange && newpos != fTrailingMarginPosition) {
|
||||
fTrailingMarginPosition = newpos;
|
||||
repaint = true;
|
||||
}
|
||||
} break;
|
||||
}
|
||||
|
||||
|
||||
if (repaint)
|
||||
paint(fHost.getGraphics());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* MouseListener method.
|
||||
*/
|
||||
public void mouseReleased(MouseEvent e)
|
||||
{
|
||||
if (fTrackItem != kTrackNone) {
|
||||
if (fTrackItem == kTrackTab && fTrackVisible) {
|
||||
fRuler = fRuler.addTab(fTrackTab.getTabStop());
|
||||
} else {
|
||||
fTrackTab = null;
|
||||
}
|
||||
|
||||
notify(fTrackItem);
|
||||
|
||||
fTrackItem = kTrackNone;
|
||||
fTrackTab = null;
|
||||
fOldTab = null;
|
||||
|
||||
fImageCache.setValid(false);
|
||||
paint(fHost.getGraphics());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* MouseListener method.
|
||||
*/
|
||||
public void mouseMoved(MouseEvent e) {}
|
||||
|
||||
private void notify(int change)
|
||||
{
|
||||
if (fTextPanel != null) {
|
||||
|
||||
StyleModifier modifier;
|
||||
|
||||
if (change == kTrackTab) {
|
||||
TabStop newTab = fTrackTab==null? null : fTrackTab.getTabStop();
|
||||
modifier = new TabRulerModifier(fOldTab, newTab, fTextPanel.getDefaultValues());
|
||||
}
|
||||
else {
|
||||
Object key;
|
||||
Object value;
|
||||
|
||||
switch(change) {
|
||||
case kTrackLM:
|
||||
key = TextAttribute.LEADING_MARGIN;
|
||||
value = new Float(getLeadingMargin());
|
||||
break;
|
||||
|
||||
case kTrackTM:
|
||||
key = TextAttribute.TRAILING_MARGIN;
|
||||
value = new Float(getTrailingMargin());
|
||||
break;
|
||||
|
||||
case kTrackFLI:
|
||||
key = TextAttribute.FIRST_LINE_INDENT;
|
||||
value = new Float(getFirstLineIndent());
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Error("Invalid change code.");
|
||||
}
|
||||
|
||||
modifier = StyleModifier.createAddModifier(key, value);
|
||||
}
|
||||
|
||||
fTextPanel.modifyParagraphStyleOnSelection(modifier);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Component override.
|
||||
*/
|
||||
public Dimension getMinimumSize()
|
||||
{
|
||||
return new Dimension(100, fBaseline + 13);
|
||||
}
|
||||
|
||||
/**
|
||||
* Component override.
|
||||
*/
|
||||
public Dimension getPreferredSize()
|
||||
{
|
||||
return getMinimumSize();
|
||||
}
|
||||
}
|
230
icu4j/src/com/ibm/richtext/uiimpl/resources/FrameResources.java
Executable file
230
icu4j/src/com/ibm/richtext/uiimpl/resources/FrameResources.java
Executable file
@ -0,0 +1,230 @@
|
||||
/*
|
||||
* @(#)$RCSfile: FrameResources.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:52:46 $
|
||||
*
|
||||
* (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.uiimpl.resources;
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
public final class FrameResources extends ListResourceBundle {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
/*
|
||||
* These Strings are keys to other String resources.
|
||||
*/
|
||||
// Menu names
|
||||
public static final String EDIT = "Edit";
|
||||
public static final String SIZE = "Size";
|
||||
public static final String FONT = "Font";
|
||||
public static final String STYLE = "Style";
|
||||
public static final String FLUSH = "Flush";
|
||||
public static final String KEYMAP = "Keymap";
|
||||
public static final String ABOUT_MENU = "About";
|
||||
public static final String BIDI = "Bidi";
|
||||
|
||||
// Buttons
|
||||
public static final String OK = "OK";
|
||||
public static final String CANCEL = "Cancel";
|
||||
|
||||
// Colors
|
||||
public static final String BLACK = "Black";
|
||||
public static final String WHITE = "White";
|
||||
public static final String GREEN = "Green";
|
||||
public static final String BLUE = "Blue";
|
||||
public static final String CYAN = "Cyan";
|
||||
public static final String GRAY = "Gray";
|
||||
public static final String DARK_GRAY = "Dark Gray";
|
||||
public static final String LIGHT_GRAY = "Light Gray";
|
||||
public static final String MAGENTA = "Magenta";
|
||||
public static final String ORANGE = "Orange";
|
||||
public static final String PINK = "Pink";
|
||||
public static final String RED = "Red";
|
||||
public static final String YELLOW = "Yellow";
|
||||
public static final String NONE = "None";
|
||||
|
||||
// Dialog titles and messages
|
||||
public static final String SET_SIZE_TITLE = "Set Font Size";
|
||||
public static final String SET_SIZE_LABEL = "Font Size:";
|
||||
|
||||
public static final String SET_SUPERSCRIPT_TITLE = "Set Superscript";
|
||||
public static final String SET_SUPERSCRIPT_LABEL = "Superscript:";
|
||||
public static final String SET_SUBSCRIPT_TITLE = "Set Subscript";
|
||||
public static final String SET_SUBSCRIPT_LABEL = "Subscript:";
|
||||
public static final String SET_FOREGROUND_TITLE = "Set Foreground";
|
||||
public static final String SET_FOREGROUND_LABEL = "Foreground:";
|
||||
public static final String SET_BACKGROUND_TITLE = "Set Background";
|
||||
public static final String SET_BACKGROUND_LABEL = "Background:";
|
||||
public static final String SET_FONT_TITLE = "Set Font";
|
||||
public static final String SET_FONT_LABEL = "Font:";
|
||||
|
||||
public static final String ABOUT_TITLE = "About the RichEdit Control";
|
||||
|
||||
// This is the only String which is not its own value:
|
||||
public static final String ABOUT_TEXT = "About text";
|
||||
private static final String ACTUAL_ABOUT_TEXT =
|
||||
"Copyright © Taligent, Inc. 1996 All rights reserved.\n" +
|
||||
"Copyright © IBM Corp. 1996-1998\n\n" +
|
||||
"John Raley\n" +
|
||||
"Stephen F. Booth\n" +
|
||||
"Doug Felt\n" +
|
||||
"John Fitzpatrick\n" +
|
||||
"Rich Gillam";
|
||||
/*
|
||||
* The following Strings are keys to MenuData resources. They
|
||||
* also double as the default menu label text.
|
||||
*/
|
||||
// Edit menu
|
||||
public static final String UNDO = "Undo";
|
||||
public static final String REDO = "Redo";
|
||||
public static final String CUT = "Cut";
|
||||
public static final String COPY = "Copy";
|
||||
public static final String PASTE = "Paste";
|
||||
public static final String CLEAR = "Clear";
|
||||
public static final String SELECT_ALL = "Select All";
|
||||
|
||||
// Flush menu
|
||||
public static final String LEADING = "Leading";
|
||||
public static final String TRAILING = "Trailing";
|
||||
public static final String CENTER = "Center";
|
||||
public static final String JUSTIFIED = "Justified";
|
||||
|
||||
// About menu
|
||||
public static final String ABOUT_ITEM = "About...";
|
||||
|
||||
// Keymap menu
|
||||
public static final String DEFAULT = "Default";
|
||||
public static final String ARABIC = "Arabic";
|
||||
public static final String HEBREW = "Hebrew";
|
||||
public static final String ISRAEL_NIKUD = "Israel Nikud";
|
||||
public static final String THAI_KETMANEE = "Thai Ketmanee";
|
||||
|
||||
// Style menu
|
||||
public static final String PLAIN = "Plain";
|
||||
public static final String BOLD = "Bold";
|
||||
public static final String ITALIC = "Italic";
|
||||
public static final String UNDERLINE = "Underline";
|
||||
public static final String STRIKETHROUGH = "Strikethrough";
|
||||
public static final String SUPERSCRIPT = "Superscript";
|
||||
public static final String SUBSCRIPT = "Subscript";
|
||||
public static final String SUPERSCRIPT_DIALOG = "Superscript...";
|
||||
public static final String SUBSCRIPT_DIALOG = "Subscript...";
|
||||
public static final String FORECOLOR_DIALOG = "Forecolor...";
|
||||
public static final String BACKCOLOR_DIALOG = "Backcolor...";
|
||||
public static final String FONT_DIALOG = "Font...";
|
||||
|
||||
|
||||
// Size menu
|
||||
public static final String OTHER_DIALOG = "Other...";
|
||||
|
||||
// Bidi menu
|
||||
public static final String DEFAULT_DIRECTION = "Default Paragraph Direction";
|
||||
public static final String LTR_DIRECTION = "Left-to-right Paragraph Direction";
|
||||
public static final String RTL_DIRECTION = "Right-to-left Paragraph Direction";
|
||||
|
||||
private static Object[] makeMenuData(String name,
|
||||
char shortCutChar,
|
||||
int shortCutKey) {
|
||||
|
||||
return new Object[] { name, new MenuData(name, shortCutChar, shortCutKey) };
|
||||
}
|
||||
|
||||
private static Object[] makeMenuData(String name) {
|
||||
|
||||
return new Object[] { name, new MenuData(name) };
|
||||
}
|
||||
|
||||
private static Object[] duplicate(Object obj) {
|
||||
|
||||
return new Object[] { obj, obj };
|
||||
}
|
||||
|
||||
protected Object[][] getContents() {
|
||||
|
||||
return new Object[][] {
|
||||
makeMenuData(UNDO, 'z', KeyEvent.VK_Z),
|
||||
makeMenuData(REDO, 'r', KeyEvent.VK_R),
|
||||
makeMenuData(CUT, 'x', KeyEvent.VK_X),
|
||||
makeMenuData(COPY, 'c', KeyEvent.VK_C),
|
||||
makeMenuData(PASTE, 'v', KeyEvent.VK_V),
|
||||
makeMenuData(CLEAR),
|
||||
makeMenuData(SELECT_ALL),
|
||||
makeMenuData(LEADING),
|
||||
makeMenuData(CENTER),
|
||||
makeMenuData(TRAILING),
|
||||
makeMenuData(JUSTIFIED),
|
||||
makeMenuData(ABOUT_ITEM),
|
||||
makeMenuData(DEFAULT),
|
||||
makeMenuData(HEBREW),
|
||||
makeMenuData(ARABIC),
|
||||
makeMenuData(ISRAEL_NIKUD),
|
||||
makeMenuData(THAI_KETMANEE),
|
||||
makeMenuData(PLAIN),
|
||||
makeMenuData(BOLD, 'b', KeyEvent.VK_B),
|
||||
makeMenuData(ITALIC, 'i', KeyEvent.VK_I), // why doesn't this work in Swing?
|
||||
// this is a Tab in AWT!!!
|
||||
makeMenuData(UNDERLINE, 'u', KeyEvent.VK_U),
|
||||
makeMenuData(STRIKETHROUGH),
|
||||
makeMenuData(SUPERSCRIPT),
|
||||
makeMenuData(SUBSCRIPT),
|
||||
makeMenuData(SUPERSCRIPT_DIALOG),
|
||||
makeMenuData(SUBSCRIPT_DIALOG),
|
||||
makeMenuData(FORECOLOR_DIALOG),
|
||||
makeMenuData(BACKCOLOR_DIALOG),
|
||||
makeMenuData(FONT_DIALOG),
|
||||
makeMenuData(OTHER_DIALOG),
|
||||
makeMenuData(DEFAULT_DIRECTION),
|
||||
makeMenuData(LTR_DIRECTION),
|
||||
makeMenuData(RTL_DIRECTION),
|
||||
duplicate(OK),
|
||||
duplicate(CANCEL),
|
||||
duplicate(BLACK),
|
||||
duplicate(WHITE),
|
||||
duplicate(GREEN),
|
||||
duplicate(BLUE),
|
||||
duplicate(CYAN),
|
||||
duplicate(GRAY),
|
||||
duplicate(DARK_GRAY),
|
||||
duplicate(LIGHT_GRAY),
|
||||
duplicate(MAGENTA),
|
||||
duplicate(ORANGE),
|
||||
duplicate(PINK),
|
||||
duplicate(RED),
|
||||
duplicate(YELLOW),
|
||||
duplicate(NONE),
|
||||
duplicate(SET_SIZE_TITLE),
|
||||
duplicate(SET_SIZE_LABEL),
|
||||
duplicate(SET_SUPERSCRIPT_TITLE),
|
||||
duplicate(SET_SUPERSCRIPT_LABEL),
|
||||
duplicate(SET_SUBSCRIPT_TITLE),
|
||||
duplicate(SET_SUBSCRIPT_LABEL),
|
||||
duplicate(SET_FOREGROUND_TITLE),
|
||||
duplicate(SET_FOREGROUND_LABEL),
|
||||
duplicate(SET_BACKGROUND_TITLE),
|
||||
duplicate(SET_BACKGROUND_LABEL),
|
||||
duplicate(SET_FONT_TITLE),
|
||||
duplicate(SET_FONT_LABEL),
|
||||
duplicate(EDIT),
|
||||
duplicate(SIZE),
|
||||
duplicate(FONT),
|
||||
duplicate(STYLE),
|
||||
duplicate(FLUSH),
|
||||
duplicate(KEYMAP),
|
||||
duplicate(BIDI),
|
||||
duplicate(ABOUT_MENU),
|
||||
duplicate(ABOUT_TITLE),
|
||||
{ ABOUT_TEXT, ACTUAL_ABOUT_TEXT }
|
||||
};
|
||||
}
|
||||
}
|
68
icu4j/src/com/ibm/richtext/uiimpl/resources/MenuData.java
Executable file
68
icu4j/src/com/ibm/richtext/uiimpl/resources/MenuData.java
Executable file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* @(#)$RCSfile: MenuData.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:52:46 $
|
||||
*
|
||||
* (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.uiimpl.resources;
|
||||
|
||||
/**
|
||||
* This class is used in resources to represent a Menu. It is
|
||||
* just a name and an optional shortcut key.
|
||||
*/
|
||||
public final class MenuData {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private String fName;
|
||||
private boolean fHasShortcut;
|
||||
private char fShortcut;
|
||||
private int fKeyCode;
|
||||
|
||||
public MenuData(String name) {
|
||||
|
||||
fName = name;
|
||||
fHasShortcut = false;
|
||||
}
|
||||
|
||||
public MenuData(String name, char ch, int keyCode) {
|
||||
|
||||
fName = name;
|
||||
fHasShortcut = true;
|
||||
fShortcut = ch;
|
||||
fKeyCode = keyCode;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
||||
return fName;
|
||||
}
|
||||
|
||||
public char getShortcutChar() {
|
||||
|
||||
if (!fHasShortcut) {
|
||||
throw new Error("Menu doesn't have shortcut");
|
||||
}
|
||||
return fShortcut;
|
||||
}
|
||||
|
||||
public int getShortcutKeyCode() {
|
||||
if (!fHasShortcut) {
|
||||
throw new Error("Menu doesn't have shortcut");
|
||||
}
|
||||
return fKeyCode;
|
||||
}
|
||||
|
||||
public boolean hasShortcut() {
|
||||
|
||||
return fHasShortcut;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user