Вы находитесь на странице: 1из 35

package JheysonMatta_BlogNota;

import java.awt.Font;
import javax.swing.JComboBox;
import javax.swing.JList;
import javax.swing.JTextField;
/**
*
* @author Jheyson Matta
*/
public class Estilo {
/*Con JComboBox*/
public static int leeTamao1(JComboBox cbTamao) {
return Integer.parseInt(cbTamao.getSelectedItem().toString());
}
public static String leeFuente1(JComboBox cbFuente) {
return cbFuente.getSelectedItem().toString();
}
public static int leeEstilo1(JComboBox cbEstilo) {
int estilo = cbEstilo.getSelectedIndex();
switch (estilo) {
case 1:
return Font.PLAIN;
case 2:
return Font.BOLD;
case 3:
return Font.ITALIC;
case 4:
return Font.BOLD + Font.ITALIC;
default:
return 0;
}
}
/*Con JList y JTextField*/
public static int leeTamao2(JTextField txtTamao) {
return Integer.parseInt(txtTamao.getText());
}
public static String leeFuente2(JTextField txtFuente) {
String fuentes = null;
try {
fuentes = txtFuente.getText();
} catch (Exception e) {
System.out.println(e.toString());
}
return fuentes;
}
public static int leeEstilo2(JList lsEstilo) {
int estilo = lsEstilo.getSelectedIndex();
switch (estilo) {
case 1:
return Font.PLAIN;
case 2:
return Font.BOLD;
case 3:
return Font.ITALIC;
case 4:
return Font.BOLD + Font.ITALIC;
default:
return 0;
}
}
}
--------------------------------------------------------------------------------
---------------------------------------
package JheysonMatta_BlogNota;
/**
*
* @author Jheyson Matta
*/
public class Funciones {
static String palabras;
static String ruta;
public static boolean buscarPalabra(String texto, String palabra) {
boolean encontrado = texto.contains(palabra);
String res = null;
if (palabra.equalsIgnoreCase(texto)) {
res = texto;
}
if (encontrado) {
System.out.println("Encontrado la palabra " + true + " y la palabra
es " + res);
} else {
System.out.println("No encontrado");
}
return encontrado;
}
}
--------------------------------------------------------------------------------
------------------------------------
package JheysonMatta_BlogNota;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
/**
*
* @author Jheyson Matta
*/
public class Notepad {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws ClassNotFoundException, Instan
tiationException, IllegalAccessException, UnsupportedLookAndFeelException {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAnd
Feel");
frmNotepad notepad = new frmNotepad();
notepad.setLocationRelativeTo(null);
notepad.setVisible(true);
}
}
--------------------------------------------------------------------------------
----------------------------------------
package JheysonMatta_BlogNota;
import java.awt.event.KeyEvent;
import javax.swing.JOptionPane;
/**
*
* @author Jheyson Matta
*/
public class dlgBuscar extends javax.swing.JDialog {
public dlgBuscar(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {
jLabel1 = new javax.swing.JLabel();
txtBuscar = new javax.swing.JTextField();
btnBuscar = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
chbMay_Min = new javax.swing.JCheckBox();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Buscar");
addKeyListener(new java.awt.event.KeyAdapter() {
public void keyReleased(java.awt.event.KeyEvent evt) {
formKeyReleased(evt);
}
});
jLabel1.setText("Buscar:");
txtBuscar.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
txtBuscarKeyPressed(evt);
}
});
btnBuscar.setText("Buscar");
btnBuscar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnBuscarActionPerformed(evt);
}
});
jButton2.setText("Cancelar");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
chbMay_Min.setText("Concidir con maysculas y minsculas");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentP
ane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING
)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali
gnment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacem
ent.RELATED)
.addComponent(txtBuscar, javax.swing.GroupLayout.DEFAULT
_SIZE, 231, Short.MAX_VALUE))
.addComponent(chbMay_Min))
.addGap(10, 10, 10)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali
gnment.LEADING, false)
.addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE
, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnBuscar, javax.swing.GroupLayout.PREFERRED_S
IZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING
)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali
gnment.BASELINE)
.addComponent(jLabel1)
.addComponent(txtBuscar, javax.swing.GroupLayout.PREFERRED_S
IZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZ
E)
.addComponent(btnBuscar))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali
gnment.BASELINE)
.addComponent(jButton2)
.addComponent(chbMay_Min))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX
_VALUE))
);
pack();
}// </editor-fold>
private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
if(chbMay_Min.isSelected()==true){
buscar();
}
else{

}
}
void buscarMay_Min(){
String palabraBuscar = txtBuscar.getText().trim();
if (palabraBuscar.length() > 0) {
String contenido = frmNotepad.txaSalida.getText();
int indice = contenido.indexOf(palabraBuscar, 0);
if (indice >= 0) {
try {
int ini = indice;
int fin = indice + palabraBuscar.length();
frmNotepad.txaSalida.setCaretPosition(fin);
frmNotepad.txaSalida.select(ini, fin);
} catch (Exception e) {
e.printStackTrace();
}
} else {
JOptionPane.showMessageDialog(this, "No se encontro la palabra",
"Mensaje", JOptionPane.INFORMATION_MESSAGE);
txtBuscar.selectAll();
}
} else {
JOptionPane.showMessageDialog(null, "Vuelva a escribir");
}
}

