Files
tarisan_gitea/Fuentes/com/tarisan/chipcard/gui/Editor.java
T
2025-06-09 13:37:06 +02:00

127 lines
5.8 KiB
Java

/*
* Created on 28-sep-2004
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package com.tarisan.chipcard.gui;
import java.awt.*;
import javax.swing.*;
import javax.swing.text.*;
public class Editor extends JScrollPane
{
EditorTexto edit = new EditorTexto();;
public Editor()
{
super();
setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_AS_NEEDED);
setVerticalScrollBarPolicy(VERTICAL_SCROLLBAR_AS_NEEDED);
getViewport().add(edit);
}
public void remove()
{
edit.remove();
}
public void append(String cadena, Color color)
{
edit.append(cadena+"\r",color);
}
public class EditorTexto extends JTextPane
{
Style Linea,Titulo; // Estilos
Style s;
StyleContext sc; // Contenedor de estilos
DefaultStyledDocument doc; // Plantilla de Documento
Color color= new Color(0) ; // color texto chat
public void remove()
{
try
{
doc.remove(0,doc.getLength());
}
catch(BadLocationException x)
{
//System.out.println("no sé");
}
}
public EditorTexto()
{
super();
sc = new StyleContext();
doc= new DefaultStyledDocument(sc);
Editable(false);
DeficionEstilos();
setDocument(doc);
}
public void Editable(boolean flag) // Estado de Edicion del NewChat
{
if(!flag)
{
setEditable(false);
setCaretColor(Color.white);
setSelectionColor(Color.BLUE);
}
else
{
setEditable(true);
}
}
public void append(String cadena, Color color)
{
Style tmp;
tmp = sc.getStyle("tmp"+ color /*Integer.toString(color)*/);
if(tmp == null) // el estilo no existe lo añadimos
{
tmp = sc.getStyle("Linea");
sc.addStyle("tmp"+color,tmp);
StyleConstants.setForeground(tmp, color);
}
else
{
StyleConstants.setForeground(tmp, color);
}
try
{
doc.insertString(doc.getLength(), cadena,tmp);
}
catch (BadLocationException e)
{
System.err.println("Internal error: " + e);
}
}
public void append(String cadena, String Estilo)
{
try
{
doc.insertString(doc.getLength(), cadena,null);
doc.setLogicalStyle(doc.getLength()-1, sc.getStyle(Estilo));
}
catch (BadLocationException e)
{
System.err.println("Internal error: " + e);
}
}
public void DeficionEstilos()
{
// Estilo de Linea
Linea = sc.getStyle(StyleContext.DEFAULT_STYLE);
Linea = sc.addStyle("Linea", Linea);
StyleConstants.setFontFamily(Linea, "Helvetica");
StyleConstants.setBold(Linea, true);
StyleConstants.setAlignment(Linea, StyleConstants.ALIGN_LEFT);
StyleConstants.setSpaceAbove(Linea, 10);
StyleConstants.setSpaceBelow(Linea, 10);
StyleConstants.setFontSize(Linea, 12);
StyleConstants.setForeground(Linea, new Color(255,255,255));
}
}
}