/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* JNotePad.java
*
* Created on 10-giu-2010, 12.21.40
*/
package jnotepad.graphics;
import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
import javax.swing.TransferHandler;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.filechooser.FileFilter;
import jnotepad.FileManager;
/**
*
* @author Paolo
*/
public class JNotePad
extends javax.
swing.
JFrame {
private FileManager manager;
private boolean salvato;
private boolean creato;
private boolean getUndo;
private ArrayList<String> storiaContent;
private int idContent;
/** Creates new form JNotePad */
public JNotePad() {
this.manager = new FileManager();
this.salvato = false;
this.getUndo = true;
try {
UIManager.
setLookAndFeel(new WindowsLookAndFeel
());
}
initComponents();
this.removeControlH();
this.newFile();
this.
setIconImage(Toolkit.
getDefaultToolkit().
getImage(getClass
().
getResource("/jnotepad/graphics/images/Notepad.png")));
}
private void removeControlH() {
this.textArea.getInputMap().put(ks, "none");
}
private void newFile() {
this.setTitle("Senza nome - JNotepad");
this.textArea.setText("");
this.manager = new FileManager();
this.salvato = false;
this.creato = true;
this.storiaContent = new ArrayList<String>();
this.storiaContent.add("");
this.idContent = 0;
}
private boolean checkSave() {
if (!this.salvato && !this.textArea.getText().isEmpty()) {
int retval
= JOptionPane.
showConfirmDialog(this,
"Il file non è stato salvato. Salvare?");
if (retval == 0) {
this.salvaActionPerformed(null);
return true;
} else if (retval == 1) {
return true;
} else {
return false;
}
}
return true;
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
trovaFrame
= new javax.
swing.
JFrame();
panello
= new javax.
swing.
JPanel();
trovaLabel
= new javax.
swing.
JLabel();
jPanel1
= new javax.
swing.
JPanel();
trovaButton
= new javax.
swing.
JButton();
annullaButton
= new javax.
swing.
JButton();
sostituisciLabel
= new javax.
swing.
JLabel();
sostituisciButton
= new javax.
swing.
JButton();
sostituisciTutto
= new javax.
swing.
JButton();
panel
= new javax.
swing.
JPanel();
Modifica
= new javax.
swing.
JMenu();
selezionaTutto
= new javax.
swing.
JMenuItem();
Formato
= new javax.
swing.
JMenu();
Help
= new javax.
swing.
JMenu();
trovaLabel.setText("Trova: ");
daTrovare.
addCaretListener(new javax.
swing.
event.
CaretListener() {
public void caretUpdate
(javax.
swing.
event.
CaretEvent evt
) {
daTrovareCaretUpdate(evt);
}
});
upperLower.setText("Maiuscole/Minuscole");
jPanel1.
setBorder(javax.
swing.
BorderFactory.
createTitledBorder("Direzione"));
gruppo.add(su);
su.setSelected(true);
su.setText("Su");
gruppo.add(giu);
giu.setText("Giu");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(su)
.addComponent(giu))
.
addContainerGap(41,
Short.
MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(su)
.
addPreferredGap(javax.
swing.
LayoutStyle.
ComponentPlacement.
RELATED, 37,
Short.
MAX_VALUE)
.addComponent(giu))
);
trovaButton.setText("Trova successivo");
trovaButton.setEnabled(false);
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
trovaButtonActionPerformed(evt);
}
});
annullaButton.setText("Annulla");
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
annullaButtonActionPerformed(evt);
}
});
sostituisciLabel.setText("Sostituisci: ");
sostituisciButton.setText("Sostituisci");
sostituisciButton.setEnabled(false);
sostituisciButton.
addActionListener(new java.
awt.
event.
ActionListener() {
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
sostituisciButtonActionPerformed(evt);
}
});
sostituisciTutto.setText("Sostituisci tutto");
sostituisciTutto.setEnabled(false);
sostituisciTutto.
addActionListener(new java.
awt.
event.
ActionListener() {
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
sostituisciTuttoActionPerformed(evt);
}
});
javax.swing.GroupLayout panelloLayout = new javax.swing.GroupLayout(panello);
panello.setLayout(panelloLayout);
panelloLayout.setHorizontalGroup(
panelloLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelloLayout.createSequentialGroup()
.addContainerGap()
.addGroup(panelloLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(upperLower)
.addGroup(panelloLayout.createSequentialGroup()
.addGroup(panelloLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(sostituisciLabel)
.addComponent(trovaLabel))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(panelloLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(daSostituire)
.addComponent(daTrovare, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(27, 27, 27)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(48, 48, 48)
.addGroup(panelloLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.
addComponent(sostituisciTutto, javax.
swing.
GroupLayout.
DEFAULT_SIZE, javax.
swing.
GroupLayout.
DEFAULT_SIZE,
Short.
MAX_VALUE)
.
addComponent(sostituisciButton, javax.
swing.
GroupLayout.
Alignment.
TRAILING, javax.
swing.
GroupLayout.
DEFAULT_SIZE, javax.
swing.
GroupLayout.
DEFAULT_SIZE,
Short.
MAX_VALUE)
.
addComponent(annullaButton, javax.
swing.
GroupLayout.
DEFAULT_SIZE, javax.
swing.
GroupLayout.
DEFAULT_SIZE,
Short.
MAX_VALUE)
.
addComponent(trovaButton, javax.
swing.
GroupLayout.
DEFAULT_SIZE, javax.
swing.
GroupLayout.
DEFAULT_SIZE,
Short.
MAX_VALUE))
.
addContainerGap(20,
Short.
MAX_VALUE))
);
panelloLayout.setVerticalGroup(
panelloLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelloLayout.createSequentialGroup()
.addContainerGap()
.addGroup(panelloLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.
addComponent(jPanel1, javax.
swing.
GroupLayout.
DEFAULT_SIZE, javax.
swing.
GroupLayout.
DEFAULT_SIZE,
Short.
MAX_VALUE)
.addGroup(panelloLayout.createSequentialGroup()
.addComponent(trovaButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(annullaButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(sostituisciButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(sostituisciTutto))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelloLayout.createSequentialGroup()
.addGroup(panelloLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(trovaLabel)
.addComponent(daTrovare, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(panelloLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(sostituisciLabel)
.addComponent(daSostituire, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.
addPreferredGap(javax.
swing.
LayoutStyle.
ComponentPlacement.
RELATED, 41,
Short.
MAX_VALUE)
.addComponent(upperLower)))
.addGap(24, 24, 24))
);
javax.swing.GroupLayout trovaFrameLayout = new javax.swing.GroupLayout(trovaFrame.getContentPane());
trovaFrame.getContentPane().setLayout(trovaFrameLayout);
trovaFrameLayout.setHorizontalGroup(
trovaFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.
addComponent(panello, javax.
swing.
GroupLayout.
DEFAULT_SIZE, javax.
swing.
GroupLayout.
DEFAULT_SIZE,
Short.
MAX_VALUE)
);
trovaFrameLayout.setVerticalGroup(
trovaFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.
addComponent(panello, javax.
swing.
GroupLayout.
DEFAULT_SIZE, javax.
swing.
GroupLayout.
DEFAULT_SIZE,
Short.
MAX_VALUE)
);
public void windowClosing
(java.
awt.
event.
WindowEvent evt
) {
formWindowClosing(evt);
}
});
textArea.setColumns(20);
textArea.setRows(5);
textArea.
addCaretListener(new javax.
swing.
event.
CaretListener() {
public void caretUpdate
(javax.
swing.
event.
CaretEvent evt
) {
textAreaCaretUpdate(evt);
}
});
jScrollPane1.setViewportView(textArea);
javax.swing.GroupLayout panelLayout = new javax.swing.GroupLayout(panel);
panel.setLayout(panelLayout);
panelLayout.setHorizontalGroup(
panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.
addComponent(jScrollPane1, javax.
swing.
GroupLayout.
DEFAULT_SIZE, 955,
Short.
MAX_VALUE)
);
panelLayout.setVerticalGroup(
panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.
addComponent(jScrollPane1, javax.
swing.
GroupLayout.
DEFAULT_SIZE, 626,
Short.
MAX_VALUE)
);
file.setText("Nuovo");
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
fileActionPerformed(evt);
}
});
apri.setText("Apri");
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
apriActionPerformed(evt);
}
});
salva.setText("Salva");
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
salvaActionPerformed(evt);
}
});
salvanome.setText("Salva con nome...");
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
salvanomeActionPerformed(evt);
}
});
esci.setText("Esci");
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
esciActionPerformed(evt);
}
});
Modifica.setText("Modifica");
annulla.setText("Annulla");
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
annullaActionPerformed(evt);
}
});
Modifica.add(annulla);
Modifica.add(jSeparator2);
taglia.setText("Taglia");
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
tagliaActionPerformed(evt);
}
});
Modifica.add(taglia);
copia.setText("Copia");
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
copiaActionPerformed(evt);
}
});
Modifica.add(copia);
incolla.setText("Incolla");
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
incollaActionPerformed(evt);
}
});
Modifica.add(incolla);
Modifica.add(jSeparator3);
trova.setText("Trova");
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
trovaActionPerformed(evt);
}
});
Modifica.add(trova);
sostituisci.setText("Sostituisci");
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
sostituisciActionPerformed(evt);
}
});
Modifica.add(sostituisci);
selezionaTutto.setText("Seleziona tutto");
selezionaTutto.
addActionListener(new java.
awt.
event.
ActionListener() {
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
selezionaTuttoActionPerformed(evt);
}
});
Modifica.add(selezionaTutto);
oradata.
setAccelerator(javax.
swing.
KeyStroke.
getKeyStroke(java.
awt.
event.
KeyEvent.
VK_F5, 0
));
oradata.setText("Ora/Data");
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
oradataActionPerformed(evt);
}
});
Modifica.add(oradata);
Formato.setText("Formato");
aCapo.setText("A capo automatico");
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
aCapoActionPerformed(evt);
}
});
Formato.add(aCapo);
Help.setText("?");
info.setText("Informazioni su JNotepad");
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
infoActionPerformed(evt);
}
});
Help.add(info);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.
addComponent(panel, javax.
swing.
GroupLayout.
DEFAULT_SIZE, javax.
swing.
GroupLayout.
DEFAULT_SIZE,
Short.
MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.
addComponent(panel, javax.
swing.
GroupLayout.
DEFAULT_SIZE, javax.
swing.
GroupLayout.
DEFAULT_SIZE,
Short.
MAX_VALUE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void fileActionPerformed
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_fileActionPerformed
if (this.checkSave()) {
this.newFile();
}
}//GEN-LAST:event_fileActionPerformed
private void apriActionPerformed
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_apriActionPerformed
apriFile.removeChoosableFileFilter(apriFile.getAcceptAllFileFilter());
@Override
public boolean accept
(File f
) {
String estensione
= path.
substring((path.
length() - 3
), path.
length());
if (estensione.toLowerCase().equals("txt") || f.isDirectory()) {
return true;
}
return false;
}
@Override
public String getDescription
() {
return "File di testo (txt)";
}
});
int retval = apriFile.showOpenDialog(this);
if (this.checkSave()) {
this.apriFile(apriFile.getSelectedFile());
}
}
}//GEN-LAST:event_apriActionPerformed
public void apriFile
(File pFile
) {
this.manager.setFile(pFile);
String contenutoFile
= this.
manager.
leggi();
this.textArea.setText(contenutoFile);
this.storiaContent = new ArrayList<String>();
this.storiaContent.add(contenutoFile);
this.idContent = 0;
this.setTitle(pFile.getName() + " - JNotepad");
this.creato = false;
}
private void salvaActionPerformed
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_salvaActionPerformed
if (this.creato) {
this.salvanomeActionPerformed(null);
} else {
this.manager.scrivi(this.textArea.getText());
this.salvato = true;
}
}//GEN-LAST:event_salvaActionPerformed
private void salvanomeActionPerformed
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_salvanomeActionPerformed
salvaFile.removeChoosableFileFilter(salvaFile.getAcceptAllFileFilter());
@Override
public boolean accept
(File f
) {
String estensione
= path.
substring((path.
length() - 3
), path.
length());
if (estensione.toLowerCase().equals("txt") || f.isDirectory()) {
return true;
}
return false;
}
@Override
public String getDescription
() {
return "File di testo (txt)";
}
});
int retval = salvaFile.showSaveDialog(this);
File daSalvare
= salvaFile.
getSelectedFile();
String est
= daSalvare.
getName().
substring(daSalvare.
getName().
length() - 4, daSalvare.
getName().
length());
if (!est.equals(".txt")) {
daSalvare
= new File(daSalvare.
getAbsoluteFile() + ".txt");
}
if (daSalvare.exists()) {
int risposta
= JOptionPane.
showConfirmDialog(this,
"Il file esiste già : sovrascrivere?");
if (risposta == 0) {
this.manager.setFile(daSalvare);
this.manager.scrivi(this.textArea.getText());
this.salvato = true;
this.creato = false;
} else if (risposta == 1) {
this.salvanomeActionPerformed(null);
}
} else {
this.manager.setFile(daSalvare);
this.manager.scrivi(this.textArea.getText());
this.salvato = true;
this.creato = false;
}
this.setTitle(daSalvare.getName() + " - JNotepad");
}
}//GEN-LAST:event_salvanomeActionPerformed
private void esciActionPerformed
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_esciActionPerformed
this.formWindowClosing(null);
}//GEN-LAST:event_esciActionPerformed
private void formWindowClosing
(java.
awt.
event.
WindowEvent evt
) {//GEN-FIRST:event_formWindowClosing
if (this.checkSave()) {
}
}//GEN-LAST:event_formWindowClosing
private void annullaActionPerformed
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_annullaActionPerformed
if (this.idContent > 0) {
this.idContent--;
this.getUndo = false;
this.textArea.setText(this.storiaContent.get(this.idContent));
this.getUndo = true;
}
}//GEN-LAST:event_annullaActionPerformed
private void textAreaCaretUpdate
(javax.
swing.
event.
CaretEvent evt
) {//GEN-FIRST:event_textAreaCaretUpdate
if (this.getUndo) {
int attuale = this.textArea.getText().length();
int vecchia = 0;
if (this.idContent != 0) {
this.storiaContent.get(this.idContent - 1).length();
}
if (attuale != vecchia) {
this.idContent++;
if (this.storiaContent.size() > this.idContent + 1) {
this.storiaContent.set(this.idContent + 1, this.textArea.getText());
} else {
this.storiaContent.add(this.textArea.getText());
}
}
}
}//GEN-LAST:event_textAreaCaretUpdate
private void tagliaActionPerformed
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_tagliaActionPerformed
TransferHandler cut = textArea.getTransferHandler();
cut.exportToClipboard(textArea, clip, TransferHandler.MOVE);
}//GEN-LAST:event_tagliaActionPerformed
private void copiaActionPerformed
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_copiaActionPerformed
TransferHandler copy = textArea.getTransferHandler();
copy.exportToClipboard(textArea, clip, TransferHandler.COPY);
}//GEN-LAST:event_copiaActionPerformed
private void incollaActionPerformed
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_incollaActionPerformed
try {
if (textArea.getSelectedText() == null) {
textArea.insert(testoIncollato, textArea.getCaretPosition());
} else {
textArea.replaceSelection(testoIncollato);
}
}
}//GEN-LAST:event_incollaActionPerformed
private void trovaActionPerformed
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_trovaActionPerformed
this.trovaFrame.setVisible(true);
this.daSostituire.setVisible(false);
this.sostituisciButton.setVisible(false);
this.sostituisciLabel.setVisible(false);
this.trovaFrame.setBounds(this.getLocation().x + 100, this.getLocation().y + 100, 500, 160);
}//GEN-LAST:event_trovaActionPerformed
private void sostituisciActionPerformed
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_sostituisciActionPerformed
this.trovaFrame.setVisible(true);
this.daSostituire.setVisible(true);
this.sostituisciButton.setVisible(true);
this.sostituisciLabel.setVisible(true);
this.trovaFrame.setBounds(this.getLocation().x + 100, this.getLocation().y + 100, 500, 160);
}//GEN-LAST:event_sostituisciActionPerformed
private void selezionaTuttoActionPerformed
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_selezionaTuttoActionPerformed
this.textArea.setSelectionStart(0);
this.textArea.setSelectionEnd(this.textArea.getText().length());
}//GEN-LAST:event_selezionaTuttoActionPerformed
private void oradataActionPerformed
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_oradataActionPerformed
String data
= ora
+ ":" + minuti
+ ":" + secondi
+ " " + giorno
+ "/" + mese
+ "/" + anno
;
this.textArea.append(data);
}//GEN-LAST:event_oradataActionPerformed
private void aCapoActionPerformed
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_aCapoActionPerformed
this.textArea.setLineWrap(this.aCapo.isSelected());
this.textArea.repaint();
}//GEN-LAST:event_aCapoActionPerformed
private void infoActionPerformed
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_infoActionPerformed
frame.setResizable(false);
frame.
setDefaultCloseOperation(JFrame.
HIDE_ON_CLOSE);
frame.setBounds(this.getLocation().x + 100, this.getLocation().y + 100, 400, 300);
frame.setVisible(true);
content.
setIcon(new ImageIcon(getClass
().
getResource("/jnotepad/graphics/images/logo.png")));
content.setText("<html>" +
"Creato da Paolo Ricciuti senza alcun scopo di lucro per la " +
"community PieroTofy a scopo illustrativo dei principali " +
"metodi e classi del package swing." +
"</html>");
frame.add(content);
}//GEN-LAST:event_infoActionPerformed
private void daTrovareCaretUpdate
(javax.
swing.
event.
CaretEvent evt
) {//GEN-FIRST:event_daTrovareCaretUpdate
if (this.daTrovare.getText().length() != 0) {
this.trovaButton.setEnabled(true);
this.sostituisciButton.setEnabled(true);
this.sostituisciTutto.setEnabled(true);
} else {
this.trovaButton.setEnabled(false);
}
}//GEN-LAST:event_daTrovareCaretUpdate
private void trovaButtonActionPerformed
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_trovaButtonActionPerformed
if (this.su.isSelected()) {
String testo
= this.
textArea.
getText();
String trovare
= this.
daTrovare.
getText();
if (this.upperLower.isSelected()) {
testo = testo.toLowerCase();
trovare = trovare.toLowerCase();
}
if (this.textArea.getSelectedText() != null) {
if (this.textArea.getSelectionEnd() == this.textArea.getCaretPosition()) {
this.textArea.setCaretPosition(this.textArea.getCaretPosition() - trovare.length());
}
}
testo = testo.substring(0, this.textArea.getCaretPosition());
int index = testo.lastIndexOf(trovare);
if (index != -1) {
this.textArea.select(index, index + trovare.length());
} else {
JOptionPane.
showMessageDialog(this,
"Ricerca completata");
}
} else {
String testo
= this.
textArea.
getText();
String trovare
= this.
daTrovare.
getText();
if (this.upperLower.isSelected()) {
testo = testo.toLowerCase();
trovare = trovare.toLowerCase();
}
int index = testo.indexOf(trovare, this.textArea.getCaretPosition());
if (index != -1) {
this.textArea.setCaretPosition(index + trovare.length());
this.textArea.select(index, index + trovare.length());
} else {
JOptionPane.
showMessageDialog(this,
"Ricerca completata");
}
}
}//GEN-LAST:event_trovaButtonActionPerformed
private void annullaButtonActionPerformed
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_annullaButtonActionPerformed
this.trovaFrame.dispose();
}//GEN-LAST:event_annullaButtonActionPerformed
private void sostituisciButtonActionPerformed
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_sostituisciButtonActionPerformed
this.textArea.replaceSelection(this.daSostituire.getText());
}//GEN-LAST:event_sostituisciButtonActionPerformed
private void sostituisciTuttoActionPerformed
(java.
awt.
event.
ActionEvent evt
) {//GEN-FIRST:event_sostituisciTuttoActionPerformed
String testo
= this.
textArea.
getText();
testo = testo.replaceAll(this.daTrovare.getText(), this.daSostituire.getText());
this.textArea.setText(testo);
}//GEN-LAST:event_sostituisciTuttoActionPerformed
/**
* @param args the command line arguments
*/
public static void main
(final String args
[]) {
public void run() {
JNotePad pad = new JNotePad();
pad.setLocation(50, 50);
pad.setVisible(true);
if (args.length == 1) {
if (args[0].toLowerCase().endsWith(".txt")) {
pad.
apriFile(new File(args
[0
]));
}
}
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.
swing.
JMenu Formato
;
private javax.
swing.
JMenu Help
;
private javax.
swing.
JMenu Modifica
;
private javax.
swing.
JButton annullaButton
;
private javax.
swing.
JPanel jPanel1
;
private javax.
swing.
JPanel panel
;
private javax.
swing.
JPanel panello
;
private javax.
swing.
JMenuItem selezionaTutto
;
private javax.
swing.
JButton sostituisciButton
;
private javax.
swing.
JLabel sostituisciLabel
;
private javax.
swing.
JButton sostituisciTutto
;
private javax.
swing.
JButton trovaButton
;
private javax.
swing.
JFrame trovaFrame
;
private javax.
swing.
JLabel trovaLabel
;
// End of variables declaration//GEN-END:variables
}