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
|
public void actionPerformed(ActionEvent e) {
this.document=textPaneTexte.getStyledDocument();
String textSelect = textPaneTexte.getSelectedText();
int positionStart = this.textPaneTexte.getSelectionStart();
int positionEnd = this.textPaneTexte.getSelectionEnd();
this.style=this.document.getLogicalStyle(textPaneTexte.getCaretPosition());
System.out.println(positionStart+"-"+positionEnd+"--"+textPaneTexte.getCaretPosition());
if(this.textPaneTexte.getCaretPosition() == positionEnd) {
this.textPaneTexte.setCaretPosition(positionStart);
this.textPaneTexte.select(positionEnd,positionStart);
System.out.println(this.textPaneTexte.getSelectedText());
}
this.attributes = new SimpleAttributeSet(this.textPaneTexte.getCharacterAttributes());
System.out.println(textPaneTexte.getSelectionStart()+"-"+textPaneTexte.getSelectionEnd()+"--"+textPaneTexte.getCaretPosition());
System.out.println("avant update");
for (Enumeration en = this.attributes.getAttributeNames(); en.hasMoreElements() ;) {
System.out.println(en.nextElement());
}
//JPane.getStyleDocument().setCharacterAttributes(debut,longueur,attribut_pasgras,true)
if(e.getSource() == this.buttonTextAlignLeft) {
StyleConstants.setAlignment(this.style, StyleConstants.ALIGN_LEFT);
}
else if(e.getSource() == this.buttonTextAlignCenter) {
StyleConstants.setAlignment(this.style, StyleConstants.ALIGN_CENTER);
}
else if(e.getSource() == this.buttonTextAlignRight) {
StyleConstants.setAlignment(this.style, StyleConstants.ALIGN_RIGHT);
}
else if(e.getSource() == this.buttonTextAlignJustify) {
StyleConstants.setAlignment(this.style, StyleConstants.ALIGN_JUSTIFIED);
}
else if(e.getSource() == this.buttonTextBold) {
if(StyleConstants.isBold(this.attributes))
this.attributes.addAttribute(StyleConstants.CharacterConstants.Bold, Boolean.FALSE);
else
this.attributes.addAttribute(StyleConstants.CharacterConstants.Bold, Boolean.TRUE);
}
else if(e.getSource() == this.buttonTextItalic) {
if(StyleConstants.isItalic(this.attributes))
this.attributes.addAttribute(StyleConstants.CharacterConstants.Italic, Boolean.FALSE);
else
this.attributes.addAttribute(StyleConstants.CharacterConstants.Italic, Boolean.TRUE);
}
else if(e.getSource() == this.buttonTextUnderline) {
if(StyleConstants.isUnderline(this.attributes))
this.attributes.addAttribute(StyleConstants.CharacterConstants.Underline, Boolean.FALSE);
else
this.attributes.addAttribute(StyleConstants.CharacterConstants.Underline, Boolean.TRUE);
}
else if(e.getSource() == this.comboBoxPolice) {
StyleConstants.setFontFamily(this.style, (String)this.comboBoxPolice.getSelectedItem());
}
else if(e.getSource() == this.comboBoxTailleTexte) {
StyleConstants.setFontSize(this.style, Integer.parseInt((String)this.comboBoxTailleTexte.getSelectedItem()));
}
this.textTampon = textSelect;
this.previousPosition = positionStart;
this.textPaneTexte.setCharacterAttributes(attributes, true);
System.out.println("fin\napres update:");
for (Enumeration en = this.attributes.getAttributeNames(); en.hasMoreElements() ;) {
System.out.println(en.nextElement());
}
} |
Partager