1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
| public class Edition_Panel extends JPanel{
/** Fields list */
public static JTextField titreAss;
public static JTextPane txtPane;
public JLabel labelColor; //la couleur
* Creates an instance of the CListeners class.
* @see CListeners
*/
Traitement_Edition m_CListeners ;
/**
* Creates an instance of the UndoManager class.
* @see UndoManager
*/
public UndoManager m_Undo = new UndoManager();
/**
* Creates an instance of the DefaultStyledDocument class.
* @see DefaultStyledDocument
*/
/**
* Creates an instance of the RTFEditorKit class.
* @see RTFEditorKit
*/
public RTFEditorKit m_Rtf;
/**
* Defines the constructor of FrameEditorTxT class.
* @param sTitle
*/
public Edition_Panel(String t,Object position,Font f,boolean exo,boolean ass,DefaultStyledDocument m_Document ){
super();
//Espace_Edition text_Panel = new Espace_Edition("Titre Formation",FlowLayout.LEFT);
m_CListeners = new Traitement_Edition(this);
/*try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
SwingUtilities.updateComponentTreeUI(this);
}
catch (Exception e) {
System.out.println("FrmUsers.FrmUsers : impossible d'appliquer le thème du système");
}*/
JPanel panTools = new JPanel();
panTools.setLayout(new FlowLayout());
panTools.add(Display_ToolBar);
panTools.add(File_ToolBar);
this.setBorder(BorderFactory.createRaisedBevelBorder());
//this.add(text_Panel);
JPanel panTitre = new JPanel();
JPanel panText = new JPanel();
BoxLayout bj = new BoxLayout (this, BoxLayout.Y_AXIS);
this.setLayout(bj);
//this.setLayout(new BorderLayout(20,20));
this.add(panTitre);
this.add(panTools);
this.add(panText); /////Ajouter toujours le panels d'ecriture à la fin
panTitre.setLayout(new FlowLayout(FlowLayout.LEFT));
//panTitre.setLayout(new FlowLayout());
titre=new JLabel(t);
titre.setFont(f);
this.setPreferredSize(new Dimension(700, 500));
this.setMaximumSize(new Dimension(700, 500));
this.setMinimumSize(new Dimension(700, 500));
panTitre.add(titre,position);
panTools.setPreferredSize(new Dimension(700,50));
panTitre.setPreferredSize(new Dimension(700,40));
panText.setPreferredSize(new Dimension(700,250));
m_Rtf = new RTFEditorKit();
StyleContext context = new StyleContext();
m_Document = new DefaultStyledDocument(context);
panText.setLayout(new BorderLayout());
txtPane= new JTextPane();
txtPane.setMargin(new Insets(10, 10, 10, 10));
txtPane.addCaretListener(m_CListeners);
txtPane.setEditorKit(m_Rtf);
txtPane.setDocument(m_Document);
if(exo==true)
{
panText.add(enc,BorderLayout.NORTH);
this.add(panExo);
panText.setPreferredSize(new Dimension(700,150));
this.setPreferredSize(new Dimension(700, 250));
this.setMaximumSize(new Dimension(700, 250));
this.setMinimumSize(new Dimension(700, 250));
}
if(ass==true)
{
panTitre.remove(titre);
panTitre.add(titreAss);
//titreAss.addPropertyChangeListener(m_CListeners);
}
Font oFont = new Font(txtPane.getFont().getFamily(), txtPane.getFont().getStyle(), 12);
txtPane.setFont(oFont);
txtPane.getDocument().addUndoableEditListener(m_CListeners);
panText.add(txtPane,BorderLayout.SOUTH);
//panText.setBackground(new Color(255,0,0));
JScrollPane sclScroll = new JScrollPane(txtPane);
panText.add(sclScroll);
txtPane.addCaretListener(new CaretListener(){
@Override
public void caretUpdate(CaretEvent e) {
int pos = e.getDot();
int row = 0, column=0;
try {
int length = txtPane.getDocument().getLength();
String text = txtPane.getDocument().getText(0, length).replaceAll("\r", "");
if(pos+1<=text.length()){
text = text.substring(0, pos+1);
column--;
}
while (text.contains("\n")) {
row++;
int start = text.indexOf("\n");
if (text.length() - start >= 1) {
text = text.substring(start+1, text.length());
}
}
column += text.length();
} catch (BadLocationException e1) {
e1.printStackTrace();
}
}
});
//////////////////////////////Vue.Fenetre1.panel21.add(this);
}
public void setTitreGrain(String t){
this.titre.setText(t);
}
public String getTitContenuAss(){
return this.titreAss.getText();
}
public void append(String s) {
try {
Document doc = txtPane.getDocument();
doc.insertString(doc.getLength(), s + "\n", txtPane.getStyle("default"));
} catch (BadLocationException e) {
e.printStackTrace();
}
}
} |
Partager