home *** CD-ROM | disk | FTP | other *** search
- package netscape.application;
-
- import netscape.util.ClassInfo;
- import netscape.util.CodingException;
- import netscape.util.Decoder;
- import netscape.util.Encoder;
-
- public class Popup extends View implements Target, FormElement {
- ListView popupList;
- Window popupWindow;
- ContainerView container;
- ListItem selectedItem;
- ListItem wasSelectedItem;
- Target target;
- Image image;
- boolean _showingPopupForKeyboard;
- boolean enabled;
- static final String LISTVIEW_KEY = "popupList";
- static final String WINDOW_KEY = "popupWindow";
- static final String CONTAINER_KEY = "container";
- static final String SELECTEDITEM_KEY = "selectedItem";
- static final String TARGET_KEY = "target";
- static final String SELECTEDIMAGE_KEY = "selectedImage";
- static final String ENABLED_KEY = "enabled";
- public static final String SELECT_NEXT_ITEM;
- public static final String SELECT_PREVIOUS_ITEM;
- public static final String POPUP = "popup";
- static final String CLOSE_POPUP_AND_CANCEL = "cancel";
- static final String CLOSE_POPUP_AND_COMMIT = "commit";
-
- public Popup() {
- this(0, 0, 0, 0);
- }
-
- public Popup(Rect var1) {
- this(var1.x, var1.y, var1.width, var1.height);
- }
-
- public Popup(int var1, int var2, int var3, int var4) {
- super(var1, var2, var3, var4);
- this.enabled = true;
- InternalWindow var8 = new InternalWindow(var1, var2, var3, var4);
- var8.setType(0);
- var8.setLayer(300);
- var8._contentView.setTransparent(true);
- var8.setScrollsToVisible(true);
- this.container = new ContainerView(0, 0, var3, var4);
- this.container.setTransparent(true);
- this.container.setBorder(BezelBorder.raisedBezel());
- this.container.setVertResizeInstruction(16);
- this.container.setHorizResizeInstruction(2);
- ListView var5 = new ListView(0, 0, var3, var4);
- PopupItem var7 = new PopupItem();
- var7.setPopup(this);
- this.setPopupList(var5);
- this.setPrototypeItem(var7);
- this.setPopupWindow(var8);
- this.setPopupImage(Bitmap.bitmapNamed("netscape/application/PopupKnobH.gif"));
- this._setupKeyboard();
- }
-
- public void setPrototypeItem(ListItem var1) {
- this.popupList.setPrototypeItem(var1);
- if (var1 instanceof PopupItem) {
- ((PopupItem)var1).setPopup(this);
- }
-
- }
-
- public ListItem prototypeItem() {
- return this.popupList.prototypeItem();
- }
-
- public void removeAllItems() {
- this.popupList.removeAllItems();
- }
-
- public ListItem addItem(String var1, String var2) {
- this.hidePopupIfNeeded();
- ListItem var3 = this.popupList.addItem();
- var3.setTitle(var1);
- var3.setCommand(var2);
- return var3;
- }
-
- public void removeItem(String var1) {
- if (var1 != null) {
- int var3 = this.popupList.count();
-
- while(var3-- > 0) {
- ListItem var2 = this.itemAt(var3);
- if (var1.equals(var2.title())) {
- this.hidePopupIfNeeded();
- this.popupList.removeItemAt(var3);
- return;
- }
- }
-
- }
- }
-
- public void removeItemAt(int var1) {
- if (this.popupList.count() > var1) {
- this.hidePopupIfNeeded();
- this.popupList.removeItemAt(var1);
- }
-
- }
-
- public int selectedIndex() {
- int var1 = this.popupList.indexOfItem(this.selectedItem);
- if (var1 < 0 && this.popupList.count() > 0) {
- var1 = 0;
- this.selectItemAt(0);
- }
-
- return var1;
- }
-
- public ListItem selectedItem() {
- int var1 = this.selectedIndex();
- return var1 < 0 ? null : this.popupList.itemAt(var1);
- }
-
- public void selectItem(ListItem var1) {
- this.selectedItem = var1;
- ((View)this).draw();
- }
-
- public void selectItemAt(int var1) {
- this.selectItem(this.popupList.itemAt(var1));
- }
-
- public int count() {
- return this.popupList.count();
- }
-
- public ListItem itemAt(int var1) {
- return this.popupList.itemAt(var1);
- }
-
- public void setBorder(Border var1) {
- this.container.setBorder(var1);
- }
-
- public Border border() {
- return this.container.border();
- }
-
- public void setPopupList(ListView var1) {
- this.popupList = var1;
- this.popupList.setTarget(this);
- this.popupList.setAllowsMultipleSelection(false);
- this.popupList.setAllowsEmptySelection(true);
- this.popupList.setTracksMouseOutsideBounds(false);
- this.container.addSubview(this.popupList);
- }
-
- public ListView popupList() {
- return this.popupList;
- }
-
- public void setPopupWindow(Window var1) {
- this.popupWindow = var1;
- if (var1 instanceof InternalWindow) {
- InternalWindow var2 = (InternalWindow)var1;
- var2.setScrollsToVisible(true);
- var1.addSubview(this.container);
- }
-
- }
-
- public Window popupWindow() {
- return this.popupWindow;
- }
-
- public void setPopupImage(Image var1) {
- this.image = var1;
- }
-
- public Image popupImage() {
- return this.image;
- }
-
- protected void layoutPopupWindow() {
- Border var1 = this.container.border();
- this.popupList.setRowHeight(super.bounds.height - var1.heightMargin());
- this.popupList.setBounds(var1.leftMargin(), var1.topMargin(), super.bounds.width - var1.widthMargin(), this.popupList.rowHeight() * this.popupList.count());
- int var3 = this.selectedIndex();
- Rect var2 = Rect.newRect(0, 0, ((View)this).width(), ((View)this).height());
- ((View)this).convertRectToView((View)null, var2, var2);
- if (((View)this).rootView().windowClipView() != null) {
- ((View)this).rootView().convertRectToView(((View)this).rootView().windowClipView(), var2, var2);
- }
-
- this.popupWindow.setBounds(var2.x, var2.y - var3 * this.popupList.rowHeight(), this.popupList.width() + var1.widthMargin(), this.popupList.height() + var1.heightMargin());
- Rect.returnRect(var2);
- }
-
- protected void showPopupWindow(MouseEvent var1) {
- if (this.popupWindow instanceof InternalWindow) {
- InternalWindow var2 = (InternalWindow)this.popupWindow;
- var2.setRootView(((View)this).rootView());
- Application.application().beginModalSessionForView(var2);
- } else {
- ExternalWindow var3 = (ExternalWindow)this.popupWindow;
- Application.application().beginModalSessionForView(var3.rootView());
- }
-
- this.popupWindow.show();
- ((View)this).rootView().setMouseView(this.popupList);
- if (var1 != null) {
- this.popupList.mouseDown(((View)this).convertEventToView(this.popupList, var1));
- } else {
- this.popupList.selectItem(this.selectedItem());
- ((View)this).rootView().makeSelectedView(this.popupList);
- }
- }
-
- public boolean mouseDown(MouseEvent var1) {
- if (!this.isEnabled()) {
- return false;
- } else {
- this.layoutPopupWindow();
- this.showPopupWindow(var1);
- return true;
- }
- }
-
- public void setEnabled(boolean var1) {
- this.enabled = var1;
- ((View)this).setDirty(true);
- }
-
- public boolean isEnabled() {
- return this.enabled;
- }
-
- public boolean isTransparent() {
- return this.popupList.isTransparent();
- }
-
- public void drawView(Graphics var1) {
- Color var4 = null;
- Border var2 = this.container.border();
- if (this.selectedItem == null && this.popupList.selectedItem() == null) {
- this.selectItem(this.popupList.itemAt(0));
- }
-
- if (!this.popupList.isTransparent() && this.selectedItem != null && this.selectedItem.isTransparent()) {
- var1.setColor(this.popupList.backgroundColor());
- var1.fillRect(0, 0, ((View)this).width(), ((View)this).height());
- }
-
- if (this.selectedItem != null) {
- Rect var3 = Rect.newRect(var2.leftMargin(), var2.topMargin(), super.bounds.width - var2.widthMargin(), super.bounds.height - var2.heightMargin());
- var1.pushState();
- var1.setClipRect(var3);
- if (!this.isEnabled()) {
- var4 = this.selectedItem.textColor();
- this.selectedItem.setTextColor(Color.gray);
- }
-
- this.selectedItem.drawInRect(var1, var3);
- if (!this.isEnabled()) {
- this.selectedItem.setTextColor(var4);
- }
-
- var1.popState();
- Rect.returnRect(var3);
- }
-
- var2.drawInRect(var1, 0, 0, ((View)this).width(), ((View)this).height());
- }
-
- public void setTarget(Target var1) {
- this.target = var1;
- }
-
- public Target target() {
- return this.target;
- }
-
- public void setCommand(String var1) {
- this.popupList.setCommand(var1);
- }
-
- public String command() {
- return this.popupList.command();
- }
-
- public void sendCommand() {
- if (this.target != null) {
- String var1 = null;
- if (this.selectedItem != null) {
- var1 = this.selectedItem.command();
- }
-
- if (var1 == null) {
- var1 = this.command();
- }
-
- this.target.performCommand(var1, this);
- }
-
- }
-
- public void performCommand(String var1, Object var2) {
- if (SELECT_NEXT_ITEM.equals(var1)) {
- this.selectNextItem(true);
- } else if (SELECT_PREVIOUS_ITEM.equals(var1)) {
- this.selectNextItem(false);
- } else if ("popup".equals(var1)) {
- this.layoutPopupWindow();
- this.wasSelectedItem = this.selectedItem();
- this._showingPopupForKeyboard = true;
- this.showPopupWindow((MouseEvent)null);
- this._setupKeyboardToClosePopup(true);
- } else if (this.showingPopupForKeyboard()) {
- boolean var5 = false;
- if ("cancel".equals(var1)) {
- this.selectItem(this.wasSelectedItem);
- var5 = true;
- } else if ("commit".equals(var1)) {
- this.selectItem(this.popupList.selectedItem());
- if (this.popupList.selectedItem() != null) {
- this.sendCommand();
- }
-
- var5 = true;
- }
-
- if (var5) {
- this.popupList.disableDrawing();
- this.popupList.deselectItem(this.popupList.selectedItem());
- this.popupList.reenableDrawing();
- this.popupWindow.hide();
- if (this.popupWindow instanceof InternalWindow) {
- InternalWindow var3 = (InternalWindow)this.popupWindow;
- Application.application().endModalSessionForView(var3);
- } else {
- ExternalWindow var4 = (ExternalWindow)this.popupWindow;
- Application.application().endModalSessionForView(var4.rootView());
- }
-
- this._setupKeyboardToClosePopup(false);
- this._showingPopupForKeyboard = false;
- }
- } else {
- if (this.popupList.selectedItem() != null) {
- this.selectedItem = this.popupList.selectedItem();
- }
-
- if (this.selectedItem != null) {
- this.sendCommand();
- }
-
- this.popupList.disableDrawing();
- this.popupList.deselectItem(this.selectedItem);
- this.popupList.reenableDrawing();
- this.popupWindow.hide();
- if (this.popupWindow instanceof InternalWindow) {
- InternalWindow var6 = (InternalWindow)this.popupWindow;
- Application.application().endModalSessionForView(var6);
- } else {
- ExternalWindow var7 = (ExternalWindow)this.popupWindow;
- Application.application().endModalSessionForView(var7.rootView());
- }
-
- this._setupKeyboardToClosePopup(false);
- }
-
- ((View)this).draw();
- }
-
- public Size minSize() {
- int var3 = 0;
- int var4 = 0;
- if (this.container.border() != null) {
- var3 = this.container.border().widthMargin();
- var4 = this.container.border().heightMargin();
- }
-
- int var1 = 0;
- int var2 = 0;
- if (this.popupList != null) {
- var1 = this.popupList.minItemWidth();
- var2 = this.popupList.minItemHeight();
- }
-
- int var5 = 0;
- int var6 = 0;
- if (this.image != null) {
- var5 = this.image.width();
- var6 = this.image.height();
- }
-
- if (var6 < var2) {
- var6 = 0;
- } else {
- var6 = var2 - var6;
- }
-
- return new Size(var3 + var1 + var5, var4 + var2 + var6);
- }
-
- public void describeClassInfo(ClassInfo var1) {
- super.describeClassInfo(var1);
- var1.addClass("netscape.application.Popup", 2);
- var1.addField("popupList", (byte)18);
- var1.addField("popupWindow", (byte)18);
- var1.addField("container", (byte)18);
- var1.addField("selectedItem", (byte)18);
- var1.addField("target", (byte)18);
- var1.addField("selectedImage", (byte)18);
- var1.addField("enabled", (byte)0);
- }
-
- public void encode(Encoder var1) throws CodingException {
- super.encode(var1);
- var1.encodeObject("popupList", this.popupList);
- var1.encodeObject("popupWindow", this.popupWindow);
- var1.encodeObject("container", this.container);
- var1.encodeObject("selectedItem", this.selectedItem);
- var1.encodeObject("target", this.target);
- var1.encodeObject("selectedImage", this.image);
- var1.encodeBoolean("enabled", this.enabled);
- }
-
- public void decode(Decoder var1) throws CodingException {
- super.decode(var1);
- this.popupList = (ListView)var1.decodeObject("popupList");
- this.popupWindow = (Window)var1.decodeObject("popupWindow");
- this.container = (ContainerView)var1.decodeObject("container");
- this.selectedItem = (ListItem)var1.decodeObject("selectedItem");
- this.target = (Target)var1.decodeObject("target");
- this.image = (Image)var1.decodeObject("selectedImage");
- if (var1.versionForClassName("netscape.application.Popup") > 1) {
- this.enabled = var1.decodeBoolean("enabled");
- }
-
- }
-
- void _setupKeyboard() {
- ((View)this).removeAllCommandsForKeys();
- ((View)this).setCommandForKey(SELECT_NEXT_ITEM, 1005, 0);
- ((View)this).setCommandForKey(SELECT_PREVIOUS_ITEM, 1004, 0);
- ((View)this).setCommandForKey("popup", 10, 0);
- ((View)this).setCommandForKey("popup", 32, 0);
- }
-
- void selectNextItem(boolean var1) {
- int var2 = this.selectedIndex();
- int var3 = this.count();
- if (var1 && var2 < var3 - 1) {
- this.selectItemAt(var2 + 1);
- } else if (!var1 && var2 > 0) {
- this.selectItemAt(var2 - 1);
- }
-
- if (this.selectedItem() != null) {
- this.sendCommand();
- }
-
- }
-
- public boolean canBecomeSelectedView() {
- return true;
- }
-
- void _setupKeyboardToClosePopup(boolean var1) {
- if (var1) {
- ((View)this).setCommandForKey("cancel", 27, 2);
- ((View)this).setCommandForKey("commit", 10, 2);
- } else {
- ((View)this).removeCommandForKey(27);
- ((View)this).setCommandForKey("popup", 10, 0);
- }
- }
-
- protected void ancestorWillRemoveFromViewHierarchy(View var1) {
- super.ancestorWillRemoveFromViewHierarchy(var1);
- this.hidePopupIfNeeded();
- }
-
- public void hidePopupIfNeeded() {
- if (this.showingPopupForKeyboard()) {
- this.performCommand("cancel", this);
- }
-
- }
-
- public boolean showingPopupForKeyboard() {
- return this._showingPopupForKeyboard;
- }
-
- public String formElementText() {
- return this.selectedItem() != null ? this.selectedItem().title() : "";
- }
-
- static {
- SELECT_NEXT_ITEM = ListView.SELECT_NEXT_ITEM;
- SELECT_PREVIOUS_ITEM = ListView.SELECT_PREVIOUS_ITEM;
- }
- }
-