void buscar(){
String palabraBuscar = txtBuscar.getText().trim();
if (palabraBuscar.length() > 0) {
String contenido = frmNotepad.txaSalida.getText();
int indice = contenido.indexOf(palabraBuscar, 0);
if (indice >= 0){
try {
int ini = indice;
int fin = indice + palabraBuscar.length();
frmNotepad.txaSalida.setCaretPosition(fin);
frmNotepad.txaSalida.select(ini, fin);
} catch (Exception e) {
e.printStackTrace();
}
} else {
JOptionPane.showMessageDialog(this, "No se encontro la palabra",
"Mensaje", JOptionPane.INFORMATION_MESSAGE);
txtBuscar.selectAll();
}
} else {
JOptionPane.showMessageDialog(null, "Vuelva a escribir");
}
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
this.dispose();
}
private void txtBuscarKeyPressed(java.awt.event.KeyEvent evt) {

// TODO add your handling code here:
if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
btnBuscar.doClick();
}
}
private void formKeyReleased(java.awt.event.KeyEvent evt) {

// TODO add your handling code here:
if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
this.dispose();
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting cod
e (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the d
efault look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lo
okandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIMana
ger.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(dlgBuscar.class.getName()).log(ja
va.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(dlgBuscar.class.getName()).log(ja
va.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(dlgBuscar.class.getName()).log(ja
va.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(dlgBuscar.class.getName()).log(ja
va.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the dialog */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
dlgBuscar dialog = new dlgBuscar(new javax.swing.JFrame(), true)
;
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btnBuscar;
private javax.swing.JCheckBox chbMay_Min;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JTextField txtBuscar;
// End of variables declaration
}
--------------------------------------------------------------------------------
---------------------------------------------ackage JheysonMatta_BlogNota;
import java.awt.Font;
/**
*
* @author Jheyson Matta
*/
public class dlgFuente extends javax.swing.JDialog {
public dlgFuente(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
inicializarListas();
}
void inicializarListas() {
lsTamao.setSelectedIndex(4);
lsEstilo.setSelectedIndex(1);
lsFuente.setSelectedIndex(1);
txtTamao.setText(String.valueOf(lsTamao.getSelectedValue()));
txtFuente.setText(String.valueOf(lsFuente.getSelectedValue()));
txtEstilo.setText(String.valueOf(lsEstilo.getSelectedValue()));
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
txtFuente = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
lsFuente = new javax.swing.JList();
jLabel2 = new javax.swing.JLabel();
jPanel2 = new javax.swing.JPanel();
txtEstilo = new javax.swing.JTextField();
jScrollPane2 = new javax.swing.JScrollPane();
lsEstilo = new javax.swing.JList();
jLabel3 = new javax.swing.JLabel();
jPanel3 = new javax.swing.JPanel();
txtTamao = new javax.swing.JTextField();
jScrollPane3 = new javax.swing.JScrollPane();
lsTamao = new javax.swing.JList();
jPanel4 = new javax.swing.JPanel();
lblMuestra = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Fuente");
jLabel1.setText("Fuente:");
jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
jPanel1.setLayout(null);
jPanel1.add(txtFuente);
txtFuente.setBounds(0, 0, 140, 20);
lsFuente.setModel(new javax.swing.AbstractListModel() {
String[] strings = { "Monospaced", "Arial", "Arial Black", "Garamond
", "Comic sans MS", "Times New Roman" };
public int getSize() { return strings.length; }
public Object getElementAt(int i) { return strings[i]; }
});
lsFuente.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
lsFuenteMouseClicked(evt);
}
});
jScrollPane1.setViewportView(lsFuente);
jPanel1.add(jScrollPane1);
jScrollPane1.setBounds(0, 20, 140, 140);
jLabel2.setText("Estilo:");
jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
jPanel2.setLayout(null);
jPanel2.add(txtEstilo);
txtEstilo.setBounds(0, 0, 120, 20);
lsEstilo.setModel(new javax.swing.AbstractListModel() {
String[] strings = { "Normal", "Negrita", "Italic", "Negrita Italic"
};
public int getSize() { return strings.length; }
public Object getElementAt(int i) { return strings[i]; }
});
lsEstilo.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
lsEstiloMouseClicked(evt);
}
});
jScrollPane2.setViewportView(lsEstilo);
jPanel2.add(jScrollPane2);
jScrollPane2.setBounds(0, 20, 120, 140);
jLabel3.setText("Tamao:");
jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());
jPanel3.setLayout(null);
jPanel3.add(txtTamao);
txtTamao.setBounds(0, 0, 60, 20);
lsTamao.setModel(new javax.swing.AbstractListModel() {
String[] strings = { "8", "9", "10", "11", "12", "14", "16", "18", "
20", "22", "24", "26", "28", "36", "28", "72" };
public int getSize() { return strings.length; }
public Object getElementAt(int i) { return strings[i]; }
});
lsTamao.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
lsTamaoMouseClicked(evt);
}
});
jScrollPane3.setViewportView(lsTamao);
jPanel3.add(jScrollPane3);
jScrollPane3.setBounds(0, 20, 60, 140);
jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Muestra"
));
lblMuestra.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
lblMuestra.setText("Texto de muestra");
javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPan
el4);
jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.
LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.addComponent(lblMuestra, javax.swing.GroupLayout.DEFAULT_SIZE,
150, Short.MAX_VALUE)
.addContainerGap())
);
jPanel4Layout.setVerticalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.
LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.addComponent(lblMuestra, javax.swing.GroupLayout.DEFAULT_SIZE,
30, Short.MAX_VALUE)
.addContainerGap())
);
jButton1.setText("Cancelar");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("Aceptar");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentP
ane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING
)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali
gnment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLa
yout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFE
RRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLa
yout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFE
RRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacem
ent.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLa
yout.Alignment.LEADING)
.addComponent(jLabel3)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFE
RRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout
.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLa
yout.Alignment.LEADING)
.addComponent(jPanel4, javax.swing.GroupLayout.Align
ment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.D
EFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING
, layout.createSequentialGroup()
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.Compone
ntPlacement.RELATED)
.addComponent(jButton1)))))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING
)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali
gnment.BASELINE)
.addComponent(jLabel1)
.addComponent(jLabel2)
.addComponent(jLabel3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali
gnment.LEADING, false)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
159, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, j
avax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali
gnment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX
_VALUE))
);
pack();
}// </editor-fold>
private void lsEstiloMouseClicked(java.awt.event.MouseEvent evt) {

// TODO add your handling code here:
txtEstilo.setText(String.valueOf(lsEstilo.getSelectedValue().toString())
);
darFormato();
}
private void lsTamaoMouseClicked(java.awt.event.MouseEvent evt) {

// TODO add your handling code here:
txtTamao.setText(String.valueOf(lsTamao.getSelectedValue().toString()));
darFormato();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
this.dispose();
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
darFormato2();
this.dispose();
}
private void lsFuenteMouseClicked(java.awt.event.MouseEvent evt) {

// TODO add your handling code here:
txtFuente.setText(String.valueOf(lsFuente.getSelectedValue().toString())
);
darFormato();
}
public void darFormato() {
String fuente = Estilo.leeFuente2(txtFuente);
int estilo = Estilo.leeEstilo2(lsEstilo);
int tamao = Estilo.leeTamao2(txtTamao);
Font miFuente = new Font(fuente, estilo, tamao);
lblMuestra.setFont(miFuente);
}
public void darFormato2() {
String fuente = Estilo.leeFuente2(txtFuente);
int estilo = Estilo.leeEstilo2(lsEstilo);
int tamao = Estilo.leeTamao2(txtTamao);
Font miFuente = new Font(fuente, estilo, tamao);
frmNotepad.txaSalida.setFont(miFuente);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting cod
e (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the d
efault look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lo
okandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIMana
ger.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(dlgFuente.class.getName()).log(ja
va.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(dlgFuente.class.getName()).log(ja
va.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(dlgFuente.class.getName()).log(ja
va.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(dlgFuente.class.getName()).log(ja
va.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the dialog */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
dlgFuente dialog = new dlgFuente(new javax.swing.JFrame(), true)
;
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JLabel lblMuestra;
private javax.swing.JList lsEstilo;
private javax.swing.JList lsFuente;
private javax.swing.JList lsTamao;
private javax.swing.JTextField txtEstilo;
private javax.swing.JTextField txtFuente;
private javax.swing.JTextField txtTamao;
// End of variables declaration
}
--------------------------------------------------------------------------------
--------------------------------------package JheysonMatta_BlogNota;
import java.awt.event.KeyEvent;
/**
*
* @author Jheyson Matta
*/
public class dlgReemplazar extends javax.swing.JDialog {
public dlgReemplazar(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
txtBuscar = new javax.swing.JTextField();
txtReemplazar = new javax.swing.JTextField();
btnReemplazar = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Reemplazar");
jLabel1.setText("Buscar:");
jLabel2.setText("Reemplazar por:");
txtReemplazar.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
txtReemplazarKeyPressed(evt);
}
});
btnReemplazar.setText("Reemplazar");
btnReemplazar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnReemplazarActionPerformed(evt);
}
});
jButton4.setText("Cancelar");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentP
ane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING
)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali
gnment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(btnReemplazar, javax.swing.GroupLayout.PRE
FERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacem
ent.RELATED)
.addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_
SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLa
yout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2))
.addGap(23, 23, 23)
.addGroup(layout.createParallelGroup(javax.swing.GroupLa
yout.Alignment.LEADING)
.addComponent(txtReemplazar, javax.swing.GroupLayout
.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtBuscar, javax.swing.GroupLayout.PRE
FERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX
_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING
)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali
gnment.BASELINE)
.addComponent(jLabel1)
.addComponent(txtBuscar, javax.swing.GroupLayout.PREFERRED_S
IZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZ
E))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali
gnment.BASELINE)
.addComponent(jLabel2)
.addComponent(txtReemplazar, javax.swing.GroupLayout.PREFERR
ED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED
_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali
gnment.BASELINE)
.addComponent(btnReemplazar)
.addComponent(jButton4))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX
_VALUE))
);
pack();
}// </editor-fold>
private void btnReemplazarActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
String cadena = frmNotepad.txaSalida.getText();
String buscar = txtBuscar.getText();
String reemplazar = txtReemplazar.getText();
frmNotepad.txaSalida.setText(reemplaza(cadena, buscar, reemplazar));
}
private void txtReemplazarKeyPressed(java.awt.event.KeyEvent evt) {

// TODO add your handling code here:
if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
btnReemplazar.doClick();
}
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
this.dispose();
}
public static String reemplaza(String cadena, String buscar, String reemplaz
ar) {
return cadena.replaceAll(buscar, reemplazar);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting cod
e (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the d
efault look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lo
okandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIMana
ger.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(dlgReemplazar.class.getName()).lo
g(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(dlgReemplazar.class.getName()).lo
g(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(dlgReemplazar.class.getName()).lo
g(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(dlgReemplazar.class.getName()).lo
g(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the dialog */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
dlgReemplazar dialog = new dlgReemplazar(new javax.swing.JFrame(
), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btnReemplazar;
private javax.swing.JButton jButton4;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JTextField txtBuscar;
private javax.swing.JTextField txtReemplazar;
// End of variables declaration
}
--------------------------------------------------------------------------------
-------------------------------------
package JheysonMatta_BlogNota;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.event.UndoableEditEvent;
import javax.swing.event.UndoableEditListener;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.text.BadLocationException;
import javax.swing.undo.CannotRedoException;
import javax.swing.undo.CannotUndoException;
import javax.swing.undo.UndoManager;
/**
*
* @author Jheyson Matta
*/
public class frmNotepad extends javax.swing.JFrame {
protected UndoManager undoManager = new UndoManager();
private FileNameExtensionFilter filter = new FileNameExtensionFilter("Archiv
o de texto (*.txt)", "txt");
String titulo = "Bloc de Notas";
String nombreArchivo;
String ruta = "";
int longitud;
int row;
boolean estado = false;
static BufferedReader reader = null;
static JFileChooser file = new JFileChooser();
static File fichero;
static int seleccion;
static String retornoDeCarro = System.getProperty("line.separator");
static String texto;
static PrintWriter writer = null;
/**
* Creates new form frmNotepad
*/
public frmNotepad() {
initComponents();
longitud = 0;
txaSalida.requestFocus();
this.setTitle("Sin ttulo : " + titulo);
lblBarraEstado.setVisible(false);
jSeparator3.setVisible(false);
deshabilitar();
pnlHerramientas.setVisible(false);
estado = false;
System.out.println(estado);
//Leer los eventos rehacer y deshacer
txaSalida.getDocument().addUndoableEditListener(
new UndoableEditListener() {
@Override
public void undoableEditHappened(UndoableEditEvent e) {
undoManager.addEdit(e.getEdit());
}
}
);
//Metodos para deshacer Ctrl + Z
mnDeshacer.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
if (txaSalida.getText().length() != 0) {
undoManager.undo();
deshabilitar();
}
} catch (CannotUndoException cre) {
System.out.println(cre.toString());
}
}
});
//----------------------------------------------
//Metodo para rehacer Ctrl + Y
mnRehacer.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
undoManager.redo();
mnRehacer.setEnabled(false);
} catch (CannotRedoException cre) {
System.out.println(cre.toString());
}
}
});
//------------------------
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {
menuEmergente = new javax.swing.JPopupMenu();
mbnDeshacer = new javax.swing.JMenuItem();
mbnCortar = new javax.swing.JMenuItem();
mbnCopiar = new javax.swing.JMenuItem();
mbnPegar = new javax.swing.JMenuItem();
jSeparator5 = new javax.swing.JPopupMenu.Separator();
mbnSelecAll = new javax.swing.JMenuItem();
mbnAlinear = new javax.swing.JMenuItem();
jScrollPane1 = new javax.swing.JScrollPane();
txaSalida = new javax.swing.JTextArea();
jSeparator3 = new javax.swing.JSeparator();
lblBarraEstado = new javax.swing.JLabel();
pnlHerramientas = new javax.swing.JPanel();
jPanel1 = new javax.swing.JPanel();
btnNuevo = new javax.swing.JButton();
btnAbrir = new javax.swing.JButton();
btnGuardar = new javax.swing.JButton();
btnCopiar = new javax.swing.JButton();
btnCortar = new javax.swing.JButton();
btnPegar = new javax.swing.JButton();
jLabel3 = new javax.swing.JLabel();
cbEstilo = new javax.swing.JComboBox();
jLabel2 = new javax.swing.JLabel();
cbTamao = new javax.swing.JComboBox();
lblFuente = new javax.swing.JLabel();
cbFuente = new javax.swing.JComboBox();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
mnbNuevo = new javax.swing.JMenuItem();
mnbAbrir = new javax.swing.JMenuItem();
mnbGuardar = new javax.swing.JMenuItem();
mnbGuardarComo = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
mnDeshacer = new javax.swing.JMenuItem();
mnRehacer = new javax.swing.JMenuItem();
jSeparator1 = new javax.swing.JPopupMenu.Separator();
mnbCortar = new javax.swing.JMenuItem();
mnbCopiar = new javax.swing.JMenuItem();
mnbPegar = new javax.swing.JMenuItem();
jSeparator2 = new javax.swing.JPopupMenu.Separator();
mnBuscar = new javax.swing.JMenuItem();
mnbReeplazar = new javax.swing.JMenuItem();
mnbIrA = new javax.swing.JMenuItem();
jSeparator4 = new javax.swing.JPopupMenu.Separator();
mnbSelecAll = new javax.swing.JMenuItem();
jMenu3 = new javax.swing.JMenu();
mnbFuente = new javax.swing.JMenuItem();
jMenu4 = new javax.swing.JMenu();
mnbHerramientas = new javax.swing.JMenuItem();
mnbEstado = new javax.swing.JMenuItem();
mbnDeshacer.setText("Deshacer");
menuEmergente.add(mbnDeshacer);
mbnCortar.setText("Cortar");
mbnCortar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mbnCortarActionPerformed(evt);
}
});
menuEmergente.add(mbnCortar);
mbnCopiar.setText("Copiar");
mbnCopiar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mbnCopiarActionPerformed(evt);
}
});
menuEmergente.add(mbnCopiar);
mbnPegar.setText("Pegar");
mbnPegar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mbnPegarActionPerformed(evt);
}
});
menuEmergente.add(mbnPegar);
menuEmergente.add(jSeparator5);
mbnSelecAll.setText("Seleccionar Todo");
mbnSelecAll.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mbnSelecAllActionPerformed(evt);
}
});
menuEmergente.add(mbnSelecAll);
mbnAlinear.setText("Alinear");
mbnAlinear.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mbnAlinearActionPerformed(evt);
}
});
menuEmergente.add(mbnAlinear);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Jheyson Matta - Bloc de Notas");
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
formWindowClosing(evt);
}
});
txaSalida.setColumns(20);
txaSalida.setRows(5);
txaSalida.setComponentPopupMenu(menuEmergente);
txaSalida.addCaretListener(new javax.swing.event.CaretListener() {
public void caretUpdate(javax.swing.event.CaretEvent evt) {
txaSalidaCaretUpdate(evt);
}
});
txaSalida.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyReleased(java.awt.event.KeyEvent evt) {
txaSalidaKeyReleased(evt);
}
});
jScrollPane1.setViewportView(txaSalida);
jSeparator3.setOrientation(javax.swing.SwingConstants.VERTICAL);
lblBarraEstado.setText("Lineas : 1 , Columnas : 1");
pnlHerramientas.setBorder(javax.swing.BorderFactory.createEtchedBorder()
);
jPanel1.setLayout(new java.awt.GridLayout(1, 6));
btnNuevo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon
os/tp_new.png"))); // NOI18N
btnNuevo.setToolTipText("Nuevo");
btnNuevo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnNuevoActionPerformed(evt);
}
});
jPanel1.add(btnNuevo);
btnAbrir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon
os/tp_open.png"))); // NOI18N
btnAbrir.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnAbrirActionPerformed(evt);
}
});
jPanel1.add(btnAbrir);
btnGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ic
onos/tp_save.png"))); // NOI18N
btnGuardar.setToolTipText("Guardar");
btnGuardar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnGuardarActionPerformed(evt);
}
});
jPanel1.add(btnGuardar);
btnCopiar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ico
nos/tp_copy.png"))); // NOI18N
btnCopiar.setToolTipText("Copiar");
btnCopiar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnCopiarActionPerformed(evt);
}
});
jPanel1.add(btnCopiar);
btnCortar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ico
nos/tp_cut.png"))); // NOI18N
btnCortar.setToolTipText("Cortar");
btnCortar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnCortarActionPerformed(evt);
}
});
jPanel1.add(btnCortar);
btnPegar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon
os/tp_paste.png"))); // NOI18N
btnPegar.setToolTipText("Pegar");
btnPegar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnPegarActionPerformed(evt);
}
});
jPanel1.add(btnPegar);
jLabel3.setText("Estilo");
cbEstilo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "N
ormal", "Negrita", "Italic", "Negrita Italic" }));
cbEstilo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cbEstiloActionPerformed(evt);
}
});
jLabel2.setText("Tamao");
cbTamao.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "8",
"9", "10", "11", "12", "14", "16", "18", "20", "22", "24", "26", "28", "36", "2
8", "72" }));
cbTamao.setSelectedIndex(4);
cbTamao.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cbTamaoActionPerformed(evt);
}
});
lblFuente.setText("Fuente");
cbFuente.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "M
onospaced", "Arial", "Arial Black", "Garamond", "Comic sans MS", "Times New Roma
n" }));
cbFuente.setSelectedIndex(1);
cbFuente.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cbFuenteActionPerformed(evt);
}
});
javax.swing.GroupLayout pnlHerramientasLayout = new javax.swing.GroupLay
out(pnlHerramientas);
pnlHerramientas.setLayout(pnlHerramientasLayout);
pnlHerramientasLayout.setHorizontalGroup(
pnlHerramientasLayout.createParallelGroup(javax.swing.GroupLayout.Al
ignment.LEADING)
.addGroup(pnlHerramientasLayout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, j
avax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addComponent(lblFuente)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addComponent(cbFuente, javax.swing.GroupLayout.PREFERRED_SIZE,
111, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addComponent(cbEstilo, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addComponent(cbTamao, javax.swing.GroupLayout.PREFERRED_SIZE, 46
, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
);
pnlHerramientasLayout.setVerticalGroup(
pnlHerramientasLayout.createParallelGroup(javax.swing.GroupLayout.Al
ignment.LEADING)
.addGroup(pnlHerramientasLayout.createSequentialGroup()
.addGroup(pnlHerramientasLayout.createParallelGroup(javax.swing.
GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZ
E, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlHer
ramientasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblFuente)
.addComponent(cbFuente, javax.swing.GroupLayout.PREFERRE
D_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_
SIZE)
.addComponent(jLabel2)
.addComponent(cbTamao, javax.swing.GroupLayout.PREFERRED_
SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SI
ZE)
.addComponent(jLabel3)
.addComponent(cbEstilo, javax.swing.GroupLayout.PREFERRE
D_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_
SIZE)))
.addGap(0, 3, Short.MAX_VALUE))
);
jMenu1.setText("Archivo");
mnbNuevo.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.even
t.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
mnbNuevo.setText("Nuevo");
mnbNuevo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mnbNuevoActionPerformed(evt);
}
});
jMenu1.add(mnbNuevo);
mnbAbrir.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.even
t.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
mnbAbrir.setText("Abrir");
mnbAbrir.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mnbAbrirActionPerformed(evt);
}
});
jMenu1.add(mnbAbrir);
mnbGuardar.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.ev
ent.KeyEvent.VK_G, java.awt.event.InputEvent.CTRL_MASK));
mnbGuardar.setText("Guardar");
mnbGuardar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mnbGuardarActionPerformed(evt);
}
});
jMenu1.add(mnbGuardar);
mnbGuardarComo.setText("Guardar Como...");
mnbGuardarComo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mnbGuardarComoActionPerformed(evt);
}
});
jMenu1.add(mnbGuardarComo);
jMenuBar1.add(jMenu1);
jMenu2.setText("Edicin");
mnDeshacer.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.ev
ent.KeyEvent.VK_Z, java.awt.event.InputEvent.CTRL_MASK));
mnDeshacer.setText("Deshacer");
jMenu2.add(mnDeshacer);
mnRehacer.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.eve
nt.KeyEvent.VK_Y, java.awt.event.InputEvent.CTRL_MASK));
mnRehacer.setText("Rehacer");
jMenu2.add(mnRehacer);
jMenu2.add(jSeparator1);
mnbCortar.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.eve
nt.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
mnbCortar.setText("Cortar");
mnbCortar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mnbCortarActionPerformed(evt);
}
});
jMenu2.add(mnbCortar);
mnbCopiar.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.eve
nt.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
mnbCopiar.setText("Copiar");
mnbCopiar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mnbCopiarActionPerformed(evt);
}
});
jMenu2.add(mnbCopiar);
mnbPegar.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.even
t.KeyEvent.VK_V, java.awt.event.InputEvent.CTRL_MASK));
mnbPegar.setText("Pegar");
mnbPegar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mnbPegarActionPerformed(evt);
}
});
jMenu2.add(mnbPegar);
jMenu2.add(jSeparator2);
mnBuscar.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.even
t.KeyEvent.VK_B, java.awt.event.InputEvent.CTRL_MASK));
mnBuscar.setText("Buscar");
mnBuscar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mnBuscarActionPerformed(evt);
}
});
jMenu2.add(mnBuscar);
mnbReeplazar.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.
event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK));
mnbReeplazar.setText("Reemplazar...");
mnbReeplazar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mnbReeplazarActionPerformed(evt);
}
});
jMenu2.add(mnbReeplazar);
mnbIrA.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.
KeyEvent.VK_T, java.awt.event.InputEvent.CTRL_MASK));
mnbIrA.setText("Ir a...");
mnbIrA.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mnbIrAActionPerformed(evt);
}
});
jMenu2.add(mnbIrA);
jMenu2.add(jSeparator4);
mnbSelecAll.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.e
vent.KeyEvent.VK_E, java.awt.event.InputEvent.CTRL_MASK));
mnbSelecAll.setText("Seleccionar Todo");
mnbSelecAll.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mnbSelecAllActionPerformed(evt);
}
});
jMenu2.add(mnbSelecAll);
jMenuBar1.add(jMenu2);
jMenu3.setText("Formato");
mnbFuente.setText("Fuente...");
mnbFuente.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mnbFuenteActionPerformed(evt);
}
});
jMenu3.add(mnbFuente);
jMenuBar1.add(jMenu3);
jMenu4.setText("Ver");
mnbHerramientas.setText("Barra de Herramientas");
mnbHerramientas.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mnbHerramientasActionPerformed(evt);
}
});
jMenu4.add(mnbHerramientas);
mnbEstado.setText("Barra de Estado");
mnbEstado.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mnbEstadoActionPerformed(evt);
}
});
jMenu4.add(mnbEstado);
jMenuBar1.add(jMenu4);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentP
ane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING
)
.addComponent(jScrollPane1)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createS
equentialGroup()
.addGap(0, 585, Short.MAX_VALUE)
.addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZ
E, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addComponent(lblBarraEstado, javax.swing.GroupLayout.PREFERRED_
SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(pnlHerramientas, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING
)
.addGroup(layout.createSequentialGroup()
.addComponent(pnlHerramientas, javax.swing.GroupLayout.PREFERRED
_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_S
IZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE
, 375, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali
gnment.LEADING, false)
.addComponent(jSeparator3)
.addComponent(lblBarraEstado)))
);
pack();
}// </editor-fold>
private void btnNuevoActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
if (estado == true && longitud != 0) {
int rpta = JOptionPane.showConfirmDialog(this, "Desea guardar los ca
mbios hechos en el documento", "Confirmar", 0);
if (rpta == 0) {
guardar();
} else {
estado = false;
}
} else {
//No se realiz ningun cambio
}
}
private void cbFuenteActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
darFormato();
}
private void cbEstiloActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
darFormato();
}
private void cbTamaoActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
darFormato();
}
private void mnbGuardarComoActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
guardarComo();
longitud = txaSalida.getText().length();
estado = false;
}
private void mnbAbrirActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
if (estado == true) {
int rpta = JOptionPane.showConfirmDialog(this, "Desea guardar los ca
mbios hechos en el documento", "Confirmar", 0);
if (rpta == 0) {
guardar();
} else {
abrir();
longitud = txaSalida.getText().length();
System.out.println("Lineas : " + row);
estado = false;
}
} else {
abrir();
this.setTitle(": " + titulo);
longitud = txaSalida.getText().length();
System.out.println("Lineas : " + row);
estado = false;
}
}
private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {

guardar();
estado = false;
longitud = txaSalida.getText().length();
}
private void mnbFuenteActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
dlgFuente dlgF = new dlgFuente(this, true);
dlgF.setLocationRelativeTo(null);
dlgF.setVisible(true);
}
private void mnbEstadoActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
String estado = mnbEstado.getText();
if (estado.equalsIgnoreCase("Barra de Estado")) {
lblBarraEstado.setVisible(true);
jSeparator3.setVisible(true);
mnbEstado.setText("Ocultar Barra de Estado");
} else {
lblBarraEstado.setVisible(false);
jSeparator3.setVisible(false);
mnbEstado.setText("Barra de Estado");
}
}
private void mnbSelecAllActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
txaSalida.selectAll();
}
private void txaSalidaKeyReleased(java.awt.event.KeyEvent evt) {

// TODO add your handling code here:
deshabilitar();
estado = true;
longitud = txaSalida.getText().length();
}
private void mnBuscarActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
dlgBuscar b = new dlgBuscar(this, false);
b.setLocationRelativeTo(null);
b.setVisible(true);
}
private void btnCopiarActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
txaSalida.copy();
deshabilitar();
txaSalida.requestFocus();
}
private void btnPegarActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
txaSalida.paste();
deshabilitar();
txaSalida.requestFocus();
}
private void btnCortarActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
txaSalida.cut();
deshabilitar();
txaSalida.requestFocus();
}
private void mnbCortarActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
txaSalida.cut();
deshabilitar();
txaSalida.requestFocus();
}
private void mnbCopiarActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
txaSalida.copy();
deshabilitar();
txaSalida.requestFocus();
}
private void mnbPegarActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
txaSalida.paste();
deshabilitar();
txaSalida.requestFocus();
}
private void mnbReeplazarActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
dlgReemplazar rem = new dlgReemplazar(this, false);
rem.setLocationRelativeTo(null);
rem.setVisible(true);
}
private void mnbIrAActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
String num = JOptionPane.showInputDialog(this, "Ingrese la fila a buscar
");
}
private void txaSalidaCaretUpdate(javax.swing.event.CaretEvent evt) {

// TODO add your handling code here:
int pos = evt.getDot();
try {
row = txaSalida.getLineOfOffset(pos) + 1;
int col = pos - txaSalida.getLineStartOffset(row - 1) + 1;
lblBarraEstado.setText("Lineas : " + row + " , Columnas : " + col);
} catch (BadLocationException e) {
e.printStackTrace();
}
}
private void formWindowClosing(java.awt.event.WindowEvent evt) {

// TODO add your handling code here:
String cad = txaSalida.getText();
int longi = cad.length();
try {
if (estado == true && longitud != 0) {//Se hizo cambios en el docume
nto
int rpta = JOptionPane.showConfirmDialog(this, "Desea guardar lo
s cambios hechos en el documento", "Confirmar", 0);
if (rpta == 0) {
guardar();
} else {
System.exit(0);
}
} else {
//No se realizo algun cambio
}
} catch (NumberFormatException e) {
System.out.println(e.toString());
}
}
private void mnbNuevoActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
if (estado == true) {
int rpta = JOptionPane.showConfirmDialog(this, "Desea guardar los ca
mbios hechos en el documento", "Confirmar", 0);
if (rpta == 0) {
guardar();
} else {
estado = true;
}
} else {
//No se realiz ningun cambio
}
}
private void mnbGuardarActionPerformed(java.awt.event.ActionEvent evt) {

guardar();
estado = false;
longitud = txaSalida.getText().length();
}
private void btnAbrirActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
if (estado == true) {
int rpta = JOptionPane.showConfirmDialog(this, "Desea guardar los ca
mbios hechos en el documento", "Confirmar", 0);
if (rpta == 0) {
guardar();
} else {
abrir();
this.setTitle(": " + titulo);
longitud = txaSalida.getText().length();
System.out.println("Lineas : " + row);
estado = false;
}
} else {
abrir();
this.setTitle(": " + titulo);
longitud = txaSalida.getText().length();
System.out.println("Lineas : " + row);
estado = false;
}
}
private void mnbHerramientasActionPerformed(java.awt.event.ActionEvent evt)
{
// TODO add your handling code here:
String herramientas = mnbHerramientas.getText();
if (herramientas.equalsIgnoreCase("Barra de Herramientas")) {
pnlHerramientas.setVisible(true);
mnbHerramientas.setText("Ocultar Barra de Herramientas");
} else {
pnlHerramientas.setVisible(false);
mnbHerramientas.setText("Barra de Herramientas");
}
}
private void mbnCopiarActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
txaSalida.copy();
deshabilitar();
txaSalida.requestFocus();
}
private void mbnCortarActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
txaSalida.cut();
deshabilitar();
txaSalida.requestFocus();
}
private void mbnPegarActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
txaSalida.paste();
deshabilitar();
txaSalida.requestFocus();
}
private void mbnSelecAllActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
txaSalida.selectAll();
}
private void mbnAlinearActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
if (mbnAlinear.getText().equals("Alinear")) {
txaSalida.setLineWrap(true);
mbnAlinear.setText("Deshalinear");
} else {
txaSalida.setLineWrap(false);
mbnAlinear.setText("Alinear");
}
}
/*Funciones*/
public void guardar() {
try {
FileWriter fos = new FileWriter(ruta);
PrintWriter out = new PrintWriter(fos);
if (out != null) {
out.println(txaSalida.getText());
out.close();
}
} catch (IOException e) {
guardarComo();
}
}
public void guardarComo() {
file = new JFileChooser();
file.setFileFilter(filter);
int opcion = file.showSaveDialog(null);
File s = null;
if (opcion == JFileChooser.APPROVE_OPTION) {
s = file.getSelectedFile();
try {
FileWriter fw = new FileWriter(s);
BufferedWriter bw = new BufferedWriter(fw);
if (txaSalida.getText().length() > 0) {
fw.write(txaSalida.getText());
ruta = String.valueOf(s);
}
fw.close();
} catch (IOException e) {
JOptionPane.showMessageDialog(null, "Error al crear el archivo")
;
}
} else {
//s = "Operacion Cancelada";
}
}
public void abrir() {
seleccion = file.showOpenDialog(txaSalida);
if (seleccion == JFileChooser.APPROVE_OPTION) {
fichero = file.getSelectedFile();
ruta = String.valueOf(fichero);
try {
reader = new BufferedReader(new FileReader(fichero));
String lineaTotal = "";
texto = reader.readLine();
while (texto != null) {
lineaTotal = lineaTotal + texto + System.getProperty("line.s
eparator");
texto = reader.readLine();
}
txaSalida.setText(lineaTotal.toString());
reader.close();
} catch (Exception e) {
}
}
}
/*------------------------*/
/*Formato a fuente*/
public void darFormato() {
String fuente = Estilo.leeFuente1(cbFuente);
int estilo = Estilo.leeEstilo1(cbEstilo);
int tamao = Estilo.leeTamao1(cbTamao);
Font miFuente = new Font(fuente, estilo, tamao);
txaSalida.setFont(miFuente);
}
/*-----------------*/
/*Deshabilitar Botones*/
void deshabilitar() {
if (txaSalida.getText().trim().length() == 0) {
mnBuscar.setEnabled(false);
mbnCopiar.setEnabled(false);
mbnCortar.setEnabled(false);
btnCopiar.setEnabled(false);
btnCortar.setEnabled(false);
mnbCopiar.setEnabled(false);
mnbCortar.setEnabled(false);
mnDeshacer.setEnabled(false);
} else {
mnBuscar.setEnabled(true);
mbnCopiar.setEnabled(true);
mbnCortar.setEnabled(true);
btnCopiar.setEnabled(true);
btnCortar.setEnabled(true);
mnbCopiar.setEnabled(true);
mnbPegar.setEnabled(true);
mnbCortar.setEnabled(true);
mnDeshacer.setEnabled(true);
}
}
/*----------------------*/
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting cod
e (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the d
efault look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lo
okandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIMana
ger.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(frmNotepad.class.getName()).log(j
ava.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(frmNotepad.class.getName()).log(j
ava.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(frmNotepad.class.getName()).log(j
ava.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(frmNotepad.class.getName()).log(j
ava.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new frmNotepad().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btnAbrir;
private javax.swing.JButton btnCopiar;
private javax.swing.JButton btnCortar;
private javax.swing.JButton btnGuardar;
private javax.swing.JButton btnNuevo;
private javax.swing.JButton btnPegar;
private javax.swing.JComboBox cbEstilo;
private javax.swing.JComboBox cbFuente;
private javax.swing.JComboBox cbTamao;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenu jMenu3;
private javax.swing.JMenu jMenu4;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JPopupMenu.Separator jSeparator1;
private javax.swing.JPopupMenu.Separator jSeparator2;
private javax.swing.JSeparator jSeparator3;
private javax.swing.JPopupMenu.Separator jSeparator4;
private javax.swing.JPopupMenu.Separator jSeparator5;
private javax.swing.JLabel lblBarraEstado;
private javax.swing.JLabel lblFuente;
private javax.swing.JMenuItem mbnAlinear;
private javax.swing.JMenuItem mbnCopiar;
private javax.swing.JMenuItem mbnCortar;
private javax.swing.JMenuItem mbnDeshacer;
private javax.swing.JMenuItem mbnPegar;
private javax.swing.JMenuItem mbnSelecAll;
private javax.swing.JPopupMenu menuEmergente;
private javax.swing.JMenuItem mnBuscar;
private javax.swing.JMenuItem mnDeshacer;
private javax.swing.JMenuItem mnRehacer;
private javax.swing.JMenuItem mnbAbrir;
private javax.swing.JMenuItem mnbCopiar;
private javax.swing.JMenuItem mnbCortar;
private javax.swing.JMenuItem mnbEstado;
private javax.swing.JMenuItem mnbFuente;
private javax.swing.JMenuItem mnbGuardar;
private javax.swing.JMenuItem mnbGuardarComo;
private javax.swing.JMenuItem mnbHerramientas;
private javax.swing.JMenuItem mnbIrA;
private javax.swing.JMenuItem mnbNuevo;
private javax.swing.JMenuItem mnbPegar;
private javax.swing.JMenuItem mnbReeplazar;
private javax.swing.JMenuItem mnbSelecAll;
private javax.swing.JPanel pnlHerramientas;
public static javax.swing.JTextArea txaSalida;
// End of variables declaration
}