001    // This file is part of AceWiki.
002    // Copyright 2008-2012, AceWiki developers.
003    // 
004    // AceWiki is free software: you can redistribute it and/or modify it under the terms of the GNU
005    // Lesser General Public License as published by the Free Software Foundation, either version 3 of
006    // the License, or (at your option) any later version.
007    // 
008    // AceWiki is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009    // even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
010    // Lesser General Public License for more details.
011    // 
012    // You should have received a copy of the GNU Lesser General Public License along with AceWiki. If
013    // not, see http://www.gnu.org/licenses/.
014    
015    package ch.uzh.ifi.attempto.preditor;
016    
017    import nextapp.echo.app.Border;
018    import nextapp.echo.app.Color;
019    import nextapp.echo.app.ContentPane;
020    import nextapp.echo.app.Extent;
021    import nextapp.echo.app.Font;
022    import nextapp.echo.app.Insets;
023    import nextapp.echo.app.WindowPane;
024    import nextapp.echo.extras.app.TabPane;
025    import nextapp.echo.extras.app.event.TabSelectionEvent;
026    import nextapp.echo.extras.app.event.TabSelectionListener;
027    import nextapp.echo.extras.app.layout.TabPaneLayoutData;
028    import ch.uzh.ifi.attempto.echocomp.Style;
029    
030    /**
031     * This class represents a word editor that can be used to create or modify words. It can contain
032     * several tabs for several types of words.
033     * 
034     * @author Tobias Kuhn
035     */
036    public class WordEditorWindow extends WindowPane implements TabSelectionListener {
037            
038            private static final long serialVersionUID = 6805275173727379038L;
039            
040            private String type;
041            private TabPane tabPane = new TabPane();
042            
043            /**
044             * Creates a new word editor window.
045             *<p>
046             * The type argument is for custom use and can be used to describe the type of word to be
047             * created. It can be retrieved later by the <code>getType</code>-method. Otherwise, the type
048             * argument has no effect and the value of the type argument is not shown in the GUI.
049             * 
050             * @param title The title of the window.
051             * @param type The type.
052             * @param width The width of the window (minimum is 400).
053             * @param height The height of the window (minimum is 250).
054             */
055            public WordEditorWindow(String title, String type, int width, int height) {
056                    this.type = type;
057                    if (width < 400) width = 400;
058                    if (height < 250) height = 250;
059                    setModal(true);
060                    setTitle(title);
061                    setTitleFont(new Font(Style.fontTypeface, Font.ITALIC, new Extent(13)));
062                    setWidth(new Extent(width));
063                    setHeight(new Extent(height));
064                    setResizable(false);
065                    setTitleBackground(Style.windowTitleBackground);
066                    setStyleName("Default");
067                    
068                    tabPane.setInsets(new Insets(10, 12, 10, 0));
069                    tabPane.setTabPosition(TabPane.TAB_POSITION_TOP);
070                    tabPane.setBorder(new Border(0, Color.BLACK, Border.STYLE_SOLID));
071                    tabPane.setFont(new Font(Style.fontTypeface, Font.ITALIC, new Extent(13)));
072                    tabPane.setTabActiveForeground(Color.BLACK);
073                    tabPane.setTabInactiveBackground(Style.shadedBackground);
074                    tabPane.setTabInactiveForeground(Style.darkDisabled);
075                    tabPane.setTabRolloverEnabled(true);
076                    tabPane.setTabRolloverForeground(Color.BLACK);
077                    tabPane.setTabRolloverBackground(Style.lightBackground);
078                    //tabPane.setTabHeight(new Extent(height-103));
079                    tabPane.addTabSelectionListener(this);
080                    
081                    ContentPane cPane = new ContentPane();
082                    cPane.setInsets(new Insets(10, 0));
083                    cPane.add(tabPane);
084                    
085                    add(cPane);
086            }
087            
088            /**
089             * Creates a new word editor window.
090             * 
091             * @param title The title of the window.
092             * @param width The width of the window (minimum is 400).
093             * @param height The height of the window (minimum is 250).
094             */
095            public WordEditorWindow(String title, int width, int height) {
096                    this(title, null, width, height);
097            }
098            
099            /**
100             * Creates a new word editor window.
101             * 
102             * @param title The title of the window.
103             * @param type The type.
104             */
105            public WordEditorWindow(String title, String type) {
106                    this(title, type, 753, 503);
107            }
108            
109            /**
110             * Creates a new word editor window.
111             * 
112             * @param title The title of the window.
113             */
114            public WordEditorWindow(String title) {
115                    this(title, null, 753, 503);
116            }
117            
118            /**
119             * Returns the type of the word editor window or null if no type has been assigned.
120             * 
121             * @return The type.
122             */
123            public String getType() {
124                    return type;
125            }
126            
127            /**
128             * Adds a new tab containing the given word editor form.
129             * 
130             * @param form The form to be shown in a new tab.
131             */
132            public void addTab(WordEditorForm form) {
133                    TabPaneLayoutData layout = new TabPaneLayoutData();
134                    layout.setTitle(form.getTitle());
135                    form.setLayoutData(layout);
136                    tabPane.add(form);
137                    if (tabPane.getComponentCount() == 1) {
138                            tabPane.setActiveTabIndex(0);
139                    }
140                    doFocus();
141            }
142            
143            /**
144             * Returns the form of the currently selected tab.
145             * 
146             * @return The current tab.
147             */
148            public WordEditorForm getCurrentTab() {
149                    return (WordEditorForm) tabPane.getComponent(tabPane.getActiveTabIndex());
150            }
151            
152            private void doFocus() {
153                    getCurrentTab().doFocus();
154            }
155            
156            public void tabSelected(TabSelectionEvent e) {
157                    doFocus();
158            }
159            
160    }