/*jadclipse*/// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) radix(10) lradix(10) 
package cn.com.origin.autocode.classification.panels;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Point;
import java.awt.SystemColor;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.PrintWriter;
import java.io.StringWriter;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JToggleButton;
import javax.swing.MenuElement;
import javax.swing.MenuSelectionManager;
import javax.swing.SwingUtilities;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;

import com.teamcenter.rac.util.HorizontalLayout;
import com.teamcenter.rac.util.InterfaceSignalOnClose;
import com.teamcenter.rac.util.Registry;
import com.teamcenter.rac.util.SignalOnClose;
import com.teamcenter.rac.util.selection.RecursiveSwingListener;

// Referenced classes of package com.teamcenter.rac.util:
//            InterfaceSignalOnClose, Registry, SignalOnClose, HorizontalLayout

public abstract class AbstractPopupPanel extends JToggleButton implements InterfaceSignalOnClose {
	private class Banner extends JPanel {

		public String getTitle() {
			return title.getText();
		}

		public void setTitle(String s) {
			title.setText(s);
			validate();
			repaint();
		}

		public void setPinnedUp(boolean flag) {
			pinup.setSelected(flag);
		}

		public boolean isPinnedUp() {
			return pinup.isSelected();
		}

		public void setCloseable(boolean flag) {
			remove(close);
			if (flag)
				add("right", close);
		}

		public boolean isCloseable() {
			boolean flag;
			if (close.getParent() != null)
				flag = true;
			else
				flag = false;
			return flag;
		}

		public void setPinnableButtonVisible(boolean flag) {
			pinup.setVisible(flag);
		}

		protected void reset() {
			if (!pinup.isSelected() && popupWindow.getSubElements().length <= 0) {
				MenuElement amenuelement[] = new MenuElement[1];
				amenuelement[0] = popupWindow;
				MenuSelectionManager.defaultManager().setSelectedPath(amenuelement);
			}
		}

		private JToggleButton pinup;
		private JLabel title;
		private JLabel close;

		public Banner(String s) {
			super();
			setLayout(new HorizontalLayout(1, 1, 1, 1, 1));
			setBackground(SystemColor.controlShadow);
			pinup = new JToggleButton(r.getImageIcon("notpinned.ICON"));
			pinup.addActionListener(new ActionListener() {

				public void actionPerformed(ActionEvent actionevent) {
					if (!pinup.isSelected())
						if (popupWindow.getSubElements().length > 0) {
							MenuElement amenuelement[] = new MenuElement[2];
							amenuelement[0] = popupWindow;
							amenuelement[1] = popupWindow.getSubElements()[0];
							MenuSelectionManager.defaultManager().setSelectedPath(amenuelement);
						} else {
							MenuElement amenuelement1[] = new MenuElement[1];
							amenuelement1[0] = popupWindow;
							MenuSelectionManager.defaultManager().setSelectedPath(amenuelement1);
						}
				}

				// JavaClassFileOutputException: Invalid index accessing method local variables table of <init>
			});
			pinup.setBackground(SystemColor.controlShadow);
			pinup.setSelectedIcon(r.getImageIcon("pinned.ICON"));
			pinup.setBorderPainted(false);
			pinup.setFocusPainted(false);
			pinup.setMargin(new Insets(0, 0, 0, 0));
			title = new JLabel(s);
			Font font = title.getFont();
			font = new Font(font.getName(), 2, font.getSize() - 2);
			title.setFont(font);
			title.setForeground(SystemColor.activeCaptionText);
			title.addMouseListener(new MouseAdapter() {

				public void mousePressed(MouseEvent mouseevent) {
					if (mouseevent.getClickCount() == 2 && tearoff) {
						postDownValue = true;
						tearoff();
					}
				}

				// JavaClassFileOutputException: Invalid index accessing method local variables table of <init>
			});
			close = new JLabel(r.getImageIcon("close7.ICON"));
			close.addMouseListener(new MouseAdapter() {

				public void mousePressed(MouseEvent mouseevent) {
					if (mouseevent.getClickCount() == 1) {
						requestFocusInWindow();
						postDown();
					}
				}

				// JavaClassFileOutputException: Invalid index accessing method local variables table of <init>
			});
			add("left", pinup);
			add("right", close);
			add("unbound", title);
		}
	}

