~ubuntu-branches/debian/squeeze/latexdraw/squeeze

« back to all changes in this revision

Viewing changes to latexDraw/ui/codeEditorPane/AbstractCodeEditorPane.java

  • Committer: Bazaar Package Importer
  • Author(s): Stuart Prescott
  • Date: 2009-05-03 23:49:35 UTC
  • Revision ID: james.westby@ubuntu.com-20090503234935-cls7n48x018g0vk2
Tags: upstream-2.0.2+1
ImportĀ upstreamĀ versionĀ 2.0.2+1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package latexDraw.ui.codeEditorPane;
 
2
 
 
3
import static latexDraw.ui.CodePanel.LABEL_COPY_SELECTION_CODE;
 
4
 
 
5
import java.awt.event.FocusEvent;
 
6
import java.awt.event.MouseEvent;
 
7
import java.awt.event.MouseListener;
 
8
 
 
9
import javax.swing.JButton;
 
10
import javax.swing.JEditorPane;
 
11
 
 
12
import latexDraw.ui.CodePanel;
 
13
import latexDraw.util.LaTeXDrawPoint2D;
 
14
 
 
15
 
 
16
/** 
 
17
 * Defines an abstract model of code editor pane.<br>
 
18
 *<br>
 
19
 * This file is part of LaTeXDraw<br>
 
20
 * Copyright (c) 2005-2008 Arnaud BLOUIN<br>
 
21
 *<br>
 
22
 *  LaTeXDraw is free software; you can redistribute it and/or modify
 
23
 *  it under the terms of the GNU General Public License as published by
 
24
 *  the Free Software Foundation; either version 2 of the License, or
 
25
 *  any later version.<br>
 
26
 *<br>
 
27
 *  LaTeXDraw is distributed without any warranty; without even the 
 
28
 *  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
 
29
 *  PURPOSE. See the GNU General Public License for more details.<br>
 
30
 *<br>
 
31
 * 06/03/07<br>
 
32
 * @author Arnaud BLOUIN<br>
 
33
 * @version 2.0.0<br>
 
34
 */
 
35
public abstract class AbstractCodeEditorPane extends JEditorPane implements MouseListener
 
36
{
 
37
        private static final long       serialVersionUID        = 1L;
 
38
 
 
39
        protected CodePanel codePanel;
 
40
        
 
41
        /** Corresponds to the beginning of the code of the figure: \begin{pspicture}... */
 
42
        protected String begin;
 
43
        
 
44
        /** Corresponds to the body of the code : the definitions of the figures (lines, dots, ...)*/
 
45
        protected String body;
 
46
        
 
47
        /** Defines the start of the code. */
 
48
        protected String beginCodeTag;
 
49
        
 
50
        /** Corresponds to the end of the code of the figure. */
 
51
        protected String endCodeTag;
 
52
        
 
53
        
 
54
        
 
55
        /**
 
56
         * The constructor.
 
57
         * @param codePanel The associated codePanel.
 
58
         */
 
59
        public AbstractCodeEditorPane(CodePanel codePanel)
 
60
        {
 
61
                super();
 
62
                setEditable(false);
 
63
                addMouseListener(this);
 
64
                setDragEnabled(true);
 
65
                this.codePanel = codePanel;
 
66
                begin = "";//$NON-NLS-1$
 
67
                body = "";//$NON-NLS-1$
 
68
                setBeginCodeTag();
 
69
                setEndCodeTag();
 
70
        }
 
71
        
 
72
        
 
73
        
 
74
        
 
75
        /**
 
76
         * Update the buttons managing the copy of the code.
 
77
         * @since 1.9
 
78
         */
 
79
        public void updateButtonsCopy()
 
80
        {
 
81
                String text = getSelectedText();
 
82
                boolean enable = text!=null && !text.equals("");//$NON-NLS-1$
 
83
                codePanel.getButtonCopySel().setEnabled(enable); 
 
84
        }
 
85
        
 
86
        
 
87
        
 
88
        public void mouseClicked(MouseEvent e)
 
89
        {
 
90
                updateButtonsCopy();
 
91
        }
 
92
 
 
93
 
 
94
 
 
95
 
 
96
        public void mousePressed(MouseEvent e)
 
97
        {
 
98
                /* No code required */          
 
99
        }
 
100
 
 
101
 
 
102
 
 
103
 
 
104
        public void mouseReleased(MouseEvent e)
 
105
        {
 
106
                updateButtonsCopy();
 
107
        }
 
108
 
 
109
 
 
110
 
 
111
 
 
112
        public void mouseEntered(MouseEvent e)
 
113
        {
 
114
                /* No code required */
 
115
        }
 
116
 
 
117
 
 
118
 
 
119
 
 
120
        public void mouseExited(MouseEvent e)
 
121
        {
 
122
                /* No code required */
 
123
        }
 
124
 
 
125
 
 
126
 
 
127
        @Override
 
128
        protected void processFocusEvent(FocusEvent e)
 
129
        {
 
130
                super.processFocusEvent(e);
 
131
        
 
132
                if(e.getID()==FocusEvent.FOCUS_LOST)
 
133
                {
 
134
                        Object o = e.getOppositeComponent();
 
135
 
 
136
                        if(!(o instanceof JButton && ((JButton)o).getActionCommand().equals(LABEL_COPY_SELECTION_CODE)))
 
137
                        {
 
138
                                select(0, 0);
 
139
                                codePanel.getButtonCopySel().setEnabled(false);
 
140
                        }
 
141
                }
 
142
        }
 
143
        
 
144
        
 
145
        
 
146
        /**
 
147
         * Update the text of the panel.
 
148
         */
 
149
        public abstract void updateText();
 
150
        
 
151
        
 
152
        
 
153
        /**
 
154
         * Set the beginning of the code generated.
 
155
         * @param SW The top right point.
 
156
         * @param NE The bottom left point.
 
157
         * @param pixPerCm The definition level of the drawing.
 
158
         * @param origin The origin point of the system of coordinates.
 
159
         */
 
160
        public abstract void setStart(LaTeXDrawPoint2D SW, LaTeXDrawPoint2D NE, float pixPerCm, LaTeXDrawPoint2D origin);
 
161
        
 
162
        
 
163
        
 
164
        /**
 
165
         * Set the body (between the beginning and the end) of the code.
 
166
         * @param code The new code.
 
167
         */
 
168
        public void setBody(String code)
 
169
        {
 
170
                body = code;
 
171
                updateText();
 
172
        }
 
173
        
 
174
        
 
175
        /**
 
176
         * Empty the panel.
 
177
         */
 
178
        public void setEmpty()
 
179
        {
 
180
                body=""; //$NON-NLS-1$
 
181
                setText("");//$NON-NLS-1$
 
182
        }
 
183
 
 
184
        
 
185
        
 
186
        /**
 
187
         * Set the tag which will be defined the start of the code.
 
188
         * @since 2.0.0
 
189
         */
 
190
        protected abstract void setBeginCodeTag();
 
191
        
 
192
        
 
193
        /**
 
194
         * Set the tag which will be defined the end of the code.
 
195
         * @since 2.0.0
 
196
         */
 
197
        protected abstract void setEndCodeTag();
 
198
}