001: /**
002: * Miroslav Popov, Dec 12, 2005
003: * miroslav.popov@gmail.com
004: */package org.enhydra.jawe;
005:
006: import java.awt.event.ActionEvent;
007: import java.awt.event.ActionListener;
008: import java.awt.event.MouseEvent;
009: import java.awt.event.MouseListener;
010: import java.util.List;
011:
012: import javax.swing.JComponent;
013: import javax.swing.JMenuItem;
014: import javax.swing.JPopupMenu;
015: import javax.swing.JTabbedPane;
016: import javax.swing.SwingUtilities;
017:
018: import org.enhydra.jawe.base.controller.JaWEFrame;
019:
020: /**
021: * @author Miroslav Popov
022: *
023: */
024: public class JaWETabbedPane extends JTabbedPane implements
025: MouseListener, ActionListener {
026:
027: private boolean maximized = false;
028:
029: JMenuItem close;
030:
031: public JaWETabbedPane() {
032: addMouseListener(this );
033: close = new JMenuItem(ResourceManager
034: .getLanguageDependentString("Close"
035: + BarFactory.LABEL_POSTFIX));
036: close.addActionListener(this );
037: }
038:
039: public void mouseClicked(MouseEvent e) {
040: if (e.getID() == MouseEvent.MOUSE_CLICKED
041: && e.getClickCount() == 2) {
042: if (maximized) {
043: JaWEFrame jf = JaWEManager.getInstance()
044: .getJaWEController().getJaWEFrame();
045: jf.restoreWorkingArea();
046: maximized = false;
047: } else {
048: JaWEFrame jf = JaWEManager.getInstance()
049: .getJaWEController().getJaWEFrame();
050: jf.maximizeComponent(this );
051: maximized = true;
052: }
053: } else if (e.getID() == MouseEvent.MOUSE_CLICKED
054: && SwingUtilities.isRightMouseButton(e)) {
055: JPopupMenu popup = new JPopupMenu();
056:
057: popup.add(close);
058: popup.addSeparator();
059: popup.addSeparator();
060:
061: List l = JaWEManager.getInstance().getComponentManager()
062: .getComponents();
063: for (int i = 0; i < l.size(); i++) {
064: JaWEComponent c = (JaWEComponent) l.get(i);
065: if (c.getType() != JaWEComponent.UPPER_STATUS_COMPONENT
066: && c.getType() != JaWEComponent.LOWER_STATUS_COMPONENT) {
067: JMenuItem t = new JMenuItem();
068: t
069: .setText(JaWEManager.getInstance()
070: .getJaWEController().getSettings()
071: .getLanguageDependentString(
072: "AddKey")
073: + " "
074: + JaWEManager
075: .getInstance()
076: .getJaWEController()
077: .getSettings()
078: .getLanguageDependentString(
079: c.getName()
080: + BarFactory.LABEL_POSTFIX));
081: t.setName(c.getName());
082: t.addActionListener(this );
083: popup.add(t);
084: }
085: }
086:
087: popup.show(this , e.getX(), e.getY());
088: }
089: }
090:
091: public void actionPerformed(ActionEvent e) {
092: if (e.getSource() == close) {
093: JComponent c = (JComponent) this .getSelectedComponent();
094:
095: JaWEComponent comp = findComponent(c);
096: JaWEManager.getInstance().getJaWEController()
097: .removeJaWEComonent(comp);
098: } else if (e.getSource() instanceof JMenuItem) {
099: JMenuItem ji = (JMenuItem) e.getSource();
100: String cn = ji.getName();
101: JaWEComponent comp = JaWEManager.getInstance()
102: .getComponentManager().getComponent(cn);
103: JaWEManager.getInstance().getJaWEController()
104: .changeJaWEComponentType(comp, this .getName());
105: this .setSelectedComponent(comp.getView().getDisplay());
106: }
107: }
108:
109: protected JaWEComponent findComponent(JComponent c) {
110: List l = JaWEManager.getInstance().getComponentManager()
111: .getComponents();
112: for (int i = 0; i < l.size(); i++) {
113: JaWEComponent comp = (JaWEComponent) l.get(i);
114:
115: if (comp.getView().getDisplay() == c)
116: return comp;
117: }
118:
119: return null;
120: }
121:
122: public void mouseEntered(MouseEvent e) {
123: }
124:
125: public void mouseExited(MouseEvent e) {
126: }
127:
128: public void mousePressed(MouseEvent e) {
129: }
130:
131: public void mouseReleased(MouseEvent e) {
132: }
133: }
|