001: package tide.editor.completions;
002:
003: import tide.project.JDocRes;
004: import tide.editor.Accelerators;
005: import javax.swing.text.html.*;
006: import tide.editor.MainEditorFrame;
007: import javax.swing.*;
008: import javax.swing.event.*;
009: import java.awt.BorderLayout;
010: import java.awt.event.*;
011:
012: /** TODO.
013: */
014: public final class AnnotationParamsCompletion extends JDialog implements
015: CompletionDialog {
016: // CompletionDialog interface
017: public void cancelDialog() {
018: }
019:
020: // CompletionDialog interface
021: public void selectAndQuit() {
022: }
023:
024: final CompletionManager completionManager;
025: final int docOffset;
026: private final JSplitPane sp;
027: private final JEditorPane memberExplorerPane = new JEditorPane();
028: private boolean wasCancelled = true;
029: private final JEditorPane javaDocPane = new JEditorPane();
030: final private HyperlinkListener hyperlinkListener;
031:
032: public AnnotationParamsCompletion(Class clazz, String title,
033: JFrame owner, int x, int y,
034: final CompletionManager completionManager,
035: final int docOffset) {
036: super (owner, title, false);
037: this .setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
038:
039: this .completionManager = completionManager;
040: this .docOffset = docOffset;
041:
042: setLayout(new BorderLayout(0, 0));
043:
044: JPanel centerPanel = new JPanel();
045:
046: JTabbedPane explPane = new JTabbedPane();
047: explPane.addTab("JavaDoc", new JScrollPane(javaDocPane));
048: explPane.addTab("Member explorer", new JScrollPane(
049: memberExplorerPane));
050: explPane.setSelectedIndex(0);
051: sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, centerPanel,
052: explPane);
053:
054: javaDocPane.setEditable(false);
055: memberExplorerPane.setEditable(false);
056:
057: add(sp, BorderLayout.CENTER);
058:
059: final int fontSize = UIManager.getFont("Label.font").getSize();
060: MainEditorFrame.instance.globalProperties
061: .setComponentSizeFromINIFile(this ,
062: "AnnotationParamsCompletion", fontSize * 50,
063: fontSize * 45, x, y);
064: this .setLocation(x, y);
065: sp.setDividerLocation(MainEditorFrame.instance.globalProperties
066: .getInteger("AnnotationParamsCompletion_divloc",
067: fontSize * 5));
068: sp.setOneTouchExpandable(true);
069:
070: ((JComponent) getContentPane()).registerKeyboardAction(
071: new ActionListener() {
072: public void actionPerformed(ActionEvent ae) {
073: wasCancelled = true;
074: setVisible(false);
075: return;
076: }
077: }, "Escape", Accelerators.escape,
078: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
079:
080: ((JComponent) getContentPane()).registerKeyboardAction(
081: new ActionListener() {
082: public void actionPerformed(ActionEvent ae) {
083: wasCancelled = false;
084: setVisible(false);
085: return;
086: }
087: }, "Enter", KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,
088: 0, true), // false => not working, let the table "jump"
089: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
090:
091: this .addWindowListener(new WindowAdapter() {
092: @Override
093: public void windowClosed(WindowEvent e) {
094: // not called on cancel
095: saveSettingsOnClose();
096: }
097:
098: @Override
099: public void windowClosing(WindowEvent e) {
100: // not called on cancel
101: saveSettingsOnClose();
102: }
103: /*@Override
104: public void windowDeactivated(WindowEvent e)
105: {
106: saveSettingsOnClose();
107: } */
108: });
109:
110: javaDocPane
111: .addHyperlinkListener(hyperlinkListener = new HyperlinkListener() {
112: public void hyperlinkUpdate(HyperlinkEvent e) {
113: if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
114: JEditorPane pane = (JEditorPane) e
115: .getSource();
116: if (e instanceof HTMLFrameHyperlinkEvent) {
117: HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent) e;
118: HTMLDocument doc = (HTMLDocument) pane
119: .getDocument();
120: doc.processHTMLFrameHyperlinkEvent(evt);
121: } else {
122: try {
123: //TODO: resolve relative names !
124: System.out.println("URL: "
125: + e.getURL());
126: pane.setPage(e.getURL());
127: } catch (Throwable t) {
128: t.printStackTrace();
129: }
130: }
131: }
132: }
133: });
134:
135: javaDocPane.setContentType("text/html");
136: JDocRes jdr = MainEditorFrame.instance.getActualProject()
137: .getJavaDocManager().getClassSummary(clazz.getName());
138: javaDocPane.setText(jdr.part);
139: javaDocPane.setCaretPosition(0);
140:
141: memberExplorerPane.setContentType("text/html");
142: memberExplorerPane.setText("<html><body>" + clazz
143: + "</body></html>");
144:
145: this .setVisible(true); // NOT MODAL !!
146:
147: }
148:
149: private void saveSettingsOnClose() {
150: MainEditorFrame.instance.globalProperties
151: .saveComponentSizeInINIFile(this ,
152: "AnnotationParamsCompletion");
153: MainEditorFrame.instance.globalProperties.setInteger(
154: "AnnotationParamsCompletion_divloc", sp
155: .getDividerLocation());
156: //MainEditorFrame.debugOut("removing caret listener for completion dialog "+this.getTitle());
157: //this.completionManager.editor.getTextPane().removeCaretListener(caretListener);
158: this .completionManager.openedDialogs.remove(this );
159: javaDocPane.removeHyperlinkListener(hyperlinkListener);
160: //actualDisplayedItem = null;
161: //new Throwable("close").printStackTrace();
162: }
163: }
|