	public class RestoreButtonState extends Thread {

		public void run() {
			try {
				Thread.sleep(100L);
			} catch (InterruptedException interruptedexception) {
			}
			if (isSelected())
				SwingUtilities.invokeLater(new Runnable() {

					public void run() {
						setSelected(false);
					}
				});
		}

		public RestoreButtonState() {
			super("AbstractPopupButton.RestoreButtonState");
			String s = getClass().getName();
			s = s.substring(s.lastIndexOf(".") + 1);
			setName(s);
		}
	}

	public AbstractPopupPanel() {
		lightWeightPopup = JPopupMenu.getDefaultLightWeightPopupEnabled();
		pinAsPersistent = false;
		latestPinStatus = false;
		postDownValue = false;
		orientation = 2;
		suggestedHorizontalAlignment = 1;
		suggestedVerticalAlignment = 2;
		setSelected(false);
		tearoff = true;
		tearoffModality = true;
		tearoffAlwaysOnTop = false;
		addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent actionevent) {
				if (isSelected()) {
					if (okToPostUp())
						postUp();
					else
						restoreButtonState();
				} else {
					postDown();
				}
			}
		});
		r = Registry.getRegistry("com.teamcenter.rac.util.AbstractPopupPanel");
		propertyMenu = new JPopupMenu();
		propertyItem = new JMenuItem(r.getString("property"));
		propertyItem.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent actionevent) {
				if (propertyDialog != null)
					propertyDialog.setVisible(true);
			}

		});
		MouseAdapter mouseadapter = new MouseAdapter() {

			public void mousePressed(MouseEvent mouseevent) {
				int i = mouseevent.getModifiers();
				if (i == 4) {
					if (propertyDialog != null && propertyMenu.getComponentIndex(propertyItem) < 0)
						propertyMenu.insert(propertyItem, 0);
					MenuElement amenuelement[] = propertyMenu.getSubElements();
					if (amenuelement != null && amenuelement.length > 0)
						propertyMenu.show((Component) mouseevent.getSource(), mouseevent.getX(), mouseevent.getY());
				}
			}
		};
		addMouseListener(mouseadapter);
		this.setPreferredSize(new Dimension(50,25));
	}

	public AbstractPopupPanel(Icon icon) {
		this();
		setIcon(icon);
	}

	public AbstractPopupPanel(Icon icon, boolean flag) {
		this();
		setIcon(icon);
		setSelected(flag);
	}

	public AbstractPopupPanel(String s) {
		this();
		setText(s);
	}

	public AbstractPopupPanel(String s, boolean flag) {
		this();
		setText(s);
		setSelected(flag);
	}

	public AbstractPopupPanel(String s, Icon icon) {
		this();
		setText(s);
		setIcon(icon);
	}

	public AbstractPopupPanel(String s, Icon icon, boolean flag) {
		this();
		setText(s);
		setIcon(icon);
		setSelected(flag);
	}

	public void postUp() {
		if (popupWindow == null)
			constructPopupWindow();
		boolean flag = popupWindow.isLightWeightPopupEnabled();
		if (flag && !JPopupMenu.getDefaultLightWeightPopupEnabled())
			popupWindow.setLightWeightPopupEnabled(false);
		setWindowLocation(popupWindow);
		if (pinAsPersistent || latestPinStatus)
			setPinnedUp(true);
		popupWindow.setInvoker(this);
		popupWindow.setVisible(true);
		popupWindow.requestFocusInWindow();
		popupWindow.setLightWeightPopupEnabled(flag);
		SwingUtilities.invokeLater(new Runnable() {

			public void run() {
				if (titleBanner != null)
					titleBanner.reset();
			}
		});
	}

	public final void postDown() {
		latestPinStatus = isPinnedUp();
		setPinnedUp(false);
		if (popupWindow != null)
			popupWindow.setVisible(false);
		MenuSelectionManager.defaultManager().clearSelectedPath();
		if (!isPinnedUp() && dlg != null) {
			dlg.setVisible(false);
			dlg.dispose();
		}
	}

	public boolean okToPostUp() {
		return true;
	}

	public void asPopupWindowComesUp() {
	}

	public boolean getTearoffModality() {
		return tearoffModality;
	}

	public void setTearoffModality(boolean flag) {
		tearoffModality = flag;
	}

	public void beforePopupWindowGoesDown() {
	}

	public void closeSignaled() {
		if (panel != null)
			SignalOnClose.close(panel);
	}

	public JPopupMenu getPopupWindow() {
		return popupWindow;
	}

	public JDialog getDialog() {
		return dlg;
	}

	public void resetPopupWindow() {
		popupWindow = null;
	}

	public int getOrientation() {
		return orientation;
	}

	public void setOrientation(int i) {
		if (i == 1 || i == 2)
			orientation = i;
		else
			i = 1;
	}

	public int getSuggestedHorizontalAlignment() {
		return suggestedHorizontalAlignment;
	}

	public void setSuggestedHorizontalAlignment(int i) {
		if (i == 1 || i == 2)
			suggestedHorizontalAlignment = i;
		else
			i = 1;
	}

	public int getSuggestedVerticalAlignment() {
		return suggestedVerticalAlignment;
	}

	public void setSuggestedVerticalAlignment(int i) {
		if (i == 1 || i == 2)
			suggestedVerticalAlignment = i;
		else
			i = 1;
	}

	public JPanel getPanel() {
		return panel;
	}

	public void setPopupTitle(String s) {
		if (panel == null)
			return;
		if (titleBanner == null) {
			titleBanner = new Banner(s);
			panel.add("North", titleBanner);
		} else {
			titleBanner.setTitle(s);
			panel.validate();
			popupWindow.validate();
		}
	}

	public void setPopupTitle(String s, boolean flag, boolean flag1) {
		setPopupTitle(s);
		setPinnedUp(flag);
		setPinPersistent(flag1);
	}

	public void setPinPersistent(boolean flag) {
		pinAsPersistent = flag;
	}

	public void setTearoff(boolean flag) {
		tearoff = flag;
	}

	public abstract void initPopupWindow();

	public JDialog constructTearoffDialog() {
		Object obj = this;
		Frame frame = null;
		do {
			if (obj == null)
				break;
			if (obj instanceof Frame) {
				frame = (Frame) obj;
				break;
			}
			obj = ((Component) (obj)).getParent();
		} while (true);
		JDialog jdialog;
		if (frame != null)
			jdialog = new JDialog(frame);
		else
			jdialog = new JDialog();
		try {
			jdialog.setIconImage(getTCIcon());
		} catch (NoSuchMethodError nosuchmethoderror) {
		}
		jdialog.setModal(tearoffModality);
		jdialog.setTitle(getTitle());
		
		jdialog.getContentPane().setLayout(new BorderLayout());
	
		if (dialogPanel != null)
			jdialog.getContentPane().add("Center", dialogPanel);
		else
			jdialog.getContentPane().add("Center", panel);
		
	
		return jdialog;
	}

	private Image getTCIcon() {
		try {
			ImageIcon imageicon = Registry.getRegistry("com.teamcenter.rac.aif.aif").getImageIcon("aifDesktop.ICON");
			return imageicon.getImage();
		} catch (Exception exception) {
			return null;
		}
	}

	public String getTitle() {
		if (titleBanner != null)
			return titleBanner.getTitle();
		else
			return null;
	}

	public void setPinnedUp(boolean flag) {
		if (titleBanner != null)
			titleBanner.setPinnedUp(flag);
	}

	public boolean isPinnedUp() {
		boolean flag = false;
		if (titleBanner != null)
			flag = titleBanner.isPinnedUp();
		return flag;
	}

	public void setCloseable(boolean flag) {
		if (titleBanner != null)
			titleBanner.setCloseable(flag);
	}

	public boolean isCloseable() {
		boolean flag = false;
		if (titleBanner != null)
			flag = titleBanner.isCloseable();
		return flag;
	}

	public void setPinnableButtonVisible(boolean flag) {
		if (titleBanner != null) {
			titleBanner.setPinnedUp(false);
			titleBanner.setPinnableButtonVisible(flag);
		}
	}

	public void setLightWeightPopupEnabled(boolean flag) {
		if (popupWindow != null)
			popupWindow.setLightWeightPopupEnabled(flag);
		lightWeightPopup = flag;
	}

	public void setPropertyDialog(final JDialog dlg) {
		propertyDialog = dlg;
		dlg.addWindowListener(new WindowAdapter() {

			public void windowDeactivated(WindowEvent windowevent) {
				dlg.toFront();
				dlg.requestFocusInWindow();
			}
		});
	}

	public JPopupMenu getPropertyPopupMenu() {
		return propertyMenu;
	}

	protected void constructPopupWindow() {
		popupWindow = new JPopupMenu() {

			public void paint(Graphics g) {
				Dimension dimension = getSize();
				dimension.width--;
				dimension.height--;
				super.paint(g);
				g.setColor(SystemColor.controlShadow);
				g.drawLine(dimension.width, 0, dimension.width, dimension.height);
				g.drawLine(0, dimension.height, dimension.width, dimension.height);
				g.setColor(SystemColor.activeCaptionText);
				g.drawLine(0, 0, dimension.width, 0);
				g.drawLine(0, 0, 0, dimension.height);
			}

			public void setVisible(boolean flag) {
				if (!flag) {
					Exception exception = new Exception();
					StringWriter stringwriter = new StringWriter();
					PrintWriter printwriter = new PrintWriter(stringwriter);
					exception.printStackTrace(printwriter);
					StringBuffer stringbuffer = stringwriter.getBuffer();
					if (stringbuffer.toString().lastIndexOf("windowDeactivated") > 0 || stringbuffer.toString().lastIndexOf("menuSelectionChanged") > 0)
						return;
				}
				if (!isPinnedUp()) {
					if (!flag) {
						MenuSelectionManager menuselectionmanager = MenuSelectionManager.defaultManager();
						MenuElement amenuelement[] = menuselectionmanager.getSelectedPath();
						if (amenuelement.length != 0 && amenuelement[0] != this)
							MenuSelectionManager.defaultManager().clearSelectedPath();
					}
					super.setVisible(flag);
				} else {
					super.setVisible(true);
				}
			}
		};
		RecursiveSwingListener.addListenersFromFosterParent(this, popupWindow);
		popupWindow.setLightWeightPopupEnabled(lightWeightPopup);
		popupWindow.setBorderPainted(false);
		popupWindow.addPopupMenuListener(new PopupMenuListener() {

			public void popupMenuWillBecomeVisible(PopupMenuEvent popupmenuevent) {
				asPopupWindowComesUp();
			}

			public void popupMenuWillBecomeInvisible(PopupMenuEvent popupmenuevent) {
				beforePopupWindowGoesDown();
				restoreButtonState();
			}

			public void popupMenuCanceled(PopupMenuEvent popupmenuevent) {
			}
		});
		panel = new JPanel(new BorderLayout());
		initPopupWindow();
		popupWindow.add(panel);
		popupWindow.pack();
		popupWindow.validate();
	}

	public void tearoff() {
		setPinnedUp(false);
		if (!postDownValue)
			postDown();
		popupWindow.remove(panel);
		if (titleBanner != null)
			panel.remove(titleBanner);
		dlg = constructTearoffDialog();
		dlg.setDefaultCloseOperation(0);
		dlg.addWindowListener(new WindowAdapter() {

			public void windowClosing(WindowEvent windowevent) {
				closeDialog();
			}
		});
		if (!dlg.getOwner().isVisible())
			dlg.addWindowListener(new WindowAdapter() {

				public void windowDeactivated(WindowEvent windowevent) {
					dlg.toFront();
					dlg.requestFocusInWindow();
				}
			});
		dlg.pack();
		dlg.validate();
		setWindowLocation(popupWindow);
		setWindowLocation(dlg);
		
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				dlg.toFront();
				if (tearoffAlwaysOnTop)
					dlg.setAlwaysOnTop(true);
			}
		});
		
		dlg.setVisible(true);
		panel.add("North", titleBanner);
		popupWindow.add(panel);
	}

	public void forceTearoffToTop() {
		tearoffAlwaysOnTop = true;
	}

	public void revalidatetWindw() {
		if (dlg != null) {
			dlg.pack();
			dlg.validate();
		}
		if (popupWindow != null) {
			popupWindow.pack();
			popupWindow.validate();
		}
	}

	public void closeDialog() {
		beforePopupWindowGoesDown();
		beforeDialogClosed();
		MenuSelectionManager.defaultManager().clearSelectedPath();
		dlg.getContentPane().removeAll();
		dlg.setVisible(false);
		dlg.dispose();
	}

	protected void beforeDialogClosed() {
		dialogPanel = null;
	}

	protected void setWindowLocation(Container container) {
		Point point = getLocationOnScreen();
		Dimension dimension = getSize();
		Dimension dimension1 = Toolkit.getDefaultToolkit().getScreenSize();
		Dimension dimension2 = container.getPreferredSize();
		Point point1 = new Point(0, 0);
		for (int i = 0; i < 8; i++) {
			int j = (i & 4) != 4 ? orientation : 3 - orientation;
			int k = (i & 2) != 2 ? suggestedVerticalAlignment : 3 - suggestedVerticalAlignment;
			int l = (i & 1) != 1 ? suggestedHorizontalAlignment : 3 - suggestedHorizontalAlignment;
			if (j == 1) {
				if (l == 1)
					point1.x = point.x - dimension2.width;
				else
					point1.x = point.x + dimension.width;
				if (k == 1)
					point1.y = point.y;
				else
					point1.y = (point.y + dimension.height) - dimension2.height;
			} else {
				if (l == 1)
					point1.x = point.x;
				else
					point1.x = (point.x + dimension.width) - dimension2.width;
				if (k == 1)
					point1.y = point.y - dimension2.height;
				else
					point1.y = point.y + dimension.height;
			}
			if (point1.x > 0 && point1.y > 0 && point1.x + dimension2.width < dimension1.width && point1.y + dimension2.height < dimension1.height) {
				container.setLocation(point1.x, point1.y);
				return;
			}
		}

		if (point1.x < 0) {
			point1.x = 0;
			point1.y = point1.y - dimension.height;
		}
		if (point1.y < 0)
			point1.y = 0;
		container.setLocation(point1.x, point1.y);
	}

	private void restoreButtonState() {
		RestoreButtonState restorebuttonstate = new RestoreButtonState();
		restorebuttonstate.start();
	}

	private JPopupMenu popupWindow;
	private JDialog dlg;
	private int orientation;
	private int suggestedHorizontalAlignment;
	private int suggestedVerticalAlignment;
	private boolean tearoff;
	private boolean tearoffModality;
	private boolean tearoffAlwaysOnTop;
	private boolean lightWeightPopup;
	private JPanel panel;
	protected JPanel dialogPanel;
	private Banner titleBanner;
	private boolean pinAsPersistent;
	private boolean latestPinStatus;
	protected JDialog propertyDialog;
	protected JPopupMenu propertyMenu;
	protected JMenuItem propertyItem;
	private Registry r;
	public java.util.List limList;
	public static final int HORIZONTAL = 1;
	public static final int VERTICAL = 2;
	public static final int LEFT = 1;
	public static final int RIGHT = 2;
	public static final int TOP = 1;
	public static final int BOTTOM = 2;
	private boolean postDownValue;

}

/*
 * DECOMPILATION REPORT
 * 
 * Decompiled from: G:\TC_plugins\TC83_plugins\plugins\com.teamcenter.rac.util_8000.3.0.jar Total time: 125 ms Jad reported messages/errors: Exit status: 0 Caught exceptions:
 */