1
package latexDraw.ui.codeEditorPane;
3
import static latexDraw.ui.CodePanel.LABEL_COPY_SELECTION_CODE;
5
import java.awt.event.FocusEvent;
6
import java.awt.event.MouseEvent;
7
import java.awt.event.MouseListener;
9
import javax.swing.JButton;
10
import javax.swing.JEditorPane;
12
import latexDraw.ui.CodePanel;
13
import latexDraw.util.LaTeXDrawPoint2D;
17
* Defines an abstract model of code editor pane.<br>
19
* This file is part of LaTeXDraw<br>
20
* Copyright (c) 2005-2008 Arnaud BLOUIN<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>
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>
32
* @author Arnaud BLOUIN<br>
35
public abstract class AbstractCodeEditorPane extends JEditorPane implements MouseListener
37
private static final long serialVersionUID = 1L;
39
protected CodePanel codePanel;
41
/** Corresponds to the beginning of the code of the figure: \begin{pspicture}... */
42
protected String begin;
44
/** Corresponds to the body of the code : the definitions of the figures (lines, dots, ...)*/
45
protected String body;
47
/** Defines the start of the code. */
48
protected String beginCodeTag;
50
/** Corresponds to the end of the code of the figure. */
51
protected String endCodeTag;
57
* @param codePanel The associated codePanel.
59
public AbstractCodeEditorPane(CodePanel codePanel)
63
addMouseListener(this);
65
this.codePanel = codePanel;
66
begin = "";//$NON-NLS-1$
67
body = "";//$NON-NLS-1$
76
* Update the buttons managing the copy of the code.
79
public void updateButtonsCopy()
81
String text = getSelectedText();
82
boolean enable = text!=null && !text.equals("");//$NON-NLS-1$
83
codePanel.getButtonCopySel().setEnabled(enable);
88
public void mouseClicked(MouseEvent e)
96
public void mousePressed(MouseEvent e)
98
/* No code required */
104
public void mouseReleased(MouseEvent e)
112
public void mouseEntered(MouseEvent e)
114
/* No code required */
120
public void mouseExited(MouseEvent e)
122
/* No code required */
128
protected void processFocusEvent(FocusEvent e)
130
super.processFocusEvent(e);
132
if(e.getID()==FocusEvent.FOCUS_LOST)
134
Object o = e.getOppositeComponent();
136
if(!(o instanceof JButton && ((JButton)o).getActionCommand().equals(LABEL_COPY_SELECTION_CODE)))
139
codePanel.getButtonCopySel().setEnabled(false);
147
* Update the text of the panel.
149
public abstract void updateText();
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.
160
public abstract void setStart(LaTeXDrawPoint2D SW, LaTeXDrawPoint2D NE, float pixPerCm, LaTeXDrawPoint2D origin);
165
* Set the body (between the beginning and the end) of the code.
166
* @param code The new code.
168
public void setBody(String code)
178
public void setEmpty()
180
body=""; //$NON-NLS-1$
181
setText("");//$NON-NLS-1$
187
* Set the tag which will be defined the start of the code.
190
protected abstract void setBeginCodeTag();
194
* Set the tag which will be defined the end of the code.
197
protected abstract void setEndCodeTag();